From e817eab93a21b67f02b737b37322f820c9496c38 Mon Sep 17 00:00:00 2001 From: dv Date: Sat, 2 Sep 2023 19:28:46 +0000 Subject: [PATCH] btrace(8): allow empty statements in probes. Allows for probes like `BEGIN {}`, in parity with bpftrace. Also fixes an incorrect syntax error parsing argN builtins in subsequent probes after an empty BEGIN block. ok mpi@ --- regress/usr.sbin/btrace/Makefile | 4 ++-- regress/usr.sbin/btrace/empty-stmts.bt | 18 ++++++++++++++++++ regress/usr.sbin/btrace/empty-stmts.ok | 0 usr.sbin/btrace/bt_parse.y | 3 ++- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 regress/usr.sbin/btrace/empty-stmts.bt create mode 100644 regress/usr.sbin/btrace/empty-stmts.ok diff --git a/regress/usr.sbin/btrace/Makefile b/regress/usr.sbin/btrace/Makefile index e1d39991082..a5b37cbab83 100644 --- a/regress/usr.sbin/btrace/Makefile +++ b/regress/usr.sbin/btrace/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.28 2023/08/28 21:23:46 dv Exp $ +# $OpenBSD: Makefile,v 1.29 2023/09/02 19:28:46 dv Exp $ BTRACE?= /usr/sbin/btrace ALLOWDT!= sysctl -n kern.allowdt 2>/dev/null @@ -14,7 +14,7 @@ BT_LANG_SCRIPTS= arithm beginend beginend-argn boolean comments delete \ BT_ARG_LANG_SCRIPTS= staticv str # scripts that use kernel probes -BT_KERN_SCRIPTS= filters mapoverwrite multiprobe +BT_KERN_SCRIPTS= empty-stmts filters mapoverwrite multiprobe REGRESS_EXPECTED_FAILURES= run-maxoperand diff --git a/regress/usr.sbin/btrace/empty-stmts.bt b/regress/usr.sbin/btrace/empty-stmts.bt new file mode 100644 index 00000000000..87cd947d5e8 --- /dev/null +++ b/regress/usr.sbin/btrace/empty-stmts.bt @@ -0,0 +1,18 @@ +// Test support for empty statement lists. +BEGIN +{ + exit(); +} + +syscall:open:return +{ +} + +syscall:close:return +/comm != "ksh"/ +{ +} + +END +{ +} \ No newline at end of file diff --git a/regress/usr.sbin/btrace/empty-stmts.ok b/regress/usr.sbin/btrace/empty-stmts.ok new file mode 100644 index 00000000000..e69de29bb2d diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y index b2c3bef3b80..b2c3e65854b 100644 --- a/usr.sbin/btrace/bt_parse.y +++ b/usr.sbin/btrace/bt_parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_parse.y,v 1.51 2023/08/28 21:23:46 dv Exp $ */ +/* $OpenBSD: bt_parse.y,v 1.52 2023/09/02 19:28:46 dv Exp $ */ /* * Copyright (c) 2019-2021 Martin Pieuchot @@ -266,6 +266,7 @@ block : action ; action : '{' stmtlist '}' { $$ = $2; } + | '{' '}' { $$ = NULL; } ; %% -- 2.20.1