mirror of
https://github.com/torvalds/linux.git
synced 2024-11-01 04:53:36 +01:00
perf/urgent 'perf probe' fixes:
Fixes: - Show correct locations for 'perf probe' on modules (Masami Hiramatsu) - Correctly handle 'perf probe's on gcc generated functions in modules (Masami Hiramatsu) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCAAGBQJYfg3EAAoJENZQFvNTUqpAdsYP/i+1KHLJo5E6w6DErr2gBscJ gqjR6ZRPRCdj3EPUkhMZFDHRN8m3+XZjTqpbc59trhRw144eANHfYuniIaY4LcmM qHhIyhSz7mFb3WSg/zYIfetGRMMheKCUE5UraHObgY2WC0n5c/5qSB0jOawyN+fR oXn0WhdqcekHIym+P19F/BivnHQsRKQVHwcswXm/4flB87olTAkKIluvIFbQVUfY rK/o32VsDn/vb+9DZ6l9qgc6kteYPk+f/2zZ7gcjNx4Tw3zA+i1mZBErVZ1SyQau zg84AWMYTNyQN1PrjZBVVFsoF+m4QKKcV53DO2Ml4+PspmY6Bqm5bw06hXSbhOH+ QF3x3fzO7fjrAQQOXXj+UTaRyrH9e2Gxewz3McMaAZvVc/gDIAKvU0GaBpEb4Sm4 6/4QV6aTJpejP/jG68jH8/8TbrkZzuPZ6wXRm/WxPMSqGFWj08GVuuYxfBI1GXeP A1rOmo4TqNJZiA4MeakCHyHJ+59DbAYwdSgZwGXalqc288paDcvGX1kRYvs7iph8 enKErzAg+LGpIWTJdOcqk8kF7i5u6x53ACuLLR1/p1wdYEvzGWdPwmfUxpWhwVLA xseVD5bl8y/jjz1eqWu8latEAlSbsFeAUv7870T9Is70/fg6x11+V944brrtsmYK LalUTkcAqYqrzC/9nvg+ =ebMR -----END PGP SIGNATURE----- Merge tag 'perf-urgent-for-mingo-4.10-20170117' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent Pull 'perf probe' fixes from Arnaldo Carvalho de Melo <acme@redhat.com> - Show correct locations for 'perf probe' on modules (Masami Hiramatsu) - Correctly handle 'perf probe's on GCC generated functions in modules (Masami Hiramatsu) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
commit
31f5260a76
3 changed files with 72 additions and 41 deletions
|
@ -610,6 +610,33 @@ static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp,
|
|||
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
|
||||
* and generate new symbols with suffixes such as .constprop.N or .isra.N
|
||||
|
@ -622,11 +649,9 @@ static int
|
|||
post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
|
||||
int ntevs, const char *pathname)
|
||||
{
|
||||
struct symbol *sym;
|
||||
struct map *map;
|
||||
unsigned long stext = 0;
|
||||
u64 addr;
|
||||
int i;
|
||||
int i, ret = 0;
|
||||
|
||||
/* Prepare a map for offline binary */
|
||||
map = dso__new_map(pathname);
|
||||
|
@ -636,23 +661,14 @@ post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
|
|||
}
|
||||
|
||||
for (i = 0; i < ntevs; i++) {
|
||||
addr = tevs[i].point.address + tevs[i].point.offset - stext;
|
||||
sym = map__find_symbol(map, addr);
|
||||
if (!sym)
|
||||
continue;
|
||||
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;
|
||||
ret = post_process_probe_trace_point(&tevs[i].point,
|
||||
map, stext);
|
||||
if (ret < 0)
|
||||
break;
|
||||
}
|
||||
map__put(map);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
|
||||
|
@ -682,18 +698,31 @@ static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
|
||||
int ntevs, const char *module)
|
||||
static int
|
||||
post_process_module_probe_trace_events(struct probe_trace_event *tevs,
|
||||
int ntevs, const char *module,
|
||||
struct debuginfo *dinfo)
|
||||
{
|
||||
Dwarf_Addr text_offs = 0;
|
||||
int i, ret = 0;
|
||||
char *mod_name = NULL;
|
||||
struct map *map;
|
||||
|
||||
if (!module)
|
||||
return 0;
|
||||
|
||||
mod_name = find_module_name(module);
|
||||
map = get_target_map(module, false);
|
||||
if (!map || debuginfo__get_text_offset(dinfo, &text_offs, true) < 0) {
|
||||
pr_warning("Failed to get ELF symbols for %s\n", module);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mod_name = find_module_name(module);
|
||||
for (i = 0; i < ntevs; i++) {
|
||||
ret = post_process_probe_trace_point(&tevs[i].point,
|
||||
map, (unsigned long)text_offs);
|
||||
if (ret < 0)
|
||||
break;
|
||||
tevs[i].point.module =
|
||||
strdup(mod_name ? mod_name : module);
|
||||
if (!tevs[i].point.module) {
|
||||
|
@ -703,6 +732,8 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
|
|||
}
|
||||
|
||||
free(mod_name);
|
||||
map__put(map);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -760,7 +791,7 @@ arch__post_process_probe_trace_events(struct perf_probe_event *pev __maybe_unuse
|
|||
static int post_process_probe_trace_events(struct perf_probe_event *pev,
|
||||
struct probe_trace_event *tevs,
|
||||
int ntevs, const char *module,
|
||||
bool uprobe)
|
||||
bool uprobe, struct debuginfo *dinfo)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -768,7 +799,8 @@ static int post_process_probe_trace_events(struct perf_probe_event *pev,
|
|||
ret = add_exec_to_probe_trace_events(tevs, ntevs, module);
|
||||
else if (module)
|
||||
/* Currently ref_reloc_sym based probe is not for drivers */
|
||||
ret = add_module_to_probe_trace_events(tevs, ntevs, module);
|
||||
ret = post_process_module_probe_trace_events(tevs, ntevs,
|
||||
module, dinfo);
|
||||
else
|
||||
ret = post_process_kernel_probe_trace_events(tevs, ntevs);
|
||||
|
||||
|
@ -812,30 +844,27 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
|
|||
}
|
||||
}
|
||||
|
||||
debuginfo__delete(dinfo);
|
||||
|
||||
if (ntevs > 0) { /* Succeeded to find trace events */
|
||||
pr_debug("Found %d probe_trace_events.\n", ntevs);
|
||||
ret = post_process_probe_trace_events(pev, *tevs, ntevs,
|
||||
pev->target, pev->uprobes);
|
||||
pev->target, pev->uprobes, dinfo);
|
||||
if (ret < 0 || ret == ntevs) {
|
||||
pr_debug("Post processing failed or all events are skipped. (%d)\n", ret);
|
||||
clear_probe_trace_events(*tevs, ntevs);
|
||||
zfree(tevs);
|
||||
ntevs = 0;
|
||||
}
|
||||
if (ret != ntevs)
|
||||
return ret < 0 ? ret : ntevs;
|
||||
ntevs = 0;
|
||||
/* Fall through */
|
||||
}
|
||||
|
||||
debuginfo__delete(dinfo);
|
||||
|
||||
if (ntevs == 0) { /* No error but failed to find probe point. */
|
||||
pr_warning("Probe point '%s' not found.\n",
|
||||
synthesize_perf_probe_point(&pev->point));
|
||||
return -ENOENT;
|
||||
}
|
||||
/* Error path : ntevs < 0 */
|
||||
pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
|
||||
if (ntevs < 0) {
|
||||
} else if (ntevs < 0) {
|
||||
/* Error path : ntevs < 0 */
|
||||
pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
|
||||
if (ntevs == -EBADF)
|
||||
pr_warning("Warning: No dwarf info found in the vmlinux - "
|
||||
"please rebuild kernel with CONFIG_DEBUG_INFO=y.\n");
|
||||
|
|
|
@ -1501,7 +1501,8 @@ int debuginfo__find_available_vars_at(struct debuginfo *dbg,
|
|||
}
|
||||
|
||||
/* For the kernel module, we need a special code to get a DIE */
|
||||
static int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs)
|
||||
int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
|
||||
bool adjust_offset)
|
||||
{
|
||||
int n, i;
|
||||
Elf32_Word shndx;
|
||||
|
@ -1530,6 +1531,8 @@ static int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs)
|
|||
if (!shdr)
|
||||
return -ENOENT;
|
||||
*offs = shdr->sh_addr;
|
||||
if (adjust_offset)
|
||||
*offs -= shdr->sh_offset;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -1543,16 +1546,12 @@ int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
|
|||
Dwarf_Addr _addr = 0, baseaddr = 0;
|
||||
const char *fname = NULL, *func = NULL, *basefunc = NULL, *tmp;
|
||||
int baseline = 0, lineno = 0, ret = 0;
|
||||
bool reloc = false;
|
||||
|
||||
retry:
|
||||
/* We always need to relocate the address for aranges */
|
||||
if (debuginfo__get_text_offset(dbg, &baseaddr, false) == 0)
|
||||
addr += baseaddr;
|
||||
/* Find cu die */
|
||||
if (!dwarf_addrdie(dbg->dbg, (Dwarf_Addr)addr, &cudie)) {
|
||||
if (!reloc && debuginfo__get_text_offset(dbg, &baseaddr) == 0) {
|
||||
addr += baseaddr;
|
||||
reloc = true;
|
||||
goto retry;
|
||||
}
|
||||
pr_warning("Failed to find debug information for address %lx\n",
|
||||
addr);
|
||||
ret = -EINVAL;
|
||||
|
|
|
@ -46,6 +46,9 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
|
|||
int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
|
||||
struct perf_probe_point *ppt);
|
||||
|
||||
int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
|
||||
bool adjust_offset);
|
||||
|
||||
/* Find a line range */
|
||||
int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr);
|
||||
|
||||
|
|
Loading…
Reference in a new issue