2 Copyright (C) 1994-2016 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 3 of the License, or (at
9 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., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 /* Written by Steve Chamberlain <sac@cygnus.com>
24 This module reads a type tree generated by coffgrok and prints
25 it out so we can test the grokker. */
29 #include "bfd_stdint.h"
30 #include "libiberty.h"
38 static void tab (int);
39 static void nl (void);
40 static void dump_coff_lines (struct coff_line
*);
41 static void dump_coff_type (struct coff_type
*);
42 static void dump_coff_where (struct coff_where
*);
43 static void dump_coff_visible (struct coff_visible
*);
44 static void dump_coff_scope (struct coff_scope
*);
45 static void dump_coff_sfile (struct coff_sfile
*);
46 static void dump_coff_section (struct coff_section
*);
47 static void show_usage (FILE *, int);
48 extern int main (int, char **);
74 for (i
= 0; i
< indent
; i
++)
84 for (i
= 0; i
< indent
; i
++)
100 dump_coff_lines (struct coff_line
*p
)
106 printf (_("#lines %d "),p
->nlines
);
108 for (i
= 0; i
< p
->nlines
; i
++)
110 printf ("(%d 0x%x)", p
->lines
[i
], p
->addresses
[i
]);
126 dump_coff_type (struct coff_type
*p
)
129 printf (_("size %d "), p
->size
);
133 case coff_secdef_type
:
134 printf (_("section definition at %x size %x\n"),
135 p
->u
.asecdef
.address
,
139 case coff_pointer_type
:
140 printf (_("pointer to"));
142 dump_coff_type (p
->u
.pointer
.points_to
);
144 case coff_array_type
:
145 printf (_("array [%d] of"), p
->u
.array
.dim
);
147 dump_coff_type (p
->u
.array
.array_of
);
149 case coff_function_type
:
150 printf (_("function returning"));
152 dump_coff_type (p
->u
.function
.function_returns
);
153 dump_coff_lines (p
->u
.function
.lines
);
154 printf (_("arguments"));
156 dump_coff_scope (p
->u
.function
.parameters
);
160 dump_coff_scope (p
->u
.function
.code
);
163 case coff_structdef_type
:
164 printf (_("structure definition"));
166 dump_coff_scope (p
->u
.astructdef
.elements
);
168 case coff_structref_type
:
169 if (!p
->u
.aenumref
.ref
)
170 printf (_("structure ref to UNKNOWN struct"));
172 printf (_("structure ref to %s"), p
->u
.aenumref
.ref
->name
);
174 case coff_enumref_type
:
175 printf (_("enum ref to %s"), p
->u
.astructref
.ref
->name
);
177 case coff_enumdef_type
:
178 printf (_("enum definition"));
180 dump_coff_scope (p
->u
.aenumdef
.elements
);
182 case coff_basic_type
:
245 dump_coff_where (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 (struct coff_visible
*p
)
289 case coff_vis_ext_def
:
290 printf ("coff_vis_ext_def");
292 case coff_vis_ext_ref
:
293 printf ("coff_vis_ext_ref");
295 case coff_vis_int_def
:
296 printf ("coff_vis_int_def");
298 case coff_vis_common
:
299 printf ("coff_vis_common");
302 printf ("coff_vis_auto");
304 case coff_vis_autoparam
:
305 printf ("coff_vis_autoparam");
307 case coff_vis_regparam
:
308 printf ("coff_vis_regparam");
310 case coff_vis_register
:
311 printf ("coff_vis_register");
314 printf ("coff_vis_tag");
316 case coff_vis_member_of_struct
:
317 printf ("coff_vis_member_of_struct");
319 case coff_vis_member_of_enum
:
320 printf ("coff_vis_member_of_enum");
330 dump_coff_symbol (struct coff_symbol
*p
)
333 printf (_("List of symbols"));
340 printf (_("Symbol %s, tag %d, number %d"), p
->name
, p
->tag
, p
->number
);
346 dump_coff_type (p
->type
);
350 dump_coff_where (p
->where
);
353 printf (_("Visible"));
354 dump_coff_visible (p
->visible
);
363 dump_coff_scope (struct coff_scope
*p
)
368 printf ("%s %" BFD_VMA_FMT
"x ",
369 _("List of blocks "), (bfd_vma
) (uintptr_t) p
);
372 printf( " %s %x..%x", p
->sec
->name
,p
->offset
, p
->offset
+ p
->size
-1);
376 printf ("*****************");
382 printf (_("vars %d"), p
->nvars
);
384 dump_coff_symbol (p
->vars_head
);
385 printf (_("blocks"));
387 dump_coff_scope (p
->list_head
);
393 printf ("*****************");
400 dump_coff_sfile (struct coff_sfile
*p
)
403 printf (_("List of source files"));
409 printf (_("Source file %s"), p
->name
);
411 dump_coff_scope (p
->scope
);
418 dump_coff_section (struct coff_section
*ptr
)
423 printf (_("section %s %d %d address %x size %x number %d nrelocs %u"),
424 ptr
->name
, ptr
->code
, ptr
->data
, ptr
->address
,ptr
->size
,
425 ptr
->number
, ptr
->nrelocs
);
428 for (i
= 0; i
< ptr
->nrelocs
; i
++)
430 struct coff_reloc
* r
= ptr
->relocs
+ i
;
432 printf ("(%x %s %x)",
434 /* PR 17512: file: 0a38fb7c. */
435 r
->symbol
== NULL
? _("<no sym>") : r
->symbol
->name
,
444 coff_dump (struct coff_ofile
*ptr
)
448 printf ("Coff dump");
450 printf (_("#sources %d"), ptr
->nsources
);
452 dump_coff_sfile (ptr
->source_head
);
454 for (i
= 0; i
< ptr
->nsections
; i
++)
455 dump_coff_section (ptr
->sections
+ i
);
461 show_usage (FILE *file
, int status
)
463 fprintf (file
, _("Usage: %s [option(s)] in-file\n"), program_name
);
464 fprintf (file
, _(" Print a human readable interpretation of a COFF object file\n"));
465 fprintf (file
, _(" The options are:\n\
466 @<file> Read options from <file>\n\
467 -h --help Display this information\n\
468 -v --version Display the program's version\n\
471 if (REPORT_BUGS_TO
[0] && status
== 0)
472 fprintf (file
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
478 main (int ac
, char **av
)
481 struct coff_ofile
*tree
;
483 char *input_file
= NULL
;
485 static struct option long_options
[] =
487 { "help", no_argument
, 0, 'h' },
488 { "version", no_argument
, 0, 'V' },
489 { NULL
, no_argument
, 0, 0 }
492 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
493 setlocale (LC_MESSAGES
, "");
495 #if defined (HAVE_SETLOCALE)
496 setlocale (LC_CTYPE
, "");
498 bindtextdomain (PACKAGE
, LOCALEDIR
);
499 textdomain (PACKAGE
);
501 program_name
= av
[0];
502 xmalloc_set_program_name (program_name
);
503 bfd_set_error_program_name (program_name
);
505 expandargv (&ac
, &av
);
507 while ((opt
= getopt_long (ac
, av
, "HhVv", long_options
,
515 show_usage (stdout
, 0);
519 print_version ("coffdump");
524 show_usage (stderr
, 1);
531 input_file
= av
[optind
];
535 fatal (_("no input file specified"));
537 abfd
= bfd_openr (input_file
, 0);
540 bfd_fatal (input_file
);
542 if (! bfd_check_format_matches (abfd
, bfd_object
, &matching
))
544 bfd_nonfatal (input_file
);
546 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
548 list_matching_formats (matching
);
554 tree
= coff_grok (abfd
);