summaryrefslogtreecommitdiffstats
path: root/src/addr2line.c
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2007-08-03 21:59:15 +0000
committerRoland McGrath <[email protected]>2007-08-03 21:59:15 +0000
commit60fc84c4288cd6edda3a78dff95e52b5858bacb2 (patch)
tree53dc93ca398da24e8644488325e552d82e830b3a /src/addr2line.c
parent87d4780beb37f265fa89ffd909e77513ef516180 (diff)
2007-08-03 Roland McGrath <[email protected]>
* 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.
Diffstat (limited to 'src/addr2line.c')
-rw-r--r--src/addr2line.c36
1 files changed, 35 insertions, 1 deletions
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;
}
@@ -298,6 +306,29 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr)
}
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)
{
Dwfl_Module *mod = dwfl_addrmodule (dwfl, addr);
@@ -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;