perf map: Add map__objdump_2rip()
authorNamhyung Kim <namhyung@kernel.org>
Tue, 19 Mar 2024 05:50:57 +0000 (22:50 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 21 Mar 2024 13:41:28 +0000 (10:41 -0300)
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>
tools/perf/util/map.c
tools/perf/util/map.h

index 14a5ea70d81e114366b1e1d16697be437dea6d12..a5d57c201a30c9633b028c6fc8ca6c97ea9785e8 100644 (file)
@@ -587,6 +587,23 @@ u64 map__objdump_2mem(struct map *map, u64 ip)
        return ip + map__reloc(map);
 }
 
+/* convert objdump address to relative address.  (To be removed) */
+u64 map__objdump_2rip(struct map *map, u64 ip)
+{
+       const struct dso *dso = map__dso(map);
+
+       if (!dso->adjust_symbols)
+               return ip;
+
+       if (dso->rel)
+               return ip + map__pgoff(map);
+
+       if (dso->kernel == DSO_SPACE__USER)
+               return ip - dso->text_offset;
+
+       return map__map_ip(map, ip + map__reloc(map));
+}
+
 bool map__contains_symbol(const struct map *map, const struct symbol *sym)
 {
        u64 ip = map__unmap_ip(map, sym->start);
index 49756716cb132790f3cb9d9c2511fc73c9a294ba..65e2609fa1b1adc65ce322dc029fd38e0efb9288 100644 (file)
@@ -132,6 +132,9 @@ u64 map__rip_2objdump(struct map *map, u64 rip);
 /* objdump address -> memory address */
 u64 map__objdump_2mem(struct map *map, u64 ip);
 
+/* objdump address -> rip */
+u64 map__objdump_2rip(struct map *map, u64 ip);
+
 struct symbol;
 struct thread;