From: Mathieu Desnoyers Date: Fri, 22 Sep 2017 00:13:17 +0000 (-0400) Subject: Filter: Implement rshift, lshift, bit not operators X-Git-Tag: v2.11.0-rc1~173 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=116d3c01872d62ee86bdbd0aea575b12fbc9c272;p=lttng-tools.git Filter: Implement rshift, lshift, bit not operators Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/lib/lttng-ctl/filter/filter-ast.h b/src/lib/lttng-ctl/filter/filter-ast.h index 4bf42fd3f..c5c73b69e 100644 --- a/src/lib/lttng-ctl/filter/filter-ast.h +++ b/src/lib/lttng-ctl/filter/filter-ast.h @@ -67,8 +67,8 @@ enum op_type { AST_OP_MOD, AST_OP_PLUS, AST_OP_MINUS, - AST_OP_RSHIFT, - AST_OP_LSHIFT, + AST_OP_BIT_RSHIFT, + AST_OP_BIT_LSHIFT, AST_OP_AND, AST_OP_OR, AST_OP_BIT_AND, diff --git a/src/lib/lttng-ctl/filter/filter-bytecode.h b/src/lib/lttng-ctl/filter/filter-bytecode.h index a86963f73..a0913af8b 100644 --- a/src/lib/lttng-ctl/filter/filter-bytecode.h +++ b/src/lib/lttng-ctl/filter/filter-bytecode.h @@ -71,8 +71,8 @@ enum filter_op { FILTER_OP_MOD = 4, FILTER_OP_PLUS = 5, FILTER_OP_MINUS = 6, - FILTER_OP_RSHIFT = 7, - FILTER_OP_LSHIFT = 8, + FILTER_OP_BIT_RSHIFT = 7, + FILTER_OP_BIT_LSHIFT = 8, FILTER_OP_BIT_AND = 9, FILTER_OP_BIT_OR = 10, FILTER_OP_BIT_XOR = 11, @@ -201,6 +201,8 @@ enum filter_op { FILTER_OP_LOAD_FIELD_SEQUENCE = 96, FILTER_OP_LOAD_FIELD_DOUBLE = 97, + FILTER_OP_UNARY_BIT_NOT = 98, + NR_FILTER_OPS, }; diff --git a/src/lib/lttng-ctl/filter/filter-parser.y b/src/lib/lttng-ctl/filter/filter-parser.y index 7c4aebe8d..2fa41ab40 100644 --- a/src/lib/lttng-ctl/filter/filter-parser.y +++ b/src/lib/lttng-ctl/filter/filter-parser.y @@ -588,11 +588,11 @@ shift_expression { $$ = $1; } | shift_expression LEFT_OP additive_expression { - $$ = make_op_node(parser_ctx, AST_OP_LSHIFT, $1, $3); + $$ = make_op_node(parser_ctx, AST_OP_BIT_LSHIFT, $1, $3); } | shift_expression RIGHT_OP additive_expression { - $$ = make_op_node(parser_ctx, AST_OP_RSHIFT, $1, $3); + $$ = make_op_node(parser_ctx, AST_OP_BIT_RSHIFT, $1, $3); } ; diff --git a/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c b/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c index d548da749..1ab98138e 100644 --- a/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c +++ b/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c @@ -587,6 +587,9 @@ int visit_node_unary(struct filter_parser_ctx *ctx, struct ir_op *node) case AST_UNARY_NOT: insn.op = FILTER_OP_UNARY_NOT; return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn)); + case AST_UNARY_BIT_NOT: + insn.op = FILTER_OP_UNARY_BIT_NOT; + return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn)); } } @@ -636,11 +639,11 @@ int visit_node_binary(struct filter_parser_ctx *ctx, struct ir_op *node) case AST_OP_MINUS: insn.op = FILTER_OP_MINUS; break; - case AST_OP_RSHIFT: - insn.op = FILTER_OP_RSHIFT; + case AST_OP_BIT_RSHIFT: + insn.op = FILTER_OP_BIT_RSHIFT; break; - case AST_OP_LSHIFT: - insn.op = FILTER_OP_LSHIFT; + case AST_OP_BIT_LSHIFT: + insn.op = FILTER_OP_BIT_LSHIFT; break; case AST_OP_BIT_AND: insn.op = FILTER_OP_BIT_AND; diff --git a/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c b/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c index cd7930ad5..a189c4e9b 100644 --- a/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c +++ b/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c @@ -358,6 +358,13 @@ struct ir_op *make_op_unary_not(struct ir_op *child, enum ir_side side) child, side); } +static +struct ir_op *make_op_unary_bit_not(struct ir_op *child, enum ir_side side) +{ + return make_op_unary(AST_UNARY_BIT_NOT, "~", child->signedness, + child, side); +} + static struct ir_op *make_op_binary_compare(enum op_type bin_op_type, const char *op_str, struct ir_op *left, struct ir_op *right, @@ -538,6 +545,20 @@ struct ir_op *make_op_binary_logical_or(struct ir_op *left, struct ir_op *right, return make_op_binary_logical(AST_OP_OR, "||", left, right, side); } +static +struct ir_op *make_op_binary_bitwise_rshift(struct ir_op *left, struct ir_op *right, + enum ir_side side) +{ + return make_op_binary_bitwise(AST_OP_BIT_RSHIFT, ">>", left, right, side); +} + +static +struct ir_op *make_op_binary_bitwise_lshift(struct ir_op *left, struct ir_op *right, + enum ir_side side) +{ + return make_op_binary_bitwise(AST_OP_BIT_LSHIFT, "<<", left, right, side); +} + static struct ir_op *make_op_binary_bitwise_and(struct ir_op *left, struct ir_op *right, enum ir_side side) @@ -662,13 +683,9 @@ struct ir_op *make_op(struct filter_parser_ctx *ctx, case AST_OP_MINUS: op_str = "-"; goto error_not_supported; - case AST_OP_RSHIFT: - op_str = ">>"; - goto error_not_supported; - case AST_OP_LSHIFT: - op_str = "<<"; - goto error_not_supported; + case AST_OP_BIT_RSHIFT: + case AST_OP_BIT_LSHIFT: case AST_OP_BIT_AND: case AST_OP_BIT_OR: case AST_OP_BIT_XOR: @@ -740,6 +757,12 @@ struct ir_op *make_op(struct filter_parser_ctx *ctx, case AST_OP_LE: op = make_op_binary_le(lchild, rchild, side); break; + case AST_OP_BIT_RSHIFT: + op = make_op_binary_bitwise_rshift(lchild, rchild, side); + break; + case AST_OP_BIT_LSHIFT: + op = make_op_binary_bitwise_lshift(lchild, rchild, side); + break; case AST_OP_BIT_AND: op = make_op_binary_bitwise_and(lchild, rchild, side); break; @@ -769,8 +792,6 @@ static struct ir_op *make_unary_op(struct filter_parser_ctx *ctx, struct filter_node *node, enum ir_side side) { - const char *op_str = "?"; - switch (node->u.unary_op.type) { case AST_UNARY_UNKNOWN: default: @@ -824,14 +845,21 @@ struct ir_op *make_unary_op(struct filter_parser_ctx *ctx, } case AST_UNARY_BIT_NOT: { - op_str = "~"; - goto error_not_supported; + struct ir_op *op, *child; + + child = generate_ir_recursive(ctx, node->u.unary_op.child, + side); + if (!child) + return NULL; + op = make_op_unary_bit_not(child, side); + if (!op) { + filter_free_ir_recursive(child); + return NULL; + } + return op; } } -error_not_supported: - fprintf(stderr, "[error] %s: unary operation '%s' not supported\n", - __func__, op_str); return NULL; } diff --git a/src/lib/lttng-ctl/filter/filter-visitor-xml.c b/src/lib/lttng-ctl/filter/filter-visitor-xml.c index 1e5812015..9352742a5 100644 --- a/src/lib/lttng-ctl/filter/filter-visitor-xml.c +++ b/src/lib/lttng-ctl/filter/filter-visitor-xml.c @@ -157,10 +157,10 @@ int recursive_visit_print(struct filter_node *node, FILE *stream, int indent) case AST_OP_MINUS: fprintf(stream, "\"-\""); break; - case AST_OP_RSHIFT: + case AST_OP_BIT_RSHIFT: fprintf(stream, "\">>\""); break; - case AST_OP_LSHIFT: + case AST_OP_BIT_LSHIFT: fprintf(stream, "\"<<\""); break; case AST_OP_AND: diff --git a/tests/regression/tools/filtering/test_invalid_filter b/tests/regression/tools/filtering/test_invalid_filter index 2c45ee09e..bea173407 100755 --- a/tests/regression/tools/filtering/test_invalid_filter +++ b/tests/regression/tools/filtering/test_invalid_filter @@ -25,8 +25,8 @@ EVENT_NAME="bogus" ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr" TRACE_PATH=$(mktemp -d) NUM_GLOBAL_TESTS=2 -NUM_UST_TESTS=144 -NUM_KERNEL_TESTS=144 +NUM_UST_TESTS=135 +NUM_KERNEL_TESTS=135 NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS)) source $TESTDIR/utils/utils.sh @@ -101,9 +101,6 @@ INVALID_FILTERS=( "intfield/1" "intfield+1" "intfield-1" - "intfield>>1" - "intfield<<1" - "~intfield" "1+11111-3333+1" "(1+2)*(55*666)" "1+2*55*666" diff --git a/tests/regression/tools/filtering/test_unsupported_op b/tests/regression/tools/filtering/test_unsupported_op index 7395da0dd..357e81c68 100755 --- a/tests/regression/tools/filtering/test_unsupported_op +++ b/tests/regression/tools/filtering/test_unsupported_op @@ -25,8 +25,8 @@ EVENT_NAME="bogus" ENABLE_EVENT_STDERR="/tmp/unsupported-ops-enable" TRACE_PATH=$(mktemp -d) NUM_GLOBAL_TESTS=2 -NUM_UST_TESTS=32 -NUM_KERNEL_TESTS=32 +NUM_UST_TESTS=20 +NUM_KERNEL_TESTS=20 NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS)) source $TESTDIR/utils/utils.sh @@ -93,10 +93,9 @@ plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" # Unsupported operators -OP_STR=("MUL" "DIV" "MOD" "PLUS" "MINUS" "LSHIFT" "RSHIFT" - "UNARY_BIN_NOT") +OP_STR=("MUL" "DIV" "MOD" "PLUS" "MINUS") -OP_TKN=("*" "/" "%" "+" "-" "<<" ">>" "~") +OP_TKN=("*" "/" "%" "+" "-") OP_COUNT=${#OP_STR[@]} diff --git a/tests/regression/tools/filtering/test_valid_filter b/tests/regression/tools/filtering/test_valid_filter index a916b1884..722a6f6ad 100755 --- a/tests/regression/tools/filtering/test_valid_filter +++ b/tests/regression/tools/filtering/test_valid_filter @@ -24,8 +24,8 @@ STATS_BIN="$TESTDIR/utils/babelstats.pl" SESSION_NAME="valid_filter" NR_ITER=100 NUM_GLOBAL_TESTS=2 -NUM_UST_TESTS=1002 -NUM_KERNEL_TESTS=936 +NUM_UST_TESTS=1074 +NUM_KERNEL_TESTS=1008 NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS)) source $TESTDIR/utils/utils.sh @@ -682,6 +682,42 @@ UST_FILTERS=( true_statement "0xF00F0F ^ 0xFF0F00 == 0x0F000F" + true_statement + "(1 << 1) == 2" + + true_statement + "(4 >> 1) == 2" + + true_statement + "(1 << 8) == 256" + + true_statement + "(262144 >> 16) == 4" + + true_statement + "(~0 & 0xffff) == 0xffff" + + true_statement + "(~0 & 0xffffffff) == 0xffffffff" + + true_statement + "(~0 & 0xffffffffffffffff) == 0xffffffffffffffff" + + true_statement + "-1==~0" + + true_statement + "1<<1==2" # C99 operator priority: comparator before bitwise + + has_no_event + "!(1<<1==2)" # C99 operator priority: comparator before bitwise + + true_statement + "(1 << 32) == 4294967296" + + true_statement + "(1 << 63) == 9223372036854775808" + true_statement "arrfield1[2] & 1 == 1" @@ -1107,6 +1143,42 @@ KERNEL_FILTERS=( true_statement "0xF00F0F ^ 0xFF0F00 == 0x0F000F" + true_statement + "(1 << 1) == 2" + + true_statement + "(4 >> 1) == 2" + + true_statement + "(1 << 8) == 256" + + true_statement + "(262144 >> 16) == 4" + + true_statement + "(~0 & 0xffff) == 0xffff" + + true_statement + "(~0 & 0xffffffff) == 0xffffffff" + + true_statement + "(~0 & 0xffffffffffffffff) == 0xffffffffffffffff" + + true_statement + "-1==~0" + + true_statement + "1<<1==2" # C99 operator priority: comparator before bitwise + + has_no_event + "!(1<<1==2)" # C99 operator priority: comparator before bitwise + + true_statement + "(1 << 32) == 4294967296" + + true_statement + "(1 << 63) == 9223372036854775808" + true_statement "arrfield1[2] & 1 == 1"