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