summaryrefslogtreecommitdiff
path: root/tools/perf/util/probe-event.c
diff options
context:
space:
mode:
authorMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>2010-07-09 13:29:11 +0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-07-16 18:48:09 +0400
commit6a330a3c8a648916b3c6bda79a78c38ac093af17 (patch)
tree76322d562a438cb47ebf95311d898394efceca8e /tools/perf/util/probe-event.c
parent7cf0b79e6ffd04bba5d4e625a0fe2e30a5b383e5 (diff)
downloadlinux-6a330a3c8a648916b3c6bda79a78c38ac093af17.tar.xz
perf probe: Support comp_dir to find an absolute source path
Gcc generates DW_AT_comp_dir and stores relative source path if building kernel without O= option. In that case, perf probe --line sometimes doesn't work without --source option, because it tries to access relative source path. This adds DW_AT_comp_dir support to perf probe for finding an absolute source path when no --source option. LKML-Reference: <4C36EBE7.3060802@hitachi.com> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/probe-event.c')
-rw-r--r--tools/perf/util/probe-event.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 8d08e75b2dd3..4445a1e7052f 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -201,28 +201,38 @@ static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev,
* a newly allocated path on success.
* Return 0 if file was found and readable, -errno otherwise.
*/
-static int get_real_path(const char *raw_path, char **new_path)
+static int get_real_path(const char *raw_path, const char *comp_dir,
+ char **new_path)
{
- if (!symbol_conf.source_prefix) {
- if (access(raw_path, R_OK) == 0) {
- *new_path = strdup(raw_path);
- return 0;
- } else
- return -errno;
+ const char *prefix = symbol_conf.source_prefix;
+
+ if (!prefix) {
+ if (raw_path[0] != '/' && comp_dir)
+ /* If not an absolute path, try to use comp_dir */
+ prefix = comp_dir;
+ else {
+ if (access(raw_path, R_OK) == 0) {
+ *new_path = strdup(raw_path);
+ return 0;
+ } else
+ return -errno;
+ }
}
- *new_path = malloc((strlen(symbol_conf.source_prefix) +
- strlen(raw_path) + 2));
+ *new_path = malloc((strlen(prefix) + strlen(raw_path) + 2));
if (!*new_path)
return -ENOMEM;
for (;;) {
- sprintf(*new_path, "%s/%s", symbol_conf.source_prefix,
- raw_path);
+ sprintf(*new_path, "%s/%s", prefix, raw_path);
if (access(*new_path, R_OK) == 0)
return 0;
+ if (!symbol_conf.source_prefix)
+ /* In case of searching comp_dir, don't retry */
+ return -errno;
+
switch (errno) {
case ENAMETOOLONG:
case ENOENT:
@@ -318,7 +328,7 @@ int show_line_range(struct line_range *lr)
/* Convert source file path */
tmp = lr->path;
- ret = get_real_path(tmp, &lr->path);
+ ret = get_real_path(tmp, lr->comp_dir, &lr->path);
free(tmp); /* Free old path */
if (ret < 0) {
pr_warning("Failed to find source file. (%d)\n", ret);