* objdump.c (disassemble_data): Handle unknown endianness.
[deliverable/binutils-gdb.git] / binutils / objdump.c
index a8c4c5ca2041ba4055fe2c270b8c9e5a7727440d..19b1243985c29f559a39deb09559497872970a2b 100644 (file)
@@ -1,5 +1,5 @@
 /* objdump.c -- dump information about an object file.
-   Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
 
 This file is part of GNU Binutils.
 
@@ -15,24 +15,25 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "bfd.h"
-#include "sysdep.h"
 #include "getopt.h"
 #include "progress.h"
 #include "bucomm.h"
-#include <stdio.h>
 #include <ctype.h>
 #include "dis-asm.h"
 #include "libiberty.h"
+#include "debug.h"
+#include "budbg.h"
 
 /* Internal headers for the ELF .stab-dump code - sorry.  */
 #define        BYTES_IN_WORD   32
 #include "aout/aout64.h"
 
-#ifndef FPRINTF_ALREADY_DECLARED
-extern int fprintf PARAMS ((FILE *, CONST char *, ...));
+#ifdef NEED_DECLARATION_FPRINTF
+/* This is needed by INIT_DISASSEMBLE_INFO.  */
+extern int fprintf ();
 #endif
 
 char *default_target = NULL;   /* default at runtime */
@@ -48,13 +49,19 @@ int dump_dynamic_symtab;    /* -T */
 int dump_reloc_info;           /* -r */
 int dump_dynamic_reloc_info;   /* -R */
 int dump_ar_hdrs;              /* -a */
+int dump_private_headers;      /* -p */
 int with_line_numbers;         /* -l */
 boolean with_source_code;      /* -S */
+int show_raw_insn;             /* --show-raw-insn */
 int dump_stab_section_info;    /* --stabs */
 boolean disassemble;           /* -d */
 boolean disassemble_all;       /* -D */
 boolean formats_info;          /* -i */
 char *only;                    /* -j secname */
+int wide_output;               /* -w */
+bfd_vma start_address = (bfd_vma) -1; /* --start-address */
+bfd_vma stop_address = (bfd_vma) -1;  /* --stop-address */
+int dump_debugging;            /* --debugging */
 
 /* Extra info to pass to the disassembler address printing function.  */
 struct objdump_disasm_info {
@@ -107,11 +114,17 @@ dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
 static void
 display_bfd PARAMS ((bfd *abfd));
 
+static void
+objdump_print_value PARAMS ((bfd_vma, FILE *));
+
 static void
 objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
 
 static void
 show_line PARAMS ((bfd *, asection *, bfd_vma));
+
+static const char *
+endian_string PARAMS ((enum bfd_endian));
 \f
 void
 usage (stream, status)
@@ -119,24 +132,34 @@ usage (stream, status)
      int status;
 {
   fprintf (stream, "\
-Usage: %s [-ahifdDrRtTxsSl] [-b bfdname] [-m machine] [-j section-name]\n\
-       [--archive-headers] [--target=bfdname] [--disassemble]\n\
+Usage: %s [-ahifdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
+       [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
        [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
-       [--info] [--section=section-name] [--line-numbers] [--source]\n\
+       [--info] [--section=section-name] [--line-numbers] [--source]\n",
+          program_name);
+  fprintf (stream, "\
        [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
        [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
-       [--version] [--help] objfile...\n\
-at least one option besides -l (--line-numbers) must be given\n",
-          program_name);
+       [--wide] [--version] [--help] [--private-headers]\n\
+       [--start-address=addr] [--stop-address=addr]\n\
+       [--show-raw-insn] objfile...\n\
+at least one option besides -l (--line-numbers) must be given\n");
   list_supported_targets (program_name, stream);
   exit (status);
 }
 
+/* 150 isn't special; it's just an arbitrary non-ASCII char value.  */
+
+#define OPTION_START_ADDRESS (150)
+#define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)
+
 static struct option long_options[]=
 {
   {"all-headers", no_argument, NULL, 'x'},
+  {"private-headers", no_argument, NULL, 'p'},
   {"architecture", required_argument, NULL, 'm'},
   {"archive-headers", no_argument, NULL, 'a'},
+  {"debugging", no_argument, &dump_debugging, 1},
   {"disassemble", no_argument, NULL, 'd'},
   {"disassemble-all", no_argument, NULL, 'D'},
   {"dynamic-reloc", no_argument, NULL, 'R'},
@@ -150,11 +173,15 @@ static struct option long_options[]=
   {"reloc", no_argument, NULL, 'r'},
   {"section", required_argument, NULL, 'j'},
   {"section-headers", no_argument, NULL, 'h'},
+  {"show-raw-insn", no_argument, &show_raw_insn, 1},
   {"source", no_argument, NULL, 'S'},
   {"stabs", no_argument, &dump_stab_section_info, 1},
+  {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
+  {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
   {"syms", no_argument, NULL, 't'},
   {"target", required_argument, NULL, 'b'},
-  {"version", no_argument, &show_version,    1},
+  {"version", no_argument, &show_version, 1},
+  {"wide", no_argument, &wide_output, 'w'},
   {0, no_argument, 0, 0}
 };
 \f
@@ -176,8 +203,10 @@ dump_section_header (abfd, section, ignored)
          (unsigned) bfd_get_section_size_before_reloc (section));
   printf (" vma ");
   printf_vma (section->vma);
-  printf (" align 2**%u\n ",
-         section->alignment_power);
+  printf (" lma ");
+  printf_vma (section->lma);
+  printf (" align 2**%u%s ",
+         section->alignment_power, (wide_output) ? "" : "\n");
   PF (SEC_ALLOC, "ALLOC");
   PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
   PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
@@ -194,6 +223,8 @@ dump_section_header (abfd, section, ignored)
   PF (SEC_ROM, "ROM");
   PF (SEC_DEBUGGING, "DEBUGGING");
   PF (SEC_NEVER_LOAD, "NEVER_LOAD");
+  PF (SEC_EXCLUDE, "EXCLUDE");
+  PF (SEC_SORT_ENTRIES, "SORT ENTRIES");
   printf ("\n");
 #undef PF
 }
@@ -215,6 +246,7 @@ slurp_symtab (abfd)
   if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
     {
       printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
+      symcount = 0;
       return NULL;
     }
 
@@ -251,6 +283,7 @@ slurp_dynamic_symtab (abfd)
        {
          fprintf (stderr, "%s: %s: not a dynamic object\n",
                   program_name, bfd_get_filename (abfd));
+         dynsymcount = 0;
          return NULL;
        }
 
@@ -298,7 +331,7 @@ remove_useless_symbols (symbols, count)
   return out_ptr - symbols;
 }
 
-/* Sort symbols into value order. */
+/* Sort symbols into value order.  */
 
 static int 
 compare_symbols (ap, bp)
@@ -307,6 +340,10 @@ compare_symbols (ap, bp)
 {
   const asymbol *a = *(const asymbol **)ap;
   const asymbol *b = *(const asymbol **)bp;
+  const char *an, *bn;
+  size_t anl, bnl;
+  boolean af, bf;
+  flagword aflags, bflags;
 
   if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
     return 1;
@@ -317,6 +354,65 @@ compare_symbols (ap, bp)
     return 1;
   else if (a->section < b->section)
     return -1;
+
+  an = bfd_asymbol_name (a);
+  bn = bfd_asymbol_name (b);
+  anl = strlen (an);
+  bnl = strlen (bn);
+
+  /* The symbols gnu_compiled and gcc2_compiled convey no real
+     information, so put them after other symbols with the same value.  */
+
+  af = (strstr (an, "gnu_compiled") != NULL
+       || strstr (an, "gcc2_compiled") != NULL);
+  bf = (strstr (bn, "gnu_compiled") != NULL
+       || strstr (bn, "gcc2_compiled") != NULL);
+
+  if (af && ! bf)
+    return 1;
+  if (! af && bf)
+    return -1;
+
+  /* We use a heuristic for the file name, to try to sort it after
+     more useful symbols.  It may not work on non Unix systems, but it
+     doesn't really matter; the only difference is precisely which
+     symbol names get printed.  */
+
+#define file_symbol(s, sn, snl)                        \
+  (((s)->flags & BSF_FILE) != 0                        \
+   || ((sn)[(snl) - 2] == '.'                  \
+       && ((sn)[(snl) - 1] == 'o'              \
+          || (sn)[(snl) - 1] == 'a')))
+
+  af = file_symbol (a, an, anl);
+  bf = file_symbol (b, bn, bnl);
+
+  if (af && ! bf)
+    return 1;
+  if (! af && bf)
+    return -1;
+
+  /* Finally, try to sort global symbols before local symbols before
+     debugging symbols.  */
+
+  aflags = a->flags;
+  bflags = b->flags;
+
+  if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
+    {
+      if ((aflags & BSF_DEBUGGING) != 0)
+       return 1;
+      else
+       return -1;
+    }
+  if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
+    {
+      if ((aflags & BSF_LOCAL) != 0)
+       return 1;
+      else
+       return -1;
+    }
+
   return 0;
 }
 
@@ -335,8 +431,30 @@ compare_relocs (ap, bp)
   else if (a->address < b->address)
     return -1;
 
-  return compare_symbols ((const PTR) a->sym_ptr_ptr,
-                         (const PTR) b->sym_ptr_ptr);
+  /* So that associated relocations tied to the same address show up
+     in the correct order, we don't do any further sorting.  */
+  if (a > b)
+    return 1;
+  else if (a < b)
+    return -1;
+  else
+    return 0;
+}
+
+/* Print VMA to STREAM with no leading zeroes.  */
+
+static void
+objdump_print_value (vma, stream)
+     bfd_vma vma;
+     FILE *stream;
+{
+  char buf[30];
+  char *p;
+
+  sprintf_vma (buf, vma);
+  for (p = buf; *p == '0'; ++p)
+    ;
+  fprintf (stream, "%s", p);
 }
 
 /* Print VMA symbolically to INFO if possible.  */
@@ -346,9 +464,6 @@ objdump_print_address (vma, info)
      bfd_vma vma;
      struct disassemble_info *info;
 {
-  /* @@ For relocateable files, should filter out symbols belonging to
-     the wrong section.  Unfortunately, not enough information is supplied
-     to this routine to determine the correct section in all cases.  */
   /* @@ Would it speed things up to cache the last two symbols returned,
      and maybe their address ranges?  For many processors, only one memory
      operand can be present at a time, so the 2-entry cache wouldn't be
@@ -359,8 +474,6 @@ objdump_print_address (vma, info)
   long max = sorted_symcount;
   long thisplace;
 
-  bfd_signed_vma vardiff;
-
   fprintf_vma (info->stream, vma);
 
   if (sorted_symcount < 1)
@@ -375,11 +488,9 @@ objdump_print_address (vma, info)
       thisplace = (max + min) / 2;
       sym = sorted_syms[thisplace];
 
-      vardiff = bfd_asymbol_value (sym) - vma;
-
-      if (vardiff > 0)
+      if (bfd_asymbol_value (sym) > vma)
        max = thisplace;
-      else if (vardiff < 0)
+      else if (bfd_asymbol_value (sym) < vma)
        min = thisplace;
       else
        {
@@ -389,39 +500,14 @@ objdump_print_address (vma, info)
     }
 
   /* The symbol we want is now in min, the low end of the range we
-     were searching.  */
+     were searching.  If there are several symbols with the same
+     value, we want the first one.  */
   thisplace = min;
+  while (thisplace > 0
+        && (bfd_asymbol_value (sorted_syms[thisplace])
+            == bfd_asymbol_value (sorted_syms[thisplace - 1])))
+    --thisplace;
 
-  {
-    /* If this symbol isn't global, search for one with the same value
-       that is.  */
-    bfd_vma val = bfd_asymbol_value (sorted_syms[thisplace]);
-    long i;
-    if (sorted_syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
-      for (i = thisplace - 1; i >= 0; i--)
-       {
-         if (bfd_asymbol_value (sorted_syms[i]) == val
-             && (!(sorted_syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
-                 || ((sorted_syms[thisplace]->flags & BSF_DEBUGGING)
-                     && !(sorted_syms[i]->flags & BSF_DEBUGGING))))
-           {
-             thisplace = i;
-             break;
-           }
-       }
-    if (sorted_syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
-      for (i = thisplace + 1; i < sorted_symcount; i++)
-       {
-         if (bfd_asymbol_value (sorted_syms[i]) == val
-             && (!(sorted_syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
-                 || ((sorted_syms[thisplace]->flags & BSF_DEBUGGING)
-                     && !(sorted_syms[i]->flags & BSF_DEBUGGING))))
-           {
-             thisplace = i;
-             break;
-           }
-       }
-  }
   {
     /* If the file is relocateable, and the symbol could be from this
        section, prefer a symbol from this section over symbols from
@@ -440,7 +526,7 @@ objdump_print_address (vma, info)
            || ((aux->abfd->flags & HAS_RELOC) != 0
                && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
                && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
-                         + bfd_get_section_size_before_reloc (aux->sec)))))
+                         + bfd_section_size (aux->abfd, aux->sec)))))
       {
        for (i = thisplace + 1; i < sorted_symcount; i++)
          {
@@ -451,7 +537,11 @@ objdump_print_address (vma, info)
        --i;
        for (; i >= 0; i--)
          {
-           if (sorted_syms[i]->section == aux->sec)
+           if (sorted_syms[i]->section == aux->sec
+               && (i == 0
+                   || sorted_syms[i - 1]->section != aux->sec
+                   || (bfd_asymbol_value (sorted_syms[i])
+                       != bfd_asymbol_value (sorted_syms[i - 1]))))
              {
                thisplace = i;
                break;
@@ -471,25 +561,47 @@ objdump_print_address (vma, info)
                  }
              }
          }
+
+       if (sorted_syms[thisplace]->section != aux->sec
+           && (aux->require_sec
+               || ((aux->abfd->flags & HAS_RELOC) != 0
+                   && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
+                   && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
+                             + bfd_section_size (aux->abfd, aux->sec)))))
+         {
+           bfd_vma secaddr;
+
+           fprintf (info->stream, " <%s",
+                    bfd_get_section_name (aux->abfd, aux->sec));
+           secaddr = bfd_get_section_vma (aux->abfd, aux->sec);
+           if (vma < secaddr)
+             {
+               fprintf (info->stream, "-");
+               objdump_print_value (secaddr - vma, info->stream);
+             }
+           else if (vma > secaddr)
+             {
+               fprintf (info->stream, "+");
+               objdump_print_value (vma - secaddr, info->stream);
+             }
+           fprintf (info->stream, ">");
+           return;
+         }
       }
   }
 
   fprintf (info->stream, " <%s", sorted_syms[thisplace]->name);
   if (bfd_asymbol_value (sorted_syms[thisplace]) > vma)
     {
-      char buf[30], *p = buf;
-      sprintf_vma (buf, bfd_asymbol_value (sorted_syms[thisplace]) - vma);
-      while (*p == '0')
-       p++;
-      fprintf (info->stream, "-%s", p);
+      fprintf (info->stream, "-");
+      objdump_print_value (bfd_asymbol_value (sorted_syms[thisplace]) - vma,
+                          info->stream);
     }
   else if (vma > bfd_asymbol_value (sorted_syms[thisplace]))
     {
-      char buf[30], *p = buf;
-      sprintf_vma (buf, vma - bfd_asymbol_value (sorted_syms[thisplace]));
-      while (*p == '0')
-       p++;
-      fprintf (info->stream, "+%s", p);
+      fprintf (info->stream, "+");
+      objdump_print_value (vma - bfd_asymbol_value (sorted_syms[thisplace]),
+                          info->stream);
     }
   fprintf (info->stream, ">");
 }
@@ -698,7 +810,6 @@ disassemble_data (abfd)
      bfd *abfd;
 {
   long i;
-  unsigned int (*print) () = 0; /* Old style */
   disassembler_ftype disassemble_fn = 0; /* New style */
   struct disassemble_info disasm_info;
   struct objdump_disasm_info aux;
@@ -723,10 +834,12 @@ disassemble_data (abfd)
   disasm_info.application_data = (PTR) &aux;
   aux.abfd = abfd;
   disasm_info.print_address_func = objdump_print_address;
+  if (show_raw_insn)
+    disasm_info.flags |= DISASM_RAW_INSN_FLAG;
 
   if (machine != (char *) NULL)
     {
-      bfd_arch_info_type *info = bfd_scan_arch (machine);
+      const bfd_arch_info_type *info = bfd_scan_arch (machine);
       if (info == NULL)
        {
          fprintf (stderr, "%s: Can't use supplied machine %s\n",
@@ -737,23 +850,25 @@ disassemble_data (abfd)
       abfd->arch_info = info;
     }
 
-  /* See if we can disassemble using bfd.  */
-
-  if (abfd->arch_info->disassemble)
+  disassemble_fn = disassembler (abfd);
+  if (!disassemble_fn)
     {
-      print = abfd->arch_info->disassemble;
+      fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
+              program_name,
+              bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
+      exit (1);
     }
+
+  disasm_info.arch = bfd_get_arch (abfd);
+  disasm_info.mach = bfd_get_mach (abfd);
+  if (bfd_big_endian (abfd))
+    disasm_info.endian = BFD_ENDIAN_BIG;
+  else if (bfd_little_endian (abfd))
+    disasm_info.endian = BFD_ENDIAN_LITTLE;
   else
-    {
-      disassemble_fn = disassembler (abfd);
-      if (!disassemble_fn)
-       {
-         fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
-                  program_name,
-                  bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
-         exit (1);
-       }
-    }
+    /* ??? Aborting here seems too drastic.  We could default to big or little
+       instead.  */
+    disasm_info.endian = BFD_ENDIAN_UNKNOWN;
 
   for (section = abfd->sections;
        section != (asection *) NULL;
@@ -764,6 +879,7 @@ disassemble_data (abfd)
       arelent **relbuf = NULL;
       arelent **relpp = NULL;
       arelent **relppend = NULL;
+      long stop;
 
       if ((section->flags & SEC_LOAD) == 0
          || (! disassemble_all
@@ -813,10 +929,26 @@ disassemble_data (abfd)
       disasm_info.buffer = data;
       disasm_info.buffer_vma = section->vma;
       disasm_info.buffer_length = datasize;
-      i = 0;
-      while (i < disasm_info.buffer_length)
+      if (start_address == (bfd_vma) -1
+         || start_address < disasm_info.buffer_vma)
+       i = 0;
+      else
+       i = start_address - disasm_info.buffer_vma;
+      if (stop_address == (bfd_vma) -1)
+       stop = datasize;
+      else
+       {
+         if (stop_address < disasm_info.buffer_vma)
+           stop = 0;
+         else
+           stop = stop_address - disasm_info.buffer_vma;
+         if (stop > disasm_info.buffer_length)
+           stop = disasm_info.buffer_length;
+       }
+      while (i < stop)
        {
          int bytes;
+         boolean need_nl = false;
 
          if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
              data[i + 3] == 0)
@@ -838,27 +970,22 @@ disassemble_data (abfd)
              aux.require_sec = false;
              putchar (' ');
 
-             if (disassemble_fn)
-               {
-                 /* New style */
-                 bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
-                 if (bytes < 0)
-                   break;
-               }
+             bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
+             if (bytes < 0)
+               break;
+
+             if (!wide_output)
+               putchar ('\n');
              else
-               {
-                 /* Old style */
-                 bytes = print (section->vma + i, data + i, stdout);
-               }
-             putchar ('\n');
+               need_nl = true;
            }
 
          if (dump_reloc_info
              && (section->flags & SEC_RELOC) != 0)
            {
              while (relpp < relppend
-                    && ((*relpp)->address >= i
-                        && (*relpp)->address < i + bytes))
+                    && ((*relpp)->address >= (bfd_vma) i
+                        && (*relpp)->address < (bfd_vma) i + bytes))
                {
                  arelent *q;
                  const char *sym_name;
@@ -895,11 +1022,14 @@ disassemble_data (abfd)
                    }
 
                  printf ("\n");
-
+                 need_nl = false;
                  ++relpp;
                }
            }
 
+         if (need_nl)
+           printf ("\n");
+
          i += bytes;
        }
 
@@ -907,6 +1037,7 @@ disassemble_data (abfd)
       if (relbuf != NULL)
        free (relbuf);
     }
+  free (sorted_syms);
 }
 \f
 
@@ -1100,11 +1231,24 @@ dump_section_stabs (abfd, stabsect_name, strsect_name)
      char *stabsect_name;
      char *strsect_name;
 {
-  if (read_section_stabs (abfd, stabsect_name, strsect_name))
+  asection *s;
+
+  /* Check for section names for which stabsect_name is a prefix, to
+     handle .stab0, etc.  */
+  for (s = abfd->sections;
+       s != NULL;
+       s = s->next)
     {
-      print_section_stabs (abfd, stabsect_name, strsect_name);
-      free (stabs);
-      free (strtab);
+      if (strncmp (stabsect_name, s->name, strlen (stabsect_name)) == 0
+         && strncmp (strsect_name, s->name, strlen (strsect_name)) != 0)
+       {
+         if (read_section_stabs (abfd, s->name, strsect_name))
+           {
+             print_section_stabs (abfd, s->name, strsect_name);
+             free (stabs);
+             free (strtab);
+           }
+       }
     }
 }
 \f
@@ -1133,7 +1277,13 @@ dump_bfd_header (abfd)
   printf ("\nstart address 0x");
   printf_vma (abfd->start_address);
 }
-
+\f
+static void
+dump_bfd_private_header (abfd)
+bfd *abfd;
+{
+  bfd_print_private_bfd_data (abfd, stdout);
+}
 static void
 display_bfd (abfd)
      bfd *abfd;
@@ -1157,10 +1307,12 @@ display_bfd (abfd)
     print_arelt_descr (stdout, abfd, true);
   if (dump_file_header)
     dump_bfd_header (abfd);
+  if (dump_private_headers)
+    dump_bfd_private_header (abfd);
   putchar ('\n');
   if (dump_section_headers)
     dump_headers (abfd);
-  if (dump_symtab || dump_reloc_info || disassemble)
+  if (dump_symtab || dump_reloc_info || disassemble || dump_debugging)
     {
       syms = slurp_symtab (abfd);
     }
@@ -1182,6 +1334,28 @@ display_bfd (abfd)
     dump_data (abfd);
   if (disassemble)
     disassemble_data (abfd);
+  if (dump_debugging)
+    {
+      PTR dhandle;
+
+      dhandle = read_debugging_info (abfd, syms, symcount);
+      if (dhandle != NULL)
+       {
+         if (! print_debugging_info (stdout, dhandle))
+           fprintf (stderr, "%s: printing debugging information failed\n",
+                    bfd_get_filename (abfd));
+       }
+    }
+  if (syms)
+    {
+      free (syms);
+      syms = NULL;
+    }
+  if (dynsyms)
+    {
+      free (dynsyms);
+      dynsyms = NULL;
+    }
 }
 
 static void
@@ -1243,6 +1417,7 @@ dump_data (abfd)
   bfd_byte *data = 0;
   bfd_size_type datasize = 0;
   bfd_size_type i;
+  bfd_size_type start, stop;
 
   for (section = abfd->sections; section != NULL; section =
        section->next)
@@ -1264,14 +1439,30 @@ dump_data (abfd)
 
              bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
 
-             for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
+             if (start_address == (bfd_vma) -1
+                 || start_address < section->vma)
+               start = 0;
+             else
+               start = start_address - section->vma;
+             if (stop_address == (bfd_vma) -1)
+               stop = bfd_section_size (abfd, section);
+             else
+               {
+                 if (stop_address < section->vma)
+                   stop = 0;
+                 else
+                   stop = stop_address - section->vma;
+                 if (stop > bfd_section_size (abfd, section))
+                   stop = bfd_section_size (abfd, section);
+               }
+             for (i = start; i < stop; i += onaline)
                {
                  bfd_size_type j;
 
                  printf (" %04lx ", (unsigned long int) (i + section->vma));
                  for (j = i; j < i + onaline; j++)
                    {
-                     if (j < bfd_section_size (abfd, section))
+                     if (j < stop)
                        printf ("%02x", (unsigned) (data[j]));
                      else
                        printf ("  ");
@@ -1282,7 +1473,7 @@ dump_data (abfd)
                  printf (" ");
                  for (j = i; j < i + onaline; j++)
                    {
-                     if (j >= bfd_section_size (abfd, section))
+                     if (j >= stop)
                        printf (" ");
                      else
                        printf ("%c", isprint (data[j]) ? data[j] : '.');
@@ -1368,12 +1559,12 @@ dump_relocs (abfd)
       else if ((a->flags & SEC_RELOC) == 0)
        continue;
 
-      printf ("RELOCATION RECORDS FOR [%s]:", a->name);
-
       relsize = bfd_get_reloc_upper_bound (abfd, a);
       if (relsize < 0)
        bfd_fatal (bfd_get_filename (abfd));
 
+      printf ("RELOCATION RECORDS FOR [%s]:", a->name);
+
       if (relsize == 0)
        {
          printf (" (none)\n\n");
@@ -1407,12 +1598,12 @@ dump_dynamic_relocs (abfd)
   arelent **relpp;
   long relcount;
 
-  printf ("DYNAMIC RELOCATION RECORDS");
-
   relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
   if (relsize < 0)
     bfd_fatal (bfd_get_filename (abfd));
 
+  printf ("DYNAMIC RELOCATION RECORDS");
+
   if (relsize == 0)
     {
       printf (" (none)\n\n");
@@ -1463,6 +1654,13 @@ dump_reloc_set (abfd, relpp, relcount)
       CONST char *sym_name;
       CONST char *section_name;
 
+      if (start_address != (bfd_vma) -1
+         && q->address < start_address)
+       continue;
+      if (stop_address != (bfd_vma) -1
+         && q->address > stop_address)
+       continue;
+
       if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
        {
          sym_name = (*(q->sym_ptr_ptr))->name;
@@ -1505,6 +1703,18 @@ dump_reloc_set (abfd, relpp, relcount)
 #define L_tmpnam 25
 #endif
 
+static const char *
+endian_string (endian)
+     enum bfd_endian endian;
+{
+  if (endian == BFD_ENDIAN_BIG)
+    return "big endian";
+  else if (endian == BFD_ENDIAN_LITTLE)
+    return "little endian";
+  else
+    return "endianness unknown";
+}
+
 /* List the targets that BFD is configured to support, each followed
    by its endianness and the architectures it supports.  */
 
@@ -1525,8 +1735,8 @@ display_target_list ()
       int a;
 
       printf ("%s\n (header %s, data %s)\n", p->name,
-             p->header_byteorder_big_p ? "big endian" : "little endian",
-             p->byteorder_big_p ? "big endian" : "little endian");
+             endian_string (p->header_byteorder),
+             endian_string (p->byteorder));
 
       if (abfd == NULL)
        {
@@ -1682,11 +1892,12 @@ main (argc, argv)
 
   bfd_init ();
 
-  while ((c = getopt_long (argc, argv, "ib:m:VdDlfahrRtTxsSj:", long_options,
+  while ((c = getopt_long (argc, argv, "pib:m:VdDlfahrRtTxsSj:w", long_options,
                           (int *) 0))
         != EOF)
     {
-      seenflag = true;
+      if (c != 'l' && c != OPTION_START_ADDRESS && c != OPTION_STOP_ADDRESS)
+       seenflag = true;
       switch (c)
        {
        case 0:
@@ -1709,7 +1920,11 @@ main (argc, argv)
        case 'i':
          formats_info = true;
          break;
+       case 'p':
+         dump_private_headers = 1;
+         break;
        case 'x':
+         dump_private_headers = 1;
          dump_symtab = 1;
          dump_reloc_info = 1;
          dump_file_header = true;
@@ -1752,6 +1967,15 @@ main (argc, argv)
        case 'V':
          show_version = 1;
          break;
+       case 'w':
+         wide_output = 1;
+         break;
+       case OPTION_START_ADDRESS:
+         start_address = parse_vma (optarg, "--start-address");
+         break;
+       case OPTION_STOP_ADDRESS:
+         stop_address = parse_vma (optarg, "--stop-address");
+         break;
        default:
          usage (stderr, 1);
        }
This page took 0.11959 seconds and 4 git commands to generate.