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