Skip to content

Commit

Permalink
fix: Prevent debugger crashing on circuits with no opcodes (noir-lang…
Browse files Browse the repository at this point in the history
…#4283)

# Description

## Problem\*

Resolves noir-lang#4231

The REPL debugger is not handling the case when the compiled circuit has
no opcodes and since it assumes there will be some opcodes, it panics on
continue.

## Summary\*

With this PR, the REPL debugger will start in a "finished" stated in
those cases and the DAP will not start the main loop.

## Additional Context

This edge case is very unlikely to happen, especially after applying
noir-lang#4185 which changes the default mode for the debugger to Brillig (seems
to generate at least a trampoline-like fragment even for empty programs)
and after the introduction of debugging instrumentation. Nevertheless it
will still be possible (eg. empty program and passing `--acir-mode`
option).

## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
ggiraldez authored Feb 6, 2024
1 parent 48e5e7c commit 2e32845
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tooling/debugger/src/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> {
}

pub fn run_loop(&mut self) -> Result<(), ServerError> {
self.running = true;
self.running = self.context.get_current_opcode_location().is_some();

if matches!(self.context.get_current_source_location(), None) {
if self.running && matches!(self.context.get_current_source_location(), None) {
// TODO: remove this? This is to ensure that the tool has a proper
// source location to show when first starting the debugger, but
// maybe the default behavior should be to start executing until the
Expand Down
15 changes: 7 additions & 8 deletions tooling/debugger/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ impl<'a, B: BlackBoxFunctionSolver> ReplDebugger<'a, B> {
initial_witness.clone(),
foreign_call_executor,
);
Self {
context,
blackbox_solver,
circuit,
debug_artifact,
initial_witness,
last_result: DebugCommandResult::Ok,
}
let last_result = if context.get_current_opcode_location().is_none() {
// handle circuit with no opcodes
DebugCommandResult::Done
} else {
DebugCommandResult::Ok
};
Self { context, blackbox_solver, circuit, debug_artifact, initial_witness, last_result }
}

pub fn show_current_vm_status(&self) {
Expand Down

0 comments on commit 2e32845

Please sign in to comment.