summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/usr.sbin/btrace/Makefile6
-rw-r--r--regress/usr.sbin/btrace/boolean.bt8
-rw-r--r--regress/usr.sbin/btrace/boolean.ok2
-rw-r--r--usr.sbin/btrace/bt_parse.y12
-rw-r--r--usr.sbin/btrace/bt_parser.h4
-rw-r--r--usr.sbin/btrace/btrace.c16
6 files changed, 38 insertions, 10 deletions
diff --git a/regress/usr.sbin/btrace/Makefile b/regress/usr.sbin/btrace/Makefile
index d1de80160fd..4ac760a3605 100644
--- a/regress/usr.sbin/btrace/Makefile
+++ b/regress/usr.sbin/btrace/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.4 2020/03/19 15:53:09 mpi Exp $
+# $OpenBSD: Makefile,v 1.5 2020/09/14 18:45:19 jasper Exp $
BTRACE?= /usr/sbin/btrace
# scripts that don't need /dev/dt
-BT_LANG_SCRIPTS= arithm beginend comments delete exit map map-unnamed \
- maxoperand min+max+sum multismts nsecs+var
+BT_LANG_SCRIPTS= arithm beginend boolean comments delete exit map \
+ map-unnamed maxoperand min+max+sum multismts nsecs+var
BT_KERN_SCRIPTS=
diff --git a/regress/usr.sbin/btrace/boolean.bt b/regress/usr.sbin/btrace/boolean.bt
new file mode 100644
index 00000000000..4de756f9187
--- /dev/null
+++ b/regress/usr.sbin/btrace/boolean.bt
@@ -0,0 +1,8 @@
+BEGIN
+{
+ @a = 9;
+ @b = 1;
+
+ printf("a & b = %d\n", @a & @b);
+ printf("a | b = %d\n", @a | @b);
+}
diff --git a/regress/usr.sbin/btrace/boolean.ok b/regress/usr.sbin/btrace/boolean.ok
new file mode 100644
index 00000000000..68b70a4e3fc
--- /dev/null
+++ b/regress/usr.sbin/btrace/boolean.ok
@@ -0,0 +1,2 @@
+a & b = 1
+a | b = 9
diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y
index 52962cd1ff0..6c73db4730d 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.16 2020/07/11 14:52:14 mpi Exp $ */
+/* $OpenBSD: bt_parse.y,v 1.17 2020/09/14 18:45:19 jasper Exp $ */
/*
* Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org>
@@ -117,6 +117,8 @@ static int yylex(void);
%type <v.arg> expr vargs map mexpr term
%type <v.rtype> beginend
+%left '|'
+%left '&'
%left '+' '-'
%left '/' '*'
%%
@@ -172,6 +174,8 @@ term : '(' term ')' { $$ = $2; }
| term '-' term { $$ = ba_op('-', $1, $3); }
| term '/' term { $$ = ba_op('/', $1, $3); }
| term '*' term { $$ = ba_op('*', $1, $3); }
+ | term '&' term { $$ = ba_op('&', $1, $3); }
+ | term '|' term { $$ = ba_op('|', $1, $3); }
| NUMBER { $$ = ba_new($1, B_AT_LONG); }
| builtin { $$ = ba_new(NULL, $1); }
| gvar { $$ = bv_get($1); }
@@ -332,6 +336,12 @@ ba_op(const char op, struct bt_arg *da0, struct bt_arg *da1)
case '/':
type = B_AT_OP_DIVIDE;
break;
+ case '&':
+ type = B_AT_OP_AND;
+ break;
+ case '|':
+ type = B_AT_OP_OR;
+ break;
default:
assert(0);
}
diff --git a/usr.sbin/btrace/bt_parser.h b/usr.sbin/btrace/bt_parser.h
index f1c710a5071..cdde6eb6e4f 100644
--- a/usr.sbin/btrace/bt_parser.h
+++ b/usr.sbin/btrace/bt_parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bt_parser.h,v 1.9 2020/08/13 11:29:39 mpi Exp $ */
+/* $OpenBSD: bt_parser.h,v 1.10 2020/09/14 18:45:19 jasper Exp $ */
/*
* Copyright (c) 2019-2020 Martin Pieuchot <mpi@openbsd.org>
@@ -143,6 +143,8 @@ struct bt_arg {
B_AT_OP_MINUS,
B_AT_OP_MULT,
B_AT_OP_DIVIDE,
+ B_AT_OP_AND,
+ B_AT_OP_OR,
} ba_type;
};
diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c
index 3c7e44230cf..7b77ceb1366 100644
--- a/usr.sbin/btrace/btrace.c
+++ b/usr.sbin/btrace/btrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: btrace.c,v 1.24 2020/09/11 08:16:15 mpi Exp $ */
+/* $OpenBSD: btrace.c,v 1.25 2020/09/14 18:45:19 jasper Exp $ */
/*
* Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org>
@@ -812,7 +812,7 @@ stmt_store(struct bt_stmt *bs, struct dt_evt *dtev)
case B_AT_BI_NSECS:
bv->bv_value = ba_new(builtin_nsecs(dtev), B_AT_LONG);
break;
- case B_AT_OP_ADD ... B_AT_OP_DIVIDE:
+ case B_AT_OP_ADD ... B_AT_OP_OR:
bv->bv_value = ba_new(ba2long(ba, dtev), B_AT_LONG);
break;
default:
@@ -992,6 +992,12 @@ baexpr2long(struct bt_arg *ba, struct dt_evt *dtev)
case B_AT_OP_DIVIDE:
result = first / second;
break;
+ case B_AT_OP_AND:
+ result = first & second;
+ break;
+ case B_AT_OP_OR:
+ result = first | second;
+ break;
default:
xabort("unsuported operation %d", ba->ba_type);
}
@@ -1025,7 +1031,7 @@ ba2long(struct bt_arg *ba, struct dt_evt *dtev)
case B_AT_BI_RETVAL:
val = dtev->dtev_sysretval[0];
break;
- case B_AT_OP_ADD ... B_AT_OP_DIVIDE:
+ case B_AT_OP_ADD ... B_AT_OP_OR:
val = baexpr2long(ba, dtev);
break;
default:
@@ -1093,7 +1099,7 @@ ba2str(struct bt_arg *ba, struct dt_evt *dtev)
case B_AT_VAR:
str = ba2str(ba_read(ba), dtev);
break;
- case B_AT_OP_ADD ... B_AT_OP_DIVIDE:
+ case B_AT_OP_ADD ... B_AT_OP_OR:
snprintf(buf, sizeof(buf) - 1, "%ld", ba2long(ba, dtev));
str = buf;
break;
@@ -1152,7 +1158,7 @@ ba2dtflags(struct bt_arg *ba)
case B_AT_MF_MAX:
case B_AT_MF_MIN:
case B_AT_MF_SUM:
- case B_AT_OP_ADD ... B_AT_OP_DIVIDE:
+ case B_AT_OP_ADD ... B_AT_OP_OR:
break;
default:
xabort("invalid argument type %d", ba->ba_type);