From cb8765d042d07a0bea821659569e867a155cac09 Mon Sep 17 00:00:00 2001 From: pjht Date: Tue, 18 Oct 2022 17:21:35 -0500 Subject: [PATCH] Add command to set and list breakpoints --- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/main.rs b/src/main.rs index ffe4f7b..7995fc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -486,6 +486,48 @@ fn main() -> Result<(), ReplError> { ))) }, ) + .with_command( + Command::new("bp") + .arg(Arg::new("location").help("The location to set a breakpoint at")) + .help("Set a breakpoint or list current breakpoints"), + |args, state| { + if let Some(location) = args.get_one::("location") { + let location = parse_location(location, &state.symbol_tables)?; + match location { + Location::Symbol((table, symbol)) => state + .symbol_tables + .get_mut(&table) + .unwrap() + .breakpoints + .insert_if_absent(symbol), + Location::Address(address) => { + state.address_breakpoints.insert_if_absent(address) + } + }; + Ok(None) + } else { + let mut out = String::new(); + for (table_name, table) in &state.symbol_tables { + if !table.breakpoints.is_empty() { + out += table_name; + out += ":\n"; + for breakpoint in &table.breakpoints { + out += breakpoint; + out += "\n"; + } + } + } + if !state.address_breakpoints.is_empty() { + out += "Address breakpoints:\n"; + for breakpoint in &state.address_breakpoints { + out += &format!("{}\n", breakpoint); + } + } + out.pop(); + Ok(Some(out)) + } + }, + ) .with_command( Command::new("quit") .visible_alias("q")