Skip to content

Commit ef51d8a

Browse files
feat(debugger): REPL add breakpoint by sourcecode line (#5204)
1 parent 69e901f commit ef51d8a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

tooling/debugger/src/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> DebugContext<'a, B> {
429429
.filter(|v: &Vec<Location>| !v.is_empty())
430430
}
431431

432+
/// Returns the `FileId` of the file associated with the innermost function on the call stack.
433+
pub(super) fn get_current_file(&mut self) -> Option<FileId> {
434+
self.get_current_source_location()
435+
.and_then(|locations| locations.last().map(|location| location.file))
436+
}
437+
432438
/// Returns the (possible) stack of source locations corresponding to the
433439
/// given opcode location. Due to compiler inlining it's possible for this
434440
/// function to return multiple source locations. An empty vector means that

tooling/debugger/src/repl.rs

+28
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,24 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ReplDebugger<'a, B> {
243243
}
244244
}
245245

246+
fn add_breakpoint_at_line(&mut self, line_number: i64) {
247+
let Some(current_file) = self.context.get_current_file() else {
248+
println!("No current file.");
249+
return;
250+
};
251+
252+
let best_location =
253+
self.context.find_opcode_for_source_location(&current_file, line_number);
254+
255+
match best_location {
256+
Some(location) => {
257+
println!("Added breakpoint at line {}", line_number);
258+
self.add_breakpoint_at(location)
259+
}
260+
None => println!("No opcode at line {}", line_number),
261+
}
262+
}
263+
246264
fn delete_breakpoint_at(&mut self, location: DebugLocation) {
247265
if self.context.delete_breakpoint(&location) {
248266
println!("Breakpoint at {location} deleted");
@@ -536,6 +554,16 @@ pub fn run<B: BlackBoxFunctionSolver<FieldElement>>(
536554
}
537555
},
538556
)
557+
.add(
558+
"break",
559+
command! {
560+
"add a breakpoint at a line of the current file",
561+
(line_number: i64) => |line_number| {
562+
ref_context.borrow_mut().add_breakpoint_at_line(line_number);
563+
Ok(CommandStatus::Done)
564+
}
565+
},
566+
)
539567
.add(
540568
"break",
541569
command! {

0 commit comments

Comments
 (0)