Fix function exit trigger and add function enter trigger.

This commit is contained in:
Stephen Chung
2022-02-02 22:42:33 +08:00
parent db2f1a601c
commit 8322e62c18
9 changed files with 115 additions and 68 deletions

View File

@@ -51,6 +51,13 @@ pub enum DebuggerCommand {
FunctionExit,
}
impl Default for DebuggerCommand {
#[inline(always)]
fn default() -> Self {
Self::Continue
}
}
/// The debugger status.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum DebuggerStatus {
@@ -60,6 +67,19 @@ pub enum DebuggerStatus {
FunctionExit(usize),
}
impl Default for DebuggerStatus {
#[inline(always)]
fn default() -> Self {
Self::CONTINUE
}
}
impl DebuggerStatus {
pub const CONTINUE: Self = Self::Next(false, false);
pub const STEP: Self = Self::Next(true, true);
pub const NEXT: Self = Self::Next(true, false);
}
/// A event that triggers the debugger.
#[derive(Debug, Clone, Copy)]
pub enum DebuggerEvent<'a> {
@@ -231,7 +251,7 @@ impl fmt::Display for CallStackFrame {
#[derive(Debug, Clone, Hash)]
pub struct Debugger {
/// The current status command.
status: DebuggerStatus,
pub(crate) status: DebuggerStatus,
/// The current state.
state: Dynamic,
/// The current set of break-points.
@@ -247,9 +267,9 @@ impl Debugger {
pub fn new(engine: &Engine) -> Self {
Self {
status: if engine.debugger.is_some() {
DebuggerStatus::Next(true, true)
DebuggerStatus::STEP
} else {
DebuggerStatus::Next(false, false)
DebuggerStatus::CONTINUE
},
state: if let Some((ref init, _)) = engine.debugger {
init()
@@ -299,12 +319,6 @@ impl Debugger {
pos,
});
}
/// Get the current status of this [`Debugger`].
#[inline(always)]
#[must_use]
pub(crate) fn status(&self) -> DebuggerStatus {
self.status
}
/// Set the status of this [`Debugger`].
#[inline(always)]
pub(crate) fn reset_status(&mut self, status: Option<DebuggerStatus>) {
@@ -476,19 +490,19 @@ impl Engine {
match command {
DebuggerCommand::Continue => {
global.debugger.status = DebuggerStatus::Next(false, false);
global.debugger.status = DebuggerStatus::CONTINUE;
Ok(None)
}
DebuggerCommand::Next => {
global.debugger.status = DebuggerStatus::Next(false, false);
Ok(Some(DebuggerStatus::Next(true, false)))
global.debugger.status = DebuggerStatus::CONTINUE;
Ok(Some(DebuggerStatus::NEXT))
}
DebuggerCommand::StepOver => {
global.debugger.status = DebuggerStatus::Next(false, false);
Ok(Some(DebuggerStatus::Next(true, true)))
global.debugger.status = DebuggerStatus::CONTINUE;
Ok(Some(DebuggerStatus::STEP))
}
DebuggerCommand::StepInto => {
global.debugger.status = DebuggerStatus::Next(true, true);
global.debugger.status = DebuggerStatus::STEP;
Ok(None)
}
DebuggerCommand::FunctionExit => {
@@ -499,6 +513,7 @@ impl Engine {
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(_, _))) => context.call_level() + 1,
_ => context.call_level(),
};
println!("Set FunctionExit to {}", level);
global.debugger.status = DebuggerStatus::FunctionExit(level);
Ok(None)
}