btrace(8): allow empty statements in probes.
authordv <dv@openbsd.org>
Sat, 2 Sep 2023 19:28:46 +0000 (19:28 +0000)
committerdv <dv@openbsd.org>
Sat, 2 Sep 2023 19:28:46 +0000 (19:28 +0000)
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
regress/usr.sbin/btrace/empty-stmts.bt [new file with mode: 0644]
regress/usr.sbin/btrace/empty-stmts.ok [new file with mode: 0644]
usr.sbin/btrace/bt_parse.y

index e1d3999..a5b37cb 100644 (file)
@@ -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 (file)
index 0000000..87cd947
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
index b2c3bef..b2c3e65 100644 (file)
@@ -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 <mpi@openbsd.org>
@@ -266,6 +266,7 @@ block       : action
        ;
 
 action : '{' stmtlist '}'              { $$ = $2; }
+       | '{' '}'                       { $$ = NULL; }
        ;
 
 %%