2 Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* Written by Steve Chamberlain <sac@cygnus.com>
23 This module reads a type tree generated by coffgrok and prints
24 it out so we can test the grokker. */
27 #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 extern int main
PARAMS ((int, char **));
74 for (i
= 0; i
< indent
; i
++)
84 for (i
= 0; i
< indent
; i
++)
107 printf (_("#lines %d "),p
->nlines
);
109 for (i
= 0; i
< p
->nlines
; i
++)
111 printf ("(%d 0x%x)", p
->lines
[i
], p
->addresses
[i
]);
131 printf ("size %d ", p
->size
);
135 case coff_secdef_type
:
136 printf ("section definition at %x size %x\n",
137 p
->u
.asecdef
.address
,
141 case coff_pointer_type
:
142 printf ("pointer to");
144 dump_coff_type (p
->u
.pointer
.points_to
);
146 case coff_array_type
:
147 printf ("array [%d] of", p
->u
.array
.dim
);
149 dump_coff_type (p
->u
.array
.array_of
);
151 case coff_function_type
:
152 printf ("function returning");
154 dump_coff_type (p
->u
.function
.function_returns
);
155 dump_coff_lines (p
->u
.function
.lines
);
156 printf ("arguments");
158 dump_coff_scope (p
->u
.function
.parameters
);
162 dump_coff_scope (p
->u
.function
.code
);
165 case coff_structdef_type
:
166 printf ("structure definition");
168 dump_coff_scope (p
->u
.astructdef
.elements
);
170 case coff_structref_type
:
171 if (!p
->u
.aenumref
.ref
)
172 printf ("structure ref to UNKNOWN struct");
174 printf ("structure ref to %s", p
->u
.aenumref
.ref
->name
);
176 case coff_enumref_type
:
177 printf ("enum ref to %s", p
->u
.astructref
.ref
->name
);
179 case coff_enumdef_type
:
180 printf ("enum definition");
182 dump_coff_scope (p
->u
.aenumdef
.elements
);
184 case coff_basic_type
:
248 struct coff_where
*p
;
253 case coff_where_stack
:
254 printf ("Stack offset %x", p
->offset
);
256 case coff_where_memory
:
257 printf ("Memory section %s+%x", p
->section
->name
, p
->offset
);
259 case coff_where_register
:
260 printf ("Register %d", p
->offset
);
262 case coff_where_member_of_struct
:
263 printf ("Struct Member offset %x", p
->offset
);
265 case coff_where_member_of_enum
:
266 printf ("Enum Member offset %x", p
->offset
);
268 case coff_where_unknown
:
269 printf ("Undefined symbol");
271 case coff_where_strtag
:
273 case coff_where_entag
:
276 case coff_where_typedef
:
287 dump_coff_visible (p
)
288 struct coff_visible
*p
;
293 case coff_vis_ext_def
:
294 printf ("coff_vis_ext_def");
296 case coff_vis_ext_ref
:
297 printf ("coff_vis_ext_ref");
299 case coff_vis_int_def
:
300 printf ("coff_vis_int_def");
302 case coff_vis_common
:
303 printf ("coff_vis_common");
306 printf ("coff_vis_auto");
308 case coff_vis_autoparam
:
309 printf ("coff_vis_autoparam");
311 case coff_vis_regparam
:
312 printf ("coff_vis_regparam");
314 case coff_vis_register
:
315 printf ("coff_vis_register");
318 printf ("coff_vis_tag");
320 case coff_vis_member_of_struct
:
321 printf ("coff_vis_member_of_struct");
323 case coff_vis_member_of_enum
:
324 printf ("coff_vis_member_of_enum");
335 struct coff_symbol
*p
;
338 printf ("List of symbols");
345 printf ("Symbol %s, tag %d, number %d", p
->name
, p
->tag
, p
->number
);
351 dump_coff_type (p
->type
);
355 dump_coff_where (p
->where
);
359 dump_coff_visible (p
->visible
);
369 struct coff_scope
*p
;
374 printf ("List of blocks %lx ",(unsigned long) p
);
377 printf( " %s %x..%x", p
->sec
->name
,p
->offset
, p
->offset
+ p
->size
-1);
381 printf ("*****************");
387 printf ("vars %d", p
->nvars
);
389 dump_coff_symbol (p
->vars_head
);
392 dump_coff_scope (p
->list_head
);
398 printf ("*****************");
406 struct coff_sfile
*p
;
409 printf ("List of source files");
415 printf ("Source file %s", p
->name
);
417 dump_coff_scope (p
->scope
);
424 dump_coff_section(ptr
)
425 struct coff_section
*ptr
;
430 printf ("section %s %d %d address %x size %x number %d nrelocs %d",
431 ptr
->name
, ptr
->code
, ptr
->data
, ptr
->address
,ptr
->size
,
432 ptr
->number
, ptr
->nrelocs
);
435 for (i
= 0; i
< ptr
->nrelocs
; i
++)
438 printf ("(%x %s %x)",
439 ptr
->relocs
[i
].offset
,
440 ptr
->relocs
[i
].symbol
->name
,
441 ptr
->relocs
[i
].addend
);
450 struct coff_ofile
*ptr
;
454 printf ("Coff dump");
456 printf ("#souces %d", ptr
->nsources
);
458 dump_coff_sfile (ptr
->source_head
);
460 for (i
= 0; i
< ptr
->nsections
; i
++)
461 dump_coff_section (ptr
->sections
+ i
);
467 show_usage (file
, status
)
471 fprintf (file
, _("Usage: %s [option(s)] in-file\n"), program_name
);
472 fprintf (file
, _(" Print a human readable interpretation of a SYSROFF object file\n"));
473 fprintf (file
, _(" The options are:\n\
474 -h --help Display this information\n\
475 -v --version Display the program's version\n\
479 fprintf (file
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
490 struct coff_ofile
*tree
;
492 char *input_file
= NULL
;
494 static struct option long_options
[] =
496 { "help", no_argument
, 0, 'h' },
497 { "version", no_argument
, 0, 'V' },
498 { NULL
, no_argument
, 0, 0 }
501 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
502 setlocale (LC_MESSAGES
, "");
504 #if defined (HAVE_SETLOCALE)
505 setlocale (LC_CTYPE
, "");
507 bindtextdomain (PACKAGE
, LOCALEDIR
);
508 textdomain (PACKAGE
);
510 program_name
= av
[0];
511 xmalloc_set_program_name (program_name
);
513 while ((opt
= getopt_long (ac
, av
, "HhVv", long_options
,
521 show_usage (stdout
, 0);
525 print_version ("coffdump");
530 show_usage (stderr
, 1);
537 input_file
= av
[optind
];
541 fatal (_("no input file specified"));
543 abfd
= bfd_openr (input_file
, 0);
546 bfd_fatal (input_file
);
548 if (! bfd_check_format_matches (abfd
, bfd_object
, &matching
))
550 bfd_nonfatal (input_file
);
552 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
554 list_matching_formats (matching
);
560 tree
= coff_grok (abfd
);