Use "nm -D" to retrieve also the symbols of crash when having stripped binaries. Use the presence of the symbol table to determine if the binary has been stripped or not. Signed-off-by: Bernhard Walle <bwalle@xxxxxxx> 2 files changed, 35 insertions(+), 1 deletion(-) defs.h | 1 + symbols.c | 35 ++++++++++++++++++++++++++++++++++-
Use "nm -D" to retrieve also the symbols of crash when having stripped binaries. Use the presence of the symbol table to determine if the binary has been stripped or not. Signed-off-by: Bernhard Walle <bwalle@xxxxxxx> diff --git a/defs.h b/defs.h --- a/defs.h +++ b/defs.h @@ -3296,6 +3296,7 @@ void dump_offset_table(char *, ulong); int is_elf_file(char *); int is_kernel(char *); +int is_binary_stripped(char *filename); int file_elf_version(char *); int is_system_map(char *); int select_namelist(char *); diff --git a/symbols.c b/symbols.c --- a/symbols.c +++ b/symbols.c @@ -2719,6 +2719,32 @@ return TRUE; } +int +is_binary_stripped(char *filename) +{ +#if defined(GDB_6_0) || defined(GDB_6_1) + struct bfd *bfd; +#else + struct _bfd *bfd; +#endif + + if ((bfd = bfd_openr(filename, NULL)) == NULL) { + error(INFO, "Cannot open ELF file: %s\n", filename); + return FALSE; + } + + if (!bfd_check_format(bfd, bfd_object)) { + error(INFO, "Invalid ELF file: %s\n", filename); + return FALSE; + } + + int number_of_symbols; + number_of_symbols = bfd_canonicalize_symtab(bfd, NULL); + + bfd_close(bfd); + + return number_of_symbols == 0; +} /* * This command may be used to: @@ -9051,6 +9077,8 @@ ulong vaddr, lookfor; ulong last_vaddr; char symbol[BUFSIZE]; + int stripped_binary; + const char *nm_call; fflush(fp); fflush(stdout); @@ -9073,11 +9101,16 @@ return; } + stripped_binary = is_binary_stripped(thisfile); + nm_call = stripped_binary + ? "/usr/bin/nm -DBn %s" + : "/usr/bin/nm -Bn %s"; + for (i = 0; i < NUMBER_STACKFRAMES; i++) { if (!(lookfor = retaddr[i])) continue; - sprintf(buf, "/usr/bin/nm -Bn %s", thisfile); + sprintf(buf, nm_call, thisfile); if (!(pipe = popen(buf, "r"))) { perror("pipe"); break;
-- Crash-utility mailing list Crash-utility@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/crash-utility