Add MMIX support
[external/binutils.git] / binutils / readelf.c
index 27c6d28..675912f 100644 (file)
@@ -68,6 +68,7 @@
 #include "elf/arc.h"
 #include "elf/fr30.h"
 #include "elf/mcore.h"
+#include "elf/mmix.h"
 #include "elf/i960.h"
 #include "elf/pj.h"
 #include "elf/avr.h"
@@ -281,61 +282,27 @@ typedef int Elf32_Word;
    : get_64bit_elf_symbols (file, offset, size))
 
 
-#ifdef ANSI_PROTOTYPES
 static void
-error (const char * message, ...)
+error VPARAMS ((const char *message, ...))
 {
-  va_list args;
+  VA_OPEN (args, message);
+  VA_FIXEDARG (args, const char *, message);
 
   fprintf (stderr, _("%s: Error: "), program_name);
-  va_start (args, message);
   vfprintf (stderr, message, args);
-  va_end (args);
-  return;
+  VA_CLOSE (args);
 }
 
 static void
-warn (const char * message, ...)
+warn VPARAMS ((const char *message, ...))
 {
-  va_list args;
+  VA_OPEN (args, message);
+  VA_FIXEDARG (args, const char *, message);
 
   fprintf (stderr, _("%s: Warning: "), program_name);
-  va_start (args, message);
   vfprintf (stderr, message, args);
-  va_end (args);
-  return;
+  VA_CLOSE (args);
 }
-#else
-static void
-error (va_alist)
-     va_dcl
-{
-  char * message;
-  va_list args;
-
-  fprintf (stderr, _("%s: Error: "), program_name);
-  va_start (args);
-  message = va_arg (args, char *);
-  vfprintf (stderr, message, args);
-  va_end (args);
-  return;
-}
-
-static void
-warn (va_alist)
-     va_dcl
-{
-  char * message;
-  va_list args;
-
-  fprintf (stderr, _("%s: Warning: "), program_name);
-  va_start (args);
-  message = va_arg (args, char *);
-  vfprintf (stderr, message, args);
-  va_end (args);
-  return;
-}
-#endif
 
 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
 
@@ -621,6 +588,7 @@ guess_is_rela (e_machine)
     case EM_X86_64:
     case EM_S390:
     case EM_S390_OLD:
+    case EM_MMIX:
       return TRUE;
 
     case EM_MMA:
@@ -975,6 +943,10 @@ dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
          rtype = elf_mcore_reloc_type (type);
          break;
 
+       case EM_MMIX:
+         rtype = elf_mmix_reloc_type (type);
+         break;
+
        case EM_PPC:
        case EM_PPC64:
          rtype = elf_ppc_reloc_type (type);
@@ -2033,12 +2005,12 @@ get_section_type_name (sh_type)
          if (result != NULL)
            return result;
 
-         sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
+         sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
        }
       else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
-       sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
+       sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
       else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
-       sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
+       sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
       else
        sprintf (buff, _("<unknown>: %x"), sh_type);
 
@@ -2236,49 +2208,53 @@ parse_args (argc, argv)
            do_debugging = 1;
          else
            {
+             unsigned int index = 0;
+             
              do_debugging = 0;
-             switch (optarg[0])
-               {
-               case 'i':
-               case 'I':
-                 do_debug_info = 1;
-                 break;
 
-               case 'a':
-               case 'A':
-                 do_debug_abbrevs = 1;
-                 break;
+             while (optarg[index])
+               switch (optarg[index++])
+                 {
+                 case 'i':
+                 case 'I':
+                   do_debug_info = 1;
+                   break;
 
-               case 'l':
-               case 'L':
-                 do_debug_lines = 1;
-                 break;
+                 case 'a':
+                 case 'A':
+                   do_debug_abbrevs = 1;
+                   break;
 
-               case 'p':
-               case 'P':
-                 do_debug_pubnames = 1;
-                 break;
+                 case 'l':
+                 case 'L':
+                   do_debug_lines = 1;
+                   break;
 
-               case 'r':
-               case 'R':
-                 do_debug_aranges = 1;
-                 break;
+                 case 'p':
+                 case 'P':
+                   do_debug_pubnames = 1;
+                   break;
 
-               case 'F':
-                 do_debug_frames_interp = 1;
-               case 'f':
-                 do_debug_frames = 1;
-                 break;
+                 case 'r':
+                 case 'R':
+                   do_debug_aranges = 1;
+                   break;
 
-               case 'm':
-               case 'M':
-                 do_debug_macinfo = 1;
-                 break;
+                 case 'F':
+                   do_debug_frames_interp = 1;
+                 case 'f':
+                   do_debug_frames = 1;
+                   break;
 
-               default:
-                 warn (_("Unrecognised debug option '%s'\n"), optarg);
-                 break;
-               }
+                 case 'm':
+                 case 'M':
+                   do_debug_macinfo = 1;
+                   break;
+
+                 default:
+                   warn (_("Unrecognised debug option '%s'\n"), optarg);
+                   break;
+                 }
            }
          break;
 #ifdef SUPPORT_DISASSEMBLY
@@ -5795,6 +5771,13 @@ display_debug_lines (section, start, file)
 
       /* Check the length of the block.  */
       info.li_length = BYTE_GET (external->li_length);
+
+      if (info.li_length == 0xffffffff)
+       {
+         warn (_("64-bit DWARF line info is not supported yet.\n"));
+         break;
+       }
+
       if (info.li_length + sizeof (external->li_length) > section->sh_size)
        {
          warn
@@ -6023,6 +6006,12 @@ display_debug_pubnames (section, start, file)
       data   = start + sizeof (* external);
       start += pubnames.pn_length + sizeof (external->pn_length);
 
+      if (pubnames.pn_length == 0xffffffff)
+       {
+         warn (_("64-bit DWARF pubnames are not supported yet.\n"));
+         break;
+       }
+
       if (pubnames.pn_version != 2)
        {
          static int warned = 0;
@@ -7067,7 +7056,7 @@ read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
          /* DWARF 2.1 values.  */
        case DW_LANG_C99:            printf ("(ANSI C99)"); break;
        case DW_LANG_Ada95:          printf ("(ADA 95)"); break;
-       case DW_LANG_Fortran95:       printf ("(Fortran 95)"); break;
+       case DW_LANG_Fortran95:      printf ("(Fortran 95)"); break;
          /* MIPS extension.  */
        case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
        default:                     printf ("(Unknown: %lx)", uvalue); break;
@@ -7217,6 +7206,12 @@ display_debug_info (section, start, file)
       compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
       compunit.cu_pointer_size  = BYTE_GET (external->cu_pointer_size);
 
+      if (compunit.cu_length == 0xffffffff)
+       {
+         warn (_("64-bit DWARF debug info is not supported yet.\n"));
+         break;
+       }
+
       /* Check for RELA relocations in the abbrev_offset address, and
          apply them.  */
       for (relsec = section_headers;
@@ -7410,6 +7405,12 @@ display_debug_aranges (section, start, file)
       arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
       arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
 
+      if (arange.ar_length == 0xffffffff)
+       {
+         warn (_("64-bit DWARF aranges are not supported yet.\n"));
+         break;
+       }
+
       if (arange.ar_version != 2)
        {
          warn (_("Only DWARF 2 aranges are currently supported.\n"));
@@ -7625,6 +7626,12 @@ display_debug_frames (section, start, file)
       if (length == 0)
        return 1;
 
+      if (length == 0xffffffff)
+       {
+         warn (_("64-bit DWARF format frames are not supported yet.\n"));
+         break;
+       }
+
       block_end = saved_start + length + 4;
       cie_id = byte_get (start, 4); start += 4;
 
@@ -7733,7 +7740,7 @@ display_debug_frames (section, start, file)
 
          look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
 
-         for (cie=chunks; cie ; cie = cie->next)
+         for (cie = chunks; cie ; cie = cie->next)
            if (cie->chunk_start == look_for)
              break;
 
@@ -8175,6 +8182,7 @@ debug_displays[] =
   { ".debug_frame",       display_debug_frames, NULL },
   { ".eh_frame",          display_debug_frames, NULL },
   { ".debug_macinfo",     display_debug_macinfo, NULL },
+  { ".debug_pubtypes",    display_debug_not_supported, NULL },
   { ".debug_str",         display_debug_not_supported, NULL },
   { ".debug_static_func", display_debug_not_supported, NULL },
   { ".debug_static_vars", display_debug_not_supported, NULL },
@@ -9104,6 +9112,8 @@ db_task_printsym (unsigned int addr)
 }
 #endif
 
+int main PARAMS ((int, char **));
+
 int
 main (argc, argv)
      int     argc;