From 3878353a7a9fb9fc4d7eafe1cb91547940393c18 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 25 Sep 2025 18:35:21 -0700 Subject: [PATCH 1/4] Disable Stmt hooks for the built-in debugger if not a debug build --- src/Stmt.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Stmt.cc b/src/Stmt.cc index 9efda21df1..08a88deee0 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -147,6 +147,7 @@ const AssertStmt* Stmt::AsAssertStmt() const { } bool Stmt::SetLocationInfo(const Location* start, const Location* end) { +#if DEBUG if ( ! Obj::SetLocationInfo(start, end) ) return false; @@ -177,6 +178,9 @@ bool Stmt::SetLocationInfo(const Location* start, const Location* end) { } return true; +#else + return Obj::SetLocationInfo(start, end); +#endif } bool Stmt::IsPure() const { return false; } @@ -436,13 +440,17 @@ ValPtr IfStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) { f->SetNextStmt(do_stmt); +#if DEBUG if ( ! pre_execute_stmt(do_stmt, f) ) { // ### Abort or something } +#endif auto result = do_stmt->Exec(f, flow); +#if DEBUG if ( ! post_execute_stmt(do_stmt, f, result.get(), &flow) ) { // ### Abort or something } +#endif return result; } @@ -1409,13 +1417,17 @@ ValPtr StmtList::Exec(Frame* f, StmtFlowType& flow) { f->SetNextStmt(stmt); +#if DEBUG if ( ! pre_execute_stmt(stmt, f) ) { // ### Abort or something } +#endif auto result = stmt->Exec(f, flow); +#if DEBUG if ( ! post_execute_stmt(stmt, f, result.get(), &flow) ) { // ### Abort or something } +#endif if ( flow != FLOW_NEXT || result || f->HasDelayed() ) return result; From 54c26f768faaee593a6a782f3e9deea93f458c2b Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 30 Sep 2025 13:05:54 -0700 Subject: [PATCH 2/4] fixup! Disable Stmt hooks for the built-in debugger if not a debug build --- src/Debug.cc | 5 +++++ src/Stmt.cc | 19 +++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Debug.cc b/src/Debug.cc index 088913a941..1c756820b3 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -25,6 +25,7 @@ #include "zeek/IntrusivePtr.h" #include "zeek/PolicyFile.h" #include "zeek/Reporter.h" +#include "zeek/RunState.h" #include "zeek/Scope.h" #include "zeek/Stmt.h" #include "zeek/Val.h" @@ -821,6 +822,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/Stmt.cc b/src/Stmt.cc index 08a88deee0..5f210013a3 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -12,6 +12,7 @@ #include "zeek/Frame.h" #include "zeek/IntrusivePtr.h" #include "zeek/Reporter.h" +#include "zeek/RunState.h" #include "zeek/Scope.h" #include "zeek/Traverse.h" #include "zeek/Trigger.h" @@ -147,9 +148,10 @@ const AssertStmt* Stmt::AsAssertStmt() const { } bool Stmt::SetLocationInfo(const Location* start, const Location* end) { -#if DEBUG - 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). @@ -178,9 +180,6 @@ bool Stmt::SetLocationInfo(const Location* start, const Location* end) { } return true; -#else - return Obj::SetLocationInfo(start, end); -#endif } bool Stmt::IsPure() const { return false; } @@ -440,17 +439,13 @@ ValPtr IfStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) { f->SetNextStmt(do_stmt); -#if DEBUG if ( ! pre_execute_stmt(do_stmt, f) ) { // ### Abort or something } -#endif auto result = do_stmt->Exec(f, flow); -#if DEBUG if ( ! post_execute_stmt(do_stmt, f, result.get(), &flow) ) { // ### Abort or something } -#endif return result; } @@ -1417,17 +1412,13 @@ ValPtr StmtList::Exec(Frame* f, StmtFlowType& flow) { f->SetNextStmt(stmt); -#if DEBUG if ( ! pre_execute_stmt(stmt, f) ) { // ### Abort or something } -#endif auto result = stmt->Exec(f, flow); -#if DEBUG if ( ! post_execute_stmt(stmt, f, result.get(), &flow) ) { // ### Abort or something } -#endif if ( flow != FLOW_NEXT || result || f->HasDelayed() ) return result; From 8ea7e0041b231927abc07f00cffecae85a825ab0 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 30 Sep 2025 16:11:02 -0700 Subject: [PATCH 3/4] Testing disabling frame tracing for performance reasons --- src/Func.cc | 9 ++++++--- src/zeek-setup.cc | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) 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/zeek-setup.cc b/src/zeek-setup.cc index 070aad5308..898ce050a6 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -1105,7 +1105,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); @@ -1113,7 +1114,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(); From 7c10b8639e0f85bbd275a9f970c51b38d0afe87a Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 30 Sep 2025 16:12:10 -0700 Subject: [PATCH 4/4] fixup! fixup! Disable Stmt hooks for the built-in debugger if not a debug build --- src/Debug.cc | 1 - src/Stmt.cc | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Debug.cc b/src/Debug.cc index 1c756820b3..1763e1b952 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -25,7 +25,6 @@ #include "zeek/IntrusivePtr.h" #include "zeek/PolicyFile.h" #include "zeek/Reporter.h" -#include "zeek/RunState.h" #include "zeek/Scope.h" #include "zeek/Stmt.h" #include "zeek/Val.h" diff --git a/src/Stmt.cc b/src/Stmt.cc index 5f210013a3..15d6920fa9 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -12,7 +12,6 @@ #include "zeek/Frame.h" #include "zeek/IntrusivePtr.h" #include "zeek/Reporter.h" -#include "zeek/RunState.h" #include "zeek/Scope.h" #include "zeek/Traverse.h" #include "zeek/Trigger.h"