Skip to content

Commit

Permalink
chore: Simplify selection/validation of package for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Oct 12, 2023
1 parent dd30bca commit f20d0e1
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,42 @@ pub(crate) fn run(
let target_dir = &workspace.target_directory_path();
let (np_language, opcode_support) = backend.get_backend_info()?;

if workspace.into_iter().filter(|p| p.is_binary()).count() == 0 {
let Some(package) = workspace.into_iter().find(|p| p.is_binary()) else {
println!(
"No matching binary packages found in workspace. Only binary packages can be debugged."
);
return Ok(());
}
};

let compiled_program = compile_bin_package(
&workspace,
package,
&args.compile_options,
true,
np_language,
&|opcode| opcode_support.is_opcode_supported(opcode),
)?;

println!("[{}] Starting debugger", package.name);
let (return_value, solved_witness) =
debug_program_and_decode(compiled_program, package, &args.prover_name)?;

for package in &workspace {
if package.is_binary() {
let compiled_program = compile_bin_package(
&workspace,
package,
&args.compile_options,
true,
np_language,
&|opcode| opcode_support.is_opcode_supported(opcode),
)?;

println!("[{}] Starting debugger", package.name);
let (return_value, solved_witness) =
debug_program_and_decode(compiled_program, package, &args.prover_name)?;

if let Some(solved_witness) = solved_witness {
println!("[{}] Circuit witness successfully solved", package.name);

if let Some(return_value) = return_value {
println!("[{}] Circuit output: {return_value:?}", package.name);
}

if let Some(witness_name) = &args.witness_name {
let witness_path =
save_witness_to_dir(solved_witness, witness_name, target_dir)?;

println!("[{}] Witness saved to {}", package.name, witness_path.display());
}
} else {
println!("Debugger execution halted.");
}

// Only debug the first binary package that matches the selection criteria
break;
if let Some(solved_witness) = solved_witness {
println!("[{}] Circuit witness successfully solved", package.name);

if let Some(return_value) = return_value {
println!("[{}] Circuit output: {return_value:?}", package.name);
}

if let Some(witness_name) = &args.witness_name {
let witness_path = save_witness_to_dir(solved_witness, witness_name, target_dir)?;

println!("[{}] Witness saved to {}", package.name, witness_path.display());
}
} else {
println!("Debugger execution halted.");
}

Ok(())
}

Expand Down

0 comments on commit f20d0e1

Please sign in to comment.