Make call stack available also under no_function.

This commit is contained in:
Stephen Chung 2022-02-02 15:07:22 +08:00
parent e0ed713bb6
commit db2f1a601c
2 changed files with 3 additions and 19 deletions

View File

@ -56,7 +56,7 @@ pub enum DebuggerCommand {
pub enum DebuggerStatus { pub enum DebuggerStatus {
// Stop at the next statement or expression. // Stop at the next statement or expression.
Next(bool, bool), Next(bool, bool),
// Run to the end of the current function call. // Run to the end of the current level of function call.
FunctionExit(usize), FunctionExit(usize),
} }
@ -193,7 +193,6 @@ impl BreakPoint {
} }
/// A function call. /// A function call.
#[cfg(not(feature = "no_function"))]
#[derive(Debug, Clone, Hash)] #[derive(Debug, Clone, Hash)]
pub struct CallStackFrame { pub struct CallStackFrame {
/// Function name. /// Function name.
@ -206,7 +205,6 @@ pub struct CallStackFrame {
pub pos: Position, pub pos: Position,
} }
#[cfg(not(feature = "no_function"))]
impl fmt::Display for CallStackFrame { impl fmt::Display for CallStackFrame {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut fp = f.debug_tuple(&self.fn_name); let mut fp = f.debug_tuple(&self.fn_name);
@ -239,7 +237,6 @@ pub struct Debugger {
/// The current set of break-points. /// The current set of break-points.
break_points: Vec<BreakPoint>, break_points: Vec<BreakPoint>,
/// The current function call stack. /// The current function call stack.
#[cfg(not(feature = "no_function"))]
call_stack: Vec<CallStackFrame>, call_stack: Vec<CallStackFrame>,
} }
@ -260,7 +257,6 @@ impl Debugger {
Dynamic::UNIT Dynamic::UNIT
}, },
break_points: Vec::new(), break_points: Vec::new(),
#[cfg(not(feature = "no_function"))]
call_stack: Vec::new(), call_stack: Vec::new(),
} }
} }
@ -277,26 +273,17 @@ impl Debugger {
&mut self.state &mut self.state
} }
/// Get the current call stack. /// Get the current call stack.
///
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[inline(always)] #[inline(always)]
#[must_use] #[must_use]
pub fn call_stack(&self) -> &[CallStackFrame] { pub fn call_stack(&self) -> &[CallStackFrame] {
&self.call_stack &self.call_stack
} }
/// Rewind the function call stack to a particular depth. /// Rewind the function call stack to a particular depth.
///
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[inline(always)] #[inline(always)]
pub(crate) fn rewind_call_stack(&mut self, len: usize) { pub(crate) fn rewind_call_stack(&mut self, len: usize) {
self.call_stack.truncate(len); self.call_stack.truncate(len);
} }
/// Add a new frame to the function call stack. /// Add a new frame to the function call stack.
///
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[inline(always)] #[inline(always)]
pub(crate) fn push_call_stack_frame( pub(crate) fn push_call_stack_frame(
&mut self, &mut self,

View File

@ -11,12 +11,9 @@ mod target;
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
pub use chaining::{ChainArgument, ChainType}; pub use chaining::{ChainArgument, ChainType};
#[cfg(feature = "debugging")] #[cfg(feature = "debugging")]
#[cfg(not(feature = "no_function"))]
pub use debugger::CallStackFrame;
#[cfg(feature = "debugging")]
pub use debugger::{ pub use debugger::{
BreakPoint, Debugger, DebuggerCommand, DebuggerEvent, DebuggerStatus, OnDebuggerCallback, BreakPoint, CallStackFrame, Debugger, DebuggerCommand, DebuggerEvent, DebuggerStatus,
OnDebuggingInit, OnDebuggerCallback, OnDebuggingInit,
}; };
pub use eval_context::EvalContext; pub use eval_context::EvalContext;
pub use eval_state::EvalState; pub use eval_state::EvalState;