Commit d69afed5 authored by Vaibhav Nagarnaik's avatar Vaibhav Nagarnaik Committed by Frederic Weisbecker

parse-events: Handle invalid opcode parsing gracefully

If an invalid opcode is encountered, trace-cmd exits with an error.
Instead it can be treated as a soft error where the event's print format
is not parsed and its binary data is dumped out.

This patch adds a return value to arg_num_eval() function to indicate if
the parsing was successful. If not, then the error is considered soft
and the parsing of the offending event fails.

Cc: Michael Rubin <mrubin@google.com>
Cc: David Sharp <dhsharp@google.com>
Signed-off-by: default avatarVaibhav Nagarnaik <vnagarnaik@google.com>
Link: http://lkml.kernel.org/r/1310785241-3799-2-git-send-email-vnagarnaik@google.comSigned-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Arun Sharma <asharma@fb.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
parent 54a36258
...@@ -1915,90 +1915,120 @@ eval_type(unsigned long long val, struct print_arg *arg, int pointer) ...@@ -1915,90 +1915,120 @@ eval_type(unsigned long long val, struct print_arg *arg, int pointer)
return eval_type_str(val, arg->typecast.type, pointer); return eval_type_str(val, arg->typecast.type, pointer);
} }
static long long arg_num_eval(struct print_arg *arg) static int arg_num_eval(struct print_arg *arg, long long *val)
{ {
long long left, right; long long left, right;
long long val = 0; int ret = 1;
switch (arg->type) { switch (arg->type) {
case PRINT_ATOM: case PRINT_ATOM:
val = strtoll(arg->atom.atom, NULL, 0); *val = strtoll(arg->atom.atom, NULL, 0);
break; break;
case PRINT_TYPE: case PRINT_TYPE:
val = arg_num_eval(arg->typecast.item); ret = arg_num_eval(arg->typecast.item, val);
val = eval_type(val, arg, 0); if (!ret)
break;
*val = eval_type(*val, arg, 0);
break; break;
case PRINT_OP: case PRINT_OP:
switch (arg->op.op[0]) { switch (arg->op.op[0]) {
case '|': case '|':
left = arg_num_eval(arg->op.left); ret = arg_num_eval(arg->op.left, &left);
right = arg_num_eval(arg->op.right); if (!ret)
break;
ret = arg_num_eval(arg->op.right, &right);
if (!ret)
break;
if (arg->op.op[1]) if (arg->op.op[1])
val = left || right; *val = left || right;
else else
val = left | right; *val = left | right;
break; break;
case '&': case '&':
left = arg_num_eval(arg->op.left); ret = arg_num_eval(arg->op.left, &left);
right = arg_num_eval(arg->op.right); if (!ret)
break;
ret = arg_num_eval(arg->op.right, &right);
if (!ret)
break;
if (arg->op.op[1]) if (arg->op.op[1])
val = left && right; *val = left && right;
else else
val = left & right; *val = left & right;
break; break;
case '<': case '<':
left = arg_num_eval(arg->op.left); ret = arg_num_eval(arg->op.left, &left);
right = arg_num_eval(arg->op.right); if (!ret)
break;
ret = arg_num_eval(arg->op.right, &right);
if (!ret)
break;
switch (arg->op.op[1]) { switch (arg->op.op[1]) {
case 0: case 0:
val = left < right; *val = left < right;
break; break;
case '<': case '<':
val = left << right; *val = left << right;
break; break;
case '=': case '=':
val = left <= right; *val = left <= right;
break; break;
default: default:
die("unknown op '%s'", arg->op.op); do_warning("unknown op '%s'", arg->op.op);
ret = 0;
} }
break; break;
case '>': case '>':
left = arg_num_eval(arg->op.left); ret = arg_num_eval(arg->op.left, &left);
right = arg_num_eval(arg->op.right); if (!ret)
break;
ret = arg_num_eval(arg->op.right, &right);
if (!ret)
break;
switch (arg->op.op[1]) { switch (arg->op.op[1]) {
case 0: case 0:
val = left > right; *val = left > right;
break; break;
case '>': case '>':
val = left >> right; *val = left >> right;
break; break;
case '=': case '=':
val = left >= right; *val = left >= right;
break; break;
default: default:
die("unknown op '%s'", arg->op.op); do_warning("unknown op '%s'", arg->op.op);
ret = 0;
} }
break; break;
case '=': case '=':
left = arg_num_eval(arg->op.left); ret = arg_num_eval(arg->op.left, &left);
right = arg_num_eval(arg->op.right); if (!ret)
break;
if (arg->op.op[1] != '=') ret = arg_num_eval(arg->op.right, &right);
die("unknown op '%s'", arg->op.op); if (!ret)
break;
val = left == right; if (arg->op.op[1] != '=') {
do_warning("unknown op '%s'", arg->op.op);
ret = 0;
} else
*val = left == right;
break; break;
case '!': case '!':
left = arg_num_eval(arg->op.left); ret = arg_num_eval(arg->op.left, &left);
right = arg_num_eval(arg->op.right); if (!ret)
break;
ret = arg_num_eval(arg->op.right, &right);
if (!ret)
break;
switch (arg->op.op[1]) { switch (arg->op.op[1]) {
case '=': case '=':
val = left != right; *val = left != right;
break; break;
default: default:
die("unknown op '%s'", arg->op.op); do_warning("unknown op '%s'", arg->op.op);
ret = 0;
} }
break; break;
case '-': case '-':
...@@ -2006,12 +2036,17 @@ static long long arg_num_eval(struct print_arg *arg) ...@@ -2006,12 +2036,17 @@ static long long arg_num_eval(struct print_arg *arg)
if (arg->op.left->type == PRINT_NULL) if (arg->op.left->type == PRINT_NULL)
left = 0; left = 0;
else else
left = arg_num_eval(arg->op.left); ret = arg_num_eval(arg->op.left, &left);
right = arg_num_eval(arg->op.right); if (!ret)
val = left - right; break;
ret = arg_num_eval(arg->op.right, &right);
if (!ret)
break;
*val = left - right;
break; break;
default: default:
die("unknown op '%s'", arg->op.op); do_warning("unknown op '%s'", arg->op.op);
ret = 0;
} }
break; break;
...@@ -2020,10 +2055,11 @@ static long long arg_num_eval(struct print_arg *arg) ...@@ -2020,10 +2055,11 @@ static long long arg_num_eval(struct print_arg *arg)
case PRINT_STRING: case PRINT_STRING:
case PRINT_BSTRING: case PRINT_BSTRING:
default: default:
die("invalid eval type %d", arg->type); do_warning("invalid eval type %d", arg->type);
ret = 0;
} }
return val; return ret;
} }
static char *arg_eval (struct print_arg *arg) static char *arg_eval (struct print_arg *arg)
...@@ -2037,7 +2073,8 @@ static char *arg_eval (struct print_arg *arg) ...@@ -2037,7 +2073,8 @@ static char *arg_eval (struct print_arg *arg)
case PRINT_TYPE: case PRINT_TYPE:
return arg_eval(arg->typecast.item); return arg_eval(arg->typecast.item);
case PRINT_OP: case PRINT_OP:
val = arg_num_eval(arg); if (!arg_num_eval(arg, &val))
break;
sprintf(buf, "%lld", val); sprintf(buf, "%lld", val);
return buf; return buf;
...@@ -2079,6 +2116,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** ...@@ -2079,6 +2116,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
memset(field, 0, sizeof(*field)); memset(field, 0, sizeof(*field));
value = arg_eval(arg); value = arg_eval(arg);
if (value == NULL)
goto out_free;
field->value = strdup(value); field->value = strdup(value);
free_arg(arg); free_arg(arg);
...@@ -2090,6 +2129,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** ...@@ -2090,6 +2129,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
goto out_free; goto out_free;
value = arg_eval(arg); value = arg_eval(arg);
if (value == NULL)
goto out_free;
field->str = strdup(value); field->str = strdup(value);
free_arg(arg); free_arg(arg);
arg = NULL; arg = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment