2 Copyright (C) 1994, 95, 98, 99, 2000 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"
36 static void dump_coff_scope ();
63 for (i
= 0; i
< indent
; i
++)
73 for (i
= 0; i
< indent
; i
++)
94 printf(_("#lines %d "),p
->nlines
);
95 for (i
= 0; i
< p
->nlines
; i
++)
97 printf("(%d 0x%x)", p
->lines
[i
], p
->addresses
[i
]);
115 printf ("size %d ", p
->size
);
118 case coff_secdef_type
:
119 printf ("section definition at %x size %x\n",
120 p
->u
.asecdef
.address
,
124 case coff_pointer_type
:
125 printf ("pointer to");
127 dump_coff_type (p
->u
.pointer
.points_to
);
129 case coff_array_type
:
130 printf ("array [%d] of", p
->u
.array
.dim
);
132 dump_coff_type (p
->u
.array
.array_of
);
134 case coff_function_type
:
135 printf ("function returning");
137 dump_coff_type (p
->u
.function
.function_returns
);
138 dump_coff_lines (p
->u
.function
.lines
);
139 printf ("arguments");
141 dump_coff_scope (p
->u
.function
.parameters
);
145 dump_coff_scope (p
->u
.function
.code
);
148 case coff_structdef_type
:
149 printf ("structure definition");
151 dump_coff_scope (p
->u
.astructdef
.elements
);
153 case coff_structref_type
:
154 if (!p
->u
.aenumref
.ref
)
155 printf ("structure ref to UNKNOWN struct");
157 printf ("structure ref to %s", p
->u
.aenumref
.ref
->name
);
159 case coff_enumref_type
:
160 printf ("enum ref to %s", p
->u
.astructref
.ref
->name
);
162 case coff_enumdef_type
:
163 printf ("enum definition");
165 dump_coff_scope (p
->u
.aenumdef
.elements
);
167 case coff_basic_type
:
231 struct coff_where
*p
;
236 case coff_where_stack
:
237 printf ("Stack offset %x", p
->offset
);
239 case coff_where_memory
:
240 printf ("Memory section %s+%x", p
->section
->name
, p
->offset
);
242 case coff_where_register
:
243 printf ("Register %d", p
->offset
);
245 case coff_where_member_of_struct
:
246 printf ("Struct Member offset %x", p
->offset
);
248 case coff_where_member_of_enum
:
249 printf ("Enum Member offset %x", p
->offset
);
251 case coff_where_unknown
:
252 printf ("Undefined symbol");
254 case coff_where_strtag
:
256 case coff_where_entag
:
259 case coff_where_typedef
:
270 dump_coff_visible (p
)
271 struct coff_visible
*p
;
276 case coff_vis_ext_def
:
277 printf ("coff_vis_ext_def");
279 case coff_vis_ext_ref
:
280 printf ("coff_vis_ext_ref");
282 case coff_vis_int_def
:
283 printf ("coff_vis_int_def");
285 case coff_vis_common
:
286 printf ("coff_vis_common");
289 printf ("coff_vis_auto");
291 case coff_vis_autoparam
:
292 printf ("coff_vis_autoparam");
294 case coff_vis_regparam
:
295 printf ("coff_vis_regparam");
297 case coff_vis_register
:
298 printf ("coff_vis_register");
301 printf ("coff_vis_tag");
303 case coff_vis_member_of_struct
:
304 printf ("coff_vis_member_of_struct");
306 case coff_vis_member_of_enum
:
307 printf ("coff_vis_member_of_enum");
319 struct coff_symbol
*p
;
322 printf ("List of symbols");
328 printf ("Symbol %s, tag %d, number %d", p
->name
, p
->tag
, p
->number
);
334 dump_coff_type (p
->type
);
338 dump_coff_where (p
->where
);
342 dump_coff_visible (p
->visible
);
352 struct coff_scope
*p
;
356 printf ("List of blocks %lx ",(unsigned long) p
);
359 printf( " %s %x..%x", p
->sec
->name
,p
->offset
, p
->offset
+ p
->size
-1);
363 printf ("*****************");
368 printf ("vars %d", p
->nvars
);
370 dump_coff_symbol (p
->vars_head
);
373 dump_coff_scope (p
->list_head
);
379 printf ("*****************");
387 struct coff_sfile
*p
;
390 printf ("List of source files");
395 printf ("Source file %s", p
->name
);
397 dump_coff_scope (p
->scope
);
404 dump_coff_section(ptr
)
405 struct coff_section
*ptr
;
409 printf("section %s %d %d address %x size %x number %d nrelocs %d",
410 ptr
->name
, ptr
->code
, ptr
->data
, ptr
->address
,ptr
->size
, ptr
->number
, ptr
->nrelocs
);
413 for (i
= 0; i
< ptr
->nrelocs
; i
++)
417 ptr
->relocs
[i
].offset
,
418 ptr
->relocs
[i
].symbol
->name
,
419 ptr
->relocs
[i
].addend
);
428 struct coff_ofile
*ptr
;
431 printf ("Coff dump");
433 printf ("#souces %d", ptr
->nsources
);
435 dump_coff_sfile (ptr
->source_head
);
436 for (i
= 0; i
< ptr
->nsections
; i
++)
437 dump_coff_section(ptr
->sections
+ i
);
445 show_usage (file
, status
)
449 fprintf (file
, "Usage: %s [-hV] in-file\n", program_name
);
456 printf (_("%s: Print a human readable interpretation of a SYSROFF object file\n"),
458 show_usage (stdout
, 0);
468 struct coff_ofile
*tree
;
470 char *input_file
= NULL
;
472 static struct option long_options
[] =
474 { "help", no_argument
, 0, 'h' },
475 { "version", no_argument
, 0, 'V' },
476 { NULL
, no_argument
, 0, 0 }
479 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
480 setlocale (LC_MESSAGES
, "");
482 bindtextdomain (PACKAGE
, LOCALEDIR
);
483 textdomain (PACKAGE
);
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 fatal (_("no input file specified"));
518 abfd
= bfd_openr (input_file
, 0);
521 bfd_fatal (input_file
);
523 if (! bfd_check_format_matches (abfd
, bfd_object
, &matching
))
525 bfd_nonfatal (input_file
);
526 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
528 list_matching_formats (matching
);
534 tree
= coff_grok (abfd
);