aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>2010-07-09 05:29:11 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-07-16 10:48:09 -0400
commit6a330a3c8a648916b3c6bda79a78c38ac093af17 (patch)
tree76322d562a438cb47ebf95311d898394efceca8e /tools/perf/util
parent7cf0b79e6ffd04bba5d4e625a0fe2e30a5b383e5 (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')
-rw-r--r--tools/perf/util/probe-event.c34
-rw-r--r--tools/perf/util/probe-event.h1
-rw-r--r--tools/perf/util/probe-finder.c21
3 files changed, 44 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 */
204static int get_real_path(const char *raw_path, char **new_path) 204static 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);
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index bc06d3e8bafa..ed362acff4b6 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -86,6 +86,7 @@ struct line_range {
86 int end; /* End line number */ 86 int end; /* End line number */
87 int offset; /* Start line offset */ 87 int offset; /* Start line offset */
88 char *path; /* Real path name */ 88 char *path; /* Real path name */
89 char *comp_dir; /* Compile directory */
89 struct list_head line_list; /* Visible lines */ 90 struct list_head line_list; /* Visible lines */
90}; 91};
91 92
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index a934a364c30f..37dcdb651a69 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -144,6 +144,15 @@ static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
144 return src; 144 return src;
145} 145}
146 146
147/* Get DW_AT_comp_dir (should be NULL with older gcc) */
148static const char *cu_get_comp_dir(Dwarf_Die *cu_die)
149{
150 Dwarf_Attribute attr;
151 if (dwarf_attr(cu_die, DW_AT_comp_dir, &attr) == NULL)
152 return NULL;
153 return dwarf_formstring(&attr);
154}
155
147/* Compare diename and tname */ 156/* Compare diename and tname */
148static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) 157static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
149{ 158{
@@ -1374,6 +1383,7 @@ int find_line_range(int fd, struct line_range *lr)
1374 size_t cuhl; 1383 size_t cuhl;
1375 Dwarf_Die *diep; 1384 Dwarf_Die *diep;
1376 Dwarf *dbg; 1385 Dwarf *dbg;
1386 const char *comp_dir;
1377 1387
1378 dbg = dwarf_begin(fd, DWARF_C_READ); 1388 dbg = dwarf_begin(fd, DWARF_C_READ);
1379 if (!dbg) { 1389 if (!dbg) {
@@ -1409,6 +1419,17 @@ int find_line_range(int fd, struct line_range *lr)
1409 } 1419 }
1410 off = noff; 1420 off = noff;
1411 } 1421 }
1422
1423 /* Store comp_dir */
1424 if (lf.found) {
1425 comp_dir = cu_get_comp_dir(&lf.cu_die);
1426 if (comp_dir) {
1427 lr->comp_dir = strdup(comp_dir);
1428 if (!lr->comp_dir)
1429 ret = -ENOMEM;
1430 }
1431 }
1432
1412 pr_debug("path: %s\n", lr->path); 1433 pr_debug("path: %s\n", lr->path);
1413 dwarf_end(dbg); 1434 dwarf_end(dbg);
1414 1435