From ca868f0e5e76020f13bb5f0bca6ddd21f2bdf7ab Mon Sep 17 00:00:00 2001 From: anton Date: Tue, 18 Sep 2018 18:25:31 +0000 Subject: [PATCH] Backport support for option -a to addr2line, which will display each address given as input before the resolved source location. This change was introduced to bintutils after the switch from GPLv2 but the author Tristan Gingold granted me permission relicense the diff under GPLv2; thanks! Taken as is from binutils commit be6f64938f985dfb0eaa2107b99f193bb865ce04 This option is used by the syzkaller kernel fuzzer to produce a human readable representation of the coverage collected by kcov. ok deraadt@ jca@ visa@ --- gnu/usr.bin/binutils-2.17/binutils/addr2line.c | 15 ++++++++++++++- .../binutils-2.17/binutils/doc/binutils.texi | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gnu/usr.bin/binutils-2.17/binutils/addr2line.c b/gnu/usr.bin/binutils-2.17/binutils/addr2line.c index 47367093140..5a8d42e1285 100644 --- a/gnu/usr.bin/binutils-2.17/binutils/addr2line.c +++ b/gnu/usr.bin/binutils-2.17/binutils/addr2line.c @@ -40,6 +40,7 @@ #include "budemang.h" static bfd_boolean unwind_inlines; /* -i, unwind inlined functions. */ +static bfd_boolean with_addresses; /* -a, show addresses. */ static bfd_boolean with_functions; /* -f, show function names. */ static bfd_boolean do_demangle; /* -C, demangle names. */ static bfd_boolean base_names; /* -s, strip directory names. */ @@ -51,6 +52,7 @@ static asymbol **syms; /* Symbol table. */ static struct option long_options[] = { + {"addresses", no_argument, NULL, 'a'}, {"basenames", no_argument, NULL, 's'}, {"demangle", optional_argument, NULL, 'C'}, {"exe", required_argument, NULL, 'e'}, @@ -80,6 +82,7 @@ usage (FILE *stream, int status) fprintf (stream, _(" If no addresses are specified on the command line, they will be read from stdin\n")); fprintf (stream, _(" The options are:\n\ @ Read options from \n\ + -a --addresses Show addresses\n\ -b --target= Set the binary file format\n\ -e --exe= Set the input file name (default is a.out)\n\ -i --inlines Unwind inlined functions\n\ @@ -200,6 +203,13 @@ translate_addresses (bfd *abfd, asection *section) pc = bfd_scan_vma (*addr++, NULL, 16); } + if (with_addresses) + { + printf ("0x"); + bfd_printf_vma (abfd, pc); + printf ("\n"); + } + found = FALSE; if (section) find_offset_in_section (abfd, section); @@ -345,13 +355,16 @@ main (int argc, char **argv) file_name = NULL; section_name = NULL; target = NULL; - while ((c = getopt_long (argc, argv, "b:Ce:sfHhij:Vv", long_options, (int *) 0)) + while ((c = getopt_long (argc, argv, "ab:Ce:sfHhij:Vv", long_options, (int *) 0)) != EOF) { switch (c) { case 0: break; /* We've been given a long option. */ + case 'a': + with_addresses = TRUE; + break; case 'b': target = optarg; break; diff --git a/gnu/usr.bin/binutils-2.17/binutils/doc/binutils.texi b/gnu/usr.bin/binutils-2.17/binutils/doc/binutils.texi index 567954ced18..0668b85d933 100644 --- a/gnu/usr.bin/binutils-2.17/binutils/doc/binutils.texi +++ b/gnu/usr.bin/binutils-2.17/binutils/doc/binutils.texi @@ -2602,7 +2602,8 @@ c++filt @var{option} @var{symbol} @smallexample @c man begin SYNOPSIS addr2line -addr2line [@option{-b} @var{bfdname}|@option{--target=}@var{bfdname}] +addr2line [@option{-a}|@option{--addresses}] + [@option{-b} @var{bfdname}|@option{--target=}@var{bfdname}] [@option{-C}|@option{--demangle}[=@var{style}]] [@option{-e} @var{filename}|@option{--exe=}@var{filename}] [@option{-f}|@option{--functions}] [@option{-s}|@option{--basename}] @@ -2653,6 +2654,11 @@ The long and short forms of options, shown here as alternatives, are equivalent. @table @env +@item -a +@itemx --addresses +Display the address before the function name, file and line number information. +The address is printed with a @samp{0x} prefix to easily identify it. + @item -b @var{bfdname} @itemx --target=@var{bfdname} @cindex object code format -- 2.20.1