Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 205306
b: refs/heads/master
c: 7cf0b79
h: refs/heads/master
v: v3
  • Loading branch information
Masami Hiramatsu authored and Arnaldo Carvalho de Melo committed Jul 16, 2010
1 parent 4364de5 commit b9daf0d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 57 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: 0dd9ac63ce26ec87b080ca9c3e6efed33c23ace6
refs/heads/master: 7cf0b79e6ffd04bba5d4e625a0fe2e30a5b383e5
59 changes: 59 additions & 0 deletions trunk/tools/perf/util/probe-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,55 @@ static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev,
return ntevs;
}

/*
* Find a src file from a DWARF tag path. Prepend optional source path prefix
* and chop off leading directories that do not exist. Result is passed back as
* 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)
{
if (!symbol_conf.source_prefix) {
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));
if (!*new_path)
return -ENOMEM;

for (;;) {
sprintf(*new_path, "%s/%s", symbol_conf.source_prefix,
raw_path);

if (access(*new_path, R_OK) == 0)
return 0;

switch (errno) {
case ENAMETOOLONG:
case ENOENT:
case EROFS:
case EFAULT:
raw_path = strchr(++raw_path, '/');
if (!raw_path) {
free(*new_path);
*new_path = NULL;
return -ENOENT;
}
continue;

default:
free(*new_path);
*new_path = NULL;
return -errno;
}
}
}

#define LINEBUF_SIZE 256
#define NR_ADDITIONAL_LINES 2

Expand Down Expand Up @@ -244,6 +293,7 @@ int show_line_range(struct line_range *lr)
struct line_node *ln;
FILE *fp;
int fd, ret;
char *tmp;

/* Search a line range */
ret = init_vmlinux();
Expand All @@ -266,6 +316,15 @@ int show_line_range(struct line_range *lr)
return ret;
}

/* Convert source file path */
tmp = lr->path;
ret = get_real_path(tmp, &lr->path);
free(tmp); /* Free old path */
if (ret < 0) {
pr_warning("Failed to find source file. (%d)\n", ret);
return ret;
}

setup_pager();

if (lr->function)
Expand Down
61 changes: 5 additions & 56 deletions trunk/tools/perf/util/probe-finder.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,55 +58,6 @@ static int strtailcmp(const char *s1, const char *s2)
return 0;
}

/*
* Find a src file from a DWARF tag path. Prepend optional source path prefix
* and chop off leading directories that do not exist. Result is passed back as
* 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)
{
if (!symbol_conf.source_prefix) {
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));
if (!*new_path)
return -ENOMEM;

for (;;) {
sprintf(*new_path, "%s/%s", symbol_conf.source_prefix,
raw_path);

if (access(*new_path, R_OK) == 0)
return 0;

switch (errno) {
case ENAMETOOLONG:
case ENOENT:
case EROFS:
case EFAULT:
raw_path = strchr(++raw_path, '/');
if (!raw_path) {
free(*new_path);
*new_path = NULL;
return -ENOENT;
}
continue;

default:
free(*new_path);
*new_path = NULL;
return -errno;
}
}
}

/* Line number list operations */

/* Add a line to line number list */
Expand Down Expand Up @@ -1256,13 +1207,11 @@ int find_perf_probe_point(int fd, unsigned long addr,
static int line_range_add_line(const char *src, unsigned int lineno,
struct line_range *lr)
{
int ret;

/* Copy real path */
/* Copy source path */
if (!lr->path) {
ret = get_real_path(src, &lr->path);
if (ret != 0)
return ret;
lr->path = strdup(src);
if (lr->path == NULL)
return -ENOMEM;
}
return line_list__add_line(&lr->line_list, lineno);
}
Expand Down Expand Up @@ -1460,7 +1409,7 @@ int find_line_range(int fd, struct line_range *lr)
}
off = noff;
}
pr_debug("path: %lx\n", (unsigned long)lr->path);
pr_debug("path: %s\n", lr->path);
dwarf_end(dbg);

return (ret < 0) ? ret : lf.found;
Expand Down

0 comments on commit b9daf0d

Please sign in to comment.