2 Copyright 1994, 1995, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Written by Steve Chamberlain <sac@cygnus.com>
22 This module reads a type tree generated by coffgrok and prints
23 it out so we can test the grokker.
28 #include <libiberty.h>
35 static void tab PARAMS ((int));
36 static void nl PARAMS ((void));
37 static void dump_coff_lines PARAMS ((struct coff_line *));
38 static void dump_coff_type PARAMS ((struct coff_type *));
39 static void dump_coff_where PARAMS ((struct coff_where *));
40 static void dump_coff_visible PARAMS ((struct coff_visible *));
41 extern void dump_coff_symbol PARAMS ((struct coff_symbol *));
42 static void dump_coff_scope PARAMS ((struct coff_scope *));
43 static void dump_coff_sfile PARAMS ((struct coff_sfile *));
44 static void dump_coff_section PARAMS ((struct coff_section *));
45 extern void coff_dump PARAMS ((struct coff_ofile *));
46 static void show_usage PARAMS ((FILE *, int));
47 static void show_help PARAMS ((void));
48 extern int main PARAMS ((int, char **));
75 for (i = 0; i < indent; i++)
85 for (i = 0; i < indent; i++)
106 printf(_("#lines %d "),p->nlines);
107 for (i = 0; i < p->nlines; i++)
109 printf("(%d 0x%x)", p->lines[i], p->addresses[i]);
127 printf ("size %d ", p->size);
130 case coff_secdef_type:
131 printf ("section definition at %x size %x\n",
132 p->u.asecdef.address,
136 case coff_pointer_type:
137 printf ("pointer to");
139 dump_coff_type (p->u.pointer.points_to);
141 case coff_array_type:
142 printf ("array [%d] of", p->u.array.dim);
144 dump_coff_type (p->u.array.array_of);
146 case coff_function_type:
147 printf ("function returning");
149 dump_coff_type (p->u.function.function_returns);
150 dump_coff_lines (p->u.function.lines);
151 printf ("arguments");
153 dump_coff_scope (p->u.function.parameters);
157 dump_coff_scope (p->u.function.code);
160 case coff_structdef_type:
161 printf ("structure definition");
163 dump_coff_scope (p->u.astructdef.elements);
165 case coff_structref_type:
166 if (!p->u.aenumref.ref)
167 printf ("structure ref to UNKNOWN struct");
169 printf ("structure ref to %s", p->u.aenumref.ref->name);
171 case coff_enumref_type:
172 printf ("enum ref to %s", p->u.astructref.ref->name);
174 case coff_enumdef_type:
175 printf ("enum definition");
177 dump_coff_scope (p->u.aenumdef.elements);
179 case coff_basic_type:
243 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 (p)
283 struct coff_visible *p;
288 case coff_vis_ext_def:
289 printf ("coff_vis_ext_def");
291 case coff_vis_ext_ref:
292 printf ("coff_vis_ext_ref");
294 case coff_vis_int_def:
295 printf ("coff_vis_int_def");
297 case coff_vis_common:
298 printf ("coff_vis_common");
301 printf ("coff_vis_auto");
303 case coff_vis_autoparam:
304 printf ("coff_vis_autoparam");
306 case coff_vis_regparam:
307 printf ("coff_vis_regparam");
309 case coff_vis_register:
310 printf ("coff_vis_register");
313 printf ("coff_vis_tag");
315 case coff_vis_member_of_struct:
316 printf ("coff_vis_member_of_struct");
318 case coff_vis_member_of_enum:
319 printf ("coff_vis_member_of_enum");
331 struct coff_symbol *p;
334 printf ("List of symbols");
340 printf ("Symbol %s, tag %d, number %d", p->name, p->tag, p->number);
346 dump_coff_type (p->type);
350 dump_coff_where (p->where);
354 dump_coff_visible (p->visible);
364 struct coff_scope *p;
368 printf ("List of blocks %lx ",(unsigned long) p);
371 printf( " %s %x..%x", p->sec->name,p->offset, p->offset + p->size -1);
375 printf ("*****************");
380 printf ("vars %d", p->nvars);
382 dump_coff_symbol (p->vars_head);
385 dump_coff_scope (p->list_head);
391 printf ("*****************");
399 struct coff_sfile *p;
402 printf ("List of source files");
407 printf ("Source file %s", p->name);
409 dump_coff_scope (p->scope);
416 dump_coff_section(ptr)
417 struct coff_section *ptr;
421 printf("section %s %d %d address %x size %x number %d nrelocs %d",
422 ptr->name, ptr->code, ptr->data, ptr->address,ptr->size, ptr->number, ptr->nrelocs);
425 for (i = 0; i < ptr->nrelocs; i++)
429 ptr->relocs[i].offset,
430 ptr->relocs[i].symbol->name,
431 ptr->relocs[i].addend);
440 struct coff_ofile *ptr;
443 printf ("Coff dump");
445 printf ("#souces %d", ptr->nsources);
447 dump_coff_sfile (ptr->source_head);
448 for (i = 0; i < ptr->nsections; i++)
449 dump_coff_section(ptr->sections + i);
457 show_usage (file, status)
461 fprintf (file, "Usage: %s [-hV] in-file\n", program_name);
468 printf (_("%s: Print a human readable interpretation of a SYSROFF object file\n"),
470 show_usage (stdout, 0);
480 struct coff_ofile *tree;
482 char *input_file = NULL;
484 static struct option long_options[] =
486 { "help", no_argument, 0, 'h' },
487 { "version", no_argument, 0, 'V' },
488 { NULL, no_argument, 0, 0 }
491 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
492 setlocale (LC_MESSAGES, "");
494 #if defined (HAVE_SETLOCALE)
495 setlocale (LC_CTYPE, "");
497 bindtextdomain (PACKAGE, LOCALEDIR);
498 textdomain (PACKAGE);
500 program_name = av[0];
501 xmalloc_set_program_name (program_name);
503 while ((opt = getopt_long (ac, av, "hV", long_options,
513 print_version ("coffdump");
519 show_usage (stderr, 1);
526 input_file = av[optind];
531 fatal (_("no input file specified"));
533 abfd = bfd_openr (input_file, 0);
536 bfd_fatal (input_file);
538 if (! bfd_check_format_matches (abfd, bfd_object, &matching))
540 bfd_nonfatal (input_file);
541 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
543 list_matching_formats (matching);
549 tree = coff_grok (abfd);