Merge remote-tracking branch 'origin/topic/timw/4553-debugger-stmts'
Some checks are pending
pre-commit / pre-commit (push) Waiting to run

* origin/topic/timw/4553-debugger-stmts:
  Add versions of IfStmt and StmtList for use in debugger
This commit is contained in:
Tim Wojtulewicz 2025-10-10 10:46:09 -07:00
commit d75a7b7be6
5 changed files with 83 additions and 20 deletions

View file

@ -1,3 +1,7 @@
8.1.0-dev.666 | 2025-10-10 10:46:09 -0700
* Add versions of IfStmt and StmtList for use in debugger (Tim Wojtulewicz, Corelight)
8.1.0-dev.664 | 2025-10-10 09:19:40 -0700 8.1.0-dev.664 | 2025-10-10 09:19:40 -0700
* Skip setting tm_gmtoff on Windows (Tim Wojtulewicz, Corelight) * Skip setting tm_gmtoff on Windows (Tim Wojtulewicz, Corelight)

View file

@ -1 +1 @@
8.1.0-dev.664 8.1.0-dev.666

View file

@ -436,15 +436,7 @@ ValPtr IfStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
f->SetNextStmt(do_stmt); f->SetNextStmt(do_stmt);
if ( ! pre_execute_stmt(do_stmt, f) ) { // ### Abort or something return do_stmt->Exec(f, flow);
}
auto result = do_stmt->Exec(f, flow);
if ( ! post_execute_stmt(do_stmt, f, result.get(), &flow) ) { // ### Abort or something
}
return result;
} }
bool IfStmt::IsPure() const { return e->IsPure() && s1->IsPure() && s2->IsPure(); } bool IfStmt::IsPure() const { return e->IsPure() && s1->IsPure() && s2->IsPure(); }
@ -488,6 +480,23 @@ TraversalCode IfStmt::Traverse(TraversalCallback* cb) const {
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
ValPtr DebugIfStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
// Treat 0 as false, but don't require 1 for true.
Stmt* do_stmt = v->IsZero() ? s2.get() : s1.get();
f->SetNextStmt(do_stmt);
if ( ! pre_execute_stmt(do_stmt, f) ) { // ### Abort or something
}
auto result = do_stmt->Exec(f, flow);
if ( ! post_execute_stmt(do_stmt, f, result.get(), &flow) ) { // ### Abort or something
}
return result;
}
static StmtTag get_last_stmt_tag(const Stmt* stmt) { static StmtTag get_last_stmt_tag(const Stmt* stmt) {
if ( ! stmt ) if ( ! stmt )
return STMT_NULL; return STMT_NULL;
@ -1409,14 +1418,8 @@ ValPtr StmtList::Exec(Frame* f, StmtFlowType& flow) {
f->SetNextStmt(stmt); f->SetNextStmt(stmt);
if ( ! pre_execute_stmt(stmt, f) ) { // ### Abort or something
}
auto result = stmt->Exec(f, flow); auto result = stmt->Exec(f, flow);
if ( ! post_execute_stmt(stmt, f, result.get(), &flow) ) { // ### Abort or something
}
if ( flow != FLOW_NEXT || result || f->HasDelayed() ) if ( flow != FLOW_NEXT || result || f->HasDelayed() )
return result; return result;
} }
@ -1469,6 +1472,30 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const {
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
ValPtr DebugStmtList::Exec(Frame* f, StmtFlowType& flow) {
RegisterAccess();
flow = FLOW_NEXT;
for ( const auto& stmt_ptr : stmts ) {
auto stmt = stmt_ptr.get();
f->SetNextStmt(stmt);
if ( ! pre_execute_stmt(stmt, f) ) { // ### Abort or something
}
auto result = stmt->Exec(f, flow);
if ( ! post_execute_stmt(stmt, f, result.get(), &flow) ) { // ### Abort or something
}
if ( flow != FLOW_NEXT || result || f->HasDelayed() )
return result;
}
return nullptr;
}
InitStmt::InitStmt(std::vector<IDPtr> arg_inits) : Stmt(STMT_INIT) { InitStmt::InitStmt(std::vector<IDPtr> arg_inits) : Stmt(STMT_INIT) {
inits = std::move(arg_inits); inits = std::move(arg_inits);

View file

@ -102,7 +102,7 @@ protected:
ExprPtr e; ExprPtr e;
}; };
class IfStmt final : public ExprStmt { class IfStmt : public ExprStmt {
public: public:
IfStmt(ExprPtr test, StmtPtr s1, StmtPtr s2); IfStmt(ExprPtr test, StmtPtr s1, StmtPtr s2);
~IfStmt() override; ~IfStmt() override;
@ -135,6 +135,15 @@ protected:
StmtPtr s2; StmtPtr s2;
}; };
class DebugIfStmt final : public IfStmt {
public:
DebugIfStmt(ExprPtr test, StmtPtr s1, StmtPtr s2) : IfStmt(test, s1, s2) {}
~DebugIfStmt() override = default;
protected:
ValPtr DoExec(Frame* f, Val* v, StmtFlowType& flow) override;
};
class Case final : public Obj { class Case final : public Obj {
public: public:
Case(ListExprPtr c, IDPList* types, StmtPtr arg_s); Case(ListExprPtr c, IDPList* types, StmtPtr arg_s);
@ -452,6 +461,14 @@ protected:
void ResetStmts(std::vector<StmtPtr> new_stmts) { stmts = std::move(new_stmts); } void ResetStmts(std::vector<StmtPtr> new_stmts) { stmts = std::move(new_stmts); }
}; };
class DebugStmtList : public StmtList {
public:
DebugStmtList() = default;
~DebugStmtList() override = default;
ValPtr Exec(Frame* f, StmtFlowType& flow) override;
};
class InitStmt final : public Stmt { class InitStmt final : public Stmt {
public: public:
explicit InitStmt(std::vector<IDPtr> arg_inits); explicit InitStmt(std::vector<IDPtr> arg_inits);

View file

@ -163,6 +163,10 @@ static int func_hdr_cond_epoch = 0;
EnumType* cur_enum_type = nullptr; EnumType* cur_enum_type = nullptr;
static ID* cur_decl_type_id = nullptr; static ID* cur_decl_type_id = nullptr;
namespace zeek::detail {
extern bool g_policy_debug;
}
static void parse_new_enum(void) { static void parse_new_enum(void) {
// Starting a new enum definition. // Starting a new enum definition.
assert(cur_enum_type == nullptr); assert(cur_enum_type == nullptr);
@ -1843,6 +1847,9 @@ stmt:
{ {
reject_directive($5); reject_directive($5);
set_location(@1, @4); set_location(@1, @4);
if ( g_policy_debug )
$$ = new DebugIfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive<NullStmt>());
else
$$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive<NullStmt>()); $$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive<NullStmt>());
script_coverage_mgr.AddStmt($$); script_coverage_mgr.AddStmt($$);
} }
@ -1852,6 +1859,9 @@ stmt:
reject_directive($5); reject_directive($5);
reject_directive($7); reject_directive($7);
set_location(@1, @4); set_location(@1, @4);
if ( g_policy_debug )
$$ = new DebugIfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7});
else
$$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7}); $$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7});
script_coverage_mgr.AddStmt($$); script_coverage_mgr.AddStmt($$);
} }
@ -1976,7 +1986,12 @@ stmt_list:
$1->UpdateLocationEndInfo(@2); $1->UpdateLocationEndInfo(@2);
} }
| |
{ $$ = new StmtList(); } {
if ( g_policy_debug )
$$ = new DebugStmtList();
else
$$ = new StmtList();
}
; ;
event: event: