2 Copyright (C) 1994 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 This module reads a type tree generated by coffgrok and prints
23 it out so we can test the grokker.
29 #include <libiberty.h>
35 #define PROGRAM_VERSION "1.0"
42 char *r = xmalloc(a*b);
48 static void dump_coff_scope ();
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_pointer_type:
131 printf ("pointer to");
133 dump_coff_type (p->u.pointer.points_to);
135 case coff_array_type:
136 printf ("array [%d] of", p->u.array.dim);
138 dump_coff_type (p->u.array.array_of);
140 case coff_function_type:
141 printf ("function returning");
143 dump_coff_type (p->u.function.function_returns);
144 dump_coff_lines (p->u.function.lines);
145 printf ("arguments");
147 dump_coff_scope (p->u.function.parameters);
151 dump_coff_scope (p->u.function.code);
154 case coff_structdef_type:
155 printf ("structure definition");
157 dump_coff_scope (p->u.astructdef.elements);
159 case coff_structref_type:
160 if (!p->u.aenumref.ref)
161 printf ("structure ref to UNKNOWN struct");
163 printf ("structure ref to %s", p->u.aenumref.ref->name);
165 case coff_enumref_type:
166 printf ("enum ref to %s", p->u.astructref.ref->name);
168 case coff_enumdef_type:
169 printf ("enum definition");
171 dump_coff_scope (p->u.aenumdef.elements);
173 case coff_basic_type:
237 struct coff_where *p;
242 case coff_where_stack:
243 printf ("Stack offset %x", p->offset);
245 case coff_where_memory:
246 printf ("Memory section %s+%x", p->section->name, p->offset);
248 case coff_where_register:
249 printf ("Register %d", p->offset);
251 case coff_where_member_of_struct:
252 printf ("Struct Member offset %x", p->offset);
254 case coff_where_member_of_enum:
255 printf ("Enum Member offset %x", p->offset);
257 case coff_where_unknown:
258 printf ("Undefined symbol");
260 case coff_where_strtag:
262 case coff_where_entag:
265 case coff_where_typedef:
276 dump_coff_visible (p)
277 struct coff_visible *p;
282 case coff_vis_ext_def:
283 printf ("coff_vis_ext_def");
285 case coff_vis_ext_ref:
286 printf ("coff_vis_ext_ref");
288 case coff_vis_int_def:
289 printf ("coff_vis_int_def");
291 case coff_vis_common:
292 printf ("coff_vis_common");
295 printf ("coff_vis_auto");
297 case coff_vis_autoparam:
298 printf ("coff_vis_autoparam");
300 case coff_vis_regparam:
301 printf ("coff_vis_regparam");
303 case coff_vis_register:
304 printf ("coff_vis_register");
307 printf ("coff_vis_tag");
309 case coff_vis_member_of_struct:
310 printf ("coff_vis_member_of_struct");
312 case coff_vis_member_of_enum:
313 printf ("coff_vis_member_of_enum");
325 struct coff_symbol *p;
328 printf ("List of symbols");
334 printf ("Symbol %s, tag %d, number %d", p->name, p->tag, p->number);
340 dump_coff_type (p->type);
344 dump_coff_where (p->where);
348 dump_coff_visible (p->visible);
358 struct coff_scope *p;
362 printf ("List of blocks %lx ",(unsigned long) p);
365 printf( " %s %x..%x", p->sec->name,p->offset, p->offset + p->size -1);
369 printf ("*****************");
374 printf ("vars %d", p->nvars);
376 dump_coff_symbol (p->vars_head);
379 dump_coff_scope (p->list_head);
385 printf ("*****************");
393 struct coff_sfile *p;
396 printf ("List of source files");
401 printf ("Source file %s", p->name);
403 dump_coff_scope (p->scope);
410 dump_coff_section(ptr)
411 struct coff_section *ptr;
415 printf("section %s %d %d address %x size %x number %d nrelocs %d",
416 ptr->name, ptr->code, ptr->data, ptr->address,ptr->size, ptr->number, ptr->nrelocs);
419 for (i = 0; i < ptr->nrelocs; i++)
423 ptr->relocs[i].offset,
424 ptr->relocs[i].symbol->name,
425 ptr->relocs[i].addend);
434 struct coff_ofile *ptr;
437 printf ("Coff dump");
439 printf ("#souces %d", ptr->nsources);
441 dump_coff_sfile (ptr->source_head);
442 for (i = 0; i < ptr->nsections; i++)
443 dump_coff_section(ptr->sections + i);
451 show_usage (file, status)
455 fprintf (file, "Usage: %s [-hV] in-file\n", program_name);
462 printf ("%s: Print a human readable interpretation of a SYSROFF object file\n",
464 show_usage (stdout, 0);
474 struct coff_ofile *tree;
476 char *input_file = NULL;
478 static struct option long_options[] =
480 { "help", no_argument, 0, 'h' },
481 { "version", no_argument, 0, 'V' },
482 { NULL, no_argument, 0, 0 }
485 program_name = av[0];
486 xmalloc_set_program_name (program_name);
488 while ((opt = getopt_long (ac, av, "hV", long_options,
498 printf ("GNU %s version %s\n", program_name, PROGRAM_VERSION);
504 show_usage (stderr, 1);
511 input_file = av[optind];
516 fprintf (stderr,"%s: no input file specified\n",
520 abfd = bfd_openr (input_file, 0);
523 bfd_fatal (input_file);
525 if (! bfd_check_format_matches (abfd, bfd_object, &matching))
527 bfd_nonfatal (input_file);
528 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
530 list_matching_formats (matching);
536 tree = coff_grok (abfd);