Fix typos in ChangeLogs and update copyright notices
[deliverable/binutils-gdb.git] / binutils / objdump.c
index 97dcc8c0e67c5c65655f12c0b65765e3fb98fc02..27002ab80ff748a91c230fe55428ec7bb697de1b 100644 (file)
@@ -1,5 +1,6 @@
 /* objdump.c -- dump information about an object file.
-   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001
    Free Software Foundation, Inc.
 
 This file is part of GNU Binutils.
@@ -29,12 +30,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "debug.h"
 #include "budbg.h"
 
-#ifdef ANSI_PROTOTYPES
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
 /* Internal headers for the ELF .stab-dump code - sorry.  */
 #define        BYTES_IN_WORD   32
 #include "aout/aout64.h"
@@ -75,6 +70,7 @@ static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
 static bfd_vma stop_address = (bfd_vma) -1;  /* --stop-address */
 static int dump_debugging;             /* --debugging */
 static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
+static int file_start_context = 0;      /* --file-start-context */
 
 /* Extra info to pass to the disassembler address printing function.  */
 struct objdump_disasm_info {
@@ -225,54 +221,58 @@ usage (stream, status)
      FILE *stream;
      int status;
 {
-  fprintf (stream, _("Usage: %s <switches> file(s)\n"), program_name);
-  fprintf (stream, _(" At least one of the following switches must be given:\n"));
+  fprintf (stream, _("Usage: %s OPTION... FILE...\n"), program_name);
+  fprintf (stream, _("Display information from object FILE.\n"));
+  fprintf (stream, _("\n At least one of the following switches must be given:\n"));
   fprintf (stream, _("\
-  -a  --archive-headers    Display archive header information\n\
-  -f  --file-headers       Display the contents of the overall file header\n\
-  -p  --private-headers    Display object format specific file header contents\n\
-  -h  --[section-]headers  Display the contents of the section headers\n\
-  -x  --all-headers        Display the contents of all headers\n\
-  -d  --disassemble        Display assembler contents of executable sections\n\
-  -D  --disassemble-all    Display assembler contents of all sections\n\
-  -S  --source             Intermix source code with disassembly\n\
-  -s  --full-contents      Display the full contents of all sections requested\n\
-  -g  --debugging          Display debug information in object file\n\
-  -G  --stabs              Display the STABS contents of an ELF format file\n\
-  -t  --syms               Display the contents of the symbol table(s)\n\
-  -T  --dynamic-syms       Display the contents of the dynamic symbol table\n\
-  -r  --reloc              Display the relocation entries in the file\n\
-  -R  --dynamic-reloc      Display the dynamic relocation entries in the file\n\
-  -V  --version            Display this program's version number\n\
-  -i  --info               List object formats and architectures supported\n\
-  -H  --help               Display this information\n\
+  -a, --archive-headers    Display archive header information\n\
+  -f, --file-headers       Display the contents of the overall file header\n\
+  -p, --private-headers    Display object format specific file header contents\n\
+  -h, --[section-]headers  Display the contents of the section headers\n\
+  -x, --all-headers        Display the contents of all headers\n\
+  -d, --disassemble        Display assembler contents of executable sections\n\
+  -D, --disassemble-all    Display assembler contents of all sections\n\
+  -S, --source             Intermix source code with disassembly\n\
+  -s, --full-contents      Display the full contents of all sections requested\n\
+  -g, --debugging          Display debug information in object file\n\
+  -G, --stabs              Display (in raw form) any STABS info in the file\n\
+  -t, --syms               Display the contents of the symbol table(s)\n\
+  -T, --dynamic-syms       Display the contents of the dynamic symbol table\n\
+  -r, --reloc              Display the relocation entries in the file\n\
+  -R, --dynamic-reloc      Display the dynamic relocation entries in the file\n\
+  -V, --version            Display this program's version number\n\
+  -i, --info               List object formats and architectures supported\n\
+  -H, --help               Display this information\n\
 "));
   if (status != 2)
     {
       fprintf (stream, _("\n The following switches are optional:\n"));
       fprintf (stream, _("\
-  -b  --target <bfdname>         Specify the target object format as <bfdname>\n\
-  -m  --architecture <machine>   Specify the target architecture as <machine>\n\
-  -j  --section <name>           Only display information for section <name>\n\
-  -M  --disassembler-options <o> Pass text <o> on to the disassembler\n\
+  -b, --target=BFDNAME           Specify the target object format as BFDNAME\n\
+  -m, --architecture=MACHINE     Specify the target architecture as MACHINE\n\
+  -j, --section=NAME             Only display information for section NAME\n\
+  -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
   -EB --endian=big               Assume big endian format when disassembling\n\
   -EL --endian=little            Assume little endian format when disassembling\n\
-  -l  --line-numbers             Include line numbers and filenames in output\n\
-  -C  --demangle                 Decode mangled/processed symbol names\n\
-  -w  --wide                     Format output for more than 80 columns\n\
-  -z  --disassemble-zeroes       Do not skip blocks of zeroes when disassembling\n\
-      --start-address <addr>     Only process data whoes address is >= <addr>\n\
-      --stop-address <addr>      Only process data whoes address is <= <addr>\n\
+      --file-start-context       Include context from start of file (with -S)\n\
+  -l, --line-numbers             Include line numbers and filenames in output\n\
+  -C, --demangle[=STYLE]         Decode mangled/processed symbol names\n\
+                                  The STYLE, if specified, can be `auto', 'gnu',\n\
+                                  'lucid', 'arm', 'hp', 'edg', or 'gnu-new-abi'\n\
+  -w, --wide                     Format output for more than 80 columns\n\
+  -z, --disassemble-zeroes       Do not skip blocks of zeroes when disassembling\n\
+      --start-address=ADDR       Only process data whoes address is >= ADDR\n\
+      --stop-address=ADDR        Only process data whoes address is <= ADDR\n\
       --prefix-addresses         Print complete address alongside disassembly\n\
       --[no-]show-raw-insn       Display hex alongside symbolic disassembly\n\
-      --adjust-vma <offset>      Add <offset> to all displayed section addresses\n\
+      --adjust-vma=OFFSET        Add OFFSET to all displayed section addresses\n\
 \n"));
       list_supported_targets (program_name, stream);
-      
+
       disassembler_usage (stream);
     }
   if (status == 0)
-    fprintf (stream, _("Report bugs to bug-gnu-utils@gnu.org\n"));
+    fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
   exit (status);
 }
 
@@ -291,7 +291,7 @@ static struct option long_options[]=
   {"architecture", required_argument, NULL, 'm'},
   {"archive-headers", no_argument, NULL, 'a'},
   {"debugging", no_argument, NULL, 'g'},
-  {"demangle", no_argument, NULL, 'C'},
+  {"demangle", optional_argument, NULL, 'C'},
   {"disassemble", no_argument, NULL, 'd'},
   {"disassemble-all", no_argument, NULL, 'D'},
   {"disassembler-options", required_argument, NULL, 'M'},
@@ -300,6 +300,7 @@ static struct option long_options[]=
   {"dynamic-syms", no_argument, NULL, 'T'},
   {"endian", required_argument, NULL, OPTION_ENDIAN},
   {"file-headers", no_argument, NULL, 'f'},
+  {"file-start-context", no_argument, &file_start_context, 1},
   {"full-contents", no_argument, NULL, 's'},
   {"headers", no_argument, NULL, 'h'},
   {"help", no_argument, NULL, 'H'},
@@ -337,7 +338,7 @@ dump_section_header (abfd, section, ignored)
      PTR ignored ATTRIBUTE_UNUSED;
 {
   char *comma = "";
-  int opb = bfd_octets_per_byte (abfd);
+  unsigned int opb = bfd_octets_per_byte (abfd);
 
   printf ("%3d %-13s %08lx  ", section->index,
          bfd_get_section_name (abfd, section),
@@ -373,6 +374,8 @@ dump_section_header (abfd, section, ignored)
   PF (SEC_NEVER_LOAD, "NEVER_LOAD");
   PF (SEC_EXCLUDE, "EXCLUDE");
   PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
+  PF (SEC_BLOCK, "BLOCK");
+  PF (SEC_CLINK, "CLINK");
   PF (SEC_SMALL_DATA, "SMALL_DATA");
   PF (SEC_SHARED, "SHARED");
 
@@ -438,7 +441,7 @@ slurp_symtab (abfd)
 
   if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
     {
-      fprintf (stderr, _("%s: no symbols\n"), bfd_get_filename (abfd));
+      non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
       symcount = 0;
       return NULL;
     }
@@ -455,7 +458,7 @@ slurp_symtab (abfd)
   if (symcount < 0)
     bfd_fatal (bfd_get_filename (abfd));
   if (symcount == 0)
-    fprintf (stderr, _("%s: no symbols\n"), bfd_get_filename (abfd));
+    non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
   return sy;
 }
 
@@ -473,8 +476,7 @@ slurp_dynamic_symtab (abfd)
     {
       if (!(bfd_get_file_flags (abfd) & DYNAMIC))
        {
-         fprintf (stderr, _("%s: %s: not a dynamic object\n"),
-                  program_name, bfd_get_filename (abfd));
+         non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
          dynsymcount = 0;
          return NULL;
        }
@@ -490,8 +492,7 @@ slurp_dynamic_symtab (abfd)
   if (dynsymcount < 0)
     bfd_fatal (bfd_get_filename (abfd));
   if (dynsymcount == 0)
-    fprintf (stderr, _("%s: %s: No dynamic symbols\n"),
-            program_name, bfd_get_filename (abfd));
+    non_fatal (_("%s: No dynamic symbols"), bfd_get_filename (abfd));
   return sy;
 }
 
@@ -740,7 +741,7 @@ find_symbol_for_address (abfd, sec, vma, require_sec, place)
   long min = 0;
   long max = sorted_symcount;
   long thisplace;
-  int opb = bfd_octets_per_byte (abfd); 
+  unsigned int opb = bfd_octets_per_byte (abfd); 
 
   if (sorted_symcount < 1)
     return NULL;
@@ -1076,8 +1077,8 @@ show_line (abfd, section, addr_offset)
              else
                {
                  l = line - SHOW_PRECEDING_CONTEXT_LINES;
-                 if (l <= 0)
-                   l = 1;
+                 if (l < 0)
+                   l = 0;
                }
 
              if (p->f == NULL)
@@ -1127,9 +1128,12 @@ show_line (abfd, section, addr_offset)
              p->next = print_files;
              print_files = p;
 
-             l = line - SHOW_PRECEDING_CONTEXT_LINES;
-             if (l <= 0)
-               l = 1;
+              if (file_start_context)
+                l = 0;
+              else
+                l = line - SHOW_PRECEDING_CONTEXT_LINES;
+             if (l < 0)
+               l = 0;
              skip_to_line (p, l, false);
              if (p->f != NULL)
                skip_to_line (p, line, true);
@@ -1191,8 +1195,7 @@ objdump_sprintf (va_alist)
 
   if (buf == NULL)
     {
-      fprintf (stderr, _("Out of virtual memory\n"));
-      exit (1);
+      fatal (_("Out of virtual memory"));
     }
 
   n = strlen (buf);
@@ -1356,13 +1359,15 @@ disassemble_bytes (info, disassemble_fn, insns, data,
              info->bytes_per_line = 0;
              info->bytes_per_chunk = 0;
 
+#ifdef DISASSEMBLER_NEEDS_RELOCS
              /* FIXME: This is wrong.  It tests the number of octets
                  in the last instruction, not the current one.  */
              if (*relppp < relppend
                  && (**relppp)->address >= addr_offset
-                 && (**relppp)->address < addr_offset + octets / opb)
+                 && (**relppp)->address <= addr_offset + octets / opb)
                info->flags = INSN_HAS_RELOC;
              else
+#endif
                info->flags = 0;
 
              octets = (*disassemble_fn) (section->vma + addr_offset, info);
@@ -1502,12 +1507,20 @@ disassemble_bytes (info, disassemble_fn, insns, data,
            need_nl = true;
        }
 
-      if (dump_reloc_info
-         && (section->flags & SEC_RELOC) != 0)
+      if ((section->flags & SEC_RELOC) != 0
+#ifndef DISASSEMBLER_NEEDS_RELOCS        
+         && dump_reloc_info
+#endif
+         )
        {
          while ((*relppp) < relppend
                 && ((**relppp)->address >= (bfd_vma) addr_offset
                     && (**relppp)->address < (bfd_vma) addr_offset + octets / opb))
+#ifdef DISASSEMBLER_NEEDS_RELOCS
+           if (! dump_reloc_info)
+             ++(*relppp);
+           else
+#endif
            {
              arelent *q;
 
@@ -1568,12 +1581,12 @@ static void
 disassemble_data (abfd)
      bfd *abfd;
 {
-  long addr_offset;
+  unsigned long addr_offset;
   disassembler_ftype disassemble_fn;
   struct disassemble_info disasm_info;
   struct objdump_disasm_info aux;
   asection *section;
-  int opb = bfd_octets_per_byte (abfd);
+  unsigned int opb;
 
   print_files = NULL;
   prev_functionname = NULL;
@@ -1595,17 +1608,13 @@ disassemble_data (abfd)
   aux.require_sec = false;
   disasm_info.print_address_func = objdump_print_address;
   disasm_info.symbol_at_address_func = objdump_symbol_at_address;
-  disasm_info.octets_per_byte = opb;
 
   if (machine != (char *) NULL)
     {
       const bfd_arch_info_type *info = bfd_scan_arch (machine);
       if (info == NULL)
        {
-         fprintf (stderr, _("%s: Can't use supplied machine %s\n"),
-                  program_name,
-                  machine);
-         exit (1);
+         fatal (_("Can't use supplied machine %s"), machine);
        }
       abfd->arch_info = info;
     }
@@ -1623,17 +1632,19 @@ disassemble_data (abfd)
   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));
+      non_fatal (_("Can't disassemble for architecture %s\n"),
+                bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
       exit_status = 1;
       return;
     }
 
+  opb = bfd_octets_per_byte (abfd);
+
   disasm_info.flavour = bfd_get_flavour (abfd);
   disasm_info.arch = bfd_get_arch (abfd);
   disasm_info.mach = bfd_get_mach (abfd);
   disasm_info.disassembler_options = disassembler_options;
+  disasm_info.octets_per_byte = opb;
   
   if (bfd_big_endian (abfd))
     disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
@@ -1653,7 +1664,7 @@ disassemble_data (abfd)
       arelent **relbuf = NULL;
       arelent **relpp = NULL;
       arelent **relppend = NULL;
-      long stop_offset;
+      unsigned long stop_offset;
       asymbol *sym = NULL;
       long place = 0;
 
@@ -1665,8 +1676,11 @@ disassemble_data (abfd)
       if (only != (char *) NULL && strcmp (only, section->name) != 0)
        continue;
 
-      if (dump_reloc_info
-         && (section->flags & SEC_RELOC) != 0)
+      if ((section->flags & SEC_RELOC) != 0
+#ifndef DISASSEMBLER_NEEDS_RELOCS        
+         && dump_reloc_info
+#endif
+         ) 
        {
          long relsize;
 
@@ -1737,7 +1751,7 @@ disassemble_data (abfd)
       while (addr_offset < stop_offset)
        {
          asymbol *nextsym;
-         long nextstop_offset;
+         unsigned long nextstop_offset;
          boolean insns;
          
          if (sym != NULL && bfd_asymbol_value (sym) <= section->vma + addr_offset)
@@ -1881,8 +1895,8 @@ read_section_stabs (abfd, stabsect_name, strsect_name)
   stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
   if (0 == stabstrsect)
     {
-      fprintf (stderr, _("%s: %s has no %s section\n"), program_name,
-              bfd_get_filename (abfd), strsect_name);
+      non_fatal (_("%s has no %s section"),
+                bfd_get_filename (abfd), strsect_name);
       exit_status = 1;
       return false;
     }
@@ -1895,9 +1909,9 @@ read_section_stabs (abfd, stabsect_name, strsect_name)
   
   if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
     {
-      fprintf (stderr, _("%s: Reading %s section of %s failed: %s\n"),
-              program_name, stabsect_name, bfd_get_filename (abfd),
-              bfd_errmsg (bfd_get_error ()));
+      non_fatal (_("Reading %s section of %s failed: %s"),
+                stabsect_name, bfd_get_filename (abfd),
+                bfd_errmsg (bfd_get_error ()));
       free (stabs);
       free (strtab);
       exit_status = 1;
@@ -1907,9 +1921,9 @@ read_section_stabs (abfd, stabsect_name, strsect_name)
   if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
                                  stabstr_size))
     {
-      fprintf (stderr, _("%s: Reading %s section of %s failed: %s\n"),
-              program_name, strsect_name, bfd_get_filename (abfd),
-              bfd_errmsg (bfd_get_error ()));
+      non_fatal (_("Reading %s section of %s failed: %s\n"),
+                strsect_name, bfd_get_filename (abfd),
+                bfd_errmsg (bfd_get_error ()));
       free (stabs);
       free (strtab);
       exit_status = 1;
@@ -2140,9 +2154,8 @@ dump_bfd (abfd)
        {
          if (! print_debugging_info (stdout, dhandle))
            {
-             fprintf (stderr,
-                      _("%s: printing debugging information failed\n"),
-                      bfd_get_filename (abfd));
+             non_fatal (_("%s: printing debugging information failed"),
+                        bfd_get_filename (abfd));
              exit_status = 1;
            }
        }
@@ -2258,7 +2271,7 @@ dump_data (abfd)
   bfd_size_type datasize = 0;
   bfd_size_type addr_offset;
   bfd_size_type start_offset, stop_offset;
-  int opb = bfd_octets_per_byte (abfd);
+  unsigned int opb = bfd_octets_per_byte (abfd);
 
   for (section = abfd->sections; section != NULL; section =
        section->next)
@@ -2612,7 +2625,7 @@ dump_reloc_set (abfd, sec, relpp, relcount)
 }
 \f
 /* The length of the longest architecture name + 1.  */
-#define LONGEST_ARCH sizeof("rs6000:6000")
+#define LONGEST_ARCH sizeof("powerpc:common")
 
 static const char *
 endian_string (endian)
@@ -2632,14 +2645,14 @@ endian_string (endian)
 static void
 display_target_list ()
 {
-  extern bfd_target *bfd_target_vector[];
+  extern const bfd_target *const *bfd_target_vector;
   char *dummy_name;
   int t;
 
-  dummy_name = choose_temp_base ();
+  dummy_name = make_temp_file (NULL);
   for (t = 0; bfd_target_vector[t]; t++)
     {
-      bfd_target *p = bfd_target_vector[t];
+      const bfd_target *p = bfd_target_vector[t];
       bfd *abfd = bfd_openw (dummy_name, p->name);
       int a;
 
@@ -2657,6 +2670,7 @@ display_target_list ()
        {
          if (bfd_get_error () != bfd_error_invalid_operation)
            nonfatal (p->name);
+         bfd_close_all_done (abfd);
          continue;
        }
 
@@ -2664,6 +2678,7 @@ display_target_list ()
        if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
          printf ("  %s\n",
                  bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
+      bfd_close_all_done (abfd);
     }
   unlink (dummy_name);
   free (dummy_name);
@@ -2678,7 +2693,7 @@ display_info_table (first, last)
      int first;
      int last;
 {
-  extern bfd_target *bfd_target_vector[];
+  extern const bfd_target *const *bfd_target_vector;
   int t, a;
   char *dummy_name;
 
@@ -2688,7 +2703,7 @@ display_info_table (first, last)
     printf ("%s ", bfd_target_vector[t]->name);
   putchar ('\n');
 
-  dummy_name = choose_temp_base ();
+  dummy_name = make_temp_file (NULL);
   for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
     if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
       {
@@ -2696,7 +2711,7 @@ display_info_table (first, last)
                bfd_printable_arch_mach (a, 0));
        for (t = first; t < last && bfd_target_vector[t]; t++)
          {
-           bfd_target *p = bfd_target_vector[t];
+           const bfd_target *p = bfd_target_vector[t];
            boolean ok = true;
            bfd *abfd = bfd_openw (dummy_name, p->name);
 
@@ -2731,6 +2746,8 @@ display_info_table (first, last)
                  putchar ('-');
                putchar (' ');
              }
+           if (abfd != NULL)
+             bfd_close_all_done (abfd);
          }
        putchar ('\n');
       }
@@ -2745,7 +2762,7 @@ static void
 display_target_tables ()
 {
   int t, columns;
-  extern bfd_target *bfd_target_vector[];
+  extern const bfd_target *const *bfd_target_vector;
   char *colum;
 
   columns = 0;
@@ -2832,6 +2849,17 @@ main (argc, argv)
          break;
        case 'C':
          do_demangle = true;
+         if (optarg != NULL)
+           {
+             enum demangling_styles style;
+             
+             style = cplus_demangle_name_to_style (optarg);
+             if (style == unknown_demangling) 
+               fatal (_("unknown demangling style `%s'"),
+                      optarg);
+             
+             cplus_demangle_set_style (style);
+           }
          break;
        case 'w':
          wide_output = true;
@@ -2852,8 +2880,7 @@ main (argc, argv)
            endian = BFD_ENDIAN_LITTLE;
          else
            {
-             fprintf (stderr, _("%s: unrecognized -E option\n"),
-                      program_name);
+             non_fatal (_("unrecognized -E option"));
              usage (stderr, 1);
            }
          break;
@@ -2864,8 +2891,7 @@ main (argc, argv)
            endian = BFD_ENDIAN_LITTLE;
          else
            {
-             fprintf (stderr, _("%s: unrecognized --endian type `%s'\n"),
-                     program_name, optarg);
+             non_fatal (_("unrecognized --endian type `%s'"), optarg);
              usage (stderr, 1);
            }
          break;
This page took 0.032821 seconds and 4 git commands to generate.