Skip to content
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 @@ -429,6 +429,12 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> DebugContext<'a, B> {
.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
28 changes: 28 additions & 0 deletions tooling/debugger/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,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: DebugLocation) {
if self.context.delete_breakpoint(&location) {
println!("Breakpoint at {location} deleted");
Expand Down Expand Up @@ -536,6 +554,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