Compare commits

..

2 commits

Author SHA1 Message Date
Tim Wojtulewicz
54c26f768f fixup! Disable Stmt hooks for the built-in debugger if not a debug build 2025-09-30 13:05:54 -07:00
Tim Wojtulewicz
3878353a7a Disable Stmt hooks for the built-in debugger if not a debug build 2025-09-30 12:48:02 -07:00
7 changed files with 13 additions and 50 deletions

View file

@ -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.

View file

@ -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();

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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