Commit b99af874829cba2b30d212bc6fd31b56275ee4d2

Authored by Steven Rostedt
Committed by Ingo Molnar
1 parent 0959b8d65c

perf tools: Handle * as typecast in trace parsing

The '*' is currently only treated as a multiplication, and it
needs to be handled as a typecast pointer.

This is the version used by trace-cmd.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <20091014194358.409327875@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 1 changed file with 22 additions and 28 deletions Side-by-side Diff

tools/perf/util/trace-event-parse.c
... ... @@ -1217,8 +1217,25 @@
1217 1217  
1218 1218 right = malloc_or_die(sizeof(*right));
1219 1219  
1220   - type = process_arg(event, right, tok);
  1220 + type = read_token_item(&token);
  1221 + *tok = token;
1221 1222  
  1223 + /* could just be a type pointer */
  1224 + if ((strcmp(arg->op.op, "*") == 0) &&
  1225 + type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
  1226 + if (left->type != PRINT_ATOM)
  1227 + die("bad pointer type");
  1228 + left->atom.atom = realloc(left->atom.atom,
  1229 + sizeof(left->atom.atom) + 3);
  1230 + strcat(left->atom.atom, " *");
  1231 + *arg = *left;
  1232 + free(arg);
  1233 +
  1234 + return type;
  1235 + }
  1236 +
  1237 + type = process_arg_token(event, right, tok, type);
  1238 +
1222 1239 arg->op.right = right;
1223 1240  
1224 1241 } else if (strcmp(token, "[") == 0) {
... ... @@ -1548,7 +1565,6 @@
1548 1565 {
1549 1566 struct print_arg *item_arg;
1550 1567 enum event_type type;
1551   - int ptr_cast = 0;
1552 1568 char *token;
1553 1569  
1554 1570 type = process_arg(event, arg, &token);
1555 1571  
... ... @@ -1556,26 +1572,11 @@
1556 1572 if (type == EVENT_ERROR)
1557 1573 return EVENT_ERROR;
1558 1574  
1559   - if (type == EVENT_OP) {
1560   - /* handle the ptr casts */
1561   - if (!strcmp(token, "*")) {
1562   - /*
1563   - * FIXME: should we zapp whitespaces before ')' ?
1564   - * (may require a peek_token_item())
1565   - */
1566   - if (__peek_char() == ')') {
1567   - ptr_cast = 1;
1568   - free_token(token);
1569   - type = read_token_item(&token);
1570   - }
1571   - }
1572   - if (!ptr_cast) {
1573   - type = process_op(event, arg, &token);
  1575 + if (type == EVENT_OP)
  1576 + type = process_op(event, arg, &token);
1574 1577  
1575   - if (type == EVENT_ERROR)
1576   - return EVENT_ERROR;
1577   - }
1578   - }
  1578 + if (type == EVENT_ERROR)
  1579 + return EVENT_ERROR;
1579 1580  
1580 1581 if (test_type_token(type, token, EVENT_DELIM, (char *)")")) {
1581 1582 free_token(token);
... ... @@ -1601,13 +1602,6 @@
1601 1602 item_arg = malloc_or_die(sizeof(*item_arg));
1602 1603  
1603 1604 arg->type = PRINT_TYPE;
1604   - if (ptr_cast) {
1605   - char *old = arg->atom.atom;
1606   -
1607   - arg->atom.atom = malloc_or_die(strlen(old + 3));
1608   - sprintf(arg->atom.atom, "%s *", old);
1609   - free(old);
1610   - }
1611 1605 arg->typecast.type = arg->atom.atom;
1612 1606 arg->typecast.item = item_arg;
1613 1607 type = process_arg_token(event, item_arg, &token, type);