From dd9124f867f9d87896201034ebb8f208c765a2f3 Mon Sep 17 00:00:00 2001 From: mpi Date: Fri, 11 Nov 2022 22:40:41 +0000 Subject: [PATCH] Add support for multiple statements in if () blocks. --- regress/usr.sbin/btrace/if.bt | 9 +++++++++ regress/usr.sbin/btrace/if.ok | 1 + usr.sbin/btrace/bt_parse.y | 4 ++-- usr.sbin/btrace/btrace.c | 14 +++++++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/regress/usr.sbin/btrace/if.bt b/regress/usr.sbin/btrace/if.bt index f11d67b645e..053801cac54 100644 --- a/regress/usr.sbin/btrace/if.bt +++ b/regress/usr.sbin/btrace/if.bt @@ -10,3 +10,12 @@ BEGIN { printf("printed!\n"); } } + +END { + if (42) { + printf("multiple "); + @var = 4; + printf("(%d) ", @var); + printf("statements\n"); + } +} diff --git a/regress/usr.sbin/btrace/if.ok b/regress/usr.sbin/btrace/if.ok index 28bc8a945d3..c2d5a91bc90 100644 --- a/regress/usr.sbin/btrace/if.ok +++ b/regress/usr.sbin/btrace/if.ok @@ -1 +1,2 @@ printed! +multiple (4) statements diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y index b8d0b68e0c0..acd12538bff 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.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 @@ -263,7 +263,7 @@ stmtlist: stmtlist stmtblck { $$ = bs_append($1, $2); } | stmt ; -block : '{' stmt ';' '}' { $$ = $2; } +block : action | stmt ';' ; diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c index ad91f1b0516..791fd368c1f 100644 --- a/usr.sbin/btrace/btrace.c +++ b/usr.sbin/btrace/btrace.c @@ -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 @@ -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); } -- 2.20.1