* Re: [PATCH 3/5] addr2line: Add -a, --address. Print address before for each entry.
@ 2015-05-21 13:46 Mark Wielaard
0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2015-05-21 13:46 UTC (permalink / raw)
To: elfutils-devel
[-- Attachment #1: Type: text/plain, Size: 1083 bytes --]
On Wed, 2015-05-20 at 11:22 -0700, Roland McGrath wrote:
> > static int
> > +get_addr_width (Dwfl_Module *mod)
> > +{
> > + // Try to find the address wide if possible.
>
> s/wide/width/
Fixed. One day I will learn this funky English language...
> > + if (width == 0 && mod)
>
> mod != NULL please, and other cases like that below.
Fixed 3 times.
> > + if (print_addresses)
> > + {
> > + int width = get_addr_width (mod);
> > + printf ("0x%0*" PRIx64 "\n", width, addr);
> > + }
>
> I tend to prefer %.* though it has the same effect for hex. I also tend to
> prefer %# to 0x%. IIRC, that includes the 0x in the width but not in the
> precision, so "%#.*" PRIx64 is probably best. The only real difference is
> 0x0 vs 0, but for some reason I really hate seeing "0x%".
Changed to use %.* but kept the 0x sorry. The reason is indeed the
different treatment of 0. With %# that is just inconsistent. You could
write printf ("%s%#0*" PRIx64 "\n", addr == 0 ? "0x" : "", width, addr);
but that seems silly.
Cheers,
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 3/5] addr2line: Add -a, --address. Print address before for each entry.
@ 2015-05-20 18:22 Roland McGrath
0 siblings, 0 replies; 3+ messages in thread
From: Roland McGrath @ 2015-05-20 18:22 UTC (permalink / raw)
To: elfutils-devel
[-- Attachment #1: Type: text/plain, Size: 651 bytes --]
> static int
> +get_addr_width (Dwfl_Module *mod)
> +{
> + // Try to find the address wide if possible.
s/wide/width/
> + if (width == 0 && mod)
mod != NULL please, and other cases like that below.
> + if (print_addresses)
> + {
> + int width = get_addr_width (mod);
> + printf ("0x%0*" PRIx64 "\n", width, addr);
> + }
I tend to prefer %.* though it has the same effect for hex. I also tend to
prefer %# to 0x%. IIRC, that includes the 0x in the width but not in the
precision, so "%#.*" PRIx64 is probably best. The only real difference is
0x0 vs 0, but for some reason I really hate seeing "0x%".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 3/5] addr2line: Add -a, --address. Print address before for each entry.
@ 2015-05-20 14:35 Mark Wielaard
0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2015-05-20 14:35 UTC (permalink / raw)
To: elfutils-devel
[-- Attachment #1: Type: text/plain, Size: 7296 bytes --]
Adds test cases with sample output.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
NEWS | 2 ++
src/ChangeLog | 8 +++++++
src/addr2line.c | 38 ++++++++++++++++++++++++++++++-
tests/ChangeLog | 5 ++++
tests/run-addr2line-i-test.sh | 53 +++++++++++++++++++++++++++++++++++++++++++
tests/run-addr2line-test.sh | 36 +++++++++++++++++++++++++++++
6 files changed, 141 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 60aa995..6d81e59 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ Version 0.162
libdw: Install new header elfutils/known-dwarf.h.
+addr2line: New option -a, --addresses to print address before each entry.
+
Version 0.161
libdw: New function dwarf_peel_type. dwarf_aggregate_size now uses
diff --git a/src/ChangeLog b/src/ChangeLog
index 284b886..127e601 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,13 @@
2015-05-20 Mark Wielaard <mjw@redhat.com>
+ * addr2line.c (argp_option): Add "addresses", 'a'.
+ (print_addresses): New static bool.
+ (parse_opt): Set print_addresses.
+ (get_addr_width): New static function.
+ (handle_address): Print address if print_addresses is true.
+
+2015-05-20 Mark Wielaard <mjw@redhat.com>
+
* addr2line.c (handle_address): Call strtoumax with base 16. Make
sure all input has been processed.
diff --git a/src/addr2line.c b/src/addr2line.c
index b1ff368..4416c7a 100644
--- a/src/addr2line.c
+++ b/src/addr2line.c
@@ -1,5 +1,5 @@
/* 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.
@@ -59,6 +59,7 @@ static const struct argp_option options[] =
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 },
@@ -100,6 +101,8 @@ static const struct argp argp =
/* 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;
@@ -210,6 +213,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
state->child_inputs[0] = state->input;
break;
+ case 'a':
+ print_addresses = true;
+ break;
+
case 'b':
case 'C':
case OPT_DEMANGLER:
@@ -529,6 +536,29 @@ print_src (const char *src, int lineno, int linecol, Dwarf_Die *cu)
}
static int
+get_addr_width (Dwfl_Module *mod)
+{
+ // Try to find the address wide if possible.
+ static int width = 0;
+ if (width == 0 && mod)
+ {
+ Dwarf_Addr bias;
+ Elf *elf = dwfl_module_getelf (mod, &bias);
+ if (elf)
+ {
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr)
+ 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)
{
char *endp;
@@ -582,6 +612,12 @@ 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%0*" PRIx64 "\n", width, addr);
+ }
+
if (show_functions)
{
/* First determine the function name. Use the DWARF information if
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 0e31012..d3a0e4b 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,10 @@
2015-05-20 Mark Wielaard <mjw@redhat.com>
+ * run-addr2line-test.sh: Add -a test variants.
+ * run-addr2line-i-test.sh: Likewise.
+
+2015-05-20 Mark Wielaard <mjw@redhat.com>
+
* run-addrname-test.sh: Make sure all input addresses are hex.
2015-05-04 Max Filippov <jcmvbkbc@gmail.com>
diff --git a/tests/run-addr2line-i-test.sh b/tests/run-addr2line-i-test.sh
index 183916c..e62aa20 100755
--- a/tests/run-addr2line-i-test.sh
+++ b/tests/run-addr2line-i-test.sh
@@ -144,4 +144,57 @@ _Z2fuv
/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
diff --git a/tests/run-addr2line-test.sh b/tests/run-addr2line-test.sh
index 768006b..8d06064 100755
--- a/tests/run-addr2line-test.sh
+++ b/tests/run-addr2line-test.sh
@@ -71,4 +71,40 @@ echo "# stdin without newline symbol, just EOF."
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
--
1.8.3.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-21 13:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-21 13:46 [PATCH 3/5] addr2line: Add -a, --address. Print address before for each entry Mark Wielaard
-- strict thread matches above, loose matches on Subject: below --
2015-05-20 18:22 Roland McGrath
2015-05-20 14:35 Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).