Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 205307
b: refs/heads/master
c: 6a330a3
h: refs/heads/master
i:
  205305: 4364de5
  205303: 4735d5a
v: v3
  • Loading branch information
Masami Hiramatsu authored and Arnaldo Carvalho de Melo committed Jul 16, 2010
1 parent b9daf0d commit 41b39cd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7cf0b79e6ffd04bba5d4e625a0fe2e30a5b383e5
refs/heads/master: 6a330a3c8a648916b3c6bda79a78c38ac093af17
34 changes: 22 additions & 12 deletions trunk/tools/perf/util/probe-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions trunk/tools/perf/util/probe-event.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct line_range {
int end; /* End line number */
int offset; /* Start line offset */
char *path; /* Real path name */
char *comp_dir; /* Compile directory */
struct list_head line_list; /* Visible lines */
};

Expand Down
21 changes: 21 additions & 0 deletions trunk/tools/perf/util/probe-finder.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
return src;
}

/* Get DW_AT_comp_dir (should be NULL with older gcc) */
static const char *cu_get_comp_dir(Dwarf_Die *cu_die)
{
Dwarf_Attribute attr;
if (dwarf_attr(cu_die, DW_AT_comp_dir, &attr) == NULL)
return NULL;
return dwarf_formstring(&attr);
}

/* Compare diename and tname */
static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
{
Expand Down Expand Up @@ -1374,6 +1383,7 @@ int find_line_range(int fd, struct line_range *lr)
size_t cuhl;
Dwarf_Die *diep;
Dwarf *dbg;
const char *comp_dir;

dbg = dwarf_begin(fd, DWARF_C_READ);
if (!dbg) {
Expand Down Expand Up @@ -1409,6 +1419,17 @@ int find_line_range(int fd, struct line_range *lr)
}
off = noff;
}

/* Store comp_dir */
if (lf.found) {
comp_dir = cu_get_comp_dir(&lf.cu_die);
if (comp_dir) {
lr->comp_dir = strdup(comp_dir);
if (!lr->comp_dir)
ret = -ENOMEM;
}
}

pr_debug("path: %s\n", lr->path);
dwarf_end(dbg);

Expand Down

0 comments on commit 41b39cd

Please sign in to comment.