2 Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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 (int);
36 static void nl (void);
37 static void dump_coff_lines (struct coff_line
*);
38 static void dump_coff_type (struct coff_type
*);
39 static void dump_coff_where (struct coff_where
*);
40 static void dump_coff_visible (struct coff_visible
*);
41 static void dump_coff_scope (struct coff_scope
*);
42 static void dump_coff_sfile (struct coff_sfile
*);
43 static void dump_coff_section (struct coff_section
*);
44 static void show_usage (FILE *, int);
45 extern int main (int, char **);
71 for (i
= 0; i
< indent
; i
++)
81 for (i
= 0; i
< indent
; i
++)
97 dump_coff_lines (struct coff_line
*p
)
103 printf (_("#lines %d "),p
->nlines
);
105 for (i
= 0; i
< p
->nlines
; i
++)
107 printf ("(%d 0x%x)", p
->lines
[i
], p
->addresses
[i
]);
123 dump_coff_type (struct coff_type
*p
)
126 printf ("size %d ", p
->size
);
130 case coff_secdef_type
:
131 printf ("section definition at %x size %x\n",
132 p
->u
.asecdef
.address
,
136 case coff_pointer_type
:
137 printf ("pointer to");
139 dump_coff_type (p
->u
.pointer
.points_to
);
141 case coff_array_type
:
142 printf ("array [%d] of", p
->u
.array
.dim
);
144 dump_coff_type (p
->u
.array
.array_of
);
146 case coff_function_type
:
147 printf ("function returning");
149 dump_coff_type (p
->u
.function
.function_returns
);
150 dump_coff_lines (p
->u
.function
.lines
);
151 printf ("arguments");
153 dump_coff_scope (p
->u
.function
.parameters
);
157 dump_coff_scope (p
->u
.function
.code
);
160 case coff_structdef_type
:
161 printf ("structure definition");
163 dump_coff_scope (p
->u
.astructdef
.elements
);
165 case coff_structref_type
:
166 if (!p
->u
.aenumref
.ref
)
167 printf ("structure ref to UNKNOWN struct");
169 printf ("structure ref to %s", p
->u
.aenumref
.ref
->name
);
171 case coff_enumref_type
:
172 printf ("enum ref to %s", p
->u
.astructref
.ref
->name
);
174 case coff_enumdef_type
:
175 printf ("enum definition");
177 dump_coff_scope (p
->u
.aenumdef
.elements
);
179 case coff_basic_type
:
242 dump_coff_where (struct coff_where
*p
)
247 case coff_where_stack
:
248 printf ("Stack offset %x", p
->offset
);
250 case coff_where_memory
:
251 printf ("Memory section %s+%x", p
->section
->name
, p
->offset
);
253 case coff_where_register
:
254 printf ("Register %d", p
->offset
);
256 case coff_where_member_of_struct
:
257 printf ("Struct Member offset %x", p
->offset
);
259 case coff_where_member_of_enum
:
260 printf ("Enum Member offset %x", p
->offset
);
262 case coff_where_unknown
:
263 printf ("Undefined symbol");
265 case coff_where_strtag
:
267 case coff_where_entag
:
270 case coff_where_typedef
:
281 dump_coff_visible (struct coff_visible
*p
)
286 case coff_vis_ext_def
:
287 printf ("coff_vis_ext_def");
289 case coff_vis_ext_ref
:
290 printf ("coff_vis_ext_ref");
292 case coff_vis_int_def
:
293 printf ("coff_vis_int_def");
295 case coff_vis_common
:
296 printf ("coff_vis_common");
299 printf ("coff_vis_auto");
301 case coff_vis_autoparam
:
302 printf ("coff_vis_autoparam");
304 case coff_vis_regparam
:
305 printf ("coff_vis_regparam");
307 case coff_vis_register
:
308 printf ("coff_vis_register");
311 printf ("coff_vis_tag");
313 case coff_vis_member_of_struct
:
314 printf ("coff_vis_member_of_struct");
316 case coff_vis_member_of_enum
:
317 printf ("coff_vis_member_of_enum");
327 dump_coff_symbol (struct coff_symbol
*p
)
330 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
);
360 dump_coff_scope (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 ("*****************");
378 printf ("vars %d", p
->nvars
);
380 dump_coff_symbol (p
->vars_head
);
383 dump_coff_scope (p
->list_head
);
389 printf ("*****************");
396 dump_coff_sfile (struct coff_sfile
*p
)
399 printf ("List of source files");
405 printf ("Source file %s", p
->name
);
407 dump_coff_scope (p
->scope
);
414 dump_coff_section (struct coff_section
*ptr
)
419 printf ("section %s %d %d address %x size %x number %d nrelocs %d",
420 ptr
->name
, ptr
->code
, ptr
->data
, ptr
->address
,ptr
->size
,
421 ptr
->number
, ptr
->nrelocs
);
424 for (i
= 0; i
< ptr
->nrelocs
; i
++)
427 printf ("(%x %s %x)",
428 ptr
->relocs
[i
].offset
,
429 ptr
->relocs
[i
].symbol
->name
,
430 ptr
->relocs
[i
].addend
);
438 coff_dump (struct coff_ofile
*ptr
)
442 printf ("Coff dump");
444 printf ("#souces %d", ptr
->nsources
);
446 dump_coff_sfile (ptr
->source_head
);
448 for (i
= 0; i
< ptr
->nsections
; i
++)
449 dump_coff_section (ptr
->sections
+ i
);
455 show_usage (FILE *file
, int status
)
457 fprintf (file
, _("Usage: %s [option(s)] in-file\n"), program_name
);
458 fprintf (file
, _(" Print a human readable interpretation of a SYSROFF object file\n"));
459 fprintf (file
, _(" The options are:\n\
460 @<file> Read options from <file>\n\
461 -h --help Display this information\n\
462 -v --version Display the program's version\n\
465 if (REPORT_BUGS_TO
[0] && status
== 0)
466 fprintf (file
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
472 main (int ac
, char **av
)
475 struct coff_ofile
*tree
;
477 char *input_file
= NULL
;
479 static struct option long_options
[] =
481 { "help", no_argument
, 0, 'h' },
482 { "version", no_argument
, 0, 'V' },
483 { NULL
, no_argument
, 0, 0 }
486 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
487 setlocale (LC_MESSAGES
, "");
489 #if defined (HAVE_SETLOCALE)
490 setlocale (LC_CTYPE
, "");
492 bindtextdomain (PACKAGE
, LOCALEDIR
);
493 textdomain (PACKAGE
);
495 program_name
= av
[0];
496 xmalloc_set_program_name (program_name
);
498 expandargv (&ac
, &av
);
500 while ((opt
= getopt_long (ac
, av
, "HhVv", long_options
,
508 show_usage (stdout
, 0);
512 print_version ("coffdump");
517 show_usage (stderr
, 1);
524 input_file
= av
[optind
];
528 fatal (_("no input file specified"));
530 abfd
= bfd_openr (input_file
, 0);
533 bfd_fatal (input_file
);
535 if (! bfd_check_format_matches (abfd
, bfd_object
, &matching
))
537 bfd_nonfatal (input_file
);
539 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
541 list_matching_formats (matching
);
547 tree
= coff_grok (abfd
);