From 60fc84c4288cd6edda3a78dff95e52b5858bacb2 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 3 Aug 2007 21:59:15 +0000 Subject: 2007-08-03 Roland McGrath * readelf.c (print_string_sections): New variable. (options, parse_opt): Handle --strings/-p to set it. (print_strings): New function. (process_elf_file): Call it under -p. * readelf.c (options): Add hidden aliases --segments, --sections, as taken by binutils readelf. --- src/addr2line.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/addr2line.c') diff --git a/src/addr2line.c b/src/addr2line.c index a112d348..394d0655 100644 --- a/src/addr2line.c +++ b/src/addr2line.c @@ -66,6 +66,7 @@ static const struct argp_option options[] = { "absolute", 'A', NULL, 0, N_("Show absolute file names using compilation directory"), 0 }, { "functions", 'f', NULL, 0, N_("Also show function names"), 0 }, + { "symbols", 'S', NULL, 0, N_("Also show symbol or section names"), 0 }, { NULL, 0, NULL, 0, N_("Miscellaneous:"), 0 }, /* Unsupported options. */ @@ -107,6 +108,9 @@ static bool use_comp_dir; /* True if function names should be shown. */ static bool show_functions; +/* True if ELF symbol or section info should be shown. */ +static bool show_symbols; + int main (int argc, char *argv[]) @@ -221,6 +225,10 @@ parse_opt (int key, char *arg __attribute__ ((unused)), show_functions = true; break; + case 'S': + show_symbols = true; + break; + default: return ARGP_ERR_UNKNOWN; } @@ -297,6 +305,29 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr) return false; } +static void +print_addrsym (Dwfl_Module *mod, GElf_Addr addr) +{ + GElf_Sym s; + GElf_Word shndx; + const char *name = dwfl_module_addrsym (mod, addr, &s, &shndx); + if (name == NULL) + { + /* No symbol name. Get a section name instead. */ + int i = dwfl_module_relocate_address (mod, &addr); + if (i >= 0) + name = dwfl_module_relocation_info (mod, i, NULL); + if (name == NULL) + puts ("??"); + else + printf ("(%s)+%#" PRIx64 "\n", name, addr); + } + else if (addr == s.st_value) + puts (name); + else + printf ("%s+%#" PRIx64 "\n", name, addr - s.st_value); +} + static void handle_address (GElf_Addr addr, Dwfl *dwfl) { @@ -306,10 +337,13 @@ handle_address (GElf_Addr addr, Dwfl *dwfl) { /* First determine the function name. Use the DWARF information if possible. */ - if (! print_dwarf_function (mod, addr)) + if (! print_dwarf_function (mod, addr) && !show_symbols) puts (dwfl_module_addrname (mod, addr) ?: "??"); } + if (show_symbols) + print_addrsym (mod, addr); + Dwfl_Line *line = dwfl_module_getsrc (mod, addr); const char *src; -- cgit v1.2.3