2 Copyright (C) 1994, 1998 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>
33 #define PROGRAM_VERSION "1.0"
39 char *r = xmalloc(a*b);
45 static void dump_coff_scope ();
72 for (i = 0; i < indent; i++)
82 for (i = 0; i < indent; i++)
103 printf(_("#lines %d "),p->nlines);
104 for (i = 0; i < p->nlines; i++)
106 printf("(%d 0x%x)", p->lines[i], p->addresses[i]);
124 printf ("size %d ", p->size);
127 case coff_secdef_type:
128 printf ("section definition at %x size %x\n",
129 p->u.asecdef.address,
133 case coff_pointer_type:
134 printf ("pointer to");
136 dump_coff_type (p->u.pointer.points_to);
138 case coff_array_type:
139 printf ("array [%d] of", p->u.array.dim);
141 dump_coff_type (p->u.array.array_of);
143 case coff_function_type:
144 printf ("function returning");
146 dump_coff_type (p->u.function.function_returns);
147 dump_coff_lines (p->u.function.lines);
148 printf ("arguments");
150 dump_coff_scope (p->u.function.parameters);
154 dump_coff_scope (p->u.function.code);
157 case coff_structdef_type:
158 printf ("structure definition");
160 dump_coff_scope (p->u.astructdef.elements);
162 case coff_structref_type:
163 if (!p->u.aenumref.ref)
164 printf ("structure ref to UNKNOWN struct");
166 printf ("structure ref to %s", p->u.aenumref.ref->name);
168 case coff_enumref_type:
169 printf ("enum ref to %s", p->u.astructref.ref->name);
171 case coff_enumdef_type:
172 printf ("enum definition");
174 dump_coff_scope (p->u.aenumdef.elements);
176 case coff_basic_type:
240 struct coff_where *p;
245 case coff_where_stack:
246 printf ("Stack offset %x", p->offset);
248 case coff_where_memory:
249 printf ("Memory section %s+%x", p->section->name, p->offset);
251 case coff_where_register:
252 printf ("Register %d", p->offset);
254 case coff_where_member_of_struct:
255 printf ("Struct Member offset %x", p->offset);
257 case coff_where_member_of_enum:
258 printf ("Enum Member offset %x", p->offset);
260 case coff_where_unknown:
261 printf ("Undefined symbol");
263 case coff_where_strtag:
265 case coff_where_entag:
268 case coff_where_typedef:
279 dump_coff_visible (p)
280 struct coff_visible *p;
285 case coff_vis_ext_def:
286 printf ("coff_vis_ext_def");
288 case coff_vis_ext_ref:
289 printf ("coff_vis_ext_ref");
291 case coff_vis_int_def:
292 printf ("coff_vis_int_def");
294 case coff_vis_common:
295 printf ("coff_vis_common");
298 printf ("coff_vis_auto");
300 case coff_vis_autoparam:
301 printf ("coff_vis_autoparam");
303 case coff_vis_regparam:
304 printf ("coff_vis_regparam");
306 case coff_vis_register:
307 printf ("coff_vis_register");
310 printf ("coff_vis_tag");
312 case coff_vis_member_of_struct:
313 printf ("coff_vis_member_of_struct");
315 case coff_vis_member_of_enum:
316 printf ("coff_vis_member_of_enum");
328 struct coff_symbol *p;
331 printf ("List of symbols");
337 printf ("Symbol %s, tag %d, number %d", p->name, p->tag, p->number);
343 dump_coff_type (p->type);
347 dump_coff_where (p->where);
351 dump_coff_visible (p->visible);
361 struct coff_scope *p;
365 printf ("List of blocks %lx ",(unsigned long) p);
368 printf( " %s %x..%x", p->sec->name,p->offset, p->offset + p->size -1);
372 printf ("*****************");
377 printf ("vars %d", p->nvars);
379 dump_coff_symbol (p->vars_head);
382 dump_coff_scope (p->list_head);
388 printf ("*****************");
396 struct coff_sfile *p;
399 printf ("List of source files");
404 printf ("Source file %s", p->name);
406 dump_coff_scope (p->scope);
413 dump_coff_section(ptr)
414 struct coff_section *ptr;
418 printf("section %s %d %d address %x size %x number %d nrelocs %d",
419 ptr->name, ptr->code, ptr->data, ptr->address,ptr->size, ptr->number, ptr->nrelocs);
422 for (i = 0; i < ptr->nrelocs; i++)
426 ptr->relocs[i].offset,
427 ptr->relocs[i].symbol->name,
428 ptr->relocs[i].addend);
437 struct coff_ofile *ptr;
440 printf ("Coff dump");
442 printf ("#souces %d", ptr->nsources);
444 dump_coff_sfile (ptr->source_head);
445 for (i = 0; i < ptr->nsections; i++)
446 dump_coff_section(ptr->sections + i);
454 show_usage (file, status)
458 fprintf (file, "Usage: %s [-hV] in-file\n", program_name);
465 printf (_("%s: Print a human readable interpretation of a SYSROFF object file\n"),
467 show_usage (stdout, 0);
477 struct coff_ofile *tree;
479 char *input_file = NULL;
481 static struct option long_options[] =
483 { "help", no_argument, 0, 'h' },
484 { "version", no_argument, 0, 'V' },
485 { NULL, no_argument, 0, 0 }
488 setlocale (LC_MESSAGES, "");
489 bindtextdomain (PACKAGE, LOCALEDIR);
490 textdomain (PACKAGE);
492 program_name = av[0];
493 xmalloc_set_program_name (program_name);
495 while ((opt = getopt_long (ac, av, "hV", long_options,
505 printf (_("GNU %s version %s\n"), program_name, PROGRAM_VERSION);
511 show_usage (stderr, 1);
518 input_file = av[optind];
523 fprintf (stderr,_("%s: no input file specified\n"),
527 abfd = bfd_openr (input_file, 0);
530 bfd_fatal (input_file);
532 if (! bfd_check_format_matches (abfd, bfd_object, &matching))
534 bfd_nonfatal (input_file);
535 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
537 list_matching_formats (matching);
543 tree = coff_grok (abfd);