summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2021-08-30 11:57:46 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2021-08-30 11:57:46 +0000
commitd473331733f7a951df16118344d8f738fe66876c (patch)
tree0bd282da67fadcdff2a23485ba44d6b0023b0aca /usr.sbin
parent5d80fbcd29a00b496bf6f518f4dd14e77a791493 (diff)
Implement '<' and '>' operators in filters.
Based on a diff from and ok dv@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/btrace/bt_parse.y24
-rw-r--r--usr.sbin/btrace/bt_parser.h4
-rw-r--r--usr.sbin/btrace/btrace.c12
3 files changed, 35 insertions, 5 deletions
diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y
index c319b511437..b079c8b4a17 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.34 2021/04/22 11:53:13 mpi Exp $ */
+/* $OpenBSD: bt_parse.y,v 1.35 2021/08/30 11:57:45 mpi Exp $ */
/*
* Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
@@ -109,7 +109,8 @@ static int yylex(void);
static int pflag;
%}
-%token <v.i> ERROR ENDFILT OP_EQ OP_NE OP_LE OP_GE OP_LAND OP_LOR
+%token <v.i> ERROR ENDFILT
+%token <v.i> OP_EQ OP_NE OP_LE OP_LT OP_GE OP_GT OP_LAND OP_LOR
/* Builtins */
%token <v.i> BUILTIN BEGIN END HZ
/* Functions and Map operators */
@@ -126,7 +127,7 @@ static int pflag;
%type <v.arg> expr vargs mentry mexpr pargs term
%right '='
-%nonassoc OP_EQ OP_NE OP_LE OP_GE OP_LAND OP_LOR
+%nonassoc OP_EQ OP_NE OP_LE OP_LT OP_GE OP_GT OP_LAND OP_LOR
%left '&' '|'
%left '+' '-'
%left '/' '*'
@@ -181,7 +182,9 @@ term : '(' term ')' { $$ = $2; }
| term OP_EQ term { $$ = ba_op(B_AT_OP_EQ, $1, $3); }
| term OP_NE term { $$ = ba_op(B_AT_OP_NE, $1, $3); }
| term OP_LE term { $$ = ba_op(B_AT_OP_LE, $1, $3); }
+ | term OP_LT term { $$ = ba_op(B_AT_OP_LT, $1, $3); }
| term OP_GE term { $$ = ba_op(B_AT_OP_GE, $1, $3); }
+ | term OP_GT term { $$ = ba_op(B_AT_OP_GT, $1, $3); }
| term OP_LAND term { $$ = ba_op(B_AT_OP_LAND, $1, $3); }
| term OP_LOR term { $$ = ba_op(B_AT_OP_LOR, $1, $3); }
| term '+' term { $$ = ba_op(B_AT_OP_PLUS, $1, $3); }
@@ -723,16 +726,31 @@ again:
lgetc();
return (c == '=') ? OP_EQ : OP_NE;
}
+ return c;
+ case '<':
+ if (peek() == '=') {
+ lgetc();
+ return OP_LE;
+ }
+ return OP_LT;
+ case '>':
+ if (peek() == '=') {
+ lgetc();
+ return OP_GE;
+ }
+ return OP_GT;
case '&':
if (peek() == '&') {
lgetc();
return OP_LAND;
}
+ return c;
case '|':
if (peek() == '|') {
lgetc();
return OP_LOR;
}
+ return c;
case '/':
if (peek() == '{' || peek() == '/' || peek() == '\n') {
return ENDFILT;
diff --git a/usr.sbin/btrace/bt_parser.h b/usr.sbin/btrace/bt_parser.h
index 7ebacf6a14e..67481456a59 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.16 2021/04/22 09:36:39 mpi Exp $ */
+/* $OpenBSD: bt_parser.h,v 1.17 2021/08/30 11:57:45 mpi Exp $ */
/*
* Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
@@ -160,7 +160,9 @@ struct bt_arg {
B_AT_OP_EQ,
B_AT_OP_NE,
B_AT_OP_LE,
+ B_AT_OP_LT,
B_AT_OP_GE,
+ B_AT_OP_GT,
B_AT_OP_LAND,
B_AT_OP_LOR,
} ba_type;
diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c
index 75966f836a4..785a4ed7c69 100644
--- a/usr.sbin/btrace/btrace.c
+++ b/usr.sbin/btrace/btrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: btrace.c,v 1.38 2021/06/28 08:55:06 bluhm Exp $ */
+/* $OpenBSD: btrace.c,v 1.39 2021/08/30 11:57:45 mpi Exp $ */
/*
* Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org>
@@ -1068,9 +1068,15 @@ baexpr2long(struct bt_arg *ba, struct dt_evt *dtev)
case B_AT_OP_LE:
result = (first <= second);
break;
+ case B_AT_OP_LT:
+ result = (first < second);
+ break;
case B_AT_OP_GE:
result = (first >= second);
break;
+ case B_AT_OP_GT:
+ result = (first > second);
+ break;
case B_AT_OP_LAND:
result = (first && second);
break;
@@ -1118,8 +1124,12 @@ ba_name(struct bt_arg *ba)
return "!=";
case B_AT_OP_LE:
return "<=";
+ case B_AT_OP_LT:
+ return "<";
case B_AT_OP_GE:
return ">=";
+ case B_AT_OP_GT:
+ return ">";
case B_AT_OP_LAND:
return "&&";
case B_AT_OP_LOR: