1999-09-12 Donn Terry <donn@interix.com>
[deliverable/binutils-gdb.git] / binutils / objdump.c
index 3f9e8c4c3f6f22b82a6dbc0f148b4da456e6956e..f51af3f725ddf969e27a22af71d2592f1639250c 100644 (file)
@@ -44,6 +44,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 extern int fprintf PARAMS ((FILE *, const char *, ...));
 #endif
 
+/* Exit status.  */
+static int exit_status = 0;
+
 static char *default_target = NULL;    /* default at runtime */
 
 static int show_version = 0;           /* show the version number */
@@ -83,6 +86,9 @@ struct objdump_disasm_info {
 /* Architecture to disassemble for, or default if NULL.  */
 static char *machine = (char *) NULL;
 
+/* Target specific options to the disassembler.  */
+static char *disassembler_options = (char *) NULL;
+
 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN.  */
 static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
 
@@ -109,6 +115,9 @@ static long dynsymcount = 0;
 static void
 usage PARAMS ((FILE *, int));
 
+static void
+nonfatal PARAMS ((const char *));
+
 static void
 display_file PARAMS ((char *filename, char *target));
 
@@ -217,7 +226,8 @@ usage (stream, status)
      int status;
 {
   fprintf (stream, _("\
-Usage: %s [-ahifCdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
+Usage: %s [-ahifCdDprRtTxsSlw] [-b bfdname] [-m machine] \n\
+       [-j section-name] [-M disassembler-options]\n\
        [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
        [--disassemble-all] [--disassemble-zeroes] [--file-headers]\n\
        [--section-headers] [--headers]\n\
@@ -255,6 +265,7 @@ static struct option long_options[]=
   {"demangle", no_argument, &do_demangle, 1},
   {"disassemble", no_argument, NULL, 'd'},
   {"disassemble-all", no_argument, NULL, 'D'},
+  {"disassembler-options", required_argument, NULL, 'M'},
   {"disassemble-zeroes", no_argument, &disassemble_zeroes, 1},
   {"dynamic-reloc", no_argument, NULL, 'R'},
   {"dynamic-syms", no_argument, NULL, 'T'},
@@ -283,10 +294,18 @@ static struct option long_options[]=
 };
 \f
 static void
+nonfatal (msg)
+     const char *msg;
+{
+  bfd_nonfatal (msg);
+  exit_status = 1;
+}
+\f
+static void
 dump_section_header (abfd, section, ignored)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      asection *section;
-     PTR ignored;
+     PTR ignored ATTRIBUTE_UNUSED;
 {
   char *comma = "";
 
@@ -324,6 +343,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_SMALL_DATA, "SMALL_DATA");
+  PF (SEC_SHARED, "SHARED");
 
   if ((section->flags & SEC_LINK_ONCE) != 0)
     {
@@ -347,6 +368,11 @@ dump_section_header (abfd, section, ignored)
          break;
        }
       printf ("%s%s", comma, ls);
+
+      if (section->comdat != NULL)
+       printf (" (COMDAT %s %ld)", section->comdat->name,
+               section->comdat->symbol);
+
       comma = ", ";
     }
 
@@ -1134,7 +1160,7 @@ objdump_sprintf (va_alist)
 
   n = strlen (buf);
 
-  while ((f->buffer + f->size) - f->current < n + 1)
+  while ((size_t) ((f->buffer + f->size) - f->current) < n + 1)
     {
       size_t curroff;
 
@@ -1305,11 +1331,16 @@ disassemble_bytes (info, disassemble_fn, insns, data, start, stop, relppp,
              if (info->bytes_per_line != 0)
                bytes_per_line = info->bytes_per_line;
              if (bytes < 0)
-               break;
+               {
+                 if (sfile.current != sfile.buffer)
+                   printf ("%s\n", sfile.buffer);
+                 free (sfile.buffer);
+                 break;
+               }
            }
          else
            {
-             long j;
+             bfd_vma j;
 
              bytes = bytes_per_line;
              if (i + bytes > stop)
@@ -1329,7 +1360,7 @@ disassemble_bytes (info, disassemble_fn, insns, data, start, stop, relppp,
              ? show_raw_insn > 0
              : show_raw_insn >= 0)
            {
-             long j;
+             bfd_vma j;
 
              /* If ! prefix_addresses and ! wide_output, we print
                  bytes_per_line bytes per line.  */
@@ -1389,7 +1420,7 @@ disassemble_bytes (info, disassemble_fn, insns, data, start, stop, relppp,
            {
              while (pb < bytes)
                {
-                 long j;
+                 bfd_vma j;
                  char *s;
 
                  putchar ('\n');
@@ -1553,16 +1584,19 @@ disassemble_data (abfd)
       fprintf (stderr, _("%s: Can't disassemble for architecture %s\n"),
               program_name,
               bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
+      exit_status = 1;
       return;
     }
 
   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;
+  
   if (bfd_big_endian (abfd))
-    disasm_info.endian = BFD_ENDIAN_BIG;
+    disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
   else if (bfd_little_endian (abfd))
-    disasm_info.endian = BFD_ENDIAN_LITTLE;
+    disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE;
   else
     /* ??? Aborting here seems too drastic.  We could default to big or little
        instead.  */
@@ -1804,6 +1838,7 @@ read_section_stabs (abfd, stabsect_name, strsect_name)
     {
       fprintf (stderr, _("%s: %s has no %s section\n"), program_name,
               bfd_get_filename (abfd), strsect_name);
+      exit_status = 1;
       return false;
     }
  
@@ -1820,6 +1855,7 @@ read_section_stabs (abfd, stabsect_name, strsect_name)
               bfd_errmsg (bfd_get_error ()));
       free (stabs);
       free (strtab);
+      exit_status = 1;
       return false;
     }
 
@@ -1831,6 +1867,7 @@ read_section_stabs (abfd, stabsect_name, strsect_name)
               bfd_errmsg (bfd_get_error ()));
       free (stabs);
       free (strtab);
+      exit_status = 1;
       return false;
     }
 
@@ -1859,7 +1896,7 @@ static void
 print_section_stabs (abfd, stabsect_name, strsect_name)
      bfd *abfd;
      const char *stabsect_name;
-     const char *strsect_name;
+     const char *strsect_name ATTRIBUTE_UNUSED;
 {
   int i;
   unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
@@ -2004,7 +2041,7 @@ display_bfd (abfd)
 
   if (!bfd_check_format_matches (abfd, bfd_object, &matching))
     {
-      bfd_nonfatal (bfd_get_filename (abfd));
+      nonfatal (bfd_get_filename (abfd));
       if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
        {
          list_matching_formats (matching);
@@ -2068,8 +2105,12 @@ display_bfd (abfd)
       if (dhandle != NULL)
        {
          if (! print_debugging_info (stdout, dhandle))
-           fprintf (stderr, _("%s: printing debugging information failed\n"),
-                    bfd_get_filename (abfd));
+           {
+             fprintf (stderr,
+                      _("%s: printing debugging information failed\n"),
+                      bfd_get_filename (abfd));
+             exit_status = 1;
+           }
        }
     }
   if (syms)
@@ -2094,7 +2135,7 @@ display_file (filename, target)
   file = bfd_openr (filename, target);
   if (file == NULL)
     {
-      bfd_nonfatal (filename);
+      nonfatal (filename);
       return;
     }
 
@@ -2111,9 +2152,7 @@ display_file (filename, target)
          if (arfile == NULL)
            {
              if (bfd_get_error () != bfd_error_no_more_archived_files)
-               {
-                 bfd_nonfatal (bfd_get_filename (file));
-               }
+               nonfatal (bfd_get_filename (file));
              break;
            }
 
@@ -2215,7 +2254,7 @@ dump_data (abfd)
 /* Should perhaps share code and display with nm? */
 static void
 dump_symbols (abfd, dynamic)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      boolean dynamic;
 {
   asymbol **current;
@@ -2468,7 +2507,10 @@ dump_reloc_set (abfd, sec, relpp, relcount)
       if (sym_name)
        {
          printf_vma (q->address);
-         printf (" %-16s  ", q->howto->name);
+         if (q->howto->name)
+           printf (" %-16s  ", q->howto->name);
+         else
+           printf (" %-16d  ", q->howto->type);
          objdump_print_symname (abfd, (struct disassemble_info *) NULL,
                                 *q->sym_ptr_ptr);
        }
@@ -2528,14 +2570,14 @@ display_target_list ()
 
       if (abfd == NULL)
        {
-         bfd_nonfatal (dummy_name);
+         nonfatal (dummy_name);
          continue;
        }
 
       if (! bfd_set_format (abfd, bfd_object))
        {
          if (bfd_get_error () != bfd_error_invalid_operation)
-           bfd_nonfatal (p->name);
+           nonfatal (p->name);
          continue;
        }
 
@@ -2581,7 +2623,7 @@ display_info_table (first, last)
 
            if (abfd == NULL)
              {
-               bfd_nonfatal (p->name);
+               nonfatal (p->name);
                ok = false;
              }
 
@@ -2590,7 +2632,7 @@ display_info_table (first, last)
                if (! bfd_set_format (abfd, bfd_object))
                  {
                    if (bfd_get_error () != bfd_error_invalid_operation)
-                     bfd_nonfatal (p->name);
+                     nonfatal (p->name);
                    ok = false;
                  }
              }
@@ -2686,7 +2728,7 @@ main (argc, argv)
   bfd_init ();
   set_default_bfd_target ();
 
-  while ((c = getopt_long (argc, argv, "pib:m:VCdDlfahrRtTxsSj:wE:",
+  while ((c = getopt_long (argc, argv, "pib:m:M:VCdDlfahrRtTxsSj:wE:",
                           long_options, (int *) 0))
         != EOF)
     {
@@ -2699,6 +2741,9 @@ main (argc, argv)
        case 'm':
          machine = optarg;
          break;
+       case 'M':
+         disassembler_options = optarg;
+         break;
        case 'j':
          only = optarg;
          break;
@@ -2783,7 +2828,8 @@ main (argc, argv)
            endian = BFD_ENDIAN_LITTLE;
          else
            {
-             fprintf (stderr, _("%s: unrecognized -E option\n"), program_name);
+             fprintf (stderr, _("%s: unrecognized -E option\n"),
+                      program_name);
              usage (stderr, 1);
            }
          break;
@@ -2825,5 +2871,5 @@ main (argc, argv)
 
   END_PROGRESS (program_name);
 
-  return 0;
+  return exit_status;
 }
This page took 0.028637 seconds and 4 git commands to generate.