2 Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007,
3 2011 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 3 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,
20 MA 02110-1301, USA. */
23 /* Written by Steve Chamberlain <sac@cygnus.com>
25 This module reads a type tree generated by coffgrok and prints
26 it out so we can test the grokker. */
30 #include "bfd_stdint.h"
31 #include "libiberty.h"
39 static void tab (int);
40 static void nl (void);
41 static void dump_coff_lines (struct coff_line
*);
42 static void dump_coff_type (struct coff_type
*);
43 static void dump_coff_where (struct coff_where
*);
44 static void dump_coff_visible (struct coff_visible
*);
45 static void dump_coff_scope (struct coff_scope
*);
46 static void dump_coff_sfile (struct coff_sfile
*);
47 static void dump_coff_section (struct coff_section
*);
48 static void show_usage (FILE *, int);
49 extern int main (int, char **);
75 for (i
= 0; i
< indent
; i
++)
85 for (i
= 0; i
< indent
; i
++)
101 dump_coff_lines (struct coff_line
*p
)
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
]);
127 dump_coff_type (struct coff_type
*p
)
130 printf (_("size %d "), p
->size
);
134 case coff_secdef_type
:
135 printf (_("section definition at %x size %x\n"),
136 p
->u
.asecdef
.address
,
140 case coff_pointer_type
:
141 printf (_("pointer to"));
143 dump_coff_type (p
->u
.pointer
.points_to
);
145 case coff_array_type
:
146 printf (_("array [%d] of"), p
->u
.array
.dim
);
148 dump_coff_type (p
->u
.array
.array_of
);
150 case coff_function_type
:
151 printf (_("function returning"));
153 dump_coff_type (p
->u
.function
.function_returns
);
154 dump_coff_lines (p
->u
.function
.lines
);
155 printf (_("arguments"));
157 dump_coff_scope (p
->u
.function
.parameters
);
161 dump_coff_scope (p
->u
.function
.code
);
164 case coff_structdef_type
:
165 printf (_("structure definition"));
167 dump_coff_scope (p
->u
.astructdef
.elements
);
169 case coff_structref_type
:
170 if (!p
->u
.aenumref
.ref
)
171 printf (_("structure ref to UNKNOWN struct"));
173 printf (_("structure ref to %s"), p
->u
.aenumref
.ref
->name
);
175 case coff_enumref_type
:
176 printf (_("enum ref to %s"), p
->u
.astructref
.ref
->name
);
178 case coff_enumdef_type
:
179 printf (_("enum definition"));
181 dump_coff_scope (p
->u
.aenumdef
.elements
);
183 case coff_basic_type
:
246 dump_coff_where (struct coff_where
*p
)
251 case coff_where_stack
:
252 printf (_("Stack offset %x"), p
->offset
);
254 case coff_where_memory
:
255 printf (_("Memory section %s+%x"), p
->section
->name
, p
->offset
);
257 case coff_where_register
:
258 printf (_("Register %d"), p
->offset
);
260 case coff_where_member_of_struct
:
261 printf (_("Struct Member offset %x"), p
->offset
);
263 case coff_where_member_of_enum
:
264 printf (_("Enum Member offset %x"), p
->offset
);
266 case coff_where_unknown
:
267 printf (_("Undefined symbol"));
269 case coff_where_strtag
:
271 case coff_where_entag
:
274 case coff_where_typedef
:
285 dump_coff_visible (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");
331 dump_coff_symbol (struct coff_symbol
*p
)
334 printf (_("List of symbols"));
341 printf (_("Symbol %s, tag %d, number %d"), p
->name
, p
->tag
, p
->number
);
347 dump_coff_type (p
->type
);
351 dump_coff_where (p
->where
);
354 printf (_("Visible"));
355 dump_coff_visible (p
->visible
);
364 dump_coff_scope (struct coff_scope
*p
)
369 printf ("%s %" BFD_VMA_FMT
"x ",
370 _("List of blocks "), (bfd_vma
) (uintptr_t) p
);
373 printf( " %s %x..%x", p
->sec
->name
,p
->offset
, p
->offset
+ p
->size
-1);
377 printf ("*****************");
383 printf (_("vars %d"), p
->nvars
);
385 dump_coff_symbol (p
->vars_head
);
386 printf (_("blocks"));
388 dump_coff_scope (p
->list_head
);
394 printf ("*****************");
401 dump_coff_sfile (struct coff_sfile
*p
)
404 printf (_("List of source files"));
410 printf (_("Source file %s"), p
->name
);
412 dump_coff_scope (p
->scope
);
419 dump_coff_section (struct coff_section
*ptr
)
424 printf (_("section %s %d %d address %x size %x number %d nrelocs %d"),
425 ptr
->name
, ptr
->code
, ptr
->data
, ptr
->address
,ptr
->size
,
426 ptr
->number
, ptr
->nrelocs
);
429 for (i
= 0; i
< ptr
->nrelocs
; i
++)
432 printf ("(%x %s %x)",
433 ptr
->relocs
[i
].offset
,
434 ptr
->relocs
[i
].symbol
->name
,
435 ptr
->relocs
[i
].addend
);
443 coff_dump (struct coff_ofile
*ptr
)
447 printf ("Coff dump");
449 printf (_("#sources %d"), ptr
->nsources
);
451 dump_coff_sfile (ptr
->source_head
);
453 for (i
= 0; i
< ptr
->nsections
; i
++)
454 dump_coff_section (ptr
->sections
+ i
);
460 show_usage (FILE *file
, int status
)
462 fprintf (file
, _("Usage: %s [option(s)] in-file\n"), program_name
);
463 fprintf (file
, _(" Print a human readable interpretation of a COFF object file\n"));
464 fprintf (file
, _(" The options are:\n\
465 @<file> Read options from <file>\n\
466 -h --help Display this information\n\
467 -v --version Display the program's version\n\
470 if (REPORT_BUGS_TO
[0] && status
== 0)
471 fprintf (file
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
477 main (int ac
, char **av
)
480 struct coff_ofile
*tree
;
482 char *input_file
= NULL
;
484 static struct option long_options
[] =
486 { "help", no_argument
, 0, 'h' },
487 { "version", no_argument
, 0, 'V' },
488 { NULL
, no_argument
, 0, 0 }
491 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
492 setlocale (LC_MESSAGES
, "");
494 #if defined (HAVE_SETLOCALE)
495 setlocale (LC_CTYPE
, "");
497 bindtextdomain (PACKAGE
, LOCALEDIR
);
498 textdomain (PACKAGE
);
500 program_name
= av
[0];
501 xmalloc_set_program_name (program_name
);
503 expandargv (&ac
, &av
);
505 while ((opt
= getopt_long (ac
, av
, "HhVv", long_options
,
513 show_usage (stdout
, 0);
517 print_version ("coffdump");
522 show_usage (stderr
, 1);
529 input_file
= av
[optind
];
533 fatal (_("no input file specified"));
535 abfd
= bfd_openr (input_file
, 0);
538 bfd_fatal (input_file
);
540 if (! bfd_check_format_matches (abfd
, bfd_object
, &matching
))
542 bfd_nonfatal (input_file
);
544 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
546 list_matching_formats (matching
);
552 tree
= coff_grok (abfd
);