diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2010-07-09 05:29:11 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-07-16 10:48:09 -0400 |
commit | 6a330a3c8a648916b3c6bda79a78c38ac093af17 (patch) | |
tree | 76322d562a438cb47ebf95311d898394efceca8e /tools/perf/util/probe-event.c | |
parent | 7cf0b79e6ffd04bba5d4e625a0fe2e30a5b383e5 (diff) |
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.c | 34 |
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, | |||
201 | * a newly allocated path on success. | 201 | * a newly allocated path on success. |
202 | * Return 0 if file was found and readable, -errno otherwise. | 202 | * Return 0 if file was found and readable, -errno otherwise. |
203 | */ | 203 | */ |
204 | static int get_real_path(const char *raw_path, char **new_path) | 204 | static int get_real_path(const char *raw_path, const char *comp_dir, |
205 | char **new_path) | ||
205 | { | 206 | { |
206 | if (!symbol_conf.source_prefix) { | 207 | const char *prefix = symbol_conf.source_prefix; |
207 | if (access(raw_path, R_OK) == 0) { | 208 | |
208 | *new_path = strdup(raw_path); | 209 | if (!prefix) { |
209 | return 0; | 210 | if (raw_path[0] != '/' && comp_dir) |
210 | } else | 211 | /* If not an absolute path, try to use comp_dir */ |
211 | return -errno; | 212 | prefix = comp_dir; |
213 | else { | ||
214 | if (access(raw_path, R_OK) == 0) { | ||
215 | *new_path = strdup(raw_path); | ||
216 | return 0; | ||
217 | } else | ||
218 | return -errno; | ||
219 | } | ||
212 | } | 220 | } |
213 | 221 | ||
214 | *new_path = malloc((strlen(symbol_conf.source_prefix) + | 222 | *new_path = malloc((strlen(prefix) + strlen(raw_path) + 2)); |
215 | strlen(raw_path) + 2)); | ||
216 | if (!*new_path) | 223 | if (!*new_path) |
217 | return -ENOMEM; | 224 | return -ENOMEM; |
218 | 225 | ||
219 | for (;;) { | 226 | for (;;) { |
220 | sprintf(*new_path, "%s/%s", symbol_conf.source_prefix, | 227 | sprintf(*new_path, "%s/%s", prefix, raw_path); |
221 | raw_path); | ||
222 | 228 | ||
223 | if (access(*new_path, R_OK) == 0) | 229 | if (access(*new_path, R_OK) == 0) |
224 | return 0; | 230 | return 0; |
225 | 231 | ||
232 | if (!symbol_conf.source_prefix) | ||
233 | /* In case of searching comp_dir, don't retry */ | ||
234 | return -errno; | ||
235 | |||
226 | switch (errno) { | 236 | switch (errno) { |
227 | case ENAMETOOLONG: | 237 | case ENAMETOOLONG: |
228 | case ENOENT: | 238 | case ENOENT: |
@@ -318,7 +328,7 @@ int show_line_range(struct line_range *lr) | |||
318 | 328 | ||
319 | /* Convert source file path */ | 329 | /* Convert source file path */ |
320 | tmp = lr->path; | 330 | tmp = lr->path; |
321 | ret = get_real_path(tmp, &lr->path); | 331 | ret = get_real_path(tmp, lr->comp_dir, &lr->path); |
322 | free(tmp); /* Free old path */ | 332 | free(tmp); /* Free old path */ |
323 | if (ret < 0) { | 333 | if (ret < 0) { |
324 | pr_warning("Failed to find source file. (%d)\n", ret); | 334 | pr_warning("Failed to find source file. (%d)\n", ret); |