1 /* Read and manage MIPS symbol tables from object modules.
2 Copyright (C) 1991, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2003, 2004,
3 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 Contributed by hartzell@boulder.colorado.edu,
5 Rewritten by meissner@osf.org.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
29 #ifndef CROSS_DIRECTORY_STRUCTURE
32 #include "mips/a.out.h"
33 #endif /* CROSS_DIRECTORY_STRUCTURE */
35 /* Include getopt.h for the sake of getopt_long. */
38 /* Macros for mips-tfile.c to encapsulate stabs in ECOFF, and for
39 mips-tdump.c to print them out.
41 These must match the corresponding definitions in gdb/mipsread.c.
42 Unfortunately, gcc and gdb do not currently share any directories. */
44 #define CODE_MASK 0x8F300
45 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
46 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
47 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
49 #define uchar unsigned char
50 #define ushort unsigned short
51 #define uint unsigned int
52 #define ulong unsigned long
55 /* Redefinition of storage classes as an enumeration for better
59 #define stStaParam 16 /* Fortran static parameters */
63 #define btVoid 26 /* void basic type */
67 sc_Nil
= scNil
, /* no storage class */
68 sc_Text
= scText
, /* text symbol */
69 sc_Data
= scData
, /* initialized data symbol */
70 sc_Bss
= scBss
, /* un-initialized data symbol */
71 sc_Register
= scRegister
, /* value of symbol is register number */
72 sc_Abs
= scAbs
, /* value of symbol is absolute */
73 sc_Undefined
= scUndefined
, /* who knows? */
74 sc_CdbLocal
= scCdbLocal
, /* variable's value is IN se->va.?? */
75 sc_Bits
= scBits
, /* this is a bit field */
76 sc_CdbSystem
= scCdbSystem
, /* var's value is IN CDB's address space */
77 sc_RegImage
= scRegImage
, /* register value saved on stack */
78 sc_Info
= scInfo
, /* symbol contains debugger information */
79 sc_UserStruct
= scUserStruct
, /* addr in struct user for current process */
80 sc_SData
= scSData
, /* load time only small data */
81 sc_SBss
= scSBss
, /* load time only small common */
82 sc_RData
= scRData
, /* load time only read only data */
83 sc_Var
= scVar
, /* Var parameter (fortran,pascal) */
84 sc_Common
= scCommon
, /* common variable */
85 sc_SCommon
= scSCommon
, /* small common */
86 sc_VarRegister
= scVarRegister
, /* Var parameter in a register */
87 sc_Variant
= scVariant
, /* Variant record */
88 sc_SUndefined
= scSUndefined
, /* small undefined(external) data */
89 sc_Init
= scInit
, /* .init section symbol */
90 sc_Max
= scMax
/* Max storage class+1 */
93 /* Redefinition of symbol type. */
96 st_Nil
= stNil
, /* Nuthin' special */
97 st_Global
= stGlobal
, /* external symbol */
98 st_Static
= stStatic
, /* static */
99 st_Param
= stParam
, /* procedure argument */
100 st_Local
= stLocal
, /* local variable */
101 st_Label
= stLabel
, /* label */
102 st_Proc
= stProc
, /* " " Procedure */
103 st_Block
= stBlock
, /* beginning of block */
104 st_End
= stEnd
, /* end (of anything) */
105 st_Member
= stMember
, /* member (of anything - struct/union/enum */
106 st_Typedef
= stTypedef
, /* type definition */
107 st_File
= stFile
, /* file name */
108 st_RegReloc
= stRegReloc
, /* register relocation */
109 st_Forward
= stForward
, /* forwarding address */
110 st_StaticProc
= stStaticProc
, /* load time only static procs */
111 st_StaParam
= stStaParam
, /* Fortran static parameters */
112 st_Constant
= stConstant
, /* const */
114 st_Struct
= stStruct
, /* struct */
115 st_Union
= stUnion
, /* union */
116 st_Enum
= stEnum
, /* enum */
118 st_Str
= stStr
, /* string */
119 st_Number
= stNumber
, /* pure number (i.e. 4 NOR 2+2) */
120 st_Expr
= stExpr
, /* 2+2 vs. 4 */
121 st_Type
= stType
, /* post-coercion SER */
122 st_Max
= stMax
/* max type+1 */
125 /* Redefinition of type qualifiers. */
128 tq_Nil
= tqNil
, /* bt is what you see */
129 tq_Ptr
= tqPtr
, /* pointer */
130 tq_Proc
= tqProc
, /* procedure */
131 tq_Array
= tqArray
, /* duh */
132 tq_Far
= tqFar
, /* longer addressing - 8086/8 land */
133 tq_Vol
= tqVol
, /* volatile */
134 tq_Max
= tqMax
/* Max type qualifier+1 */
137 /* Redefinition of basic types. */
140 bt_Nil
= btNil
, /* undefined */
141 bt_Adr
= btAdr
, /* address - integer same size as pointer */
142 bt_Char
= btChar
, /* character */
143 bt_UChar
= btUChar
, /* unsigned character */
144 bt_Short
= btShort
, /* short */
145 bt_UShort
= btUShort
, /* unsigned short */
146 bt_Int
= btInt
, /* int */
147 bt_UInt
= btUInt
, /* unsigned int */
148 bt_Long
= btLong
, /* long */
149 bt_ULong
= btULong
, /* unsigned long */
150 bt_Float
= btFloat
, /* float (real) */
151 bt_Double
= btDouble
, /* Double (real) */
152 bt_Struct
= btStruct
, /* Structure (Record) */
153 bt_Union
= btUnion
, /* Union (variant) */
154 bt_Enum
= btEnum
, /* Enumerated */
155 bt_Typedef
= btTypedef
, /* defined via a typedef, isymRef points */
156 bt_Range
= btRange
, /* subrange of int */
157 bt_Set
= btSet
, /* pascal sets */
158 bt_Complex
= btComplex
, /* fortran complex */
159 bt_DComplex
= btDComplex
, /* fortran double complex */
160 bt_Indirect
= btIndirect
, /* forward or unnamed typedef */
161 bt_FixedDec
= btFixedDec
, /* Fixed Decimal */
162 bt_FloatDec
= btFloatDec
, /* Float Decimal */
163 bt_String
= btString
, /* Varying Length Character String */
164 bt_Bit
= btBit
, /* Aligned Bit String */
165 bt_Picture
= btPicture
, /* Picture */
166 bt_Void
= btVoid
, /* void */
167 bt_Max
= btMax
/* Max basic type+1 */
170 /* Redefinition of the language codes. */
174 lang_Pascal
= langPascal
,
175 lang_Fortran
= langFortran
,
176 lang_Assembler
= langAssembler
,
177 lang_Machine
= langMachine
,
181 lang_Cobol
= langCobol
184 /* Redefinition of the debug level codes. */
186 typedef enum glevel
{
194 /* Keep track of the active scopes. */
195 typedef struct scope
{
196 struct scope
*prev
; /* previous scope */
197 ulong open_sym
; /* symbol opening scope */
198 sc_t sc
; /* storage class */
199 st_t st
; /* symbol type */
202 struct filehdr global_hdr
; /* a.out header */
204 int errors
= 0; /* # of errors */
205 int want_aux
= 0; /* print aux table */
206 int want_line
= 0; /* print line numbers */
207 int want_rfd
= 0; /* print relative file desc's */
208 int want_scope
= 0; /* print scopes for every symbol */
209 int tfile
= 0; /* no global header file */
210 int version
= 0; /* print version # */
212 int tfile_fd
; /* file descriptor of .T file */
213 off_t tfile_offset
; /* current offset in .T file */
214 scope_t
*cur_scope
= 0; /* list of active scopes */
215 scope_t
*free_scope
= 0; /* list of freed scopes */
216 HDRR sym_hdr
; /* symbolic header */
217 char *l_strings
; /* local strings */
218 char *e_strings
; /* external strings */
219 SYMR
*l_symbols
; /* local symbols */
220 EXTR
*e_symbols
; /* external symbols */
221 LINER
*lines
; /* line numbers */
222 DNR
*dense_nums
; /* dense numbers */
223 OPTR
*opt_symbols
; /* optimization symbols */
224 AUXU
*aux_symbols
; /* Auxiliary symbols */
225 char *aux_used
; /* map of which aux syms are used */
226 FDR
*file_desc
; /* file tables */
227 ulong
*rfile_desc
; /* relative file tables */
228 PDR
*proc_desc
; /* procedure tables */
230 /* Forward reference for functions. */
231 static void *read_seek (void *, size_t, off_t
, const char *);
232 static void read_tfile (void);
233 static void print_global_hdr (struct filehdr
*);
234 static void print_sym_hdr (HDRR
*);
235 static void print_file_desc (FDR
*, int);
236 static void print_symbol (SYMR
*, int, const char *, AUXU
*, int, FDR
*);
237 static void print_aux (AUXU
, int, int);
238 static void emit_aggregate (char *, AUXU
, AUXU
, const char *, FDR
*);
239 static const char *st_to_string (st_t
);
240 static const char *sc_to_string (sc_t
);
241 static const char *glevel_to_string (glevel_t
);
242 static const char *lang_to_string (lang_t
);
243 static const char *type_to_string (AUXU
*, int, FDR
*);
249 /* Create a table of debugging stab-codes and corresponding names. */
251 #define __define_stab(NAME, CODE, STRING) {(int)CODE, STRING},
252 const struct {const short code
; const char string
[10];} stab_names
[] = {
257 /* Command line options for getopt_long. */
259 static const struct option options
[] =
261 { "version", 0, 0, 'V' },
262 { "verbose", 0, 0, 'v' },
266 /* Read some bytes at a specified location, and return a pointer.
267 Read_seek takes a pointer PTR to a buffer or NULL and reads SIZE
268 bytes from offset OFFSET. In case of errors CONTEXT is used as
272 read_seek (void *ptr
, size_t size
, off_t offset
, const char *context
)
276 if (size
== 0) /* nothing to read */
280 ptr
= xmalloc (size
);
282 if ((tfile_offset
!= offset
&& lseek (tfile_fd
, offset
, 0) == -1)
283 || (read_size
= read (tfile_fd
, ptr
, size
)) < 0)
289 if (read_size
!= (long) size
)
291 fprintf (stderr
, "%s: read %ld bytes, expected %ld bytes\n",
292 context
, read_size
, (long) size
);
296 tfile_offset
= offset
+ size
;
301 /* Convert language code to string format. */
304 lang_to_string (lang_t lang
)
308 case langC
: return "C";
309 case langPascal
: return "Pascal";
310 case langFortran
: return "Fortran";
311 case langAssembler
: return "Assembler";
312 case langMachine
: return "Machine";
313 case langNil
: return "Nil";
314 case langAda
: return "Ada";
315 case langPl1
: return "Pl1";
316 case langCobol
: return "Cobol";
319 return "Unknown language";
323 /* Convert storage class to string. */
326 sc_to_string (sc_t storage_class
)
328 switch(storage_class
)
330 case sc_Nil
: return "Nil";
331 case sc_Text
: return "Text";
332 case sc_Data
: return "Data";
333 case sc_Bss
: return "Bss";
334 case sc_Register
: return "Register";
335 case sc_Abs
: return "Abs";
336 case sc_Undefined
: return "Undefined";
337 case sc_CdbLocal
: return "CdbLocal";
338 case sc_Bits
: return "Bits";
339 case sc_CdbSystem
: return "CdbSystem";
340 case sc_RegImage
: return "RegImage";
341 case sc_Info
: return "Info";
342 case sc_UserStruct
: return "UserStruct";
343 case sc_SData
: return "SData";
344 case sc_SBss
: return "SBss";
345 case sc_RData
: return "RData";
346 case sc_Var
: return "Var";
347 case sc_Common
: return "Common";
348 case sc_SCommon
: return "SCommon";
349 case sc_VarRegister
: return "VarRegister";
350 case sc_Variant
: return "Variant";
351 case sc_SUndefined
: return "SUndefined";
352 case sc_Init
: return "Init";
353 case sc_Max
: return "Max";
360 /* Convert symbol type to string. */
363 st_to_string (st_t symbol_type
)
367 case st_Nil
: return "Nil";
368 case st_Global
: return "Global";
369 case st_Static
: return "Static";
370 case st_Param
: return "Param";
371 case st_Local
: return "Local";
372 case st_Label
: return "Label";
373 case st_Proc
: return "Proc";
374 case st_Block
: return "Block";
375 case st_End
: return "End";
376 case st_Member
: return "Member";
377 case st_Typedef
: return "Typedef";
378 case st_File
: return "File";
379 case st_RegReloc
: return "RegReloc";
380 case st_Forward
: return "Forward";
381 case st_StaticProc
: return "StaticProc";
382 case st_Constant
: return "Constant";
383 case st_StaParam
: return "StaticParam";
385 case st_Struct
: return "Struct";
386 case st_Union
: return "Union";
387 case st_Enum
: return "Enum";
389 case st_Str
: return "String";
390 case st_Number
: return "Number";
391 case st_Expr
: return "Expr";
392 case st_Type
: return "Type";
393 case st_Max
: return "Max";
400 /* Convert debug level to string. */
403 glevel_to_string (glevel_t g_level
)
407 case GLEVEL_0
: return "G0";
408 case GLEVEL_1
: return "G1";
409 case GLEVEL_2
: return "G2";
410 case GLEVEL_3
: return "G3";
417 /* Convert the type information to string format. */
420 type_to_string (AUXU
*aux_ptr
, int index
, FDR
*fdp
)
432 static char buffer1
[1024];
433 static char buffer2
[1024];
436 char *used_ptr
= aux_used
+ (aux_ptr
- aux_symbols
);
438 for (i
= 0; i
< 7; i
++)
440 qualifiers
[i
].low_bound
= 0;
441 qualifiers
[i
].high_bound
= 0;
442 qualifiers
[i
].stride
= 0;
446 u
= aux_ptr
[index
++];
448 return "-1 (no type)";
450 basic_type
= (bt_t
) u
.ti
.bt
;
451 qualifiers
[0].type
= (tq_t
) u
.ti
.tq0
;
452 qualifiers
[1].type
= (tq_t
) u
.ti
.tq1
;
453 qualifiers
[2].type
= (tq_t
) u
.ti
.tq2
;
454 qualifiers
[3].type
= (tq_t
) u
.ti
.tq3
;
455 qualifiers
[4].type
= (tq_t
) u
.ti
.tq4
;
456 qualifiers
[5].type
= (tq_t
) u
.ti
.tq5
;
457 qualifiers
[6].type
= tq_Nil
;
460 * Go get the basic type.
464 case bt_Nil
: /* undefined */
468 case bt_Adr
: /* address - integer same size as pointer */
469 strcpy (p1
, "address");
472 case bt_Char
: /* character */
476 case bt_UChar
: /* unsigned character */
477 strcpy (p1
, "unsigned char");
480 case bt_Short
: /* short */
481 strcpy (p1
, "short");
484 case bt_UShort
: /* unsigned short */
485 strcpy (p1
, "unsigned short");
488 case bt_Int
: /* int */
492 case bt_UInt
: /* unsigned int */
493 strcpy (p1
, "unsigned int");
496 case bt_Long
: /* long */
500 case bt_ULong
: /* unsigned long */
501 strcpy (p1
, "unsigned long");
504 case bt_Float
: /* float (real) */
505 strcpy (p1
, "float");
508 case bt_Double
: /* Double (real) */
509 strcpy (p1
, "double");
512 /* Structures add 1-2 aux words:
513 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
514 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
516 case bt_Struct
: /* Structure (Record) */
517 emit_aggregate (p1
, aux_ptr
[index
], aux_ptr
[index
+1], "struct", fdp
);
519 if (aux_ptr
[index
].rndx
.rfd
== ST_RFDESCAPE
)
520 used_ptr
[++index
] = 1;
522 index
++; /* skip aux words */
525 /* Unions add 1-2 aux words:
526 1st word is [ST_RFDESCAPE, offset] pointer to union def;
527 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
529 case bt_Union
: /* Union */
530 emit_aggregate (p1
, aux_ptr
[index
], aux_ptr
[index
+1], "union", fdp
);
532 if (aux_ptr
[index
].rndx
.rfd
== ST_RFDESCAPE
)
533 used_ptr
[++index
] = 1;
535 index
++; /* skip aux words */
538 /* Enumerations add 1-2 aux words:
539 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
540 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
542 case bt_Enum
: /* Enumeration */
543 emit_aggregate (p1
, aux_ptr
[index
], aux_ptr
[index
+1], "enum", fdp
);
545 if (aux_ptr
[index
].rndx
.rfd
== ST_RFDESCAPE
)
546 used_ptr
[++index
] = 1;
548 index
++; /* skip aux words */
551 case bt_Typedef
: /* defined via a typedef, isymRef points */
552 strcpy (p1
, "typedef");
555 case bt_Range
: /* subrange of int */
556 strcpy (p1
, "subrange");
559 case bt_Set
: /* pascal sets */
563 case bt_Complex
: /* fortran complex */
564 strcpy (p1
, "complex");
567 case bt_DComplex
: /* fortran double complex */
568 strcpy (p1
, "double complex");
571 case bt_Indirect
: /* forward or unnamed typedef */
572 strcpy (p1
, "forward/unnamed typedef");
575 case bt_FixedDec
: /* Fixed Decimal */
576 strcpy (p1
, "fixed decimal");
579 case bt_FloatDec
: /* Float Decimal */
580 strcpy (p1
, "float decimal");
583 case bt_String
: /* Varying Length Character String */
584 strcpy (p1
, "string");
587 case bt_Bit
: /* Aligned Bit String */
591 case bt_Picture
: /* Picture */
592 strcpy (p1
, "picture");
595 case bt_Void
: /* Void */
600 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
604 p1
+= strlen (buffer1
);
607 * If this is a bitfield, get the bitsize.
614 bitsize
= aux_ptr
[index
++].width
;
615 sprintf (p1
, " : %d", bitsize
);
616 p1
+= strlen (buffer1
);
621 * Deal with any qualifiers.
623 if (qualifiers
[0].type
!= tq_Nil
)
626 * Snarf up any array bounds in the correct order. Arrays
627 * store 5 successive words in the aux. table:
628 * word 0 RNDXR to type of the bounds (i.e., int)
629 * word 1 Current file descriptor index
631 * word 3 high bound (or -1 if [])
632 * word 4 stride size in bits
634 for (i
= 0; i
< 7; i
++)
636 if (qualifiers
[i
].type
== tq_Array
)
638 qualifiers
[i
].low_bound
= aux_ptr
[index
+2].dnLow
;
639 qualifiers
[i
].high_bound
= aux_ptr
[index
+3].dnHigh
;
640 qualifiers
[i
].stride
= aux_ptr
[index
+4].width
;
642 used_ptr
[index
+1] = 1;
643 used_ptr
[index
+2] = 1;
644 used_ptr
[index
+3] = 1;
645 used_ptr
[index
+4] = 1;
651 * Now print out the qualifiers.
653 for (i
= 0; i
< 6; i
++)
655 switch (qualifiers
[i
].type
)
662 strcpy (p2
, "ptr to ");
663 p2
+= sizeof ("ptr to ")-1;
667 strcpy (p2
, "volatile ");
668 p2
+= sizeof ("volatile ")-1;
673 p2
+= sizeof ("far ")-1;
677 strcpy (p2
, "func. ret. ");
678 p2
+= sizeof ("func. ret. ");
686 /* Print array bounds reversed (i.e., in the order the C
687 programmer writes them). C is such a fun language.... */
689 while (i
< 5 && qualifiers
[i
+1].type
== tq_Array
)
692 for (j
= i
; j
>= first_array
; j
--)
694 strcpy (p2
, "array [");
695 p2
+= sizeof ("array [")-1;
696 if (qualifiers
[j
].low_bound
!= 0)
698 "%ld:%ld {%ld bits}",
699 (long) qualifiers
[j
].low_bound
,
700 (long) qualifiers
[j
].high_bound
,
701 (long) qualifiers
[j
].stride
);
703 else if (qualifiers
[j
].high_bound
!= -1)
706 (long) (qualifiers
[j
].high_bound
+ 1),
707 (long) (qualifiers
[j
].stride
));
710 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
713 strcpy (p2
, "] of ");
714 p2
+= sizeof ("] of ")-1;
722 strcpy (p2
, buffer1
);
727 /* Print out the global file header for object files. */
730 print_global_hdr (struct filehdr
*ptr
)
732 char *time
= ctime ((time_t *)&ptr
->f_timdat
);
733 ushort flags
= ptr
->f_flags
;
735 printf("Global file header:\n");
736 printf(" %-*s 0x%x\n", 24, "magic number", (ushort
) ptr
->f_magic
);
737 printf(" %-*s %d\n", 24, "# sections", (int) ptr
->f_nscns
);
738 printf(" %-*s %ld, %s", 24, "timestamp", (long) ptr
->f_timdat
, time
);
739 printf(" %-*s %ld\n", 24, "symbolic header offset", (long) ptr
->f_symptr
);
740 printf(" %-*s %ld\n", 24, "symbolic header size", (long) ptr
->f_nsyms
);
741 printf(" %-*s %ld\n", 24, "optional header", (long) ptr
->f_opthdr
);
742 printf(" %-*s 0x%x", 24, "flags", (ushort
) flags
);
744 if ((flags
& F_RELFLG
) != 0)
745 printf (", F_RELFLG");
747 if ((flags
& F_EXEC
) != 0)
750 if ((flags
& F_LNNO
) != 0)
753 if ((flags
& F_LSYMS
) != 0)
754 printf (", F_LSYMS");
756 if ((flags
& F_MINMAL
) != 0)
757 printf (", F_MINMAL");
759 if ((flags
& F_UPDATE
) != 0)
760 printf (", F_UPDATE");
762 if ((flags
& F_SWABD
) != 0)
763 printf (", F_SWABD");
765 if ((flags
& F_AR16WR
) != 0)
766 printf (", F_AR16WR");
768 if ((flags
& F_AR32WR
) != 0)
769 printf (", F_AR32WR");
771 if ((flags
& F_AR32W
) != 0)
772 printf (", F_AR32W");
774 if ((flags
& F_PATCH
) != 0)
775 printf (", F_PATCH/F_NODF");
781 /* Print out the symbolic header. */
784 print_sym_hdr (HDRR
*sym_ptr
)
788 printf("Symbolic header, magic number = 0x%04x, vstamp = %d.%d:\n\n",
789 sym_ptr
->magic
& 0xffff,
790 (sym_ptr
->vstamp
& 0xffff) >> 8,
791 sym_ptr
->vstamp
& 0xff);
793 printf(" %-*s %11s %11s %11s\n", width
, "Info", "Offset", "Number", "Bytes");
794 printf(" %-*s %11s %11s %11s\n", width
, "====", "======", "======", "=====\n");
796 printf(" %-*s %11ld %11ld %11ld [%d]\n", width
, "Line numbers",
797 (long) sym_ptr
->cbLineOffset
,
798 (long) sym_ptr
->cbLine
,
799 (long) sym_ptr
->cbLine
,
800 (int) sym_ptr
->ilineMax
);
802 printf(" %-*s %11ld %11ld %11ld\n", width
, "Dense numbers",
803 (long) sym_ptr
->cbDnOffset
,
804 (long) sym_ptr
->idnMax
,
805 (long) (sym_ptr
->idnMax
* sizeof (DNR
)));
807 printf(" %-*s %11ld %11ld %11ld\n", width
, "Procedures Tables",
808 (long) sym_ptr
->cbPdOffset
,
809 (long) sym_ptr
->ipdMax
,
810 (long) (sym_ptr
->ipdMax
* sizeof (PDR
)));
812 printf(" %-*s %11ld %11ld %11ld\n", width
, "Local Symbols",
813 (long) sym_ptr
->cbSymOffset
,
814 (long) sym_ptr
->isymMax
,
815 (long) (sym_ptr
->isymMax
* sizeof (SYMR
)));
817 printf(" %-*s %11ld %11ld %11ld\n", width
, "Optimization Symbols",
818 (long) sym_ptr
->cbOptOffset
,
819 (long) sym_ptr
->ioptMax
,
820 (long) (sym_ptr
->ioptMax
* sizeof (OPTR
)));
822 printf(" %-*s %11ld %11ld %11ld\n", width
, "Auxiliary Symbols",
823 (long) sym_ptr
->cbAuxOffset
,
824 (long) sym_ptr
->iauxMax
,
825 (long) (sym_ptr
->iauxMax
* sizeof (AUXU
)));
827 printf(" %-*s %11ld %11ld %11ld\n", width
, "Local Strings",
828 (long) sym_ptr
->cbSsOffset
,
829 (long) sym_ptr
->issMax
,
830 (long) sym_ptr
->issMax
);
832 printf(" %-*s %11ld %11ld %11ld\n", width
, "External Strings",
833 (long) sym_ptr
->cbSsExtOffset
,
834 (long) sym_ptr
->issExtMax
,
835 (long) sym_ptr
->issExtMax
);
837 printf(" %-*s %11ld %11ld %11ld\n", width
, "File Tables",
838 (long) sym_ptr
->cbFdOffset
,
839 (long) sym_ptr
->ifdMax
,
840 (long) (sym_ptr
->ifdMax
* sizeof (FDR
)));
842 printf(" %-*s %11ld %11ld %11ld\n", width
, "Relative Files",
843 (long) sym_ptr
->cbRfdOffset
,
844 (long) sym_ptr
->crfd
,
845 (long) (sym_ptr
->crfd
* sizeof (ulong
)));
847 printf(" %-*s %11ld %11ld %11ld\n", width
, "External Symbols",
848 (long) sym_ptr
->cbExtOffset
,
849 (long) sym_ptr
->iextMax
,
850 (long) (sym_ptr
->iextMax
* sizeof (EXTR
)));
854 /* Print out a symbol. */
857 print_symbol (SYMR
*sym_ptr
, int number
, const char *strbase
, AUXU
*aux_base
,
860 sc_t storage_class
= (sc_t
) sym_ptr
->sc
;
861 st_t symbol_type
= (st_t
) sym_ptr
->st
;
862 ulong index
= sym_ptr
->index
;
863 char *used_ptr
= aux_used
+ (aux_base
- aux_symbols
);
866 printf ("\n Symbol# %d: \"%s\"\n", number
, sym_ptr
->iss
+ strbase
);
868 if (aux_base
!= (AUXU
*) 0 && index
!= indexNil
)
877 printf (" End+1 symbol: %ld\n", index
);
880 if (free_scope
== (scope_t
*) 0)
881 scope_ptr
= (scope_t
*) xmalloc (sizeof (scope_t
));
884 scope_ptr
= free_scope
;
885 free_scope
= scope_ptr
->prev
;
887 scope_ptr
->open_sym
= number
;
888 scope_ptr
->st
= symbol_type
;
889 scope_ptr
->sc
= storage_class
;
890 scope_ptr
->prev
= cur_scope
;
891 cur_scope
= scope_ptr
;
896 if (storage_class
== sc_Text
|| storage_class
== sc_Info
)
897 printf (" First symbol: %ld\n", index
);
901 printf (" First symbol: %ld\n", (long) aux_base
[index
].isym
);
906 if (cur_scope
== (scope_t
*) 0)
907 printf (" Can't pop end scope\n");
910 scope_ptr
= cur_scope
;
911 cur_scope
= scope_ptr
->prev
;
912 scope_ptr
->prev
= free_scope
;
913 free_scope
= scope_ptr
;
920 if (MIPS_IS_STAB(sym_ptr
))
922 else if (ifd
== -1) /* local symbol */
924 used_ptr
[index
] = used_ptr
[index
+1] = 1;
925 printf (" End+1 symbol: %-7ld Type: %s\n",
926 (long) aux_base
[index
].isym
,
927 type_to_string (aux_base
, index
+1, fdp
));
929 else /* global symbol */
930 printf (" Local symbol: %ld\n", index
);
934 if (free_scope
== (scope_t
*) 0)
935 scope_ptr
= (scope_t
*) xmalloc (sizeof (scope_t
));
938 scope_ptr
= free_scope
;
939 free_scope
= scope_ptr
->prev
;
941 scope_ptr
->open_sym
= number
;
942 scope_ptr
->st
= symbol_type
;
943 scope_ptr
->sc
= storage_class
;
944 scope_ptr
->prev
= cur_scope
;
945 cur_scope
= scope_ptr
;
953 printf (" End+1 symbol: %lu\n", index
);
958 if (!MIPS_IS_STAB (sym_ptr
))
961 printf (" Type: %s\n",
962 type_to_string (aux_base
, index
, fdp
));
969 printf (" Scopes: ");
970 if (cur_scope
== (scope_t
*) 0)
974 for (scope_ptr
= cur_scope
;
975 scope_ptr
!= (scope_t
*) 0;
976 scope_ptr
= scope_ptr
->prev
)
979 if (scope_ptr
->st
== st_Proc
|| scope_ptr
->st
== st_StaticProc
)
981 else if (scope_ptr
->st
== st_File
)
983 else if (scope_ptr
->st
== st_Block
&& scope_ptr
->sc
== sc_Text
)
985 else if (scope_ptr
->st
== st_Block
&& scope_ptr
->sc
== sc_Info
)
990 printf (" %ld [%s]", scope_ptr
->open_sym
, sclass
);
996 printf (" Value: %-13ld ",
997 (long)sym_ptr
->value
);
999 printf ("String index: %ld\n", (long)sym_ptr
->iss
);
1001 printf ("String index: %-11ld Ifd: %d\n",
1002 (long)sym_ptr
->iss
, ifd
);
1004 printf (" Symbol type: %-11sStorage class: %-11s",
1005 st_to_string (symbol_type
), sc_to_string (storage_class
));
1007 if (MIPS_IS_STAB(sym_ptr
))
1009 int i
= ARRAY_SIZE (stab_names
);
1010 const char *stab_name
= "stab";
1011 short code
= MIPS_UNMARK_STAB(sym_ptr
->index
);
1014 if (stab_names
[i
].code
== code
)
1016 stab_name
= stab_names
[i
].string
;
1019 printf ("Index: 0x%lx (%s)\n", (long)sym_ptr
->index
, stab_name
);
1021 else if (sym_ptr
->st
== stLabel
&& sym_ptr
->index
!= indexNil
)
1022 printf ("Index: %ld (line#)\n", (long)sym_ptr
->index
);
1024 printf ("Index: %ld\n", (long)sym_ptr
->index
);
1029 /* Print out a word from the aux. table in various formats. */
1032 print_aux (AUXU u
, int auxi
, int used
)
1034 printf ("\t%s#%-5d %11ld, [%4ld/%7ld], [%2d %1d:%1d %1x:%1x:%1x:%1x:%1x:%1x]\n",
1035 (used
) ? " " : "* ",
1039 (long) u
.rndx
.index
,
1052 /* Write aggregate information to a string. */
1055 emit_aggregate (char *string
, AUXU u
, AUXU u2
, const char *which
, FDR
*fdp
)
1057 unsigned int ifd
= u
.rndx
.rfd
;
1058 unsigned int index
= u
.rndx
.index
;
1061 if (ifd
== ST_RFDESCAPE
)
1064 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1065 struct return type of a procedure compiled without -g. */
1066 if (ifd
== 0xffffffff
1067 || (u
.rndx
.rfd
== ST_RFDESCAPE
&& index
== 0))
1068 name
= "<undefined>";
1069 else if (index
== indexNil
)
1073 if (fdp
== 0 || sym_hdr
.crfd
== 0)
1074 fdp
= &file_desc
[ifd
];
1076 fdp
= &file_desc
[rfile_desc
[fdp
->rfdBase
+ ifd
]];
1077 name
= &l_strings
[fdp
->issBase
+ l_symbols
[index
+ fdp
->isymBase
].iss
];
1081 "%s %s { ifd = %u, index = %u }",
1082 which
, name
, ifd
, index
);
1086 /* Print out information about a file descriptor, and the symbols,
1087 procedures, and line numbers within it. */
1090 print_file_desc (FDR
*fdp
, int number
)
1098 str_base
= l_strings
+ fdp
->issBase
;
1099 aux_base
= aux_symbols
+ fdp
->iauxBase
;
1100 used_base
= aux_used
+ (aux_base
- aux_symbols
);
1102 printf ("\nFile #%d, \"%s\"\n\n",
1104 fdp
->rss
!= issNil
? str_base
+ fdp
->rss
: "<unknown>");
1106 printf (" Name index = %-10ld Readin = %s\n",
1107 (long) fdp
->rss
, (fdp
->fReadin
) ? "Yes" : "No");
1109 printf (" Merge = %-10s Endian = %s\n",
1110 (fdp
->fMerge
) ? "Yes" : "No",
1111 (fdp
->fBigendian
) ? "BIG" : "LITTLE");
1113 printf (" Debug level = %-10s Language = %s\n",
1114 glevel_to_string ((glevel_t
) fdp
->glevel
),
1115 lang_to_string((lang_t
) fdp
->lang
));
1117 printf (" Adr = 0x%08lx\n\n", (long) fdp
->adr
);
1119 printf(" %-*s %11s %11s %11s %11s\n", width
, "Info", "Start", "Number", "Size", "Offset");
1120 printf(" %-*s %11s %11s %11s %11s\n", width
, "====", "=====", "======", "====", "======");
1122 printf(" %-*s %11lu %11lu %11lu %11lu\n",
1123 width
, "Local strings",
1124 (ulong
) fdp
->issBase
,
1127 (ulong
) (fdp
->issBase
+ sym_hdr
.cbSsOffset
));
1129 printf(" %-*s %11lu %11lu %11lu %11lu\n",
1130 width
, "Local symbols",
1131 (ulong
) fdp
->isymBase
,
1133 (ulong
) (fdp
->csym
* sizeof (SYMR
)),
1134 (ulong
) (fdp
->isymBase
* sizeof (SYMR
) + sym_hdr
.cbSymOffset
));
1136 printf(" %-*s %11lu %11lu %11lu %11lu\n",
1137 width
, "Line numbers",
1138 (ulong
) fdp
->cbLineOffset
,
1140 (ulong
) fdp
->cbLine
,
1141 (ulong
) (fdp
->cbLineOffset
+ sym_hdr
.cbLineOffset
));
1143 printf(" %-*s %11lu %11lu %11lu %11lu\n",
1144 width
, "Optimization symbols",
1145 (ulong
) fdp
->ioptBase
,
1147 (ulong
) (fdp
->copt
* sizeof (OPTR
)),
1148 (ulong
) (fdp
->ioptBase
* sizeof (OPTR
) + sym_hdr
.cbOptOffset
));
1150 printf(" %-*s %11lu %11lu %11lu %11lu\n",
1151 width
, "Procedures",
1152 (ulong
) fdp
->ipdFirst
,
1154 (ulong
) (fdp
->cpd
* sizeof (PDR
)),
1155 (ulong
) (fdp
->ipdFirst
* sizeof (PDR
) + sym_hdr
.cbPdOffset
));
1157 printf(" %-*s %11lu %11lu %11lu %11lu\n",
1158 width
, "Auxiliary symbols",
1159 (ulong
) fdp
->iauxBase
,
1161 (ulong
) (fdp
->caux
* sizeof (AUXU
)),
1162 (ulong
) (fdp
->iauxBase
* sizeof(AUXU
) + sym_hdr
.cbAuxOffset
));
1164 printf(" %-*s %11lu %11lu %11lu %11lu\n",
1165 width
, "Relative Files",
1166 (ulong
) fdp
->rfdBase
,
1168 (ulong
) (fdp
->crfd
* sizeof (ulong
)),
1169 (ulong
) (fdp
->rfdBase
* sizeof(ulong
) + sym_hdr
.cbRfdOffset
));
1172 if (want_scope
&& cur_scope
!= (scope_t
*) 0)
1173 printf ("\n Warning scope does not start at 0!\n");
1176 * print the info about the symbol table.
1178 printf ("\n There are %lu local symbols, starting at %lu\n",
1180 (ulong
) (fdp
->isymBase
+ sym_hdr
.cbSymOffset
));
1182 for(symi
= fdp
->isymBase
; symi
< (fdp
->csym
+ fdp
->isymBase
); symi
++)
1183 print_symbol (&l_symbols
[symi
],
1184 symi
- fdp
->isymBase
,
1190 if (want_scope
&& cur_scope
!= (scope_t
*) 0)
1191 printf ("\n Warning scope does not end at 0!\n");
1194 * print the aux. table if desired.
1197 if (want_aux
&& fdp
->caux
!= 0)
1201 printf ("\n There are %lu auxiliary table entries, starting at %lu.\n\n",
1203 (ulong
) (fdp
->iauxBase
+ sym_hdr
.cbAuxOffset
));
1205 for (auxi
= fdp
->iauxBase
; auxi
< (fdp
->caux
+ fdp
->iauxBase
); auxi
++)
1206 print_aux (aux_base
[auxi
], auxi
, used_base
[auxi
]);
1210 * print the relative file descriptors.
1212 if (want_rfd
&& fdp
->crfd
!= 0)
1216 printf ("\n There are %lu relative file descriptors, starting at %lu.\n",
1218 (ulong
) fdp
->rfdBase
);
1220 rfd_ptr
= rfile_desc
+ fdp
->rfdBase
;
1221 for (i
= 0; i
< (ulong
) fdp
->crfd
; i
++)
1223 printf ("\t#%-5ld %11ld, 0x%08lx\n", i
, *rfd_ptr
, *rfd_ptr
);
1229 * do the procedure descriptors.
1231 printf ("\n There are %lu procedure descriptor entries, ", (ulong
) fdp
->cpd
);
1232 printf ("starting at %lu.\n", (ulong
) fdp
->ipdFirst
);
1234 for (pdi
= fdp
->ipdFirst
; pdi
< (fdp
->cpd
+ fdp
->ipdFirst
); pdi
++)
1236 PDR
*proc_ptr
= &proc_desc
[pdi
];
1237 printf ("\n\tProcedure descriptor %d:\n", (pdi
- fdp
->ipdFirst
));
1240 printf ("\t Name index = %-11ld Name = \"%s\"\n",
1241 (long) l_symbols
[proc_ptr
->isym
+ fdp
->isymBase
].iss
,
1242 l_symbols
[proc_ptr
->isym
+ fdp
->isymBase
].iss
+ str_base
);
1244 printf ("\t .mask 0x%08lx,%-9ld .fmask 0x%08lx,%ld\n",
1245 (long) proc_ptr
->regmask
,
1246 (long) proc_ptr
->regoffset
,
1247 (long) proc_ptr
->fregmask
,
1248 (long) proc_ptr
->fregoffset
);
1250 printf ("\t .frame $%d,%ld,$%d\n",
1251 (int) proc_ptr
->framereg
,
1252 (long) proc_ptr
->frameoffset
,
1253 (int) proc_ptr
->pcreg
);
1255 printf ("\t Opt. start = %-11ld Symbols start = %ld\n",
1256 (long) proc_ptr
->iopt
,
1257 (long) proc_ptr
->isym
);
1259 printf ("\t First line # = %-11ld Last line # = %ld\n",
1260 (long) proc_ptr
->lnLow
,
1261 (long) proc_ptr
->lnHigh
);
1263 printf ("\t Line Offset = %-11ld Address = 0x%08lx\n",
1264 (long) proc_ptr
->cbLineOffset
,
1265 (long) proc_ptr
->adr
);
1268 * print the line number entries.
1271 if (want_line
&& fdp
->cline
!= 0)
1274 long cur_line
= proc_ptr
->lnLow
;
1275 uchar
*line_ptr
= (((uchar
*)lines
) + proc_ptr
->cbLineOffset
1276 + fdp
->cbLineOffset
);
1279 if (pdi
== fdp
->cpd
+ fdp
->ipdFirst
- 1) /* last procedure */
1280 line_end
= ((uchar
*)lines
) + fdp
->cbLine
+ fdp
->cbLineOffset
;
1281 else /* not last proc. */
1282 line_end
= (((uchar
*)lines
) + proc_desc
[pdi
+1].cbLineOffset
1283 + fdp
->cbLineOffset
);
1285 printf ("\n\tThere are %lu bytes holding line numbers, starting at %lu.\n",
1286 (ulong
) (line_end
- line_ptr
),
1287 (ulong
) (fdp
->ilineBase
+ sym_hdr
.cbLineOffset
));
1289 while (line_ptr
< line_end
)
1290 { /* sign extend nibble */
1291 delta
= ((*line_ptr
>> 4) ^ 0x8) - 0x8;
1292 count
= (*line_ptr
& 0xf) + 1;
1297 delta
= (((line_ptr
[1]) & 0xff) << 8) + ((line_ptr
[2]) & 0xff);
1298 delta
= (delta
^ 0x8000) - 0x8000;
1303 printf ("\t Line %11ld, delta %5d, count %2d\n",
1313 /* Read in the portions of the .T file that we will print out. */
1319 off_t sym_hdr_offset
= 0;
1321 read_seek (&magic
, sizeof (magic
), 0, "Magic number");
1324 /* Print out the global header, since this is not a T-file. */
1326 read_seek (&global_hdr
, sizeof (global_hdr
), 0, "Global file header");
1328 print_global_hdr (&global_hdr
);
1330 if (global_hdr
.f_symptr
== 0)
1332 printf ("No symbolic header, Goodbye!\n");
1336 sym_hdr_offset
= global_hdr
.f_symptr
;
1339 read_seek (&sym_hdr
, sizeof (sym_hdr
), sym_hdr_offset
, "Symbolic header");
1341 print_sym_hdr (&sym_hdr
);
1343 lines
= (LINER
*) read_seek (NULL
, sym_hdr
.cbLine
, sym_hdr
.cbLineOffset
,
1346 dense_nums
= (DNR
*) read_seek (NULL
, sym_hdr
.idnMax
* sizeof (DNR
),
1347 sym_hdr
.cbDnOffset
, "Dense numbers");
1349 proc_desc
= (PDR
*) read_seek (NULL
, sym_hdr
.ipdMax
* sizeof (PDR
),
1350 sym_hdr
.cbPdOffset
, "Procedure tables");
1352 l_symbols
= (SYMR
*) read_seek (NULL
, sym_hdr
.isymMax
* sizeof (SYMR
),
1353 sym_hdr
.cbSymOffset
, "Local symbols");
1355 opt_symbols
= (OPTR
*) read_seek (NULL
, sym_hdr
.ioptMax
* sizeof (OPTR
),
1356 sym_hdr
.cbOptOffset
,
1357 "Optimization symbols");
1359 aux_symbols
= (AUXU
*) read_seek (NULL
, sym_hdr
.iauxMax
* sizeof (AUXU
),
1360 sym_hdr
.cbAuxOffset
, "Auxiliary symbols");
1362 if (sym_hdr
.iauxMax
> 0)
1363 aux_used
= (char *) xcalloc (sym_hdr
.iauxMax
, 1);
1365 l_strings
= (char *) read_seek (NULL
, sym_hdr
.issMax
,
1366 sym_hdr
.cbSsOffset
, "Local string table");
1368 e_strings
= (char *) read_seek (NULL
, sym_hdr
.issExtMax
,
1369 sym_hdr
.cbSsExtOffset
,
1370 "External string table");
1372 file_desc
= (FDR
*) read_seek (NULL
, sym_hdr
.ifdMax
* sizeof (FDR
),
1373 sym_hdr
.cbFdOffset
, "File tables");
1375 rfile_desc
= (ulong
*) read_seek (NULL
, sym_hdr
.crfd
* sizeof (ulong
),
1376 sym_hdr
.cbRfdOffset
,
1377 "Relative file tables");
1379 e_symbols
= (EXTR
*) read_seek (NULL
, sym_hdr
.iextMax
* sizeof (EXTR
),
1380 sym_hdr
.cbExtOffset
, "External symbols");
1385 extern int main (int, char **);
1388 main (int argc
, char **argv
)
1395 while ((opt
= getopt_long (argc
, argv
, "alrsvt", options
, NULL
)) != -1)
1398 default: errors
++; break;
1399 case 'a': want_aux
++; break; /* print aux table */
1400 case 'l': want_line
++; break; /* print line numbers */
1401 case 'r': want_rfd
++; break; /* print relative fd's */
1402 case 's': want_scope
++; break; /* print scope info */
1403 case 'v': verbose
++; break; /* print version # */
1404 case 'V': version
++; break; /* print version # */
1405 case 't': tfile
++; break; /* this is a tfile (without header),
1411 printf ("mips-tdump %s%s\n", pkgversion_string
, version_string
);
1412 fputs ("Copyright (C) 2011 Free Software Foundation, Inc.\n", stdout
);
1413 fputs ("This is free software; see the source for copying conditions. There is NO\n\
1414 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n",
1419 if (optind
!= argc
- 1)
1422 if (verbose
|| errors
)
1423 fprintf (stderr
, "mips-tdump (GCC) %s\n", version_string
);
1427 fprintf (stderr
, "Calling Sequence:\n");
1428 fprintf (stderr
, "\t%s [-alrst] <object-or-T-file>\n", argv
[0]);
1429 fprintf (stderr
, "\n");
1430 fprintf (stderr
, "switches:\n");
1431 fprintf (stderr
, "\t-a Print out auxiliary table.\n");
1432 fprintf (stderr
, "\t-l Print out line numbers.\n");
1433 fprintf (stderr
, "\t-r Print out relative file descriptors.\n");
1434 fprintf (stderr
, "\t-s Print out the current scopes for an item.\n");
1435 fprintf (stderr
, "\t-t Assume there is no global header (ie, a T-file).\n");
1436 fprintf (stderr
, "\t-v Print program version.\n");
1441 * Open and process the input file.
1443 tfile_fd
= open (argv
[optind
], O_RDONLY
);
1446 perror (argv
[optind
]);
1453 * Print any global aux words if any.
1457 long last_aux_in_use
;
1459 if (sym_hdr
.ifdMax
!= 0 && file_desc
[0].iauxBase
!= 0)
1461 printf ("\nGlobal auxiliary entries before first file:\n");
1462 for (i
= 0; i
< file_desc
[0].iauxBase
; i
++)
1463 print_aux (aux_symbols
[i
], 0, aux_used
[i
]);
1466 if (sym_hdr
.ifdMax
== 0)
1467 last_aux_in_use
= 0;
1470 = (file_desc
[sym_hdr
.ifdMax
-1].iauxBase
1471 + file_desc
[sym_hdr
.ifdMax
-1].caux
- 1);
1473 if (last_aux_in_use
< sym_hdr
.iauxMax
-1)
1475 printf ("\nGlobal auxiliary entries after last file:\n");
1476 for (i
= last_aux_in_use
; i
< sym_hdr
.iauxMax
; i
++)
1477 print_aux (aux_symbols
[i
], i
- last_aux_in_use
, aux_used
[i
]);
1482 * Print the information for each file.
1484 for (i
= 0; i
< sym_hdr
.ifdMax
; i
++)
1485 print_file_desc (&file_desc
[i
], i
);
1488 * Print the external symbols.
1490 want_scope
= 0; /* scope info is meaning for extern symbols */
1491 printf ("\nThere are %lu external symbols, starting at %lu\n",
1492 (ulong
) sym_hdr
.iextMax
,
1493 (ulong
) sym_hdr
.cbExtOffset
);
1495 for(i
= 0; i
< sym_hdr
.iextMax
; i
++)
1496 print_symbol (&e_symbols
[i
].asym
, i
, e_strings
,
1497 aux_symbols
+ file_desc
[e_symbols
[i
].ifd
].iauxBase
,
1499 &file_desc
[e_symbols
[i
].ifd
]);
1502 * Print unused aux symbols now.
1509 for (i
= 0; i
< sym_hdr
.iauxMax
; i
++)
1515 printf ("\nThe following auxiliary table entries were unused:\n\n");
1519 printf (" #%-5d %11ld 0x%08lx %s\n",
1521 (long) aux_symbols
[i
].isym
,
1522 (long) aux_symbols
[i
].isym
,
1523 type_to_string (aux_symbols
, i
, (FDR
*) 0));