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>
33 #define PROGRAM_VERSION "1.0"
37 static void tab
PARAMS ((int));
38 static void nl
PARAMS ((void));
39 static void dump_coff_lines
PARAMS ((struct coff_line
*));
40 static void dump_coff_type
PARAMS ((struct coff_type
*));
41 static void dump_coff_where
PARAMS ((struct coff_where
*));
42 static void dump_coff_visible
PARAMS ((struct coff_visible
*));
43 extern void dump_coff_symbol
PARAMS ((struct coff_symbol
*));
44 static void dump_coff_scope
PARAMS ((struct coff_scope
*));
45 static void dump_coff_sfile
PARAMS ((struct coff_sfile
*));
46 static void dump_coff_section
PARAMS ((struct coff_section
*));
47 extern void coff_dump
PARAMS ((struct coff_ofile
*));
48 static void show_usage
PARAMS ((FILE *, int));
49 static void show_help
PARAMS ((void));
50 extern int main
PARAMS ((int, char **));
77 for (i
= 0; i
< indent
; i
++)
87 for (i
= 0; i
< indent
; i
++)
108 printf(_("#lines %d "),p
->nlines
);
109 for (i
= 0; i
< p
->nlines
; i
++)
111 printf("(%d 0x%x)", p
->lines
[i
], p
->addresses
[i
]);
129 printf ("size %d ", p
->size
);
132 case coff_secdef_type
:
133 printf ("section definition at %x size %x\n",
134 p
->u
.asecdef
.address
,
138 case coff_pointer_type
:
139 printf ("pointer to");
141 dump_coff_type (p
->u
.pointer
.points_to
);
143 case coff_array_type
:
144 printf ("array [%d] of", p
->u
.array
.dim
);
146 dump_coff_type (p
->u
.array
.array_of
);
148 case coff_function_type
:
149 printf ("function returning");
151 dump_coff_type (p
->u
.function
.function_returns
);
152 dump_coff_lines (p
->u
.function
.lines
);
153 printf ("arguments");
155 dump_coff_scope (p
->u
.function
.parameters
);
159 dump_coff_scope (p
->u
.function
.code
);
162 case coff_structdef_type
:
163 printf ("structure definition");
165 dump_coff_scope (p
->u
.astructdef
.elements
);
167 case coff_structref_type
:
168 if (!p
->u
.aenumref
.ref
)
169 printf ("structure ref to UNKNOWN struct");
171 printf ("structure ref to %s", p
->u
.aenumref
.ref
->name
);
173 case coff_enumref_type
:
174 printf ("enum ref to %s", p
->u
.astructref
.ref
->name
);
176 case coff_enumdef_type
:
177 printf ("enum definition");
179 dump_coff_scope (p
->u
.aenumdef
.elements
);
181 case coff_basic_type
:
245 struct coff_where
*p
;
250 case coff_where_stack
:
251 printf ("Stack offset %x", p
->offset
);
253 case coff_where_memory
:
254 printf ("Memory section %s+%x", p
->section
->name
, p
->offset
);
256 case coff_where_register
:
257 printf ("Register %d", p
->offset
);
259 case coff_where_member_of_struct
:
260 printf ("Struct Member offset %x", p
->offset
);
262 case coff_where_member_of_enum
:
263 printf ("Enum Member offset %x", p
->offset
);
265 case coff_where_unknown
:
266 printf ("Undefined symbol");
268 case coff_where_strtag
:
270 case coff_where_entag
:
273 case coff_where_typedef
:
284 dump_coff_visible (p
)
285 struct coff_visible
*p
;
290 case coff_vis_ext_def
:
291 printf ("coff_vis_ext_def");
293 case coff_vis_ext_ref
:
294 printf ("coff_vis_ext_ref");
296 case coff_vis_int_def
:
297 printf ("coff_vis_int_def");
299 case coff_vis_common
:
300 printf ("coff_vis_common");
303 printf ("coff_vis_auto");
305 case coff_vis_autoparam
:
306 printf ("coff_vis_autoparam");
308 case coff_vis_regparam
:
309 printf ("coff_vis_regparam");
311 case coff_vis_register
:
312 printf ("coff_vis_register");
315 printf ("coff_vis_tag");
317 case coff_vis_member_of_struct
:
318 printf ("coff_vis_member_of_struct");
320 case coff_vis_member_of_enum
:
321 printf ("coff_vis_member_of_enum");
333 struct coff_symbol
*p
;
336 printf ("List of symbols");
342 printf ("Symbol %s, tag %d, number %d", p
->name
, p
->tag
, p
->number
);
348 dump_coff_type (p
->type
);
352 dump_coff_where (p
->where
);
356 dump_coff_visible (p
->visible
);
366 struct coff_scope
*p
;
370 printf ("List of blocks %lx ",(unsigned long) p
);
373 printf( " %s %x..%x", p
->sec
->name
,p
->offset
, p
->offset
+ p
->size
-1);
377 printf ("*****************");
382 printf ("vars %d", p
->nvars
);
384 dump_coff_symbol (p
->vars_head
);
387 dump_coff_scope (p
->list_head
);
393 printf ("*****************");
401 struct coff_sfile
*p
;
404 printf ("List of source files");
409 printf ("Source file %s", p
->name
);
411 dump_coff_scope (p
->scope
);
418 dump_coff_section(ptr
)
419 struct coff_section
*ptr
;
423 printf("section %s %d %d address %x size %x number %d nrelocs %d",
424 ptr
->name
, ptr
->code
, ptr
->data
, ptr
->address
,ptr
->size
, ptr
->number
, ptr
->nrelocs
);
427 for (i
= 0; i
< ptr
->nrelocs
; i
++)
431 ptr
->relocs
[i
].offset
,
432 ptr
->relocs
[i
].symbol
->name
,
433 ptr
->relocs
[i
].addend
);
442 struct coff_ofile
*ptr
;
445 printf ("Coff dump");
447 printf ("#souces %d", ptr
->nsources
);
449 dump_coff_sfile (ptr
->source_head
);
450 for (i
= 0; i
< ptr
->nsections
; i
++)
451 dump_coff_section(ptr
->sections
+ i
);
459 show_usage (file
, status
)
463 fprintf (file
, "Usage: %s [-hV] in-file\n", program_name
);
470 printf (_("%s: Print a human readable interpretation of a SYSROFF object file\n"),
472 show_usage (stdout
, 0);
482 struct coff_ofile
*tree
;
484 char *input_file
= NULL
;
486 static struct option long_options
[] =
488 { "help", no_argument
, 0, 'h' },
489 { "version", no_argument
, 0, 'V' },
490 { NULL
, no_argument
, 0, 0 }
493 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
494 setlocale (LC_MESSAGES
, "");
496 bindtextdomain (PACKAGE
, LOCALEDIR
);
497 textdomain (PACKAGE
);
499 program_name
= av
[0];
500 xmalloc_set_program_name (program_name
);
502 while ((opt
= getopt_long (ac
, av
, "hV", long_options
,
512 printf (_("GNU %s version %s\n"), program_name
, PROGRAM_VERSION
);
518 show_usage (stderr
, 1);
525 input_file
= av
[optind
];
530 fatal (_("no input file specified"));
532 abfd
= bfd_openr (input_file
, 0);
535 bfd_fatal (input_file
);
537 if (! bfd_check_format_matches (abfd
, bfd_object
, &matching
))
539 bfd_nonfatal (input_file
);
540 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
542 list_matching_formats (matching
);
548 tree
= coff_grok (abfd
);