perf: support specify vdso path in cmdline
v3 cover perf: support specify vdso path in cmdline
The vdso dumped from process memory (in buildid-cache) lacks debugging info. To annotate vdso symbols with source lines we need specify a debugging version.
For x86, we can find them from your local build as 'arch/x86/entry/vdso/vdso{32,64}.so.dbg'. Or they may resides in '/lib/modules/<version>/vdso/vdso{32,64}.so' on Ubuntu. But notice that the builid has to match.
If user doesn't specify the path, perf will search them internally as long as vmlinux.
Below samples are captured on my local build kernel. perf succesfully find debugging version vdso and we can annotate with source without specifying vdso path.
$ sudo perf record -a $ sudo perf report --objdump=llvm-objdump
Samples: 17K of event 'cycles:P', 4000 Hz, Event count (approx.): 1760 __vdso_clock_gettime /work/linux-host/arch/x86/entry/vdso/vdso64.so.d
Percent│ movq -48(%rbp),%rsi
│ testq %rax,%rax
│ ; return vread_hvclock();
│ movq %rax,%rdx
│ ; if (unlikely(!vdso_cycles_ok(cycles)))
│ ↑ js eb
│ ↑ jmp 74
│ ; ts->tv_sec = vdso_ts->sec;
0.02 │147: leaq 2(%rbx),%rax
│ shlq $4, %rax
│ addq %r10,%rax
│ ; while ((seq = READ_ONCE(vd->seq)) & 1) {
9.38 │152: movl (%r10),%ecxWhen doing cross platform analysis, we need to specify the vdso path if we are interested in its symbols. At most two vdso can be given.
$ sudo perf report --objdump=llvm-objdump \
--vdso arch/x86/entry/vdso/vdso64.so.dbg,arch/x86/entry/vdso/vdso32.so.dbgv3:
- update documentation.
v2:
- now search vdso automatically as long as vmlinux, as suggested by Adrian.
- remove change 'prefer symsrc_filename for filename'.
Changbin Du (4):
perf: support specify vdso path in cmdline
perf: disasm: use build_id_path if fallback failed
perf: symbol: generalize vmlinux path searching
perf: symbol: try to seach vdso path if not given by user
tools/perf/Documentation/perf-annotate.txt | 3 + tools/perf/Documentation/perf-c2c.txt | 3 + tools/perf/Documentation/perf-inject.txt | 3 + tools/perf/Documentation/perf-report.txt | 3 + tools/perf/Documentation/perf-script.txt | 3 + tools/perf/Documentation/perf-top.txt | 3 + tools/perf/builtin-annotate.c | 3 + tools/perf/builtin-c2c.c | 2 + tools/perf/builtin-inject.c | 2 + tools/perf/builtin-kallsyms.c | 2 + tools/perf/builtin-probe.c | 2 + tools/perf/builtin-report.c | 2 + tools/perf/builtin-script.c | 2 + tools/perf/builtin-top.c | 4 + tools/perf/tests/builtin-test.c | 3 +- tools/perf/util/disasm.c | 122 +++++++---- tools/perf/util/machine.c | 4 +- tools/perf/util/symbol.c | 233 ++++++++++++++++----- tools/perf/util/symbol.h | 9 +- tools/perf/util/symbol_conf.h | 6 + 20 files changed, 312 insertions(+), 102 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/4 perf: support specify vdso path in cmdline
The vdso dumped from process memory (in buildid-cache) lacks debugging info. To annotate vdso symbols with source lines we need specify a debugging version.
For x86, we can find them from your local build as arch/x86/entry/vdso/vdso{32,64}.so.dbg. Or they may reside in /lib/modules/<version>/vdso/vdso{32,64}.so on Ubuntu. But notice that the buildid has to match.
$ sudo perf record -a $ sudo perf report --objdump=llvm-objdump \ --vdso arch/x86/entry/vdso/vdso64.so.dbg,arch/x86/entry/vdso/vdso32.so.dbg
Samples: 17K of event 'cycles:P', 4000 Hz, Event count (approx.): 1760 __vdso_clock_gettime /work/linux-host/arch/x86/entry/vdso/vdso64.so.d
Percent│ movq -48(%rbp),%rsi
│ testq %rax,%rax
│ ; return vread_hvclock();
│ movq %rax,%rdx
│ ; if (unlikely(!vdso_cycles_ok(cycles)))
│ ↑ js eb
│ ↑ jmp 74
│ ; ts->tv_sec = vdso_ts->sec;
0.02 │147: leaq 2(%rbx),%rax
│ shlq $4, %rax
│ addq %r10,%rax
│ ; while ((seq = READ_ONCE(vd->seq)) & 1) {
9.38 │152: movl (%r10),%ecxWhen doing cross platform analysis, we also need specify the vdso path if we are interested in its symbols.
v2: update documentation.
--- tools/perf/Documentation/perf-annotate.txt | 3 + tools/perf/Documentation/perf-c2c.txt | 3 + tools/perf/Documentation/perf-inject.txt | 3 + tools/perf/Documentation/perf-report.txt | 3 + tools/perf/Documentation/perf-script.txt | 3 + tools/perf/Documentation/perf-top.txt | 3 + tools/perf/builtin-annotate.c | 2 + tools/perf/builtin-c2c.c | 2 + tools/perf/builtin-inject.c | 2 + tools/perf/builtin-report.c | 2 + tools/perf/builtin-script.c | 2 + tools/perf/builtin-top.c | 2 + tools/perf/util/disasm.c | 5 +- tools/perf/util/symbol.c | 82 +++++++++++++++++++++- tools/perf/util/symbol_conf.h | 5 ++ 15 files changed, 118 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-annotate.txt +3 -0
@@ -58,6 +58,9 @@ OPTIONS --ignore-vmlinux:: Ignore vmlinux files. +--vdso=<vdso1[,vdso2]>:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + --itrace:: Options for decoding instruction tracing data. The options are:
tools/perf/Documentation/perf-c2c.txt +3 -0
@@ -71,6 +71,9 @@ REPORT OPTIONS --vmlinux=<file>:: vmlinux pathname +--vdso=<vdso1[,vdso2]>:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + -v:: --verbose:: Be more verbose (show counter open errors, etc).
tools/perf/Documentation/perf-inject.txt +3 -0
@@ -62,6 +62,9 @@ OPTIONS --kallsyms=<file>:: kallsyms pathname +--vdso=<vdso1[,vdso2]>:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + --itrace:: Decode Instruction Tracing data, replacing it with synthesized events. Options are:
tools/perf/Documentation/perf-report.txt +3 -0
@@ -345,6 +345,9 @@ OPTIONS Load module symbols. WARNING: This should only be used with -k and a LIVE kernel. +--vdso=<vdso1[,vdso2]>:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + -f:: --force:: Don't do ownership validation.
tools/perf/Documentation/perf-script.txt +3 -0
@@ -296,6 +296,9 @@ OPTIONS --kallsyms=<file>:: kallsyms pathname +--vdso=<vdso1[,vdso2]>:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + --symfs=<directory>:: Look for files with symbols relative to this directory.
tools/perf/Documentation/perf-top.txt +3 -0
@@ -76,6 +76,9 @@ Default is to monitor all CPUS. --kallsyms=<file>:: kallsyms pathname +--vdso=<vdso1[,vdso2]>:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + -m <pages>:: --mmap-pages=<pages>:: Number of mmap data pages (must be a power of two) or size
tools/perf/builtin-annotate.c +2 -0
@@ -742,6 +742,8 @@ int cmd_annotate(int argc, const char **argv) "file", "vmlinux pathname"),OPT_BOOLEAN ('m' ,"modules" , &symbol_conf.use_modules,"load module symbols - WARNING: use only with -k and LIVE kernel" ), +OPT_CALLBACK (0 ,"vdso" ,NULL ,"vdso1[,vdso2]" ,"vdso pathnames" , + parse_vdso_pathnames),OPT_BOOLEAN ('l' ,"print-line" , &annotate_opts.print_lines,"print matching source lines (may be slow)" ), OPT_BOOLEAN('P', "full-paths", &annotate_opts.full_path,
tools/perf/builtin-c2c.c +2 -0
@@ -3018,6 +3018,8 @@ static int perf_c2c__report(int argc, const char **argv)const struct option options[] = {OPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), +OPT_CALLBACK (0 ,"vdso" ,NULL ,"vdso1[,vdso2]" ,"vdso pathnames" , + parse_vdso_pathnames),OPT_STRING ('i' ,"input" , &input_name,"file" ,"the input file to process" ), OPT_INCR('N', "node-info", &c2c.node_info,
tools/perf/builtin-inject.c +2 -0
@@ -2247,6 +2247,8 @@ int cmd_inject(int argc, const char **argv) "don't load vmlinux even if found"),OPT_STRING (0 ,"kallsyms" , &symbol_conf.kallsyms_name,"file" ,"kallsyms pathname" ), +OPT_CALLBACK (0 ,"vdso" ,NULL ,"vdso1[,vdso2]" ,"vdso pathnames" , + parse_vdso_pathnames),OPT_BOOLEAN ('f' ,"force" , &data.force,"don't complain, do it" ),OPT_CALLBACK_OPTARG (0 ,"itrace" , &inject.itrace_synth_opts, NULL, "opts", "Instruction Tracing options\n"
tools/perf/builtin-report.c +2 -0
@@ -1324,6 +1324,8 @@ int cmd_report(int argc, const char **argv) "don't load vmlinux even if found"),OPT_STRING (0 ,"kallsyms" , &symbol_conf.kallsyms_name,"file" ,"kallsyms pathname" ), +OPT_CALLBACK (0 ,"vdso" ,NULL ,"vdso1[,vdso2]" ,"vdso pathnames" , + parse_vdso_pathnames),OPT_BOOLEAN ('f' ,"force" , &symbol_conf.force,"don't complain, do it" ),OPT_BOOLEAN ('m' ,"modules" , &symbol_conf.use_modules, "load module symbols - WARNING: use only with -k and LIVE kernel"),
tools/perf/builtin-script.c +2 -0
@@ -3965,6 +3965,8 @@ int cmd_script(int argc, const char **argv) "file", "vmlinux pathname"),OPT_STRING (0 ,"kallsyms" , &symbol_conf.kallsyms_name,"file" ,"kallsyms pathname" ), +OPT_CALLBACK (0 ,"vdso" ,NULL ,"vdso1[,vdso2]" ,"vdso pathnames" , + parse_vdso_pathnames),OPT_BOOLEAN ('G' ,"hide-call-graph" , &no_callchain,"When printing symbols do not display call chain" ), OPT_CALLBACK(0, "symfs", NULL, "directory",
tools/perf/builtin-top.c +2 -0
@@ -1479,6 +1479,8 @@ int cmd_top(int argc, const char **argv) "file", "kallsyms pathname"),OPT_BOOLEAN ('K' ,"hide_kernel_symbols" , &top.hide_kernel_symbols,"hide kernel symbols" ), +OPT_CALLBACK (0 ,"vdso" ,NULL ,"vdso1[,vdso2]" ,"vdso pathnames" , + parse_vdso_pathnames),OPT_CALLBACK ('m' ,"mmap-pages" , &opts->mmap_pages,"pages" ,"number of mmap data pages" , evlist__parse_mmap_pages), OPT_INTEGER('r', "realtime", &top.realtime_prio,
tools/perf/util/disasm.c +3 -2
@@ -16,6 +16,7 @@#include "debug.h" #include "disasm.h" #include "dso.h" +#include "vdso.h" #include "env.h" #include "evsel.h" #include "map.h"
@@ -1134,7 +1135,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil goto fallback; linkname[len] ='\0' ; -if (strstr (linkname,DSO__NAME_KALLSYMS ) || +if (strstr (linkname,DSO__NAME_KALLSYMS ) ||strstr (linkname,DSO__NAME_VDSO ) ||access (filename,R_OK )) { fallback:/*
@@ -1142,7 +1143,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil* cache, or is just a kallsyms file, well, lets hope that this * DSO is the same as when 'perf record' ran. */ -if (dso__kernel (dso) &&dso__long_name (dso)[0 ] =='/' ) +if ((dso__kernel (dso) ||dso__is_vdso (dso)) &&dso__long_name (dso)[0 ] =='/' )snprintf (filename, filename_size,"%s" ,dso__long_name (dso));else __symbol__join_symfs (filename, filename_size,dso__long_name (dso));
tools/perf/util/symbol.c +80 -2
116 lines not on this page · raw message
tools/perf/util/symbol_conf.h +5 -0
@@ -3,6 +3,7 @@#define __PERF_SYMBOL_CONF 1#include <stdbool.h> +#include <subcmd/parse-options.h> struct strlist ;struct intlist ;
@@ -55,6 +56,7 @@ struct symbol_conf {const char *default_guest_vmlinux_name, *default_guest_kallsyms, *default_guest_modules; +const char *vdso_name[2 ];const char *guestmount;const char *dso_list_str, *comm_list_str,
@@ -85,4 +87,7 @@ struct symbol_conf {extern struct symbol_conf symbol_conf; +int parse_vdso_pathnames (const struct option *opt__maybe_unused , +const char *arg,int unset__maybe_unused ); +#endif // __PERF_SYMBOL_CONF
Signature · 1 line
2.34.1
PATCH v3 2/4 perf: disasm: use build_id_path if fallback failed
In reply to Changbin DuIf we can not fallback for special dso (vmlinx and vdso), use the build_id_path found previously.
To make change easy, this change first refactors the code by extracting two functions read_buildid_linkname() and fallback_filename().
--- tools/perf/util/disasm.c | 121 ++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 46 deletions(-)
tools/perf/util/disasm.c +75 -46
@@ -1092,14 +1092,72 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, sreturn 0 ; } -static int dso__disassemble_filename (struct dso *dso,char *filename,size_t filename_size) +static int read_buildid_linkname (char *filename,char *linkname,size_t linkname_size) { -char linkname[PATH_MAX ]; -char *build_id_filename;char *build_id_path =NULL ;char *pos;int len; + build_id_path =strdup (filename); +if (!build_id_path) +return ENOMEM ; + +/* +* old style build-id cache has name of XX/XXXXXXX.. while +* new style has XX/XXXXXXX../{elf,kallsyms,vdso}. +* extract the build-id part of dirname in the new style only. +*/ + pos =strrchr (build_id_path,'/' ); +if (pos &&strlen (pos) <SBUILD_ID_SIZE -2 ) +dirname (build_id_path); + + len =readlink (build_id_path, linkname, linkname_size); +if (len <0 ) { +free (build_id_path); +return -1 ; + } + + linkname[len] ='\0' ; +free (build_id_path); +return 0 ; +} + +static int fallback_filename (struct dso *dso,char *filename,size_t filename_size) +{ +char filepath[PATH_MAX ]; + +/* +* If we don't have build-ids or the build-id file isn't in the +* cache, or is just a kallsyms file, well, lets hope that this +* DSO is the same as when 'perf record' ran. +*/ +if ((dso__kernel (dso) ||dso__is_vdso (dso)) &&dso__long_name (dso)[0 ] =='/' ) +snprintf (filepath,sizeof (filepath),"%s" ,dso__long_name (dso)); +else +__symbol__join_symfs (filepath,sizeof (filepath),dso__long_name (dso)); + +mutex_lock (dso__lock (dso)); +if (access (filepath,R_OK ) && errno ==ENOENT &&dso__nsinfo (dso)) { +char *new_name =dso__filename_with_chroot (dso, filepath); +if (new_name) { +strlcpy (filepath, new_name,sizeof (filepath)); +free (new_name); + } + } +mutex_unlock (dso__lock (dso)); + +if (access (filepath,R_OK ) && errno ==ENOENT ) +return ENOENT ; + +snprintf (filename, filename_size,"%s" , filepath); +return 0 ; +} + +static int dso__disassemble_filename (struct dso *dso,char *filename,size_t filename_size) +{ +char linkname[PATH_MAX ]; +char *build_id_filename; +if (dso__symtab_type (dso) ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso))return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX ;
@@ -1111,57 +1169,28 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil }else {if (dso__has_build_id (dso))return ENOMEM ; - goto fallback; +return fallback_filename (dso, filename, filename_size); } - build_id_path =strdup (filename); -if (!build_id_path) -return ENOMEM ; - -/* -* old style build-id cache has name of XX/XXXXXXX.. while -* new style has XX/XXXXXXX../{elf,kallsyms,vdso}. -* extract the build-id part of dirname in the new style only. -*/ - pos =strrchr (build_id_path,'/' ); -if (pos &&strlen (pos) <SBUILD_ID_SIZE -2 ) -dirname (build_id_path); +if (access (filename,R_OK )) +return fallback_filename (dso, filename, filename_size); -if (dso__is_kcore (dso)) +if (dso__is_kcore (dso) ||dso__is_vdso (dso)) goto fallback; - len =readlink (build_id_path, linkname,sizeof (linkname) -1 ); -if (len <0 ) - goto fallback; +if (!read_buildid_linkname (filename, linkname,sizeof (linkname) -1 ) && + (!strstr (linkname,DSO__NAME_KALLSYMS ) && !strstr (linkname,DSO__NAME_VDSO ))) { +/* not kallsysms or vdso, use build_id path found above */ + goto out; + } - linkname[len] ='\0' ; -if (strstr (linkname,DSO__NAME_KALLSYMS ) ||strstr (linkname,DSO__NAME_VDSO ) || -access (filename,R_OK )) { fallback: -/* -* If we don't have build-ids or the build-id file isn't in the -* cache, or is just a kallsyms file, well, lets hope that this -* DSO is the same as when 'perf record' ran. -*/ -if ((dso__kernel (dso) ||dso__is_vdso (dso)) &&dso__long_name (dso)[0 ] =='/' ) -snprintf (filename, filename_size,"%s" ,dso__long_name (dso)); -else -__symbol__join_symfs (filename, filename_size,dso__long_name (dso)); - -mutex_lock (dso__lock (dso)); -if (access (filename,R_OK ) && errno ==ENOENT &&dso__nsinfo (dso)) { -char *new_name =dso__filename_with_chroot (dso, filename); -if (new_name) { -strlcpy (filename, new_name, filename_size); -free (new_name); - } - } -mutex_unlock (dso__lock (dso)); - }else if (dso__binary_type (dso) ==DSO_BINARY_TYPE__NOT_FOUND ) { -dso__set_binary_type (dso,DSO_BINARY_TYPE__BUILD_ID_CACHE ); +if (fallback_filename (dso, filename, filename_size)) { +/* if fallback failed, use build_id path found above */ +out: +if (dso__binary_type (dso) ==DSO_BINARY_TYPE__NOT_FOUND ) +dso__set_binary_type (dso,DSO_BINARY_TYPE__BUILD_ID_CACHE ); } - -free (build_id_path);return 0 ; }
Signature · 1 line
2.34.1
Namhyung Kim
maintainerRe: [PATCH v3 2/4] perf: disasm: use build_id_path if fallback failed
Hello,
Quoted 5 lines · Changbin Du
If we can not fallback for special dso (vmlinx and vdso), use the
build_id_pathfound previously.To make change easy, this change first refactors the code by extracting two functions
read_buildid_linkname()andfallback_filename().
Can you please split the refactoring from the actual change? It'd be easier to review and to maintain the code.
Thanks,
Namhyung
Quoted 161 lines
Signed-off-by Changbin Du <[email protected]>--- tools/perf/util/disasm.c | 121 ++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 46 deletions(-)tools/perf/util/disasm.c +75
-46@@ -1092,14 +1092,72 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, sreturn 0 ; } -static int dso__disassemble_filename (struct dso *dso,char *filename,size_t filename_size) +static int read_buildid_linkname (char *filename,char *linkname,size_t linkname_size) { -char linkname[PATH_MAX ]; -char *build_id_filename;char *build_id_path =NULL ;char *pos;int len; + build_id_path =strdup (filename); +if (!build_id_path) +return ENOMEM ; + +/* +* old style build-id cache has name of XX/XXXXXXX.. while +* new style has XX/XXXXXXX../{elf,kallsyms,vdso}. +* extract the build-id part of dirname in the new style only. +*/ + pos =strrchr (build_id_path,'/' ); +if (pos &&strlen (pos) <SBUILD_ID_SIZE -2 ) +dirname (build_id_path); + + len =readlink (build_id_path, linkname, linkname_size); +if (len <0 ) { +free (build_id_path); +return -1 ; + } + + linkname[len] ='\0' ; +free (build_id_path); +return 0 ; +} + +static int fallback_filename (struct dso *dso,char *filename,size_t filename_size) +{ +char filepath[PATH_MAX ]; + +/* +* If we don't have build-ids or the build-id file isn't in the +* cache, or is just a kallsyms file, well, lets hope that this +* DSO is the same as when 'perf record' ran. +*/ +if ((dso__kernel (dso) ||dso__is_vdso (dso)) &&dso__long_name (dso)[0 ] =='/' ) +snprintf (filepath,sizeof (filepath),"%s" ,dso__long_name (dso)); +else +__symbol__join_symfs (filepath,sizeof (filepath),dso__long_name (dso)); + +mutex_lock (dso__lock (dso)); +if (access (filepath,R_OK ) && errno ==ENOENT &&dso__nsinfo (dso)) { +char *new_name =dso__filename_with_chroot (dso, filepath); +if (new_name) { +strlcpy (filepath, new_name,sizeof (filepath)); +free (new_name); + } + } +mutex_unlock (dso__lock (dso)); + +if (access (filepath,R_OK ) && errno ==ENOENT ) +return ENOENT ; + +snprintf (filename, filename_size,"%s" , filepath); +return 0 ; +} + +static int dso__disassemble_filename (struct dso *dso,char *filename,size_t filename_size) +{ +char linkname[PATH_MAX ]; +char *build_id_filename; +if (dso__symtab_type (dso) ==DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore (dso))return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX ;@@ -1111,57 +1169,28 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil }else {if (dso__has_build_id (dso))return ENOMEM ; - goto fallback; +return fallback_filename (dso, filename, filename_size); } - build_id_path =strdup (filename); -if (!build_id_path) -return ENOMEM ; - -/* -* old style build-id cache has name of XX/XXXXXXX.. while -* new style has XX/XXXXXXX../{elf,kallsyms,vdso}. -* extract the build-id part of dirname in the new style only. -*/ - pos =strrchr (build_id_path,'/' ); -if (pos &&strlen (pos) <SBUILD_ID_SIZE -2 ) -dirname (build_id_path); +if (access (filename,R_OK )) +return fallback_filename (dso, filename, filename_size); -if (dso__is_kcore (dso)) +if (dso__is_kcore (dso) ||dso__is_vdso (dso)) goto fallback; - len =readlink (build_id_path, linkname,sizeof (linkname) -1 ); -if (len <0 ) - goto fallback; +if (!read_buildid_linkname (filename, linkname,sizeof (linkname) -1 ) && + (!strstr (linkname,DSO__NAME_KALLSYMS ) && !strstr (linkname,DSO__NAME_VDSO ))) { +/* not kallsysms or vdso, use build_id path found above */ + goto out; + } - linkname[len] ='\0' ; -if (strstr (linkname,DSO__NAME_KALLSYMS ) ||strstr (linkname,DSO__NAME_VDSO ) || -access (filename,R_OK )) { fallback: -/* -* If we don't have build-ids or the build-id file isn't in the -* cache, or is just a kallsyms file, well, lets hope that this -* DSO is the same as when 'perf record' ran. -*/ -if ((dso__kernel (dso) ||dso__is_vdso (dso)) &&dso__long_name (dso)[0 ] =='/' ) -snprintf (filename, filename_size,"%s" ,dso__long_name (dso)); -else -__symbol__join_symfs (filename, filename_size,dso__long_name (dso)); - -mutex_lock (dso__lock (dso)); -if (access (filename,R_OK ) && errno ==ENOENT &&dso__nsinfo (dso)) { -char *new_name =dso__filename_with_chroot (dso, filename); -if (new_name) { -strlcpy (filename, new_name, filename_size); -free (new_name); - } - } -mutex_unlock (dso__lock (dso)); - }else if (dso__binary_type (dso) ==DSO_BINARY_TYPE__NOT_FOUND ) { -dso__set_binary_type (dso,DSO_BINARY_TYPE__BUILD_ID_CACHE ); +if (fallback_filename (dso, filename, filename_size)) { +/* if fallback failed, use build_id path found above */ +out: +if (dso__binary_type (dso) ==DSO_BINARY_TYPE__NOT_FOUND ) +dso__set_binary_type (dso,DSO_BINARY_TYPE__BUILD_ID_CACHE ); } - -free (build_id_path);return 0 ; }Signature · 1 line
2.34.1
Re: [PATCH v3 2/4] perf: disasm: use build_id_path if fallback failed
Quoted 12 lines · Namhyung Kim
Hello,
Quoted 5 lines · Changbin Du
If we can not fallback for special dso (vmlinx and vdso), use the
build_id_pathfound previously.To make change easy, this change first refactors the code by extracting two functions
read_buildid_linkname()andfallback_filename().Can you please split the refactoring from the actual change? It'd be easier to review and to maintain the code.
Sure, I'll do it taday.
Quoted 3 lines
Thanks,
Namhyung
Signature · 2 lines
Cheers, Changbin Du
PATCH v3 3/4 perf: symbol: generalize vmlinux path searching
In reply to Changbin DuThis generalizes the vmlinux path searching logic. Later we will add another instance for vdso.
The search pattern is described by struct dso_filename_pattern, and the formatted paths are hold in struct dso_filename_paths.
--- tools/perf/util/machine.c | 4 +- tools/perf/util/symbol.c | 112 +++++++++++++++++++++----------------- tools/perf/util/symbol.h | 8 ++- 3 files changed, 70 insertions(+), 54 deletions(-)
tools/perf/util/machine.c +2 -2
@@ -896,9 +896,9 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp) printed +=fprintf (fp,"[0] %s\n" , filename); } -for (i =0 ; i < vmlinux_path__nr_entries; ++i) { +for (i =0 ; i < vmlinux_paths.nr_entries; ++i) { printed +=fprintf (fp,"[%d] %s\n" , i +dso__has_build_id (kdso), - vmlinux_path[i]); + vmlinux_paths.paths[i]); }return printed; }
tools/perf/util/symbol.c +62 -50
175 lines not on this page · raw message
tools/perf/util/symbol.h +6 -2
@@ -101,8 +101,12 @@ static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)#define symbol__join_symfs (bf, path) __symbol__join_symfs(bf, sizeof(bf), path) -extern int vmlinux_path__nr_entries; -extern char **vmlinux_path; +struct dso_filename_paths { +int nr_entries; +char **paths; +}; + +extern struct dso_filename_paths vmlinux_paths;static inline void *symbol__priv (struct symbol *sym) {
Signature · 1 line
2.34.1
PATCH v3 4/4 perf: symbol: try to seach vdso path if not given by user
In reply to Changbin DuJust like vmlinux, try to search vdso in predefined path if it's not given by user. The searched path usually has debugging info.
For example, the vdso can be found in /lib/modules/<version>/build/arch/x86/entry/vdso/vdso*.so.dbg for local build on x86.
--- tools/perf/builtin-annotate.c | 1 + tools/perf/builtin-kallsyms.c | 2 ++ tools/perf/builtin-probe.c | 2 ++ tools/perf/builtin-top.c | 2 ++ tools/perf/tests/builtin-test.c | 3 ++- tools/perf/util/symbol.c | 41 +++++++++++++++++++++++++++++++++ tools/perf/util/symbol.h | 1 + tools/perf/util/symbol_conf.h | 1 + 8 files changed, 52 insertions(+), 1 deletion(-)
tools/perf/builtin-annotate.c +1 -0
@@ -883,6 +883,7 @@ int cmd_annotate(int argc, const char **argv) goto out_delete; symbol_conf.try_vmlinux_path = true; + symbol_conf.try_vdso_path = true; ret =symbol__init (&annotate.session->header.env);if (ret <0 )
tools/perf/builtin-kallsyms.c +2 -0
@@ -63,6 +63,8 @@ int cmd_kallsyms(int argc, const char **argv)usage_with_options (kallsyms_usage, options); symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name ==NULL ); + symbol_conf.try_vdso_path = (symbol_conf.vdso_name[0 ] ==NULL && + symbol_conf.vdso_name[1 ] ==NULL );if (symbol__init (NULL ) <0 )return -1 ;
tools/perf/builtin-probe.c +2 -0
@@ -667,6 +667,8 @@ __cmd_probe(int argc, const char **argv)* Only consider the user's kernel image path if given. */ symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name ==NULL ); + symbol_conf.try_vdso_path = (symbol_conf.vdso_name[0 ] ==NULL && + symbol_conf.vdso_name[1 ] ==NULL );/* * Except for --list, --del and --add, other command doesn't depend
tools/perf/builtin-top.c +2 -0
@@ -1792,6 +1792,8 @@ int cmd_top(int argc, const char **argv)annotation_config__init (); symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name ==NULL ); + symbol_conf.try_vdso_path = (symbol_conf.vdso_name[0 ] ==NULL && + symbol_conf.vdso_name[1 ] ==NULL ); status =symbol__init (NULL );if (status <0 ) goto out_delete_evlist;
tools/perf/tests/builtin-test.c +2 -1
@@ -575,7 +575,8 @@ int cmd_test(int argc, const char **argv) symbol_conf.priv_size =sizeof (int ); symbol_conf.try_vmlinux_path = true; - + symbol_conf.try_vdso_path = (symbol_conf.vdso_name[0 ] ==NULL && + symbol_conf.vdso_name[1 ] ==NULL );if (symbol__init (NULL ) <0 )return -1 ;
tools/perf/util/symbol.c +41 -0
82 lines not on this page · raw message
tools/perf/util/symbol.h +1 -0
@@ -107,6 +107,7 @@ struct dso_filename_paths { };extern struct dso_filename_paths vmlinux_paths; +extern struct dso_filename_paths vdso_paths;static inline void *symbol__priv (struct symbol *sym) {
tools/perf/util/symbol_conf.h +1 -0
@@ -12,6 +12,7 @@ struct symbol_conf {bool nanosecs;unsigned short priv_size;bool try_vmlinux_path, + try_vdso_path, init_annotation, force, ignore_vmlinux,
Signature · 1 line
2.34.1