Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(debugger): REPL add breakpoint by sourcecode line #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tooling/debugger/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@
.filter(|v: &Vec<Location>| !v.is_empty())
}

/// Returns the `FileId` of the file associated with the innermost function on the call stack.
pub(super) fn get_current_file(&mut self) -> Option<FileId> {
self.get_current_source_location()
.and_then(|locations| locations.last().map(|location| location.file))
}

/// Returns the (possible) stack of source locations corresponding to the
/// given opcode location. Due to compiler inlining it's possible for this
/// function to return multiple source locations. An empty vector means that
Expand Down Expand Up @@ -673,7 +679,7 @@
outputs: vec![],
predicate: None,
}];
let brillig_funcs = &vec![brillig_bytecode];

Check warning on line 682 in tooling/debugger/src/context.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funcs)
let current_witness_index = 2;
let circuit = &Circuit { current_witness_index, opcodes, ..Circuit::default() };

Expand All @@ -691,7 +697,7 @@
debug_artifact,
initial_witness,
foreign_call_executor,
brillig_funcs,

Check warning on line 700 in tooling/debugger/src/context.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funcs)
);

assert_eq!(context.get_current_opcode_location(), Some(OpcodeLocation::Acir(0)));
Expand Down Expand Up @@ -794,14 +800,14 @@

let foreign_call_executor =
Box::new(DefaultDebugForeignCallExecutor::from_artifact(true, debug_artifact));
let brillig_funcs = &vec![brillig_bytecode];

Check warning on line 803 in tooling/debugger/src/context.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funcs)
let mut context = DebugContext::new(
&StubbedBlackBoxSolver,
circuit,
debug_artifact,
initial_witness,
foreign_call_executor,
brillig_funcs,

Check warning on line 810 in tooling/debugger/src/context.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funcs)
);

// set breakpoint
Expand Down Expand Up @@ -846,7 +852,7 @@
];
let circuit = Circuit { opcodes, ..Circuit::default() };
let debug_artifact = DebugArtifact { debug_symbols: vec![], file_map: BTreeMap::new() };
let brillig_funcs = &vec![brillig_bytecode];

Check warning on line 855 in tooling/debugger/src/context.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funcs)
let context = DebugContext::new(
&StubbedBlackBoxSolver,
&circuit,
Expand Down
28 changes: 28 additions & 0 deletions tooling/debugger/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ReplDebugger<'a, B> {
}
}

fn add_breakpoint_at_line(&mut self, line_number: i64) {
let Some(current_file) = self.context.get_current_file() else {
println!("No current file.");
return;
};

let best_location =
self.context.find_opcode_for_source_location(&current_file, line_number);

match best_location {
Some(location) => {
println!("Added breakpoint at line {}", line_number);
self.add_breakpoint_at(location)
}
None => println!("No opcode at line {}", line_number),
}
}

fn delete_breakpoint_at(&mut self, location: OpcodeLocation) {
if self.context.delete_breakpoint(&location) {
println!("Breakpoint at opcode {location} deleted");
Expand Down Expand Up @@ -475,6 +493,16 @@ pub fn run<B: BlackBoxFunctionSolver<FieldElement>>(
}
},
)
.add(
"break",
command! {
"add a breakpoint at a line of the current file",
(line_number: i64) => |line_number| {
ref_context.borrow_mut().add_breakpoint_at_line(line_number);
Ok(CommandStatus::Done)
}
},
)
.add(
"break",
command! {
Expand Down
Loading