X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=binutils%2Fcoffdump.c;h=7b6ead4af3886a11ee40e40e4a1fa9fff0edcfac;hb=51afcce0d32788512d303eb321b332492e8691d1;hp=120915d7f0dda15ec02441b773bb23b031cd09e7;hpb=958998b7aacbe2a7da7928add10a20e0b0e7424f;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/coffdump.c b/binutils/coffdump.c index 120915d7f0..7b6ead4af3 100644 --- a/binutils/coffdump.c +++ b/binutils/coffdump.c @@ -1,55 +1,52 @@ /* Coff file dumper. - Copyright (C) 1994 Free Software Foundation, Inc. + Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007 + 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 2 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., 675 Mass Ave, Cambridge, MA 02139, 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Steve Chamberlain This module reads a type tree generated by coffgrok and prints - it out so we can test the grokker. -*/ + it out so we can test the grokker. */ -#include -#include -#include -#include +#include "sysdep.h" +#include "bfd.h" +#include "libiberty.h" #include "bucomm.h" #include "coffgrok.h" - - -#define PROGRAM_VERSION "1.0" - - -char *xcalloc(a,b) -int a; -int b; -{ - char *r = xmalloc(a*b); - memset (r, 0, a * b); - return r; -} +#include "getopt.h" static int atnl; -static void dump_coff_scope (); + +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; @@ -91,42 +88,52 @@ 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); + switch (p->type) { + case coff_secdef_type: + printf ("section definition at %x size %x\n", + p->u.asecdef.address, + p->u.asecdef.size); + nl (); + break; case coff_pointer_type: printf ("pointer to"); nl (); @@ -233,8 +240,7 @@ 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) @@ -273,8 +279,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) @@ -319,14 +324,13 @@ 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"); nl (); + while (p) { tab (1); @@ -354,47 +358,48 @@ 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 ("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 (); - 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"); nl (); + while (p) { tab (0); @@ -407,68 +412,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(); - for (i = 0; i < ptr->nrelocs; 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 (); + + 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(); + tab (0); + printf ("(%x %s %x)", + ptr->relocs[i].offset, + ptr->relocs[i].symbol->name, + ptr->relocs[i].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); 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 SYSROFF object file\n")); + fprintf (file, _(" The options are:\n\ + @ Read options from \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; @@ -482,27 +484,39 @@ main (ac, av) { NULL, no_argument, 0, 0 } }; +#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) + setlocale (LC_MESSAGES, ""); +#endif +#if defined (HAVE_SETLOCALE) + setlocale (LC_CTYPE, ""); +#endif + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + program_name = av[0]; xmalloc_set_program_name (program_name); - while ((opt = getopt_long (ac, av, "hV", long_options, + expandargv (&ac, &av); + + 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; } } @@ -512,11 +526,8 @@ main (ac, av) } if (!input_file) - { - fprintf (stderr,"%s: no input file specified\n", - program_name); - exit(1); - } + fatal (_("no input file specified")); + abfd = bfd_openr (input_file, 0); if (!abfd) @@ -525,6 +536,7 @@ 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); @@ -535,7 +547,8 @@ main (ac, av) tree = coff_grok (abfd); - coff_dump(tree); - printf("\n"); + coff_dump (tree); + printf ("\n"); + return 0; }