]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/coffdump.c
gprofng: use StringBuilder to create long messages
[thirdparty/binutils-gdb.git] / binutils / coffdump.c
index 42a1e706c9fabe4f03925173ae31a4cdca4faaeb..59906b63da857b1ecaf0ca60f54ce0416aa4d0bd 100644 (file)
@@ -1,57 +1,54 @@
 /* Coff file dumper.
-   Copyright 1994, 1995, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1994-2024 Free Software Foundation, Inc.
 
-This file is part of GNU Binutils.
+   This file is part of GNU Binutils.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or (at
+   your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* Written by Steve Chamberlain <sac@cygnus.com>
 
    This module reads a type tree generated by coffgrok and prints
-   it out so we can test the grokker.
-*/
-
-#include <bfd.h>
-#include <getopt.h>
-#include <libiberty.h>
+   it out so we can test the grokker.  */
 
-#include "coffgrok.h"
+#include "sysdep.h"
+#include "bfd.h"
+#include <stdint.h>
+#include "libiberty.h"
 #include "bucomm.h"
 
-#define PROGRAM_VERSION "1.0"
+#include "coffgrok.h"
+#include "getopt.h"
 
 static int atnl;
 
-static void tab PARAMS ((int));
-static void nl PARAMS ((void));
-static void dump_coff_lines PARAMS ((struct coff_line *));
-static void dump_coff_type PARAMS ((struct coff_type *));
-static void dump_coff_where PARAMS ((struct coff_where *));
-static void dump_coff_visible PARAMS ((struct coff_visible *));
-extern void dump_coff_symbol PARAMS ((struct coff_symbol *));
-static void dump_coff_scope PARAMS ((struct coff_scope *));
-static void dump_coff_sfile PARAMS ((struct coff_sfile *));
-static void dump_coff_section PARAMS ((struct coff_section *));
-extern void coff_dump PARAMS ((struct coff_ofile *));
-static void show_usage PARAMS ((FILE *, int));
-static void show_help PARAMS ((void));
-extern int main PARAMS ((int, char **));
+static void tab (int);
+static void nl (void);
+static void dump_coff_lines (struct coff_line *);
+static void dump_coff_type (struct coff_type *);
+static void dump_coff_where (struct coff_where *);
+static void dump_coff_visible (struct coff_visible *);
+static void dump_coff_scope (struct coff_scope *);
+static void dump_coff_sfile (struct coff_sfile *);
+static void dump_coff_section (struct coff_section *);
+static void show_usage (FILE *, int);
+extern int main (int, char **);
 
 static void
-tab (x)
-int x;
+tab (int x)
 {
   static int indent;
   int i;
@@ -93,88 +90,92 @@ int x;
     }
 }
 
-static void nl ()
+static void
+nl (void)
 {
   atnl = 1;
 }
 
 static void
-dump_coff_lines (p)
-     struct coff_line *p;
+dump_coff_lines (struct coff_line *p)
 {
   int i;
   int online = 0;
-  tab(1);
-  printf(_("#lines %d "),p->nlines);
-  for (i = 0; i < p->nlines; i++) 
+
+  tab (1);
+  printf (_("#lines %d "),p->nlines);
+
+  for (i = 0; i < p->nlines; i++)
     {
-      printf("(%d 0x%x)", p->lines[i], p->addresses[i]);
+      printf ("(%d 0x%x)", p->lines[i], p->addresses[i]);
+
       online++;
+
       if (online > 6)
        {
-         nl();
-         tab(0);
+         nl ();
+         tab (0);
          online = 0;
        }
     }
-  nl();
-  tab(-1);
+  nl ();
+  tab (-1);
 }
 
 static void
-dump_coff_type (p)
-     struct coff_type *p;
+dump_coff_type (struct coff_type *p)
 {
   tab (1);
-  printf ("size %d ", p->size);
+  printf (_("size %d "), p->size);
+
   switch (p->type)
     {
     case coff_secdef_type:
-      printf ("section definition at %x size %x\n", 
+      printf (_("section definition at %x size %x\n"),
              p->u.asecdef.address,
              p->u.asecdef.size);
-      nl();
+      nl ();
       break;
     case coff_pointer_type:
-      printf ("pointer to");
+      printf (_("pointer to"));
       nl ();
       dump_coff_type (p->u.pointer.points_to);
       break;
     case coff_array_type:
-      printf ("array [%d] of", p->u.array.dim);
+      printf (_("array [%d] of"), p->u.array.dim);
       nl ();
       dump_coff_type (p->u.array.array_of);
       break;
     case coff_function_type:
-      printf ("function returning");
+      printf (_("function returning"));
       nl ();
       dump_coff_type (p->u.function.function_returns);
       dump_coff_lines (p->u.function.lines);
-      printf ("arguments");
+      printf (_("arguments"));
       nl ();
       dump_coff_scope (p->u.function.parameters);
       tab (0);
-      printf ("code");
+      printf (_("code"));
       nl ();
       dump_coff_scope (p->u.function.code);
       tab(0);
       break;
     case coff_structdef_type:
-      printf ("structure definition");
+      printf (_("structure definition"));
       nl ();
       dump_coff_scope (p->u.astructdef.elements);
       break;
     case coff_structref_type:
       if (!p->u.aenumref.ref)
-       printf ("structure ref to UNKNOWN struct");
+       printf (_("structure ref to UNKNOWN struct"));
       else
-       printf ("structure ref to %s", p->u.aenumref.ref->name);
+       printf (_("structure ref to %s"), p->u.aenumref.ref->name);
       break;
     case coff_enumref_type:
-      printf ("enum ref to %s", p->u.astructref.ref->name);
+      printf (_("enum ref to %s"), p->u.astructref.ref->name);
       break;
     case coff_enumdef_type:
-      printf ("enum definition");
+      printf (_("enum definition"));
       nl ();
       dump_coff_scope (p->u.aenumdef.elements);
       break;
@@ -241,32 +242,32 @@ dump_coff_type (p)
 }
 
 static void
-dump_coff_where (p)
-     struct coff_where *p;
+dump_coff_where (struct coff_where *p)
 {
   tab (1);
   switch (p->where)
     {
     case coff_where_stack:
-      printf ("Stack offset %x", p->offset);
+      printf (_("Stack offset %x"), p->offset);
       break;
     case coff_where_memory:
-      printf ("Memory section %s+%x", p->section->name, p->offset);
+      printf (_("Memory section %s+%x"), p->section->name, p->offset);
       break;
     case coff_where_register:
-      printf ("Register %d", p->offset);
+      printf (_("Register %d"), p->offset);
       break;
     case coff_where_member_of_struct:
-      printf ("Struct Member offset %x", p->offset);
+      printf (_("Struct Member offset %x"), p->offset);
       break;
     case coff_where_member_of_enum:
-      printf ("Enum Member offset %x", p->offset);
+      printf (_("Enum Member offset %x"), p->offset);
       break;
     case coff_where_unknown:
-      printf ("Undefined symbol");
+      printf (_("Undefined symbol"));
       break;
     case coff_where_strtag:
       printf ("STRTAG");
+      break;
     case coff_where_entag:
       printf ("ENTAG");
       break;
@@ -281,8 +282,7 @@ dump_coff_where (p)
 }
 
 static void
-dump_coff_visible (p)
-     struct coff_visible *p;
+dump_coff_visible (struct coff_visible *p)
 {
   tab (1);
   switch (p->type)
@@ -327,32 +327,31 @@ dump_coff_visible (p)
   tab (-1);
 }
 
-
-void
-dump_coff_symbol (p)
-     struct coff_symbol *p;
+static void
+dump_coff_symbol (struct coff_symbol *p)
 {
   tab (1);
-  printf ("List of symbols");
+  printf (_("List of symbols"));
   nl ();
+
   while (p)
     {
       tab (1);
       tab (1);
-      printf ("Symbol  %s, tag %d, number %d", p->name, p->tag, p->number);
+      printf (_("Symbol  %s, tag %d, number %d"), p->name, p->tag, p->number);
       nl ();
       tab (-1);
       tab (1);
-      printf ("Type");
+      printf (_("Type"));
       nl ();
       dump_coff_type (p->type);
       tab (-1);
       tab (1);
-      printf ("Where");
+      printf (_("Where"));
       dump_coff_where (p->where);
       tab (-1);
       tab (1);
-      printf ("Visible");
+      printf (_("Visible"));
       dump_coff_visible (p->visible);
       tab (-1);
       p = p->next;
@@ -362,51 +361,52 @@ dump_coff_symbol (p)
 }
 
 static void
-dump_coff_scope (p)
-     struct coff_scope *p;
+dump_coff_scope (struct coff_scope *p)
 {
-if (p) {
-  tab (1);
-  printf ("List of blocks %lx ",(unsigned long) p);
-
-  if (p->sec) {
-    printf( "  %s %x..%x",  p->sec->name,p->offset, p->offset + p->size -1);
-  }
-  nl ();
-  tab (0);
-  printf ("*****************");
-  nl ();
-  while (p)
+  if (p)
     {
-      tab (0);
-      printf ("vars %d", p->nvars);
+      tab (1);
+      printf ("%s %p ", _("List of blocks "), p);
+
+      if (p->sec)
+       printf( "  %s %x..%x",  p->sec->name,p->offset, p->offset + p->size -1);
+
       nl ();
-      dump_coff_symbol (p->vars_head);
-      printf ("blocks");
+      tab (0);
+      printf ("*****************");
       nl ();
-      dump_coff_scope (p->list_head);
+
+      while (p)
+       {
+         tab (0);
+         printf (_("vars %d"), p->nvars);
+         nl ();
+         dump_coff_symbol (p->vars_head);
+         printf (_("blocks"));
+         nl ();
+         dump_coff_scope (p->list_head);
+         nl ();
+         p = p->next;
+       }
+
+      tab (0);
+      printf ("*****************");
       nl ();
-      p = p->next;
+      tab (-1);
     }
-
-  tab (0);
-  printf ("*****************");
-  nl ();
-  tab (-1);
-}
 }
 
 static void
-dump_coff_sfile (p)
-     struct coff_sfile *p;
+dump_coff_sfile (struct coff_sfile *p)
 {
   tab (1);
-  printf ("List of source files");
+  printf (_("List of source files"));
   nl ();
+
   while (p)
     {
       tab (0);
-      printf ("Source file %s", p->name);
+      printf (_("Source file %s"), p->name);
       nl ();
       dump_coff_scope (p->scope);
       p = p->next;
@@ -415,68 +415,65 @@ dump_coff_sfile (p)
 }
 
 static void
-dump_coff_section(ptr)
-struct coff_section *ptr;
+dump_coff_section (struct coff_section *ptr)
 {
-  int i;
-  tab(1);
-  printf("section %s %d %d address %x size %x number %d nrelocs %d", 
-        ptr->name, ptr->code, ptr->data, ptr->address,ptr->size, ptr->number, ptr->nrelocs);
-  nl();
+  unsigned int i;
 
-  for (i = 0; i < ptr->nrelocs; i++) 
+  tab (1);
+  printf (_("section %s %d %d address %x size %x number %d nrelocs %u"),
+         ptr->name, ptr->code, ptr->data, ptr->address,ptr->size,
+         ptr->number, ptr->nrelocs);
+  nl ();
+
+  for (i = 0; i < ptr->nrelocs; i++)
     {
-      tab(0);    
-      printf("(%x %s %x)",
-            ptr->relocs[i].offset,
-            ptr->relocs[i].symbol->name,
-            ptr->relocs[i].addend);
-      nl();
+      struct coff_reloc * r = ptr->relocs + i;
+      tab (0);
+      printf ("(%x %s %x)",
+             r->offset,
+             /* PR 17512: file: 0a38fb7c.  */
+             r->symbol == NULL ? _("<no sym>") : r->symbol->name,
+             r->addend);
+      nl ();
     }
-  tab(-1);
 
+  tab (-1);
 }
 
-void
-coff_dump (ptr)
-     struct coff_ofile *ptr;
+static void
+coff_dump (struct coff_ofile *ptr)
 {
   int i;
+
   printf ("Coff dump");
   nl ();
-  printf ("#souces %d", ptr->nsources);
+  printf (_("#sources %d"), ptr->nsources);
   nl ();
   dump_coff_sfile (ptr->source_head);
+
   for (i = 0; i < ptr->nsections; i++)
-    dump_coff_section(ptr->sections + i);
+    dump_coff_section (ptr->sections + i);
 }
 
-
-
-char * program_name;
-
 static void
-show_usage (file, status)
-     FILE *file;
-     int status;
+show_usage (FILE *file, int status)
 {
-  fprintf (file, "Usage: %s [-hV] in-file\n",   program_name);
-  exit (status);
-}
+  fprintf (file, _("Usage: %s [option(s)] in-file\n"), program_name);
+  fprintf (file, _(" Print a human readable interpretation of a COFF object file\n"));
+  fprintf (file, _(" The options are:\n\
+  @<file>                Read options from <file>\n\
+  -h --help              Display this information\n\
+  -v --version           Display the program's version\n\
+\n"));
 
-static void
-show_help ()
-{
-  printf (_("%s: Print a human readable interpretation of a SYSROFF object file\n"),
-         program_name);
-  show_usage (stdout, 0);
-}
+  if (REPORT_BUGS_TO[0] && status == 0)
+    fprintf (file, _("Report bugs to %s\n"), REPORT_BUGS_TO);
 
+  exit (status);
+}
 
 int
-main (ac, av)
-     int ac;
-     char *av[];
+main (int ac, char **av)
 {
   bfd *abfd;
   struct coff_ofile *tree;
@@ -490,33 +487,38 @@ main (ac, av)
       { NULL, no_argument, 0, 0 }
     };
 
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
+#ifdef HAVE_LC_MESSAGES
   setlocale (LC_MESSAGES, "");
 #endif
+  setlocale (LC_CTYPE, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
   program_name = av[0];
   xmalloc_set_program_name (program_name);
+  bfd_set_error_program_name (program_name);
+
+  expandargv (&ac, &av);
 
-  while ((opt = getopt_long (ac, av, "hV", long_options,
+  while ((opt = getopt_long (ac, av, "HhVv", long_options,
                             (int *) NULL))
         != EOF)
     {
       switch (opt)
        {
+       case 'H':
        case 'h':
-         show_help ();
-         /*NOTREACHED*/
+         show_usage (stdout, 0);
+         break;
+       case 'v':
        case 'V':
-         printf (_("GNU %s version %s\n"), program_name, PROGRAM_VERSION);
+         print_version ("coffdump");
          exit (0);
-         /*NOTREACHED*/
        case 0:
          break;
        default:
          show_usage (stderr, 1);
-         /*NOTREACHED*/
+         break;
        }
     }
 
@@ -526,9 +528,8 @@ main (ac, av)
     }
 
   if (!input_file)
-    {
-      fatal (_("no input file specified"));
-    }
+    fatal (_("no input file specified"));
+
   abfd = bfd_openr (input_file, 0);
 
   if (!abfd)
@@ -537,17 +538,18 @@ main (ac, av)
   if (! bfd_check_format_matches (abfd, bfd_object, &matching))
     {
       bfd_nonfatal (input_file);
+
       if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
-       {
-         list_matching_formats (matching);
-         free (matching);
-       }
+       list_matching_formats (matching);
       exit (1);
     }
 
   tree = coff_grok (abfd);
+  if (tree)
+    {
+      coff_dump (tree);
+      printf ("\n");
+    }
 
-  coff_dump(tree);
-  printf("\n");
   return 0;
 }