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