Skip to content

Commit

Permalink
[Cider 2 | Debugger] Preserve debugger info and command history on re…
Browse files Browse the repository at this point in the history
…start (#2213)

A small patch that makes the new `restart` command preserve the
watchpoints, breakpoints, and command history of the debugger rather
than fully resetting it.
  • Loading branch information
EclecticGriffin authored Jul 18, 2024
1 parent dd22480 commit d1a2b96
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion interp/src/debugger/commands/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ lazy_static! {
CIBuilder::new().invocation("explain")
.description("Show examples of commands which take arguments").build(),
CIBuilder::new().invocation("restart")
.description("Restart the debugger from the beginning of the execution. This will reset all breakpoints, watchpoints, and the command history").build(),
.description("Restart the debugger from the beginning of the execution. Command history, breakpoints, watchpoints, etc. are preserved").build(),
// exit/quit
CIBuilder::new().invocation("exit")
.invocation("quit")
Expand Down
38 changes: 33 additions & 5 deletions interp/src/debugger/debugger_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ impl ProgramStatus {
}
}

/// An opaque wrapper type for internal debugging information
pub struct DebuggerInfo {
ctx: DebuggingContext,
input_stream: Input,
}

pub enum DebuggerReturnStatus {
Restart,
Restart(Box<DebuggerInfo>),
Exit,
}

Expand Down Expand Up @@ -177,8 +183,20 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {

// so on and so forth

pub fn main_loop(mut self) -> InterpreterResult<DebuggerReturnStatus> {
let mut input_stream = Input::new()?;
pub fn main_loop(
mut self,
info: Option<DebuggerInfo>,
) -> InterpreterResult<DebuggerReturnStatus> {
let (input_stream, dbg_ctx) = info
.map(|x| (Some(x.input_stream), Some(x.ctx)))
.unwrap_or_else(|| (None, None));

if let Some(dbg_ctx) = dbg_ctx {
self.debugging_context = dbg_ctx;
}

let mut input_stream =
input_stream.map(Ok).unwrap_or_else(Input::new)?;

println!(
"==== {}: The {}alyx {}nterpreter and {}bugge{} ====",
Expand Down Expand Up @@ -275,7 +293,12 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {
}

Command::Restart => {
return Ok(DebuggerReturnStatus::Restart);
return Ok(DebuggerReturnStatus::Restart(Box::new(
DebuggerInfo {
ctx: self.debugging_context,
input_stream,
},
)));
}
}
}
Expand Down Expand Up @@ -322,7 +345,12 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {
print!("{}", Command::get_explain_string().blue().bold())
}
Command::Restart => {
return Ok(DebuggerReturnStatus::Restart);
return Ok(DebuggerReturnStatus::Restart(Box::new(
DebuggerInfo {
ctx: self.debugging_context,
input_stream,
},
)));
}
_ => {
println!(
Expand Down
6 changes: 6 additions & 0 deletions interp/src/debugger/debugging_context/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,9 @@ impl DebuggingContext {
}
}
}

impl Default for DebuggingContext {
fn default() -> Self {
Self::new()
}
}
7 changes: 3 additions & 4 deletions interp/src/debugger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ mod io_utils;
mod macros;
pub mod source;

pub use debugger_core::Debugger;
pub use debugger_core::DebuggerReturnStatus;
pub use debugger_core::OwnedDebugger;
pub use debugger_core::ProgramStatus;
pub use debugger_core::{
Debugger, DebuggerInfo, DebuggerReturnStatus, OwnedDebugger, ProgramStatus,
};

pub(crate) use macros::unwrap_error_message;
9 changes: 6 additions & 3 deletions interp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use argh::FromArgs;
use calyx_utils::OutputFile;
use interp::{
configuration,
debugger::{Debugger, DebuggerReturnStatus},
debugger::{Debugger, DebuggerInfo, DebuggerReturnStatus},
errors::InterpreterResult,
flatten::structures::environment::Simulator,
};
Expand Down Expand Up @@ -128,13 +128,16 @@ fn main() -> InterpreterResult<()> {
Ok(())
}
Command::Debug(_) => {
let mut info: Option<DebuggerInfo> = None;
loop {
let debugger = Debugger::new(&i_ctx, &opts.data_file)?;

let result = debugger.main_loop()?;
let result = debugger.main_loop(info)?;
match result {
DebuggerReturnStatus::Exit => break,
DebuggerReturnStatus::Restart => continue,
DebuggerReturnStatus::Restart(new_info) => {
info = Some(*new_info);
}
}
}
Ok(())
Expand Down

0 comments on commit d1a2b96

Please sign in to comment.