diff options
| -rw-r--r-- | tools/perf/util/probe-event.c | 59 | ||||
| -rw-r--r-- | tools/perf/util/probe-finder.c | 71 | ||||
| -rw-r--r-- | tools/perf/util/probe-finder.h | 4 |
3 files changed, 74 insertions, 60 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 5483d98236d3..d8bb616ff57c 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
| @@ -655,65 +655,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | |||
| 655 | return ntevs; | 655 | return ntevs; |
| 656 | } | 656 | } |
| 657 | 657 | ||
| 658 | /* | ||
| 659 | * Find a src file from a DWARF tag path. Prepend optional source path prefix | ||
| 660 | * and chop off leading directories that do not exist. Result is passed back as | ||
| 661 | * a newly allocated path on success. | ||
| 662 | * Return 0 if file was found and readable, -errno otherwise. | ||
| 663 | */ | ||
| 664 | static int get_real_path(const char *raw_path, const char *comp_dir, | ||
| 665 | char **new_path) | ||
| 666 | { | ||
| 667 | const char *prefix = symbol_conf.source_prefix; | ||
| 668 | |||
| 669 | if (!prefix) { | ||
| 670 | if (raw_path[0] != '/' && comp_dir) | ||
| 671 | /* If not an absolute path, try to use comp_dir */ | ||
| 672 | prefix = comp_dir; | ||
| 673 | else { | ||
| 674 | if (access(raw_path, R_OK) == 0) { | ||
| 675 | *new_path = strdup(raw_path); | ||
| 676 | return *new_path ? 0 : -ENOMEM; | ||
| 677 | } else | ||
| 678 | return -errno; | ||
| 679 | } | ||
| 680 | } | ||
| 681 | |||
| 682 | *new_path = malloc((strlen(prefix) + strlen(raw_path) + 2)); | ||
| 683 | if (!*new_path) | ||
| 684 | return -ENOMEM; | ||
| 685 | |||
| 686 | for (;;) { | ||
| 687 | sprintf(*new_path, "%s/%s", prefix, raw_path); | ||
| 688 | |||
| 689 | if (access(*new_path, R_OK) == 0) | ||
| 690 | return 0; | ||
| 691 | |||
| 692 | if (!symbol_conf.source_prefix) { | ||
| 693 | /* In case of searching comp_dir, don't retry */ | ||
| 694 | zfree(new_path); | ||
| 695 | return -errno; | ||
| 696 | } | ||
| 697 | |||
| 698 | switch (errno) { | ||
| 699 | case ENAMETOOLONG: | ||
| 700 | case ENOENT: | ||
| 701 | case EROFS: | ||
| 702 | case EFAULT: | ||
| 703 | raw_path = strchr(++raw_path, '/'); | ||
| 704 | if (!raw_path) { | ||
| 705 | zfree(new_path); | ||
| 706 | return -ENOENT; | ||
| 707 | } | ||
| 708 | continue; | ||
| 709 | |||
| 710 | default: | ||
| 711 | zfree(new_path); | ||
| 712 | return -errno; | ||
| 713 | } | ||
| 714 | } | ||
| 715 | } | ||
| 716 | |||
| 717 | #define LINEBUF_SIZE 256 | 658 | #define LINEBUF_SIZE 256 |
| 718 | #define NR_ADDITIONAL_LINES 2 | 659 | #define NR_ADDITIONAL_LINES 2 |
| 719 | 660 | ||
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 7831e2d93949..ff7865ca3ca3 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
| @@ -855,11 +855,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno, | |||
| 855 | static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | 855 | static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) |
| 856 | { | 856 | { |
| 857 | int ret = 0; | 857 | int ret = 0; |
| 858 | char *fpath; | ||
| 858 | 859 | ||
| 859 | if (intlist__empty(pf->lcache)) { | 860 | if (intlist__empty(pf->lcache)) { |
| 861 | const char *comp_dir; | ||
| 862 | |||
| 863 | comp_dir = cu_get_comp_dir(&pf->cu_die); | ||
| 864 | ret = get_real_path(pf->fname, comp_dir, &fpath); | ||
| 865 | if (ret < 0) { | ||
| 866 | pr_warning("Failed to find source file path.\n"); | ||
| 867 | return ret; | ||
| 868 | } | ||
| 869 | |||
| 860 | /* Matching lazy line pattern */ | 870 | /* Matching lazy line pattern */ |
| 861 | ret = find_lazy_match_lines(pf->lcache, pf->fname, | 871 | ret = find_lazy_match_lines(pf->lcache, fpath, |
| 862 | pf->pev->point.lazy_line); | 872 | pf->pev->point.lazy_line); |
| 873 | free(fpath); | ||
| 863 | if (ret <= 0) | 874 | if (ret <= 0) |
| 864 | return ret; | 875 | return ret; |
| 865 | } | 876 | } |
| @@ -1622,3 +1633,61 @@ found: | |||
| 1622 | return (ret < 0) ? ret : lf.found; | 1633 | return (ret < 0) ? ret : lf.found; |
| 1623 | } | 1634 | } |
| 1624 | 1635 | ||
| 1636 | /* | ||
| 1637 | * Find a src file from a DWARF tag path. Prepend optional source path prefix | ||
| 1638 | * and chop off leading directories that do not exist. Result is passed back as | ||
| 1639 | * a newly allocated path on success. | ||
| 1640 | * Return 0 if file was found and readable, -errno otherwise. | ||
| 1641 | */ | ||
| 1642 | int get_real_path(const char *raw_path, const char *comp_dir, | ||
| 1643 | char **new_path) | ||
| 1644 | { | ||
| 1645 | const char *prefix = symbol_conf.source_prefix; | ||
| 1646 | |||
| 1647 | if (!prefix) { | ||
| 1648 | if (raw_path[0] != '/' && comp_dir) | ||
| 1649 | /* If not an absolute path, try to use comp_dir */ | ||
| 1650 | prefix = comp_dir; | ||
| 1651 | else { | ||
| 1652 | if (access(raw_path, R_OK) == 0) { | ||
| 1653 | *new_path = strdup(raw_path); | ||
| 1654 | return *new_path ? 0 : -ENOMEM; | ||
| 1655 | } else | ||
| 1656 | return -errno; | ||
| 1657 | } | ||
| 1658 | } | ||
| 1659 | |||
| 1660 | *new_path = malloc((strlen(prefix) + strlen(raw_path) + 2)); | ||
| 1661 | if (!*new_path) | ||
| 1662 | return -ENOMEM; | ||
| 1663 | |||
| 1664 | for (;;) { | ||
| 1665 | sprintf(*new_path, "%s/%s", prefix, raw_path); | ||
| 1666 | |||
| 1667 | if (access(*new_path, R_OK) == 0) | ||
| 1668 | return 0; | ||
| 1669 | |||
| 1670 | if (!symbol_conf.source_prefix) { | ||
| 1671 | /* In case of searching comp_dir, don't retry */ | ||
| 1672 | zfree(new_path); | ||
| 1673 | return -errno; | ||
| 1674 | } | ||
| 1675 | |||
| 1676 | switch (errno) { | ||
| 1677 | case ENAMETOOLONG: | ||
| 1678 | case ENOENT: | ||
| 1679 | case EROFS: | ||
| 1680 | case EFAULT: | ||
| 1681 | raw_path = strchr(++raw_path, '/'); | ||
| 1682 | if (!raw_path) { | ||
| 1683 | zfree(new_path); | ||
| 1684 | return -ENOENT; | ||
| 1685 | } | ||
| 1686 | continue; | ||
| 1687 | |||
| 1688 | default: | ||
| 1689 | zfree(new_path); | ||
| 1690 | return -errno; | ||
| 1691 | } | ||
| 1692 | } | ||
| 1693 | } | ||
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 92590b2c7e1c..ebf8c8c81453 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
| @@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg, | |||
| 55 | struct variable_list **vls, | 55 | struct variable_list **vls, |
| 56 | int max_points, bool externs); | 56 | int max_points, bool externs); |
| 57 | 57 | ||
| 58 | /* Find a src file from a DWARF tag path */ | ||
| 59 | int get_real_path(const char *raw_path, const char *comp_dir, | ||
| 60 | char **new_path); | ||
| 61 | |||
| 58 | struct probe_finder { | 62 | struct probe_finder { |
| 59 | struct perf_probe_event *pev; /* Target probe event */ | 63 | struct perf_probe_event *pev; /* Target probe event */ |
| 60 | 64 | ||
