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