perf symbols: Follow .gnu_debuglink section to find separate symbols
PATCH v2 1/1 perf symbols: Follow .gnu_debuglink section to find separate symbols
The .gnu_debuglink section is specified to contain the filename of the debug info file, as well as a CRC that can be used to validate it.
This doesn't currently use the checksum and relies on the usual build-id matching for validation.
This provides more context:
http://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
--- tools/perf/util/symbol.c | 65 +++++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/symbol.h | 1 + 2 files changed, 65 insertions(+), 1 deletion(-)
tools/perf/util/symbol.c +64 -1
@@ -1590,11 +1590,62 @@ out:return err; } +static int filename__read_debuglink (const char *filename, +char *debuglink,size_t size) +{ +int fd, err =-1 ; +Elf *elf; +GElf_Ehdr ehdr; +GElf_Shdr shdr; +Elf_Data *data; +Elf_Scn *sec; +Elf_Kind ek; + + fd =open (filename,O_RDONLY ); +if (fd <0 ) + goto out; + + elf =elf_begin (fd,PERF_ELF_C_READ_MMAP ,NULL ); +if (elf ==NULL ) { +pr_debug2 ("%s: cannot read %s ELF file.\n" , __func__, filename); + goto out_close; + } + + ek =elf_kind (elf); +if (ek !=ELF_K_ELF ) + goto out_close; + +if (gelf_getehdr (elf, &ehdr) ==NULL ) { +pr_err ("%s: cannot get elf header.\n" , __func__); + goto out_close; + } + + sec =elf_section_by_name (elf, &ehdr, &shdr, +".gnu_debuglink" ,NULL ); +if (sec ==NULL ) + goto out_close; + + data =elf_getdata (sec,NULL ); +if (data ==NULL ) + goto out_close; + +/* the start of this section is a zero-terminated string */ +strncpy (debuglink, data->d_buf, size); + +elf_end (elf); + +out_close: +close (fd); +out: +return err; +} +char dso__symtab_origin (const struct dso *dso) {static const char origin[] = { [SYMTAB__KALLSYMS ] ='k' , [SYMTAB__JAVA_JIT ] ='j' , + [SYMTAB__DEBUGLINK ] ='l' , [SYMTAB__BUILD_ID_CACHE ] ='B' , [SYMTAB__FEDORA_DEBUGINFO ] ='f' , [SYMTAB__UBUNTU_DEBUGINFO ] ='u' ,
@@ -1662,10 +1713,22 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)*/ want_symtab =1 ; restart: -for (dso->symtab_type =SYMTAB__BUILD_ID_CACHE ; +for (dso->symtab_type =SYMTAB__DEBUGLINK ; dso->symtab_type !=SYMTAB__NOT_FOUND ; dso->symtab_type++) {switch (dso->symtab_type) { +case SYMTAB__DEBUGLINK : { +char *debuglink; +strncpy (name, dso->long_name, size); + debuglink = name + dso->long_name_len; +while (debuglink != name && *debuglink !='/' ) + debuglink--; +if (*debuglink =='/' ) + debuglink++; +filename__read_debuglink (dso->long_name, debuglink, + size - (debuglink - name)); + } +break ;case SYMTAB__BUILD_ID_CACHE :/* skip the locally configured cache if a symfs is given */ if (symbol_conf.symfs[0] ||
tools/perf/util/symbol.h +1 -0
@@ -257,6 +257,7 @@ enum symtab_type {SYMTAB__KALLSYMS =0 ,SYMTAB__GUEST_KALLSYMS ,SYMTAB__JAVA_JIT , +SYMTAB__DEBUGLINK ,SYMTAB__BUILD_ID_CACHE ,SYMTAB__FEDORA_DEBUGINFO , SYMTAB__UBUNTU_DEBUGINFO,
Signature · 1 line
1.7.9.5
[tip:perf/core] perf symbols: Follow . gnu_debuglink section to find separate symbols
Commit-ID: 209bd9e3e14712d74c8bebb028afda905d689f1c Gitweb: http://git.kernel.org/tip/209bd9e3e14712d74c8bebb028afda905d689f1c Author: Pierre-Loup A. Griffais <[email protected]> AuthorDate: Fri, 22 Jun 2012 11:38:13 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 27 Jun 2012 13:14:18 -0300
perf symbols: Follow .gnu_debuglink section to find separate symbols
The .gnu_debuglink section is specified to contain the filename of the debug info file, as well as a CRC that can be used to validate it.
This doesn't currently use the checksum and relies on the usual build-id matching for validation.
This provides more context:
http://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
--- tools/perf/util/symbol.c | 65 +++++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/symbol.h | 1 + 2 files changed, 65 insertions(+), 1 deletions(-)
tools/perf/util/symbol.c +64 -1
@@ -1590,11 +1590,62 @@ out:return err; } +static int filename__read_debuglink (const char *filename, +char *debuglink,size_t size) +{ +int fd, err =-1 ; +Elf *elf; +GElf_Ehdr ehdr; +GElf_Shdr shdr; +Elf_Data *data; +Elf_Scn *sec; +Elf_Kind ek; + + fd =open (filename,O_RDONLY ); +if (fd <0 ) + goto out; + + elf =elf_begin (fd,PERF_ELF_C_READ_MMAP ,NULL ); +if (elf ==NULL ) { +pr_debug2 ("%s: cannot read %s ELF file.\n" , __func__, filename); + goto out_close; + } + + ek =elf_kind (elf); +if (ek !=ELF_K_ELF ) + goto out_close; + +if (gelf_getehdr (elf, &ehdr) ==NULL ) { +pr_err ("%s: cannot get elf header.\n" , __func__); + goto out_close; + } + + sec =elf_section_by_name (elf, &ehdr, &shdr, +".gnu_debuglink" ,NULL ); +if (sec ==NULL ) + goto out_close; + + data =elf_getdata (sec,NULL ); +if (data ==NULL ) + goto out_close; + +/* the start of this section is a zero-terminated string */ +strncpy (debuglink, data->d_buf, size); + +elf_end (elf); + +out_close: +close (fd); +out: +return err; +} +char dso__symtab_origin (const struct dso *dso) {static const char origin[] = { [SYMTAB__KALLSYMS ] ='k' , [SYMTAB__JAVA_JIT ] ='j' , + [SYMTAB__DEBUGLINK ] ='l' , [SYMTAB__BUILD_ID_CACHE ] ='B' , [SYMTAB__FEDORA_DEBUGINFO ] ='f' , [SYMTAB__UBUNTU_DEBUGINFO ] ='u' ,
@@ -1662,10 +1713,22 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)*/ want_symtab =1 ; restart: -for (dso->symtab_type =SYMTAB__BUILD_ID_CACHE ; +for (dso->symtab_type =SYMTAB__DEBUGLINK ; dso->symtab_type !=SYMTAB__NOT_FOUND ; dso->symtab_type++) {switch (dso->symtab_type) { +case SYMTAB__DEBUGLINK : { +char *debuglink; +strncpy (name, dso->long_name, size); + debuglink = name + dso->long_name_len; +while (debuglink != name && *debuglink !='/' ) + debuglink--; +if (*debuglink =='/' ) + debuglink++; +filename__read_debuglink (dso->long_name, debuglink, + size - (debuglink - name)); + } +break ;case SYMTAB__BUILD_ID_CACHE :/* skip the locally configured cache if a symfs is given */ if (symbol_conf.symfs[0] ||
tools/perf/util/symbol.h +1 -0
@@ -257,6 +257,7 @@ enum symtab_type {SYMTAB__KALLSYMS =0 ,SYMTAB__GUEST_KALLSYMS ,SYMTAB__JAVA_JIT , +SYMTAB__DEBUGLINK ,SYMTAB__BUILD_ID_CACHE ,SYMTAB__FEDORA_DEBUGINFO , SYMTAB__UBUNTU_DEBUGINFO,