From: mpi Date: Mon, 30 Aug 2021 11:57:45 +0000 (+0000) Subject: Implement '<' and '>' operators in filters. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=25efc3b062af75f14b579024470a947dc3451587;p=openbsd Implement '<' and '>' operators in filters. Based on a diff from and ok dv@ --- 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 @@ -109,7 +109,8 @@ static int yylex(void); static int pflag; %} -%token ERROR ENDFILT OP_EQ OP_NE OP_LE OP_GE OP_LAND OP_LOR +%token ERROR ENDFILT +%token OP_EQ OP_NE OP_LE OP_LT OP_GE OP_GT OP_LAND OP_LOR /* Builtins */ %token BUILTIN BEGIN END HZ /* Functions and Map operators */ @@ -126,7 +127,7 @@ static int pflag; %type 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 @@ -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 @@ -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: