Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf tools: Get debug info of DSO properly

The dso__debuginfo() just used the path name to open the file but it may
be outdated. It should check build-ID and use the file in the build-ID
cache if available rather than just using the path name.

Let's factor out dso__get_filename() to avoid code duplicate.

Fixes: 53a61a6ca279165d ("perf annotate: Add dso__debuginfo() helper")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
069e603d b42c4dfe

+50 -24
+48 -15
tools/perf/util/dso.c
··· 112 112 113 113 int dso__read_binary_type_filename(const struct dso *dso, 114 114 enum dso_binary_type type, 115 - char *root_dir, char *filename, size_t size) 115 + const char *root_dir, char *filename, size_t size) 116 116 { 117 117 char build_id_hex[SBUILD_ID_SIZE]; 118 118 int ret = 0; ··· 561 561 return filename_with_chroot(nsinfo__pid(dso__nsinfo_const(dso)), filename); 562 562 } 563 563 564 - static int __open_dso(struct dso *dso, struct machine *machine) 565 - EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock) 564 + static char *dso__get_filename(struct dso *dso, const char *root_dir, 565 + bool *decomp) 566 566 { 567 - int fd = -EINVAL; 568 - char *root_dir = (char *)""; 569 567 char *name = malloc(PATH_MAX); 570 - bool decomp = false; 571 568 572 - if (!name) 573 - return -ENOMEM; 569 + *decomp = false; 574 570 575 - mutex_lock(dso__lock(dso)); 576 - if (machine) 577 - root_dir = machine->root_dir; 571 + if (name == NULL) 572 + return NULL; 578 573 579 574 if (dso__read_binary_type_filename(dso, dso__binary_type(dso), 580 575 root_dir, name, PATH_MAX)) ··· 594 599 size_t len = sizeof(newpath); 595 600 596 601 if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) { 597 - fd = -(*dso__load_errno(dso)); 602 + errno = *dso__load_errno(dso); 598 603 goto out; 599 604 } 600 605 601 - decomp = true; 606 + *decomp = true; 602 607 strcpy(name, newpath); 603 608 } 609 + return name; 604 610 605 - fd = do_open(name); 611 + out: 612 + free(name); 613 + return NULL; 614 + } 615 + 616 + static int __open_dso(struct dso *dso, struct machine *machine) 617 + EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock) 618 + { 619 + int fd = -EINVAL; 620 + char *name; 621 + bool decomp = false; 622 + 623 + mutex_lock(dso__lock(dso)); 624 + 625 + name = dso__get_filename(dso, machine ? machine->root_dir : "", &decomp); 626 + if (name) 627 + fd = do_open(name); 628 + else 629 + fd = -errno; 606 630 607 631 if (decomp) 608 632 unlink(name); 609 633 610 - out: 611 634 mutex_unlock(dso__lock(dso)); 612 635 free(name); 613 636 return fd; ··· 1928 1915 } 1929 1916 return __dso__read_symbol(dso, symfs_filename, start, len, 1930 1917 out_buf, out_buf_len, is_64bit); 1918 + } 1919 + 1920 + struct debuginfo *dso__debuginfo(struct dso *dso) 1921 + { 1922 + char *name; 1923 + bool decomp = false; 1924 + struct debuginfo *dinfo = NULL; 1925 + 1926 + mutex_lock(dso__lock(dso)); 1927 + 1928 + name = dso__get_filename(dso, "", &decomp); 1929 + if (name) 1930 + dinfo = debuginfo__new(name); 1931 + 1932 + if (decomp) 1933 + unlink(name); 1934 + 1935 + mutex_unlock(dso__lock(dso)); 1936 + free(name); 1937 + return dinfo; 1931 1938 }
+2 -9
tools/perf/util/dso.h
··· 784 784 785 785 char dso__symtab_origin(const struct dso *dso); 786 786 int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type, 787 - char *root_dir, char *filename, size_t size); 787 + const char *root_dir, char *filename, size_t size); 788 788 bool is_kernel_module(const char *pathname, int cpumode); 789 789 bool dso__needs_decompress(struct dso *dso); 790 790 int dso__decompress_kmodule_fd(struct dso *dso, const char *name); ··· 933 933 bool perf_pid_map_tid(const char *dso_name, int *tid); 934 934 bool is_perf_pid_map_name(const char *dso_name); 935 935 936 - /* 937 - * In the future, we may get debuginfo using build-ID (w/o path). 938 - * Add this helper is for the smooth conversion. 939 - */ 940 - static inline struct debuginfo *dso__debuginfo(struct dso *dso) 941 - { 942 - return debuginfo__new(dso__long_name(dso)); 943 - } 936 + struct debuginfo *dso__debuginfo(struct dso *dso); 944 937 945 938 const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename, 946 939 const struct map *map, const struct symbol *sym,