Commit graph

244 commits

Author SHA1 Message Date
Tim Wojtulewicz
7c10b8639e fixup! fixup! Disable Stmt hooks for the built-in debugger if not a debug build 2025-09-30 16:12:10 -07:00
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
Vern Paxson
34831aa7d3 fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 11:19:38 -07:00
Vern Paxson
693aa244f9 shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 11:19:31 -07:00
Vern Paxson
46d0b55417 fix line numbers associated with "if" and initialization statements 2025-08-16 14:09:32 -07:00
Tim Wojtulewicz
7a5209855f Add ODesc::Size() that returns size_t, deprecate ODesc::Len() 2025-07-25 09:13:10 -07:00
Tim Wojtulewicz
d22810e476 Add a few extra null checks, plus a missing initialization that led to a bad null check 2025-07-23 15:17:53 -07:00
Vern Paxson
5c63133226 isolate Location specifics to private class variables to enforce correct line number ordering 2025-07-08 10:39:28 +02:00
Tim Wojtulewicz
fb55c8856e Fix clang-tidy modernize-use-default-member-init warnings in headers 2025-06-23 08:35:24 -07:00
Tim Wojtulewicz
74acc30258 Fix clang-tidy bugprone-parent-virtual-call warnings 2025-05-27 11:58:27 -07:00
Arne Welzel
eb15997cc3 Merge remote-tracking branch 'origin/topic/awelzel/event-trace-mgr-destructor-fclose'
* origin/topic/awelzel/event-trace-mgr-destructor-fclose:
  btest/core: Add event-trace test
  zeek-setup: Free event_trace_mgr after generating trace
  EventTraceMgr: Rename etm to event_trace_mgr
  EventTraceMgr: Move fclose() to destructor
2025-05-19 20:02:12 +02:00
Tim Wojtulewicz
896e41c794 Remove unnecessary #includes in base files in repo 2025-05-19 09:50:23 -07:00
Arne Welzel
5bcf6bec52 EventTraceMgr: Rename etm to event_trace_mgr
Mostly to avoid having new maintainers/developers knowing about yet
another abbreviation.
2025-05-19 18:10:36 +02:00
Vern Paxson
908e8a3a27 ZAM support for keeping "assert" statements 2024-12-03 10:37:38 -07:00
Vern Paxson
05e913db1b simplified "assert" by not trying to catch messages that themselves have errors 2024-12-02 10:37:10 -08:00
Arne Welzel
ec1088c3ef Merge remote-tracking branch 'origin/topic/vern/zam-regularization'
* origin/topic/vern/zam-regularization: (33 commits)
  simpler and more robust identification of function parameters for AST profiling
  fixes to limit AST traversal in the face of recursive types
  address some script optimization compiler warnings under Linux
  fix for -O C++ construction of variable names that use multiple module namespaces
  fix for script optimization of "opaque" values that are run-time constants
  fix for script optimization of nested switch statements
  script optimization fix for complex "in" expressions in conditionals
  updates to typos allow-list reflecting ZAM regularization changes
  BTest updates for ZAM regularization changes
  convert new ZAM operations to use typed operands
  complete migration of ZAM to use only public ZVal methods
  "-O validate-ZAM" option to validate generated ZAM instructions
  internal option to suppress control-flow optimization
  exposing some functionality for greater flexibility in structuring run-time execution
  rework ZAM compilation of type switches to leverage value switches
  add tracking of control flow information
  factoring of ZAM operation specifications into separate files
  updates to ZAM operations / gen-zam regularization, other than the operations themselves
  type-checking fix for vector-of-string operations
  ZVal constructor for booleans
  ...
2024-08-16 12:10:33 +02:00
Vern Paxson
e93db75f78 fixes for script optimization of coerce-to-any expressions 2024-08-16 11:18:57 +02:00
Tim Wojtulewicz
1d4bd2c70a Remove STMT_ANY statement type 2024-08-07 11:58:21 -07:00
Vern Paxson
0aaf83e299 removing now-vestigial "add" and "delete" statements 2024-05-29 12:40:06 -07:00
Tim Wojtulewicz
9abf8ea8b7 Check for valid identifier in WhenStmt::Describe 2024-04-10 16:20:36 -07:00
Tim Wojtulewicz
9de1dd16d5 Remove variant from StdFunctionStmt
The variant ended up conflicting with std::bind, which resulted in failures
on the btest invoking it. Change back to a single function that takes a
flow, and default it to a value in Exec.
2024-03-19 09:07:45 -07:00
Tim Wojtulewicz
39890fda5e Add a method to register an event handler to a std::function via C++ 2024-03-18 16:36:25 -07:00
Vern Paxson
99f43d3c8b AST location fixes for -O gen-C++ 2024-03-08 19:09:46 +01:00
Arne Welzel
6572324b8c Stmt: Fix assert evaluating cond twice
Since 81a9745fb3, the assert condition is
evaluated twice. This leads to unexpected behavior when cond has a side
effect like publishing a message or creating a log stream or filter.

Found while using the following in ad-hoc testing code and wondering
why two messages were published.

    assert publish(Cluster::worker_topic, hello, "abc")
2024-03-04 15:30:09 +01:00
Arne Welzel
4019e9917a Stmt: Deprecate STMT_ANY
This isn't used in-tree and has been misused by some external plugins
of mine (zeekjs and zeek-perf-support) for their own Stmt subclasses.
These plugins should be updated to use the new STMT_EXTERN statement.

Handle STMT_ANY explicitly in stmt_name() for the time being
to fix #3529 until we remove STMT_ANY for good.
2024-02-06 14:40:23 +01:00
Arne Welzel
a5c941139c Stmt: Introduce STMT_EXTERN
It's currently possible for plugin's to implement their own statement
subclasses and override the Exec() implementation. This has been leveraged
by ZeekJS [1] and zeek-perf-support [2] as well as a private WASM plugin.
All of these used STMT_ANY as the tag of their own statement subclasses.

With STMT_EXTERN, we make the possibility to add external code into the AST
somewhat more supported. It's all in detail space and plugin authors have
no guarantee for stability, but it seems such a powerful extension point
that IMO we should keep it.

I'm conscious there's the broader topic how this interacts with ZAM
optimization like in-lining or rewriting of statements. However, this
already applies to the STMT_ANY usage of the mentioned plugins.

[1] https://github.com/corelight/zeekjs
[2] https://github.com/zeek/zeek-perf-support
2024-02-06 14:40:20 +01:00
Vern Paxson
e5bb63c662 fixes & enhancements to location information associated w/ AST nodes & ZAM optimization 2024-02-06 11:03:02 +01:00
Vern Paxson
b489cfc508 greater ZAM optimization of inlined function calls 2023-11-10 09:57:35 +01:00
Vern Paxson
23c08a05de descriptions of "for" statements now include their "value variable" if present 2023-11-10 09:56:51 +01:00
Dominik Charousset
cebb85b1e8 Fix unsafe and inefficient uses of copy_string
Add a new overload to `copy_string` that takes the input characters plus
size. The new overload avoids inefficient scanning of the input for the
null terminator in cases where we know the size beforehand. Furthermore,
this overload *must* be used when dealing with input character sequences
that may have no null terminator, e.g., when the input is from a
`std::string_view` object.
2023-11-03 15:25:38 +01:00
Benjamin Bannier
f5a76c1aed Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
2023-10-30 09:40:55 +01:00
Arne Welzel
cbaf43e8ea VectorVal: Embed vector_val
Similar motivation as for RecordVal, save an extra malloc/free
and pointer indirection.

This breaks the `auto& RawVec()` API which previously returned
a reference to the std::vector*. It now returns a reference
to the vector instead. It's commented as intended for internal
and compiled code, so even though it's public API,

The previous `std::vector<std::optional<ZVal>>*&` return type was also very
likely not intended (all consumers just dereference it anyhow). I'm certain
this API was never meant to modify the actual pointer value.

I've switched to explicit typing, too.
2023-09-22 21:52:52 +02:00
Arne Welzel
cea7c0ab46 ID/Stmt: Introduce INIT_SKIP and use in ForStmt
Currently, loop vars are added to a function scope's inits and
initialized upon entering a function with default values. This
applies to vector, record and table types.

This is unnecessary for variables used in for loops as they are
guaranteed to be initialized while iterating.
2023-09-08 13:05:44 +02:00
Vern Paxson
e8f4e54475 change Trigger constructor to not potentially auto-delete itself 2023-08-28 10:17:26 -07:00
Vern Paxson
81a9745fb3 "-O gen-C++" support for "assert" statements 2023-08-24 11:46:59 -07:00
Vern Paxson
3925ff4592 addressed performance and correctness issues flagged by Coverity 2023-08-15 16:07:49 -07:00
Vern Paxson
79c53c9ed6 some code simplifications and streamlining 2023-07-20 09:35:07 -07:00
Tim Wojtulewicz
f202073387 Merge remote-tracking branch 'origin/topic/vern/minor-modernization'
* origin/topic/vern/minor-modernization:
  removed use of unnecessary member variable accessors for StmtList methods
  migrated some raw pointers to smart pointers
2023-07-11 16:15:52 -07:00
Vern Paxson
fbdc5e3f29 removed use of unnecessary member variable accessors for StmtList methods 2023-07-11 16:04:30 -07:00
Vern Paxson
1b2cd0c767 migrated some raw pointers to smart pointers 2023-07-11 16:04:30 -07:00
Tim Wojtulewicz
64b78f6fb9 Use emplace_back over push_back where appropriate 2023-07-07 09:17:05 -07:00
Vern Paxson
b6b4a81e0d removal of unused functionality and some follow-on simplifications 2023-06-30 09:36:14 +02:00
Vern Paxson
1dd2270272 WhenStmt/WhenInfo restructuring in support of ZAM "when" statements 2023-06-30 09:36:14 +02:00
Vern Paxson
b6464814c9 the "Capture" struct is now a class 2023-06-30 09:36:14 +02:00
Arne Welzel
8550c691bd Stmt/Assert: Use std::move() for backtrace element 2023-06-16 12:45:39 +02:00
Arne Welzel
0b0f6e509f Stmt: Rework assertion hooks break semantics
Using break in either of the hooks allows to suppress the default reporter
error message rather than suppressing solely based on the existence of an
assertion_failure() handler.
2023-06-13 16:18:01 +02:00
Arne Welzel
25ea678626 Stmt: Introduce assert statement and related hooks
including two hooks called assertion_failure() and assertion_result() for
customization and tracking of assertion results.
2023-06-12 18:16:02 +02:00
Vern Paxson
84906171ba simplify WhenInfo and Trigger classes given removal of old capture semantics 2023-04-02 11:36:39 -07:00
Arne Welzel
bb80d80218 Stmt: Error on deprecated when/local usage
This has been around since Zeek v4.1, so it was warned about in Zeek 5.0
LTS and we could've removed it with 5.1.

Also removed merge_top_scope() from the zeek::detail namespace, it's
unused now.

Updated the when-aggregates test somehow. I'm not quite sure what had
been tested there :-/
2023-03-20 21:35:53 +01:00