home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / sdbout.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  43KB  |  1,520 lines

  1. /* Output sdb-format symbol table information from GNU compiler.
  2.    Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC 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 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC 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.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /*  mike@tredysvr.Tredydev.Unisys.COM says:
  21. I modified the struct.c example and have a nm of a .o resulting from the
  22. AT&T C compiler.  From the example below I would conclude the following:
  23.  
  24. 1. All .defs from structures are emitted as scanned.  The example below
  25.    clearly shows the symbol table entries for BoxRec2 are after the first
  26.    function.
  27.  
  28. 2. All functions and their locals (including statics) are emitted as scanned.
  29.  
  30. 3. All nested unnamed union and structure .defs must be emitted before
  31.    the structure in which they are nested.  The AT&T assembler is a
  32.    one pass beast as far as symbolics are concerned.
  33.  
  34. 4. All structure .defs are emitted before the typedefs that refer to them.
  35.  
  36. 5. All top level static and external variable definitions are moved to the
  37.    end of file with all top level statics occurring first before externs.
  38.  
  39. 6. All undefined references are at the end of the file.
  40. */
  41.  
  42. #include "config.h"
  43.  
  44. #ifdef SDB_DEBUGGING_INFO
  45.  
  46. #include "tree.h"
  47. #include "rtl.h"
  48. #include <stdio.h>
  49. #include "regs.h"
  50. #include "flags.h"
  51. #include "insn-config.h"
  52. #include "reload.h"
  53.  
  54. /* Mips systems use the SDB functions to dump out symbols, but
  55.    do not supply usable syms.h include files.  */
  56. #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(WINNT)
  57. #include <syms.h>
  58. /* Use T_INT if we don't have T_VOID.  */
  59. #ifndef T_VOID
  60. #define T_VOID T_INT
  61. #endif
  62. #else /* not USG, or MIPS */
  63. #include "gsyms.h"
  64. #endif /* not USG, or MIPS */
  65.  
  66. /* #include <storclass.h>  used to be this instead of syms.h.  */
  67.  
  68. /* 1 if PARM is passed to this function in memory.  */
  69.  
  70. #define PARM_PASSED_IN_MEMORY(PARM) \
  71.  (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
  72.  
  73. /* A C expression for the integer offset value of an automatic variable
  74.    (C_AUTO) having address X (an RTX).  */
  75. #ifndef DEBUGGER_AUTO_OFFSET
  76. #define DEBUGGER_AUTO_OFFSET(X) \
  77.   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
  78. #endif
  79.  
  80. /* A C expression for the integer offset value of an argument (C_ARG)
  81.    having address X (an RTX).  The nominal offset is OFFSET.  */
  82. #ifndef DEBUGGER_ARG_OFFSET
  83. #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
  84. #endif
  85.  
  86. /* Line number of beginning of current function, minus one.
  87.    Negative means not in a function or not using sdb.  */
  88.  
  89. int sdb_begin_function_line = -1;
  90.  
  91. /* Counter to generate unique "names" for nameless struct members.  */
  92.  
  93. static int unnamed_struct_number = 0;
  94.  
  95. extern FILE *asm_out_file;
  96.  
  97. extern tree current_function_decl;
  98.  
  99. void sdbout_init ();
  100. void sdbout_symbol ();
  101. void sdbout_types();
  102.  
  103. static void sdbout_typedefs ();
  104. static void sdbout_syms ();
  105. static void sdbout_one_type ();
  106. static void sdbout_queue_anonymous_type ();
  107. static void sdbout_dequeue_anonymous_types ();
  108. static int plain_type_1 ();
  109.  
  110. /* Define the default sizes for various types.  */
  111.  
  112. #ifndef CHAR_TYPE_SIZE
  113. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  114. #endif
  115.  
  116. #ifndef SHORT_TYPE_SIZE
  117. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  118. #endif
  119.  
  120. #ifndef INT_TYPE_SIZE
  121. #define INT_TYPE_SIZE BITS_PER_WORD
  122. #endif
  123.  
  124. #ifndef LONG_TYPE_SIZE
  125. #define LONG_TYPE_SIZE BITS_PER_WORD
  126. #endif
  127.  
  128. #ifndef LONG_LONG_TYPE_SIZE
  129. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  130. #endif
  131.  
  132. #ifndef FLOAT_TYPE_SIZE
  133. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  134. #endif
  135.  
  136. #ifndef DOUBLE_TYPE_SIZE
  137. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  138. #endif
  139.  
  140. #ifndef LONG_DOUBLE_TYPE_SIZE
  141. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  142. #endif
  143.  
  144. /* Random macros describing parts of SDB data.  */
  145.  
  146. /* Put something here if lines get too long */
  147. #define CONTIN
  148.  
  149. /* Default value of delimiter is ";".  */
  150. #ifndef SDB_DELIM
  151. #define SDB_DELIM    ";"
  152. #endif
  153.  
  154. /* Maximum number of dimensions the assembler will allow.  */
  155. #ifndef SDB_MAX_DIM
  156. #define SDB_MAX_DIM 4
  157. #endif
  158.  
  159. #ifndef PUT_SDB_SCL
  160. #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
  161. #endif
  162.  
  163. #ifndef PUT_SDB_INT_VAL
  164. #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
  165. #endif
  166.  
  167. #ifndef PUT_SDB_VAL
  168. #define PUT_SDB_VAL(a)                \
  169. ( fputs ("\t.val\t", asm_out_file),        \
  170.   output_addr_const (asm_out_file, (a)),    \
  171.   fprintf (asm_out_file, SDB_DELIM))
  172. #endif
  173.  
  174. #ifndef PUT_SDB_DEF
  175. #define PUT_SDB_DEF(a)                \
  176. do { fprintf (asm_out_file, "\t.def\t");    \
  177.      ASM_OUTPUT_LABELREF (asm_out_file, a);     \
  178.      fprintf (asm_out_file, SDB_DELIM); } while (0)
  179. #endif
  180.  
  181. #ifndef PUT_SDB_PLAIN_DEF
  182. #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
  183. #endif
  184.  
  185. #ifndef PUT_SDB_ENDEF
  186. #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
  187. #endif
  188.  
  189. #ifndef PUT_SDB_TYPE
  190. #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
  191. #endif
  192.  
  193. #ifndef PUT_SDB_SIZE
  194. #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
  195. #endif
  196.  
  197. #ifndef PUT_SDB_START_DIM
  198. #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
  199. #endif
  200.  
  201. #ifndef PUT_SDB_NEXT_DIM
  202. #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
  203. #endif
  204.  
  205. #ifndef PUT_SDB_LAST_DIM
  206. #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
  207. #endif
  208.  
  209. #ifndef PUT_SDB_TAG
  210. #define PUT_SDB_TAG(a)                \
  211. do { fprintf (asm_out_file, "\t.tag\t");    \
  212.      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
  213.      fprintf (asm_out_file, SDB_DELIM); } while (0)
  214. #endif
  215.  
  216. #ifndef PUT_SDB_BLOCK_START
  217. #define PUT_SDB_BLOCK_START(LINE)        \
  218.   fprintf (asm_out_file,            \
  219.        "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
  220.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  221. #endif
  222.  
  223. #ifndef PUT_SDB_BLOCK_END
  224. #define PUT_SDB_BLOCK_END(LINE)            \
  225.   fprintf (asm_out_file,            \
  226.        "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n",  \
  227.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  228. #endif
  229.  
  230. #ifndef PUT_SDB_FUNCTION_START
  231. #define PUT_SDB_FUNCTION_START(LINE)        \
  232.   fprintf (asm_out_file,            \
  233.        "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
  234.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  235. #endif
  236.  
  237. #ifndef PUT_SDB_FUNCTION_END
  238. #define PUT_SDB_FUNCTION_END(LINE)        \
  239.   fprintf (asm_out_file,            \
  240.        "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
  241.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  242. #endif
  243.  
  244. #ifndef PUT_SDB_EPILOGUE_END
  245. #define PUT_SDB_EPILOGUE_END(NAME)            \
  246. do { fprintf (asm_out_file, "\t.def\t");        \
  247.      ASM_OUTPUT_LABELREF (asm_out_file, NAME);        \
  248.      fprintf (asm_out_file,                \
  249.           "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",    \
  250.           SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
  251. #endif
  252.  
  253. #ifndef SDB_GENERATE_FAKE
  254. #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
  255.   sprintf ((BUFFER), ".%dfake", (NUMBER));
  256. #endif
  257.  
  258. /* Return the sdb tag identifier string for TYPE
  259.    if TYPE has already been defined; otherwise return a null pointer.   */
  260.  
  261. #define KNOWN_TYPE_TAG(type)  TYPE_SYMTAB_POINTER (type)
  262.  
  263. /* Set the sdb tag identifier string for TYPE to NAME.  */
  264.  
  265. #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
  266.   TYPE_SYMTAB_POINTER (TYPE) = (NAME)
  267.  
  268. /* Return the name (a string) of the struct, union or enum tag
  269.    described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
  270.  
  271. #define TAG_NAME(link) \
  272.   (((link) && TREE_PURPOSE ((link)) \
  273.     && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
  274.    ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
  275.  
  276. /* Ensure we don't output a negative line number.  */
  277. #define MAKE_LINE_SAFE(line)  \
  278.   if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
  279.  
  280. /* Set up for SDB output at the start of compilation.  */
  281.  
  282. void
  283. sdbout_init (asm_file, input_file_name, syms)
  284.      FILE *asm_file;
  285.      char *input_file_name;
  286.      tree syms;
  287. {
  288. #ifdef RMS_QUICK_HACK_1
  289.   tree t;
  290.   for (t = syms; t; t = TREE_CHAIN (t))
  291.     if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
  292.     && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
  293.       sdbout_symbol (t, 0);
  294. #endif  
  295.  
  296. #if 0 /* Nothing need be output for the predefined types.  */
  297.   /* Get all permanent types that have typedef names,
  298.      and output them all, except for those already output.  */
  299.  
  300.   sdbout_typedefs (syms);
  301. #endif
  302. }
  303.  
  304. #if 0
  305.  
  306. /* return the tag identifier for type
  307.  */
  308.  
  309. char *
  310. tag_of_ru_type (type,link)
  311.      tree type,link;
  312. {
  313.   if (TYPE_SYMTAB_ADDRESS (type))
  314.     return TYPE_SYMTAB_ADDRESS (type);
  315.   if (link && TREE_PURPOSE (link)
  316.       && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
  317.     TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
  318.   else
  319.     return (char *) TYPE_SYMTAB_ADDRESS (type);
  320. }
  321. #endif
  322.  
  323. /* Return a unique string to name an anonymous type.  */
  324.  
  325. static char *
  326. gen_fake_label ()
  327. {
  328.   char label[10];
  329.   char *labelstr;
  330.   SDB_GENERATE_FAKE (label, unnamed_struct_number);
  331.   unnamed_struct_number++;
  332.   labelstr = (char *) permalloc (strlen (label) + 1);
  333.   strcpy (labelstr, label);
  334.   return labelstr;
  335. }
  336.  
  337. /* Return the number which describes TYPE for SDB.
  338.    For pointers, etc., this function is recursive.
  339.    Each record, union or enumeral type must already have had a
  340.    tag number output.  */
  341.  
  342. /* The number is given by d6d5d4d3d2d1bbbb
  343.    where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
  344.    Thus, char *foo () has bbbb=T_CHAR
  345.               d1=D_FCN
  346.               d2=D_PTR
  347.  N_BTMASK=     017       1111     basic type field.
  348.  N_TSHIFT=       2                derived type shift
  349.  N_BTSHFT=       4                Basic type shift */
  350.  
  351. /* Produce the number that describes a pointer, function or array type.
  352.    PREV is the number describing the target, value or element type.
  353.    DT_type describes how to transform that type.  */
  354. #define PUSH_DERIVED_LEVEL(DT_type,PREV)        \
  355.   ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT)        \
  356.    | ((int)DT_type << (int)N_BTSHFT)            \
  357.    | ((PREV) & (int)N_BTMASK))
  358.  
  359. /* Number of elements used in sdb_dims.  */
  360. static int sdb_n_dims = 0;
  361.  
  362. /* Table of array dimensions of current type.  */
  363. static int sdb_dims[SDB_MAX_DIM];
  364.  
  365. /* Size of outermost array currently being processed.  */
  366. static int sdb_type_size = -1;
  367.  
  368. static int
  369. plain_type (type)
  370.      tree type;
  371. {
  372.   int val = plain_type_1 (type);
  373.  
  374.   /* If we have already saved up some array dimensions, print them now.  */
  375.   if (sdb_n_dims > 0)
  376.     {
  377.       int i;
  378.       PUT_SDB_START_DIM;
  379.       for (i = sdb_n_dims - 1; i > 0; i--)
  380.     PUT_SDB_NEXT_DIM (sdb_dims[i]);
  381.       PUT_SDB_LAST_DIM (sdb_dims[0]);
  382.       sdb_n_dims = 0;
  383.  
  384.       sdb_type_size = int_size_in_bytes (type);
  385.       /* Don't kill sdb if type is not laid out or has variable size.  */
  386.       if (sdb_type_size < 0)
  387.     sdb_type_size = 0;
  388.     }
  389.   /* If we have computed the size of an array containing this type,
  390.      print it now.  */
  391.   if (sdb_type_size >= 0)
  392.     {
  393.       PUT_SDB_SIZE (sdb_type_size);
  394.       sdb_type_size = -1;
  395.     }
  396.   return val;
  397. }
  398.  
  399. static int
  400. template_name_p (name)
  401.      tree name;
  402. {
  403.   register char *ptr = IDENTIFIER_POINTER (name);
  404.   while (*ptr && *ptr != '<')
  405.     ptr++;
  406.  
  407.   return *ptr != '\0';
  408. }
  409.  
  410. static void
  411. sdbout_record_type_name (type)
  412.      tree type;
  413. {
  414.   char *name = 0;
  415.   int no_name;
  416.  
  417.   if (KNOWN_TYPE_TAG (type))
  418.     return;
  419.  
  420.   if (TYPE_NAME (type) != 0)
  421.     {
  422.       tree t = 0;
  423.       /* Find the IDENTIFIER_NODE for the type name.  */
  424.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  425.     t = TYPE_NAME (type);
  426.       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  427.     {
  428.       t = DECL_NAME (TYPE_NAME (type));
  429.       /* The DECL_NAME for templates includes "<>", which breaks
  430.          most assemblers.  Use its assembler name instead, which
  431.          has been mangled into being safe.  */
  432.       if (t && template_name_p (t))
  433.         t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
  434.     }
  435.  
  436.       /* Now get the name as a string, or invent one.  */
  437.       if (t != NULL_TREE)
  438.     name = IDENTIFIER_POINTER (t);
  439.     }
  440.  
  441.   no_name = (name == 0 || *name == 0);
  442.   if (no_name)
  443.     name = gen_fake_label ();
  444.  
  445.   SET_KNOWN_TYPE_TAG (type, name);
  446. #ifdef SDB_ALLOW_FORWARD_REFERENCES
  447.   if (no_name)
  448.     sdbout_queue_anonymous_type (type);
  449. #endif
  450. }
  451.  
  452. static int
  453. plain_type_1 (type)
  454.      tree type;
  455. {
  456.   if (type == 0)
  457.     type = void_type_node;
  458.   if (type == error_mark_node)
  459.     type = integer_type_node;
  460.   type = TYPE_MAIN_VARIANT (type);
  461.  
  462.   switch (TREE_CODE (type))
  463.     {
  464.     case VOID_TYPE:
  465.       return T_VOID;
  466.     case INTEGER_TYPE:
  467.       {
  468.     int size = int_size_in_bytes (type) * BITS_PER_UNIT;
  469.  
  470.     /* Carefully distinguish all the standard types of C,
  471.        without messing up if the language is not C.
  472.        Note that we check only for the names that contain spaces;
  473.        other names might occur by coincidence in other languages.  */
  474.     if (TYPE_NAME (type) != 0
  475.         && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  476.         && DECL_NAME (TYPE_NAME (type)) != 0
  477.         && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
  478.       {
  479.         char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  480.  
  481.         if (!strcmp (name, "unsigned char"))
  482.           return T_UCHAR;
  483.         if (!strcmp (name, "signed char"))
  484.           return T_CHAR;
  485.         if (!strcmp (name, "unsigned int"))
  486.           return T_UINT;
  487.         if (!strcmp (name, "short int"))
  488.           return T_SHORT;
  489.         if (!strcmp (name, "short unsigned int"))
  490.           return T_USHORT;
  491.         if (!strcmp (name, "long int"))
  492.           return T_LONG;
  493.         if (!strcmp (name, "long unsigned int"))
  494.           return T_ULONG;
  495.       }
  496.  
  497.     if (size == CHAR_TYPE_SIZE)
  498.       return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
  499.     if (size == SHORT_TYPE_SIZE)
  500.       return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
  501.     if (size == INT_TYPE_SIZE)
  502.       return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
  503.     if (size == LONG_TYPE_SIZE)
  504.       return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
  505.     return 0;
  506.       }
  507.  
  508.     case REAL_TYPE:
  509.       {
  510.     int size = int_size_in_bytes (type) * BITS_PER_UNIT;
  511.     if (size == FLOAT_TYPE_SIZE)
  512.       return T_FLOAT;
  513.     if (size == DOUBLE_TYPE_SIZE)
  514.       return T_DOUBLE;
  515.     return 0;
  516.       }
  517.  
  518.     case ARRAY_TYPE:
  519.       {
  520.     int m;
  521.     m = plain_type_1 (TREE_TYPE (type));
  522.     if (sdb_n_dims < SDB_MAX_DIM)
  523.       sdb_dims[sdb_n_dims++]
  524.         = (TYPE_DOMAIN (type)
  525.            ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
  526.            : 0);
  527.     return PUSH_DERIVED_LEVEL (DT_ARY, m);
  528.       }
  529.  
  530.     case RECORD_TYPE:
  531.     case UNION_TYPE:
  532.     case QUAL_UNION_TYPE:
  533.     case ENUMERAL_TYPE:
  534.       {
  535.     char *tag;
  536. #ifdef SDB_ALLOW_FORWARD_REFERENCES
  537.     sdbout_record_type_name (type);
  538. #endif
  539. #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
  540.     if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
  541. #ifdef SDB_ALLOW_FORWARD_REFERENCES
  542.         || TYPE_MODE (type) != VOIDmode
  543. #endif
  544.         )
  545. #endif
  546.       {
  547.         /* Output the referenced structure tag name
  548.            only if the .def has already been finished.
  549.            At least on 386, the Unix assembler
  550.            cannot handle forward references to tags.  */
  551.         /* But the 88100, it requires them, sigh... */
  552.         /* And the MIPS requires unknown refs as well... */
  553.         tag = KNOWN_TYPE_TAG (type);
  554.         PUT_SDB_TAG (tag);
  555.         /* These 3 lines used to follow the close brace.
  556.            However, a size of 0 without a tag implies a tag of 0,
  557.            so if we don't know a tag, we can't mention the size.  */
  558.         sdb_type_size = int_size_in_bytes (type);
  559.         if (sdb_type_size < 0)
  560.           sdb_type_size = 0;
  561.       }
  562.     return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
  563.         : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
  564.         : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
  565.         : T_ENUM);
  566.       }
  567.     case POINTER_TYPE:
  568.     case REFERENCE_TYPE:
  569.       {
  570.     int m = plain_type_1 (TREE_TYPE (type));
  571.     return PUSH_DERIVED_LEVEL (DT_PTR, m);
  572.       }
  573.     case FUNCTION_TYPE:
  574.     case METHOD_TYPE:
  575.       {
  576.     int m = plain_type_1 (TREE_TYPE (type));
  577.     return PUSH_DERIVED_LEVEL (DT_FCN, m);
  578.       }
  579.     default:
  580.       return 0;
  581.     }
  582. }
  583.  
  584. /* Output the symbols defined in block number DO_BLOCK.
  585.    Set NEXT_BLOCK_NUMBER to 0 before calling.
  586.  
  587.    This function works by walking the tree structure of blocks,
  588.    counting blocks until it finds the desired block.  */
  589.  
  590. static int do_block = 0;
  591.  
  592. static int next_block_number;
  593.  
  594. static void
  595. sdbout_block (block)
  596.      register tree block;
  597. {
  598.   while (block)
  599.     {
  600.       /* Ignore blocks never expanded or otherwise marked as real.  */
  601.       if (TREE_USED (block))
  602.     {
  603.       /* When we reach the specified block, output its symbols.  */
  604.       if (next_block_number == do_block)
  605.         {
  606.           sdbout_syms (BLOCK_VARS (block));
  607.         }
  608.  
  609.       /* If we are past the specified block, stop the scan.  */
  610.       if (next_block_number > do_block)
  611.         return;
  612.  
  613.       next_block_number++;
  614.  
  615.       /* Scan the blocks within this block.  */
  616.       sdbout_block (BLOCK_SUBBLOCKS (block));
  617.     }
  618.  
  619.       block = BLOCK_CHAIN (block);
  620.     }
  621. }
  622.  
  623. /* Call sdbout_symbol on each decl in the chain SYMS.  */
  624.  
  625. static void
  626. sdbout_syms (syms)
  627.      tree syms;
  628. {
  629.   while (syms)
  630.     {
  631.       if (TREE_CODE (syms) != LABEL_DECL)
  632.     sdbout_symbol (syms, 1);
  633.       syms = TREE_CHAIN (syms);
  634.     }
  635. }
  636.  
  637. /* Output SDB information for a symbol described by DECL.
  638.    LOCAL is nonzero if the symbol is not file-scope.  */
  639.  
  640. void
  641. sdbout_symbol (decl, local)
  642.      tree decl;
  643.      int local;
  644. {
  645.   tree type = TREE_TYPE (decl);
  646.   tree context = NULL_TREE;
  647.   rtx value;
  648.   int regno = -1;
  649.   char *name;
  650.  
  651.   sdbout_one_type (type);
  652.  
  653. #if 0 /* This loses when functions are marked to be ignored,
  654.      which happens in the C++ front end.  */
  655.   if (DECL_IGNORED_P (decl))
  656.     return;
  657. #endif
  658.  
  659.   switch (TREE_CODE (decl))
  660.     {
  661.     case CONST_DECL:
  662.       /* Enum values are defined by defining the enum type.  */
  663.       return;
  664.  
  665.     case FUNCTION_DECL:
  666.       /* Don't mention a nested function under its parent.  */
  667.       context = decl_function_context (decl);
  668.       if (context == current_function_decl)
  669.     return;
  670.       if (DECL_EXTERNAL (decl))
  671.     return;
  672.       if (GET_CODE (DECL_RTL (decl)) != MEM
  673.       || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  674.     return;
  675.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
  676.       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  677.       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
  678.       break;
  679.  
  680.     case TYPE_DECL:
  681.       /* Done with tagged types.  */
  682.       if (DECL_NAME (decl) == 0)
  683.     return;
  684.       if (DECL_IGNORED_P (decl))
  685.     return;
  686.  
  687.       /* Output typedef name.  */
  688.       if (template_name_p (DECL_NAME (decl)))
  689.     PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
  690.       else
  691.     PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  692.       PUT_SDB_SCL (C_TPDEF);
  693.       break;
  694.  
  695.     case PARM_DECL:
  696.       /* Parm decls go in their own separate chains
  697.      and are output by sdbout_reg_parms and sdbout_parms.  */
  698.       abort ();
  699.  
  700.     case VAR_DECL:
  701.       /* Don't mention a variable that is external.
  702.      Let the file that defines it describe it.  */
  703.       if (DECL_EXTERNAL (decl))
  704.     return;
  705.  
  706.       /* Ignore __FUNCTION__, etc.  */
  707.       if (DECL_IGNORED_P (decl))
  708.     return;
  709.  
  710.       /* If there was an error in the declaration, don't dump core
  711.      if there is no RTL associated with the variable doesn't
  712.      exist.  */
  713.       if (DECL_RTL (decl) == 0)
  714.     return;
  715.  
  716.       DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
  717. #ifdef LEAF_REG_REMAP
  718.       if (leaf_function)
  719.     leaf_renumber_regs_insn (DECL_RTL (decl));
  720. #endif
  721.       value = DECL_RTL (decl);
  722.  
  723.       /* Don't mention a variable at all
  724.      if it was completely optimized into nothingness.
  725.  
  726.      If DECL was from an inline function, then its rtl
  727.      is not identically the rtl that was used in this
  728.      particular compilation.  */
  729.       if (GET_CODE (value) == REG)
  730.     {
  731.       regno = REGNO (DECL_RTL (decl));
  732.       if (regno >= FIRST_PSEUDO_REGISTER)
  733.         return;
  734.     }
  735.       else if (GET_CODE (value) == SUBREG)
  736.     {
  737.       int offset = 0;
  738.       while (GET_CODE (value) == SUBREG)
  739.         {
  740.           offset += SUBREG_WORD (value);
  741.           value = SUBREG_REG (value);
  742.         }
  743.       if (GET_CODE (value) == REG)
  744.         {
  745.           regno = REGNO (value);
  746.           if (regno >= FIRST_PSEUDO_REGISTER)
  747.         return;
  748.           regno += offset;
  749.         }
  750.       alter_subreg (DECL_RTL (decl));
  751.       value = DECL_RTL (decl);
  752.     }
  753.       /* Don't output anything if an auto variable
  754.      gets RTL that is static.
  755.      GAS version 2.2 can't handle such output.  */
  756.       else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
  757.            && ! TREE_STATIC (decl))
  758.     return;
  759.  
  760.       /* Emit any structure, union, or enum type that has not been output.
  761.      This occurs for tag-less structs (et al) used to declare variables
  762.      within functions.  */
  763.       if (TREE_CODE (type) == ENUMERAL_TYPE
  764.       || TREE_CODE (type) == RECORD_TYPE
  765.       || TREE_CODE (type) == UNION_TYPE
  766.       || TREE_CODE (type) == QUAL_UNION_TYPE)
  767.     {
  768.       if (TYPE_SIZE (type) != 0        /* not a forward reference */
  769.           && KNOWN_TYPE_TAG (type) == 0)    /* not yet declared */
  770.         sdbout_one_type (type);
  771.     }
  772.  
  773.       /* Defer SDB information for top-level initialized variables! */
  774.       if (! local
  775.       && GET_CODE (value) == MEM
  776.       && DECL_INITIAL (decl))
  777.     return;
  778.  
  779.       /* C++ in 2.3 makes nameless symbols.  That will be fixed later.
  780.      For now, avoid crashing.  */
  781.       if (DECL_NAME (decl) == NULL_TREE)
  782.     return;
  783.  
  784.       /* Record the name for, starting a symtab entry.  */
  785.       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
  786.  
  787.       if (GET_CODE (value) == MEM
  788.       && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
  789.     {
  790.       PUT_SDB_DEF (name);
  791.       if (TREE_PUBLIC (decl))
  792.         {
  793.           PUT_SDB_VAL (XEXP (value, 0));
  794.               PUT_SDB_SCL (C_EXT);
  795.         }
  796.       else
  797.         {
  798.           PUT_SDB_VAL (XEXP (value, 0));
  799.               PUT_SDB_SCL (C_STAT);
  800.         }
  801.     }
  802.       else if (regno >= 0)
  803.     {
  804.       PUT_SDB_DEF (name);
  805.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
  806.       PUT_SDB_SCL (C_REG);
  807.     }
  808.       else if (GET_CODE (value) == MEM
  809.            && (GET_CODE (XEXP (value, 0)) == MEM
  810.            || (GET_CODE (XEXP (value, 0)) == REG
  811.                && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
  812.                && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
  813.     /* If the value is indirect by memory or by a register
  814.        that isn't the frame pointer
  815.        then it means the object is variable-sized and address through
  816.        that register or stack slot.  COFF has no way to represent this
  817.        so all we can do is output the variable as a pointer.  */
  818.     {
  819.       PUT_SDB_DEF (name);
  820.       if (GET_CODE (XEXP (value, 0)) == REG)
  821.         {
  822.           PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
  823.           PUT_SDB_SCL (C_REG);
  824.         }
  825.       else
  826.         {
  827.           /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
  828.          (CONST_INT...)))).
  829.          We want the value of that CONST_INT.  */
  830.           /* Encore compiler hates a newline in a macro arg, it seems.  */
  831.           PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
  832.                    (XEXP (XEXP (value, 0), 0)));
  833.           PUT_SDB_SCL (C_AUTO);
  834.         }
  835.  
  836.       type = build_pointer_type (TREE_TYPE (decl));
  837.     }
  838.       else if (GET_CODE (value) == MEM
  839.            && ((GET_CODE (XEXP (value, 0)) == PLUS
  840.             && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
  841.             && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
  842.            /* This is for variables which are at offset zero from
  843.               the frame pointer.  This happens on the Alpha.
  844.               Non-frame pointer registers are excluded above.  */
  845.            || (GET_CODE (XEXP (value, 0)) == REG)))
  846.     {
  847.       /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
  848.          or (MEM (REG...)).  We want the value of that CONST_INT
  849.          or zero.  */
  850.       PUT_SDB_DEF (name);
  851.       PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
  852.       PUT_SDB_SCL (C_AUTO);
  853.     }
  854.       else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
  855.     {
  856.       /* Handle an obscure case which can arise when optimizing and
  857.          when there are few available registers.  (This is *always*
  858.          the case for i386/i486 targets).  The DECL_RTL looks like
  859.          (MEM (CONST ...)) even though this variable is a local `auto'
  860.          or a local `register' variable.  In effect, what has happened
  861.          is that the reload pass has seen that all assignments and
  862.          references for one such a local variable can be replaced by
  863.          equivalent assignments and references to some static storage
  864.          variable, thereby avoiding the need for a register.  In such
  865.          cases we're forced to lie to debuggers and tell them that
  866.          this variable was itself `static'.  */
  867.       PUT_SDB_DEF (name);
  868.       PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
  869.       PUT_SDB_SCL (C_STAT);
  870.     }
  871.       else
  872.     {
  873.       /* It is something we don't know how to represent for SDB.  */
  874.       return;
  875.     }
  876.       break;
  877.     }
  878.   PUT_SDB_TYPE (plain_type (type));
  879.   PUT_SDB_ENDEF;
  880. }
  881.  
  882. /* Output SDB information for a top-level initialized variable
  883.    that has been delayed.  */
  884.  
  885. void
  886. sdbout_toplevel_data (decl)
  887.      tree decl;
  888. {
  889.   tree type = TREE_TYPE (decl);
  890.  
  891.   if (DECL_IGNORED_P (decl))
  892.     return;
  893.  
  894.   if (! (TREE_CODE (decl) == VAR_DECL
  895.      && GET_CODE (DECL_RTL (decl)) == MEM
  896.      && DECL_INITIAL (decl)))
  897.     abort ();
  898.  
  899.   PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
  900.   PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  901.   if (TREE_PUBLIC (decl))
  902.     {
  903.       PUT_SDB_SCL (C_EXT);
  904.     }
  905.   else
  906.     {
  907.       PUT_SDB_SCL (C_STAT);
  908.     }
  909.   PUT_SDB_TYPE (plain_type (type));
  910.   PUT_SDB_ENDEF;
  911. }
  912.  
  913. #ifdef SDB_ALLOW_FORWARD_REFERENCES
  914.  
  915. /* Machinery to record and output anonymous types. */
  916.  
  917. static tree anonymous_types;
  918.  
  919. static void
  920. sdbout_queue_anonymous_type (type)
  921.      tree type;
  922. {
  923.   anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
  924. }
  925.  
  926. static void
  927. sdbout_dequeue_anonymous_types ()
  928. {
  929.   register tree types, link;
  930.  
  931.   while (anonymous_types)
  932.     {
  933.       types = nreverse (anonymous_types);
  934.       anonymous_types = NULL_TREE;
  935.  
  936.       for (link = types; link; link = TREE_CHAIN (link))
  937.     {
  938.       register tree type = TREE_VALUE (link);
  939.  
  940.       if (type && ! TREE_ASM_WRITTEN (type))
  941.         sdbout_one_type (type);
  942.     }
  943.     }
  944. }
  945.  
  946. #endif
  947.  
  948. /* Given a chain of ..._TYPE nodes, all of which have names,
  949.    output definitions of those names, as typedefs.  */
  950.  
  951. void
  952. sdbout_types (types)
  953.      register tree types;
  954. {
  955.   register tree link;
  956.  
  957.   for (link = types; link; link = TREE_CHAIN (link))
  958.     sdbout_one_type (link);
  959.  
  960. #ifdef SDB_ALLOW_FORWARD_REFERENCES
  961.   sdbout_dequeue_anonymous_types ();
  962. #endif
  963. }
  964.  
  965. static void
  966. sdbout_type (type)
  967.      tree type;
  968. {
  969.   if (type == error_mark_node)
  970.     type = integer_type_node;
  971.   PUT_SDB_TYPE (plain_type (type));
  972. }
  973.  
  974. /* Output types of the fields of type TYPE, if they are structs.
  975.  
  976.    Formerly did not chase through pointer types, since that could be circular.
  977.    They must come before TYPE, since forward refs are not allowed.
  978.    Now james@bigtex.cactus.org says to try them.  */
  979.  
  980. static void
  981. sdbout_field_types (type)
  982.      tree type;
  983. {
  984.   tree tail;
  985.   for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
  986.     if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
  987.       sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
  988.     else
  989.       sdbout_one_type (TREE_TYPE (tail));
  990. }
  991.  
  992. /* Use this to put out the top level defined record and union types
  993.    for later reference.  If this is a struct with a name, then put that
  994.    name out.  Other unnamed structs will have .xxfake labels generated so
  995.    that they may be referred to later.
  996.    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
  997.    It may NOT be called recursively.  */
  998.  
  999. static void
  1000. sdbout_one_type (type)
  1001.      tree type;
  1002. {
  1003.   text_section ();
  1004.  
  1005.   switch (TREE_CODE (type))
  1006.     {
  1007.     case RECORD_TYPE:
  1008.     case UNION_TYPE:
  1009.     case QUAL_UNION_TYPE:
  1010.     case ENUMERAL_TYPE:
  1011.       type = TYPE_MAIN_VARIANT (type);
  1012.       /* Don't output a type twice.  */
  1013.       if (TREE_ASM_WRITTEN (type))
  1014.     /* James said test TREE_ASM_BEING_WRITTEN here.  */
  1015.     return;
  1016.  
  1017.       /* Output nothing if type is not yet defined.  */
  1018.       if (TYPE_SIZE (type) == 0)
  1019.     return;
  1020.  
  1021.       TREE_ASM_WRITTEN (type) = 1;
  1022. #if 1
  1023.       /* This is reputed to cause trouble with the following case,
  1024.      but perhaps checking TYPE_SIZE above will fix it.  */
  1025.  
  1026.       /* Here is a test case:
  1027.  
  1028.     struct foo {
  1029.       struct badstr *bbb;
  1030.     } forwardref;
  1031.  
  1032.     typedef struct intermediate {
  1033.       int aaaa;
  1034.     } intermediate_ref;
  1035.  
  1036.     typedef struct badstr {
  1037.       int ccccc;
  1038.     } badtype;   */
  1039.  
  1040. #if 0
  1041.       TREE_ASM_BEING_WRITTEN (type) = 1;
  1042. #endif
  1043.       /* This change, which ought to make better output,
  1044.      used to make the COFF assembler unhappy.
  1045.      Changes involving KNOWN_TYPE_TAG may fix the problem.  */
  1046.       /* Before really doing anything, output types we want to refer to.  */
  1047.       /* Note that in version 1 the following two lines
  1048.      are not used if forward references are in use.  */
  1049.       if (TREE_CODE (type) != ENUMERAL_TYPE)
  1050.     sdbout_field_types (type);
  1051. #if 0
  1052.       TREE_ASM_WRITTEN (type) = 1;
  1053. #endif
  1054. #endif
  1055.  
  1056.       /* Output a structure type.  */
  1057.       {
  1058.     int size = int_size_in_bytes (type);
  1059.     int member_scl;
  1060.     tree tem;
  1061.     int i, n_baseclasses = 0;
  1062.  
  1063.     /* Record the type tag, but not in its permanent place just yet.  */
  1064.     sdbout_record_type_name (type);
  1065.  
  1066.     PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
  1067.  
  1068.     switch (TREE_CODE (type))
  1069.       {
  1070.       case UNION_TYPE:
  1071.       case QUAL_UNION_TYPE:
  1072.         PUT_SDB_SCL (C_UNTAG);
  1073.         PUT_SDB_TYPE (T_UNION);
  1074.         member_scl = C_MOU;
  1075.         break;
  1076.  
  1077.       case RECORD_TYPE:
  1078.         PUT_SDB_SCL (C_STRTAG);
  1079.         PUT_SDB_TYPE (T_STRUCT);
  1080.         member_scl = C_MOS;
  1081.         break;
  1082.  
  1083.       case ENUMERAL_TYPE:
  1084.         PUT_SDB_SCL (C_ENTAG);
  1085.         PUT_SDB_TYPE (T_ENUM);
  1086.         member_scl = C_MOE;
  1087.         break;
  1088.       }
  1089.  
  1090.     PUT_SDB_SIZE (size);
  1091.     PUT_SDB_ENDEF;
  1092.  
  1093.     /* Print out the base class information with fields
  1094.        named after the types they hold.  */
  1095.     if (TYPE_BINFO (type)
  1096.         && TYPE_BINFO_BASETYPES (type))
  1097.       n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
  1098.     for (i = 0; i < n_baseclasses; i++)
  1099.       {
  1100.         tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
  1101.         tree child_type = BINFO_TYPE (child);
  1102.         tree child_type_name;
  1103.         if (TYPE_NAME (child_type) == 0)
  1104.           continue;
  1105.         if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
  1106.           child_type_name = TYPE_NAME (child_type);
  1107.         else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
  1108.           {
  1109.         child_type_name = DECL_NAME (TYPE_NAME (child_type));
  1110.         if (child_type_name && template_name_p (child_type_name))
  1111.           child_type_name
  1112.             = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
  1113.           }
  1114.         else
  1115.           continue;
  1116.  
  1117.         CONTIN;
  1118.         PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
  1119.         PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
  1120.         PUT_SDB_SCL (member_scl);
  1121.         sdbout_type (BINFO_TYPE (child));
  1122.         PUT_SDB_ENDEF;
  1123.       }
  1124.  
  1125.     /* output the individual fields */
  1126.  
  1127.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  1128.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  1129.         {
  1130.           PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
  1131.           PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
  1132.           PUT_SDB_SCL (C_MOE);
  1133.           PUT_SDB_TYPE (T_MOE);
  1134.           PUT_SDB_ENDEF;
  1135.         }
  1136.  
  1137.     else            /* record or union type */
  1138.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  1139.         /* Output the name, type, position (in bits), size (in bits)
  1140.            of each field.  */
  1141.  
  1142.         /* Omit here the nameless fields that are used to skip bits.
  1143.            Also omit fields with variable size or position.
  1144.            Also omit non FIELD_DECL nodes that GNU C++ may put here.  */
  1145.         if (TREE_CODE (tem) == FIELD_DECL
  1146.         && DECL_NAME (tem) != 0
  1147.         && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
  1148.         && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
  1149.           {
  1150.         char *name;
  1151.  
  1152.         CONTIN;
  1153.         name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
  1154.         PUT_SDB_DEF (name);
  1155.         if (DECL_BIT_FIELD_TYPE (tem))
  1156.           {
  1157.             PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
  1158.             PUT_SDB_SCL (C_FIELD);
  1159.             sdbout_type (DECL_BIT_FIELD_TYPE (tem));
  1160.             PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
  1161.           }
  1162.         else
  1163.           {
  1164.             PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
  1165.                      / BITS_PER_UNIT);
  1166.             PUT_SDB_SCL (member_scl);
  1167.             sdbout_type (TREE_TYPE (tem));
  1168.           }
  1169.         PUT_SDB_ENDEF;
  1170.           }
  1171.     /* output end of a structure,union, or enumeral definition */
  1172.  
  1173.     PUT_SDB_PLAIN_DEF ("eos");
  1174.     PUT_SDB_INT_VAL (size);
  1175.     PUT_SDB_SCL (C_EOS);
  1176.     PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
  1177.     PUT_SDB_SIZE (size);
  1178.     PUT_SDB_ENDEF;
  1179.     break;
  1180.       }
  1181.     }
  1182. }
  1183.  
  1184. /* The following two functions output definitions of function parameters.
  1185.    Each parameter gets a definition locating it in the parameter list.
  1186.    Each parameter that is a register variable gets a second definition
  1187.    locating it in the register.
  1188.  
  1189.    Printing or argument lists in gdb uses the definitions that
  1190.    locate in the parameter list.  But reference to the variable in
  1191.    expressions uses preferentially the definition as a register.  */
  1192.  
  1193. /* Output definitions, referring to storage in the parmlist,
  1194.    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
  1195.  
  1196. static void
  1197. sdbout_parms (parms)
  1198.      tree parms;
  1199. {
  1200.   for (; parms; parms = TREE_CHAIN (parms))
  1201.     if (DECL_NAME (parms))
  1202.       {
  1203.     int current_sym_value = 0;
  1204.     char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
  1205.  
  1206.     if (name == 0 || *name == 0)
  1207.       name = gen_fake_label ();
  1208.  
  1209.     /* Perform any necessary register eliminations on the parameter's rtl,
  1210.        so that the debugging output will be accurate.  */
  1211.     DECL_INCOMING_RTL (parms) =
  1212.       eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
  1213.     DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
  1214.  
  1215.     if (PARM_PASSED_IN_MEMORY (parms))
  1216.       {
  1217.         rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
  1218.         tree type;
  1219.  
  1220.         /* ??? Here we assume that the parm address is indexed
  1221.            off the frame pointer or arg pointer.
  1222.            If that is not true, we produce meaningless results,
  1223.            but do not crash.  */
  1224.         if (GET_CODE (addr) == PLUS
  1225.         && GET_CODE (XEXP (addr, 1)) == CONST_INT)
  1226.           current_sym_value = INTVAL (XEXP (addr, 1));
  1227.         else
  1228.           current_sym_value = 0;
  1229.  
  1230.         if (GET_CODE (DECL_RTL (parms)) == REG
  1231.         && REGNO (DECL_RTL (parms)) >= 0
  1232.         && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  1233.           type = DECL_ARG_TYPE (parms);
  1234.         else
  1235.           {
  1236.         int original_sym_value = current_sym_value;
  1237.  
  1238.         /* This is the case where the parm is passed as an int or
  1239.            double and it is converted to a char, short or float
  1240.            and stored back in the parmlist.  In this case, describe
  1241.            the parm with the variable's declared type, and adjust
  1242.            the address if the least significant bytes (which we are
  1243.            using) are not the first ones.  */
  1244. #if BYTES_BIG_ENDIAN
  1245.         if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  1246.           current_sym_value +=
  1247.             (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  1248.              - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  1249. #endif
  1250.         if (GET_CODE (DECL_RTL (parms)) == MEM
  1251.             && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  1252.             && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
  1253.             == CONST_INT)
  1254.             && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
  1255.             == current_sym_value))
  1256.           type = TREE_TYPE (parms);
  1257.         else
  1258.           {
  1259.             current_sym_value = original_sym_value;
  1260.             type = DECL_ARG_TYPE (parms);
  1261.           }
  1262.           }
  1263.  
  1264.         PUT_SDB_DEF (name);
  1265.         PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
  1266.         PUT_SDB_SCL (C_ARG);
  1267.         PUT_SDB_TYPE (plain_type (type));
  1268.         PUT_SDB_ENDEF;
  1269.       }
  1270.     else if (GET_CODE (DECL_RTL (parms)) == REG)
  1271.       {
  1272.         rtx best_rtl;
  1273.         /* Parm passed in registers and lives in registers or nowhere.  */
  1274.  
  1275.         /* If parm lives in a register, use that register;
  1276.            pretend the parm was passed there.  It would be more consistent
  1277.            to describe the register where the parm was passed,
  1278.            but in practice that register usually holds something else.  */
  1279.         if (REGNO (DECL_RTL (parms)) >= 0
  1280.         && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  1281.           best_rtl = DECL_RTL (parms);
  1282.         /* If the parm lives nowhere,
  1283.            use the register where it was passed.  */
  1284.         else
  1285.           best_rtl = DECL_INCOMING_RTL (parms);
  1286.  
  1287.         PUT_SDB_DEF (name);
  1288.         PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
  1289.         PUT_SDB_SCL (C_REGPARM);
  1290.         PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
  1291.         PUT_SDB_ENDEF;
  1292.       }
  1293.     else if (GET_CODE (DECL_RTL (parms)) == MEM
  1294.          && XEXP (DECL_RTL (parms), 0) != const0_rtx)
  1295.       {
  1296.         /* Parm was passed in registers but lives on the stack.  */
  1297.  
  1298.         /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
  1299.            in which case we want the value of that CONST_INT,
  1300.            or (MEM (REG ...)) or (MEM (MEM ...)),
  1301.            in which case we use a value of zero.  */
  1302.         if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
  1303.         || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
  1304.           current_sym_value = 0;
  1305.         else
  1306.           current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
  1307.  
  1308.         /* Again, this assumes the offset is based on the arg pointer.  */
  1309.         PUT_SDB_DEF (name);
  1310.         PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
  1311.                           XEXP (DECL_RTL (parms), 0)));
  1312.         PUT_SDB_SCL (C_ARG);
  1313.         PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
  1314.         PUT_SDB_ENDEF;
  1315.       }
  1316.       }
  1317. }
  1318.  
  1319. /* Output definitions for the places where parms live during the function,
  1320.    when different from where they were passed, when the parms were passed
  1321.    in memory.
  1322.  
  1323.    It is not useful to do this for parms passed in registers
  1324.    that live during the function in different registers, because it is
  1325.    impossible to look in the passed register for the passed value,
  1326.    so we use the within-the-function register to begin with.
  1327.  
  1328.    PARMS is a chain of PARM_DECL nodes.  */
  1329.  
  1330. static void
  1331. sdbout_reg_parms (parms)
  1332.      tree parms;
  1333. {
  1334.   for (; parms; parms = TREE_CHAIN (parms))
  1335.     if (DECL_NAME (parms))
  1336.       {
  1337.     char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
  1338.  
  1339.     /* Report parms that live in registers during the function
  1340.        but were passed in memory.  */
  1341.     if (GET_CODE (DECL_RTL (parms)) == REG
  1342.         && REGNO (DECL_RTL (parms)) >= 0
  1343.         && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
  1344.         && PARM_PASSED_IN_MEMORY (parms))
  1345.       {
  1346.         if (name == 0 || *name == 0)
  1347.           name = gen_fake_label ();
  1348.         PUT_SDB_DEF (name);
  1349.         PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
  1350.         PUT_SDB_SCL (C_REG);
  1351.         PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
  1352.         PUT_SDB_ENDEF;
  1353.       }
  1354.     /* Report parms that live in memory but not where they were passed.  */
  1355.     else if (GET_CODE (DECL_RTL (parms)) == MEM
  1356.          && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  1357.          && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
  1358.          && PARM_PASSED_IN_MEMORY (parms)
  1359.          && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
  1360.       {
  1361. #if 0 /* ??? It is not clear yet what should replace this.  */
  1362.         int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
  1363.         /* A parm declared char is really passed as an int,
  1364.            so it occupies the least significant bytes.
  1365.            On a big-endian machine those are not the low-numbered ones.  */
  1366. #if BYTES_BIG_ENDIAN
  1367.         if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  1368.           offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  1369.              - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  1370. #endif
  1371.         if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
  1372. #endif
  1373.           {
  1374.         if (name == 0 || *name == 0)
  1375.           name = gen_fake_label ();
  1376.         PUT_SDB_DEF (name);
  1377.         PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
  1378.                  (XEXP (DECL_RTL (parms), 0)));
  1379.         PUT_SDB_SCL (C_AUTO);
  1380.         PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
  1381.         PUT_SDB_ENDEF;
  1382.           }
  1383.       }
  1384.       }
  1385. }
  1386.  
  1387. /* Describe the beginning of an internal block within a function.
  1388.    Also output descriptions of variables defined in this block.
  1389.  
  1390.    N is the number of the block, by order of beginning, counting from 1,
  1391.    and not counting the outermost (function top-level) block.
  1392.    The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
  1393.    if the count starts at 0 for the outermost one.  */
  1394.  
  1395. void
  1396. sdbout_begin_block (file, line, n)
  1397.      FILE *file;
  1398.      int line;
  1399.      int n;
  1400. {
  1401.   tree decl = current_function_decl;
  1402.   MAKE_LINE_SAFE (line);
  1403.  
  1404.   /* The SCO compiler does not emit a separate block for the function level
  1405.      scope, so we avoid it here also.  However, mips ECOFF compilers do emit
  1406.      a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
  1407. #ifndef MIPS_DEBUGGING_INFO
  1408.   if (n != 1)
  1409. #endif
  1410.     PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
  1411.  
  1412.   if (n == 1)
  1413.     {
  1414.       /* Include the outermost BLOCK's variables in block 1.  */
  1415.       next_block_number = 0;
  1416.       do_block = 0;
  1417.       sdbout_block (DECL_INITIAL (decl));
  1418.     }
  1419.   /* If -g1, suppress all the internal symbols of functions
  1420.      except for arguments.  */
  1421.   if (debug_info_level != DINFO_LEVEL_TERSE)
  1422.     {
  1423.       next_block_number = 0;
  1424.       do_block = n;
  1425.       sdbout_block (DECL_INITIAL (decl));
  1426.     }
  1427.  
  1428. #ifdef SDB_ALLOW_FORWARD_REFERENCES
  1429.   sdbout_dequeue_anonymous_types ();
  1430. #endif
  1431. }
  1432.  
  1433. /* Describe the end line-number of an internal block within a function.  */
  1434.  
  1435. void
  1436. sdbout_end_block (file, line, n)
  1437.      FILE *file;
  1438.      int line;
  1439.      int n;
  1440. {
  1441.   MAKE_LINE_SAFE (line);
  1442.  
  1443.   /* The SCO compiler does not emit a separate block for the function level
  1444.      scope, so we avoid it here also.  However, mips ECOFF compilers do emit
  1445.      a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
  1446. #ifndef MIPS_DEBUGGING_INFO
  1447.   if (n != 1)
  1448. #endif
  1449.   PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
  1450. }
  1451.  
  1452. /* Output sdb info for the current function name.
  1453.    Called from assemble_start_function.  */
  1454.  
  1455. void
  1456. sdbout_mark_begin_function ()
  1457. {
  1458.   sdbout_symbol (current_function_decl, 0);
  1459. }
  1460.  
  1461. /* Called at beginning of function body (after prologue).
  1462.    Record the function's starting line number, so we can output
  1463.    relative line numbers for the other lines.
  1464.    Describe beginning of outermost block.
  1465.    Also describe the parameter list.  */
  1466.  
  1467. void
  1468. sdbout_begin_function (line)
  1469.      int line;
  1470. {
  1471.   sdb_begin_function_line = line - 1;
  1472.   PUT_SDB_FUNCTION_START (line);
  1473.   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
  1474.   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
  1475. }
  1476.  
  1477. /* Called at end of function (before epilogue).
  1478.    Describe end of outermost block.  */
  1479.  
  1480. void
  1481. sdbout_end_function (line)
  1482.      int line;
  1483. {
  1484. #ifdef SDB_ALLOW_FORWARD_REFERENCES
  1485.   sdbout_dequeue_anonymous_types ();
  1486. #endif
  1487.  
  1488.   MAKE_LINE_SAFE (line);
  1489.   PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
  1490.  
  1491.   /* Indicate we are between functions, for line-number output.  */
  1492.   sdb_begin_function_line = -1;
  1493. }
  1494.  
  1495. /* Output sdb info for the absolute end of a function.
  1496.    Called after the epilogue is output.  */
  1497.  
  1498. void
  1499. sdbout_end_epilogue ()
  1500. {
  1501.   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
  1502.   PUT_SDB_EPILOGUE_END (name);
  1503. }
  1504.  
  1505. /* Output sdb info for the given label.  Called only if LABEL_NAME (insn)
  1506.    is present.  */
  1507.  
  1508. void
  1509. sdbout_label (insn)
  1510.      register rtx insn;
  1511. {
  1512.   PUT_SDB_DEF (LABEL_NAME (insn));
  1513.   PUT_SDB_VAL (insn);
  1514.   PUT_SDB_SCL (C_LABEL);
  1515.   PUT_SDB_TYPE (T_NULL);
  1516.   PUT_SDB_ENDEF;
  1517. }
  1518.  
  1519. #endif /* SDB_DEBUGGING_INFO */
  1520.