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/Debug.h b/src/Debug.h index 7748beb1e5..3d256ca4a8 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -60,13 +60,7 @@ public: // Returns previous filename. FILE* SetTraceFile(const char* trace_filename); - bool DoTrace() const { -#if DEBUG - return dbgtrace; -#else - return false; -#endif - } + bool DoTrace() const { return dbgtrace; } void TraceOn(); void TraceOff(); diff --git a/src/Func.cc b/src/Func.cc index ac64d64d28..e6047df71e 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -339,9 +339,7 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const { f->SetTriggerAssoc(parent->GetTriggerAssoc()); } -#if DEBUG g_frame_stack.push_back(f.get()); // used for backtracing -#endif const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; call_stack.emplace_back(CallInfo{call_expr, this, *args}); @@ -393,9 +391,7 @@ 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 ) { -#if DEBUG g_frame_stack.pop_back(); -#endif call_stack.pop_back(); // Result not set b/c exception was thrown throw; @@ -452,9 +448,7 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const { g_trace_state.LogTrace("Function return: %s\n", d.Description()); } -#if DEBUG g_frame_stack.pop_back(); -#endif return result; } diff --git a/src/Options.cc b/src/Options.cc index 40b291f3d6..ef771cc984 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -445,15 +445,7 @@ Options parse_cmdline(int argc, char** argv) { case 'a': rval.parse_only = true; break; case 'b': rval.bare_mode = true; break; case 'c': rval.unprocessed_output_file = optarg; break; - case 'd': -#if DEBUG - rval.debug_scripts = true; - break; -#else - fprintf(stderr, "ERROR: Debugger is disabled in non-debug builds\n"); - exit(1); - break; -#endif + case 'd': rval.debug_scripts = true; break; case 'e': rval.script_code_to_exec = optarg; break; case 'f': rval.pcap_filter = optarg; break; case 'h': rval.print_usage = true; break; @@ -497,15 +489,7 @@ Options parse_cmdline(int argc, char** argv) { rval.pcap_file = optarg; break; case 's': rval.signature_files.emplace_back(optarg); break; - case 't': -#ifdef DEBUG - rval.debug_script_tracing_file = optarg; - break; -#else - fprintf(stderr, "ERROR: Script tracing is disabled in non-debug builds\n"); - exit(1); - break; -#endif + case 't': rval.debug_script_tracing_file = optarg; break; case 'u': ++rval.analysis_options.usage_issues; break; case 'v': rval.print_version = true; break; case 'V': rval.print_build_info = true; break; 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; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 119e8b1e70..070aad5308 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -1105,9 +1105,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) { auto [body, scope] = get_global_stmts(); StmtFlowType flow; Frame f(scope->Length(), nullptr, nullptr); -#ifdef DEBUG g_frame_stack.push_back(&f); -#endif try { body->Exec(&f, flow); @@ -1115,9 +1113,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) { reporter->FatalError("failed to execute script statements at top-level scope"); } -#ifdef DEBUG g_frame_stack.pop_back(); -#endif } clear_script_analysis(); diff --git a/testing/btest/spicy/file-analyzer-nested.zeek b/testing/btest/spicy/file-analyzer-nested.zeek index 35931a312c..98dccbe7f0 100644 --- a/testing/btest/spicy/file-analyzer-nested.zeek +++ b/testing/btest/spicy/file-analyzer-nested.zeek @@ -1,5 +1,4 @@ # @TEST-REQUIRES: have-spicy -# @TEST-REQUIRES: test "$($BUILD/zeek-config --build_type)" = "debug" # # @TEST-EXEC: spicyz -d -o text.hlto text.spicy ./text.evt # @TEST-EXEC: zeek -r ${TRACES}/http/post.trace text.hlto %INPUT Spicy::enable_print=T | sort -k 3 >output