Commit ce02effe authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Greg Kroah-Hartman

perf probe: Add error checks to offline probe post-processing

commit 3e96dac7 upstream.

Add error check codes on post processing and improve it for offline
probe events as:

 - post processing fails if no matched symbol found in map(-ENOENT)
   or strdup() failed(-ENOMEM).

 - Even if the symbol name is the same, it updates symbol address
   and offset.
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/148411443738.9978.4617979132625405545.stgit@devboxSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Krister Johansen <kjlx@templeofstupid.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 36497359
...@@ -618,6 +618,33 @@ static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp, ...@@ -618,6 +618,33 @@ static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp,
return ret ? : -ENOENT; return ret ? : -ENOENT;
} }
/* Adjust symbol name and address */
static int post_process_probe_trace_point(struct probe_trace_point *tp,
struct map *map, unsigned long offs)
{
struct symbol *sym;
u64 addr = tp->address + tp->offset - offs;
sym = map__find_symbol(map, addr);
if (!sym)
return -ENOENT;
if (strcmp(sym->name, tp->symbol)) {
/* If we have no realname, use symbol for it */
if (!tp->realname)
tp->realname = tp->symbol;
else
free(tp->symbol);
tp->symbol = strdup(sym->name);
if (!tp->symbol)
return -ENOMEM;
}
tp->offset = addr - sym->start;
tp->address -= offs;
return 0;
}
/* /*
* Rename DWARF symbols to ELF symbols -- gcc sometimes optimizes functions * Rename DWARF symbols to ELF symbols -- gcc sometimes optimizes functions
* and generate new symbols with suffixes such as .constprop.N or .isra.N * and generate new symbols with suffixes such as .constprop.N or .isra.N
...@@ -630,11 +657,9 @@ static int ...@@ -630,11 +657,9 @@ static int
post_process_offline_probe_trace_events(struct probe_trace_event *tevs, post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
int ntevs, const char *pathname) int ntevs, const char *pathname)
{ {
struct symbol *sym;
struct map *map; struct map *map;
unsigned long stext = 0; unsigned long stext = 0;
u64 addr; int i, ret = 0;
int i;
/* Prepare a map for offline binary */ /* Prepare a map for offline binary */
map = dso__new_map(pathname); map = dso__new_map(pathname);
...@@ -644,23 +669,14 @@ post_process_offline_probe_trace_events(struct probe_trace_event *tevs, ...@@ -644,23 +669,14 @@ post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
} }
for (i = 0; i < ntevs; i++) { for (i = 0; i < ntevs; i++) {
addr = tevs[i].point.address + tevs[i].point.offset - stext; ret = post_process_probe_trace_point(&tevs[i].point,
sym = map__find_symbol(map, addr); map, stext);
if (!sym) if (ret < 0)
continue; break;
if (!strcmp(sym->name, tevs[i].point.symbol))
continue;
/* If we have no realname, use symbol for it */
if (!tevs[i].point.realname)
tevs[i].point.realname = tevs[i].point.symbol;
else
free(tevs[i].point.symbol);
tevs[i].point.symbol = strdup(sym->name);
tevs[i].point.offset = addr - sym->start;
} }
map__put(map); map__put(map);
return 0; return ret;
} }
static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs, static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment