From c30f7879497c77863437a95f3e685790748b178a Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 10 Jan 2021 13:19:59 -0800 Subject: [PATCH 01/30] removed unused EventBodyList subclass --- src/Stmt.cc | 58 ----------------------------------------------------- src/Stmt.h | 18 ----------------- 2 files changed, 76 deletions(-) diff --git a/src/Stmt.cc b/src/Stmt.cc index 6211ff507d..58c1d712f8 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1655,64 +1655,6 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -ValPtr EventBodyList::Exec(Frame* f, StmtFlowType& flow) const - { - RegisterAccess(); - flow = FLOW_NEXT; - - for ( const auto& stmt : stmts ) - { - f->SetNextStmt(stmt); - - // Ignore the return value, since there shouldn't be - // any; and ignore the flow, since we still execute - // all of the event bodies even if one of them does - // a FLOW_RETURN. - 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 - } - } - - // Simulate a return so the hooks operate properly. - StmtFlowType ft = FLOW_RETURN; - (void) post_execute_stmt(f->GetNextStmt(), f, nullptr, &ft); - - return nullptr; - } - -void EventBodyList::StmtDescribe(ODesc* d) const - { - if ( d->IsReadable() && stmts.length() > 0 ) - { - for ( const auto& stmt : stmts ) - { - if ( ! d->IsBinary() ) - { - d->Add("{"); - d->PushIndent(); - stmt->AccessStats(d); - } - - stmt->Describe(d); - - if ( ! d->IsBinary() ) - { - d->Add("}"); - d->PopIndent(); - } - } - } - - else - StmtList::StmtDescribe(d); - } - InitStmt::InitStmt(std::vector arg_inits) : Stmt(STMT_INIT) { inits = std::move(arg_inits); diff --git a/src/Stmt.h b/src/Stmt.h index 7bb9edecf2..c72dcad196 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -372,23 +372,6 @@ protected: StmtPList stmts; }; -class EventBodyList final : public StmtList { -public: - EventBodyList() : StmtList() - { topmost = false; tag = STMT_EVENT_BODY_LIST; } - - ValPtr Exec(Frame* f, StmtFlowType& flow) const override; - - void StmtDescribe(ODesc* d) const override; - - // "Topmost" means that this is the main body of a function or event. - // void SetTopmost(bool is_topmost) { topmost = is_topmost; } - // bool IsTopmost() { return topmost; } - -protected: - bool topmost; -}; - class InitStmt final : public Stmt { public: explicit InitStmt(std::vector arg_inits); @@ -474,7 +457,6 @@ using BreakStmt [[deprecated("Remove in v4.1. Use zeek::detail::BreakStmt instea using FallthroughStmt [[deprecated("Remove in v4.1. Use zeek::detail::FallthroughStmt instead.")]] = zeek::detail::FallthroughStmt; using ReturnStmt [[deprecated("Remove in v4.1. Use zeek::detail::ReturnStmt instead.")]] = zeek::detail::ReturnStmt; using StmtList [[deprecated("Remove in v4.1. Use zeek::detail::StmtList instead.")]] = zeek::detail::StmtList; -using EventBodyList [[deprecated("Remove in v4.1. Use zeek::detail::EventBodyList instead.")]] = zeek::detail::EventBodyList; using InitStmt [[deprecated("Remove in v4.1. Use zeek::detail::InitStmt instead.")]] = zeek::detail::InitStmt; using NullStmt [[deprecated("Remove in v4.1. Use zeek::detail::NullStmt instead.")]] = zeek::detail::NullStmt; using WhenStmt [[deprecated("Remove in v4.1. Use zeek::detail::WhenStmt instead.")]] = zeek::detail::WhenStmt; From 63502e655f29d10b2315e851be5b2ff099753049 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 10 Jan 2021 13:22:23 -0800 Subject: [PATCH 02/30] convenience function for accessing object descriptions --- src/Desc.cc | 13 +++++++++++++ src/Desc.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/Desc.cc b/src/Desc.cc index f23c1d5e00..dc8c39b848 100644 --- a/src/Desc.cc +++ b/src/Desc.cc @@ -427,4 +427,17 @@ bool ODesc::FindType(const Type* type) return false; } + +std::string obj_desc(const Obj* o) + { + static ODesc d; + + d.Clear(); + o->Describe(&d); + d.SP(); + o->GetLocationInfo()->Describe(&d); + + return std::string(d.Description()); + } + } // namespace zeek diff --git a/src/Desc.h b/src/Desc.h index 8711e2c4f9..54cf79e60d 100644 --- a/src/Desc.h +++ b/src/Desc.h @@ -210,6 +210,13 @@ protected: std::set encountered_types; }; +// Returns a string representation of an object's description. Used for +// debugging and error messages. takes a bare pointer rather than an +// IntrusivePtr because the latter is harder to deal with when making +// calls from a debugger like lldb, which is the main use of this function. +class Obj; +extern std::string obj_desc(const Obj* o); + } // namespace zeek using BroFile [[deprecated("Remove in v4.1. Use zeek::File.")]] = zeek::File; From 8f001062bf713f153ee9a827d754c669aa57647f Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 10 Jan 2021 13:25:01 -0800 Subject: [PATCH 03/30] support for rewriting script function bodies --- src/Func.cc | 15 +++++++++++++++ src/Func.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/Func.cc b/src/Func.cc index 7a120e0538..5233074630 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -503,6 +503,21 @@ void ScriptFunc::AddBody(StmtPtr new_body, sort(bodies.begin(), bodies.end()); } +void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body) + { + bool found_it = false; + + for ( auto& body : bodies ) + if ( body.stmts.get() == old_body.get() ) + { + body.stmts = new_body; + found_it = true; + } + + ASSERT(found_it); + current_body = new_body; + } + void ScriptFunc::AddClosure(IDPList ids, Frame* f) { if ( ! f ) diff --git a/src/Func.h b/src/Func.h index 191a766218..7d9a9686ff 100644 --- a/src/Func.h +++ b/src/Func.h @@ -196,6 +196,11 @@ public: const std::vector& new_inits, size_t new_frame_size, int priority) override; + // Replace the given current instance of a function body with + // a new one. + void ReplaceBody(const detail::StmtPtr& old_body, + detail::StmtPtr new_body); + StmtPtr CurrentBody() const { return current_body; } /** From 77e9610086d7d4b99482c529c24607bc1d063c75 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 10 Jan 2021 13:29:05 -0800 Subject: [PATCH 04/30] options relating to script transformation: activation, dumping, selecting only a single function (for debugging) --- src/Options.cc | 29 ++++++++++++++++++++++++----- src/script_opt/ScriptOpt.h | 11 +++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Options.cc b/src/Options.cc index b3ce952ac5..b7382716dc 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -106,6 +106,7 @@ void usage(const char* prog, int code) fprintf(stderr, " -I|--print-id | print out given ID\n"); fprintf(stderr, " -N|--print-plugins | print available plugins and exit (-NN for verbose)\n"); fprintf(stderr, " -O|--optimize[=