Skip to content

Commit

Permalink
perf annotate: Fix handling of goto labels that are valid hex numbers
Browse files Browse the repository at this point in the history
When parsing the objdump disassembly output we can have goto labels that
are valid hex numbers and thus get confused with lines with machine
code.

Handle the common case of a label that has nothing after it and other
cases where there is just source code by validating the resulting "ip".

It is still possible that we find goto labels that are in the function
address range, but only if they are located before the real address we
should be OK.

A change in the objdump output to have a clear marker separating
addresses from the disassembly would come handy, but we would still have
to deal with older versions.

Reported-by: Gleb Natapov <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Gleb Natapov <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Jul 22, 2010
1 parent 07fca0e commit 70a7cb3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,13 +976,17 @@ static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file,
* Parse hexa addresses followed by ':'
*/
line_ip = strtoull(tmp, &tmp2, 16);
if (*tmp2 != ':' || tmp == tmp2)
if (*tmp2 != ':' || tmp == tmp2 || tmp2[1] == '\0')
line_ip = -1;
}

if (line_ip != -1) {
u64 start = map__rip_2objdump(self->ms.map, sym->start);
u64 start = map__rip_2objdump(self->ms.map, sym->start),
end = map__rip_2objdump(self->ms.map, sym->end);

offset = line_ip - start;
if (offset < 0 || (u64)line_ip > end)
offset = -1;
}

objdump_line = objdump_line__new(offset, line);
Expand Down

0 comments on commit 70a7cb3

Please sign in to comment.