Skip to content

Commit

Permalink
chore(debugger): Run debugger REPL in thread (#3611)
Browse files Browse the repository at this point in the history
Run debugger REPL in thread
  • Loading branch information
mverzilli authored Nov 29, 2023
1 parent c789228 commit 3140468
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use acvm::acir::native_types::WitnessMap;
use clap::Args;

Expand Down Expand Up @@ -64,27 +66,42 @@ pub(crate) fn run(
&opcode_support,
)?;

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

fn run_async(
package: &Package,
program: CompiledProgram,
prover_name: &str,
witness_name: &Option<String>,
target_dir: &PathBuf,
) -> Result<(), CliError> {
use tokio::runtime::Builder;
let runtime = Builder::new_current_thread().enable_all().build().unwrap();

runtime.block_on(async {
println!("[{}] Starting debugger", package.name);
let (return_value, solved_witness) =
debug_program_and_decode(program, package, prover_name)?;

if let Some(solved_witness) = solved_witness {
println!("[{}] Circuit witness successfully solved", package.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(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)?;
if let Some(witness_name) = witness_name {
let witness_path = save_witness_to_dir(solved_witness, witness_name, target_dir)?;

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

Ok(())
Ok(())
})
}

fn debug_program_and_decode(
Expand Down

0 comments on commit 3140468

Please sign in to comment.