Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf map: Add map__objdump_2rip()

Sometimes we want to convert an address in objdump output to
map-relative address to match with a sample data. Let's add
map__objdump_2rip() for that.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240319055115.4063940-6-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
52a09bc2 7a838c2f

+20
+17
tools/perf/util/map.c
··· 587 587 return ip + map__reloc(map); 588 588 } 589 589 590 + /* convert objdump address to relative address. (To be removed) */ 591 + u64 map__objdump_2rip(struct map *map, u64 ip) 592 + { 593 + const struct dso *dso = map__dso(map); 594 + 595 + if (!dso->adjust_symbols) 596 + return ip; 597 + 598 + if (dso->rel) 599 + return ip + map__pgoff(map); 600 + 601 + if (dso->kernel == DSO_SPACE__USER) 602 + return ip - dso->text_offset; 603 + 604 + return map__map_ip(map, ip + map__reloc(map)); 605 + } 606 + 590 607 bool map__contains_symbol(const struct map *map, const struct symbol *sym) 591 608 { 592 609 u64 ip = map__unmap_ip(map, sym->start);
+3
tools/perf/util/map.h
··· 132 132 /* objdump address -> memory address */ 133 133 u64 map__objdump_2mem(struct map *map, u64 ip); 134 134 135 + /* objdump address -> rip */ 136 + u64 map__objdump_2rip(struct map *map, u64 ip); 137 + 135 138 struct symbol; 136 139 struct thread; 137 140