/* Locate source files and line information for given addresses
- Copyright (C) 2005-2010, 2012, 2013 Red Hat, Inc.
+ Copyright (C) 2005-2010, 2012, 2013, 2015 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2005.
N_("Treat addresses as offsets relative to NAME section."), 0 },
{ NULL, 0, NULL, 0, N_("Output format options:"), 3 },
+ { "addresses", 'a', NULL, 0, N_("Print address before each entry"), 0 },
{ "basenames", 's', NULL, 0, N_("Show only base names of source files"), 0 },
{ "absolute", 'A', NULL, 0,
N_("Show absolute file names using compilation directory"), 0 },
/* Handle ADDR. */
static int handle_address (const char *addr, Dwfl *dwfl);
+/* True when we should print the address for each entry. */
+static bool print_addresses;
/* True if only base names of files should be shown. */
static bool only_basenames;
state->child_inputs[0] = state->input;
break;
+ case 'a':
+ print_addresses = true;
+ break;
+
case 'b':
case 'C':
case OPT_DEMANGLER:
comp_dir, comp_dir_sep, src, lineno);
}
+static int
+get_addr_width (Dwfl_Module *mod)
+{
+ // Try to find the address width if possible.
+ static int width = 0;
+ if (width == 0 && mod != NULL)
+ {
+ Dwarf_Addr bias;
+ Elf *elf = dwfl_module_getelf (mod, &bias);
+ if (elf != NULL)
+ {
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr != NULL)
+ width = ehdr->e_ident[EI_CLASS] == ELFCLASS32 ? 8 : 16;
+ }
+ }
+ if (width == 0)
+ width = 16;
+
+ return width;
+}
+
static int
handle_address (const char *string, Dwfl *dwfl)
{
Dwfl_Module *mod = dwfl_addrmodule (dwfl, addr);
+ if (print_addresses)
+ {
+ int width = get_addr_width (mod);
+ printf ("0x%.*" PRIx64 "\n", width, addr);
+ }
+
if (show_functions)
{
/* First determine the function name. Use the DWARF information if
/tmp/x.cpp:33
EOF
+# All together now (plus function names plus addresses).
+testrun_compare ${abs_top_builddir}/src/addr2line -a -f -i -e testfile-inlines 0x00000000000005a0 0x00000000000005a1 0x00000000000005b0 0x00000000000005b1 0x00000000000005c0 0x00000000000005d0 0x00000000000005e0 0x00000000000005e1 0x00000000000005f0 0x00000000000005f1 0x00000000000005f2 <<\EOF
+0x00000000000005a0
+foobar
+/tmp/x.cpp:5
+0x00000000000005a1
+foobar
+/tmp/x.cpp:6
+0x00000000000005b0
+fubar
+/tmp/x.cpp:10
+0x00000000000005b1
+fubar
+/tmp/x.cpp:11
+0x00000000000005c0
+foobar inlined at /tmp/x.cpp:15 in _Z3barv
+/tmp/x.cpp:5
+bar
+/tmp/x.cpp:15
+0x00000000000005d0
+fubar inlined at /tmp/x.cpp:20 in _Z3bazv
+/tmp/x.cpp:10
+baz
+/tmp/x.cpp:20
+0x00000000000005e0
+foobar inlined at /tmp/x.cpp:15 in _Z3foov
+/tmp/x.cpp:5
+bar
+/tmp/x.cpp:15
+_Z3foov
+/tmp/x.cpp:25
+0x00000000000005e1
+fubar inlined at /tmp/x.cpp:20 in _Z3foov
+/tmp/x.cpp:10
+baz
+/tmp/x.cpp:20
+_Z3foov
+/tmp/x.cpp:26
+0x00000000000005f0
+_Z2fuv
+/tmp/x.cpp:31
+0x00000000000005f1
+fubar inlined at /tmp/x.cpp:32 in _Z2fuv
+/tmp/x.cpp:10
+_Z2fuv
+/tmp/x.cpp:32
+0x00000000000005f2
+foobar inlined at /tmp/x.cpp:33 in _Z2fuv
+/tmp/x.cpp:5
+_Z2fuv
+/tmp/x.cpp:33
+EOF
+
exit 0
echo -n "foo" | testrun ${abs_top_builddir}/src/addr2line -f -e testfile > stdin.nl.out || exit 1
cmp foo.out stdin.nonl.out || exit 1
+tempfiles good.addr.out
+
+cat > good.addr.out <<\EOF
+0x08048468
+foo
+/home/drepper/gnu/new-bu/build/ttt/f.c:3
+0x0804845c
+bar
+/home/drepper/gnu/new-bu/build/ttt/b.c:4
+0x08048468
+foo
+/home/drepper/gnu/new-bu/build/ttt/f.c:3
+0x0804845c
+bar
+/home/drepper/gnu/new-bu/build/ttt/b.c:4
+0x08048468
+foo
+/home/drepper/gnu/new-bu/build/ttt/f.c:3
+0x0804845c
+bar
+/home/drepper/gnu/new-bu/build/ttt/b.c:4
+0x08048468
+foo
+/home/drepper/gnu/new-bu/build/ttt/f.c:3
+0x0804845c
+bar
+/home/drepper/gnu/new-bu/build/ttt/b.c:4
+EOF
+
+echo "# Everything on the command line with addresses"
+cat good.addr.out | testrun_compare ${abs_top_builddir}/src/addr2line -a -f -e testfile 0x08048468 0x0804845c foo bar foo+0x0 bar+0x0 foo-0x0 bar-0x0
+
+echo "# Everything from stdin (with newlines) with addresses."
+cat stdin.nl | testrun ${abs_top_builddir}/src/addr2line -a -f -e testfile > stdin.nl.out || exit 1
+cmp good.addr.out stdin.nl.out || exit 1
+
exit 0