diff options
| author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2014-02-06 00:32:20 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-02-18 07:34:51 -0500 |
| commit | 8f33f7deac485a61f38aa690b85489322a4d958e (patch) | |
| tree | 7b04900ac991f0022cdfcd3f4fdda8fccf7bb485 /tools/perf | |
| parent | f90acac75713cc6f18a4b2f1b9162bc1cd893c20 (diff) | |
perf probe: Show appropriate symbol for ref_reloc_sym based kprobes
Show appropriate symbol for ref_reloc_sym based kprobes instead of
refpoint+offset when perf-probe -l runs without debuginfo.
Without this change:
# ./perf probe -l
probe:t_show (on _stext+889880 with m v)
probe:t_show_1 (on _stext+928568 with m v t)
probe:t_show_2 (on _stext+969512 with m v fmt)
probe:t_show_3 (on _stext+1001416 with m v file)
With this change:
# ./perf probe -l
probe:t_show (on t_show with m v)
probe:t_show_1 (on t_show with m v t)
probe:t_show_2 (on t_show with m v fmt)
probe:t_show_3 (on t_show with m v file)
Changes from v2:
- Check ref_reloc_sym to find correct unrelocated address.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: "David A. Long" <dave.long@linaro.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: yrl.pp-manager.tt@hitachi.com
Link: http://lkml.kernel.org/r/20140206053220.29635.81819.stgit@kbuild-fedora.yrl.intra.hitachi.co.jp
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
| -rw-r--r-- | tools/perf/util/probe-event.c | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 8e34c8d47813..f86820c39ea4 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
| @@ -121,6 +121,42 @@ static struct symbol *__find_kernel_function_by_name(const char *name, | |||
| 121 | NULL); | 121 | NULL); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | static struct symbol *__find_kernel_function(u64 addr, struct map **mapp) | ||
| 125 | { | ||
| 126 | return machine__find_kernel_function(host_machine, addr, mapp, NULL); | ||
| 127 | } | ||
| 128 | |||
| 129 | static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void) | ||
| 130 | { | ||
| 131 | /* kmap->ref_reloc_sym should be set if host_machine is initialized */ | ||
| 132 | struct kmap *kmap; | ||
| 133 | |||
| 134 | if (map__load(host_machine->vmlinux_maps[MAP__FUNCTION], NULL) < 0) | ||
| 135 | return NULL; | ||
| 136 | |||
| 137 | kmap = map__kmap(host_machine->vmlinux_maps[MAP__FUNCTION]); | ||
| 138 | return kmap->ref_reloc_sym; | ||
| 139 | } | ||
| 140 | |||
| 141 | static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc) | ||
| 142 | { | ||
| 143 | struct ref_reloc_sym *reloc_sym; | ||
| 144 | struct symbol *sym; | ||
| 145 | struct map *map; | ||
| 146 | |||
| 147 | /* ref_reloc_sym is just a label. Need a special fix*/ | ||
| 148 | reloc_sym = kernel_get_ref_reloc_sym(); | ||
| 149 | if (reloc_sym && strcmp(name, reloc_sym->name) == 0) | ||
| 150 | return (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr; | ||
| 151 | else { | ||
| 152 | sym = __find_kernel_function_by_name(name, &map); | ||
| 153 | if (sym) | ||
| 154 | return map->unmap_ip(map, sym->start) - | ||
| 155 | (reloc) ? 0 : map->reloc; | ||
| 156 | } | ||
| 157 | return 0; | ||
| 158 | } | ||
| 159 | |||
| 124 | static struct map *kernel_get_module_map(const char *module) | 160 | static struct map *kernel_get_module_map(const char *module) |
| 125 | { | 161 | { |
| 126 | struct rb_node *nd; | 162 | struct rb_node *nd; |
| @@ -216,12 +252,26 @@ out: | |||
| 216 | static int convert_to_perf_probe_point(struct probe_trace_point *tp, | 252 | static int convert_to_perf_probe_point(struct probe_trace_point *tp, |
| 217 | struct perf_probe_point *pp) | 253 | struct perf_probe_point *pp) |
| 218 | { | 254 | { |
| 219 | pp->function = strdup(tp->symbol); | 255 | struct symbol *sym; |
| 256 | struct map *map; | ||
| 257 | u64 addr = kernel_get_symbol_address_by_name(tp->symbol, true); | ||
| 258 | |||
| 259 | if (addr) { | ||
| 260 | addr += tp->offset; | ||
| 261 | sym = __find_kernel_function(addr, &map); | ||
| 262 | if (!sym) | ||
| 263 | goto failed; | ||
| 264 | pp->function = strdup(sym->name); | ||
| 265 | pp->offset = addr - map->unmap_ip(map, sym->start); | ||
| 266 | } else { | ||
| 267 | failed: | ||
| 268 | pp->function = strdup(tp->symbol); | ||
| 269 | pp->offset = tp->offset; | ||
| 270 | } | ||
| 220 | 271 | ||
| 221 | if (pp->function == NULL) | 272 | if (pp->function == NULL) |
| 222 | return -ENOMEM; | 273 | return -ENOMEM; |
| 223 | 274 | ||
| 224 | pp->offset = tp->offset; | ||
| 225 | pp->retprobe = tp->retprobe; | 275 | pp->retprobe = tp->retprobe; |
| 226 | 276 | ||
| 227 | return 0; | 277 | return 0; |
| @@ -248,18 +298,6 @@ static struct debuginfo *open_debuginfo(const char *module) | |||
| 248 | return debuginfo__new(path); | 298 | return debuginfo__new(path); |
| 249 | } | 299 | } |
| 250 | 300 | ||
| 251 | static struct ref_reloc_sym *__kernel_get_ref_reloc_sym(void) | ||
| 252 | { | ||
| 253 | /* kmap->ref_reloc_sym should be set if host_machine is initialized */ | ||
| 254 | struct kmap *kmap; | ||
| 255 | |||
| 256 | if (map__load(host_machine->vmlinux_maps[MAP__FUNCTION], NULL) < 0) | ||
| 257 | return NULL; | ||
| 258 | |||
| 259 | kmap = map__kmap(host_machine->vmlinux_maps[MAP__FUNCTION]); | ||
| 260 | return kmap->ref_reloc_sym; | ||
| 261 | } | ||
| 262 | |||
| 263 | /* | 301 | /* |
| 264 | * Convert trace point to probe point with debuginfo | 302 | * Convert trace point to probe point with debuginfo |
| 265 | * Currently only handles kprobes. | 303 | * Currently only handles kprobes. |
| @@ -267,24 +305,13 @@ static struct ref_reloc_sym *__kernel_get_ref_reloc_sym(void) | |||
| 267 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | 305 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, |
| 268 | struct perf_probe_point *pp) | 306 | struct perf_probe_point *pp) |
| 269 | { | 307 | { |
| 270 | struct symbol *sym; | ||
| 271 | struct ref_reloc_sym *reloc_sym; | ||
| 272 | struct map *map; | ||
| 273 | u64 addr = 0; | 308 | u64 addr = 0; |
| 274 | int ret = -ENOENT; | 309 | int ret = -ENOENT; |
| 275 | struct debuginfo *dinfo; | 310 | struct debuginfo *dinfo; |
| 276 | 311 | ||
| 277 | /* ref_reloc_sym is just a label. Need a special fix*/ | 312 | addr = kernel_get_symbol_address_by_name(tp->symbol, false); |
| 278 | reloc_sym = __kernel_get_ref_reloc_sym(); | ||
| 279 | if (reloc_sym && strcmp(tp->symbol, reloc_sym->name) == 0) | ||
| 280 | addr = reloc_sym->unrelocated_addr + tp->offset; | ||
| 281 | else { | ||
| 282 | sym = __find_kernel_function_by_name(tp->symbol, &map); | ||
| 283 | if (sym) | ||
| 284 | addr = map->unmap_ip(map, sym->start + tp->offset) - | ||
| 285 | map->reloc; | ||
| 286 | } | ||
| 287 | if (addr) { | 313 | if (addr) { |
| 314 | addr += tp->offset; | ||
| 288 | pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol, | 315 | pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol, |
| 289 | tp->offset, addr); | 316 | tp->offset, addr); |
| 290 | 317 | ||
| @@ -420,7 +447,7 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs, | |||
| 420 | if (module) | 447 | if (module) |
| 421 | return add_module_to_probe_trace_events(tevs, ntevs, module); | 448 | return add_module_to_probe_trace_events(tevs, ntevs, module); |
| 422 | 449 | ||
| 423 | reloc_sym = __kernel_get_ref_reloc_sym(); | 450 | reloc_sym = kernel_get_ref_reloc_sym(); |
| 424 | if (!reloc_sym) { | 451 | if (!reloc_sym) { |
| 425 | pr_warning("Relocated base symbol is not found!\n"); | 452 | pr_warning("Relocated base symbol is not found!\n"); |
| 426 | return -EINVAL; | 453 | return -EINVAL; |
