Mach-O: improve objdump -P load output.
authorTristan Gingold <tristan.gingold@adacore.com>
Fri, 11 Apr 2014 13:27:10 +0000 (15:27 +0200)
committerTristan Gingold <tristan.gingold@adacore.com>
Wed, 16 Apr 2014 08:51:05 +0000 (10:51 +0200)
binutils/
* od-macho.c (dump_header): Display sizeofcmds in decimal too.
(dump_segment): Reformat output.
(dump_dyld_info): Also display end offsets.
(dump_load_command): Add IDX argument, display commands size
and offset, reformat display.
(dump_load_commands): Adjust for added argument.

binutils/ChangeLog
binutils/od-macho.c

index 56df68f03c1b5ab273c6712b8edaf45f6d2443d9..02931b78d6e5711d6221a8cb9d2fecab4306de10 100644 (file)
@@ -1,3 +1,12 @@
+2014-04-16  Tristan Gingold  <gingold@adacore.com>
+
+       * od-macho.c (dump_header): Display sizeofcmds in decimal too.
+       (dump_segment): Reformat output.
+       (dump_dyld_info): Also display end offsets.
+       (dump_load_command): Add IDX argument, display commands size
+       and offset, reformat display.
+       (dump_load_commands): Adjust for added argument.
+
 2014-04-07  Alan Modra  <amodra@gmail.com>
 
        PR binutils/16811
index 780b43848375288f0f8510667a9f825d20e75539..92d6a73322f49a3f5607b8e9c92284e9dea8aff7 100644 (file)
@@ -294,7 +294,7 @@ dump_header (bfd *abfd)
           h->filetype,
           bfd_mach_o_get_name (bfd_mach_o_filetype_name, h->filetype));
   printf (_(" ncmds     : %08lx (%lu)\n"), h->ncmds, h->ncmds);
-  printf (_(" sizeofcmds: %08lx\n"), h->sizeofcmds);
+  printf (_(" sizeofcmds: %08lx (%lu)\n"), h->sizeofcmds, h->sizeofcmds);
   printf (_(" flags     : %08lx ("), h->flags);
   bfd_mach_o_print_flags (bfd_mach_o_header_flags_name, h->flags);
   fputs (_(")\n"), stdout);
@@ -405,26 +405,26 @@ dump_segment (bfd *abfd ATTRIBUTE_UNUSED, bfd_mach_o_load_command *cmd)
   bfd_mach_o_segment_command *seg = &cmd->command.segment;
   bfd_mach_o_section *sec;
 
-  printf (" name: %s\n", *seg->segname ? seg->segname : "*none*");
-  printf ("    vmaddr: ");
+  printf ("     name: %16s", *seg->segname ? seg->segname : "*none*");
+  printf ("  nsects: %lu", seg->nsects);
+  printf ("  flags: %lx", seg->flags);
+  printf ("  initprot: ");
+  disp_segment_prot (seg->initprot);
+  printf ("  maxprot: ");
+  disp_segment_prot (seg->maxprot);
+  printf ("\n");
+  printf ("   vmaddr: ");
   printf_vma (seg->vmaddr);
   printf ("   vmsize: ");
   printf_vma  (seg->vmsize);
   printf ("\n");
-  printf ("   fileoff: ");
+  printf ("  fileoff: ");
   printf_vma (seg->fileoff);
   printf (" filesize: ");
   printf_vma ((bfd_vma)seg->filesize);
   printf (" endoff: ");
   printf_vma ((bfd_vma)(seg->fileoff + seg->filesize));
   printf ("\n");
-  printf ("   nsects: %lu", seg->nsects);
-  printf ("   flags: %lx", seg->flags);
-  printf ("   initprot: ");
-  disp_segment_prot (seg->initprot);
-  printf ("   maxprot: ");
-  disp_segment_prot (seg->maxprot);
-  printf ("\n");
   for (sec = seg->sect_head; sec != NULL; sec = sec->next)
     dump_section_header (abfd, sec);
 }
@@ -627,16 +627,21 @@ dump_dyld_info (bfd *abfd ATTRIBUTE_UNUSED, bfd_mach_o_load_command *cmd)
 {
   bfd_mach_o_dyld_info_command *info = &cmd->command.dyld_info;
 
-  printf ("       rebase: off: 0x%08x  size: %-8u\n",
-           info->rebase_off, info->rebase_size);
-  printf ("         bind: off: 0x%08x  size: %-8u\n",
-           info->bind_off, info->bind_size);
-  printf ("    weak bind: off: 0x%08x  size: %-8u\n",
-           info->weak_bind_off, info->weak_bind_size);
-  printf ("    lazy bind: off: 0x%08x  size: %-8u\n",
-           info->lazy_bind_off, info->lazy_bind_size);
-  printf ("       export: off: 0x%08x  size: %-8u\n",
-           info->export_off, info->export_size);
+  printf ("       rebase: off: 0x%08x  size: %-8u   (endoff: 0x%08x)\n",
+         info->rebase_off, info->rebase_size,
+         info->rebase_off + info->rebase_size);
+  printf ("         bind: off: 0x%08x  size: %-8u   (endoff: 0x%08x)\n",
+         info->bind_off, info->bind_size,
+         info->bind_off + info->bind_size);
+  printf ("    weak bind: off: 0x%08x  size: %-8u   (endoff: 0x%08x)\n",
+         info->weak_bind_off, info->weak_bind_size,
+         info->weak_bind_off + info->weak_bind_size);
+  printf ("    lazy bind: off: 0x%08x  size: %-8u   (endoff: 0x%08x)\n",
+         info->lazy_bind_off, info->lazy_bind_size,
+         info->lazy_bind_off + info->lazy_bind_size);
+  printf ("       export: off: 0x%08x  size: %-8u   (endoff: 0x%08x)\n",
+         info->export_off, info->export_size,
+         info->export_off + info->export_size);
 }
 
 static void
@@ -1084,18 +1089,19 @@ dump_twolevel_hints (bfd *abfd, bfd_mach_o_twolevel_hints_command *cmd)
 
 static void
 dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
-                   bfd_boolean verbose)
+                   unsigned int idx, bfd_boolean verbose)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   const char *cmd_name;
 
   cmd_name = bfd_mach_o_get_name_or_null
     (bfd_mach_o_load_command_name, cmd->type);
-  printf ("Load command ");
+  printf ("Load command #%-2u (size: %3u, offset: %4u): ",
+         idx, cmd->len, cmd->offset);
   if (cmd_name == NULL)
-    printf ("0x%02x:", cmd->type);
+    printf ("0x%02x\n", cmd->type);
   else
-    printf ("%s:", cmd_name);
+    printf ("%s\n", cmd_name);
 
   switch (cmd->type)
     {
@@ -1108,6 +1114,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
         bfd_mach_o_uuid_command *uuid = &cmd->command.uuid;
         unsigned int j;
 
+       printf ("   ");
         for (j = 0; j < sizeof (uuid->uuid); j ++)
           printf (" %02x", uuid->uuid[j]);
         putchar ('\n');
@@ -1121,7 +1128,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
     case BFD_MACH_O_LC_LOAD_UPWARD_DYLIB:
       {
         bfd_mach_o_dylib_command *dylib = &cmd->command.dylib;
-        printf (" %s\n", dylib->name_str);
+        printf ("  name: %s\n", dylib->name_str);
         printf ("            time stamp: 0x%08lx\n",
                 dylib->timestamp);
         printf ("       current version: 0x%08lx\n",
@@ -1132,17 +1139,15 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
       break;
     case BFD_MACH_O_LC_LOAD_DYLINKER:
     case BFD_MACH_O_LC_ID_DYLINKER:
-      printf (" %s\n", cmd->command.dylinker.name_str);
+      printf ("    %s\n", cmd->command.dylinker.name_str);
       break;
     case BFD_MACH_O_LC_DYLD_ENVIRONMENT:
-      putchar ('\n');
-      printf ("  %s\n", cmd->command.dylinker.name_str);
+      printf ("    %s\n", cmd->command.dylinker.name_str);
       break;
     case BFD_MACH_O_LC_SYMTAB:
       {
         bfd_mach_o_symtab_command *symtab = &cmd->command.symtab;
-        printf ("\n"
-                "   symoff: 0x%08x    nsyms: %8u  (endoff: 0x%08x)\n",
+        printf ("   symoff: 0x%08x    nsyms: %8u  (endoff: 0x%08x)\n",
                 symtab->symoff, symtab->nsyms,
                 symtab->symoff + symtab->nsyms
                 * (mdata->header.version == 2
@@ -1153,14 +1158,13 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
         break;
       }
     case BFD_MACH_O_LC_DYSYMTAB:
-      putchar ('\n');
       dump_dysymtab (abfd, cmd, verbose);
       break;
     case BFD_MACH_O_LC_LOADFVMLIB:
     case BFD_MACH_O_LC_IDFVMLIB:
       {
         bfd_mach_o_fvmlib_command *fvmlib = &cmd->command.fvmlib;
-        printf (" %s\n", fvmlib->name_str);
+        printf ("                fvmlib: %s\n", fvmlib->name_str);
         printf ("         minor version: 0x%08x\n", fvmlib->minor_version);
         printf ("        header address: 0x%08x\n", fvmlib->header_addr);
       }
@@ -1173,8 +1177,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
       {
         bfd_mach_o_linkedit_command *linkedit = &cmd->command.linkedit;
         printf
-          ("\n"
-           "  dataoff: 0x%08lx  datasize: 0x%08lx  (endoff: 0x%08lx)\n",
+          ("  dataoff: 0x%08lx  datasize: 0x%08lx  (endoff: 0x%08lx)\n",
            linkedit->dataoff, linkedit->datasize,
            linkedit->dataoff + linkedit->datasize);
 
@@ -1205,7 +1208,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
     case BFD_MACH_O_LC_RPATH:
       {
         bfd_mach_o_str_command *str = &cmd->command.str;
-        printf (" %s\n", str->str);
+        printf ("    %s\n", str->str);
         break;
       }
     case BFD_MACH_O_LC_THREAD:
@@ -1217,8 +1220,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
         bfd_mach_o_encryption_info_command *cryp =
           &cmd->command.encryption_info;
         printf
-          ("\n"
-           "  cryptoff: 0x%08x  cryptsize: 0x%08x (endoff 0x%08x)"
+          ("  cryptoff: 0x%08x  cryptsize: 0x%08x (endoff 0x%08x)"
            " cryptid: %u\n",
            cryp->cryptoff, cryp->cryptsize,
            cryp->cryptoff + cryp->cryptsize,
@@ -1226,7 +1228,6 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
       }
       break;
     case BFD_MACH_O_LC_DYLD_INFO:
-      putchar ('\n');
       dump_dyld_info (abfd, cmd);
       break;
     case BFD_MACH_O_LC_VERSION_MIN_MACOSX:
@@ -1234,15 +1235,14 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
       {
         bfd_mach_o_version_min_command *ver = &cmd->command.version_min;
 
-        printf (" %u.%u.%u\n", ver->rel, ver->maj, ver->min);
+        printf ("    %u.%u.%u\n", ver->rel, ver->maj, ver->min);
       }
       break;
     case BFD_MACH_O_LC_SOURCE_VERSION:
       {
         bfd_mach_o_source_version_command *version =
          &cmd->command.source_version;
-        printf ("\n"
-                "   version a.b.c.d.e: %u.%u.%u.%u.%u\n",
+        printf ("   version a.b.c.d.e: %u.%u.%u.%u.%u\n",
                version->a, version->b, version->c, version->d, version->e);
         break;
       }
@@ -1253,7 +1253,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
        unsigned int j;
        unsigned int last;
 
-        printf (" %s\n", pbdy->name_str);
+        printf ("      dylib: %s\n", pbdy->name_str);
         printf ("   nmodules: %u\n", pbdy->nmodules);
        printf ("   linked modules (at %u): ",
                pbdy->linked_modules_offset - cmd->offset);
@@ -1268,7 +1268,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
     case BFD_MACH_O_LC_PREBIND_CKSUM:
       {
         bfd_mach_o_prebind_cksum_command *cksum = &cmd->command.prebind_cksum;
-        printf (" 0x%08x\n", cksum->cksum);
+        printf ("   0x%08x\n", cksum->cksum);
         break;
       }
     case BFD_MACH_O_LC_TWOLEVEL_HINTS:
@@ -1276,8 +1276,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
         bfd_mach_o_twolevel_hints_command *hints =
          &cmd->command.twolevel_hints;
 
-        printf ("\n"
-                "   table offset: 0x%08x  nbr hints: %u\n",
+        printf ("   table offset: 0x%08x  nbr hints: %u\n",
                hints->offset, hints->nhints);
        if (verbose)
          dump_twolevel_hints (abfd, hints);
@@ -1286,8 +1285,7 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
     case BFD_MACH_O_LC_MAIN:
       {
         bfd_mach_o_main_command *entry = &cmd->command.main;
-        printf ("\n"
-                "   entry offset: ");
+        printf ("   entry offset: ");
        printf_uint64 (entry->entryoff);
         printf ("\n"
                 "   stack size:   ");
@@ -1296,9 +1294,6 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
         break;
       }
     default:
-      putchar ('\n');
-      printf ("  offset: 0x%08lx\n", (unsigned long)cmd->offset);
-      printf ("    size: 0x%08lx\n", (unsigned long)cmd->len);
       break;
     }
   putchar ('\n');
@@ -1315,9 +1310,9 @@ dump_load_commands (bfd *abfd, unsigned int cmd32, unsigned int cmd64)
       bfd_mach_o_load_command *cmd = &mdata->commands[i];
 
       if (cmd32 == 0)
-        dump_load_command (abfd, cmd, FALSE);
+        dump_load_command (abfd, cmd, i, FALSE);
       else if (cmd->type == cmd32 || cmd->type == cmd64)
-        dump_load_command (abfd, cmd, TRUE);
+        dump_load_command (abfd, cmd, i, TRUE);
     }
 }