home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / mips-tdump.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  41KB  |  1,551 lines

  1. /* Read and manage MIPS symbol tables from object modules.
  2.    Source originally from hartzell@boulder.colorado.edu
  3.    Rewritten by: meissner@osf.org
  4.    Copyright (C) 1991 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include <stdio.h>
  23. #include <sys/types.h>
  24. #include <sys/file.h>
  25. #include <fcntl.h>
  26. #include <errno.h>
  27. #include "config.h"
  28.  
  29. #ifdef index
  30. #undef index
  31. #undef rindex
  32. #endif
  33. #ifndef CROSS_COMPILE
  34. #include <a.out.h>
  35. #else
  36. #include "symconst.h"
  37. #define LANGUAGE_C
  38. #include "sym.h"
  39. #include "filehdr.h"
  40. #define ST_RFDESCAPE    0xfff
  41. #endif
  42.  
  43. #ifdef __STDC__
  44. typedef void *PTR_T;
  45. typedef const void *CPTR_T;
  46. #define __proto(x) x
  47. #else
  48.  
  49. #if defined(_STDIO_H_) || defined(__STDIO_H__)        /* Ultrix 4.0, SGI */
  50. typedef void *PTR_T;
  51. typedef void *CPTR_T;
  52.  
  53. #else
  54. typedef char *PTR_T;                    /* Ultrix 3.1 */
  55. typedef char *CPTR_T;
  56. #endif
  57.  
  58. #define __proto(x) ()
  59. #define const
  60. #endif
  61.  
  62. #define uchar    unsigned char
  63. #define ushort    unsigned short
  64. #define uint    unsigned int
  65. #define ulong    unsigned long
  66.  
  67.  
  68. /* Do to size_t being defined in sys/types.h and different
  69.    in stddef.h, we have to do this by hand.....  Note, these
  70.    types are correct for MIPS based systems, and may not be
  71.    correct for other systems.  */
  72.  
  73. #define size_t        uint
  74. #define ptrdiff_t    int
  75.  
  76.  
  77. /* Redefinition of of storage classes as an enumeration for better
  78.    debugging.  */
  79.  
  80. #ifndef stStaParam
  81. #define stStaParam    16    /* Fortran static parameters */
  82. #endif
  83.  
  84. #ifndef btVoid
  85. #define btVoid        26    /* void basic type */
  86. #endif
  87.  
  88. typedef enum sc {
  89.   sc_Nil     = scNil,      /* no storage class */
  90.   sc_Text     = scText,      /* text symbol */
  91.   sc_Data     = scData,      /* initialized data symbol */
  92.   sc_Bss     = scBss,      /* un-initialized data symbol */
  93.   sc_Register     = scRegister,      /* value of symbol is register number */
  94.   sc_Abs     = scAbs,      /* value of symbol is absolute */
  95.   sc_Undefined     = scUndefined,      /* who knows? */
  96.   sc_CdbLocal     = scCdbLocal,      /* variable's value is IN se->va.?? */
  97.   sc_Bits     = scBits,      /* this is a bit field */
  98.   sc_CdbSystem     = scCdbSystem,      /* var's value is IN CDB's address space */
  99.   sc_RegImage     = scRegImage,      /* register value saved on stack */
  100.   sc_Info     = scInfo,      /* symbol contains debugger information */
  101.   sc_UserStruct     = scUserStruct,  /* addr in struct user for current process */
  102.   sc_SData     = scSData,      /* load time only small data */
  103.   sc_SBss     = scSBss,      /* load time only small common */
  104.   sc_RData     = scRData,      /* load time only read only data */
  105.   sc_Var     = scVar,      /* Var parameter (fortran,pascal) */
  106.   sc_Common     = scCommon,      /* common variable */
  107.   sc_SCommon     = scSCommon,      /* small common */
  108.   sc_VarRegister = scVarRegister, /* Var parameter in a register */
  109.   sc_Variant     = scVariant,      /* Variant record */
  110.   sc_SUndefined     = scSUndefined,  /* small undefined(external) data */
  111.   sc_Init     = scInit,      /* .init section symbol */
  112.   sc_Max     = scMax      /* Max storage class+1 */
  113. } sc_t;
  114.  
  115. /* Redefinition of symbol type.  */
  116.  
  117. typedef enum st {
  118.   st_Nil    = stNil,    /* Nuthin' special */
  119.   st_Global    = stGlobal,    /* external symbol */
  120.   st_Static    = stStatic,    /* static */
  121.   st_Param    = stParam,    /* procedure argument */
  122.   st_Local    = stLocal,    /* local variable */
  123.   st_Label    = stLabel,    /* label */
  124.   st_Proc    = stProc,    /*     "      "     Procedure */
  125.   st_Block    = stBlock,    /* beginning of block */
  126.   st_End    = stEnd,    /* end (of anything) */
  127.   st_Member    = stMember,    /* member (of anything    - struct/union/enum */
  128.   st_Typedef    = stTypedef,    /* type definition */
  129.   st_File    = stFile,    /* file name */
  130.   st_RegReloc    = stRegReloc,    /* register relocation */
  131.   st_Forward    = stForward,    /* forwarding address */
  132.   st_StaticProc    = stStaticProc,    /* load time only static procs */
  133.   st_StaParam    = stStaParam,    /* Fortran static parameters */
  134.   st_Constant    = stConstant,    /* const */
  135.   st_Str    = stStr,    /* string */
  136.   st_Number    = stNumber,    /* pure number (ie. 4 NOR 2+2) */
  137.   st_Expr    = stExpr,    /* 2+2 vs. 4 */
  138.   st_Type    = stType,    /* post-coercion SER */
  139.   st_Max    = stMax        /* max type+1 */
  140. } st_t;
  141.  
  142. /* Redefinition of type qualifiers.  */
  143.  
  144. typedef enum tq {
  145.   tq_Nil    = tqNil,    /* bt is what you see */
  146.   tq_Ptr    = tqPtr,    /* pointer */
  147.   tq_Proc    = tqProc,    /* procedure */
  148.   tq_Array    = tqArray,    /* duh */
  149.   tq_Far    = tqFar,    /* longer addressing - 8086/8 land */
  150.   tq_Vol    = tqVol,    /* volatile */
  151.   tq_Max    = tqMax        /* Max type qualifier+1 */
  152. } tq_t;
  153.  
  154. /* Redefinition of basic types.  */
  155.  
  156. typedef enum bt {
  157.   bt_Nil    = btNil,    /* undefined */
  158.   bt_Adr    = btAdr,    /* address - integer same size as pointer */
  159.   bt_Char    = btChar,    /* character */
  160.   bt_UChar    = btUChar,    /* unsigned character */
  161.   bt_Short    = btShort,    /* short */
  162.   bt_UShort    = btUShort,    /* unsigned short */
  163.   bt_Int    = btInt,    /* int */
  164.   bt_UInt    = btUInt,    /* unsigned int */
  165.   bt_Long    = btLong,    /* long */
  166.   bt_ULong    = btULong,    /* unsigned long */
  167.   bt_Float    = btFloat,    /* float (real) */
  168.   bt_Double    = btDouble,    /* Double (real) */
  169.   bt_Struct    = btStruct,    /* Structure (Record) */
  170.   bt_Union    = btUnion,    /* Union (variant) */
  171.   bt_Enum    = btEnum,    /* Enumerated */
  172.   bt_Typedef    = btTypedef,    /* defined via a typedef, isymRef points */
  173.   bt_Range    = btRange,    /* subrange of int */
  174.   bt_Set    = btSet,    /* pascal sets */
  175.   bt_Complex    = btComplex,    /* fortran complex */
  176.   bt_DComplex    = btDComplex,    /* fortran double complex */
  177.   bt_Indirect    = btIndirect,    /* forward or unnamed typedef */
  178.   bt_FixedDec    = btFixedDec,    /* Fixed Decimal */
  179.   bt_FloatDec    = btFloatDec,    /* Float Decimal */
  180.   bt_String    = btString,    /* Varying Length Character String */
  181.   bt_Bit    = btBit,    /* Aligned Bit String */
  182.   bt_Picture    = btPicture,    /* Picture */
  183.   bt_Void    = btVoid,    /* void */
  184.   bt_Max    = btMax        /* Max basic type+1 */
  185. } bt_t;
  186.  
  187. /* Redefinition of the language codes.  */
  188.  
  189. typedef enum lang {
  190.   lang_C     = langC,
  191.   lang_Pascal     = langPascal,
  192.   lang_Fortran     = langFortran,
  193.   lang_Assembler = langAssembler,
  194.   lang_Machine     = langMachine,
  195.   lang_Nil     = langNil,
  196.   lang_Ada     = langAda,
  197.   lang_Pl1     = langPl1,
  198.   lang_Cobol     = langCobol
  199. } lang_t;
  200.  
  201. /* Redefinition of the debug level codes.  */
  202.  
  203. typedef enum glevel {
  204.   glevel_0    = GLEVEL_0,
  205.   glevel_1    = GLEVEL_1,
  206.   glevel_2    = GLEVEL_2,
  207.   glevel_3    = GLEVEL_3
  208. } glevel_t;
  209.  
  210.  
  211. /* Keep track of the active scopes.  */
  212. typedef struct scope {
  213.   struct scope *prev;        /* previous scope */
  214.   ulong open_sym;        /* symbol opening scope */
  215.   sc_t sc;            /* storage class */
  216.   st_t st;            /* symbol type */
  217. } scope_t;
  218.  
  219. struct filehdr global_hdr;    /* a.out header */
  220.  
  221. int     errors        = 0;    /* # of errors */
  222. int     want_aux    = 0;    /* print aux table */
  223. int     want_line    = 0;    /* print line numbers */
  224. int     want_rfd    = 0;    /* print relative file desc's */
  225. int     want_scope    = 0;    /* print scopes for every symbol */
  226. int     tfile_fd;        /* file descriptor of .T file */
  227. off_t     tfile_offset;        /* current offset in .T file */
  228. scope_t    *cur_scope    = 0;    /* list of active scopes */
  229. scope_t    *free_scope    = 0;    /* list of freed scopes */
  230. HDRR     sym_hdr;        /* symbolic header */
  231. char    *l_strings;        /* local strings */
  232. char    *e_strings;        /* external strings */
  233. SYMR    *l_symbols;        /* local symbols */
  234. EXTR    *e_symbols;        /* external symbols */
  235. LINER    *lines;            /* line numbers */
  236. DNR    *dense_nums;        /* dense numbers */
  237. OPTR    *opt_symbols;        /* optimization symbols */
  238. AUXU    *aux_symbols;        /* Auxiliary symbols */
  239. char    *aux_used;        /* map of which aux syms are used */
  240. FDR    *file_desc;        /* file tables */
  241. ulong    *rfile_desc;        /* relative file tables */
  242. PDR    *proc_desc;        /* procedure tables */
  243.  
  244. /* Forward reference for functions.  */
  245. PTR_T read_seek        __proto((PTR_T, size_t, off_t, const char *));
  246. void  read_tfile    __proto((void));
  247. void  print_