Skip to content

Commit 85c116a

Browse files
Andi Kleenacmel
Andi Kleen
authored andcommitted
perf callchain: Make get_srcline fall back to sym+offset
When the source line is not found fall back to sym + offset. This is generally much more useful than a raw address. For this we need to pass in the symbol from the caller. For some callers it's awkward to compute, so we stay at the old behaviour. Signed-off-by: Andi Kleen <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent aaba4e1 commit 85c116a

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

tools/perf/util/annotate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
11921192
goto next;
11931193

11941194
offset = start + i;
1195-
src_line->path = get_srcline(map->dso, offset);
1195+
src_line->path = get_srcline(map->dso, offset, NULL, false);
11961196
insert_source_line(&tmp_root, src_line);
11971197

11981198
next:

tools/perf/util/callchain.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@ char *callchain_list__sym_name(struct callchain_list *cl,
819819
cl->ms.map && !cl->srcline)
820820
cl->srcline = get_srcline(cl->ms.map->dso,
821821
map__rip_2objdump(cl->ms.map,
822-
cl->ip));
822+
cl->ip),
823+
cl->ms.sym, false);
823824
if (cl->srcline)
824825
printed = scnprintf(bf, bfsize, "%s %s",
825826
cl->ms.sym->name, cl->srcline);

tools/perf/util/map.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
360360

361361
if (map && map->dso) {
362362
srcline = get_srcline(map->dso,
363-
map__rip_2objdump(map, addr));
363+
map__rip_2objdump(map, addr), NULL, true);
364364
if (srcline != SRCLINE_UNKNOWN)
365365
ret = fprintf(fp, "%s%s", prefix, srcline);
366366
free_srcline(srcline);

tools/perf/util/sort.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
291291
else {
292292
struct map *map = left->ms.map;
293293
left->srcline = get_srcline(map->dso,
294-
map__rip_2objdump(map, left->ip));
294+
map__rip_2objdump(map, left->ip),
295+
left->ms.sym, true);
295296
}
296297
}
297298
if (!right->srcline) {
@@ -300,7 +301,8 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
300301
else {
301302
struct map *map = right->ms.map;
302303
right->srcline = get_srcline(map->dso,
303-
map__rip_2objdump(map, right->ip));
304+
map__rip_2objdump(map, right->ip),
305+
right->ms.sym, true);
304306
}
305307
}
306308
return strcmp(right->srcline, left->srcline);

tools/perf/util/srcline.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "util/util.h"
99
#include "util/debug.h"
1010

11+
#include "symbol.h"
12+
1113
#ifdef HAVE_LIBBFD_SUPPORT
1214

1315
/*
@@ -250,7 +252,8 @@ void dso__free_a2l(struct dso *dso __maybe_unused)
250252
*/
251253
#define A2L_FAIL_LIMIT 123
252254

253-
char *get_srcline(struct dso *dso, unsigned long addr)
255+
char *get_srcline(struct dso *dso, unsigned long addr, struct symbol *sym,
256+
bool show_sym)
254257
{
255258
char *file = NULL;
256259
unsigned line = 0;
@@ -289,7 +292,11 @@ char *get_srcline(struct dso *dso, unsigned long addr)
289292
dso->has_srcline = 0;
290293
dso__free_a2l(dso);
291294
}
292-
if (asprintf(&srcline, "%s[%lx]", dso->short_name, addr) < 0)
295+
if (sym) {
296+
if (asprintf(&srcline, "%s+%ld", show_sym ? sym->name : "",
297+
addr - sym->start) < 0)
298+
return SRCLINE_UNKNOWN;
299+
} else if (asprintf(&srcline, "%s[%lx]", dso->short_name, addr) < 0)
293300
return SRCLINE_UNKNOWN;
294301
return srcline;
295302
}

tools/perf/util/util.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,10 @@ static inline int path__join3(char *bf, size_t size,
337337
}
338338

339339
struct dso;
340+
struct symbol;
340341

341-
char *get_srcline(struct dso *dso, unsigned long addr);
342+
char *get_srcline(struct dso *dso, unsigned long addr, struct symbol *sym,
343+
bool show_sym);
342344
void free_srcline(char *srcline);
343345

344346
int filename__read_int(const char *filename, int *value);

0 commit comments

Comments
 (0)