dwarf2_physname patchset:
[deliverable/binutils-gdb.git] / binutils / addr2line.c
index 23643e21ded5ab4496ad3d50b2e2b2d940534075..b49c43a479105776015bfe8788daeb2544b582aa 100644 (file)
@@ -1,6 +1,6 @@
 /* addr2line.c -- convert addresses to line number and function name
-   Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
-   Free Software Foundation, Inc.
+   Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+   2007, 2009  Free Software Foundation, Inc.
    Contributed by Ulrich Lauther <Ulrich.Lauther@mchp.siemens.de>
 
    This file is part of GNU Binutils.
 #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 pretty_print;       /* -p, print on one line.  */
 static bfd_boolean base_names;         /* -s, strip directory names.  */
 
 static int naddr;              /* Number of addresses to process.  */
@@ -50,11 +52,13 @@ 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'},
   {"functions", no_argument, NULL, 'f'},
   {"inlines", no_argument, NULL, 'i'},
+  {"pretty-print", no_argument, NULL, 'p'},
   {"section", required_argument, NULL, 'j'},
   {"target", required_argument, NULL, 'b'},
   {"help", no_argument, NULL, 'H'},
@@ -78,10 +82,12 @@ 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\
   @<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\
   -j --section=<name>    Read section-relative offsets instead of addresses\n\
+  -p --pretty-print      Make the output easier to read for humans\n\
   -s --basenames         Strip directory names\n\
   -f --functions         Show function names\n\
   -C --demangle[=style]  Demangle function names\n\
@@ -100,16 +106,27 @@ usage (FILE *stream, int status)
 static void
 slurp_symtab (bfd *abfd)
 {
+  long storage;
   long symcount;
-  unsigned int size;
+  bfd_boolean dynamic = FALSE;
 
   if ((bfd_get_file_flags (abfd) & HAS_SYMS) == 0)
     return;
 
-  symcount = bfd_read_minisymbols (abfd, FALSE, (void *) &syms, &size);
-  if (symcount == 0)
-    symcount = bfd_read_minisymbols (abfd, TRUE /* dynamic */, (void *) &syms, &size);
+  storage = bfd_get_symtab_upper_bound (abfd);
+  if (storage == 0)
+    {
+      storage = bfd_get_dynamic_symtab_upper_bound (abfd);
+      dynamic = TRUE;
+    }
+  if (storage < 0)
+    bfd_fatal (bfd_get_filename (abfd));
 
+  syms = (asymbol **) xmalloc (storage);
+  if (dynamic)
+    symcount = bfd_canonicalize_dynamic_symtab (abfd, syms);
+  else
+    symcount = bfd_canonicalize_symtab (abfd, syms);
   if (symcount < 0)
     bfd_fatal (bfd_get_filename (abfd));
 }
@@ -198,6 +215,17 @@ translate_addresses (bfd *abfd, asection *section)
          pc = bfd_scan_vma (*addr++, NULL, 16);
        }
 
+      if (with_addresses)
+        {
+          printf ("0x");
+          bfd_printf_vma (abfd, pc);
+
+          if (pretty_print)
+            printf (": ");
+          else
+            printf ("\n");
+        }
+
       found = FALSE;
       if (section)
        find_offset_in_section (abfd, section);
@@ -212,44 +240,52 @@ translate_addresses (bfd *abfd, asection *section)
        }
       else
        {
-         do {
-           if (with_functions)
-             {
-               const char *name;
-               char *alloc = NULL;
-
-               name = functionname;
-               if (name == NULL || *name == '\0')
-                 name = "??";
-               else if (do_demangle)
-                 {
-                   alloc = bfd_demangle (abfd, name, DMGL_ANSI | DMGL_PARAMS);
-                   if (alloc != NULL)
-                     name = alloc;
-                 }
-
-               printf ("%s\n", name);
-
-               if (alloc != NULL)
-                 free (alloc);
-             }
-
-           if (base_names && filename != NULL)
-             {
-               char *h;
-
-               h = strrchr (filename, '/');
-               if (h != NULL)
-                 filename = h + 1;
-             }
-
-           printf ("%s:%u\n", filename ? filename : "??", line);
-           if (!unwind_inlines)
-             found = FALSE;
-           else
-             found = bfd_find_inliner_info (abfd, &filename, &functionname, &line);
-         } while (found);
-
+         while (1)
+            {
+              if (with_functions)
+                {
+                  const char *name;
+                  char *alloc = NULL;
+
+                  name = functionname;
+                  if (name == NULL || *name == '\0')
+                    name = "??";
+                  else if (do_demangle)
+                    {
+                      alloc = bfd_demangle (abfd, name, DMGL_ANSI | DMGL_PARAMS);
+                      if (alloc != NULL)
+                        name = alloc;
+                    }
+
+                  printf ("%s", name);
+                  if (pretty_print)
+                    printf (_(" at "));
+                  else
+                    printf ("\n");
+
+                  if (alloc != NULL)
+                    free (alloc);
+                }
+
+              if (base_names && filename != NULL)
+                {
+                  char *h;
+
+                  h = strrchr (filename, '/');
+                  if (h != NULL)
+                    filename = h + 1;
+                }
+
+              printf ("%s:%u\n", filename ? filename : "??", line);
+              if (!unwind_inlines)
+                found = FALSE;
+              else
+                found = bfd_find_inliner_info (abfd, &filename, &functionname, &line);
+              if (! found)
+                break;
+              if (pretty_print)
+                printf (_(" (inlined by) "));
+            }
        }
 
       /* fflush() is essential for using this command as a server
@@ -343,13 +379,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:pVv", 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;
@@ -376,6 +415,9 @@ main (int argc, char **argv)
        case 'f':
          with_functions = TRUE;
          break;
+        case 'p':
+          pretty_print = TRUE;
+          break;
        case 'v':
        case 'V':
          print_version ("addr2line");
This page took 0.038813 seconds and 4 git commands to generate.