home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__src1 / dbxout.c < prev    next >
C/C++ Source or Header  |  1993-07-23  |  42KB  |  1,445 lines

  1. /* Output dbx-format symbol table information from GNU compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Output dbx-format symbol table data.
  23.    This consists of many symbol table entries, each of them
  24.    a .stabs assembler pseudo-op with four operands:
  25.    a "name" which is really a description of one symbol and its type,
  26.    a "code", which is a symbol defined in stab.h whose name starts with N_,
  27.    an unused operand always 0,
  28.    and a "value" which is an address or an offset.
  29.    The name is enclosed in doublequote characters.
  30.  
  31.    Each function, variable, typedef, and structure tag
  32.    has a symbol table entry to define it.
  33.    The beginning and end of each level of name scoping within
  34.    a function are also marked by special symbol table entries.
  35.  
  36.    The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
  37.    and a data type number.  The data type number may be followed by
  38.    "=" and a type definition; normally this will happen the first time
  39.    the type number is mentioned.  The type definition may refer to
  40.    other types by number, and those type numbers may be followed
  41.    by "=" and nested definitions.
  42.  
  43.    This can make the "name" quite long.
  44.    When a name is more than 80 characters, we split the .stabs pseudo-op
  45.    into two .stabs pseudo-ops, both sharing the same "code" and "value".
  46.    The first one is marked as continued with a double-backslash at the
  47.    end of its "name".
  48.  
  49.    The kind-of-symbol letter distinguished function names from global
  50.    variables from file-scope variables from parameters from auto
  51.    variables in memory from typedef names from register variables.
  52.    See `dbxout_symbol'.
  53.  
  54.    The "code" is mostly redundant with the kind-of-symbol letter
  55.    that goes in the "name", but not entirely: for symbols located
  56.    in static storage, the "code" says which segment the address is in,
  57.    which controls how it is relocated.
  58.  
  59.    The "value" for a symbol in static storage
  60.    is the core address of the symbol (actually, the assembler
  61.    label for the symbol).  For a symbol located in a stack slot
  62.    it is the stack offset; for one in a register, the register number.
  63.    For a typedef symbol, it is zero.
  64.  
  65.    If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
  66.    output while in the text section.
  67.  
  68.    For more on data type definitions, see `dbxout_type'.  */
  69.  
  70. #include "config.h"
  71. #include "tree.h"
  72. #include "cplus-tree.h"
  73. #include "rtl.h"
  74. #include "flags.h"
  75. #include <stdio.h>
  76.  
  77. /* Typical USG systems don't have stab.h, and they also have
  78.    no use for DBX-format debugging info.  */
  79.  
  80. #ifdef DBX_DEBUGGING_INFO
  81.  
  82. #ifdef DEBUG_SYMS_TEXT
  83. #define FORCE_TEXT text_section ();
  84. #else
  85. #define FORCE_TEXT
  86. #endif
  87.  
  88. #ifdef USG
  89. #include "stab.h"  /* If doing DBX on sysV, use our own stab.h.  */
  90. #else
  91. #include <stab.h>  /* On BSD, use the system's stab.h.  */
  92. #endif /* not USG */
  93.  
  94. /* Stream for writing to assembler file.  */
  95.  
  96. static FILE *asmfile;
  97.  
  98. enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
  99.  
  100. /* Vector recording the status of describing C data types.
  101.    When we first notice a data type (a tree node),
  102.    we assign it a number using next_type_number.
  103.    That is its index in this vector.
  104.    The vector element says whether we have yet output
  105.    the definition of the type.  TYPE_XREF says we have
  106.    output it as a cross-reference only.  */
  107.  
  108. enum typestatus *typevec;
  109.  
  110. /* Number of elements of space allocated in `typevec'.  */
  111.  
  112. static int typevec_len;
  113.  
  114. /* In dbx output, each type gets a unique number.
  115.    This is the number for the next type output.
  116.    The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
  117.  
  118. static int next_type_number;
  119.  
  120. /* In dbx output, we must assign symbol-blocks id numbers
  121.    in the order in which their beginnings are encountered.
  122.    We output debugging info that refers to the beginning and
  123.    end of the ranges of code in each block
  124.    with assembler labels LBBn and LBEn, where n is the block number.
  125.    The labels are generated in final, which assigns numbers to the
  126.    blocks in the same way.  */
  127.  
  128. static int next_block_number;
  129.  
  130. /* These variables are for dbxout_symbol to communicate to
  131.    dbxout_finish_symbol.
  132.    current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
  133.    current_sym_value and current_sym_addr are two ways to address the
  134.    value to store in the symtab entry.
  135.    current_sym_addr if nonzero represents the value as an rtx.
  136.    If that is zero, current_sym_value is used.  This is used
  137.    when the value is an offset (such as for auto variables,
  138.    register variables and parms).  */
  139.  
  140. static int current_sym_code;
  141. static int current_sym_value;
  142. static rtx current_sym_addr;
  143.  
  144. /* Number of chars of symbol-description generated so far for the
  145.    current symbol.  Used by CHARS and CONTIN.  */
  146.  
  147. static int current_sym_nchars;
  148.  
  149. /* Report having output N chars of the current symbol-description.  */
  150.  
  151. #define CHARS(N) (current_sym_nchars += (N))
  152.  
  153. /* Break the current symbol-description, generating a continuation,
  154.    if it has become long.  */
  155.  
  156. #ifndef DBX_CONTIN_LENGTH
  157. #define DBX_CONTIN_LENGTH 80
  158. #endif
  159.  
  160. #if DBX_CONTIN_LENGTH > 0
  161. #define CONTIN  \
  162.   do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
  163. #else
  164. #define CONTIN
  165. #endif
  166.  
  167. void dbxout_types ();
  168. void dbxout_tags ();
  169. void dbxout_args ();
  170. void dbxout_symbol ();
  171. static void dbxout_type_name ();
  172. static void dbxout_type ();
  173. static void dbxout_finish_symbol ();
  174. static void dbxout_continue ();
  175.  
  176. /* At the beginning of compilation, start writing the symbol table.
  177.    Initialize `typevec' and output the standard data types of C.  */
  178.  
  179. void
  180. dbxout_init (asm_file, input_file_name)
  181.      FILE *asm_file;
  182.      char *input_file_name;
  183. {
  184.   asmfile = asm_file;
  185.  
  186.   typevec_len = 100;
  187.   typevec = (enum typestatus *) xmalloc (typevec_len * sizeof typevec[0]);
  188.   bzero (typevec, typevec_len * sizeof typevec[0]);
  189.  
  190.   /* Used to put `Ltext:' before the reference, but that loses on sun 4.  */
  191.   fprintf (asmfile,
  192.        "\t.stabs \"%s\",%d,0,0,Ltext\nLtext:\n",
  193.        input_file_name, N_SO);
  194.  
  195.   next_type_number = 1;
  196.   next_block_number = 2;
  197.  
  198.   /* Make sure that types `int' and `char' have numbers 1 and 2.
  199.      Definitions of other integer types will refer to those numbers.  */
  200.  
  201.   dbxout_symbol (TYPE_NAME (integer_type_node), 0);
  202.   dbxout_symbol (TYPE_NAME (char_type_node), 0);
  203.  
  204.   /* Get all permanent types not yet gotten, and output them.  */
  205.  
  206.   dbxout_types (get_permanent_types ());
  207. }
  208.  
  209. /* Continue a symbol-description that gets too big.
  210.    End one symbol table entry with a double-backslash
  211.    and start a new one, eventually producing something like
  212.    .stabs "start......\\",code,0,value
  213.    .stabs "...rest",code,0,value   */
  214.  
  215. static void
  216. dbxout_continue ()
  217. {
  218. #ifdef DBX_CONTIN_CHAR
  219.   fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
  220. #else
  221.   fprintf (asmfile, "\\\\");
  222. #endif
  223.   dbxout_finish_symbol ();
  224.   fprintf (asmfile, ".stabs \"");
  225.   current_sym_nchars = 0;
  226. }
  227.  
  228. /* Output a reference to a type.  If the type has not yet been
  229.    described in the dbx output, output its definition now.
  230.    For a type already defined, just refer to its definition
  231.    using the type number.
  232.  
  233.    If FULL is nonzero, and the type has been described only with
  234.    a forward-reference, output the definition now.
  235.    If FULL is zero in this case, just refer to the forward-reference
  236.    using the number previously allocated.  */
  237.  
  238. static void
  239. dbxout_type (type, full)
  240.      tree type;
  241.      int full;
  242. {
  243.   register tree fields, tem;
  244.   char *vfield_name = 0;
  245.   tree virtual_basetype = 0;
  246.  
  247.   /* If there was an input error and we don't really have a type,
  248.      avoid crashing and write something that is at least valid
  249.      by assuming `int'.  */
  250.   if (type == error_mark_node)
  251.     type = integer_type_node;
  252.   else /* if (TYPE_SIZE (type) == 0) */
  253.     type = TYPE_MAIN_VARIANT (type);
  254.  
  255.   if (TYPE_SYMTAB_ADDRESS (type) == 0)
  256.     {
  257.       /* Type has no dbx number assigned.  Assign next available number.  */
  258.       TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
  259.  
  260.       /* Make sure type vector is long enough to record about this type.  */
  261.  
  262.       if (next_type_number == typevec_len)
  263.     {
  264.       typevec = (enum typestatus *) xrealloc (typevec, typevec_len * 2 * sizeof typevec[0]);
  265.       bzero (typevec + typevec_len, typevec_len * sizeof typevec[0]);
  266.       typevec_len *= 2;
  267.     }
  268.     }
  269.  
  270.   /* Output the number of this type, to refer to it.  */
  271.   fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
  272.   CHARS (3);
  273.  
  274.   /* If this type's definition has been output or is now being output,
  275.      that is all.  */
  276.  
  277.   switch (typevec[TYPE_SYMTAB_ADDRESS (type)])
  278.     {
  279.     case TYPE_UNSEEN:
  280.       break;
  281.     case TYPE_XREF:
  282.       if (! full)
  283.     return;
  284.       break;
  285.     case TYPE_DEFINED:
  286.       return;
  287.     }
  288.  
  289. #ifdef DBX_NO_XREFS
  290.   /* For systems where dbx output does not allow the `=xsNAME:' syntax,
  291.      leave the type-number completely undefined rather than output
  292.      a cross-reference.  */
  293.   if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
  294.       || TREE_CODE (type) == ENUMERAL_TYPE)
  295.  
  296.     if ((TYPE_NAME (type) != 0 && !full)
  297.     || TYPE_SIZE (type) == 0)
  298.       {
  299.     typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  300.     return;
  301.       }
  302. #endif
  303.  
  304.   /* Output a definition now.  */
  305.  
  306.   fprintf (asmfile, "=");
  307.   CHARS (1);
  308.  
  309.   /* Mark it as defined, so that if it is self-referent
  310.      we will not get into an infinite recursion of definitions.  */
  311.  
  312.   typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED;
  313.  
  314.   switch (TREE_CODE (type))
  315.     {
  316.     case VOID_TYPE:
  317.     case LANG_TYPE:
  318.       /* For a void type, just define it as itself; ie, "5=5".
  319.      This makes us consider it defined
  320.      without saying what it is.  The debugger will make it
  321.      a void type when the reference is seen, and nothing will
  322.      ever override that default.  */
  323.       fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
  324.       CHARS (3);
  325.       break;
  326.  
  327.     case INTEGER_TYPE:
  328.       if (type == char_type_node && ! TREE_UNSIGNED (type))
  329.     /* Output the type `char' as a subrange of itself!
  330.        I don't understand this definition, just copied it
  331.        from the output of pcc.  */
  332.     fprintf (asmfile, "r2;0;127;");
  333.       else
  334.     /* Output other integer types as subranges of `int'.  */
  335.     fprintf (asmfile, "r1;%d;%d;",
  336.          TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)),
  337.          TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
  338.       CHARS (25);
  339.       break;
  340.  
  341.     case REAL_TYPE:
  342.       /* This must be magic.  */
  343.       fprintf (asmfile, "r1;%d;0;",
  344.            TREE_INT_CST_LOW (size_in_bytes (type)));
  345.       CHARS (16);
  346.       break;
  347.  
  348.     case ARRAY_TYPE:
  349.       /* Output "a" followed by a range type definition
  350.      for the index type of the array
  351.      followed by a reference to the target-type.
  352.      ar1;0;N;M for an array of type M and size N.  */
  353.       fprintf (asmfile, "ar1;0;%d;",
  354.            (TYPE_DOMAIN (type)
  355.         ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
  356.             : -1));
  357.       CHARS (17);
  358.       dbxout_type (TREE_TYPE (type), 0);
  359.       break;
  360.  
  361.     case RECORD_TYPE:
  362.     case UNION_TYPE:
  363.       {
  364.     int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (type);
  365.  
  366.     /* Output a structure type.  */
  367.     if ((TYPE_NAME (type) != 0 && !full)
  368.         || TYPE_SIZE (type) == 0)
  369.       {
  370.         /* If the type is just a cross reference, output one
  371.            and mark the type as partially described.
  372.            If it later becomes defined, we will output
  373.            its real definition.
  374.            If the type has a name, don't nest its name within
  375.            another type's definition; instead, output an xref
  376.            and let the definition come when the name is defined.  */
  377.         fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
  378.         CHARS (3);
  379.         dbxout_type_name (type);
  380.         fprintf (asmfile, ":");
  381.         typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  382.         break;
  383.       }
  384.     tem = size_in_bytes (type);
  385.     fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "s%d" : "u%d",
  386.          TREE_INT_CST_LOW (tem));
  387.  
  388.     if (use_gdb_dbx_extensions)
  389.       {
  390.         if (n_baseclasses)
  391.           {
  392.         fprintf (asmfile, "!%d,", n_baseclasses);
  393.         CHARS (8);
  394.           }
  395.       }
  396.     for (i = 1; i <= n_baseclasses; i++)
  397.       {
  398.         tree basetype = CLASSTYPE_BASECLASS (type, i);
  399.         if (use_gdb_dbx_extensions)
  400.           {
  401.         putc (CLASSTYPE_VIA_VIRTUAL (type, 1) ? '1'
  402.               : '0',
  403.               asmfile);
  404.         putc (CLASSTYPE_VIA_PUBLIC (type, 1) ? '2'
  405.               : '0',
  406.               asmfile);
  407.         fprintf (asmfile, "%d,",
  408.              BITS_PER_UNIT * DECL_OFFSET (TYPE_NAME (basetype)));
  409.         CHARS (15);
  410.         dbxout_type (basetype);
  411.         putc (';', asmfile);
  412.           }
  413.         else
  414.           {
  415.         /* Print out the base class information with fields
  416.            which have the same names at the types they hold.  */
  417.         tree name = TREE_CODE (TYPE_NAME (basetype)) == TYPE_DECL
  418.           ? DECL_NAME (TYPE_NAME (basetype)) : TYPE_NAME (basetype);
  419.  
  420.         fprintf (asmfile, "%s:", IDENTIFIER_POINTER (name));
  421.         CHARS (2 + IDENTIFIER_LENGTH (name));
  422.         dbxout_type (basetype);
  423.         fprintf (asmfile, ",%d,%d;",
  424.              BITS_PER_UNIT * DECL_OFFSET (TYPE_NAME (basetype)),
  425.              TREE_INT_CST_LOW (TYPE_SIZE (basetype)) * DECL_SIZE_UNIT (basetype));
  426.         CHARS (20);
  427.           }
  428.       }
  429.       }
  430.  
  431.       CHARS (11);
  432.  
  433.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  434.     /* Output the name, type, position (in bits), size (in bits)
  435.        of each field.  */
  436.     /* Omit here local type decls until we know how to support them.  */
  437.     if (TREE_CODE (tem) == TYPE_DECL)
  438.       continue;
  439.     /* Omit here the nameless fields that are used to skip bits.  */
  440.     else if (DECL_NAME (tem) != 0
  441.         && (use_gdb_dbx_extensions || TREE_CODE (tem) != CONST_DECL))
  442.       {
  443.         /* Continue the line if necessary,
  444.            but not before the first field.  */
  445.         if (tem != TYPE_FIELDS (type))
  446.           CONTIN;
  447.         fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
  448.         CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
  449.         if (use_gdb_dbx_extensions)
  450.           {
  451.         putc ('/', asmfile);
  452. #ifdef TREE_PRIVATE
  453.         putc ((TREE_PRIVATE (tem) ? '0'
  454.               : TREE_PROTECTED (tem) ? '1' : '2'),
  455.               asmfile);
  456. #endif
  457.         CHARS (2);
  458.           }
  459.  
  460.         dbxout_type (TREE_TYPE (tem), 0);
  461.         if (TREE_CODE (tem) == VAR_DECL)
  462.           {
  463.         if (use_gdb_dbx_extensions)
  464.           {
  465.             char *name = XSTR (XEXP (DECL_RTL (tem), 0), 0);
  466.             if (name[0] == '*')
  467.               name += 1;
  468.             /* Adding 1 here only works on systems
  469.                which flush an initial underscore.  */
  470.             fprintf (asmfile, ":%s;", name+1);
  471.             CHARS (strlen (name));
  472.           }
  473.         else
  474.           {
  475.             fprintf (asmfile, ",0,0;");
  476.           }
  477.           }
  478.         else if (TREE_CODE (tem) == CONST_DECL)
  479.           {
  480.         /* Only get here if using GDB's extensions to DBX format.  */
  481.         fprintf (asmfile, "~i%d;", TREE_INT_CST_LOW (DECL_INITIAL (tem)));
  482.           }
  483.         else
  484.           {
  485.         fprintf (asmfile, ",%d,%d;", DECL_OFFSET (tem),
  486.              TREE_INT_CST_LOW (DECL_SIZE (tem)) * DECL_SIZE_UNIT (tem));
  487.           }
  488.         CHARS (23);
  489.       }
  490.       /* C++: put out the method names and their parameter lists */
  491.       /* We do constructors, destructor, if any, followed by the method names.  */
  492.       fields = use_gdb_dbx_extensions ? CLASSTYPE_FN_FIELDS (type) : NULL_TREE;
  493.       if (TREE_CODE (type) == RECORD_TYPE
  494.       && (TYPE_HAS_DESTRUCTOR (type) | TYPE_HAS_CONSTRUCTOR (type))
  495.       && use_gdb_dbx_extensions)
  496.     {
  497.       tree dtor;
  498.  
  499.       /* Destructors lie in a special place.  */
  500.       if (TYPE_HAS_DESTRUCTOR (type))
  501.         {
  502.           dtor = TREE_VALUE (fields);
  503.           tem = TREE_CHAIN (dtor);
  504.         }
  505.       else
  506.         {
  507.           dtor = NULL_TREE;
  508.           tem = TREE_VALUE (fields);
  509.         }
  510.       CHARS (2);
  511.  
  512.       if (tem)
  513.         {
  514.           if (TREE_OPERATOR (tem))
  515.         {
  516.           char *name1 = operator_name_string (DECL_NAME (tem));
  517.           fprintf (asmfile, "op$::%s.", name1);
  518.           CHARS (strlen (name1) + 7);
  519.         }
  520.           else
  521.         {
  522.           fprintf (asmfile, "%s::", IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (tem)));
  523.           CHARS (IDENTIFIER_LENGTH (DECL_ORIGINAL_NAME (tem)) + 3);
  524.         }
  525.  
  526.           while (tem)
  527.         {
  528.           /* Output the name of the field (after overloading), as
  529.              well as the name of the field before overloading, along
  530.              with its parameter list.  */
  531.           tree t;
  532.  
  533.           CONTIN;
  534.           /* Get to the FUNCTION_DECL */
  535.           t = tem;
  536.           dbxout_type (TREE_TYPE (t), 0); /* METHOD_TYPE */
  537.           fprintf (asmfile, ":%s;%c%c",
  538.                IDENTIFIER_POINTER (DECL_NAME (t)),
  539.                TREE_PRIVATE (tem) ? '0' : TREE_PROTECTED (tem) ? '1' : '2',
  540.                DECL_VIRTUAL_P (tem) ? '*' : '.');
  541.           CHARS (IDENTIFIER_LENGTH (DECL_NAME (t)) + 5);
  542.           if (DECL_VIRTUAL_P (tem))
  543.             {
  544.               fprintf (asmfile, "%d;",
  545.                    TREE_INT_CST_LOW (DECL_VINDEX (tem)));
  546.               CHARS (8);
  547.             }
  548.           if (tem == dtor)
  549.             break;
  550.           tem = TREE_CHAIN (tem);
  551.           if (tem == NULL_TREE)
  552.             tem = dtor;
  553.         }
  554.           putc (';', asmfile);
  555.         }
  556.       fields = TREE_CHAIN (fields);
  557.     }
  558.       for (; fields; fields = TREE_CHAIN (fields))
  559.     {
  560.       tem = TREE_VALUE (fields);
  561.  
  562.       if (tem)
  563.         {
  564.           if (TREE_OPERATOR (tem))
  565.         {
  566.           char *name1 = operator_name_string (DECL_NAME (tem));
  567.           fprintf (asmfile, "op$::%s.", name1);
  568.           CHARS (strlen (name1) + 6);
  569.         }
  570.           else
  571.         {
  572.           fprintf (asmfile, "%s::",
  573.                IDENTIFIER_POINTER (TREE_PURPOSE (fields)));
  574.           CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (fields)) + 3);
  575.         }
  576.  
  577.           for (; tem; tem = TREE_CHAIN (tem))
  578.         /* Output the name of the field (after overloading), as
  579.            well as the name of the field before overloading, along
  580.            with its parameter list */
  581.         {
  582.           /* @@ */
  583.           tree t;
  584.  
  585.           CONTIN;
  586.  
  587.           /* Get to the FUNCTION_DECL */
  588.           t = tem;
  589.           dbxout_type (TREE_TYPE (t), 0); /* METHOD_TYPE */
  590.           fprintf (asmfile, ":%s;%c%c",
  591.                IDENTIFIER_POINTER (DECL_NAME (t)),
  592.                TREE_PRIVATE (tem) ? '0' : TREE_PROTECTED (tem) ? '1' : '2',
  593.                DECL_VIRTUAL_P (tem) ? '*' : '.');
  594.           CHARS (IDENTIFIER_LENGTH (DECL_NAME (t)) + 6);
  595.           if (DECL_VIRTUAL_P (tem))
  596.             {
  597.               fprintf (asmfile, "%d;",
  598.                    TREE_INT_CST_LOW (DECL_VINDEX (tem)));
  599.               CHARS (8);
  600.             }
  601.         }
  602.           putc (';', asmfile);
  603.           CHARS (1);
  604.         }
  605.     }
  606.  
  607.       putc (';', asmfile);
  608.  
  609.       if (use_gdb_dbx_extensions && TREE_CODE (type) == RECORD_TYPE)
  610.     {
  611.       /* Tell GDB+ that it may keep reading.  */
  612.       putc ('~', asmfile);
  613.       if (TYPE_HAS_DESTRUCTOR (type) && TYPE_HAS_CONSTRUCTOR (type))
  614.         putc ('=', asmfile);
  615.       else if (TYPE_HAS_DESTRUCTOR (type))
  616.         putc ('-', asmfile);
  617.       else if (TYPE_HAS_CONSTRUCTOR (type))
  618.         putc ('+', asmfile);
  619.  
  620.       if (TYPE_VIRTUAL_P (type))
  621.         {
  622.           tree t, v = DECL_NAME (CLASSTYPE_VFIELD (type));
  623.           t = type;
  624.           while (CLASSTYPE_N_BASECLASSES (t) && TYPE_VIRTUAL_P (CLASSTYPE_BASECLASS (t, 1)))
  625.         t = CLASSTYPE_BASECLASS (t, 1);
  626.           putc ('%', asmfile);
  627.           dbxout_type (t, 0);
  628.           fprintf (asmfile, ",%s;", IDENTIFIER_POINTER (v));
  629.           CHARS (IDENTIFIER_LENGTH (v) + 6);
  630.         }
  631.       else
  632.         {
  633.           putc (';', asmfile);
  634.           CHARS (3);
  635.         }
  636.     }
  637.       break;
  638.  
  639.     case ENUMERAL_TYPE:
  640.       if ((TYPE_NAME (type) != 0
  641.        && !full
  642.        && ((TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  643.         && ! ANON_AGGRNAME_P (DECL_NAME (TYPE_NAME (type))))
  644.            || (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
  645.            && ! ANON_AGGRNAME_P (TYPE_NAME (type)))))
  646.       || TYPE_SIZE (type) == 0)
  647.     {
  648.       fprintf (asmfile, "xe");
  649.       CHARS (3);
  650.       dbxout_type_name (type);
  651.       typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
  652.       fprintf (asmfile, ":");
  653.       return;
  654.     }
  655.       putc ('e', asmfile);
  656.       CHARS (1);
  657.       for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
  658.     {
  659.       fprintf (asmfile, "%s:%d,", IDENTIFIER_POINTER (TREE_PURPOSE (tem)),
  660.            TREE_INT_CST_LOW (TREE_VALUE (tem)));
  661.       CHARS (11 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
  662.       if (TREE_CHAIN (tem) != 0)
  663.         CONTIN;
  664.     }
  665.       putc (';', asmfile);
  666.       CHARS (1);
  667.       break;
  668.  
  669.     case POINTER_TYPE:
  670.       putc ('*', asmfile);
  671.       CHARS (1);
  672.       dbxout_type (TREE_TYPE (type), 0);
  673.       break;
  674.  
  675.     case METHOD_TYPE:
  676.       if (use_gdb_dbx_extensions)
  677.     {
  678.       putc ('#', asmfile);
  679.       CHARS (1);
  680.       dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
  681.       putc (',', asmfile);
  682.       CHARS (1);
  683.       dbxout_type (TREE_TYPE (type), 0);
  684.       dbxout_args (TYPE_ARG_TYPES (type));
  685.       putc (';', asmfile);
  686.       CHARS (1);
  687.     }
  688.       else
  689.     {
  690.       /* Should print as an int, because it is really
  691.          just an offset.  */
  692.       dbxout_type (integer_type_node, 0);
  693.     }
  694.       break;
  695.  
  696.     case OFFSET_TYPE:
  697.       if (use_gdb_dbx_extensions)
  698.     {
  699.       putc ('@', asmfile);
  700.       CHARS (1);
  701.       dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
  702.       putc (',', asmfile);
  703.       CHARS (1);
  704.       dbxout_type (TREE_TYPE (type), 0);
  705.     }
  706.       else
  707.     {
  708.       /* Should print as an int, because it is really
  709.          just an offset.  */
  710.       dbxout_type (integer_type_node, 0);
  711.     }
  712.       break;
  713.  
  714.     case REFERENCE_TYPE:
  715.       putc (use_gdb_dbx_extensions ? '&' : '*', asmfile);
  716.       CHARS (1);
  717.       dbxout_type (TREE_TYPE (type), 0);
  718.       break;
  719.  
  720.     case FUNCTION_TYPE:
  721.       putc ('f', asmfile);
  722.       CHARS (1);
  723.       dbxout_type (TREE_TYPE (type), 0);
  724.       break;
  725.  
  726.     default:
  727.       abort ();
  728.     }
  729. }
  730.  
  731. /* Output the name of type TYPE, with no punctuation.
  732.    Such names can be set up either by typedef declarations
  733.    or by struct, enum and union tags.  */
  734.  
  735. static void
  736. dbxout_type_name (type)
  737.      register tree type;
  738. {
  739.   tree t;
  740.   if (TYPE_NAME (type) == 0)
  741.     abort ();
  742.   if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  743.     {
  744.       t = TYPE_NAME (type);
  745.     }
  746.   else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  747.     {
  748.       t = DECL_NAME (TYPE_NAME (type));
  749.     }
  750.   else
  751.     abort ();
  752.  
  753.   fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
  754.   CHARS (IDENTIFIER_LENGTH (t));
  755. }
  756.  
  757. /* Output a .stabs for the symbol defined by DECL,
  758.    which must be a ..._DECL node in the normal namespace.
  759.    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
  760.    LOCAL is nonzero if the scope is less than the entire file.  */
  761.  
  762. void
  763. dbxout_symbol (decl, local)
  764.      tree decl;
  765.      int local;
  766. {
  767.   int letter = 0;
  768.   tree type = TREE_TYPE (decl);
  769.   char *name;
  770.  
  771.   /* If global, first output all types and all
  772.      struct, enum and union tags that have been created
  773.      and not yet output.  */
  774.  
  775.   if (local == 0)
  776.     {
  777.       dbxout_tags (gettags ());
  778.       dbxout_types (get_permanent_types ());
  779.     }
  780.  
  781.   current_sym_code = 0;
  782.   current_sym_value = 0;
  783.   current_sym_addr = 0;
  784.  
  785.   /* The output will always start with the symbol name,
  786.      so count that always in the length-output-so-far.  */
  787.  
  788.   if (DECL_NAME (decl) == 0)
  789.     return;
  790.  
  791.   current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
  792.  
  793.   switch (TREE_CODE (decl))
  794.     {
  795.     case CONST_DECL:
  796.       /* Enum values are defined by defining the enum type.  */
  797.       break;
  798.  
  799.     case FUNCTION_DECL:
  800.       if (DECL_RTL (decl) == 0)
  801.     return;
  802.       if (TREE_EXTERNAL (decl))
  803.     break;
  804.       if (GET_CODE (DECL_RTL (decl)) != MEM
  805.       || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  806.     break;
  807.       FORCE_TEXT;
  808.       fprintf (asmfile, ".stabs \"%s:%c",
  809.            IDENTIFIER_POINTER (DECL_NAME (decl)),
  810.            TREE_PUBLIC (decl) ? 'F' : 'f');
  811.  
  812.       current_sym_code = N_FUN;
  813.       current_sym_addr = XEXP (DECL_RTL (decl), 0);
  814.  
  815.       if (TREE_TYPE (TREE_TYPE (decl)))
  816.     dbxout_type (TREE_TYPE (TREE_TYPE (decl)), 0);
  817.       else
  818.     dbxout_type (void_type_node, 0);
  819.       dbxout_finish_symbol ();
  820.       break;
  821.  
  822.     case TYPE_DECL:
  823. #if 0
  824.       /* This seems all wrong.  Outputting most kinds of types gives no name
  825.      at all.  A true definition gives no name; a cross-ref for a
  826.      structure can give the tag name, but not a type name.
  827.      It seems that no typedef name is defined by outputting a type.  */
  828.  
  829.       /* If this typedef name was defined by outputting the type,
  830.      don't duplicate it.  */
  831.       if (typevec[TYPE_SYMTAB_ADDRESS (type)] == TYPE_DEFINED
  832.       && TYPE_NAME (TREE_TYPE (decl)) == decl)
  833.     return;
  834. #endif
  835.       /* Don't output the same typedef twice.  */
  836.       if (TREE_ASM_WRITTEN (decl))
  837.     return;
  838.  
  839.       /* Output typedef name.  */
  840.       FORCE_TEXT;
  841.       fprintf (asmfile, ".stabs \"%s:t",
  842.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  843.  
  844.       current_sym_code = N_LSYM;
  845.  
  846.       dbxout_type (TREE_TYPE (decl), 1);
  847.       dbxout_finish_symbol ();
  848.  
  849.       /* Prevent duplicate output of a typedef.  */
  850.       TREE_ASM_WRITTEN (decl) = 1;
  851.       break;
  852.       
  853.     case PARM_DECL:
  854.       /* Parm decls go in their own separate chains
  855.      and are output by dbxout_reg_parms and dbxout_parms.  */
  856.       abort ();
  857.  
  858.     case VAR_DECL:
  859.       if (DECL_RTL (decl) == 0)
  860.     return;
  861.       /* Don't mention a variable that is external.
  862.      Let the file that defines it describe it.  */
  863.       if (TREE_EXTERNAL (decl))
  864.     break;
  865.  
  866.       /* If the variable is really a constant, inform dbx of such.  */
  867.       if (TREE_STATIC (decl) && TREE_READONLY (decl)
  868.       && DECL_INITIAL (decl) != 0
  869.       && (DECL_FIELD_CONTEXT (decl) == NULL_TREE
  870.           || TREE_CODE (DECL_FIELD_CONTEXT (decl)) == LET_STMT))
  871.     {
  872.       if (TREE_PUBLIC (decl) == 0)
  873.         {
  874.           /* The sun4 assembler does not grok this.  */
  875.           name = IDENTIFIER_POINTER (DECL_NAME (decl));
  876.           if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
  877.           || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
  878.         {
  879.           int ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
  880.           fprintf (asmfile, ".stabs \"%s:c=i%d\",0x%x,0,0,0\n",
  881.                name, ival, N_LSYM);
  882.           return;
  883.         }
  884.           else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
  885.         {
  886.           /* don't know how to do this yet.  */
  887.         }
  888.           break;
  889.         }
  890.       /* else it is something we handle like a normal variable.  */
  891.     }
  892.  
  893.       /* Don't mention a variable at all
  894.      if it was completely optimized into nothingness.  */
  895.       if (GET_CODE (DECL_RTL (decl)) == REG
  896.       && (REGNO (DECL_RTL (decl)) < 0
  897.           || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
  898.     break;
  899.  
  900.       /* The kind-of-variable letter depends on where
  901.      the variable is and on the scope of its name:
  902.      G and N_GSYM for static storage and global scope,
  903.      S for static storage and file scope,
  904.      V for static storage and local scope,
  905.         for those two, use N_LCSYM if data is in bss segment,
  906.         N_STSYM otherwise.  (N_FUN confuses GDB.)
  907.      no letter at all, and N_LSYM, for auto variable,
  908.      r and N_RSYM for register variable.  */
  909.  
  910.       if (GET_CODE (DECL_RTL (decl)) == MEM
  911.       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
  912.     {
  913.       if (TREE_PUBLIC (decl))
  914.         {
  915.           letter = 'G';
  916.           current_sym_code = N_GSYM;
  917.         }
  918.       else
  919.         {
  920.           current_sym_addr = XEXP (DECL_RTL (decl), 0);
  921.  
  922.           letter = TREE_PERMANENT (decl) ? 'S' : 'V';
  923.  
  924.           if (!DECL_INITIAL (decl))
  925.         current_sym_code = N_LCSYM;
  926. #if 0  /* Note: N_FUN confuses GDB, since GDB expects it to start a new
  927.       nest of N_LBRAC/N_RBRAC, etc.  But N_STSYM probably does not
  928.       work either, since it relocates as data segment.
  929.       Probably no standard N_ code works, so we must invent one.  */
  930.           else if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
  931.         /* This is not quite right, but it's the closest
  932.            of all the codes that Unix defines.  */
  933.         current_sym_code = N_FUN;
  934. #endif
  935.           else
  936.         current_sym_code = N_STSYM;
  937.         }
  938.     }
  939.       else if (GET_CODE (DECL_RTL (decl)) == REG)
  940.     {
  941.       letter = 'r';
  942.       current_sym_code = N_RSYM;
  943.       current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl)));
  944.     }
  945.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  946.            && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
  947.            || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
  948.                && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
  949.     /* If the value is indirect by memory or by a register
  950.        that isn't the frame pointer
  951.        then it means the object is variable-sized and address through
  952.        that register or stack slot.  DBX has no way to represent this
  953.        so all we can do is output the variable as a pointer.
  954.        If it's not a parameter, ignore it.
  955.        (VAR_DECLs like this can be made by integrate.c.)  */
  956.     {
  957.       if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  958.         {
  959.           letter = 'r';
  960.           current_sym_code = N_RSYM;
  961.           current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (DECL_RTL (decl), 0)));
  962.         }
  963.       else
  964.         {
  965.           current_sym_code = N_LSYM;
  966.           /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
  967.          We want the value of that CONST_INT.  */
  968.           current_sym_value = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1));
  969.         }
  970.  
  971.       type = build_pointer_type (TREE_TYPE (decl));
  972.     }
  973.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  974.            && GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  975.     {
  976.       current_sym_code = N_LSYM;
  977.       current_sym_value = 0;
  978.     }
  979.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  980.            && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
  981.            && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
  982.     {
  983.       current_sym_code = N_LSYM;
  984.       /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
  985.          We want the value of that CONST_INT.  */
  986.       current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1));
  987.     }
  988.       else
  989.     /* Address might be a MEM, when DECL is a variable-sized object.
  990.        Or it might be const0_rtx, meaning previous passes
  991.        want us to ignore this variable.  */
  992.     break;
  993.  
  994.       /* Ok, start a symtab entry and output the variable name.  */
  995.       FORCE_TEXT;
  996.       /* One slight hitch: if this is a VAR_DECL which is a static
  997.      class member, we must put out the mangled name instead of the
  998.      DECL_NAME.  */
  999.       if (DECL_LANG_SPECIFIC (decl))
  1000.     {
  1001.       name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
  1002.       if (name[0] == '*')
  1003.         name += 1;
  1004.     }
  1005.       else
  1006.     {
  1007.       name = IDENTIFIER_POINTER (DECL_NAME (decl));
  1008.     }
  1009.  
  1010.       /* Adding 1 here only works on systems
  1011.      which flush an initial underscore.  */
  1012.       fprintf (asmfile, ".stabs \"%s:",
  1013.            name + (DECL_CONTEXT (decl) != 0
  1014.                && TREE_CODE (DECL_CONTEXT (decl)) == RECORD_TYPE));
  1015.       if (letter) putc (letter, asmfile);
  1016.       dbxout_type (type, 0);
  1017.       dbxout_finish_symbol ();
  1018.       break;
  1019.     }
  1020. }
  1021.  
  1022. static void
  1023. dbxout_finish_symbol ()
  1024. {
  1025.   fprintf (asmfile, "\",%d,0,0,", current_sym_code);
  1026.   if (current_sym_addr)
  1027.     output_addr_const (asmfile, current_sym_addr);
  1028.   else
  1029.     fprintf (asmfile, "%d", current_sym_value);
  1030.   putc ('\n', asmfile);
  1031. }
  1032.  
  1033. /* Output definitions of all the decls in a chain.  */
  1034.  
  1035. static void
  1036. dbxout_syms (syms)
  1037.      tree syms;
  1038. {
  1039.   while (syms)
  1040.     {
  1041.       dbxout_symbol (syms, 1);
  1042.       syms = TREE_CHAIN (syms);
  1043.     }
  1044. }
  1045.  
  1046. /* The following two functions output definitions of function parameters.
  1047.    Each parameter gets a definition locating it in the parameter list.
  1048.    Each parameter that is a register variable gets a second definition
  1049.    locating it in the register.
  1050.  
  1051.    Printing or argument lists in gdb uses the definitions that
  1052.    locate in the parameter list.  But reference to the variable in
  1053.    expressions uses preferentially the definition as a register.  */
  1054.  
  1055. /* Output definitions, referring to storage in the parmlist,
  1056.    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
  1057.  
  1058. static void
  1059. dbxout_parms (parms)
  1060.      tree parms;
  1061. {
  1062.   for (; parms; parms = TREE_CHAIN (parms))
  1063.     {
  1064.       if (DECL_OFFSET (parms) >= 0)
  1065.     {
  1066.       current_sym_code = N_PSYM;
  1067.       current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  1068.       current_sym_addr = 0;
  1069.  
  1070.       FORCE_TEXT;
  1071.       if (DECL_NAME (parms))
  1072.         {
  1073.           current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
  1074.  
  1075.           fprintf (asmfile, ".stabs \"%s:p",
  1076.                IDENTIFIER_POINTER (DECL_NAME (parms)));
  1077.         }
  1078.       else
  1079.         {
  1080.           current_sym_nchars = 8;
  1081.           fprintf (asmfile, ".stabs \"(anon):p");
  1082.         }
  1083.  
  1084.       if (GET_CODE (DECL_RTL (parms)) == REG
  1085.           && REGNO (DECL_RTL (parms)) >= 0
  1086.           && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  1087.         dbxout_type (DECL_ARG_TYPE (parms), 0);
  1088.       else
  1089.         {
  1090.           /* This is the case where the parm is passed as an int or double
  1091.          and it is converted to a char, short or float and stored back
  1092.          in the parmlist.  In this case, describe the parm
  1093.          with the variable's declared type, and adjust the address
  1094.          if the least significant bytes (which we are using) are not
  1095.          the first ones.  */
  1096. #ifdef BYTES_BIG_ENDIAN
  1097.           if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  1098.         current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  1099.                       - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  1100. #endif
  1101.  
  1102.           if (GET_CODE (DECL_RTL (parms)) == MEM
  1103.           && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  1104.           && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
  1105.           && INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == current_sym_value)
  1106.         dbxout_type (TREE_TYPE (parms), 0);
  1107.           else
  1108.         {
  1109.           current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  1110.           dbxout_type (DECL_ARG_TYPE (parms), 0);
  1111.         }
  1112.         }
  1113.       dbxout_finish_symbol ();
  1114.     }
  1115.       /* Parm was passed in registers.
  1116.      If it lives in a hard register, output a "regparm" symbol
  1117.      for the register it lives in.  */
  1118.       else if (GET_CODE (DECL_RTL (parms)) == REG
  1119.            && REGNO (DECL_RTL (parms)) >= 0
  1120.            && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  1121.     {
  1122.       current_sym_code = N_RSYM;
  1123.       current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
  1124.       current_sym_addr = 0;
  1125.  
  1126.       FORCE_TEXT;
  1127.       if (DECL_NAME (parms))
  1128.         {
  1129.           current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
  1130.  
  1131.           FORCE_TEXT;
  1132.           fprintf (asmfile, ".stabs \"%s:P",
  1133.                IDENTIFIER_POINTER (DECL_NAME (parms)));
  1134.         }
  1135.       else
  1136.         {
  1137.           current_sym_nchars = 8;
  1138.           FORCE_TEXT;
  1139.           fprintf (asmfile, ".stabs \"(anon):P");
  1140.         }
  1141.  
  1142.       dbxout_type (DECL_ARG_TYPE (parms), 0);
  1143.       dbxout_finish_symbol ();
  1144.     }
  1145.       else if (GET_CODE (DECL_RTL (parms)) == MEM
  1146.            && XEXP (DECL_RTL (parms), 0) != const0_rtx)
  1147.     {
  1148.       current_sym_code = N_LSYM;
  1149.       /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
  1150.          We want the value of that CONST_INT.  */
  1151.       current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
  1152.       current_sym_addr = 0;
  1153.  
  1154.       FORCE_TEXT;
  1155.       if (DECL_NAME (parms))
  1156.         {
  1157.           current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
  1158.  
  1159.           FORCE_TEXT;
  1160.           fprintf (asmfile, ".stabs \"%s:p",
  1161.                IDENTIFIER_POINTER (DECL_NAME (parms)));
  1162.         }
  1163.       else
  1164.         {
  1165.           current_sym_nchars = 8;
  1166.           FORCE_TEXT;
  1167.           fprintf (asmfile, ".stabs \"(anon):p");
  1168.         }
  1169.  
  1170.       /* This is the case where the parm is passed as an int or double
  1171.          and it is converted to a char, short or float and stored back
  1172.          in the parmlist.  In this case, describe the parm
  1173.          with the variable's declared type, and adjust the address
  1174.          if the least significant bytes (which we are using) are not
  1175.          the first ones.  */
  1176. #ifdef BYTES_BIG_ENDIAN
  1177.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  1178.         current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  1179.                   - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  1180. #endif
  1181.  
  1182.       dbxout_type (TREE_TYPE (parms), 0);
  1183.       dbxout_finish_symbol ();
  1184.     }
  1185.     }
  1186. }
  1187.  
  1188. /* Output definitions, referring to registers,
  1189.    of all the parms in PARMS which are stored in registers during the function.
  1190.    PARMS is a chain of PARM_DECL nodes.  */
  1191.  
  1192. static void
  1193. dbxout_reg_parms (parms)
  1194.      tree parms;
  1195. {
  1196.   while (parms)
  1197.     {
  1198.       /* Report parms that live in registers during the function.  */
  1199.       if (GET_CODE (DECL_RTL (parms)) == REG
  1200.       && REGNO (DECL_RTL (parms)) >= 0
  1201.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
  1202.       && DECL_OFFSET (parms) >= 0)
  1203.     {
  1204.       current_sym_code = N_RSYM;
  1205.       current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
  1206.       current_sym_addr = 0;
  1207.  
  1208.       FORCE_TEXT;
  1209.       if (DECL_NAME (parms))
  1210.         {
  1211.           current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
  1212.           FORCE_TEXT;
  1213.           fprintf (asmfile, ".stabs \"%s:r",
  1214.                IDENTIFIER_POINTER (DECL_NAME (parms)));
  1215.         }
  1216.       else
  1217.         {
  1218.           current_sym_nchars = 8;
  1219.           FORCE_TEXT;
  1220.           fprintf (asmfile, ".stabs \"(anon):r");
  1221.         }
  1222.       dbxout_type (TREE_TYPE (parms), 0);
  1223.       dbxout_finish_symbol ();
  1224.     }
  1225.       /* Report parms that live in memory but outside the parmlist.  */
  1226.       else if (GET_CODE (DECL_RTL (parms)) == MEM
  1227.            && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  1228.            && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
  1229.     {
  1230.       int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
  1231.       /* A parm declared char is really passed as an int,
  1232.          so it occupies the least significant bytes.
  1233.          On a big-endian machine those are not the low-numbered ones.  */
  1234. #ifdef BYTES_BIG_ENDIAN
  1235.       if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  1236.         offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  1237.                - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  1238. #endif
  1239.       if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
  1240.         {
  1241.           current_sym_code = N_LSYM;
  1242.           current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
  1243.           current_sym_addr = 0;
  1244.           FORCE_TEXT;
  1245.           if (DECL_NAME (parms))
  1246.         {
  1247.           current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
  1248.           FORCE_TEXT;
  1249.           fprintf (asmfile, ".stabs \"%s:",
  1250.                IDENTIFIER_POINTER (DECL_NAME (parms)));
  1251.         }
  1252.           else
  1253.         {
  1254.           current_sym_nchars = 8;
  1255.           FORCE_TEXT;
  1256.           fprintf (asmfile, ".stabs \"(anon):");
  1257.         }
  1258.           dbxout_type (TREE_TYPE (parms), 0);
  1259.           dbxout_finish_symbol ();
  1260.         }
  1261.     }
  1262.       parms = TREE_CHAIN (parms);
  1263.     }
  1264. }
  1265.  
  1266. /* Given a chain of ..._TYPE nodes (as come in a parameter list),
  1267.    output definitions of those names, in raw form */
  1268.  
  1269. void
  1270. dbxout_args (args)
  1271.      tree args;
  1272. {
  1273.   while (args)
  1274.     {
  1275.       putc (',', asmfile);
  1276.       dbxout_type (TREE_VALUE (args), 0);
  1277.       CHARS (1);
  1278.       args = TREE_CHAIN (args);
  1279.     }
  1280. }
  1281.  
  1282. /* Given a chain of ..._TYPE nodes,
  1283.    find those which have typedef names and output those names.
  1284.    This is to ensure those types get output.  */
  1285.  
  1286. void
  1287. dbxout_types (types)
  1288.      register tree types;
  1289. {
  1290.   while (types)
  1291.     {
  1292.       if (TYPE_NAME (types)
  1293.       && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
  1294.       && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
  1295.     dbxout_symbol (TYPE_NAME (types), 1);
  1296.       types = TREE_CHAIN (types);
  1297.     }
  1298. }
  1299.  
  1300. /* Output the tags (struct, union and enum definitions with names) for a block,
  1301.    given a list of them (a chain of TREE_LIST nodes) in TAGS.
  1302.    We must check to include those that have been mentioned already with
  1303.    only a cross-reference.  */
  1304.  
  1305. void
  1306. dbxout_tags (tags)
  1307.      tree tags;
  1308. {
  1309.   register tree link;
  1310.   for (link = tags; link; link = TREE_CHAIN (link))
  1311.     {
  1312.       register tree type = TYPE_MAIN_VARIANT (TREE_VALUE (link));
  1313.       if (TREE_PURPOSE (link) != 0
  1314.       && ! TREE_ASM_WRITTEN (link)
  1315.       && TYPE_SIZE (type) != 0)
  1316.     {
  1317.       TREE_ASM_WRITTEN (link) = 1;
  1318.       current_sym_code = N_LSYM;
  1319.       current_sym_value = 0;
  1320.       current_sym_addr = 0;
  1321.       current_sym_nchars = 2 + IDENTIFIER_LENGTH (TREE_PURPOSE (link));
  1322.  
  1323.       FORCE_TEXT;
  1324.       fprintf (asmfile, ".stabs \"%s:T",
  1325.            ANON_AGGRNAME_P (TREE_PURPOSE (link)) ? "" : IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  1326.       dbxout_type (type, 1);
  1327.       dbxout_finish_symbol ();
  1328.     }
  1329.     }
  1330. }
  1331.  
  1332. /* Output everything about a symbol block (that is to say, a LET_STMT node
  1333.    that represents a scope level),
  1334.    including recursive output of contained blocks.
  1335.  
  1336.    STMT is the LET_STMT node.
  1337.    DEPTH is its depth within containing symbol blocks.
  1338.    ARGS is usually zero; but for the outermost block of the
  1339.    body of a function, it is a chain of PARM_DECLs for the function parameters.
  1340.    We output definitions of all the register parms
  1341.    as if they were local variables of that block.
  1342.  
  1343.    Actually, STMT may be several statements chained together.
  1344.    We handle them all in sequence.  */
  1345.  
  1346. static void
  1347. dbxout_block (stmt, depth, args)
  1348.      register tree stmt;
  1349.      int depth;
  1350.      tree args;
  1351. {
  1352.   int blocknum;
  1353.  
  1354.   while (stmt)
  1355.     {
  1356.       switch (TREE_CODE (stmt))
  1357.     {
  1358.     case COMPOUND_STMT:
  1359.     case LOOP_STMT:
  1360.       dbxout_block (STMT_BODY (stmt), depth, 0);
  1361.       break;
  1362.  
  1363.     case IF_STMT:
  1364.       dbxout_block (STMT_THEN (stmt), depth, 0);
  1365.       dbxout_block (STMT_ELSE (stmt), depth, 0);
  1366.       break;
  1367.  
  1368.     case LET_STMT:
  1369.       /* In dbx format, the syms of a block come before the N_LBRAC.  */
  1370.       dbxout_tags (STMT_TYPE_TAGS (stmt));
  1371.       dbxout_syms (STMT_VARS (stmt));
  1372.       if (args)
  1373.         dbxout_reg_parms (args);
  1374.  
  1375.       /* Now output an N_LBRAC symbol to represent the beginning of
  1376.          the block.  Use the block's tree-walk order to generate
  1377.          the assembler symbols LBBn and LBEn
  1378.          that final will define around the code in this block.  */
  1379.       if (depth > 0)
  1380.         {
  1381.           blocknum = next_block_number++;
  1382.           fprintf (asmfile, ".stabn %d,0,0,LBB%d\n", N_LBRAC, blocknum);
  1383.         }
  1384.  
  1385.       /* Output the interior of the block.  */
  1386.       dbxout_block (STMT_BODY (stmt), depth + 1, 0);
  1387.  
  1388.       /* Refer to the marker for the end of the block.  */
  1389.       if (depth > 0)
  1390.         fprintf (asmfile, ".stabn %d,0,0,LBE%d\n", N_RBRAC, blocknum);
  1391.     }
  1392.       stmt = TREE_CHAIN (stmt);
  1393.     }
  1394. }
  1395.  
  1396. /* Output dbx data for a function definition.
  1397.    This includes a definition of the function name itself (a symbol),
  1398.    definitions of the parameters (locating them in the parameter list)
  1399.    and then output the block that makes up the function's body
  1400.    (including all the auto variables of the function).  */
  1401.  
  1402. void
  1403. dbxout_function (decl)
  1404.      tree decl;
  1405. {
  1406.   dbxout_symbol (decl, 0);
  1407.   dbxout_parms (DECL_ARGUMENTS (decl));
  1408.   dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
  1409.   
  1410.   /* If we made any temporary types in this fn that weren't
  1411.      output, output them now.  */
  1412.   dbxout_types (get_temporary_types ());
  1413. }
  1414.  
  1415. #else /* not DBX_DEBUGGING_INFO */
  1416.  
  1417. void
  1418. dbxout_init (asm_file, input_file_name)
  1419.      FILE *asm_file;
  1420.      char *input_file_name;
  1421. {}
  1422.  
  1423. void
  1424. dbxout_symbol (decl, local)
  1425.      tree decl;
  1426.      int local;
  1427. {}
  1428.  
  1429. void
  1430. dbxout_types (types)
  1431.      register tree types;
  1432. {}
  1433.  
  1434. void
  1435. dbxout_tags (tags)
  1436.      tree tags;
  1437. {}
  1438.  
  1439. void
  1440. dbxout_function (decl)
  1441.      tree decl;
  1442. {}
  1443.  
  1444. #endif /* DBX_DEBUGGING_INFO */
  1445.