[PATCH 19/22] perf annotate: Resolve 'call' operands to function names

From: Arnaldo Carvalho de Melo
Date: Tue Sep 20 2016 - 16:05:03 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

Before this patch the '_raw_spin_lock_irqsave' and 'update_rq_clock' operands
were appearing just as hexadecimal numbers:

update_blocked_averages /proc/kcore
â push %r12
â push %rbx
â and $0xfffffffffffffff0,%rsp
â sub $0x40,%rsp
â add -0x662cac00(,%rdi,8),%rax
â mov %rax,%rbx
â mov %rax,%rdi
â mov %rax,0x38(%rsp)
â â callq _raw_spin_lock_irqsave
â mov %rbx,%rdi
â mov %rax,0x30(%rsp)
â â callq update_rq_clock
â mov 0x8d0(%rbx),%rax
â lea 0x8d0(%rbx),%r11

To check that all is right one can always use the 'o' hotkey and see
the original objdump -dS output, that for this case is:

update_blocked_averages /proc/kcore
âffffffff990d5489: push %r12
âffffffff990d548b: push %rbx
âffffffff990d548c: and $0xfffffffffffffff0,%rsp
âffffffff990d5490: sub $0x40,%rsp
âffffffff990d5494: add -0x662cac00(,%rdi,8),%rax
âffffffff990d549c: mov %rax,%rbx
âffffffff990d549f: mov %rax,%rdi
âffffffff990d54a2: mov %rax,0x38(%rsp)
âffffffff990d54a7: â callq 0xffffffff997eb7a0
âffffffff990d54ac: mov %rbx,%rdi
âffffffff990d54af: mov %rax,0x30(%rsp)
âffffffff990d54b4: â callq 0xffffffff990c7720
âffffffff990d54b9: mov 0x8d0(%rbx),%rax
âffffffff990d54c0: lea 0x8d0(%rbx),%r11

Use the 'h' hotkey to see a list of available hotkeys.

More work needed to cover operands for other instructions, such as 'mov',
that can resolve variable names, etc.

Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Chris Riyder <chris.ryder@xxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Hemant Kumar <hemant@xxxxxxxxxxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Markus Trippelsdorf <markus@xxxxxxxxxxxxxxx>
Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Naveen N. Rao <naveen.n.rao@xxxxxxxxxxxxxxxxxx>
Cc: Pawel Moll <pawel.moll@xxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ravi Bangoria <ravi.bangoria@xxxxxxxxxxxxxxxxxx>
Cc: Russell King <rmk+kernel@xxxxxxxxxxxxxxxx>
Cc: Taeung Song <treeze.taeung@xxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-xqgtw9mzmzcjgwkis9kiiv1p@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/annotate.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index aef841706dff..aeb5a441bd74 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -54,7 +54,7 @@ int ins__scnprintf(struct ins *ins, char *bf, size_t size,
return ins__raw_scnprintf(ins, bf, size, ops);
}

-static int call__parse(struct ins_operands *ops, struct map *map __maybe_unused)
+static int call__parse(struct ins_operands *ops, struct map *map)
{
char *endptr, *tok, *name;

@@ -84,7 +84,11 @@ static int call__parse(struct ins_operands *ops, struct map *map __maybe_unused)
indirect_call:
tok = strchr(endptr, '*');
if (tok == NULL) {
- ops->target.addr = 0;
+ struct symbol *sym = map__find_symbol(map, map->map_ip(map, ops->target.addr));
+ if (sym != NULL)
+ ops->target.name = strdup(sym->name);
+ else
+ ops->target.addr = 0;
return 0;
}

--
2.7.4