xref: /openbsd/gnu/gcc/gcc/dbxout.c (revision 404b540a)
1*404b540aSrobert /* Output dbx-format symbol table information from GNU compiler.
2*404b540aSrobert    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3*404b540aSrobert    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4*404b540aSrobert    Free Software Foundation, Inc.
5*404b540aSrobert 
6*404b540aSrobert This file is part of GCC.
7*404b540aSrobert 
8*404b540aSrobert GCC is free software; you can redistribute it and/or modify it under
9*404b540aSrobert the terms of the GNU General Public License as published by the Free
10*404b540aSrobert Software Foundation; either version 2, or (at your option) any later
11*404b540aSrobert version.
12*404b540aSrobert 
13*404b540aSrobert GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*404b540aSrobert WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*404b540aSrobert FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16*404b540aSrobert for more details.
17*404b540aSrobert 
18*404b540aSrobert You should have received a copy of the GNU General Public License
19*404b540aSrobert along with GCC; see the file COPYING.  If not, write to the Free
20*404b540aSrobert Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21*404b540aSrobert 02110-1301, USA.  */
22*404b540aSrobert 
23*404b540aSrobert 
24*404b540aSrobert /* Output dbx-format symbol table data.
25*404b540aSrobert    This consists of many symbol table entries, each of them
26*404b540aSrobert    a .stabs assembler pseudo-op with four operands:
27*404b540aSrobert    a "name" which is really a description of one symbol and its type,
28*404b540aSrobert    a "code", which is a symbol defined in stab.h whose name starts with N_,
29*404b540aSrobert    an unused operand always 0,
30*404b540aSrobert    and a "value" which is an address or an offset.
31*404b540aSrobert    The name is enclosed in doublequote characters.
32*404b540aSrobert 
33*404b540aSrobert    Each function, variable, typedef, and structure tag
34*404b540aSrobert    has a symbol table entry to define it.
35*404b540aSrobert    The beginning and end of each level of name scoping within
36*404b540aSrobert    a function are also marked by special symbol table entries.
37*404b540aSrobert 
38*404b540aSrobert    The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
39*404b540aSrobert    and a data type number.  The data type number may be followed by
40*404b540aSrobert    "=" and a type definition; normally this will happen the first time
41*404b540aSrobert    the type number is mentioned.  The type definition may refer to
42*404b540aSrobert    other types by number, and those type numbers may be followed
43*404b540aSrobert    by "=" and nested definitions.
44*404b540aSrobert 
45*404b540aSrobert    This can make the "name" quite long.
46*404b540aSrobert    When a name is more than 80 characters, we split the .stabs pseudo-op
47*404b540aSrobert    into two .stabs pseudo-ops, both sharing the same "code" and "value".
48*404b540aSrobert    The first one is marked as continued with a double-backslash at the
49*404b540aSrobert    end of its "name".
50*404b540aSrobert 
51*404b540aSrobert    The kind-of-symbol letter distinguished function names from global
52*404b540aSrobert    variables from file-scope variables from parameters from auto
53*404b540aSrobert    variables in memory from typedef names from register variables.
54*404b540aSrobert    See `dbxout_symbol'.
55*404b540aSrobert 
56*404b540aSrobert    The "code" is mostly redundant with the kind-of-symbol letter
57*404b540aSrobert    that goes in the "name", but not entirely: for symbols located
58*404b540aSrobert    in static storage, the "code" says which segment the address is in,
59*404b540aSrobert    which controls how it is relocated.
60*404b540aSrobert 
61*404b540aSrobert    The "value" for a symbol in static storage
62*404b540aSrobert    is the core address of the symbol (actually, the assembler
63*404b540aSrobert    label for the symbol).  For a symbol located in a stack slot
64*404b540aSrobert    it is the stack offset; for one in a register, the register number.
65*404b540aSrobert    For a typedef symbol, it is zero.
66*404b540aSrobert 
67*404b540aSrobert    If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
68*404b540aSrobert    output while in the text section.
69*404b540aSrobert 
70*404b540aSrobert    For more on data type definitions, see `dbxout_type'.  */
71*404b540aSrobert 
72*404b540aSrobert #include "config.h"
73*404b540aSrobert #include "system.h"
74*404b540aSrobert #include "coretypes.h"
75*404b540aSrobert #include "tm.h"
76*404b540aSrobert 
77*404b540aSrobert #include "tree.h"
78*404b540aSrobert #include "rtl.h"
79*404b540aSrobert #include "flags.h"
80*404b540aSrobert #include "regs.h"
81*404b540aSrobert #include "insn-config.h"
82*404b540aSrobert #include "reload.h"
83*404b540aSrobert #include "output.h"
84*404b540aSrobert #include "dbxout.h"
85*404b540aSrobert #include "toplev.h"
86*404b540aSrobert #include "tm_p.h"
87*404b540aSrobert #include "ggc.h"
88*404b540aSrobert #include "debug.h"
89*404b540aSrobert #include "function.h"
90*404b540aSrobert #include "target.h"
91*404b540aSrobert #include "langhooks.h"
92*404b540aSrobert #include "obstack.h"
93*404b540aSrobert #include "expr.h"
94*404b540aSrobert 
95*404b540aSrobert #ifdef XCOFF_DEBUGGING_INFO
96*404b540aSrobert #include "xcoffout.h"
97*404b540aSrobert #endif
98*404b540aSrobert 
99*404b540aSrobert #define DBXOUT_DECR_NESTING \
100*404b540aSrobert   if (--debug_nesting == 0 && symbol_queue_index > 0) \
101*404b540aSrobert     { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
102*404b540aSrobert 
103*404b540aSrobert #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
104*404b540aSrobert   do {--debug_nesting; return (x);} while (0)
105*404b540aSrobert 
106*404b540aSrobert #ifndef ASM_STABS_OP
107*404b540aSrobert # ifdef XCOFF_DEBUGGING_INFO
108*404b540aSrobert #  define ASM_STABS_OP "\t.stabx\t"
109*404b540aSrobert # else
110*404b540aSrobert #  define ASM_STABS_OP "\t.stabs\t"
111*404b540aSrobert # endif
112*404b540aSrobert #endif
113*404b540aSrobert 
114*404b540aSrobert #ifndef ASM_STABN_OP
115*404b540aSrobert #define ASM_STABN_OP "\t.stabn\t"
116*404b540aSrobert #endif
117*404b540aSrobert 
118*404b540aSrobert #ifndef ASM_STABD_OP
119*404b540aSrobert #define ASM_STABD_OP "\t.stabd\t"
120*404b540aSrobert #endif
121*404b540aSrobert 
122*404b540aSrobert #ifndef DBX_TYPE_DECL_STABS_CODE
123*404b540aSrobert #define DBX_TYPE_DECL_STABS_CODE N_LSYM
124*404b540aSrobert #endif
125*404b540aSrobert 
126*404b540aSrobert #ifndef DBX_STATIC_CONST_VAR_CODE
127*404b540aSrobert #define DBX_STATIC_CONST_VAR_CODE N_FUN
128*404b540aSrobert #endif
129*404b540aSrobert 
130*404b540aSrobert #ifndef DBX_REGPARM_STABS_CODE
131*404b540aSrobert #define DBX_REGPARM_STABS_CODE N_RSYM
132*404b540aSrobert #endif
133*404b540aSrobert 
134*404b540aSrobert #ifndef DBX_REGPARM_STABS_LETTER
135*404b540aSrobert #define DBX_REGPARM_STABS_LETTER 'P'
136*404b540aSrobert #endif
137*404b540aSrobert 
138*404b540aSrobert #ifndef NO_DBX_FUNCTION_END
139*404b540aSrobert #define NO_DBX_FUNCTION_END 0
140*404b540aSrobert #endif
141*404b540aSrobert 
142*404b540aSrobert #ifndef NO_DBX_BNSYM_ENSYM
143*404b540aSrobert #define NO_DBX_BNSYM_ENSYM 0
144*404b540aSrobert #endif
145*404b540aSrobert 
146*404b540aSrobert #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
147*404b540aSrobert #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
148*404b540aSrobert #endif
149*404b540aSrobert 
150*404b540aSrobert #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
151*404b540aSrobert #define DBX_BLOCKS_FUNCTION_RELATIVE 0
152*404b540aSrobert #endif
153*404b540aSrobert 
154*404b540aSrobert #ifndef DBX_LINES_FUNCTION_RELATIVE
155*404b540aSrobert #define DBX_LINES_FUNCTION_RELATIVE 0
156*404b540aSrobert #endif
157*404b540aSrobert 
158*404b540aSrobert #ifndef DBX_CONTIN_LENGTH
159*404b540aSrobert #define DBX_CONTIN_LENGTH 80
160*404b540aSrobert #endif
161*404b540aSrobert 
162*404b540aSrobert #ifndef DBX_CONTIN_CHAR
163*404b540aSrobert #define DBX_CONTIN_CHAR '\\'
164*404b540aSrobert #endif
165*404b540aSrobert 
166*404b540aSrobert enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
167*404b540aSrobert 
168*404b540aSrobert /* Structure recording information about a C data type.
169*404b540aSrobert    The status element says whether we have yet output
170*404b540aSrobert    the definition of the type.  TYPE_XREF says we have
171*404b540aSrobert    output it as a cross-reference only.
172*404b540aSrobert    The file_number and type_number elements are used if DBX_USE_BINCL
173*404b540aSrobert    is defined.  */
174*404b540aSrobert 
175*404b540aSrobert struct typeinfo GTY(())
176*404b540aSrobert {
177*404b540aSrobert   enum typestatus status;
178*404b540aSrobert   int file_number;
179*404b540aSrobert   int type_number;
180*404b540aSrobert };
181*404b540aSrobert 
182*404b540aSrobert /* Vector recording information about C data types.
183*404b540aSrobert    When we first notice a data type (a tree node),
184*404b540aSrobert    we assign it a number using next_type_number.
185*404b540aSrobert    That is its index in this vector.  */
186*404b540aSrobert 
187*404b540aSrobert static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
188*404b540aSrobert 
189*404b540aSrobert /* Number of elements of space allocated in `typevec'.  */
190*404b540aSrobert 
191*404b540aSrobert static GTY(()) int typevec_len;
192*404b540aSrobert 
193*404b540aSrobert /* In dbx output, each type gets a unique number.
194*404b540aSrobert    This is the number for the next type output.
195*404b540aSrobert    The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
196*404b540aSrobert 
197*404b540aSrobert static GTY(()) int next_type_number;
198*404b540aSrobert 
199*404b540aSrobert /* The C front end may call dbxout_symbol before dbxout_init runs.
200*404b540aSrobert    We save all such decls in this list and output them when we get
201*404b540aSrobert    to dbxout_init.  */
202*404b540aSrobert 
203*404b540aSrobert static GTY(()) tree preinit_symbols;
204*404b540aSrobert 
205*404b540aSrobert enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
206*404b540aSrobert 
207*404b540aSrobert /* When using N_BINCL in dbx output, each type number is actually a
208*404b540aSrobert    pair of the file number and the type number within the file.
209*404b540aSrobert    This is a stack of input files.  */
210*404b540aSrobert 
211*404b540aSrobert struct dbx_file
212*404b540aSrobert {
213*404b540aSrobert   struct dbx_file *next;
214*404b540aSrobert   int file_number;
215*404b540aSrobert   int next_type_number;
216*404b540aSrobert   enum binclstatus bincl_status;  /* Keep track of lazy bincl.  */
217*404b540aSrobert   const char *pending_bincl_name; /* Name of bincl.  */
218*404b540aSrobert   struct dbx_file *prev;          /* Chain to traverse all pending bincls.  */
219*404b540aSrobert };
220*404b540aSrobert 
221*404b540aSrobert /* This is the top of the stack.
222*404b540aSrobert 
223*404b540aSrobert    This is not saved for PCH, because restoring a PCH should not change it.
224*404b540aSrobert    next_file_number does have to be saved, because the PCH may use some
225*404b540aSrobert    file numbers; however, just before restoring a PCH, next_file_number
226*404b540aSrobert    should always be 0 because we should not have needed any file numbers
227*404b540aSrobert    yet.  */
228*404b540aSrobert 
229*404b540aSrobert #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
230*404b540aSrobert     && defined (DBX_USE_BINCL)
231*404b540aSrobert static struct dbx_file *current_file;
232*404b540aSrobert #endif
233*404b540aSrobert 
234*404b540aSrobert /* This is the next file number to use.  */
235*404b540aSrobert 
236*404b540aSrobert static GTY(()) int next_file_number;
237*404b540aSrobert 
238*404b540aSrobert /* A counter for dbxout_function_end.  */
239*404b540aSrobert 
240*404b540aSrobert static GTY(()) int scope_labelno;
241*404b540aSrobert 
242*404b540aSrobert /* A counter for dbxout_source_line.  */
243*404b540aSrobert 
244*404b540aSrobert static GTY(()) int dbxout_source_line_counter;
245*404b540aSrobert 
246*404b540aSrobert /* Number for the next N_SOL filename stabs label.  The number 0 is reserved
247*404b540aSrobert    for the N_SO filename stabs label.  */
248*404b540aSrobert 
249*404b540aSrobert static GTY(()) int source_label_number = 1;
250*404b540aSrobert 
251*404b540aSrobert /* Last source file name mentioned in a NOTE insn.  */
252*404b540aSrobert 
253*404b540aSrobert static GTY(()) const char *lastfile;
254*404b540aSrobert 
255*404b540aSrobert /* Used by PCH machinery to detect if 'lastfile' should be reset to
256*404b540aSrobert    base_input_file.  */
257*404b540aSrobert static GTY(()) int lastfile_is_base;
258*404b540aSrobert 
259*404b540aSrobert /* Typical USG systems don't have stab.h, and they also have
260*404b540aSrobert    no use for DBX-format debugging info.  */
261*404b540aSrobert 
262*404b540aSrobert #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
263*404b540aSrobert 
264*404b540aSrobert #ifdef DBX_USE_BINCL
265*404b540aSrobert /* If zero then there is no pending BINCL.  */
266*404b540aSrobert static int pending_bincls = 0;
267*404b540aSrobert #endif
268*404b540aSrobert 
269*404b540aSrobert /* The original input file name.  */
270*404b540aSrobert static const char *base_input_file;
271*404b540aSrobert 
272*404b540aSrobert #ifdef DEBUG_SYMS_TEXT
273*404b540aSrobert #define FORCE_TEXT switch_to_section (current_function_section ())
274*404b540aSrobert #else
275*404b540aSrobert #define FORCE_TEXT
276*404b540aSrobert #endif
277*404b540aSrobert 
278*404b540aSrobert #include "gstab.h"
279*404b540aSrobert 
280*404b540aSrobert #define STAB_CODE_TYPE enum __stab_debug_code
281*404b540aSrobert 
282*404b540aSrobert /* 1 if PARM is passed to this function in memory.  */
283*404b540aSrobert 
284*404b540aSrobert #define PARM_PASSED_IN_MEMORY(PARM) \
285*404b540aSrobert  (MEM_P (DECL_INCOMING_RTL (PARM)))
286*404b540aSrobert 
287*404b540aSrobert /* A C expression for the integer offset value of an automatic variable
288*404b540aSrobert    (N_LSYM) having address X (an RTX).  */
289*404b540aSrobert #ifndef DEBUGGER_AUTO_OFFSET
290*404b540aSrobert #define DEBUGGER_AUTO_OFFSET(X) \
291*404b540aSrobert   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
292*404b540aSrobert #endif
293*404b540aSrobert 
294*404b540aSrobert /* A C expression for the integer offset value of an argument (N_PSYM)
295*404b540aSrobert    having address X (an RTX).  The nominal offset is OFFSET.  */
296*404b540aSrobert #ifndef DEBUGGER_ARG_OFFSET
297*404b540aSrobert #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
298*404b540aSrobert #endif
299*404b540aSrobert 
300*404b540aSrobert /* This obstack holds the stab string currently being constructed.  We
301*404b540aSrobert    build it up here, then write it out, so we can split long lines up
302*404b540aSrobert    properly (see dbxout_finish_complex_stabs).  */
303*404b540aSrobert static struct obstack stabstr_ob;
304*404b540aSrobert static size_t stabstr_last_contin_point;
305*404b540aSrobert 
306*404b540aSrobert #ifdef DBX_USE_BINCL
307*404b540aSrobert static void emit_bincl_stab             (const char *c);
308*404b540aSrobert static void emit_pending_bincls         (void);
309*404b540aSrobert #endif
310*404b540aSrobert static inline void emit_pending_bincls_if_required (void);
311*404b540aSrobert 
312*404b540aSrobert static void dbxout_init (const char *);
313*404b540aSrobert 
314*404b540aSrobert static void dbxout_finish (const char *);
315*404b540aSrobert static void dbxout_start_source_file (unsigned, const char *);
316*404b540aSrobert static void dbxout_end_source_file (unsigned);
317*404b540aSrobert static void dbxout_typedefs (tree);
318*404b540aSrobert static void dbxout_type_index (tree);
319*404b540aSrobert static void dbxout_args (tree);
320*404b540aSrobert static void dbxout_type_fields (tree);
321*404b540aSrobert static void dbxout_type_method_1 (tree);
322*404b540aSrobert static void dbxout_type_methods (tree);
323*404b540aSrobert static void dbxout_range_type (tree);
324*404b540aSrobert static void dbxout_type (tree, int);
325*404b540aSrobert static bool print_int_cst_bounds_in_octal_p (tree);
326*404b540aSrobert static void dbxout_type_name (tree);
327*404b540aSrobert static void dbxout_class_name_qualifiers (tree);
328*404b540aSrobert static int dbxout_symbol_location (tree, tree, const char *, rtx);
329*404b540aSrobert static void dbxout_symbol_name (tree, const char *, int);
330*404b540aSrobert static void dbxout_block (tree, int, tree);
331*404b540aSrobert static void dbxout_global_decl (tree);
332*404b540aSrobert static void dbxout_type_decl (tree, int);
333*404b540aSrobert static void dbxout_handle_pch (unsigned);
334*404b540aSrobert 
335*404b540aSrobert /* The debug hooks structure.  */
336*404b540aSrobert #if defined (DBX_DEBUGGING_INFO)
337*404b540aSrobert 
338*404b540aSrobert static void dbxout_source_line (unsigned int, const char *);
339*404b540aSrobert static void dbxout_begin_prologue (unsigned int, const char *);
340*404b540aSrobert static void dbxout_source_file (const char *);
341*404b540aSrobert static void dbxout_function_end (tree);
342*404b540aSrobert static void dbxout_begin_function (tree);
343*404b540aSrobert static void dbxout_begin_block (unsigned, unsigned);
344*404b540aSrobert static void dbxout_end_block (unsigned, unsigned);
345*404b540aSrobert static void dbxout_function_decl (tree);
346*404b540aSrobert 
347*404b540aSrobert const struct gcc_debug_hooks dbx_debug_hooks =
348*404b540aSrobert {
349*404b540aSrobert   dbxout_init,
350*404b540aSrobert   dbxout_finish,
351*404b540aSrobert   debug_nothing_int_charstar,
352*404b540aSrobert   debug_nothing_int_charstar,
353*404b540aSrobert   dbxout_start_source_file,
354*404b540aSrobert   dbxout_end_source_file,
355*404b540aSrobert   dbxout_begin_block,
356*404b540aSrobert   dbxout_end_block,
357*404b540aSrobert   debug_true_tree,		         /* ignore_block */
358*404b540aSrobert   dbxout_source_line,		         /* source_line */
359*404b540aSrobert   dbxout_begin_prologue,	         /* begin_prologue */
360*404b540aSrobert   debug_nothing_int_charstar,	         /* end_prologue */
361*404b540aSrobert   debug_nothing_int_charstar,	         /* end_epilogue */
362*404b540aSrobert #ifdef DBX_FUNCTION_FIRST
363*404b540aSrobert   dbxout_begin_function,
364*404b540aSrobert #else
365*404b540aSrobert   debug_nothing_tree,		         /* begin_function */
366*404b540aSrobert #endif
367*404b540aSrobert   debug_nothing_int,		         /* end_function */
368*404b540aSrobert   dbxout_function_decl,
369*404b540aSrobert   dbxout_global_decl,		         /* global_decl */
370*404b540aSrobert   dbxout_type_decl,			 /* type_decl */
371*404b540aSrobert   debug_nothing_tree_tree,               /* imported_module_or_decl */
372*404b540aSrobert   debug_nothing_tree,		         /* deferred_inline_function */
373*404b540aSrobert   debug_nothing_tree,		         /* outlining_inline_function */
374*404b540aSrobert   debug_nothing_rtx,		         /* label */
375*404b540aSrobert   dbxout_handle_pch,		         /* handle_pch */
376*404b540aSrobert   debug_nothing_rtx,		         /* var_location */
377*404b540aSrobert   debug_nothing_void,                    /* switch_text_section */
378*404b540aSrobert   0                                      /* start_end_main_source_file */
379*404b540aSrobert };
380*404b540aSrobert #endif /* DBX_DEBUGGING_INFO  */
381*404b540aSrobert 
382*404b540aSrobert #if defined (XCOFF_DEBUGGING_INFO)
383*404b540aSrobert const struct gcc_debug_hooks xcoff_debug_hooks =
384*404b540aSrobert {
385*404b540aSrobert   dbxout_init,
386*404b540aSrobert   dbxout_finish,
387*404b540aSrobert   debug_nothing_int_charstar,
388*404b540aSrobert   debug_nothing_int_charstar,
389*404b540aSrobert   dbxout_start_source_file,
390*404b540aSrobert   dbxout_end_source_file,
391*404b540aSrobert   xcoffout_begin_block,
392*404b540aSrobert   xcoffout_end_block,
393*404b540aSrobert   debug_true_tree,		         /* ignore_block */
394*404b540aSrobert   xcoffout_source_line,
395*404b540aSrobert   xcoffout_begin_prologue,	         /* begin_prologue */
396*404b540aSrobert   debug_nothing_int_charstar,	         /* end_prologue */
397*404b540aSrobert   xcoffout_end_epilogue,
398*404b540aSrobert   debug_nothing_tree,		         /* begin_function */
399*404b540aSrobert   xcoffout_end_function,
400*404b540aSrobert   debug_nothing_tree,		         /* function_decl */
401*404b540aSrobert   dbxout_global_decl,		         /* global_decl */
402*404b540aSrobert   dbxout_type_decl,			 /* type_decl */
403*404b540aSrobert   debug_nothing_tree_tree,               /* imported_module_or_decl */
404*404b540aSrobert   debug_nothing_tree,		         /* deferred_inline_function */
405*404b540aSrobert   debug_nothing_tree,		         /* outlining_inline_function */
406*404b540aSrobert   debug_nothing_rtx,		         /* label */
407*404b540aSrobert   dbxout_handle_pch,		         /* handle_pch */
408*404b540aSrobert   debug_nothing_rtx,		         /* var_location */
409*404b540aSrobert   debug_nothing_void,                    /* switch_text_section */
410*404b540aSrobert   0                                      /* start_end_main_source_file */
411*404b540aSrobert };
412*404b540aSrobert #endif /* XCOFF_DEBUGGING_INFO  */
413*404b540aSrobert 
414*404b540aSrobert /* Numeric formatting helper macro.  Note that this does not handle
415*404b540aSrobert    hexadecimal.  */
416*404b540aSrobert #define NUMBER_FMT_LOOP(P, NUM, BASE)		\
417*404b540aSrobert   do						\
418*404b540aSrobert     {						\
419*404b540aSrobert       int digit = NUM % BASE;			\
420*404b540aSrobert       NUM /= BASE;				\
421*404b540aSrobert       *--P = digit + '0';			\
422*404b540aSrobert     }						\
423*404b540aSrobert   while (NUM > 0)
424*404b540aSrobert 
425*404b540aSrobert /* Utility: write a decimal integer NUM to asm_out_file.  */
426*404b540aSrobert void
dbxout_int(int num)427*404b540aSrobert dbxout_int (int num)
428*404b540aSrobert {
429*404b540aSrobert   char buf[64];
430*404b540aSrobert   char *p = buf + sizeof buf;
431*404b540aSrobert   unsigned int unum;
432*404b540aSrobert 
433*404b540aSrobert   if (num == 0)
434*404b540aSrobert     {
435*404b540aSrobert       putc ('0', asm_out_file);
436*404b540aSrobert       return;
437*404b540aSrobert     }
438*404b540aSrobert   if (num < 0)
439*404b540aSrobert     {
440*404b540aSrobert       putc ('-', asm_out_file);
441*404b540aSrobert       unum = -num;
442*404b540aSrobert     }
443*404b540aSrobert   else
444*404b540aSrobert     unum = num;
445*404b540aSrobert 
446*404b540aSrobert   NUMBER_FMT_LOOP (p, unum, 10);
447*404b540aSrobert 
448*404b540aSrobert   while (p < buf + sizeof buf)
449*404b540aSrobert     {
450*404b540aSrobert       putc (*p, asm_out_file);
451*404b540aSrobert       p++;
452*404b540aSrobert     }
453*404b540aSrobert }
454*404b540aSrobert 
455*404b540aSrobert 
456*404b540aSrobert /* Primitives for emitting simple stabs directives.  All other stabs
457*404b540aSrobert    routines should use these functions instead of directly emitting
458*404b540aSrobert    stabs.  They are exported because machine-dependent code may need
459*404b540aSrobert    to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
460*404b540aSrobert    forwards to code in CPU.c.  */
461*404b540aSrobert 
462*404b540aSrobert /* The following functions should all be called immediately after one
463*404b540aSrobert    of the dbxout_begin_stab* functions (below).  They write out
464*404b540aSrobert    various things as the value of a stab.  */
465*404b540aSrobert 
466*404b540aSrobert /* Write out a literal zero as the value of a stab.  */
467*404b540aSrobert void
dbxout_stab_value_zero(void)468*404b540aSrobert dbxout_stab_value_zero (void)
469*404b540aSrobert {
470*404b540aSrobert   fputs ("0\n", asm_out_file);
471*404b540aSrobert }
472*404b540aSrobert 
473*404b540aSrobert /* Write out the label LABEL as the value of a stab.  */
474*404b540aSrobert void
dbxout_stab_value_label(const char * label)475*404b540aSrobert dbxout_stab_value_label (const char *label)
476*404b540aSrobert {
477*404b540aSrobert   assemble_name (asm_out_file, label);
478*404b540aSrobert   putc ('\n', asm_out_file);
479*404b540aSrobert }
480*404b540aSrobert 
481*404b540aSrobert /* Write out the difference of two labels, LABEL - BASE, as the value
482*404b540aSrobert    of a stab.  */
483*404b540aSrobert void
dbxout_stab_value_label_diff(const char * label,const char * base)484*404b540aSrobert dbxout_stab_value_label_diff (const char *label, const char *base)
485*404b540aSrobert {
486*404b540aSrobert   assemble_name (asm_out_file, label);
487*404b540aSrobert   putc ('-', asm_out_file);
488*404b540aSrobert   assemble_name (asm_out_file, base);
489*404b540aSrobert   putc ('\n', asm_out_file);
490*404b540aSrobert }
491*404b540aSrobert 
492*404b540aSrobert /* Write out an internal label as the value of a stab, and immediately
493*404b540aSrobert    emit that internal label.  This should be used only when
494*404b540aSrobert    dbxout_stabd will not work.  STEM is the name stem of the label,
495*404b540aSrobert    COUNTERP is a pointer to a counter variable which will be used to
496*404b540aSrobert    guarantee label uniqueness.  */
497*404b540aSrobert void
dbxout_stab_value_internal_label(const char * stem,int * counterp)498*404b540aSrobert dbxout_stab_value_internal_label (const char *stem, int *counterp)
499*404b540aSrobert {
500*404b540aSrobert   char label[100];
501*404b540aSrobert   int counter = counterp ? (*counterp)++ : 0;
502*404b540aSrobert 
503*404b540aSrobert   ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
504*404b540aSrobert   dbxout_stab_value_label (label);
505*404b540aSrobert   targetm.asm_out.internal_label (asm_out_file, stem, counter);
506*404b540aSrobert }
507*404b540aSrobert 
508*404b540aSrobert /* Write out the difference between BASE and an internal label as the
509*404b540aSrobert    value of a stab, and immediately emit that internal label.  STEM and
510*404b540aSrobert    COUNTERP are as for dbxout_stab_value_internal_label.  */
511*404b540aSrobert void
dbxout_stab_value_internal_label_diff(const char * stem,int * counterp,const char * base)512*404b540aSrobert dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
513*404b540aSrobert 				       const char *base)
514*404b540aSrobert {
515*404b540aSrobert   char label[100];
516*404b540aSrobert   int counter = counterp ? (*counterp)++ : 0;
517*404b540aSrobert 
518*404b540aSrobert   ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
519*404b540aSrobert   dbxout_stab_value_label_diff (label, base);
520*404b540aSrobert   targetm.asm_out.internal_label (asm_out_file, stem, counter);
521*404b540aSrobert }
522*404b540aSrobert 
523*404b540aSrobert /* The following functions produce specific kinds of stab directives.  */
524*404b540aSrobert 
525*404b540aSrobert /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file.  */
526*404b540aSrobert void
dbxout_stabd(int stype,int sdesc)527*404b540aSrobert dbxout_stabd (int stype, int sdesc)
528*404b540aSrobert {
529*404b540aSrobert   fputs (ASM_STABD_OP, asm_out_file);
530*404b540aSrobert   dbxout_int (stype);
531*404b540aSrobert   fputs (",0,", asm_out_file);
532*404b540aSrobert   dbxout_int (sdesc);
533*404b540aSrobert   putc ('\n', asm_out_file);
534*404b540aSrobert }
535*404b540aSrobert 
536*404b540aSrobert /* Write a .stabn directive with type STYPE.  This function stops
537*404b540aSrobert    short of emitting the value field, which is the responsibility of
538*404b540aSrobert    the caller (normally it will be either a symbol or the difference
539*404b540aSrobert    of two symbols).  */
540*404b540aSrobert 
541*404b540aSrobert void
dbxout_begin_stabn(int stype)542*404b540aSrobert dbxout_begin_stabn (int stype)
543*404b540aSrobert {
544*404b540aSrobert   fputs (ASM_STABN_OP, asm_out_file);
545*404b540aSrobert   dbxout_int (stype);
546*404b540aSrobert   fputs (",0,0,", asm_out_file);
547*404b540aSrobert }
548*404b540aSrobert 
549*404b540aSrobert /* Write a .stabn directive with type N_SLINE and desc LINE.  As above,
550*404b540aSrobert    the value field is the responsibility of the caller.  */
551*404b540aSrobert void
dbxout_begin_stabn_sline(int lineno)552*404b540aSrobert dbxout_begin_stabn_sline (int lineno)
553*404b540aSrobert {
554*404b540aSrobert   fputs (ASM_STABN_OP, asm_out_file);
555*404b540aSrobert   dbxout_int (N_SLINE);
556*404b540aSrobert   fputs (",0,", asm_out_file);
557*404b540aSrobert   dbxout_int (lineno);
558*404b540aSrobert   putc (',', asm_out_file);
559*404b540aSrobert }
560*404b540aSrobert 
561*404b540aSrobert /* Begin a .stabs directive with string "", type STYPE, and desc and
562*404b540aSrobert    other fields 0.  The value field is the responsibility of the
563*404b540aSrobert    caller.  This function cannot be used for .stabx directives.  */
564*404b540aSrobert void
dbxout_begin_empty_stabs(int stype)565*404b540aSrobert dbxout_begin_empty_stabs (int stype)
566*404b540aSrobert {
567*404b540aSrobert   fputs (ASM_STABS_OP, asm_out_file);
568*404b540aSrobert   fputs ("\"\",", asm_out_file);
569*404b540aSrobert   dbxout_int (stype);
570*404b540aSrobert   fputs (",0,0,", asm_out_file);
571*404b540aSrobert }
572*404b540aSrobert 
573*404b540aSrobert /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
574*404b540aSrobert    The value field is the responsibility of the caller.  */
575*404b540aSrobert void
dbxout_begin_simple_stabs(const char * str,int stype)576*404b540aSrobert dbxout_begin_simple_stabs (const char *str, int stype)
577*404b540aSrobert {
578*404b540aSrobert   fputs (ASM_STABS_OP, asm_out_file);
579*404b540aSrobert   output_quoted_string (asm_out_file, str);
580*404b540aSrobert   putc (',', asm_out_file);
581*404b540aSrobert   dbxout_int (stype);
582*404b540aSrobert   fputs (",0,0,", asm_out_file);
583*404b540aSrobert }
584*404b540aSrobert 
585*404b540aSrobert /* As above but use SDESC for the desc field.  */
586*404b540aSrobert void
dbxout_begin_simple_stabs_desc(const char * str,int stype,int sdesc)587*404b540aSrobert dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
588*404b540aSrobert {
589*404b540aSrobert   fputs (ASM_STABS_OP, asm_out_file);
590*404b540aSrobert   output_quoted_string (asm_out_file, str);
591*404b540aSrobert   putc (',', asm_out_file);
592*404b540aSrobert   dbxout_int (stype);
593*404b540aSrobert   fputs (",0,", asm_out_file);
594*404b540aSrobert   dbxout_int (sdesc);
595*404b540aSrobert   putc (',', asm_out_file);
596*404b540aSrobert }
597*404b540aSrobert 
598*404b540aSrobert /* The next set of functions are entirely concerned with production of
599*404b540aSrobert    "complex" .stabs directives: that is, .stabs directives whose
600*404b540aSrobert    strings have to be constructed piecemeal.  dbxout_type,
601*404b540aSrobert    dbxout_symbol, etc. use these routines heavily.  The string is queued
602*404b540aSrobert    up in an obstack, then written out by dbxout_finish_complex_stabs, which
603*404b540aSrobert    is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
604*404b540aSrobert    (You might think it would be more efficient to go straight to stdio
605*404b540aSrobert    when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
606*404b540aSrobert    out not to be the case, and anyway this needs fewer #ifdefs.)  */
607*404b540aSrobert 
608*404b540aSrobert /* Begin a complex .stabs directive.  If we can, write the initial
609*404b540aSrobert    ASM_STABS_OP to the asm_out_file.  */
610*404b540aSrobert 
611*404b540aSrobert static void
dbxout_begin_complex_stabs(void)612*404b540aSrobert dbxout_begin_complex_stabs (void)
613*404b540aSrobert {
614*404b540aSrobert   emit_pending_bincls_if_required ();
615*404b540aSrobert   FORCE_TEXT;
616*404b540aSrobert   fputs (ASM_STABS_OP, asm_out_file);
617*404b540aSrobert   putc ('"', asm_out_file);
618*404b540aSrobert   gcc_assert (stabstr_last_contin_point == 0);
619*404b540aSrobert }
620*404b540aSrobert 
621*404b540aSrobert /* As above, but do not force text or emit pending bincls.  This is
622*404b540aSrobert    used by dbxout_symbol_location, which needs to do something else.  */
623*404b540aSrobert static void
dbxout_begin_complex_stabs_noforcetext(void)624*404b540aSrobert dbxout_begin_complex_stabs_noforcetext (void)
625*404b540aSrobert {
626*404b540aSrobert   fputs (ASM_STABS_OP, asm_out_file);
627*404b540aSrobert   putc ('"', asm_out_file);
628*404b540aSrobert   gcc_assert (stabstr_last_contin_point == 0);
629*404b540aSrobert }
630*404b540aSrobert 
631*404b540aSrobert /* Add CHR, a single character, to the string being built.  */
632*404b540aSrobert #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
633*404b540aSrobert 
634*404b540aSrobert /* Add STR, a normal C string, to the string being built.  */
635*404b540aSrobert #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen(str))
636*404b540aSrobert 
637*404b540aSrobert /* Add the text of ID, an IDENTIFIER_NODE, to the string being built.  */
638*404b540aSrobert #define stabstr_I(id) obstack_grow (&stabstr_ob, \
639*404b540aSrobert                                     IDENTIFIER_POINTER (id), \
640*404b540aSrobert                                     IDENTIFIER_LENGTH (id))
641*404b540aSrobert 
642*404b540aSrobert /* Add NUM, a signed decimal number, to the string being built.  */
643*404b540aSrobert static void
stabstr_D(HOST_WIDE_INT num)644*404b540aSrobert stabstr_D (HOST_WIDE_INT num)
645*404b540aSrobert {
646*404b540aSrobert   char buf[64];
647*404b540aSrobert   char *p = buf + sizeof buf;
648*404b540aSrobert   unsigned int unum;
649*404b540aSrobert 
650*404b540aSrobert   if (num == 0)
651*404b540aSrobert     {
652*404b540aSrobert       stabstr_C ('0');
653*404b540aSrobert       return;
654*404b540aSrobert     }
655*404b540aSrobert   if (num < 0)
656*404b540aSrobert     {
657*404b540aSrobert       stabstr_C ('-');
658*404b540aSrobert       unum = -num;
659*404b540aSrobert     }
660*404b540aSrobert   else
661*404b540aSrobert     unum = num;
662*404b540aSrobert 
663*404b540aSrobert   NUMBER_FMT_LOOP (p, unum, 10);
664*404b540aSrobert 
665*404b540aSrobert   obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
666*404b540aSrobert }
667*404b540aSrobert 
668*404b540aSrobert /* Add NUM, an unsigned decimal number, to the string being built.  */
669*404b540aSrobert static void
stabstr_U(unsigned HOST_WIDE_INT num)670*404b540aSrobert stabstr_U (unsigned HOST_WIDE_INT num)
671*404b540aSrobert {
672*404b540aSrobert   char buf[64];
673*404b540aSrobert   char *p = buf + sizeof buf;
674*404b540aSrobert   if (num == 0)
675*404b540aSrobert     {
676*404b540aSrobert       stabstr_C ('0');
677*404b540aSrobert       return;
678*404b540aSrobert     }
679*404b540aSrobert   NUMBER_FMT_LOOP (p, num, 10);
680*404b540aSrobert   obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
681*404b540aSrobert }
682*404b540aSrobert 
683*404b540aSrobert /* Add CST, an INTEGER_CST tree, to the string being built as an
684*404b540aSrobert    unsigned octal number.  This routine handles values which are
685*404b540aSrobert    larger than a single HOST_WIDE_INT.  */
686*404b540aSrobert static void
stabstr_O(tree cst)687*404b540aSrobert stabstr_O (tree cst)
688*404b540aSrobert {
689*404b540aSrobert   unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (cst);
690*404b540aSrobert   unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
691*404b540aSrobert 
692*404b540aSrobert   char buf[128];
693*404b540aSrobert   char *p = buf + sizeof buf;
694*404b540aSrobert 
695*404b540aSrobert   /* GDB wants constants with no extra leading "1" bits, so
696*404b540aSrobert      we need to remove any sign-extension that might be
697*404b540aSrobert      present.  */
698*404b540aSrobert   {
699*404b540aSrobert     const unsigned int width = TYPE_PRECISION (TREE_TYPE (cst));
700*404b540aSrobert     if (width == HOST_BITS_PER_WIDE_INT * 2)
701*404b540aSrobert       ;
702*404b540aSrobert     else if (width > HOST_BITS_PER_WIDE_INT)
703*404b540aSrobert       high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
704*404b540aSrobert     else if (width == HOST_BITS_PER_WIDE_INT)
705*404b540aSrobert       high = 0;
706*404b540aSrobert     else
707*404b540aSrobert       high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
708*404b540aSrobert   }
709*404b540aSrobert 
710*404b540aSrobert   /* Leading zero for base indicator.  */
711*404b540aSrobert   stabstr_C ('0');
712*404b540aSrobert 
713*404b540aSrobert   /* If the value is zero, the base indicator will serve as the value
714*404b540aSrobert      all by itself.  */
715*404b540aSrobert   if (high == 0 && low == 0)
716*404b540aSrobert     return;
717*404b540aSrobert 
718*404b540aSrobert   /* If the high half is zero, we need only print the low half normally.  */
719*404b540aSrobert   if (high == 0)
720*404b540aSrobert     NUMBER_FMT_LOOP (p, low, 8);
721*404b540aSrobert   else
722*404b540aSrobert     {
723*404b540aSrobert       /* When high != 0, we need to print enough zeroes from low to
724*404b540aSrobert 	 give the digits from high their proper place-values.  Hence
725*404b540aSrobert 	 NUMBER_FMT_LOOP cannot be used.  */
726*404b540aSrobert       const int n_digits = HOST_BITS_PER_WIDE_INT / 3;
727*404b540aSrobert       int i;
728*404b540aSrobert 
729*404b540aSrobert       for (i = 1; i <= n_digits; i++)
730*404b540aSrobert 	{
731*404b540aSrobert 	  unsigned int digit = low % 8;
732*404b540aSrobert 	  low /= 8;
733*404b540aSrobert 	  *--p = '0' + digit;
734*404b540aSrobert 	}
735*404b540aSrobert 
736*404b540aSrobert       /* Octal digits carry exactly three bits of information.  The
737*404b540aSrobert 	 width of a HOST_WIDE_INT is not normally a multiple of three.
738*404b540aSrobert 	 Therefore, the next digit printed probably needs to carry
739*404b540aSrobert 	 information from both low and high.  */
740*404b540aSrobert       if (HOST_BITS_PER_WIDE_INT % 3 != 0)
741*404b540aSrobert 	{
742*404b540aSrobert 	  const int n_leftover_bits = HOST_BITS_PER_WIDE_INT % 3;
743*404b540aSrobert 	  const int n_bits_from_high = 3 - n_leftover_bits;
744*404b540aSrobert 
745*404b540aSrobert 	  const unsigned HOST_WIDE_INT
746*404b540aSrobert 	    low_mask = (((unsigned HOST_WIDE_INT)1) << n_leftover_bits) - 1;
747*404b540aSrobert 	  const unsigned HOST_WIDE_INT
748*404b540aSrobert 	    high_mask = (((unsigned HOST_WIDE_INT)1) << n_bits_from_high) - 1;
749*404b540aSrobert 
750*404b540aSrobert 	  unsigned int digit;
751*404b540aSrobert 
752*404b540aSrobert 	  /* At this point, only the bottom n_leftover_bits bits of low
753*404b540aSrobert 	     should be set.  */
754*404b540aSrobert 	  gcc_assert (!(low & ~low_mask));
755*404b540aSrobert 
756*404b540aSrobert 	  digit = (low | ((high & high_mask) << n_leftover_bits));
757*404b540aSrobert 	  high >>= n_bits_from_high;
758*404b540aSrobert 
759*404b540aSrobert 	  *--p = '0' + digit;
760*404b540aSrobert 	}
761*404b540aSrobert 
762*404b540aSrobert       /* Now we can format high in the normal manner.  However, if
763*404b540aSrobert 	 the only bits of high that were set were handled by the
764*404b540aSrobert 	 digit split between low and high, high will now be zero, and
765*404b540aSrobert 	 we don't want to print extra digits in that case.  */
766*404b540aSrobert       if (high)
767*404b540aSrobert 	NUMBER_FMT_LOOP (p, high, 8);
768*404b540aSrobert     }
769*404b540aSrobert 
770*404b540aSrobert   obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
771*404b540aSrobert }
772*404b540aSrobert 
773*404b540aSrobert /* Called whenever it is safe to break a stabs string into multiple
774*404b540aSrobert    .stabs directives.  If the current string has exceeded the limit
775*404b540aSrobert    set by DBX_CONTIN_LENGTH, mark the current position in the buffer
776*404b540aSrobert    as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
777*404b540aSrobert    it is a backslash) and a null character.  */
778*404b540aSrobert static inline void
stabstr_continue(void)779*404b540aSrobert stabstr_continue (void)
780*404b540aSrobert {
781*404b540aSrobert   if (DBX_CONTIN_LENGTH > 0
782*404b540aSrobert       && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
783*404b540aSrobert 	 > DBX_CONTIN_LENGTH)
784*404b540aSrobert     {
785*404b540aSrobert       if (DBX_CONTIN_CHAR == '\\')
786*404b540aSrobert 	obstack_1grow (&stabstr_ob, '\\');
787*404b540aSrobert       obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
788*404b540aSrobert       obstack_1grow (&stabstr_ob, '\0');
789*404b540aSrobert       stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
790*404b540aSrobert     }
791*404b540aSrobert }
792*404b540aSrobert #define CONTIN stabstr_continue ()
793*404b540aSrobert 
794*404b540aSrobert /* Macro subroutine of dbxout_finish_complex_stabs, which emits
795*404b540aSrobert    all of the arguments to the .stabs directive after the string.
796*404b540aSrobert    Overridden by xcoffout.h.  CODE is the stabs code for this symbol;
797*404b540aSrobert    LINE is the source line to write into the desc field (in extended
798*404b540aSrobert    mode); SYM is the symbol itself.
799*404b540aSrobert 
800*404b540aSrobert    ADDR, LABEL, and NUMBER are three different ways to represent the
801*404b540aSrobert    stabs value field.  At most one of these should be nonzero.
802*404b540aSrobert 
803*404b540aSrobert      ADDR is used most of the time; it represents the value as an
804*404b540aSrobert      RTL address constant.
805*404b540aSrobert 
806*404b540aSrobert      LABEL is used (currently) only for N_CATCH stabs; it represents
807*404b540aSrobert      the value as a string suitable for assemble_name.
808*404b540aSrobert 
809*404b540aSrobert      NUMBER is used when the value is an offset from an implicit base
810*404b540aSrobert      pointer (e.g. for a stack variable), or an index (e.g. for a
811*404b540aSrobert      register variable).  It represents the value as a decimal integer.  */
812*404b540aSrobert 
813*404b540aSrobert #ifndef DBX_FINISH_STABS
814*404b540aSrobert #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER)	\
815*404b540aSrobert do {								\
816*404b540aSrobert   int line_ = use_gnu_debug_info_extensions ? LINE : 0;		\
817*404b540aSrobert 								\
818*404b540aSrobert   dbxout_int (CODE);						\
819*404b540aSrobert   fputs (",0,", asm_out_file);					\
820*404b540aSrobert   dbxout_int (line_);						\
821*404b540aSrobert   putc (',', asm_out_file);					\
822*404b540aSrobert   if (ADDR)							\
823*404b540aSrobert     output_addr_const (asm_out_file, ADDR);			\
824*404b540aSrobert   else if (LABEL)						\
825*404b540aSrobert     assemble_name (asm_out_file, LABEL);			\
826*404b540aSrobert   else								\
827*404b540aSrobert     dbxout_int (NUMBER);					\
828*404b540aSrobert   putc ('\n', asm_out_file);					\
829*404b540aSrobert } while (0)
830*404b540aSrobert #endif
831*404b540aSrobert 
832*404b540aSrobert /* Finish the emission of a complex .stabs directive.  When DBX_CONTIN_LENGTH
833*404b540aSrobert    is zero, this has only to emit the close quote and the remainder of
834*404b540aSrobert    the arguments.  When it is nonzero, the string has been marshalled in
835*404b540aSrobert    stabstr_ob, and this routine is responsible for breaking it up into
836*404b540aSrobert    DBX_CONTIN_LENGTH-sized chunks.
837*404b540aSrobert 
838*404b540aSrobert    SYM is the DECL of the symbol under consideration; it is used only
839*404b540aSrobert    for its DECL_SOURCE_LINE.  The other arguments are all passed directly
840*404b540aSrobert    to DBX_FINISH_STABS; see above for details.  */
841*404b540aSrobert 
842*404b540aSrobert static void
dbxout_finish_complex_stabs(tree sym,STAB_CODE_TYPE code,rtx addr,const char * label,int number)843*404b540aSrobert dbxout_finish_complex_stabs (tree sym, STAB_CODE_TYPE code,
844*404b540aSrobert 			     rtx addr, const char *label, int number)
845*404b540aSrobert {
846*404b540aSrobert   int line ATTRIBUTE_UNUSED;
847*404b540aSrobert   char *str;
848*404b540aSrobert   size_t len;
849*404b540aSrobert 
850*404b540aSrobert   line = sym ? DECL_SOURCE_LINE (sym) : 0;
851*404b540aSrobert   if (DBX_CONTIN_LENGTH > 0)
852*404b540aSrobert     {
853*404b540aSrobert       char *chunk;
854*404b540aSrobert       size_t chunklen;
855*404b540aSrobert 
856*404b540aSrobert       /* Nul-terminate the growing string, then get its size and
857*404b540aSrobert 	 address.  */
858*404b540aSrobert       obstack_1grow (&stabstr_ob, '\0');
859*404b540aSrobert 
860*404b540aSrobert       len = obstack_object_size (&stabstr_ob);
861*404b540aSrobert       chunk = str = XOBFINISH (&stabstr_ob, char *);
862*404b540aSrobert 
863*404b540aSrobert       /* Within the buffer are a sequence of NUL-separated strings,
864*404b540aSrobert 	 each of which is to be written out as a separate stab
865*404b540aSrobert 	 directive.  */
866*404b540aSrobert       for (;;)
867*404b540aSrobert 	{
868*404b540aSrobert 	  chunklen = strlen (chunk);
869*404b540aSrobert 	  fwrite (chunk, 1, chunklen, asm_out_file);
870*404b540aSrobert 	  fputs ("\",", asm_out_file);
871*404b540aSrobert 
872*404b540aSrobert 	  /* Must add an extra byte to account for the NUL separator.  */
873*404b540aSrobert 	  chunk += chunklen + 1;
874*404b540aSrobert 	  len   -= chunklen + 1;
875*404b540aSrobert 
876*404b540aSrobert 	  /* Only put a line number on the last stab in the sequence.  */
877*404b540aSrobert 	  DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
878*404b540aSrobert 			    addr, label, number);
879*404b540aSrobert 	  if (len == 0)
880*404b540aSrobert 	    break;
881*404b540aSrobert 
882*404b540aSrobert 	  fputs (ASM_STABS_OP, asm_out_file);
883*404b540aSrobert 	  putc ('"', asm_out_file);
884*404b540aSrobert 	}
885*404b540aSrobert       stabstr_last_contin_point = 0;
886*404b540aSrobert     }
887*404b540aSrobert   else
888*404b540aSrobert     {
889*404b540aSrobert       /* No continuations - we can put the whole string out at once.
890*404b540aSrobert 	 It is faster to augment the string with the close quote and
891*404b540aSrobert 	 comma than to do a two-character fputs.  */
892*404b540aSrobert       obstack_grow (&stabstr_ob, "\",", 2);
893*404b540aSrobert       len = obstack_object_size (&stabstr_ob);
894*404b540aSrobert       str = XOBFINISH (&stabstr_ob, char *);
895*404b540aSrobert 
896*404b540aSrobert       fwrite (str, 1, len, asm_out_file);
897*404b540aSrobert       DBX_FINISH_STABS (sym, code, line, addr, label, number);
898*404b540aSrobert     }
899*404b540aSrobert   obstack_free (&stabstr_ob, str);
900*404b540aSrobert }
901*404b540aSrobert 
902*404b540aSrobert #if defined (DBX_DEBUGGING_INFO)
903*404b540aSrobert 
904*404b540aSrobert static void
dbxout_function_end(tree decl)905*404b540aSrobert dbxout_function_end (tree decl)
906*404b540aSrobert {
907*404b540aSrobert   char lscope_label_name[100];
908*404b540aSrobert 
909*404b540aSrobert   /* The Lscope label must be emitted even if we aren't doing anything
910*404b540aSrobert      else; dbxout_block needs it.  */
911*404b540aSrobert   switch_to_section (function_section (current_function_decl));
912*404b540aSrobert 
913*404b540aSrobert   /* Convert Lscope into the appropriate format for local labels in case
914*404b540aSrobert      the system doesn't insert underscores in front of user generated
915*404b540aSrobert      labels.  */
916*404b540aSrobert   ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
917*404b540aSrobert   targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
918*404b540aSrobert 
919*404b540aSrobert   /* The N_FUN tag at the end of the function is a GNU extension,
920*404b540aSrobert      which may be undesirable, and is unnecessary if we do not have
921*404b540aSrobert      named sections.  */
922*404b540aSrobert   if (!use_gnu_debug_info_extensions
923*404b540aSrobert       || NO_DBX_FUNCTION_END
924*404b540aSrobert       || !targetm.have_named_sections
925*404b540aSrobert       || DECL_IGNORED_P (decl))
926*404b540aSrobert     return;
927*404b540aSrobert 
928*404b540aSrobert   /* By convention, GCC will mark the end of a function with an N_FUN
929*404b540aSrobert      symbol and an empty string.  */
930*404b540aSrobert   if (flag_reorder_blocks_and_partition)
931*404b540aSrobert     {
932*404b540aSrobert       dbxout_begin_empty_stabs (N_FUN);
933*404b540aSrobert       dbxout_stab_value_label_diff (cfun->hot_section_end_label,
934*404b540aSrobert 				    cfun->hot_section_label);
935*404b540aSrobert       dbxout_begin_empty_stabs (N_FUN);
936*404b540aSrobert       dbxout_stab_value_label_diff (cfun->cold_section_end_label,
937*404b540aSrobert 				    cfun->cold_section_label);
938*404b540aSrobert     }
939*404b540aSrobert   else
940*404b540aSrobert     {
941*404b540aSrobert       char begin_label[20];
942*404b540aSrobert       /* Reference current function start using LFBB.  */
943*404b540aSrobert       ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
944*404b540aSrobert       dbxout_begin_empty_stabs (N_FUN);
945*404b540aSrobert       dbxout_stab_value_label_diff (lscope_label_name, begin_label);
946*404b540aSrobert     }
947*404b540aSrobert 
948*404b540aSrobert   if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
949*404b540aSrobert     dbxout_stabd (N_ENSYM, 0);
950*404b540aSrobert }
951*404b540aSrobert #endif /* DBX_DEBUGGING_INFO */
952*404b540aSrobert 
953*404b540aSrobert /* Get lang description for N_SO stab.  */
954*404b540aSrobert static unsigned int ATTRIBUTE_UNUSED
get_lang_number(void)955*404b540aSrobert get_lang_number (void)
956*404b540aSrobert {
957*404b540aSrobert   const char *language_string = lang_hooks.name;
958*404b540aSrobert 
959*404b540aSrobert   if (strcmp (language_string, "GNU C") == 0)
960*404b540aSrobert     return N_SO_C;
961*404b540aSrobert   else if (strcmp (language_string, "GNU C++") == 0)
962*404b540aSrobert     return N_SO_CC;
963*404b540aSrobert   else if (strcmp (language_string, "GNU F77") == 0)
964*404b540aSrobert     return N_SO_FORTRAN;
965*404b540aSrobert   else if (strcmp (language_string, "GNU F95") == 0)
966*404b540aSrobert     return N_SO_FORTRAN90; /* CHECKME */
967*404b540aSrobert   else if (strcmp (language_string, "GNU Pascal") == 0)
968*404b540aSrobert     return N_SO_PASCAL;
969*404b540aSrobert   else if (strcmp (language_string, "GNU Objective-C") == 0)
970*404b540aSrobert     return N_SO_OBJC;
971*404b540aSrobert   else if (strcmp (language_string, "GNU Objective-C++") == 0)
972*404b540aSrobert     return N_SO_OBJCPLUS;
973*404b540aSrobert   else
974*404b540aSrobert     return 0;
975*404b540aSrobert 
976*404b540aSrobert }
977*404b540aSrobert 
978*404b540aSrobert /* At the beginning of compilation, start writing the symbol table.
979*404b540aSrobert    Initialize `typevec' and output the standard data types of C.  */
980*404b540aSrobert 
981*404b540aSrobert static void
dbxout_init(const char * input_file_name)982*404b540aSrobert dbxout_init (const char *input_file_name)
983*404b540aSrobert {
984*404b540aSrobert   char ltext_label_name[100];
985*404b540aSrobert   bool used_ltext_label_name = false;
986*404b540aSrobert   tree syms = lang_hooks.decls.getdecls ();
987*404b540aSrobert 
988*404b540aSrobert   typevec_len = 100;
989*404b540aSrobert   typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
990*404b540aSrobert 
991*404b540aSrobert   /* stabstr_ob contains one string, which will be just fine with
992*404b540aSrobert      1-byte alignment.  */
993*404b540aSrobert   obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
994*404b540aSrobert 
995*404b540aSrobert   /* Convert Ltext into the appropriate format for local labels in case
996*404b540aSrobert      the system doesn't insert underscores in front of user generated
997*404b540aSrobert      labels.  */
998*404b540aSrobert   ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
999*404b540aSrobert 
1000*404b540aSrobert   /* Put the current working directory in an N_SO symbol.  */
1001*404b540aSrobert   if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
1002*404b540aSrobert     {
1003*404b540aSrobert       static const char *cwd;
1004*404b540aSrobert 
1005*404b540aSrobert       if (!cwd)
1006*404b540aSrobert 	{
1007*404b540aSrobert 	  cwd = get_src_pwd ();
1008*404b540aSrobert 	  if (cwd[0] == '\0')
1009*404b540aSrobert 	    cwd = "/";
1010*404b540aSrobert 	  else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
1011*404b540aSrobert 	    cwd = concat (cwd, "/", NULL);
1012*404b540aSrobert 	}
1013*404b540aSrobert #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
1014*404b540aSrobert       DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
1015*404b540aSrobert #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1016*404b540aSrobert       dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
1017*404b540aSrobert       dbxout_stab_value_label (ltext_label_name);
1018*404b540aSrobert       used_ltext_label_name = true;
1019*404b540aSrobert #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1020*404b540aSrobert     }
1021*404b540aSrobert 
1022*404b540aSrobert #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1023*404b540aSrobert   DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, input_file_name);
1024*404b540aSrobert #else
1025*404b540aSrobert   dbxout_begin_simple_stabs_desc (input_file_name, N_SO, get_lang_number ());
1026*404b540aSrobert   dbxout_stab_value_label (ltext_label_name);
1027*404b540aSrobert   used_ltext_label_name = true;
1028*404b540aSrobert #endif
1029*404b540aSrobert 
1030*404b540aSrobert   if (used_ltext_label_name)
1031*404b540aSrobert     {
1032*404b540aSrobert       switch_to_section (text_section);
1033*404b540aSrobert       targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1034*404b540aSrobert     }
1035*404b540aSrobert 
1036*404b540aSrobert   /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1037*404b540aSrobert      The string used is historical.  */
1038*404b540aSrobert #ifndef NO_DBX_GCC_MARKER
1039*404b540aSrobert   dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1040*404b540aSrobert   dbxout_stab_value_zero ();
1041*404b540aSrobert #endif
1042*404b540aSrobert 
1043*404b540aSrobert   base_input_file = lastfile = input_file_name;
1044*404b540aSrobert 
1045*404b540aSrobert   next_type_number = 1;
1046*404b540aSrobert 
1047*404b540aSrobert #ifdef DBX_USE_BINCL
1048*404b540aSrobert   current_file = XNEW (struct dbx_file);
1049*404b540aSrobert   current_file->next = NULL;
1050*404b540aSrobert   current_file->file_number = 0;
1051*404b540aSrobert   current_file->next_type_number = 1;
1052*404b540aSrobert   next_file_number = 1;
1053*404b540aSrobert   current_file->prev = NULL;
1054*404b540aSrobert   current_file->bincl_status = BINCL_NOT_REQUIRED;
1055*404b540aSrobert   current_file->pending_bincl_name = NULL;
1056*404b540aSrobert #endif
1057*404b540aSrobert 
1058*404b540aSrobert   /* Get all permanent types that have typedef names, and output them
1059*404b540aSrobert      all, except for those already output.  Some language front ends
1060*404b540aSrobert      put these declarations in the top-level scope; some do not;
1061*404b540aSrobert      the latter are responsible for calling debug_hooks->type_decl from
1062*404b540aSrobert      their record_builtin_type function.  */
1063*404b540aSrobert   dbxout_typedefs (syms);
1064*404b540aSrobert 
1065*404b540aSrobert   if (preinit_symbols)
1066*404b540aSrobert     {
1067*404b540aSrobert       tree t;
1068*404b540aSrobert       for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1069*404b540aSrobert 	dbxout_symbol (TREE_VALUE (t), 0);
1070*404b540aSrobert       preinit_symbols = 0;
1071*404b540aSrobert     }
1072*404b540aSrobert }
1073*404b540aSrobert 
1074*404b540aSrobert /* Output any typedef names for types described by TYPE_DECLs in SYMS.  */
1075*404b540aSrobert 
1076*404b540aSrobert static void
dbxout_typedefs(tree syms)1077*404b540aSrobert dbxout_typedefs (tree syms)
1078*404b540aSrobert {
1079*404b540aSrobert   for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
1080*404b540aSrobert     {
1081*404b540aSrobert       if (TREE_CODE (syms) == TYPE_DECL)
1082*404b540aSrobert 	{
1083*404b540aSrobert 	  tree type = TREE_TYPE (syms);
1084*404b540aSrobert 	  if (TYPE_NAME (type)
1085*404b540aSrobert 	      && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1086*404b540aSrobert 	      && COMPLETE_OR_VOID_TYPE_P (type)
1087*404b540aSrobert 	      && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
1088*404b540aSrobert 	    dbxout_symbol (TYPE_NAME (type), 0);
1089*404b540aSrobert 	}
1090*404b540aSrobert     }
1091*404b540aSrobert }
1092*404b540aSrobert 
1093*404b540aSrobert #ifdef DBX_USE_BINCL
1094*404b540aSrobert /* Emit BINCL stab using given name.  */
1095*404b540aSrobert static void
emit_bincl_stab(const char * name)1096*404b540aSrobert emit_bincl_stab (const char *name)
1097*404b540aSrobert {
1098*404b540aSrobert   dbxout_begin_simple_stabs (name, N_BINCL);
1099*404b540aSrobert   dbxout_stab_value_zero ();
1100*404b540aSrobert }
1101*404b540aSrobert 
1102*404b540aSrobert /* If there are pending bincls then it is time to emit all of them.  */
1103*404b540aSrobert 
1104*404b540aSrobert static inline void
emit_pending_bincls_if_required(void)1105*404b540aSrobert emit_pending_bincls_if_required (void)
1106*404b540aSrobert {
1107*404b540aSrobert   if (pending_bincls)
1108*404b540aSrobert     emit_pending_bincls ();
1109*404b540aSrobert }
1110*404b540aSrobert 
1111*404b540aSrobert /* Emit all pending bincls.  */
1112*404b540aSrobert 
1113*404b540aSrobert static void
emit_pending_bincls(void)1114*404b540aSrobert emit_pending_bincls (void)
1115*404b540aSrobert {
1116*404b540aSrobert   struct dbx_file *f = current_file;
1117*404b540aSrobert 
1118*404b540aSrobert   /* Find first pending bincl.  */
1119*404b540aSrobert   while (f->bincl_status == BINCL_PENDING)
1120*404b540aSrobert     f = f->next;
1121*404b540aSrobert 
1122*404b540aSrobert   /* Now emit all bincls.  */
1123*404b540aSrobert   f = f->prev;
1124*404b540aSrobert 
1125*404b540aSrobert   while (f)
1126*404b540aSrobert     {
1127*404b540aSrobert       if (f->bincl_status == BINCL_PENDING)
1128*404b540aSrobert         {
1129*404b540aSrobert           emit_bincl_stab (f->pending_bincl_name);
1130*404b540aSrobert 
1131*404b540aSrobert 	  /* Update file number and status.  */
1132*404b540aSrobert           f->file_number = next_file_number++;
1133*404b540aSrobert           f->bincl_status = BINCL_PROCESSED;
1134*404b540aSrobert         }
1135*404b540aSrobert       if (f == current_file)
1136*404b540aSrobert         break;
1137*404b540aSrobert       f = f->prev;
1138*404b540aSrobert     }
1139*404b540aSrobert 
1140*404b540aSrobert   /* All pending bincls have been emitted.  */
1141*404b540aSrobert   pending_bincls = 0;
1142*404b540aSrobert }
1143*404b540aSrobert 
1144*404b540aSrobert #else
1145*404b540aSrobert 
1146*404b540aSrobert static inline void
emit_pending_bincls_if_required(void)1147*404b540aSrobert emit_pending_bincls_if_required (void) {}
1148*404b540aSrobert #endif
1149*404b540aSrobert 
1150*404b540aSrobert /* Change to reading from a new source file.  Generate a N_BINCL stab.  */
1151*404b540aSrobert 
1152*404b540aSrobert static void
dbxout_start_source_file(unsigned int line ATTRIBUTE_UNUSED,const char * filename ATTRIBUTE_UNUSED)1153*404b540aSrobert dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1154*404b540aSrobert 			  const char *filename ATTRIBUTE_UNUSED)
1155*404b540aSrobert {
1156*404b540aSrobert #ifdef DBX_USE_BINCL
1157*404b540aSrobert   struct dbx_file *n = XNEW (struct dbx_file);
1158*404b540aSrobert 
1159*404b540aSrobert   n->next = current_file;
1160*404b540aSrobert   n->next_type_number = 1;
1161*404b540aSrobert   /* Do not assign file number now.
1162*404b540aSrobert      Delay it until we actually emit BINCL.  */
1163*404b540aSrobert   n->file_number = 0;
1164*404b540aSrobert   n->prev = NULL;
1165*404b540aSrobert   current_file->prev = n;
1166*404b540aSrobert   n->bincl_status = BINCL_PENDING;
1167*404b540aSrobert   n->pending_bincl_name = filename;
1168*404b540aSrobert   pending_bincls = 1;
1169*404b540aSrobert   current_file = n;
1170*404b540aSrobert #endif
1171*404b540aSrobert }
1172*404b540aSrobert 
1173*404b540aSrobert /* Revert to reading a previous source file.  Generate a N_EINCL stab.  */
1174*404b540aSrobert 
1175*404b540aSrobert static void
dbxout_end_source_file(unsigned int line ATTRIBUTE_UNUSED)1176*404b540aSrobert dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1177*404b540aSrobert {
1178*404b540aSrobert #ifdef DBX_USE_BINCL
1179*404b540aSrobert   /* Emit EINCL stab only if BINCL is not pending.  */
1180*404b540aSrobert   if (current_file->bincl_status == BINCL_PROCESSED)
1181*404b540aSrobert     {
1182*404b540aSrobert       dbxout_begin_stabn (N_EINCL);
1183*404b540aSrobert       dbxout_stab_value_zero ();
1184*404b540aSrobert     }
1185*404b540aSrobert   current_file->bincl_status = BINCL_NOT_REQUIRED;
1186*404b540aSrobert   current_file = current_file->next;
1187*404b540aSrobert #endif
1188*404b540aSrobert }
1189*404b540aSrobert 
1190*404b540aSrobert /* Handle a few odd cases that occur when trying to make PCH files work.  */
1191*404b540aSrobert 
1192*404b540aSrobert static void
dbxout_handle_pch(unsigned at_end)1193*404b540aSrobert dbxout_handle_pch (unsigned at_end)
1194*404b540aSrobert {
1195*404b540aSrobert   if (! at_end)
1196*404b540aSrobert     {
1197*404b540aSrobert       /* When using the PCH, this file will be included, so we need to output
1198*404b540aSrobert 	 a BINCL.  */
1199*404b540aSrobert       dbxout_start_source_file (0, lastfile);
1200*404b540aSrobert 
1201*404b540aSrobert       /* The base file when using the PCH won't be the same as
1202*404b540aSrobert 	 the base file when it's being generated.  */
1203*404b540aSrobert       lastfile = NULL;
1204*404b540aSrobert     }
1205*404b540aSrobert   else
1206*404b540aSrobert     {
1207*404b540aSrobert       /* ... and an EINCL.  */
1208*404b540aSrobert       dbxout_end_source_file (0);
1209*404b540aSrobert 
1210*404b540aSrobert       /* Deal with cases where 'lastfile' was never actually changed.  */
1211*404b540aSrobert       lastfile_is_base = lastfile == NULL;
1212*404b540aSrobert     }
1213*404b540aSrobert }
1214*404b540aSrobert 
1215*404b540aSrobert #if defined (DBX_DEBUGGING_INFO)
1216*404b540aSrobert /* Output debugging info to FILE to switch to sourcefile FILENAME.  */
1217*404b540aSrobert 
1218*404b540aSrobert static void
dbxout_source_file(const char * filename)1219*404b540aSrobert dbxout_source_file (const char *filename)
1220*404b540aSrobert {
1221*404b540aSrobert   if (lastfile == 0 && lastfile_is_base)
1222*404b540aSrobert     {
1223*404b540aSrobert       lastfile = base_input_file;
1224*404b540aSrobert       lastfile_is_base = 0;
1225*404b540aSrobert     }
1226*404b540aSrobert 
1227*404b540aSrobert   if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
1228*404b540aSrobert     {
1229*404b540aSrobert       /* Don't change section amid function.  */
1230*404b540aSrobert       if (current_function_decl == NULL_TREE)
1231*404b540aSrobert 	switch_to_section (text_section);
1232*404b540aSrobert 
1233*404b540aSrobert       dbxout_begin_simple_stabs (filename, N_SOL);
1234*404b540aSrobert       dbxout_stab_value_internal_label ("Ltext", &source_label_number);
1235*404b540aSrobert       lastfile = filename;
1236*404b540aSrobert     }
1237*404b540aSrobert }
1238*404b540aSrobert 
1239*404b540aSrobert /* Output N_BNSYM, line number symbol entry, and local symbol at
1240*404b540aSrobert    function scope  */
1241*404b540aSrobert 
1242*404b540aSrobert static void
dbxout_begin_prologue(unsigned int lineno,const char * filename)1243*404b540aSrobert dbxout_begin_prologue (unsigned int lineno, const char *filename)
1244*404b540aSrobert {
1245*404b540aSrobert   if (use_gnu_debug_info_extensions
1246*404b540aSrobert       && !NO_DBX_FUNCTION_END
1247*404b540aSrobert       && !NO_DBX_BNSYM_ENSYM
1248*404b540aSrobert       && !flag_debug_only_used_symbols)
1249*404b540aSrobert     dbxout_stabd (N_BNSYM, 0);
1250*404b540aSrobert 
1251*404b540aSrobert   /* pre-increment the scope counter */
1252*404b540aSrobert   scope_labelno++;
1253*404b540aSrobert 
1254*404b540aSrobert   dbxout_source_line (lineno, filename);
1255*404b540aSrobert   /* Output function begin block at function scope, referenced
1256*404b540aSrobert      by dbxout_block, dbxout_source_line and dbxout_function_end.  */
1257*404b540aSrobert   emit_pending_bincls_if_required ();
1258*404b540aSrobert   targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno);
1259*404b540aSrobert }
1260*404b540aSrobert 
1261*404b540aSrobert /* Output a line number symbol entry for source file FILENAME and line
1262*404b540aSrobert    number LINENO.  */
1263*404b540aSrobert 
1264*404b540aSrobert static void
dbxout_source_line(unsigned int lineno,const char * filename)1265*404b540aSrobert dbxout_source_line (unsigned int lineno, const char *filename)
1266*404b540aSrobert {
1267*404b540aSrobert   dbxout_source_file (filename);
1268*404b540aSrobert 
1269*404b540aSrobert #ifdef DBX_OUTPUT_SOURCE_LINE
1270*404b540aSrobert   DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
1271*404b540aSrobert #else
1272*404b540aSrobert   if (DBX_LINES_FUNCTION_RELATIVE)
1273*404b540aSrobert     {
1274*404b540aSrobert       char begin_label[20];
1275*404b540aSrobert       dbxout_begin_stabn_sline (lineno);
1276*404b540aSrobert       /* Reference current function start using LFBB.  */
1277*404b540aSrobert       ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
1278*404b540aSrobert       dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
1279*404b540aSrobert 					     begin_label);
1280*404b540aSrobert     }
1281*404b540aSrobert   else
1282*404b540aSrobert     dbxout_stabd (N_SLINE, lineno);
1283*404b540aSrobert #endif
1284*404b540aSrobert }
1285*404b540aSrobert 
1286*404b540aSrobert /* Describe the beginning of an internal block within a function.  */
1287*404b540aSrobert 
1288*404b540aSrobert static void
dbxout_begin_block(unsigned int line ATTRIBUTE_UNUSED,unsigned int n)1289*404b540aSrobert dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1290*404b540aSrobert {
1291*404b540aSrobert   emit_pending_bincls_if_required ();
1292*404b540aSrobert   targetm.asm_out.internal_label (asm_out_file, "LBB", n);
1293*404b540aSrobert }
1294*404b540aSrobert 
1295*404b540aSrobert /* Describe the end line-number of an internal block within a function.  */
1296*404b540aSrobert 
1297*404b540aSrobert static void
dbxout_end_block(unsigned int line ATTRIBUTE_UNUSED,unsigned int n)1298*404b540aSrobert dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1299*404b540aSrobert {
1300*404b540aSrobert   emit_pending_bincls_if_required ();
1301*404b540aSrobert   targetm.asm_out.internal_label (asm_out_file, "LBE", n);
1302*404b540aSrobert }
1303*404b540aSrobert 
1304*404b540aSrobert /* Output dbx data for a function definition.
1305*404b540aSrobert    This includes a definition of the function name itself (a symbol),
1306*404b540aSrobert    definitions of the parameters (locating them in the parameter list)
1307*404b540aSrobert    and then output the block that makes up the function's body
1308*404b540aSrobert    (including all the auto variables of the function).  */
1309*404b540aSrobert 
1310*404b540aSrobert static void
dbxout_function_decl(tree decl)1311*404b540aSrobert dbxout_function_decl (tree decl)
1312*404b540aSrobert {
1313*404b540aSrobert   emit_pending_bincls_if_required ();
1314*404b540aSrobert #ifndef DBX_FUNCTION_FIRST
1315*404b540aSrobert   dbxout_begin_function (decl);
1316*404b540aSrobert #endif
1317*404b540aSrobert   dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1318*404b540aSrobert   dbxout_function_end (decl);
1319*404b540aSrobert }
1320*404b540aSrobert 
1321*404b540aSrobert #endif /* DBX_DEBUGGING_INFO  */
1322*404b540aSrobert 
1323*404b540aSrobert /* Debug information for a global DECL.  Called from toplev.c after
1324*404b540aSrobert    compilation proper has finished.  */
1325*404b540aSrobert static void
dbxout_global_decl(tree decl)1326*404b540aSrobert dbxout_global_decl (tree decl)
1327*404b540aSrobert {
1328*404b540aSrobert   if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
1329*404b540aSrobert     {
1330*404b540aSrobert       int saved_tree_used = TREE_USED (decl);
1331*404b540aSrobert       TREE_USED (decl) = 1;
1332*404b540aSrobert       dbxout_symbol (decl, 0);
1333*404b540aSrobert       TREE_USED (decl) = saved_tree_used;
1334*404b540aSrobert     }
1335*404b540aSrobert }
1336*404b540aSrobert 
1337*404b540aSrobert /* This is just a function-type adapter; dbxout_symbol does exactly
1338*404b540aSrobert    what we want but returns an int.  */
1339*404b540aSrobert static void
dbxout_type_decl(tree decl,int local)1340*404b540aSrobert dbxout_type_decl (tree decl, int local)
1341*404b540aSrobert {
1342*404b540aSrobert   dbxout_symbol (decl, local);
1343*404b540aSrobert }
1344*404b540aSrobert 
1345*404b540aSrobert /* At the end of compilation, finish writing the symbol table.
1346*404b540aSrobert    The default is to call debug_free_queue but do nothing else.  */
1347*404b540aSrobert 
1348*404b540aSrobert static void
dbxout_finish(const char * filename ATTRIBUTE_UNUSED)1349*404b540aSrobert dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
1350*404b540aSrobert {
1351*404b540aSrobert #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1352*404b540aSrobert   DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1353*404b540aSrobert #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1354*404b540aSrobert  {
1355*404b540aSrobert    switch_to_section (text_section);
1356*404b540aSrobert    dbxout_begin_empty_stabs (N_SO);
1357*404b540aSrobert    dbxout_stab_value_internal_label ("Letext", 0);
1358*404b540aSrobert  }
1359*404b540aSrobert #endif
1360*404b540aSrobert   debug_free_queue ();
1361*404b540aSrobert }
1362*404b540aSrobert 
1363*404b540aSrobert /* Output the index of a type.  */
1364*404b540aSrobert 
1365*404b540aSrobert static void
dbxout_type_index(tree type)1366*404b540aSrobert dbxout_type_index (tree type)
1367*404b540aSrobert {
1368*404b540aSrobert #ifndef DBX_USE_BINCL
1369*404b540aSrobert   stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1370*404b540aSrobert #else
1371*404b540aSrobert   struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1372*404b540aSrobert   stabstr_C ('(');
1373*404b540aSrobert   stabstr_D (t->file_number);
1374*404b540aSrobert   stabstr_C (',');
1375*404b540aSrobert   stabstr_D (t->type_number);
1376*404b540aSrobert   stabstr_C (')');
1377*404b540aSrobert #endif
1378*404b540aSrobert }
1379*404b540aSrobert 
1380*404b540aSrobert 
1381*404b540aSrobert 
1382*404b540aSrobert /* Used in several places: evaluates to '0' for a private decl,
1383*404b540aSrobert    '1' for a protected decl, '2' for a public decl.  */
1384*404b540aSrobert #define DECL_ACCESSIBILITY_CHAR(DECL) \
1385*404b540aSrobert (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1386*404b540aSrobert 
1387*404b540aSrobert /* Subroutine of `dbxout_type'.  Output the type fields of TYPE.
1388*404b540aSrobert    This must be a separate function because anonymous unions require
1389*404b540aSrobert    recursive calls.  */
1390*404b540aSrobert 
1391*404b540aSrobert static void
dbxout_type_fields(tree type)1392*404b540aSrobert dbxout_type_fields (tree type)
1393*404b540aSrobert {
1394*404b540aSrobert   tree tem;
1395*404b540aSrobert 
1396*404b540aSrobert   /* Output the name, type, position (in bits), size (in bits) of each
1397*404b540aSrobert      field that we can support.  */
1398*404b540aSrobert   for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1399*404b540aSrobert     {
1400*404b540aSrobert       /* If one of the nodes is an error_mark or its type is then
1401*404b540aSrobert 	 return early.  */
1402*404b540aSrobert       if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
1403*404b540aSrobert 	return;
1404*404b540aSrobert 
1405*404b540aSrobert       /* Omit here local type decls until we know how to support them.  */
1406*404b540aSrobert       if (TREE_CODE (tem) == TYPE_DECL
1407*404b540aSrobert 	  /* Omit here the nameless fields that are used to skip bits.  */
1408*404b540aSrobert 	  || DECL_IGNORED_P (tem)
1409*404b540aSrobert 	  /* Omit fields whose position or size are variable or too large to
1410*404b540aSrobert 	     represent.  */
1411*404b540aSrobert 	  || (TREE_CODE (tem) == FIELD_DECL
1412*404b540aSrobert 	      && (! host_integerp (bit_position (tem), 0)
1413*404b540aSrobert 		  || ! DECL_SIZE (tem)
1414*404b540aSrobert 		  || ! host_integerp (DECL_SIZE (tem), 1))))
1415*404b540aSrobert 	continue;
1416*404b540aSrobert 
1417*404b540aSrobert       else if (TREE_CODE (tem) != CONST_DECL)
1418*404b540aSrobert 	{
1419*404b540aSrobert 	  /* Continue the line if necessary,
1420*404b540aSrobert 	     but not before the first field.  */
1421*404b540aSrobert 	  if (tem != TYPE_FIELDS (type))
1422*404b540aSrobert 	    CONTIN;
1423*404b540aSrobert 
1424*404b540aSrobert 	  if (DECL_NAME (tem))
1425*404b540aSrobert 	    stabstr_I (DECL_NAME (tem));
1426*404b540aSrobert 	  stabstr_C (':');
1427*404b540aSrobert 
1428*404b540aSrobert 	  if (use_gnu_debug_info_extensions
1429*404b540aSrobert 	      && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1430*404b540aSrobert 		  || TREE_CODE (tem) != FIELD_DECL))
1431*404b540aSrobert 	    {
1432*404b540aSrobert 	      stabstr_C ('/');
1433*404b540aSrobert 	      stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
1434*404b540aSrobert 	    }
1435*404b540aSrobert 
1436*404b540aSrobert 	  dbxout_type ((TREE_CODE (tem) == FIELD_DECL
1437*404b540aSrobert 			&& DECL_BIT_FIELD_TYPE (tem))
1438*404b540aSrobert 		       ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
1439*404b540aSrobert 
1440*404b540aSrobert 	  if (TREE_CODE (tem) == VAR_DECL)
1441*404b540aSrobert 	    {
1442*404b540aSrobert 	      if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
1443*404b540aSrobert 		{
1444*404b540aSrobert 		  tree name = DECL_ASSEMBLER_NAME (tem);
1445*404b540aSrobert 
1446*404b540aSrobert 		  stabstr_C (':');
1447*404b540aSrobert 		  stabstr_I (name);
1448*404b540aSrobert 		  stabstr_C (';');
1449*404b540aSrobert 		}
1450*404b540aSrobert 	      else
1451*404b540aSrobert 		/* If TEM is non-static, GDB won't understand it.  */
1452*404b540aSrobert 		stabstr_S (",0,0;");
1453*404b540aSrobert 	    }
1454*404b540aSrobert 	  else
1455*404b540aSrobert 	    {
1456*404b540aSrobert 	      stabstr_C (',');
1457*404b540aSrobert 	      stabstr_D (int_bit_position (tem));
1458*404b540aSrobert 	      stabstr_C (',');
1459*404b540aSrobert 	      stabstr_D (tree_low_cst (DECL_SIZE (tem), 1));
1460*404b540aSrobert 	      stabstr_C (';');
1461*404b540aSrobert 	    }
1462*404b540aSrobert 	}
1463*404b540aSrobert     }
1464*404b540aSrobert }
1465*404b540aSrobert 
1466*404b540aSrobert /* Subroutine of `dbxout_type_methods'.  Output debug info about the
1467*404b540aSrobert    method described DECL.  */
1468*404b540aSrobert 
1469*404b540aSrobert static void
dbxout_type_method_1(tree decl)1470*404b540aSrobert dbxout_type_method_1 (tree decl)
1471*404b540aSrobert {
1472*404b540aSrobert   char c1 = 'A', c2;
1473*404b540aSrobert 
1474*404b540aSrobert   if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1475*404b540aSrobert     c2 = '?';
1476*404b540aSrobert   else /* it's a METHOD_TYPE.  */
1477*404b540aSrobert     {
1478*404b540aSrobert       tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1479*404b540aSrobert       /* A for normal functions.
1480*404b540aSrobert 	 B for `const' member functions.
1481*404b540aSrobert 	 C for `volatile' member functions.
1482*404b540aSrobert 	 D for `const volatile' member functions.  */
1483*404b540aSrobert       if (TYPE_READONLY (TREE_TYPE (firstarg)))
1484*404b540aSrobert 	c1 += 1;
1485*404b540aSrobert       if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1486*404b540aSrobert 	c1 += 2;
1487*404b540aSrobert 
1488*404b540aSrobert       if (DECL_VINDEX (decl))
1489*404b540aSrobert 	c2 = '*';
1490*404b540aSrobert       else
1491*404b540aSrobert 	c2 = '.';
1492*404b540aSrobert     }
1493*404b540aSrobert 
1494*404b540aSrobert   /* ??? Output the mangled name, which contains an encoding of the
1495*404b540aSrobert      method's type signature.  May not be necessary anymore.  */
1496*404b540aSrobert   stabstr_C (':');
1497*404b540aSrobert   stabstr_I (DECL_ASSEMBLER_NAME (decl));
1498*404b540aSrobert   stabstr_C (';');
1499*404b540aSrobert   stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1500*404b540aSrobert   stabstr_C (c1);
1501*404b540aSrobert   stabstr_C (c2);
1502*404b540aSrobert 
1503*404b540aSrobert   if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1504*404b540aSrobert     {
1505*404b540aSrobert       stabstr_D (tree_low_cst (DECL_VINDEX (decl), 0));
1506*404b540aSrobert       stabstr_C (';');
1507*404b540aSrobert       dbxout_type (DECL_CONTEXT (decl), 0);
1508*404b540aSrobert       stabstr_C (';');
1509*404b540aSrobert     }
1510*404b540aSrobert }
1511*404b540aSrobert 
1512*404b540aSrobert /* Subroutine of `dbxout_type'.  Output debug info about the methods defined
1513*404b540aSrobert    in TYPE.  */
1514*404b540aSrobert 
1515*404b540aSrobert static void
dbxout_type_methods(tree type)1516*404b540aSrobert dbxout_type_methods (tree type)
1517*404b540aSrobert {
1518*404b540aSrobert   /* C++: put out the method names and their parameter lists */
1519*404b540aSrobert   tree methods = TYPE_METHODS (type);
1520*404b540aSrobert   tree fndecl;
1521*404b540aSrobert   tree last;
1522*404b540aSrobert 
1523*404b540aSrobert   if (methods == NULL_TREE)
1524*404b540aSrobert     return;
1525*404b540aSrobert 
1526*404b540aSrobert   if (TREE_CODE (methods) != TREE_VEC)
1527*404b540aSrobert     fndecl = methods;
1528*404b540aSrobert   else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1529*404b540aSrobert     fndecl = TREE_VEC_ELT (methods, 0);
1530*404b540aSrobert   else
1531*404b540aSrobert     fndecl = TREE_VEC_ELT (methods, 1);
1532*404b540aSrobert 
1533*404b540aSrobert   while (fndecl)
1534*404b540aSrobert     {
1535*404b540aSrobert       int need_prefix = 1;
1536*404b540aSrobert 
1537*404b540aSrobert       /* Group together all the methods for the same operation.
1538*404b540aSrobert 	 These differ in the types of the arguments.  */
1539*404b540aSrobert       for (last = NULL_TREE;
1540*404b540aSrobert 	   fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1541*404b540aSrobert 	   fndecl = TREE_CHAIN (fndecl))
1542*404b540aSrobert 	/* Output the name of the field (after overloading), as
1543*404b540aSrobert 	   well as the name of the field before overloading, along
1544*404b540aSrobert 	   with its parameter list */
1545*404b540aSrobert 	{
1546*404b540aSrobert 	  /* Skip methods that aren't FUNCTION_DECLs.  (In C++, these
1547*404b540aSrobert 	     include TEMPLATE_DECLs.)  The debugger doesn't know what
1548*404b540aSrobert 	     to do with such entities anyhow.  */
1549*404b540aSrobert 	  if (TREE_CODE (fndecl) != FUNCTION_DECL)
1550*404b540aSrobert 	    continue;
1551*404b540aSrobert 
1552*404b540aSrobert 	  CONTIN;
1553*404b540aSrobert 
1554*404b540aSrobert 	  last = fndecl;
1555*404b540aSrobert 
1556*404b540aSrobert 	  /* Also ignore abstract methods; those are only interesting to
1557*404b540aSrobert 	     the DWARF backends.  */
1558*404b540aSrobert 	  if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1559*404b540aSrobert 	    continue;
1560*404b540aSrobert 
1561*404b540aSrobert 	  /* Redundantly output the plain name, since that's what gdb
1562*404b540aSrobert 	     expects.  */
1563*404b540aSrobert 	  if (need_prefix)
1564*404b540aSrobert 	    {
1565*404b540aSrobert 	      stabstr_I (DECL_NAME (fndecl));
1566*404b540aSrobert 	      stabstr_S ("::");
1567*404b540aSrobert 	      need_prefix = 0;
1568*404b540aSrobert 	    }
1569*404b540aSrobert 
1570*404b540aSrobert 	  dbxout_type (TREE_TYPE (fndecl), 0);
1571*404b540aSrobert 	  dbxout_type_method_1 (fndecl);
1572*404b540aSrobert 	}
1573*404b540aSrobert       if (!need_prefix)
1574*404b540aSrobert 	stabstr_C (';');
1575*404b540aSrobert     }
1576*404b540aSrobert }
1577*404b540aSrobert 
1578*404b540aSrobert /* Emit a "range" type specification, which has the form:
1579*404b540aSrobert    "r<index type>;<lower bound>;<upper bound>;".
1580*404b540aSrobert    TYPE is an INTEGER_TYPE.  */
1581*404b540aSrobert 
1582*404b540aSrobert static void
dbxout_range_type(tree type)1583*404b540aSrobert dbxout_range_type (tree type)
1584*404b540aSrobert {
1585*404b540aSrobert   stabstr_C ('r');
1586*404b540aSrobert   if (TREE_TYPE (type))
1587*404b540aSrobert     dbxout_type (TREE_TYPE (type), 0);
1588*404b540aSrobert   else if (TREE_CODE (type) != INTEGER_TYPE)
1589*404b540aSrobert     dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1590*404b540aSrobert   else
1591*404b540aSrobert     {
1592*404b540aSrobert       /* Traditionally, we made sure 'int' was type 1, and builtin types
1593*404b540aSrobert 	 were defined to be sub-ranges of int.  Unfortunately, this
1594*404b540aSrobert 	 does not allow us to distinguish true sub-ranges from integer
1595*404b540aSrobert 	 types.  So, instead we define integer (non-sub-range) types as
1596*404b540aSrobert 	 sub-ranges of themselves.  This matters for Chill.  If this isn't
1597*404b540aSrobert 	 a subrange type, then we want to define it in terms of itself.
1598*404b540aSrobert 	 However, in C, this may be an anonymous integer type, and we don't
1599*404b540aSrobert 	 want to emit debug info referring to it.  Just calling
1600*404b540aSrobert 	 dbxout_type_index won't work anyways, because the type hasn't been
1601*404b540aSrobert 	 defined yet.  We make this work for both cases by checked to see
1602*404b540aSrobert 	 whether this is a defined type, referring to it if it is, and using
1603*404b540aSrobert 	 'int' otherwise.  */
1604*404b540aSrobert       if (TYPE_SYMTAB_ADDRESS (type) != 0)
1605*404b540aSrobert 	dbxout_type_index (type);
1606*404b540aSrobert       else
1607*404b540aSrobert 	dbxout_type_index (integer_type_node);
1608*404b540aSrobert     }
1609*404b540aSrobert 
1610*404b540aSrobert   stabstr_C (';');
1611*404b540aSrobert   if (TYPE_MIN_VALUE (type) != 0
1612*404b540aSrobert       && host_integerp (TYPE_MIN_VALUE (type), 0))
1613*404b540aSrobert     {
1614*404b540aSrobert       if (print_int_cst_bounds_in_octal_p (type))
1615*404b540aSrobert         stabstr_O (TYPE_MIN_VALUE (type));
1616*404b540aSrobert       else
1617*404b540aSrobert         stabstr_D (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1618*404b540aSrobert     }
1619*404b540aSrobert   else
1620*404b540aSrobert     stabstr_C ('0');
1621*404b540aSrobert 
1622*404b540aSrobert   stabstr_C (';');
1623*404b540aSrobert   if (TYPE_MAX_VALUE (type) != 0
1624*404b540aSrobert       && host_integerp (TYPE_MAX_VALUE (type), 0))
1625*404b540aSrobert     {
1626*404b540aSrobert       if (print_int_cst_bounds_in_octal_p (type))
1627*404b540aSrobert         stabstr_O (TYPE_MAX_VALUE (type));
1628*404b540aSrobert       else
1629*404b540aSrobert         stabstr_D (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1630*404b540aSrobert       stabstr_C (';');
1631*404b540aSrobert     }
1632*404b540aSrobert   else
1633*404b540aSrobert     stabstr_S ("-1;");
1634*404b540aSrobert }
1635*404b540aSrobert 
1636*404b540aSrobert 
1637*404b540aSrobert /* Output a reference to a type.  If the type has not yet been
1638*404b540aSrobert    described in the dbx output, output its definition now.
1639*404b540aSrobert    For a type already defined, just refer to its definition
1640*404b540aSrobert    using the type number.
1641*404b540aSrobert 
1642*404b540aSrobert    If FULL is nonzero, and the type has been described only with
1643*404b540aSrobert    a forward-reference, output the definition now.
1644*404b540aSrobert    If FULL is zero in this case, just refer to the forward-reference
1645*404b540aSrobert    using the number previously allocated.  */
1646*404b540aSrobert 
1647*404b540aSrobert static void
dbxout_type(tree type,int full)1648*404b540aSrobert dbxout_type (tree type, int full)
1649*404b540aSrobert {
1650*404b540aSrobert   tree tem;
1651*404b540aSrobert   tree main_variant;
1652*404b540aSrobert   static int anonymous_type_number = 0;
1653*404b540aSrobert   bool vector_type = false;
1654*404b540aSrobert 
1655*404b540aSrobert   if (TREE_CODE (type) == VECTOR_TYPE)
1656*404b540aSrobert     {
1657*404b540aSrobert       /* The frontend feeds us a representation for the vector as a struct
1658*404b540aSrobert 	 containing an array.  Pull out the array type.  */
1659*404b540aSrobert       type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1660*404b540aSrobert       vector_type = true;
1661*404b540aSrobert     }
1662*404b540aSrobert 
1663*404b540aSrobert   /* If there was an input error and we don't really have a type,
1664*404b540aSrobert      avoid crashing and write something that is at least valid
1665*404b540aSrobert      by assuming `int'.  */
1666*404b540aSrobert   if (type == error_mark_node)
1667*404b540aSrobert     type = integer_type_node;
1668*404b540aSrobert   else
1669*404b540aSrobert     {
1670*404b540aSrobert       if (TYPE_NAME (type)
1671*404b540aSrobert 	  && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1672*404b540aSrobert 	  && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1673*404b540aSrobert 	full = 0;
1674*404b540aSrobert     }
1675*404b540aSrobert 
1676*404b540aSrobert   /* Try to find the "main variant" with the same name.  */
1677*404b540aSrobert   if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1678*404b540aSrobert       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1679*404b540aSrobert     main_variant = TREE_TYPE (TYPE_NAME (type));
1680*404b540aSrobert   else
1681*404b540aSrobert     main_variant = TYPE_MAIN_VARIANT (type);
1682*404b540aSrobert 
1683*404b540aSrobert   /* If we are not using extensions, stabs does not distinguish const and
1684*404b540aSrobert      volatile, so there is no need to make them separate types.  */
1685*404b540aSrobert   if (!use_gnu_debug_info_extensions)
1686*404b540aSrobert     type = main_variant;
1687*404b540aSrobert 
1688*404b540aSrobert   if (TYPE_SYMTAB_ADDRESS (type) == 0)
1689*404b540aSrobert     {
1690*404b540aSrobert       /* Type has no dbx number assigned.  Assign next available number.  */
1691*404b540aSrobert       TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1692*404b540aSrobert 
1693*404b540aSrobert       /* Make sure type vector is long enough to record about this type.  */
1694*404b540aSrobert 
1695*404b540aSrobert       if (next_type_number == typevec_len)
1696*404b540aSrobert 	{
1697*404b540aSrobert 	  typevec
1698*404b540aSrobert 	    = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1699*404b540aSrobert 	  memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1700*404b540aSrobert 	  typevec_len *= 2;
1701*404b540aSrobert 	}
1702*404b540aSrobert 
1703*404b540aSrobert #ifdef DBX_USE_BINCL
1704*404b540aSrobert       emit_pending_bincls_if_required ();
1705*404b540aSrobert       typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1706*404b540aSrobert 	= current_file->file_number;
1707*404b540aSrobert       typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1708*404b540aSrobert 	= current_file->next_type_number++;
1709*404b540aSrobert #endif
1710*404b540aSrobert     }
1711*404b540aSrobert 
1712*404b540aSrobert   if (flag_debug_only_used_symbols)
1713*404b540aSrobert     {
1714*404b540aSrobert       if ((TREE_CODE (type) == RECORD_TYPE
1715*404b540aSrobert 	   || TREE_CODE (type) == UNION_TYPE
1716*404b540aSrobert 	   || TREE_CODE (type) == QUAL_UNION_TYPE
1717*404b540aSrobert 	   || TREE_CODE (type) == ENUMERAL_TYPE)
1718*404b540aSrobert 	  && TYPE_STUB_DECL (type)
1719*404b540aSrobert 	  && DECL_P (TYPE_STUB_DECL (type))
1720*404b540aSrobert 	  && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1721*404b540aSrobert 	debug_queue_symbol (TYPE_STUB_DECL (type));
1722*404b540aSrobert       else if (TYPE_NAME (type)
1723*404b540aSrobert 	       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1724*404b540aSrobert 	debug_queue_symbol (TYPE_NAME (type));
1725*404b540aSrobert     }
1726*404b540aSrobert 
1727*404b540aSrobert   /* Output the number of this type, to refer to it.  */
1728*404b540aSrobert   dbxout_type_index (type);
1729*404b540aSrobert 
1730*404b540aSrobert #ifdef DBX_TYPE_DEFINED
1731*404b540aSrobert   if (DBX_TYPE_DEFINED (type))
1732*404b540aSrobert     return;
1733*404b540aSrobert #endif
1734*404b540aSrobert 
1735*404b540aSrobert   /* If this type's definition has been output or is now being output,
1736*404b540aSrobert      that is all.  */
1737*404b540aSrobert 
1738*404b540aSrobert   switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1739*404b540aSrobert     {
1740*404b540aSrobert     case TYPE_UNSEEN:
1741*404b540aSrobert       break;
1742*404b540aSrobert     case TYPE_XREF:
1743*404b540aSrobert       /* If we have already had a cross reference,
1744*404b540aSrobert 	 and either that's all we want or that's the best we could do,
1745*404b540aSrobert 	 don't repeat the cross reference.
1746*404b540aSrobert 	 Sun dbx crashes if we do.  */
1747*404b540aSrobert       if (! full || !COMPLETE_TYPE_P (type)
1748*404b540aSrobert 	  /* No way in DBX fmt to describe a variable size.  */
1749*404b540aSrobert 	  || ! host_integerp (TYPE_SIZE (type), 1))
1750*404b540aSrobert 	return;
1751*404b540aSrobert       break;
1752*404b540aSrobert     case TYPE_DEFINED:
1753*404b540aSrobert       return;
1754*404b540aSrobert     }
1755*404b540aSrobert 
1756*404b540aSrobert #ifdef DBX_NO_XREFS
1757*404b540aSrobert   /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1758*404b540aSrobert      leave the type-number completely undefined rather than output
1759*404b540aSrobert      a cross-reference.  If we have already used GNU debug info extensions,
1760*404b540aSrobert      then it is OK to output a cross reference.  This is necessary to get
1761*404b540aSrobert      proper C++ debug output.  */
1762*404b540aSrobert   if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1763*404b540aSrobert        || TREE_CODE (type) == QUAL_UNION_TYPE
1764*404b540aSrobert        || TREE_CODE (type) == ENUMERAL_TYPE)
1765*404b540aSrobert       && ! use_gnu_debug_info_extensions)
1766*404b540aSrobert     /* We must use the same test here as we use twice below when deciding
1767*404b540aSrobert        whether to emit a cross-reference.  */
1768*404b540aSrobert     if ((TYPE_NAME (type) != 0
1769*404b540aSrobert 	 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1770*404b540aSrobert 	       && DECL_IGNORED_P (TYPE_NAME (type)))
1771*404b540aSrobert 	 && !full)
1772*404b540aSrobert 	|| !COMPLETE_TYPE_P (type)
1773*404b540aSrobert 	/* No way in DBX fmt to describe a variable size.  */
1774*404b540aSrobert 	|| ! host_integerp (TYPE_SIZE (type), 1))
1775*404b540aSrobert       {
1776*404b540aSrobert 	typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1777*404b540aSrobert 	return;
1778*404b540aSrobert       }
1779*404b540aSrobert #endif
1780*404b540aSrobert 
1781*404b540aSrobert   /* Output a definition now.  */
1782*404b540aSrobert   stabstr_C ('=');
1783*404b540aSrobert 
1784*404b540aSrobert   /* Mark it as defined, so that if it is self-referent
1785*404b540aSrobert      we will not get into an infinite recursion of definitions.  */
1786*404b540aSrobert 
1787*404b540aSrobert   typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1788*404b540aSrobert 
1789*404b540aSrobert   /* If this type is a variant of some other, hand off.  Types with
1790*404b540aSrobert      different names are usefully distinguished.  We only distinguish
1791*404b540aSrobert      cv-qualified types if we're using extensions.  */
1792*404b540aSrobert   if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1793*404b540aSrobert     {
1794*404b540aSrobert       stabstr_C ('k');
1795*404b540aSrobert       dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1796*404b540aSrobert       return;
1797*404b540aSrobert     }
1798*404b540aSrobert   else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1799*404b540aSrobert     {
1800*404b540aSrobert       stabstr_C ('B');
1801*404b540aSrobert       dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1802*404b540aSrobert       return;
1803*404b540aSrobert     }
1804*404b540aSrobert   else if (main_variant != TYPE_MAIN_VARIANT (type))
1805*404b540aSrobert     {
1806*404b540aSrobert       if (flag_debug_only_used_symbols)
1807*404b540aSrobert         {
1808*404b540aSrobert           tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1809*404b540aSrobert 
1810*404b540aSrobert           if ((TREE_CODE (orig_type) == RECORD_TYPE
1811*404b540aSrobert                || TREE_CODE (orig_type) == UNION_TYPE
1812*404b540aSrobert                || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1813*404b540aSrobert                || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1814*404b540aSrobert               && TYPE_STUB_DECL (orig_type)
1815*404b540aSrobert               && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1816*404b540aSrobert             debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1817*404b540aSrobert         }
1818*404b540aSrobert       /* 'type' is a typedef; output the type it refers to.  */
1819*404b540aSrobert       dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1820*404b540aSrobert       return;
1821*404b540aSrobert     }
1822*404b540aSrobert   /* else continue.  */
1823*404b540aSrobert 
1824*404b540aSrobert   switch (TREE_CODE (type))
1825*404b540aSrobert     {
1826*404b540aSrobert     case VOID_TYPE:
1827*404b540aSrobert     case LANG_TYPE:
1828*404b540aSrobert       /* For a void type, just define it as itself; i.e., "5=5".
1829*404b540aSrobert 	 This makes us consider it defined
1830*404b540aSrobert 	 without saying what it is.  The debugger will make it
1831*404b540aSrobert 	 a void type when the reference is seen, and nothing will
1832*404b540aSrobert 	 ever override that default.  */
1833*404b540aSrobert       dbxout_type_index (type);
1834*404b540aSrobert       break;
1835*404b540aSrobert 
1836*404b540aSrobert     case INTEGER_TYPE:
1837*404b540aSrobert       if (type == char_type_node && ! TYPE_UNSIGNED (type))
1838*404b540aSrobert 	{
1839*404b540aSrobert 	  /* Output the type `char' as a subrange of itself!
1840*404b540aSrobert 	     I don't understand this definition, just copied it
1841*404b540aSrobert 	     from the output of pcc.
1842*404b540aSrobert 	     This used to use `r2' explicitly and we used to
1843*404b540aSrobert 	     take care to make sure that `char' was type number 2.  */
1844*404b540aSrobert 	  stabstr_C ('r');
1845*404b540aSrobert 	  dbxout_type_index (type);
1846*404b540aSrobert 	  stabstr_S (";0;127;");
1847*404b540aSrobert 	}
1848*404b540aSrobert 
1849*404b540aSrobert       /* If this is a subtype of another integer type, always prefer to
1850*404b540aSrobert 	 write it as a subtype.  */
1851*404b540aSrobert       else if (TREE_TYPE (type) != 0
1852*404b540aSrobert 	       && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1853*404b540aSrobert 	{
1854*404b540aSrobert 	  /* If the size is non-standard, say what it is if we can use
1855*404b540aSrobert 	     GDB extensions.  */
1856*404b540aSrobert 
1857*404b540aSrobert 	  if (use_gnu_debug_info_extensions
1858*404b540aSrobert 	      && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1859*404b540aSrobert 	    {
1860*404b540aSrobert 	      stabstr_S ("@s");
1861*404b540aSrobert 	      stabstr_D (TYPE_PRECISION (type));
1862*404b540aSrobert 	      stabstr_C (';');
1863*404b540aSrobert 	    }
1864*404b540aSrobert 
1865*404b540aSrobert 	  dbxout_range_type (type);
1866*404b540aSrobert 	}
1867*404b540aSrobert 
1868*404b540aSrobert       else
1869*404b540aSrobert 	{
1870*404b540aSrobert 	  /* If the size is non-standard, say what it is if we can use
1871*404b540aSrobert 	     GDB extensions.  */
1872*404b540aSrobert 
1873*404b540aSrobert 	  if (use_gnu_debug_info_extensions
1874*404b540aSrobert 	      && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1875*404b540aSrobert 	    {
1876*404b540aSrobert 	      stabstr_S ("@s");
1877*404b540aSrobert 	      stabstr_D (TYPE_PRECISION (type));
1878*404b540aSrobert 	      stabstr_C (';');
1879*404b540aSrobert 	    }
1880*404b540aSrobert 
1881*404b540aSrobert 	  if (print_int_cst_bounds_in_octal_p (type))
1882*404b540aSrobert 	    {
1883*404b540aSrobert 	      stabstr_C ('r');
1884*404b540aSrobert 
1885*404b540aSrobert               /* If this type derives from another type, output type index of
1886*404b540aSrobert 		 parent type. This is particularly important when parent type
1887*404b540aSrobert 		 is an enumerated type, because not generating the parent type
1888*404b540aSrobert 		 index would transform the definition of this enumerated type
1889*404b540aSrobert 		 into a plain unsigned type.  */
1890*404b540aSrobert               if (TREE_TYPE (type) != 0)
1891*404b540aSrobert                 dbxout_type_index (TREE_TYPE (type));
1892*404b540aSrobert               else
1893*404b540aSrobert                 dbxout_type_index (type);
1894*404b540aSrobert 
1895*404b540aSrobert 	      stabstr_C (';');
1896*404b540aSrobert 	      stabstr_O (TYPE_MIN_VALUE (type));
1897*404b540aSrobert 	      stabstr_C (';');
1898*404b540aSrobert 	      stabstr_O (TYPE_MAX_VALUE (type));
1899*404b540aSrobert 	      stabstr_C (';');
1900*404b540aSrobert 	    }
1901*404b540aSrobert 
1902*404b540aSrobert 	  else
1903*404b540aSrobert 	    /* Output other integer types as subranges of `int'.  */
1904*404b540aSrobert 	    dbxout_range_type (type);
1905*404b540aSrobert 	}
1906*404b540aSrobert 
1907*404b540aSrobert       break;
1908*404b540aSrobert 
1909*404b540aSrobert     case REAL_TYPE:
1910*404b540aSrobert       /* This used to say `r1' and we used to take care
1911*404b540aSrobert 	 to make sure that `int' was type number 1.  */
1912*404b540aSrobert       stabstr_C ('r');
1913*404b540aSrobert       dbxout_type_index (integer_type_node);
1914*404b540aSrobert       stabstr_C (';');
1915*404b540aSrobert       stabstr_D (int_size_in_bytes (type));
1916*404b540aSrobert       stabstr_S (";0;");
1917*404b540aSrobert       break;
1918*404b540aSrobert 
1919*404b540aSrobert     case BOOLEAN_TYPE:
1920*404b540aSrobert       if (use_gnu_debug_info_extensions)
1921*404b540aSrobert 	{
1922*404b540aSrobert 	  stabstr_S ("@s");
1923*404b540aSrobert 	  stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1924*404b540aSrobert 	  stabstr_S (";-16;");
1925*404b540aSrobert 	}
1926*404b540aSrobert       else /* Define as enumeral type (False, True) */
1927*404b540aSrobert 	stabstr_S ("eFalse:0,True:1,;");
1928*404b540aSrobert       break;
1929*404b540aSrobert 
1930*404b540aSrobert     case COMPLEX_TYPE:
1931*404b540aSrobert       /* Differs from the REAL_TYPE by its new data type number.
1932*404b540aSrobert 	 R3 is NF_COMPLEX.  We don't try to use any of the other NF_*
1933*404b540aSrobert 	 codes since gdb doesn't care anyway.  */
1934*404b540aSrobert 
1935*404b540aSrobert       if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1936*404b540aSrobert 	{
1937*404b540aSrobert 	  stabstr_S ("R3;");
1938*404b540aSrobert 	  stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
1939*404b540aSrobert 	  stabstr_S (";0;");
1940*404b540aSrobert 	}
1941*404b540aSrobert       else
1942*404b540aSrobert 	{
1943*404b540aSrobert 	  /* Output a complex integer type as a structure,
1944*404b540aSrobert 	     pending some other way to do it.  */
1945*404b540aSrobert 	  stabstr_C ('s');
1946*404b540aSrobert 	  stabstr_D (int_size_in_bytes (type));
1947*404b540aSrobert 
1948*404b540aSrobert 	  stabstr_S ("real:");
1949*404b540aSrobert 	  dbxout_type (TREE_TYPE (type), 0);
1950*404b540aSrobert 	  stabstr_S (",0,");
1951*404b540aSrobert 	  stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1952*404b540aSrobert 
1953*404b540aSrobert 	  stabstr_S (";imag:");
1954*404b540aSrobert 	  dbxout_type (TREE_TYPE (type), 0);
1955*404b540aSrobert 	  stabstr_C (',');
1956*404b540aSrobert 	  stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1957*404b540aSrobert 	  stabstr_C (',');
1958*404b540aSrobert 	  stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1959*404b540aSrobert 	  stabstr_S (";;");
1960*404b540aSrobert 	}
1961*404b540aSrobert       break;
1962*404b540aSrobert 
1963*404b540aSrobert     case ARRAY_TYPE:
1964*404b540aSrobert       /* Make arrays of packed bits look like bitstrings for chill.  */
1965*404b540aSrobert       if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1966*404b540aSrobert 	{
1967*404b540aSrobert 	  stabstr_S ("@s");
1968*404b540aSrobert 	  stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1969*404b540aSrobert 	  stabstr_S (";@S;S");
1970*404b540aSrobert 	  dbxout_type (TYPE_DOMAIN (type), 0);
1971*404b540aSrobert 	  break;
1972*404b540aSrobert 	}
1973*404b540aSrobert 
1974*404b540aSrobert       if (use_gnu_debug_info_extensions && vector_type)
1975*404b540aSrobert 	stabstr_S ("@V;");
1976*404b540aSrobert 
1977*404b540aSrobert       /* Output "a" followed by a range type definition
1978*404b540aSrobert 	 for the index type of the array
1979*404b540aSrobert 	 followed by a reference to the target-type.
1980*404b540aSrobert 	 ar1;0;N;M for a C array of type M and size N+1.  */
1981*404b540aSrobert       /* Check if a character string type, which in Chill is
1982*404b540aSrobert 	 different from an array of characters.  */
1983*404b540aSrobert       if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1984*404b540aSrobert 	{
1985*404b540aSrobert 	  stabstr_S ("@S;");
1986*404b540aSrobert 	}
1987*404b540aSrobert       tem = TYPE_DOMAIN (type);
1988*404b540aSrobert       if (tem == NULL)
1989*404b540aSrobert 	{
1990*404b540aSrobert 	  stabstr_S ("ar");
1991*404b540aSrobert 	  dbxout_type_index (integer_type_node);
1992*404b540aSrobert 	  stabstr_S (";0;-1;");
1993*404b540aSrobert 	}
1994*404b540aSrobert       else
1995*404b540aSrobert 	{
1996*404b540aSrobert 	  stabstr_C ('a');
1997*404b540aSrobert 	  dbxout_range_type (tem);
1998*404b540aSrobert 	}
1999*404b540aSrobert 
2000*404b540aSrobert       dbxout_type (TREE_TYPE (type), 0);
2001*404b540aSrobert       break;
2002*404b540aSrobert 
2003*404b540aSrobert     case RECORD_TYPE:
2004*404b540aSrobert     case UNION_TYPE:
2005*404b540aSrobert     case QUAL_UNION_TYPE:
2006*404b540aSrobert       {
2007*404b540aSrobert 	tree binfo = TYPE_BINFO (type);
2008*404b540aSrobert 
2009*404b540aSrobert 	/* Output a structure type.  We must use the same test here as we
2010*404b540aSrobert 	   use in the DBX_NO_XREFS case above.  */
2011*404b540aSrobert 	if ((TYPE_NAME (type) != 0
2012*404b540aSrobert 	     && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2013*404b540aSrobert 		   && DECL_IGNORED_P (TYPE_NAME (type)))
2014*404b540aSrobert 	     && !full)
2015*404b540aSrobert 	    || !COMPLETE_TYPE_P (type)
2016*404b540aSrobert 	    /* No way in DBX fmt to describe a variable size.  */
2017*404b540aSrobert 	    || ! host_integerp (TYPE_SIZE (type), 1))
2018*404b540aSrobert 	  {
2019*404b540aSrobert 	    /* If the type is just a cross reference, output one
2020*404b540aSrobert 	       and mark the type as partially described.
2021*404b540aSrobert 	       If it later becomes defined, we will output
2022*404b540aSrobert 	       its real definition.
2023*404b540aSrobert 	       If the type has a name, don't nest its definition within
2024*404b540aSrobert 	       another type's definition; instead, output an xref
2025*404b540aSrobert 	       and let the definition come when the name is defined.  */
2026*404b540aSrobert 	    stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2027*404b540aSrobert 	    if (TYPE_NAME (type) != 0)
2028*404b540aSrobert 	      dbxout_type_name (type);
2029*404b540aSrobert 	    else
2030*404b540aSrobert 	      {
2031*404b540aSrobert 		stabstr_S ("$$");
2032*404b540aSrobert 		stabstr_D (anonymous_type_number++);
2033*404b540aSrobert 	      }
2034*404b540aSrobert 
2035*404b540aSrobert 	    stabstr_C (':');
2036*404b540aSrobert 	    typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2037*404b540aSrobert 	    break;
2038*404b540aSrobert 	  }
2039*404b540aSrobert 
2040*404b540aSrobert 	/* Identify record or union, and print its size.  */
2041*404b540aSrobert 	stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2042*404b540aSrobert 	stabstr_D (int_size_in_bytes (type));
2043*404b540aSrobert 
2044*404b540aSrobert 	if (binfo)
2045*404b540aSrobert 	  {
2046*404b540aSrobert 	    int i;
2047*404b540aSrobert 	    tree child;
2048*404b540aSrobert 	    VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
2049*404b540aSrobert 
2050*404b540aSrobert 	    if (use_gnu_debug_info_extensions)
2051*404b540aSrobert 	      {
2052*404b540aSrobert 		if (BINFO_N_BASE_BINFOS (binfo))
2053*404b540aSrobert 		  {
2054*404b540aSrobert 		    stabstr_C ('!');
2055*404b540aSrobert 		    stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2056*404b540aSrobert 		    stabstr_C (',');
2057*404b540aSrobert 		  }
2058*404b540aSrobert 	      }
2059*404b540aSrobert 	    for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2060*404b540aSrobert 	      {
2061*404b540aSrobert 		tree access = (accesses ? VEC_index (tree, accesses, i)
2062*404b540aSrobert 			       : access_public_node);
2063*404b540aSrobert 
2064*404b540aSrobert 		if (use_gnu_debug_info_extensions)
2065*404b540aSrobert 		  {
2066*404b540aSrobert 		    stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2067*404b540aSrobert 		    stabstr_C (access == access_public_node ? '2' :
2068*404b540aSrobert 				   access == access_protected_node
2069*404b540aSrobert 				   ? '1' :'0');
2070*404b540aSrobert 		    if (BINFO_VIRTUAL_P (child)
2071*404b540aSrobert 			&& (strcmp (lang_hooks.name, "GNU C++") == 0
2072*404b540aSrobert 			    || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
2073*404b540aSrobert 		      /* For a virtual base, print the (negative)
2074*404b540aSrobert 		     	 offset within the vtable where we must look
2075*404b540aSrobert 		     	 to find the necessary adjustment.  */
2076*404b540aSrobert 		      stabstr_D
2077*404b540aSrobert 			(tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2078*404b540aSrobert 			 * BITS_PER_UNIT);
2079*404b540aSrobert 		    else
2080*404b540aSrobert 		      stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2081*404b540aSrobert 				       * BITS_PER_UNIT);
2082*404b540aSrobert 		    stabstr_C (',');
2083*404b540aSrobert 		    dbxout_type (BINFO_TYPE (child), 0);
2084*404b540aSrobert 		    stabstr_C (';');
2085*404b540aSrobert 		  }
2086*404b540aSrobert 		else
2087*404b540aSrobert 		  {
2088*404b540aSrobert 		    /* Print out the base class information with
2089*404b540aSrobert 		       fields which have the same names at the types
2090*404b540aSrobert 		       they hold.  */
2091*404b540aSrobert 		    dbxout_type_name (BINFO_TYPE (child));
2092*404b540aSrobert 		    stabstr_C (':');
2093*404b540aSrobert 		    dbxout_type (BINFO_TYPE (child), full);
2094*404b540aSrobert 		    stabstr_C (',');
2095*404b540aSrobert 		    stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2096*404b540aSrobert 				     * BITS_PER_UNIT);
2097*404b540aSrobert 		    stabstr_C (',');
2098*404b540aSrobert 		    stabstr_D
2099*404b540aSrobert 		      (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2100*404b540aSrobert 		       * BITS_PER_UNIT);
2101*404b540aSrobert 		    stabstr_C (';');
2102*404b540aSrobert 		  }
2103*404b540aSrobert 	      }
2104*404b540aSrobert 	  }
2105*404b540aSrobert       }
2106*404b540aSrobert 
2107*404b540aSrobert       /* Write out the field declarations.  */
2108*404b540aSrobert       dbxout_type_fields (type);
2109*404b540aSrobert       if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2110*404b540aSrobert 	{
2111*404b540aSrobert 	  dbxout_type_methods (type);
2112*404b540aSrobert 	}
2113*404b540aSrobert 
2114*404b540aSrobert       stabstr_C (';');
2115*404b540aSrobert 
2116*404b540aSrobert       if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2117*404b540aSrobert 	  /* Avoid the ~ if we don't really need it--it confuses dbx.  */
2118*404b540aSrobert 	  && TYPE_VFIELD (type))
2119*404b540aSrobert 	{
2120*404b540aSrobert 
2121*404b540aSrobert 	  /* We need to write out info about what field this class
2122*404b540aSrobert 	     uses as its "main" vtable pointer field, because if this
2123*404b540aSrobert 	     field is inherited from a base class, GDB cannot necessarily
2124*404b540aSrobert 	     figure out which field it's using in time.  */
2125*404b540aSrobert 	  stabstr_S ("~%");
2126*404b540aSrobert 	  dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2127*404b540aSrobert 	  stabstr_C (';');
2128*404b540aSrobert 	}
2129*404b540aSrobert       break;
2130*404b540aSrobert 
2131*404b540aSrobert     case ENUMERAL_TYPE:
2132*404b540aSrobert       /* We must use the same test here as we use in the DBX_NO_XREFS case
2133*404b540aSrobert 	 above.  We simplify it a bit since an enum will never have a variable
2134*404b540aSrobert 	 size.  */
2135*404b540aSrobert       if ((TYPE_NAME (type) != 0
2136*404b540aSrobert 	   && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2137*404b540aSrobert 		 && DECL_IGNORED_P (TYPE_NAME (type)))
2138*404b540aSrobert 	   && !full)
2139*404b540aSrobert 	  || !COMPLETE_TYPE_P (type))
2140*404b540aSrobert 	{
2141*404b540aSrobert 	  stabstr_S ("xe");
2142*404b540aSrobert 	  dbxout_type_name (type);
2143*404b540aSrobert 	  typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2144*404b540aSrobert 	  stabstr_C (':');
2145*404b540aSrobert 	  return;
2146*404b540aSrobert 	}
2147*404b540aSrobert       if (use_gnu_debug_info_extensions
2148*404b540aSrobert 	  && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2149*404b540aSrobert 	{
2150*404b540aSrobert 	  stabstr_S ("@s");
2151*404b540aSrobert 	  stabstr_D (TYPE_PRECISION (type));
2152*404b540aSrobert 	  stabstr_C (';');
2153*404b540aSrobert 	}
2154*404b540aSrobert 
2155*404b540aSrobert       stabstr_C ('e');
2156*404b540aSrobert       for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2157*404b540aSrobert 	{
2158*404b540aSrobert 	  stabstr_I (TREE_PURPOSE (tem));
2159*404b540aSrobert 	  stabstr_C (':');
2160*404b540aSrobert 
2161*404b540aSrobert 	  if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
2162*404b540aSrobert 	    stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2163*404b540aSrobert 	  else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
2164*404b540aSrobert 		   && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
2165*404b540aSrobert 	    stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2166*404b540aSrobert 	  else
2167*404b540aSrobert 	    stabstr_O (TREE_VALUE (tem));
2168*404b540aSrobert 
2169*404b540aSrobert 	  stabstr_C (',');
2170*404b540aSrobert 	  if (TREE_CHAIN (tem) != 0)
2171*404b540aSrobert 	    CONTIN;
2172*404b540aSrobert 	}
2173*404b540aSrobert 
2174*404b540aSrobert       stabstr_C (';');
2175*404b540aSrobert       break;
2176*404b540aSrobert 
2177*404b540aSrobert     case POINTER_TYPE:
2178*404b540aSrobert       stabstr_C ('*');
2179*404b540aSrobert       dbxout_type (TREE_TYPE (type), 0);
2180*404b540aSrobert       break;
2181*404b540aSrobert 
2182*404b540aSrobert     case METHOD_TYPE:
2183*404b540aSrobert       if (use_gnu_debug_info_extensions)
2184*404b540aSrobert 	{
2185*404b540aSrobert 	  stabstr_C ('#');
2186*404b540aSrobert 
2187*404b540aSrobert 	  /* Write the argument types out longhand.  */
2188*404b540aSrobert 	  dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2189*404b540aSrobert 	  stabstr_C (',');
2190*404b540aSrobert 	  dbxout_type (TREE_TYPE (type), 0);
2191*404b540aSrobert 	  dbxout_args (TYPE_ARG_TYPES (type));
2192*404b540aSrobert 	  stabstr_C (';');
2193*404b540aSrobert 	}
2194*404b540aSrobert       else
2195*404b540aSrobert 	/* Treat it as a function type.  */
2196*404b540aSrobert 	dbxout_type (TREE_TYPE (type), 0);
2197*404b540aSrobert       break;
2198*404b540aSrobert 
2199*404b540aSrobert     case OFFSET_TYPE:
2200*404b540aSrobert       if (use_gnu_debug_info_extensions)
2201*404b540aSrobert 	{
2202*404b540aSrobert 	  stabstr_C ('@');
2203*404b540aSrobert 	  dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2204*404b540aSrobert 	  stabstr_C (',');
2205*404b540aSrobert 	  dbxout_type (TREE_TYPE (type), 0);
2206*404b540aSrobert 	}
2207*404b540aSrobert       else
2208*404b540aSrobert 	/* Should print as an int, because it is really just an offset.  */
2209*404b540aSrobert 	dbxout_type (integer_type_node, 0);
2210*404b540aSrobert       break;
2211*404b540aSrobert 
2212*404b540aSrobert     case REFERENCE_TYPE:
2213*404b540aSrobert       if (use_gnu_debug_info_extensions)
2214*404b540aSrobert 	{
2215*404b540aSrobert 	  stabstr_C ('&');
2216*404b540aSrobert 	}
2217*404b540aSrobert       else
2218*404b540aSrobert 	stabstr_C ('*');
2219*404b540aSrobert       dbxout_type (TREE_TYPE (type), 0);
2220*404b540aSrobert       break;
2221*404b540aSrobert 
2222*404b540aSrobert     case FUNCTION_TYPE:
2223*404b540aSrobert       stabstr_C ('f');
2224*404b540aSrobert       dbxout_type (TREE_TYPE (type), 0);
2225*404b540aSrobert       break;
2226*404b540aSrobert 
2227*404b540aSrobert     default:
2228*404b540aSrobert       gcc_unreachable ();
2229*404b540aSrobert     }
2230*404b540aSrobert }
2231*404b540aSrobert 
2232*404b540aSrobert /* Return nonzero if the given type represents an integer whose bounds
2233*404b540aSrobert    should be printed in octal format.  */
2234*404b540aSrobert 
2235*404b540aSrobert static bool
print_int_cst_bounds_in_octal_p(tree type)2236*404b540aSrobert print_int_cst_bounds_in_octal_p (tree type)
2237*404b540aSrobert {
2238*404b540aSrobert   /* If we can use GDB extensions and the size is wider than a long
2239*404b540aSrobert      (the size used by GDB to read them) or we may have trouble writing
2240*404b540aSrobert      the bounds the usual way, write them in octal.  Note the test is for
2241*404b540aSrobert      the *target's* size of "long", not that of the host.  The host test
2242*404b540aSrobert      is just to make sure we can write it out in case the host wide int
2243*404b540aSrobert      is narrower than the target "long".
2244*404b540aSrobert 
2245*404b540aSrobert      For unsigned types, we use octal if they are the same size or larger.
2246*404b540aSrobert      This is because we print the bounds as signed decimal, and hence they
2247*404b540aSrobert      can't span same size unsigned types.  */
2248*404b540aSrobert 
2249*404b540aSrobert   if (use_gnu_debug_info_extensions
2250*404b540aSrobert       && TYPE_MIN_VALUE (type) != 0
2251*404b540aSrobert       && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
2252*404b540aSrobert       && TYPE_MAX_VALUE (type) != 0
2253*404b540aSrobert       && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
2254*404b540aSrobert       && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2255*404b540aSrobert 	  || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2256*404b540aSrobert 	      && TYPE_UNSIGNED (type))
2257*404b540aSrobert 	  || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2258*404b540aSrobert 	  || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2259*404b540aSrobert 	      && TYPE_UNSIGNED (type))))
2260*404b540aSrobert     return TRUE;
2261*404b540aSrobert   else
2262*404b540aSrobert     return FALSE;
2263*404b540aSrobert }
2264*404b540aSrobert 
2265*404b540aSrobert /* Output the name of type TYPE, with no punctuation.
2266*404b540aSrobert    Such names can be set up either by typedef declarations
2267*404b540aSrobert    or by struct, enum and union tags.  */
2268*404b540aSrobert 
2269*404b540aSrobert static void
dbxout_type_name(tree type)2270*404b540aSrobert dbxout_type_name (tree type)
2271*404b540aSrobert {
2272*404b540aSrobert   tree t = TYPE_NAME (type);
2273*404b540aSrobert 
2274*404b540aSrobert   gcc_assert (t);
2275*404b540aSrobert   switch (TREE_CODE (t))
2276*404b540aSrobert     {
2277*404b540aSrobert     case IDENTIFIER_NODE:
2278*404b540aSrobert       break;
2279*404b540aSrobert     case TYPE_DECL:
2280*404b540aSrobert       t = DECL_NAME (t);
2281*404b540aSrobert       break;
2282*404b540aSrobert     default:
2283*404b540aSrobert       gcc_unreachable ();
2284*404b540aSrobert     }
2285*404b540aSrobert 
2286*404b540aSrobert   stabstr_I (t);
2287*404b540aSrobert }
2288*404b540aSrobert 
2289*404b540aSrobert /* Output leading leading struct or class names needed for qualifying
2290*404b540aSrobert    type whose scope is limited to a struct or class.  */
2291*404b540aSrobert 
2292*404b540aSrobert static void
dbxout_class_name_qualifiers(tree decl)2293*404b540aSrobert dbxout_class_name_qualifiers (tree decl)
2294*404b540aSrobert {
2295*404b540aSrobert   tree context = decl_type_context (decl);
2296*404b540aSrobert 
2297*404b540aSrobert   if (context != NULL_TREE
2298*404b540aSrobert       && TREE_CODE(context) == RECORD_TYPE
2299*404b540aSrobert       && TYPE_NAME (context) != 0
2300*404b540aSrobert       && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2301*404b540aSrobert           || (DECL_NAME (TYPE_NAME (context)) != 0)))
2302*404b540aSrobert     {
2303*404b540aSrobert       tree name = TYPE_NAME (context);
2304*404b540aSrobert 
2305*404b540aSrobert       if (TREE_CODE (name) == TYPE_DECL)
2306*404b540aSrobert 	{
2307*404b540aSrobert 	  dbxout_class_name_qualifiers (name);
2308*404b540aSrobert 	  name = DECL_NAME (name);
2309*404b540aSrobert 	}
2310*404b540aSrobert       stabstr_I (name);
2311*404b540aSrobert       stabstr_S ("::");
2312*404b540aSrobert     }
2313*404b540aSrobert }
2314*404b540aSrobert 
2315*404b540aSrobert /* This is a specialized subset of expand_expr for use by dbxout_symbol in
2316*404b540aSrobert    evaluating DECL_VALUE_EXPR.  In particular, we stop if we find decls that
2317*404b540aSrobert    havn't been expanded, or if the expression is getting so complex we won't
2318*404b540aSrobert    be able to represent it in stabs anyway.  Returns NULL on failure.  */
2319*404b540aSrobert 
2320*404b540aSrobert static rtx
dbxout_expand_expr(tree expr)2321*404b540aSrobert dbxout_expand_expr (tree expr)
2322*404b540aSrobert {
2323*404b540aSrobert   switch (TREE_CODE (expr))
2324*404b540aSrobert     {
2325*404b540aSrobert     case VAR_DECL:
2326*404b540aSrobert     case PARM_DECL:
2327*404b540aSrobert       if (DECL_HAS_VALUE_EXPR_P (expr))
2328*404b540aSrobert 	return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2329*404b540aSrobert       /* FALLTHRU */
2330*404b540aSrobert 
2331*404b540aSrobert     case CONST_DECL:
2332*404b540aSrobert     case RESULT_DECL:
2333*404b540aSrobert       return DECL_RTL_IF_SET (expr);
2334*404b540aSrobert 
2335*404b540aSrobert     case INTEGER_CST:
2336*404b540aSrobert       return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2337*404b540aSrobert 
2338*404b540aSrobert     case COMPONENT_REF:
2339*404b540aSrobert     case ARRAY_REF:
2340*404b540aSrobert     case ARRAY_RANGE_REF:
2341*404b540aSrobert     case BIT_FIELD_REF:
2342*404b540aSrobert       {
2343*404b540aSrobert 	enum machine_mode mode;
2344*404b540aSrobert 	HOST_WIDE_INT bitsize, bitpos;
2345*404b540aSrobert 	tree offset, tem;
2346*404b540aSrobert 	int volatilep = 0, unsignedp = 0;
2347*404b540aSrobert 	rtx x;
2348*404b540aSrobert 
2349*404b540aSrobert 	tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
2350*404b540aSrobert 				   &mode, &unsignedp, &volatilep, true);
2351*404b540aSrobert 
2352*404b540aSrobert 	x = dbxout_expand_expr (tem);
2353*404b540aSrobert 	if (x == NULL || !MEM_P (x))
2354*404b540aSrobert 	  return NULL;
2355*404b540aSrobert 	if (offset != NULL)
2356*404b540aSrobert 	  {
2357*404b540aSrobert 	    if (!host_integerp (offset, 0))
2358*404b540aSrobert 	      return NULL;
2359*404b540aSrobert 	    x = adjust_address_nv (x, mode, tree_low_cst (offset, 0));
2360*404b540aSrobert 	  }
2361*404b540aSrobert 	if (bitpos != 0)
2362*404b540aSrobert 	  x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
2363*404b540aSrobert 
2364*404b540aSrobert 	return x;
2365*404b540aSrobert       }
2366*404b540aSrobert 
2367*404b540aSrobert     default:
2368*404b540aSrobert       return NULL;
2369*404b540aSrobert     }
2370*404b540aSrobert }
2371*404b540aSrobert 
2372*404b540aSrobert /* Helper function for output_used_types.  Queue one entry from the
2373*404b540aSrobert    used types hash to be output.  */
2374*404b540aSrobert 
2375*404b540aSrobert static int
output_used_types_helper(void ** slot,void * data)2376*404b540aSrobert output_used_types_helper (void **slot, void *data)
2377*404b540aSrobert {
2378*404b540aSrobert   tree type = *slot;
2379*404b540aSrobert   VEC(tree, heap) **types_p = data;
2380*404b540aSrobert 
2381*404b540aSrobert   if ((TREE_CODE (type) == RECORD_TYPE
2382*404b540aSrobert        || TREE_CODE (type) == UNION_TYPE
2383*404b540aSrobert        || TREE_CODE (type) == QUAL_UNION_TYPE
2384*404b540aSrobert        || TREE_CODE (type) == ENUMERAL_TYPE)
2385*404b540aSrobert       && TYPE_STUB_DECL (type)
2386*404b540aSrobert       && DECL_P (TYPE_STUB_DECL (type))
2387*404b540aSrobert       && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
2388*404b540aSrobert     VEC_quick_push (tree, *types_p, TYPE_STUB_DECL (type));
2389*404b540aSrobert   else if (TYPE_NAME (type)
2390*404b540aSrobert 	   && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2391*404b540aSrobert     VEC_quick_push (tree, *types_p, TYPE_NAME (type));
2392*404b540aSrobert 
2393*404b540aSrobert   return 1;
2394*404b540aSrobert }
2395*404b540aSrobert 
2396*404b540aSrobert /* This is a qsort callback which sorts types and declarations into a
2397*404b540aSrobert    predictable order (types, then declarations, sorted by UID
2398*404b540aSrobert    within).  */
2399*404b540aSrobert 
2400*404b540aSrobert static int
output_types_sort(const void * pa,const void * pb)2401*404b540aSrobert output_types_sort (const void *pa, const void *pb)
2402*404b540aSrobert {
2403*404b540aSrobert   const tree lhs = *((const tree *)pa);
2404*404b540aSrobert   const tree rhs = *((const tree *)pb);
2405*404b540aSrobert 
2406*404b540aSrobert   if (TYPE_P (lhs))
2407*404b540aSrobert     {
2408*404b540aSrobert       if (TYPE_P (rhs))
2409*404b540aSrobert 	return TYPE_UID (lhs) - TYPE_UID (rhs);
2410*404b540aSrobert       else
2411*404b540aSrobert 	return 1;
2412*404b540aSrobert     }
2413*404b540aSrobert   else
2414*404b540aSrobert     {
2415*404b540aSrobert       if (TYPE_P (rhs))
2416*404b540aSrobert 	return -1;
2417*404b540aSrobert       else
2418*404b540aSrobert 	return DECL_UID (lhs) - DECL_UID (rhs);
2419*404b540aSrobert     }
2420*404b540aSrobert }
2421*404b540aSrobert 
2422*404b540aSrobert 
2423*404b540aSrobert /* Force all types used by this function to be output in debug
2424*404b540aSrobert    information.  */
2425*404b540aSrobert 
2426*404b540aSrobert static void
output_used_types(void)2427*404b540aSrobert output_used_types (void)
2428*404b540aSrobert {
2429*404b540aSrobert   if (cfun && cfun->used_types_hash)
2430*404b540aSrobert     {
2431*404b540aSrobert       VEC(tree, heap) *types;
2432*404b540aSrobert       int i;
2433*404b540aSrobert       tree type;
2434*404b540aSrobert 
2435*404b540aSrobert       types = VEC_alloc (tree, heap, htab_elements (cfun->used_types_hash));
2436*404b540aSrobert       htab_traverse (cfun->used_types_hash, output_used_types_helper, &types);
2437*404b540aSrobert 
2438*404b540aSrobert       /* Sort by UID to prevent dependence on hash table ordering.  */
2439*404b540aSrobert       qsort (VEC_address (tree, types), VEC_length (tree, types),
2440*404b540aSrobert 	     sizeof (tree), output_types_sort);
2441*404b540aSrobert 
2442*404b540aSrobert       for (i = 0; VEC_iterate (tree, types, i, type); i++)
2443*404b540aSrobert 	debug_queue_symbol (type);
2444*404b540aSrobert 
2445*404b540aSrobert       VEC_free (tree, heap, types);
2446*404b540aSrobert     }
2447*404b540aSrobert }
2448*404b540aSrobert 
2449*404b540aSrobert /* Output a .stabs for the symbol defined by DECL,
2450*404b540aSrobert    which must be a ..._DECL node in the normal namespace.
2451*404b540aSrobert    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2452*404b540aSrobert    LOCAL is nonzero if the scope is less than the entire file.
2453*404b540aSrobert    Return 1 if a stabs might have been emitted.  */
2454*404b540aSrobert 
2455*404b540aSrobert int
dbxout_symbol(tree decl,int local ATTRIBUTE_UNUSED)2456*404b540aSrobert dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2457*404b540aSrobert {
2458*404b540aSrobert   tree type = TREE_TYPE (decl);
2459*404b540aSrobert   tree context = NULL_TREE;
2460*404b540aSrobert   int result = 0;
2461*404b540aSrobert   rtx decl_rtl;
2462*404b540aSrobert 
2463*404b540aSrobert   /* "Intercept" dbxout_symbol() calls like we do all debug_hooks.  */
2464*404b540aSrobert   ++debug_nesting;
2465*404b540aSrobert 
2466*404b540aSrobert   /* Ignore nameless syms, but don't ignore type tags.  */
2467*404b540aSrobert 
2468*404b540aSrobert   if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2469*404b540aSrobert       || DECL_IGNORED_P (decl))
2470*404b540aSrobert     DBXOUT_DECR_NESTING_AND_RETURN (0);
2471*404b540aSrobert 
2472*404b540aSrobert   /* If we are to generate only the symbols actually used then such
2473*404b540aSrobert      symbol nodes are flagged with TREE_USED.  Ignore any that
2474*404b540aSrobert      aren't flaged as TREE_USED.  */
2475*404b540aSrobert 
2476*404b540aSrobert   if (flag_debug_only_used_symbols
2477*404b540aSrobert       && (!TREE_USED (decl)
2478*404b540aSrobert           && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2479*404b540aSrobert     DBXOUT_DECR_NESTING_AND_RETURN (0);
2480*404b540aSrobert 
2481*404b540aSrobert   /* If dbxout_init has not yet run, queue this symbol for later.  */
2482*404b540aSrobert   if (!typevec)
2483*404b540aSrobert     {
2484*404b540aSrobert       preinit_symbols = tree_cons (0, decl, preinit_symbols);
2485*404b540aSrobert       DBXOUT_DECR_NESTING_AND_RETURN (0);
2486*404b540aSrobert     }
2487*404b540aSrobert 
2488*404b540aSrobert   if (flag_debug_only_used_symbols)
2489*404b540aSrobert     {
2490*404b540aSrobert       tree t;
2491*404b540aSrobert 
2492*404b540aSrobert       /* We now have a used symbol.  We need to generate the info for
2493*404b540aSrobert          the symbol's type in addition to the symbol itself.  These
2494*404b540aSrobert          type symbols are queued to be generated after were done with
2495*404b540aSrobert          the symbol itself (otherwise they would fight over the
2496*404b540aSrobert          stabstr obstack).
2497*404b540aSrobert 
2498*404b540aSrobert          Note, because the TREE_TYPE(type) might be something like a
2499*404b540aSrobert          pointer to a named type we need to look for the first name
2500*404b540aSrobert          we see following the TREE_TYPE chain.  */
2501*404b540aSrobert 
2502*404b540aSrobert       t = type;
2503*404b540aSrobert       while (POINTER_TYPE_P (t))
2504*404b540aSrobert         t = TREE_TYPE (t);
2505*404b540aSrobert 
2506*404b540aSrobert       /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2507*404b540aSrobert          need special treatment.  The TYPE_STUB_DECL field in these
2508*404b540aSrobert          types generally represents the tag name type we want to
2509*404b540aSrobert          output.  In addition there  could be a typedef type with
2510*404b540aSrobert          a different name.  In that case we also want to output
2511*404b540aSrobert          that.  */
2512*404b540aSrobert 
2513*404b540aSrobert       if (TREE_CODE (t) == RECORD_TYPE
2514*404b540aSrobert            || TREE_CODE (t) == UNION_TYPE
2515*404b540aSrobert            || TREE_CODE (t) == QUAL_UNION_TYPE
2516*404b540aSrobert            || TREE_CODE (t) == ENUMERAL_TYPE)
2517*404b540aSrobert         {
2518*404b540aSrobert 	    if (TYPE_STUB_DECL (t)
2519*404b540aSrobert 		&& TYPE_STUB_DECL (t) != decl
2520*404b540aSrobert 		&& DECL_P (TYPE_STUB_DECL (t))
2521*404b540aSrobert 		&& ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2522*404b540aSrobert 	    {
2523*404b540aSrobert 	      debug_queue_symbol (TYPE_STUB_DECL (t));
2524*404b540aSrobert 	      if (TYPE_NAME (t)
2525*404b540aSrobert 		  && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2526*404b540aSrobert 		  && TYPE_NAME (t) != decl
2527*404b540aSrobert 		  && DECL_P (TYPE_NAME (t)))
2528*404b540aSrobert 		debug_queue_symbol (TYPE_NAME (t));
2529*404b540aSrobert 	    }
2530*404b540aSrobert 	}
2531*404b540aSrobert       else if (TYPE_NAME (t)
2532*404b540aSrobert 	       && TYPE_NAME (t) != decl
2533*404b540aSrobert 	       && DECL_P (TYPE_NAME (t)))
2534*404b540aSrobert         debug_queue_symbol (TYPE_NAME (t));
2535*404b540aSrobert     }
2536*404b540aSrobert 
2537*404b540aSrobert   emit_pending_bincls_if_required ();
2538*404b540aSrobert 
2539*404b540aSrobert   switch (TREE_CODE (decl))
2540*404b540aSrobert     {
2541*404b540aSrobert     case CONST_DECL:
2542*404b540aSrobert       /* Enum values are defined by defining the enum type.  */
2543*404b540aSrobert       break;
2544*404b540aSrobert 
2545*404b540aSrobert     case FUNCTION_DECL:
2546*404b540aSrobert       decl_rtl = DECL_RTL_IF_SET (decl);
2547*404b540aSrobert       if (!decl_rtl)
2548*404b540aSrobert 	DBXOUT_DECR_NESTING_AND_RETURN (0);
2549*404b540aSrobert       if (DECL_EXTERNAL (decl))
2550*404b540aSrobert 	break;
2551*404b540aSrobert       /* Don't mention a nested function under its parent.  */
2552*404b540aSrobert       context = decl_function_context (decl);
2553*404b540aSrobert       if (context == current_function_decl)
2554*404b540aSrobert 	break;
2555*404b540aSrobert       /* Don't mention an inline instance of a nested function.  */
2556*404b540aSrobert       if (context && DECL_FROM_INLINE (decl))
2557*404b540aSrobert 	break;
2558*404b540aSrobert       if (!MEM_P (decl_rtl)
2559*404b540aSrobert 	  || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
2560*404b540aSrobert 	break;
2561*404b540aSrobert 
2562*404b540aSrobert       if (flag_debug_only_used_symbols)
2563*404b540aSrobert 	output_used_types ();
2564*404b540aSrobert 
2565*404b540aSrobert       dbxout_begin_complex_stabs ();
2566*404b540aSrobert       stabstr_I (DECL_ASSEMBLER_NAME (decl));
2567*404b540aSrobert       stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2568*404b540aSrobert       result = 1;
2569*404b540aSrobert 
2570*404b540aSrobert       if (TREE_TYPE (type))
2571*404b540aSrobert 	dbxout_type (TREE_TYPE (type), 0);
2572*404b540aSrobert       else
2573*404b540aSrobert 	dbxout_type (void_type_node, 0);
2574*404b540aSrobert 
2575*404b540aSrobert       /* For a nested function, when that function is compiled,
2576*404b540aSrobert 	 mention the containing function name
2577*404b540aSrobert 	 as well as (since dbx wants it) our own assembler-name.  */
2578*404b540aSrobert       if (context != 0)
2579*404b540aSrobert 	{
2580*404b540aSrobert 	  stabstr_C (',');
2581*404b540aSrobert 	  stabstr_I (DECL_ASSEMBLER_NAME (decl));
2582*404b540aSrobert 	  stabstr_C (',');
2583*404b540aSrobert 	  stabstr_I (DECL_NAME (context));
2584*404b540aSrobert 	}
2585*404b540aSrobert 
2586*404b540aSrobert       dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
2587*404b540aSrobert       break;
2588*404b540aSrobert 
2589*404b540aSrobert     case TYPE_DECL:
2590*404b540aSrobert       /* Don't output the same typedef twice.
2591*404b540aSrobert          And don't output what language-specific stuff doesn't want output.  */
2592*404b540aSrobert       if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2593*404b540aSrobert 	DBXOUT_DECR_NESTING_AND_RETURN (0);
2594*404b540aSrobert 
2595*404b540aSrobert       /* Don't output typedefs for types with magic type numbers (XCOFF).  */
2596*404b540aSrobert #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2597*404b540aSrobert       {
2598*404b540aSrobert 	int fundamental_type_number =
2599*404b540aSrobert 	  DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2600*404b540aSrobert 
2601*404b540aSrobert 	if (fundamental_type_number != 0)
2602*404b540aSrobert 	  {
2603*404b540aSrobert 	    TREE_ASM_WRITTEN (decl) = 1;
2604*404b540aSrobert 	    TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2605*404b540aSrobert 	    DBXOUT_DECR_NESTING_AND_RETURN (0);
2606*404b540aSrobert 	  }
2607*404b540aSrobert       }
2608*404b540aSrobert #endif
2609*404b540aSrobert       FORCE_TEXT;
2610*404b540aSrobert       result = 1;
2611*404b540aSrobert       {
2612*404b540aSrobert 	int tag_needed = 1;
2613*404b540aSrobert 	int did_output = 0;
2614*404b540aSrobert 
2615*404b540aSrobert 	if (DECL_NAME (decl))
2616*404b540aSrobert 	  {
2617*404b540aSrobert 	    /* Nonzero means we must output a tag as well as a typedef.  */
2618*404b540aSrobert 	    tag_needed = 0;
2619*404b540aSrobert 
2620*404b540aSrobert 	    /* Handle the case of a C++ structure or union
2621*404b540aSrobert 	       where the TYPE_NAME is a TYPE_DECL
2622*404b540aSrobert 	       which gives both a typedef name and a tag.  */
2623*404b540aSrobert 	    /* dbx requires the tag first and the typedef second.  */
2624*404b540aSrobert 	    if ((TREE_CODE (type) == RECORD_TYPE
2625*404b540aSrobert 		 || TREE_CODE (type) == UNION_TYPE
2626*404b540aSrobert 		 || TREE_CODE (type) == QUAL_UNION_TYPE)
2627*404b540aSrobert 		&& TYPE_NAME (type) == decl
2628*404b540aSrobert 		&& !use_gnu_debug_info_extensions
2629*404b540aSrobert 		&& !TREE_ASM_WRITTEN (TYPE_NAME (type))
2630*404b540aSrobert 		/* Distinguish the implicit typedefs of C++
2631*404b540aSrobert 		   from explicit ones that might be found in C.  */
2632*404b540aSrobert 		&& DECL_ARTIFICIAL (decl)
2633*404b540aSrobert                 /* Do not generate a tag for incomplete records.  */
2634*404b540aSrobert                 && COMPLETE_TYPE_P (type)
2635*404b540aSrobert 		/* Do not generate a tag for records of variable size,
2636*404b540aSrobert 		   since this type can not be properly described in the
2637*404b540aSrobert 		   DBX format, and it confuses some tools such as objdump.  */
2638*404b540aSrobert 		&& host_integerp (TYPE_SIZE (type), 1))
2639*404b540aSrobert 	      {
2640*404b540aSrobert 		tree name = TYPE_NAME (type);
2641*404b540aSrobert 		if (TREE_CODE (name) == TYPE_DECL)
2642*404b540aSrobert 		  name = DECL_NAME (name);
2643*404b540aSrobert 
2644*404b540aSrobert 		dbxout_begin_complex_stabs ();
2645*404b540aSrobert 		stabstr_I (name);
2646*404b540aSrobert 		stabstr_S (":T");
2647*404b540aSrobert 		dbxout_type (type, 1);
2648*404b540aSrobert 		dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2649*404b540aSrobert 					     0, 0, 0);
2650*404b540aSrobert 	      }
2651*404b540aSrobert 
2652*404b540aSrobert 	    dbxout_begin_complex_stabs ();
2653*404b540aSrobert 
2654*404b540aSrobert 	    /* Output leading class/struct qualifiers.  */
2655*404b540aSrobert 	    if (use_gnu_debug_info_extensions)
2656*404b540aSrobert 	      dbxout_class_name_qualifiers (decl);
2657*404b540aSrobert 
2658*404b540aSrobert 	    /* Output typedef name.  */
2659*404b540aSrobert 	    stabstr_I (DECL_NAME (decl));
2660*404b540aSrobert 	    stabstr_C (':');
2661*404b540aSrobert 
2662*404b540aSrobert 	    /* Short cut way to output a tag also.  */
2663*404b540aSrobert 	    if ((TREE_CODE (type) == RECORD_TYPE
2664*404b540aSrobert 		 || TREE_CODE (type) == UNION_TYPE
2665*404b540aSrobert 		 || TREE_CODE (type) == QUAL_UNION_TYPE)
2666*404b540aSrobert 		&& TYPE_NAME (type) == decl
2667*404b540aSrobert 		/* Distinguish the implicit typedefs of C++
2668*404b540aSrobert 		   from explicit ones that might be found in C.  */
2669*404b540aSrobert 		&& DECL_ARTIFICIAL (decl))
2670*404b540aSrobert 	      {
2671*404b540aSrobert 		if (use_gnu_debug_info_extensions)
2672*404b540aSrobert 		  {
2673*404b540aSrobert 		    stabstr_C ('T');
2674*404b540aSrobert 		    TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2675*404b540aSrobert 		  }
2676*404b540aSrobert 	      }
2677*404b540aSrobert 
2678*404b540aSrobert 	    stabstr_C ('t');
2679*404b540aSrobert 	    dbxout_type (type, 1);
2680*404b540aSrobert 	    dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2681*404b540aSrobert 					 0, 0, 0);
2682*404b540aSrobert 	    did_output = 1;
2683*404b540aSrobert 	  }
2684*404b540aSrobert 
2685*404b540aSrobert 	/* Don't output a tag if this is an incomplete type.  This prevents
2686*404b540aSrobert 	   the sun4 Sun OS 4.x dbx from crashing.  */
2687*404b540aSrobert 
2688*404b540aSrobert 	if (tag_needed && TYPE_NAME (type) != 0
2689*404b540aSrobert 	    && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2690*404b540aSrobert 		|| (DECL_NAME (TYPE_NAME (type)) != 0))
2691*404b540aSrobert 	    && COMPLETE_TYPE_P (type)
2692*404b540aSrobert 	    && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2693*404b540aSrobert 	  {
2694*404b540aSrobert 	    /* For a TYPE_DECL with no name, but the type has a name,
2695*404b540aSrobert 	       output a tag.
2696*404b540aSrobert 	       This is what represents `struct foo' with no typedef.  */
2697*404b540aSrobert 	    /* In C++, the name of a type is the corresponding typedef.
2698*404b540aSrobert 	       In C, it is an IDENTIFIER_NODE.  */
2699*404b540aSrobert 	    tree name = TYPE_NAME (type);
2700*404b540aSrobert 	    if (TREE_CODE (name) == TYPE_DECL)
2701*404b540aSrobert 	      name = DECL_NAME (name);
2702*404b540aSrobert 
2703*404b540aSrobert 	    dbxout_begin_complex_stabs ();
2704*404b540aSrobert 	    stabstr_I (name);
2705*404b540aSrobert 	    stabstr_S (":T");
2706*404b540aSrobert 	    dbxout_type (type, 1);
2707*404b540aSrobert 	    dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2708*404b540aSrobert 	    did_output = 1;
2709*404b540aSrobert 	  }
2710*404b540aSrobert 
2711*404b540aSrobert 	/* If an enum type has no name, it cannot be referred to, but
2712*404b540aSrobert 	   we must output it anyway, to record the enumeration
2713*404b540aSrobert 	   constants.  */
2714*404b540aSrobert 
2715*404b540aSrobert 	if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2716*404b540aSrobert 	  {
2717*404b540aSrobert 	    dbxout_begin_complex_stabs ();
2718*404b540aSrobert 	    /* Some debuggers fail when given NULL names, so give this a
2719*404b540aSrobert 	       harmless name of " " (Why not "(anon)"?).  */
2720*404b540aSrobert 	    stabstr_S (" :T");
2721*404b540aSrobert 	    dbxout_type (type, 1);
2722*404b540aSrobert 	    dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2723*404b540aSrobert 	  }
2724*404b540aSrobert 
2725*404b540aSrobert 	/* Prevent duplicate output of a typedef.  */
2726*404b540aSrobert 	TREE_ASM_WRITTEN (decl) = 1;
2727*404b540aSrobert 	break;
2728*404b540aSrobert       }
2729*404b540aSrobert 
2730*404b540aSrobert     case PARM_DECL:
2731*404b540aSrobert       /* Parm decls go in their own separate chains
2732*404b540aSrobert 	 and are output by dbxout_reg_parms and dbxout_parms.  */
2733*404b540aSrobert       gcc_unreachable ();
2734*404b540aSrobert 
2735*404b540aSrobert     case RESULT_DECL:
2736*404b540aSrobert     case VAR_DECL:
2737*404b540aSrobert       /* Don't mention a variable that is external.
2738*404b540aSrobert 	 Let the file that defines it describe it.  */
2739*404b540aSrobert       if (DECL_EXTERNAL (decl))
2740*404b540aSrobert 	break;
2741*404b540aSrobert 
2742*404b540aSrobert       /* If the variable is really a constant
2743*404b540aSrobert 	 and not written in memory, inform the debugger.
2744*404b540aSrobert 
2745*404b540aSrobert 	 ??? Why do we skip emitting the type and location in this case?  */
2746*404b540aSrobert       if (TREE_STATIC (decl) && TREE_READONLY (decl)
2747*404b540aSrobert 	  && DECL_INITIAL (decl) != 0
2748*404b540aSrobert 	  && host_integerp (DECL_INITIAL (decl), 0)
2749*404b540aSrobert 	  && ! TREE_ASM_WRITTEN (decl)
2750*404b540aSrobert 	  && (DECL_CONTEXT (decl) == NULL_TREE
2751*404b540aSrobert 	      || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
2752*404b540aSrobert 	      || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
2753*404b540aSrobert 	  && TREE_PUBLIC (decl) == 0)
2754*404b540aSrobert 	{
2755*404b540aSrobert 	  /* The sun4 assembler does not grok this.  */
2756*404b540aSrobert 
2757*404b540aSrobert 	  if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2758*404b540aSrobert 	      || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2759*404b540aSrobert 	    {
2760*404b540aSrobert 	      HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
2761*404b540aSrobert 
2762*404b540aSrobert 	      dbxout_begin_complex_stabs ();
2763*404b540aSrobert 	      dbxout_symbol_name (decl, NULL, 'c');
2764*404b540aSrobert 	      stabstr_S ("=i");
2765*404b540aSrobert 	      stabstr_D (ival);
2766*404b540aSrobert 	      dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2767*404b540aSrobert 	      DBXOUT_DECR_NESTING;
2768*404b540aSrobert 	      return 1;
2769*404b540aSrobert 	    }
2770*404b540aSrobert 	  else
2771*404b540aSrobert 	    break;
2772*404b540aSrobert 	}
2773*404b540aSrobert       /* else it is something we handle like a normal variable.  */
2774*404b540aSrobert 
2775*404b540aSrobert       decl_rtl = dbxout_expand_expr (decl);
2776*404b540aSrobert       if (!decl_rtl)
2777*404b540aSrobert 	DBXOUT_DECR_NESTING_AND_RETURN (0);
2778*404b540aSrobert 
2779*404b540aSrobert       decl_rtl = eliminate_regs (decl_rtl, 0, NULL_RTX);
2780*404b540aSrobert #ifdef LEAF_REG_REMAP
2781*404b540aSrobert       if (current_function_uses_only_leaf_regs)
2782*404b540aSrobert 	leaf_renumber_regs_insn (decl_rtl);
2783*404b540aSrobert #endif
2784*404b540aSrobert 
2785*404b540aSrobert       result = dbxout_symbol_location (decl, type, 0, decl_rtl);
2786*404b540aSrobert       break;
2787*404b540aSrobert 
2788*404b540aSrobert     default:
2789*404b540aSrobert       break;
2790*404b540aSrobert     }
2791*404b540aSrobert   DBXOUT_DECR_NESTING;
2792*404b540aSrobert   return result;
2793*404b540aSrobert }
2794*404b540aSrobert 
2795*404b540aSrobert /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2796*404b540aSrobert    Add SUFFIX to its name, if SUFFIX is not 0.
2797*404b540aSrobert    Describe the variable as residing in HOME
2798*404b540aSrobert    (usually HOME is DECL_RTL (DECL), but not always).
2799*404b540aSrobert    Returns 1 if the stab was really emitted.  */
2800*404b540aSrobert 
2801*404b540aSrobert static int
dbxout_symbol_location(tree decl,tree type,const char * suffix,rtx home)2802*404b540aSrobert dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2803*404b540aSrobert {
2804*404b540aSrobert   int letter = 0;
2805*404b540aSrobert   STAB_CODE_TYPE code;
2806*404b540aSrobert   rtx addr = 0;
2807*404b540aSrobert   int number = 0;
2808*404b540aSrobert   int regno = -1;
2809*404b540aSrobert 
2810*404b540aSrobert   /* Don't mention a variable at all
2811*404b540aSrobert      if it was completely optimized into nothingness.
2812*404b540aSrobert 
2813*404b540aSrobert      If the decl was from an inline function, then its rtl
2814*404b540aSrobert      is not identically the rtl that was used in this
2815*404b540aSrobert      particular compilation.  */
2816*404b540aSrobert   if (GET_CODE (home) == SUBREG)
2817*404b540aSrobert     {
2818*404b540aSrobert       rtx value = home;
2819*404b540aSrobert 
2820*404b540aSrobert       while (GET_CODE (value) == SUBREG)
2821*404b540aSrobert 	value = SUBREG_REG (value);
2822*404b540aSrobert       if (REG_P (value))
2823*404b540aSrobert 	{
2824*404b540aSrobert 	  if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2825*404b540aSrobert 	    return 0;
2826*404b540aSrobert 	}
2827*404b540aSrobert       home = alter_subreg (&home);
2828*404b540aSrobert     }
2829*404b540aSrobert   if (REG_P (home))
2830*404b540aSrobert     {
2831*404b540aSrobert       regno = REGNO (home);
2832*404b540aSrobert       if (regno >= FIRST_PSEUDO_REGISTER)
2833*404b540aSrobert 	return 0;
2834*404b540aSrobert     }
2835*404b540aSrobert 
2836*404b540aSrobert   /* The kind-of-variable letter depends on where
2837*404b540aSrobert      the variable is and on the scope of its name:
2838*404b540aSrobert      G and N_GSYM for static storage and global scope,
2839*404b540aSrobert      S for static storage and file scope,
2840*404b540aSrobert      V for static storage and local scope,
2841*404b540aSrobert      for those two, use N_LCSYM if data is in bss segment,
2842*404b540aSrobert      N_STSYM if in data segment, N_FUN otherwise.
2843*404b540aSrobert      (We used N_FUN originally, then changed to N_STSYM
2844*404b540aSrobert      to please GDB.  However, it seems that confused ld.
2845*404b540aSrobert      Now GDB has been fixed to like N_FUN, says Kingdon.)
2846*404b540aSrobert      no letter at all, and N_LSYM, for auto variable,
2847*404b540aSrobert      r and N_RSYM for register variable.  */
2848*404b540aSrobert 
2849*404b540aSrobert   if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2850*404b540aSrobert     {
2851*404b540aSrobert       if (TREE_PUBLIC (decl))
2852*404b540aSrobert 	{
2853*404b540aSrobert 	  letter = 'G';
2854*404b540aSrobert 	  code = N_GSYM;
2855*404b540aSrobert 	}
2856*404b540aSrobert       else
2857*404b540aSrobert 	{
2858*404b540aSrobert 	  addr = XEXP (home, 0);
2859*404b540aSrobert 
2860*404b540aSrobert 	  letter = decl_function_context (decl) ? 'V' : 'S';
2861*404b540aSrobert 
2862*404b540aSrobert 	  /* Some ports can transform a symbol ref into a label ref,
2863*404b540aSrobert 	     because the symbol ref is too far away and has to be
2864*404b540aSrobert 	     dumped into a constant pool.  Alternatively, the symbol
2865*404b540aSrobert 	     in the constant pool might be referenced by a different
2866*404b540aSrobert 	     symbol.  */
2867*404b540aSrobert 	  if (GET_CODE (addr) == SYMBOL_REF
2868*404b540aSrobert 	      && CONSTANT_POOL_ADDRESS_P (addr))
2869*404b540aSrobert 	    {
2870*404b540aSrobert 	      bool marked;
2871*404b540aSrobert 	      rtx tmp = get_pool_constant_mark (addr, &marked);
2872*404b540aSrobert 
2873*404b540aSrobert 	      if (GET_CODE (tmp) == SYMBOL_REF)
2874*404b540aSrobert 		{
2875*404b540aSrobert 		  addr = tmp;
2876*404b540aSrobert 		  if (CONSTANT_POOL_ADDRESS_P (addr))
2877*404b540aSrobert 		    get_pool_constant_mark (addr, &marked);
2878*404b540aSrobert 		  else
2879*404b540aSrobert 		    marked = true;
2880*404b540aSrobert 		}
2881*404b540aSrobert 	      else if (GET_CODE (tmp) == LABEL_REF)
2882*404b540aSrobert 		{
2883*404b540aSrobert 		  addr = tmp;
2884*404b540aSrobert 		  marked = true;
2885*404b540aSrobert 		}
2886*404b540aSrobert 
2887*404b540aSrobert 	      /* If all references to the constant pool were optimized
2888*404b540aSrobert 		 out, we just ignore the symbol.  */
2889*404b540aSrobert 	      if (!marked)
2890*404b540aSrobert 		return 0;
2891*404b540aSrobert 	    }
2892*404b540aSrobert 
2893*404b540aSrobert 	  /* This should be the same condition as in assemble_variable, but
2894*404b540aSrobert 	     we don't have access to dont_output_data here.  So, instead,
2895*404b540aSrobert 	     we rely on the fact that error_mark_node initializers always
2896*404b540aSrobert 	     end up in bss for C++ and never end up in bss for C.  */
2897*404b540aSrobert 	  if (DECL_INITIAL (decl) == 0
2898*404b540aSrobert 	      || (!strcmp (lang_hooks.name, "GNU C++")
2899*404b540aSrobert 		  && DECL_INITIAL (decl) == error_mark_node))
2900*404b540aSrobert 	    code = N_LCSYM;
2901*404b540aSrobert 	  else if (DECL_IN_TEXT_SECTION (decl))
2902*404b540aSrobert 	    /* This is not quite right, but it's the closest
2903*404b540aSrobert 	       of all the codes that Unix defines.  */
2904*404b540aSrobert 	    code = DBX_STATIC_CONST_VAR_CODE;
2905*404b540aSrobert 	  else
2906*404b540aSrobert 	    {
2907*404b540aSrobert 	      /* Ultrix `as' seems to need this.  */
2908*404b540aSrobert #ifdef DBX_STATIC_STAB_DATA_SECTION
2909*404b540aSrobert 	      switch_to_section (data_section);
2910*404b540aSrobert #endif
2911*404b540aSrobert 	      code = N_STSYM;
2912*404b540aSrobert 	    }
2913*404b540aSrobert 	}
2914*404b540aSrobert     }
2915*404b540aSrobert   else if (regno >= 0)
2916*404b540aSrobert     {
2917*404b540aSrobert       letter = 'r';
2918*404b540aSrobert       code = N_RSYM;
2919*404b540aSrobert       number = DBX_REGISTER_NUMBER (regno);
2920*404b540aSrobert     }
2921*404b540aSrobert   else if (MEM_P (home)
2922*404b540aSrobert 	   && (MEM_P (XEXP (home, 0))
2923*404b540aSrobert 	       || (REG_P (XEXP (home, 0))
2924*404b540aSrobert 		   && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2925*404b540aSrobert 		   && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2926*404b540aSrobert #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2927*404b540aSrobert 		   && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2928*404b540aSrobert #endif
2929*404b540aSrobert 		   )))
2930*404b540aSrobert     /* If the value is indirect by memory or by a register
2931*404b540aSrobert        that isn't the frame pointer
2932*404b540aSrobert        then it means the object is variable-sized and address through
2933*404b540aSrobert        that register or stack slot.  DBX has no way to represent this
2934*404b540aSrobert        so all we can do is output the variable as a pointer.
2935*404b540aSrobert        If it's not a parameter, ignore it.  */
2936*404b540aSrobert     {
2937*404b540aSrobert       if (REG_P (XEXP (home, 0)))
2938*404b540aSrobert 	{
2939*404b540aSrobert 	  letter = 'r';
2940*404b540aSrobert 	  code = N_RSYM;
2941*404b540aSrobert 	  if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2942*404b540aSrobert 	    return 0;
2943*404b540aSrobert 	  number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2944*404b540aSrobert 	}
2945*404b540aSrobert       else
2946*404b540aSrobert 	{
2947*404b540aSrobert 	  code = N_LSYM;
2948*404b540aSrobert 	  /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2949*404b540aSrobert 	     We want the value of that CONST_INT.  */
2950*404b540aSrobert 	  number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2951*404b540aSrobert 	}
2952*404b540aSrobert 
2953*404b540aSrobert       /* Effectively do build_pointer_type, but don't cache this type,
2954*404b540aSrobert 	 since it might be temporary whereas the type it points to
2955*404b540aSrobert 	 might have been saved for inlining.  */
2956*404b540aSrobert       /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
2957*404b540aSrobert       type = make_node (POINTER_TYPE);
2958*404b540aSrobert       TREE_TYPE (type) = TREE_TYPE (decl);
2959*404b540aSrobert     }
2960*404b540aSrobert   else if (MEM_P (home)
2961*404b540aSrobert 	   && REG_P (XEXP (home, 0)))
2962*404b540aSrobert     {
2963*404b540aSrobert       code = N_LSYM;
2964*404b540aSrobert       number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2965*404b540aSrobert     }
2966*404b540aSrobert   else if (MEM_P (home)
2967*404b540aSrobert 	   && GET_CODE (XEXP (home, 0)) == PLUS
2968*404b540aSrobert 	   && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2969*404b540aSrobert     {
2970*404b540aSrobert       code = N_LSYM;
2971*404b540aSrobert       /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2972*404b540aSrobert 	 We want the value of that CONST_INT.  */
2973*404b540aSrobert       number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2974*404b540aSrobert     }
2975*404b540aSrobert   else if (MEM_P (home)
2976*404b540aSrobert 	   && GET_CODE (XEXP (home, 0)) == CONST)
2977*404b540aSrobert     {
2978*404b540aSrobert       /* Handle an obscure case which can arise when optimizing and
2979*404b540aSrobert 	 when there are few available registers.  (This is *always*
2980*404b540aSrobert 	 the case for i386/i486 targets).  The RTL looks like
2981*404b540aSrobert 	 (MEM (CONST ...)) even though this variable is a local `auto'
2982*404b540aSrobert 	 or a local `register' variable.  In effect, what has happened
2983*404b540aSrobert 	 is that the reload pass has seen that all assignments and
2984*404b540aSrobert 	 references for one such a local variable can be replaced by
2985*404b540aSrobert 	 equivalent assignments and references to some static storage
2986*404b540aSrobert 	 variable, thereby avoiding the need for a register.  In such
2987*404b540aSrobert 	 cases we're forced to lie to debuggers and tell them that
2988*404b540aSrobert 	 this variable was itself `static'.  */
2989*404b540aSrobert       code = N_LCSYM;
2990*404b540aSrobert       letter = 'V';
2991*404b540aSrobert       addr = XEXP (XEXP (home, 0), 0);
2992*404b540aSrobert     }
2993*404b540aSrobert   else if (GET_CODE (home) == CONCAT)
2994*404b540aSrobert     {
2995*404b540aSrobert       tree subtype;
2996*404b540aSrobert 
2997*404b540aSrobert       /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2998*404b540aSrobert 	 for example), then there is no easy way to figure out
2999*404b540aSrobert 	 what SUBTYPE should be.  So, we give up.  */
3000*404b540aSrobert       if (TREE_CODE (type) != COMPLEX_TYPE)
3001*404b540aSrobert 	return 0;
3002*404b540aSrobert 
3003*404b540aSrobert       subtype = TREE_TYPE (type);
3004*404b540aSrobert 
3005*404b540aSrobert       /* If the variable's storage is in two parts,
3006*404b540aSrobert 	 output each as a separate stab with a modified name.  */
3007*404b540aSrobert       if (WORDS_BIG_ENDIAN)
3008*404b540aSrobert 	dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
3009*404b540aSrobert       else
3010*404b540aSrobert 	dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
3011*404b540aSrobert 
3012*404b540aSrobert       if (WORDS_BIG_ENDIAN)
3013*404b540aSrobert 	dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
3014*404b540aSrobert       else
3015*404b540aSrobert 	dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
3016*404b540aSrobert       return 1;
3017*404b540aSrobert     }
3018*404b540aSrobert   else
3019*404b540aSrobert     /* Address might be a MEM, when DECL is a variable-sized object.
3020*404b540aSrobert        Or it might be const0_rtx, meaning previous passes
3021*404b540aSrobert        want us to ignore this variable.  */
3022*404b540aSrobert     return 0;
3023*404b540aSrobert 
3024*404b540aSrobert   /* Ok, start a symtab entry and output the variable name.  */
3025*404b540aSrobert   emit_pending_bincls_if_required ();
3026*404b540aSrobert   FORCE_TEXT;
3027*404b540aSrobert 
3028*404b540aSrobert #ifdef DBX_STATIC_BLOCK_START
3029*404b540aSrobert   DBX_STATIC_BLOCK_START (asm_out_file, code);
3030*404b540aSrobert #endif
3031*404b540aSrobert 
3032*404b540aSrobert   dbxout_begin_complex_stabs_noforcetext ();
3033*404b540aSrobert   dbxout_symbol_name (decl, suffix, letter);
3034*404b540aSrobert   dbxout_type (type, 0);
3035*404b540aSrobert   dbxout_finish_complex_stabs (decl, code, addr, 0, number);
3036*404b540aSrobert 
3037*404b540aSrobert #ifdef DBX_STATIC_BLOCK_END
3038*404b540aSrobert   DBX_STATIC_BLOCK_END (asm_out_file, code);
3039*404b540aSrobert #endif
3040*404b540aSrobert   return 1;
3041*404b540aSrobert }
3042*404b540aSrobert 
3043*404b540aSrobert /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
3044*404b540aSrobert    Then output LETTER to indicate the kind of location the symbol has.  */
3045*404b540aSrobert 
3046*404b540aSrobert static void
dbxout_symbol_name(tree decl,const char * suffix,int letter)3047*404b540aSrobert dbxout_symbol_name (tree decl, const char *suffix, int letter)
3048*404b540aSrobert {
3049*404b540aSrobert   tree name;
3050*404b540aSrobert 
3051*404b540aSrobert   if (DECL_CONTEXT (decl)
3052*404b540aSrobert       && (TYPE_P (DECL_CONTEXT (decl))
3053*404b540aSrobert 	  || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
3054*404b540aSrobert     /* One slight hitch: if this is a VAR_DECL which is a class member
3055*404b540aSrobert        or a namespace member, we must put out the mangled name instead of the
3056*404b540aSrobert        DECL_NAME.  Note also that static member (variable) names DO NOT begin
3057*404b540aSrobert        with underscores in .stabs directives.  */
3058*404b540aSrobert     name = DECL_ASSEMBLER_NAME (decl);
3059*404b540aSrobert   else
3060*404b540aSrobert     /* ...but if we're function-local, we don't want to include the junk
3061*404b540aSrobert        added by ASM_FORMAT_PRIVATE_NAME.  */
3062*404b540aSrobert     name = DECL_NAME (decl);
3063*404b540aSrobert 
3064*404b540aSrobert   if (name)
3065*404b540aSrobert     stabstr_I (name);
3066*404b540aSrobert   else
3067*404b540aSrobert     stabstr_S ("(anon)");
3068*404b540aSrobert 
3069*404b540aSrobert   if (suffix)
3070*404b540aSrobert     stabstr_S (suffix);
3071*404b540aSrobert   stabstr_C (':');
3072*404b540aSrobert   if (letter)
3073*404b540aSrobert     stabstr_C (letter);
3074*404b540aSrobert }
3075*404b540aSrobert 
3076*404b540aSrobert /* Output definitions of all the decls in a chain. Return nonzero if
3077*404b540aSrobert    anything was output */
3078*404b540aSrobert 
3079*404b540aSrobert int
dbxout_syms(tree syms)3080*404b540aSrobert dbxout_syms (tree syms)
3081*404b540aSrobert {
3082*404b540aSrobert   int result = 0;
3083*404b540aSrobert   while (syms)
3084*404b540aSrobert     {
3085*404b540aSrobert       result += dbxout_symbol (syms, 1);
3086*404b540aSrobert       syms = TREE_CHAIN (syms);
3087*404b540aSrobert     }
3088*404b540aSrobert   return result;
3089*404b540aSrobert }
3090*404b540aSrobert 
3091*404b540aSrobert /* The following two functions output definitions of function parameters.
3092*404b540aSrobert    Each parameter gets a definition locating it in the parameter list.
3093*404b540aSrobert    Each parameter that is a register variable gets a second definition
3094*404b540aSrobert    locating it in the register.
3095*404b540aSrobert 
3096*404b540aSrobert    Printing or argument lists in gdb uses the definitions that
3097*404b540aSrobert    locate in the parameter list.  But reference to the variable in
3098*404b540aSrobert    expressions uses preferentially the definition as a register.  */
3099*404b540aSrobert 
3100*404b540aSrobert /* Output definitions, referring to storage in the parmlist,
3101*404b540aSrobert    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
3102*404b540aSrobert 
3103*404b540aSrobert void
dbxout_parms(tree parms)3104*404b540aSrobert dbxout_parms (tree parms)
3105*404b540aSrobert {
3106*404b540aSrobert   ++debug_nesting;
3107*404b540aSrobert   emit_pending_bincls_if_required ();
3108*404b540aSrobert 
3109*404b540aSrobert   for (; parms; parms = TREE_CHAIN (parms))
3110*404b540aSrobert     if (DECL_NAME (parms)
3111*404b540aSrobert 	&& TREE_TYPE (parms) != error_mark_node
3112*404b540aSrobert 	&& DECL_RTL_SET_P (parms)
3113*404b540aSrobert 	&& DECL_INCOMING_RTL (parms))
3114*404b540aSrobert       {
3115*404b540aSrobert 	tree eff_type;
3116*404b540aSrobert 	char letter;
3117*404b540aSrobert 	STAB_CODE_TYPE code;
3118*404b540aSrobert 	int number;
3119*404b540aSrobert 
3120*404b540aSrobert 	/* Perform any necessary register eliminations on the parameter's rtl,
3121*404b540aSrobert 	   so that the debugging output will be accurate.  */
3122*404b540aSrobert 	DECL_INCOMING_RTL (parms)
3123*404b540aSrobert 	  = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
3124*404b540aSrobert 	SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
3125*404b540aSrobert #ifdef LEAF_REG_REMAP
3126*404b540aSrobert 	if (current_function_uses_only_leaf_regs)
3127*404b540aSrobert 	  {
3128*404b540aSrobert 	    leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3129*404b540aSrobert 	    leaf_renumber_regs_insn (DECL_RTL (parms));
3130*404b540aSrobert 	  }
3131*404b540aSrobert #endif
3132*404b540aSrobert 
3133*404b540aSrobert 	if (PARM_PASSED_IN_MEMORY (parms))
3134*404b540aSrobert 	  {
3135*404b540aSrobert 	    rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3136*404b540aSrobert 
3137*404b540aSrobert 	    /* ??? Here we assume that the parm address is indexed
3138*404b540aSrobert 	       off the frame pointer or arg pointer.
3139*404b540aSrobert 	       If that is not true, we produce meaningless results,
3140*404b540aSrobert 	       but do not crash.  */
3141*404b540aSrobert 	    if (GET_CODE (inrtl) == PLUS
3142*404b540aSrobert 		&& GET_CODE (XEXP (inrtl, 1)) == CONST_INT)
3143*404b540aSrobert 	      number = INTVAL (XEXP (inrtl, 1));
3144*404b540aSrobert 	    else
3145*404b540aSrobert 	      number = 0;
3146*404b540aSrobert 
3147*404b540aSrobert 	    code = N_PSYM;
3148*404b540aSrobert 	    number = DEBUGGER_ARG_OFFSET (number, inrtl);
3149*404b540aSrobert 	    letter = 'p';
3150*404b540aSrobert 
3151*404b540aSrobert 	    /* It is quite tempting to use TREE_TYPE (parms) instead
3152*404b540aSrobert 	       of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3153*404b540aSrobert 	       reports the actual type of the parameter, rather than
3154*404b540aSrobert 	       the promoted type.  This certainly makes GDB's life
3155*404b540aSrobert 	       easier, at least for some ports.  The change is a bad
3156*404b540aSrobert 	       idea however, since GDB expects to be able access the
3157*404b540aSrobert 	       type without performing any conversions.  So for
3158*404b540aSrobert 	       example, if we were passing a float to an unprototyped
3159*404b540aSrobert 	       function, gcc will store a double on the stack, but if
3160*404b540aSrobert 	       we emit a stab saying the type is a float, then gdb
3161*404b540aSrobert 	       will only read in a single value, and this will produce
3162*404b540aSrobert 	       an erroneous value.  */
3163*404b540aSrobert 	    eff_type = DECL_ARG_TYPE (parms);
3164*404b540aSrobert 	  }
3165*404b540aSrobert 	else if (REG_P (DECL_RTL (parms)))
3166*404b540aSrobert 	  {
3167*404b540aSrobert 	    rtx best_rtl;
3168*404b540aSrobert 
3169*404b540aSrobert 	    /* Parm passed in registers and lives in registers or nowhere.  */
3170*404b540aSrobert 	    code = DBX_REGPARM_STABS_CODE;
3171*404b540aSrobert 	    letter = DBX_REGPARM_STABS_LETTER;
3172*404b540aSrobert 
3173*404b540aSrobert 	    /* For parms passed in registers, it is better to use the
3174*404b540aSrobert 	       declared type of the variable, not the type it arrived in.  */
3175*404b540aSrobert 	    eff_type = TREE_TYPE (parms);
3176*404b540aSrobert 
3177*404b540aSrobert 	    /* If parm lives in a register, use that register; pretend
3178*404b540aSrobert 	       the parm was passed there.  It would be more consistent
3179*404b540aSrobert 	       to describe the register where the parm was passed, but
3180*404b540aSrobert 	       in practice that register usually holds something else.
3181*404b540aSrobert 	       If the parm lives nowhere, use the register where it
3182*404b540aSrobert 	       was passed.  */
3183*404b540aSrobert 	    if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3184*404b540aSrobert 	      best_rtl = DECL_RTL (parms);
3185*404b540aSrobert 	    else
3186*404b540aSrobert 	      best_rtl = DECL_INCOMING_RTL (parms);
3187*404b540aSrobert 
3188*404b540aSrobert 	    number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3189*404b540aSrobert 	  }
3190*404b540aSrobert 	else if (MEM_P (DECL_RTL (parms))
3191*404b540aSrobert 		 && REG_P (XEXP (DECL_RTL (parms), 0))
3192*404b540aSrobert 		 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3193*404b540aSrobert 		 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3194*404b540aSrobert #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3195*404b540aSrobert 		 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3196*404b540aSrobert #endif
3197*404b540aSrobert 		 )
3198*404b540aSrobert 	  {
3199*404b540aSrobert 	    /* Parm was passed via invisible reference.
3200*404b540aSrobert 	       That is, its address was passed in a register.
3201*404b540aSrobert 	       Output it as if it lived in that register.
3202*404b540aSrobert 	       The debugger will know from the type
3203*404b540aSrobert 	       that it was actually passed by invisible reference.  */
3204*404b540aSrobert 
3205*404b540aSrobert 	    code = DBX_REGPARM_STABS_CODE;
3206*404b540aSrobert 
3207*404b540aSrobert 	    /* GDB likes this marked with a special letter.  */
3208*404b540aSrobert 	    letter = (use_gnu_debug_info_extensions
3209*404b540aSrobert 		      ? 'a' : DBX_REGPARM_STABS_LETTER);
3210*404b540aSrobert 	    eff_type = TREE_TYPE (parms);
3211*404b540aSrobert 
3212*404b540aSrobert 	    /* DECL_RTL looks like (MEM (REG...).  Get the register number.
3213*404b540aSrobert 	       If it is an unallocated pseudo-reg, then use the register where
3214*404b540aSrobert 	       it was passed instead.
3215*404b540aSrobert 	       ??? Why is DBX_REGISTER_NUMBER not used here?  */
3216*404b540aSrobert 
3217*404b540aSrobert 	    if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3218*404b540aSrobert 	      number = REGNO (XEXP (DECL_RTL (parms), 0));
3219*404b540aSrobert 	    else
3220*404b540aSrobert 	      number = REGNO (DECL_INCOMING_RTL (parms));
3221*404b540aSrobert 	  }
3222*404b540aSrobert 	else if (MEM_P (DECL_RTL (parms))
3223*404b540aSrobert 		 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3224*404b540aSrobert 	  {
3225*404b540aSrobert 	    /* Parm was passed via invisible reference, with the reference
3226*404b540aSrobert 	       living on the stack.  DECL_RTL looks like
3227*404b540aSrobert 	       (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3228*404b540aSrobert 	       could look like (MEM (MEM (REG))).  */
3229*404b540aSrobert 
3230*404b540aSrobert 	    code = N_PSYM;
3231*404b540aSrobert 	    letter = 'v';
3232*404b540aSrobert 	    eff_type = TREE_TYPE (parms);
3233*404b540aSrobert 
3234*404b540aSrobert 	    if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3235*404b540aSrobert 	      number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3236*404b540aSrobert 	    else
3237*404b540aSrobert 	      number = 0;
3238*404b540aSrobert 
3239*404b540aSrobert 	    number = DEBUGGER_ARG_OFFSET (number,
3240*404b540aSrobert 					  XEXP (XEXP (DECL_RTL (parms), 0), 0));
3241*404b540aSrobert 	  }
3242*404b540aSrobert 	else if (MEM_P (DECL_RTL (parms))
3243*404b540aSrobert 		 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3244*404b540aSrobert 		 /* ??? A constant address for a parm can happen
3245*404b540aSrobert 		    when the reg it lives in is equiv to a constant in memory.
3246*404b540aSrobert 		    Should make this not happen, after 2.4.  */
3247*404b540aSrobert 		 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3248*404b540aSrobert 	  {
3249*404b540aSrobert 	    /* Parm was passed in registers but lives on the stack.  */
3250*404b540aSrobert 
3251*404b540aSrobert 	    code = N_PSYM;
3252*404b540aSrobert 	    letter = 'p';
3253*404b540aSrobert 	    eff_type = TREE_TYPE (parms);
3254*404b540aSrobert 
3255*404b540aSrobert 	    /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3256*404b540aSrobert 	       in which case we want the value of that CONST_INT,
3257*404b540aSrobert 	       or (MEM (REG ...)),
3258*404b540aSrobert 	       in which case we use a value of zero.  */
3259*404b540aSrobert 	    if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3260*404b540aSrobert 	      number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3261*404b540aSrobert 	    else
3262*404b540aSrobert 	      number = 0;
3263*404b540aSrobert 
3264*404b540aSrobert 	    /* Make a big endian correction if the mode of the type of the
3265*404b540aSrobert 	       parameter is not the same as the mode of the rtl.  */
3266*404b540aSrobert 	    if (BYTES_BIG_ENDIAN
3267*404b540aSrobert 		&& TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3268*404b540aSrobert 		&& GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3269*404b540aSrobert 	      number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3270*404b540aSrobert 			 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3271*404b540aSrobert 	  }
3272*404b540aSrobert 	else
3273*404b540aSrobert 	  /* ??? We don't know how to represent this argument.  */
3274*404b540aSrobert 	  continue;
3275*404b540aSrobert 
3276*404b540aSrobert 	dbxout_begin_complex_stabs ();
3277*404b540aSrobert 
3278*404b540aSrobert 	if (DECL_NAME (parms))
3279*404b540aSrobert 	  {
3280*404b540aSrobert 	    stabstr_I (DECL_NAME (parms));
3281*404b540aSrobert 	    stabstr_C (':');
3282*404b540aSrobert 	  }
3283*404b540aSrobert 	else
3284*404b540aSrobert 	  stabstr_S ("(anon):");
3285*404b540aSrobert 	stabstr_C (letter);
3286*404b540aSrobert 	dbxout_type (eff_type, 0);
3287*404b540aSrobert 	dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3288*404b540aSrobert       }
3289*404b540aSrobert   DBXOUT_DECR_NESTING;
3290*404b540aSrobert }
3291*404b540aSrobert 
3292*404b540aSrobert /* Output definitions for the places where parms live during the function,
3293*404b540aSrobert    when different from where they were passed, when the parms were passed
3294*404b540aSrobert    in memory.
3295*404b540aSrobert 
3296*404b540aSrobert    It is not useful to do this for parms passed in registers
3297*404b540aSrobert    that live during the function in different registers, because it is
3298*404b540aSrobert    impossible to look in the passed register for the passed value,
3299*404b540aSrobert    so we use the within-the-function register to begin with.
3300*404b540aSrobert 
3301*404b540aSrobert    PARMS is a chain of PARM_DECL nodes.  */
3302*404b540aSrobert 
3303*404b540aSrobert void
dbxout_reg_parms(tree parms)3304*404b540aSrobert dbxout_reg_parms (tree parms)
3305*404b540aSrobert {
3306*404b540aSrobert   ++debug_nesting;
3307*404b540aSrobert 
3308*404b540aSrobert   for (; parms; parms = TREE_CHAIN (parms))
3309*404b540aSrobert     if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3310*404b540aSrobert       {
3311*404b540aSrobert 	/* Report parms that live in registers during the function
3312*404b540aSrobert 	   but were passed in memory.  */
3313*404b540aSrobert 	if (REG_P (DECL_RTL (parms))
3314*404b540aSrobert 	    && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3315*404b540aSrobert 	  dbxout_symbol_location (parms, TREE_TYPE (parms),
3316*404b540aSrobert 				  0, DECL_RTL (parms));
3317*404b540aSrobert 	else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3318*404b540aSrobert 	  dbxout_symbol_location (parms, TREE_TYPE (parms),
3319*404b540aSrobert 				  0, DECL_RTL (parms));
3320*404b540aSrobert 	/* Report parms that live in memory but not where they were passed.  */
3321*404b540aSrobert 	else if (MEM_P (DECL_RTL (parms))
3322*404b540aSrobert 		 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3323*404b540aSrobert 	  dbxout_symbol_location (parms, TREE_TYPE (parms),
3324*404b540aSrobert 				  0, DECL_RTL (parms));
3325*404b540aSrobert       }
3326*404b540aSrobert   DBXOUT_DECR_NESTING;
3327*404b540aSrobert }
3328*404b540aSrobert 
3329*404b540aSrobert /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3330*404b540aSrobert    output definitions of those names, in raw form */
3331*404b540aSrobert 
3332*404b540aSrobert static void
dbxout_args(tree args)3333*404b540aSrobert dbxout_args (tree args)
3334*404b540aSrobert {
3335*404b540aSrobert   while (args)
3336*404b540aSrobert     {
3337*404b540aSrobert       stabstr_C (',');
3338*404b540aSrobert       dbxout_type (TREE_VALUE (args), 0);
3339*404b540aSrobert       args = TREE_CHAIN (args);
3340*404b540aSrobert     }
3341*404b540aSrobert }
3342*404b540aSrobert 
3343*404b540aSrobert /* Subroutine of dbxout_block.  Emit an N_LBRAC stab referencing LABEL.
3344*404b540aSrobert    BEGIN_LABEL is the name of the beginning of the function, which may
3345*404b540aSrobert    be required.  */
3346*404b540aSrobert static void
dbx_output_lbrac(const char * label,const char * begin_label ATTRIBUTE_UNUSED)3347*404b540aSrobert dbx_output_lbrac (const char *label,
3348*404b540aSrobert 		  const char *begin_label ATTRIBUTE_UNUSED)
3349*404b540aSrobert {
3350*404b540aSrobert   dbxout_begin_stabn (N_LBRAC);
3351*404b540aSrobert   if (DBX_BLOCKS_FUNCTION_RELATIVE)
3352*404b540aSrobert     dbxout_stab_value_label_diff (label, begin_label);
3353*404b540aSrobert   else
3354*404b540aSrobert     dbxout_stab_value_label (label);
3355*404b540aSrobert }
3356*404b540aSrobert 
3357*404b540aSrobert /* Subroutine of dbxout_block.  Emit an N_RBRAC stab referencing LABEL.
3358*404b540aSrobert    BEGIN_LABEL is the name of the beginning of the function, which may
3359*404b540aSrobert    be required.  */
3360*404b540aSrobert static void
dbx_output_rbrac(const char * label,const char * begin_label ATTRIBUTE_UNUSED)3361*404b540aSrobert dbx_output_rbrac (const char *label,
3362*404b540aSrobert 		  const char *begin_label ATTRIBUTE_UNUSED)
3363*404b540aSrobert {
3364*404b540aSrobert   dbxout_begin_stabn (N_RBRAC);
3365*404b540aSrobert   if (DBX_BLOCKS_FUNCTION_RELATIVE)
3366*404b540aSrobert     dbxout_stab_value_label_diff (label, begin_label);
3367*404b540aSrobert   else
3368*404b540aSrobert     dbxout_stab_value_label (label);
3369*404b540aSrobert }
3370*404b540aSrobert 
3371*404b540aSrobert /* Output everything about a symbol block (a BLOCK node
3372*404b540aSrobert    that represents a scope level),
3373*404b540aSrobert    including recursive output of contained blocks.
3374*404b540aSrobert 
3375*404b540aSrobert    BLOCK is the BLOCK node.
3376*404b540aSrobert    DEPTH is its depth within containing symbol blocks.
3377*404b540aSrobert    ARGS is usually zero; but for the outermost block of the
3378*404b540aSrobert    body of a function, it is a chain of PARM_DECLs for the function parameters.
3379*404b540aSrobert    We output definitions of all the register parms
3380*404b540aSrobert    as if they were local variables of that block.
3381*404b540aSrobert 
3382*404b540aSrobert    If -g1 was used, we count blocks just the same, but output nothing
3383*404b540aSrobert    except for the outermost block.
3384*404b540aSrobert 
3385*404b540aSrobert    Actually, BLOCK may be several blocks chained together.
3386*404b540aSrobert    We handle them all in sequence.  */
3387*404b540aSrobert 
3388*404b540aSrobert static void
dbxout_block(tree block,int depth,tree args)3389*404b540aSrobert dbxout_block (tree block, int depth, tree args)
3390*404b540aSrobert {
3391*404b540aSrobert   char begin_label[20];
3392*404b540aSrobert   /* Reference current function start using LFBB.  */
3393*404b540aSrobert   ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
3394*404b540aSrobert 
3395*404b540aSrobert   while (block)
3396*404b540aSrobert     {
3397*404b540aSrobert       /* Ignore blocks never expanded or otherwise marked as real.  */
3398*404b540aSrobert       if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3399*404b540aSrobert 	{
3400*404b540aSrobert 	  int did_output;
3401*404b540aSrobert 	  int blocknum = BLOCK_NUMBER (block);
3402*404b540aSrobert 
3403*404b540aSrobert 	  /* In dbx format, the syms of a block come before the N_LBRAC.
3404*404b540aSrobert 	     If nothing is output, we don't need the N_LBRAC, either.  */
3405*404b540aSrobert 	  did_output = 0;
3406*404b540aSrobert 	  if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3407*404b540aSrobert 	    did_output = dbxout_syms (BLOCK_VARS (block));
3408*404b540aSrobert 	  if (args)
3409*404b540aSrobert 	    dbxout_reg_parms (args);
3410*404b540aSrobert 
3411*404b540aSrobert 	  /* Now output an N_LBRAC symbol to represent the beginning of
3412*404b540aSrobert 	     the block.  Use the block's tree-walk order to generate
3413*404b540aSrobert 	     the assembler symbols LBBn and LBEn
3414*404b540aSrobert 	     that final will define around the code in this block.  */
3415*404b540aSrobert 	  if (did_output)
3416*404b540aSrobert 	    {
3417*404b540aSrobert 	      char buf[20];
3418*404b540aSrobert 	      const char *scope_start;
3419*404b540aSrobert 
3420*404b540aSrobert 	      if (depth == 0)
3421*404b540aSrobert 		/* The outermost block doesn't get LBB labels; use
3422*404b540aSrobert 		   the LFBB local symbol emitted by dbxout_begin_prologue.  */
3423*404b540aSrobert 		scope_start = begin_label;
3424*404b540aSrobert 	      else
3425*404b540aSrobert 		{
3426*404b540aSrobert 		  ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3427*404b540aSrobert 		  scope_start = buf;
3428*404b540aSrobert 		}
3429*404b540aSrobert 
3430*404b540aSrobert 	      if (BLOCK_HANDLER_BLOCK (block))
3431*404b540aSrobert 		{
3432*404b540aSrobert 		  /* A catch block.  Must precede N_LBRAC.  */
3433*404b540aSrobert 		  tree decl = BLOCK_VARS (block);
3434*404b540aSrobert 		  while (decl)
3435*404b540aSrobert 		    {
3436*404b540aSrobert 		      dbxout_begin_complex_stabs ();
3437*404b540aSrobert 		      stabstr_I (DECL_NAME (decl));
3438*404b540aSrobert 		      stabstr_S (":C1");
3439*404b540aSrobert 		      dbxout_finish_complex_stabs (0, N_CATCH, 0,
3440*404b540aSrobert 						   scope_start, 0);
3441*404b540aSrobert 		      decl = TREE_CHAIN (decl);
3442*404b540aSrobert 		    }
3443*404b540aSrobert 		}
3444*404b540aSrobert 	      dbx_output_lbrac (scope_start, begin_label);
3445*404b540aSrobert 	    }
3446*404b540aSrobert 
3447*404b540aSrobert 	  /* Output the subblocks.  */
3448*404b540aSrobert 	  dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3449*404b540aSrobert 
3450*404b540aSrobert 	  /* Refer to the marker for the end of the block.  */
3451*404b540aSrobert 	  if (did_output)
3452*404b540aSrobert 	    {
3453*404b540aSrobert 	      char buf[100];
3454*404b540aSrobert 	      if (depth == 0)
3455*404b540aSrobert 		/* The outermost block doesn't get LBE labels;
3456*404b540aSrobert 		   use the "scope" label which will be emitted
3457*404b540aSrobert 		   by dbxout_function_end.  */
3458*404b540aSrobert 		ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3459*404b540aSrobert 	      else
3460*404b540aSrobert 		ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3461*404b540aSrobert 
3462*404b540aSrobert 	      dbx_output_rbrac (buf, begin_label);
3463*404b540aSrobert 	    }
3464*404b540aSrobert 	}
3465*404b540aSrobert       block = BLOCK_CHAIN (block);
3466*404b540aSrobert     }
3467*404b540aSrobert }
3468*404b540aSrobert 
3469*404b540aSrobert /* Output the information about a function and its arguments and result.
3470*404b540aSrobert    Usually this follows the function's code,
3471*404b540aSrobert    but on some systems, it comes before.  */
3472*404b540aSrobert 
3473*404b540aSrobert #if defined (DBX_DEBUGGING_INFO)
3474*404b540aSrobert static void
dbxout_begin_function(tree decl)3475*404b540aSrobert dbxout_begin_function (tree decl)
3476*404b540aSrobert {
3477*404b540aSrobert   int saved_tree_used1;
3478*404b540aSrobert 
3479*404b540aSrobert   if (DECL_IGNORED_P (decl))
3480*404b540aSrobert     return;
3481*404b540aSrobert 
3482*404b540aSrobert   saved_tree_used1 = TREE_USED (decl);
3483*404b540aSrobert   TREE_USED (decl) = 1;
3484*404b540aSrobert   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3485*404b540aSrobert     {
3486*404b540aSrobert       int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3487*404b540aSrobert       TREE_USED (DECL_RESULT (decl)) = 1;
3488*404b540aSrobert       dbxout_symbol (decl, 0);
3489*404b540aSrobert       TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3490*404b540aSrobert     }
3491*404b540aSrobert   else
3492*404b540aSrobert     dbxout_symbol (decl, 0);
3493*404b540aSrobert   TREE_USED (decl) = saved_tree_used1;
3494*404b540aSrobert 
3495*404b540aSrobert   dbxout_parms (DECL_ARGUMENTS (decl));
3496*404b540aSrobert   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3497*404b540aSrobert     dbxout_symbol (DECL_RESULT (decl), 1);
3498*404b540aSrobert }
3499*404b540aSrobert #endif /* DBX_DEBUGGING_INFO */
3500*404b540aSrobert 
3501*404b540aSrobert #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3502*404b540aSrobert 
3503*404b540aSrobert #include "gt-dbxout.h"
3504