2 Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 /* Written by Steve Chamberlain <sac@cygnus.com>
23 This module reads a type tree generated by coffgrok and prints
24 it out so we can test the grokker. */
28 #include "libiberty.h"
36 static void tab (int);
37 static void nl (void);
38 static void dump_coff_lines (struct coff_line *);
39 static void dump_coff_type (struct coff_type *);
40 static void dump_coff_where (struct coff_where *);
41 static void dump_coff_visible (struct coff_visible *);
42 static void dump_coff_scope (struct coff_scope *);
43 static void dump_coff_sfile (struct coff_sfile *);
44 static void dump_coff_section (struct coff_section *);
45 static void show_usage (FILE *, int);
46 extern int main (int, char **);
72 for (i = 0; i < indent; i++)
82 for (i = 0; i < indent; i++)
98 dump_coff_lines (struct coff_line *p)
104 printf (_("#lines %d "),p->nlines);
106 for (i = 0; i < p->nlines; i++)
108 printf ("(%d 0x%x)", p->lines[i], p->addresses[i]);
124 dump_coff_type (struct coff_type *p)
127 printf ("size %d ", p->size);
131 case coff_secdef_type:
132 printf ("section definition at %x size %x\n",
133 p->u.asecdef.address,
137 case coff_pointer_type:
138 printf ("pointer to");
140 dump_coff_type (p->u.pointer.points_to);
142 case coff_array_type:
143 printf ("array [%d] of", p->u.array.dim);
145 dump_coff_type (p->u.array.array_of);
147 case coff_function_type:
148 printf ("function returning");
150 dump_coff_type (p->u.function.function_returns);
151 dump_coff_lines (p->u.function.lines);
152 printf ("arguments");
154 dump_coff_scope (p->u.function.parameters);
158 dump_coff_scope (p->u.function.code);
161 case coff_structdef_type:
162 printf ("structure definition");
164 dump_coff_scope (p->u.astructdef.elements);
166 case coff_structref_type:
167 if (!p->u.aenumref.ref)
168 printf ("structure ref to UNKNOWN struct");
170 printf ("structure ref to %s", p->u.aenumref.ref->name);
172 case coff_enumref_type:
173 printf ("enum ref to %s", p->u.astructref.ref->name);
175 case coff_enumdef_type:
176 printf ("enum definition");
178 dump_coff_scope (p->u.aenumdef.elements);
180 case coff_basic_type:
243 dump_coff_where (struct coff_where *p)
248 case coff_where_stack:
249 printf ("Stack offset %x", p->offset);
251 case coff_where_memory:
252 printf ("Memory section %s+%x", p->section->name, p->offset);
254 case coff_where_register:
255 printf ("Register %d", p->offset);
257 case coff_where_member_of_struct:
258 printf ("Struct Member offset %x", p->offset);
260 case coff_where_member_of_enum:
261 printf ("Enum Member offset %x", p->offset);
263 case coff_where_unknown:
264 printf ("Undefined symbol");
266 case coff_where_strtag:
268 case coff_where_entag:
271 case coff_where_typedef:
282 dump_coff_visible (struct coff_visible *p)
287 case coff_vis_ext_def:
288 printf ("coff_vis_ext_def");
290 case coff_vis_ext_ref:
291 printf ("coff_vis_ext_ref");
293 case coff_vis_int_def:
294 printf ("coff_vis_int_def");
296 case coff_vis_common:
297 printf ("coff_vis_common");
300 printf ("coff_vis_auto");
302 case coff_vis_autoparam:
303 printf ("coff_vis_autoparam");
305 case coff_vis_regparam:
306 printf ("coff_vis_regparam");
308 case coff_vis_register:
309 printf ("coff_vis_register");
312 printf ("coff_vis_tag");
314 case coff_vis_member_of_struct:
315 printf ("coff_vis_member_of_struct");
317 case coff_vis_member_of_enum:
318 printf ("coff_vis_member_of_enum");
328 dump_coff_symbol (struct coff_symbol *p)
331 printf ("List of symbols");
338 printf ("Symbol %s, tag %d, number %d", p->name, p->tag, p->number);
344 dump_coff_type (p->type);
348 dump_coff_where (p->where);
352 dump_coff_visible (p->visible);
361 dump_coff_scope (struct coff_scope *p)
366 printf ("List of blocks %lx ",(unsigned long) p);
369 printf( " %s %x..%x", p->sec->name,p->offset, p->offset + p->size -1);
373 printf ("*****************");
379 printf ("vars %d", p->nvars);
381 dump_coff_symbol (p->vars_head);
384 dump_coff_scope (p->list_head);
390 printf ("*****************");
397 dump_coff_sfile (struct coff_sfile *p)
400 printf ("List of source files");
406 printf ("Source file %s", p->name);
408 dump_coff_scope (p->scope);
415 dump_coff_section (struct coff_section *ptr)
420 printf ("section %s %d %d address %x size %x number %d nrelocs %d",
421 ptr->name, ptr->code, ptr->data, ptr->address,ptr->size,
422 ptr->number, ptr->nrelocs);
425 for (i = 0; i < ptr->nrelocs; i++)
428 printf ("(%x %s %x)",
429 ptr->relocs[i].offset,
430 ptr->relocs[i].symbol->name,
431 ptr->relocs[i].addend);
439 coff_dump (struct coff_ofile *ptr)
443 printf ("Coff dump");
445 printf ("#souces %d", ptr->nsources);
447 dump_coff_sfile (ptr->source_head);
449 for (i = 0; i < ptr->nsections; i++)
450 dump_coff_section (ptr->sections + i);
456 show_usage (FILE *file, int status)
458 fprintf (file, _("Usage: %s [option(s)] in-file\n"), program_name);
459 fprintf (file, _(" Print a human readable interpretation of a SYSROFF object file\n"));
460 fprintf (file, _(" The options are:\n\
461 @<file> Read options from <file>\n\
462 -h --help Display this information\n\
463 -v --version Display the program's version\n\
466 if (REPORT_BUGS_TO[0] && status == 0)
467 fprintf (file, _("Report bugs to %s\n"), REPORT_BUGS_TO);
473 main (int ac, char **av)
476 struct coff_ofile *tree;
478 char *input_file = NULL;
480 static struct option long_options[] =
482 { "help", no_argument, 0, 'h' },
483 { "version", no_argument, 0, 'V' },
484 { NULL, no_argument, 0, 0 }
487 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
488 setlocale (LC_MESSAGES, "");
490 #if defined (HAVE_SETLOCALE)
491 setlocale (LC_CTYPE, "");
493 bindtextdomain (PACKAGE, LOCALEDIR);
494 textdomain (PACKAGE);
496 program_name = av[0];
497 xmalloc_set_program_name (program_name);
499 expandargv (&ac, &av);
501 while ((opt = getopt_long (ac, av, "HhVv", long_options,
509 show_usage (stdout, 0);
513 print_version ("coffdump");
518 show_usage (stderr, 1);
525 input_file = av[optind];
529 fatal (_("no input file specified"));
531 abfd = bfd_openr (input_file, 0);
534 bfd_fatal (input_file);
536 if (! bfd_check_format_matches (abfd, bfd_object, &matching))
538 bfd_nonfatal (input_file);
540 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
542 list_matching_formats (matching);
548 tree = coff_grok (abfd);