This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] addr2line: display the address


Hi,

some of our users found useful to have the address in the output of addr2line.  With it, they can check
that it was correctly parsed and they easily relate the function and line to the address.
It is also useful as it acts as a separate when -i/--inlines is used.

Tristan.

binutils/
2009-12-04  Tristan Gingold  <gingold@adacore.com>

        * addr2line.c (translate_addresses): Display addresses
        if option -a is used.
        (with_addresses): New variable.
        (long_options): Add option '-a'.
        (usage): Add usage for option '-a'.
        (main): Handle option '-a'.
        * doc/binutils.texi (addr2line): Document option '-a'.

diff -c -r1.35 addr2line.c
*** addr2line.c	1 Oct 2009 06:33:15 -0000	1.35
--- addr2line.c	4 Dec 2009 13:37:10 -0000
***************
*** 39,44 ****
--- 39,45 ----
  #include "bucomm.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.  */
***************
*** 50,55 ****
--- 51,57 ----
  
  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'},
***************
*** 78,83 ****
--- 80,86 ----
    fprintf (stream, _(" If no addresses are specified on the command line, they will be read from stdin\n"));
    fprintf (stream, _(" The options are:\n\
    @<file>                Read options from <file>\n\
+   -a --addresses         Show addresses\n\
    -b --target=<bfdname>  Set the binary file format\n\
    -e --exe=<executable>  Set the input file name (default is a.out)\n\
    -i --inlines           Unwind inlined functions\n\
***************
*** 209,214 ****
--- 212,224 ----
  	  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);
***************
*** 354,366 ****
    file_name = NULL;
    section_name = NULL;
    target = NULL;
!   while ((c = getopt_long (argc, argv, "b:Ce:sfHhij:Vv", long_options, (int *) 0))
  	 != EOF)
      {
        switch (c)
  	{
  	case 0:
  	  break;		/* We've been given a long option.  */
  	case 'b':
  	  target = optarg;
  	  break;
--- 364,379 ----
    file_name = NULL;
    section_name = NULL;
    target = NULL;
!   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;
Index: doc/binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.159
diff -c -r1.159 binutils.texi
*** doc/binutils.texi	3 Dec 2009 12:28:37 -0000	1.159
--- doc/binutils.texi	4 Dec 2009 13:37:11 -0000
***************
*** 2906,2912 ****
  
  @smallexample
  @c man begin SYNOPSIS addr2line
! addr2line [@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}]
--- 2906,2913 ----
  
  @smallexample
  @c man begin SYNOPSIS addr2line
! 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}]
***************
*** 2943,2949 ****
  line number for each address is printed on a separate line.  If the
  @command{-f} option is used, then each @samp{FILENAME:LINENO} line is
  preceded by a @samp{FUNCTIONNAME} line which is the name of the function
! containing the address.
  
  If the file name or function name can not be determined,
  @command{addr2line} will print two question marks in their place.  If the
--- 2944,2951 ----
  line number for each address is printed on a separate line.  If the
  @command{-f} option is used, then each @samp{FILENAME:LINENO} line is
  preceded by a @samp{FUNCTIONNAME} line which is the name of the function
! containing the address.  If the @command{-a} option is used, then the
! address read is first printed.
  
  If the file name or function name can not be determined,
  @command{addr2line} will print two question marks in their place.  If the
***************
*** 2957,2962 ****
--- 2959,2970 ----
  equivalent.
  
  @table @env
+ @item -a
+ @itemx --addresses
+ Display address before function names or 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]