Add support for multiple statements in if () blocks.
authormpi <mpi@openbsd.org>
Fri, 11 Nov 2022 22:40:41 +0000 (22:40 +0000)
committermpi <mpi@openbsd.org>
Fri, 11 Nov 2022 22:40:41 +0000 (22:40 +0000)
regress/usr.sbin/btrace/if.bt
regress/usr.sbin/btrace/if.ok
usr.sbin/btrace/bt_parse.y
usr.sbin/btrace/btrace.c

index f11d67b..053801c 100644 (file)
@@ -10,3 +10,12 @@ BEGIN {
                printf("printed!\n");
        }
 }
+
+END {
+       if (42) {
+               printf("multiple ");
+               @var = 4;
+               printf("(%d) ", @var);
+               printf("statements\n");
+       }
+}
index 28bc8a9..c2d5a91 100644 (file)
@@ -1 +1,2 @@
 printed!
+multiple (4) statements
index b8d0b68..acd1253 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bt_parse.y,v 1.46 2022/04/28 21:04:24 dv Exp $        */
+/*     $OpenBSD: bt_parse.y,v 1.47 2022/11/11 22:40:41 mpi Exp $       */
 
 /*
  * Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
@@ -263,7 +263,7 @@ stmtlist: stmtlist stmtblck         { $$ = bs_append($1, $2); }
        | stmt
        ;
 
-block  : '{' stmt ';' '}'                      { $$ = $2; }
+block  : action
        | stmt ';'
        ;
 
index ad91f1b..791fd36 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: btrace.c,v 1.64 2022/11/11 10:51:39 mpi Exp $ */
+/*     $OpenBSD: btrace.c,v 1.65 2022/11/11 22:40:41 mpi Exp $ */
 
 /*
  * Copyright (c) 2019 - 2021 Martin Pieuchot <mpi@openbsd.org>
@@ -599,8 +599,16 @@ rule_eval(struct bt_rule *r, struct dt_evt *dtev)
        }
 
        SLIST_FOREACH(bs, &r->br_action, bs_next) {
-               if ((bs->bs_act == B_AC_TEST) && stmt_test(bs, dtev) == true)
-                       stmt_eval((struct bt_stmt *)bs->bs_var, dtev);
+               if ((bs->bs_act == B_AC_TEST) && stmt_test(bs, dtev) == true) {
+                       struct bt_stmt *bbs = (struct bt_stmt *)bs->bs_var;
+
+                       while (bbs != NULL) {
+                               stmt_eval(bbs, dtev);
+                               bbs = SLIST_NEXT(bbs, bs_next);
+                       }
+
+                       continue;
+               }
 
                stmt_eval(bs, dtev);
        }