diff --git a/src/Debug.cc b/src/Debug.cc index 088913a941..1763e1b952 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -821,6 +821,10 @@ bool pre_execute_stmt(Stmt* stmt, Frame* f) { } bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, StmtFlowType* flow) { + // If the debugger isn't currently active, return true so the caller continues. + if ( ! g_policy_debug ) + return true; + // Handle the case where someone issues a "next" debugger command, // but we're at a return statement, so the next statement is in // some other function. diff --git a/src/Func.cc b/src/Func.cc index e6047df71e..2a1247d725 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -339,7 +339,8 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const { f->SetTriggerAssoc(parent->GetTriggerAssoc()); } - g_frame_stack.push_back(f.get()); // used for backtracing + if ( ! g_policy_debug ) + g_frame_stack.push_back(f.get()); // used for backtracing const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; call_stack.emplace_back(CallInfo{call_expr, this, *args}); @@ -391,7 +392,8 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const { catch ( InterpreterException& e ) { // Already reported, but now determine whether to unwind further. if ( Flavor() == FUNC_FLAVOR_FUNCTION ) { - g_frame_stack.pop_back(); + if ( ! g_policy_debug ) + g_frame_stack.pop_back(); call_stack.pop_back(); // Result not set b/c exception was thrown throw; @@ -448,7 +450,8 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const { g_trace_state.LogTrace("Function return: %s\n", d.Description()); } - g_frame_stack.pop_back(); + if ( ! g_policy_debug ) + g_frame_stack.pop_back(); return result; } diff --git a/src/Stmt.cc b/src/Stmt.cc index 9efda21df1..15d6920fa9 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -147,8 +147,10 @@ const AssertStmt* Stmt::AsAssertStmt() const { } bool Stmt::SetLocationInfo(const Location* start, const Location* end) { - if ( ! Obj::SetLocationInfo(start, end) ) - return false; + // Skip the rest of this code if the debugger isn't active or if the initial set + // failed. + if ( bool res = Obj::SetLocationInfo(start, end); ! res || ! detail::g_policy_debug ) + return res; // Update the Filemap of line number -> statement mapping for // breakpoints (Debug.h). diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 83d8f7ea63..cc075dca57 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -1052,7 +1052,8 @@ SetupResult setup(int argc, char** argv, Options* zopts) { auto [body, scope] = get_global_stmts(); StmtFlowType flow; Frame f(scope->Length(), nullptr, nullptr); - g_frame_stack.push_back(&f); + if ( ! g_policy_debug ) + g_frame_stack.push_back(&f); try { body->Exec(&f, flow); @@ -1060,7 +1061,8 @@ SetupResult setup(int argc, char** argv, Options* zopts) { reporter->FatalError("failed to execute script statements at top-level scope"); } - g_frame_stack.pop_back(); + if ( ! g_policy_debug ) + g_frame_stack.pop_back(); } clear_script_analysis();