* gcc.dg/ipa/inlinehint-4.c: Also pass --param inline-unit-growth=20.
[official-gcc.git] / gcc / dbxout.c
blob507fd41f9ead5f8c09ce3388d9962bb72c5baa7b
1 /* Output dbx-format symbol table information from GNU compiler.
2 Copyright (C) 1987-2018 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 /* Last line number mentioned in a NOTE insn. */
249 static GTY(()) unsigned int lastlineno;
251 /* Used by PCH machinery to detect if 'lastfile' should be reset to
252 base_input_file. */
253 static GTY(()) int lastfile_is_base;
255 /* Typical USG systems don't have stab.h, and they also have
256 no use for DBX-format debugging info. */
258 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
260 #ifdef DBX_USE_BINCL
261 /* If zero then there is no pending BINCL. */
262 static int pending_bincls = 0;
263 #endif
265 /* The original input file name. */
266 static const char *base_input_file;
268 #ifdef DEBUG_SYMS_TEXT
269 #define FORCE_TEXT switch_to_section (current_function_section ())
270 #else
271 #define FORCE_TEXT
272 #endif
274 #include "gstab.h"
276 /* 1 if PARM is passed to this function in memory. */
278 #define PARM_PASSED_IN_MEMORY(PARM) \
279 (MEM_P (DECL_INCOMING_RTL (PARM)))
281 /* A C expression for the integer offset value of an automatic variable
282 (N_LSYM) having address X (an RTX). */
283 #ifndef DEBUGGER_AUTO_OFFSET
284 #define DEBUGGER_AUTO_OFFSET(X) \
285 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
286 #endif
288 /* A C expression for the integer offset value of an argument (N_PSYM)
289 having address X (an RTX). The nominal offset is OFFSET.
290 Note that we use OFFSET + 0 here to avoid the self-assign warning
291 when the macro is called in a context like
292 number = DEBUGGER_ARG_OFFSET(number, X) */
293 #ifndef DEBUGGER_ARG_OFFSET
294 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0)
295 #endif
297 /* This obstack holds the stab string currently being constructed. We
298 build it up here, then write it out, so we can split long lines up
299 properly (see dbxout_finish_complex_stabs). */
300 static struct obstack stabstr_ob;
301 static size_t stabstr_last_contin_point;
303 #ifdef DBX_USE_BINCL
304 static void emit_bincl_stab (const char *c);
305 static void emit_pending_bincls (void);
306 #endif
307 static inline void emit_pending_bincls_if_required (void);
309 static void dbxout_init (const char *);
311 static void dbxout_finish (const char *);
312 static void dbxout_start_source_file (unsigned, const char *);
313 static void dbxout_end_source_file (unsigned);
314 static void dbxout_typedefs (tree);
315 static void dbxout_type_index (tree);
316 static void dbxout_args (tree);
317 static void dbxout_type_fields (tree);
318 static void dbxout_type_method_1 (tree);
319 static void dbxout_type_methods (tree);
320 static void dbxout_range_type (tree, tree, tree);
321 static void dbxout_type (tree, int);
322 static bool print_int_cst_bounds_in_octal_p (tree, tree, tree);
323 static bool is_fortran (void);
324 static void dbxout_type_name (tree);
325 static void dbxout_class_name_qualifiers (tree);
326 static int dbxout_symbol_location (tree, tree, const char *, rtx);
327 static void dbxout_symbol_name (tree, const char *, int);
328 static void dbxout_common_name (tree, const char *, stab_code_type);
329 static const char *dbxout_common_check (tree, int *);
330 static void dbxout_early_global_decl (tree);
331 static void dbxout_late_global_decl (tree);
332 static void dbxout_type_decl (tree, int);
333 static void dbxout_handle_pch (unsigned);
334 static void debug_free_queue (void);
336 /* The debug hooks structure. */
337 #if defined (DBX_DEBUGGING_INFO)
339 static void dbxout_source_line (unsigned int, unsigned int, const char *,
340 int, bool);
341 static void dbxout_switch_text_section (void);
342 static void dbxout_begin_prologue (unsigned int, unsigned int, const char *);
343 static void dbxout_source_file (const char *);
344 static void dbxout_function_end (tree);
345 static void dbxout_begin_function (tree);
346 static void dbxout_begin_block (unsigned, unsigned);
347 static void dbxout_end_block (unsigned, unsigned);
348 static void dbxout_function_decl (tree);
350 const struct gcc_debug_hooks dbx_debug_hooks =
352 dbxout_init,
353 dbxout_finish,
354 debug_nothing_charstar,
355 debug_nothing_void,
356 debug_nothing_int_charstar,
357 debug_nothing_int_charstar,
358 dbxout_start_source_file,
359 dbxout_end_source_file,
360 dbxout_begin_block,
361 dbxout_end_block,
362 debug_true_const_tree, /* ignore_block */
363 dbxout_source_line, /* source_line */
364 dbxout_begin_prologue, /* begin_prologue */
365 debug_nothing_int_charstar, /* end_prologue */
366 debug_nothing_int_charstar, /* begin_epilogue */
367 debug_nothing_int_charstar, /* end_epilogue */
368 #ifdef DBX_FUNCTION_FIRST
369 dbxout_begin_function,
370 #else
371 debug_nothing_tree, /* begin_function */
372 #endif
373 debug_nothing_int, /* end_function */
374 debug_nothing_tree, /* register_main_translation_unit */
375 dbxout_function_decl,
376 dbxout_early_global_decl, /* early_global_decl */
377 dbxout_late_global_decl, /* late_global_decl */
378 dbxout_type_decl, /* type_decl */
379 debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
380 debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */
381 debug_nothing_tree_charstar_uhwi, /* register_external_die */
382 debug_nothing_tree, /* deferred_inline_function */
383 debug_nothing_tree, /* outlining_inline_function */
384 debug_nothing_rtx_code_label, /* label */
385 dbxout_handle_pch, /* handle_pch */
386 debug_nothing_rtx_insn, /* var_location */
387 debug_nothing_tree, /* inline_entry */
388 debug_nothing_tree, /* size_function */
389 dbxout_switch_text_section, /* switch_text_section */
390 debug_nothing_tree_tree, /* set_name */
391 0, /* start_end_main_source_file */
392 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
394 #endif /* DBX_DEBUGGING_INFO */
396 #if defined (XCOFF_DEBUGGING_INFO)
397 const struct gcc_debug_hooks xcoff_debug_hooks =
399 dbxout_init,
400 dbxout_finish,
401 debug_nothing_charstar,
402 debug_nothing_void,
403 debug_nothing_int_charstar,
404 debug_nothing_int_charstar,
405 dbxout_start_source_file,
406 dbxout_end_source_file,
407 xcoffout_begin_block,
408 xcoffout_end_block,
409 debug_true_const_tree, /* ignore_block */
410 xcoffout_source_line,
411 xcoffout_begin_prologue, /* begin_prologue */
412 debug_nothing_int_charstar, /* end_prologue */
413 debug_nothing_int_charstar, /* begin_epilogue */
414 xcoffout_end_epilogue,
415 debug_nothing_tree, /* begin_function */
416 xcoffout_end_function,
417 debug_nothing_tree, /* register_main_translation_unit */
418 debug_nothing_tree, /* function_decl */
419 dbxout_early_global_decl, /* early_global_decl */
420 dbxout_late_global_decl, /* late_global_decl */
421 dbxout_type_decl, /* type_decl */
422 debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
423 debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */
424 debug_nothing_tree_charstar_uhwi, /* register_external_die */
425 debug_nothing_tree, /* deferred_inline_function */
426 debug_nothing_tree, /* outlining_inline_function */
427 debug_nothing_rtx_code_label, /* label */
428 dbxout_handle_pch, /* handle_pch */
429 debug_nothing_rtx_insn, /* var_location */
430 debug_nothing_tree, /* inline_entry */
431 debug_nothing_tree, /* size_function */
432 debug_nothing_void, /* switch_text_section */
433 debug_nothing_tree_tree, /* set_name */
434 0, /* start_end_main_source_file */
435 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
437 #endif /* XCOFF_DEBUGGING_INFO */
439 /* Numeric formatting helper macro. Note that this does not handle
440 hexadecimal. */
441 #define NUMBER_FMT_LOOP(P, NUM, BASE) \
442 do \
444 int digit = NUM % BASE; \
445 NUM /= BASE; \
446 *--P = digit + '0'; \
448 while (NUM > 0)
450 /* Utility: write a decimal integer NUM to asm_out_file. */
451 void
452 dbxout_int (int num)
454 char buf[64];
455 char *p = buf + sizeof buf;
456 unsigned int unum;
458 if (num == 0)
460 putc ('0', asm_out_file);
461 return;
463 if (num < 0)
465 putc ('-', asm_out_file);
466 unum = -num;
468 else
469 unum = num;
471 NUMBER_FMT_LOOP (p, unum, 10);
473 while (p < buf + sizeof buf)
475 putc (*p, asm_out_file);
476 p++;
481 /* Primitives for emitting simple stabs directives. All other stabs
482 routines should use these functions instead of directly emitting
483 stabs. They are exported because machine-dependent code may need
484 to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
485 forwards to code in CPU.c. */
487 /* The following functions should all be called immediately after one
488 of the dbxout_begin_stab* functions (below). They write out
489 various things as the value of a stab. */
491 /* Write out a literal zero as the value of a stab. */
492 void
493 dbxout_stab_value_zero (void)
495 fputs ("0\n", asm_out_file);
498 /* Write out the label LABEL as the value of a stab. */
499 void
500 dbxout_stab_value_label (const char *label)
502 assemble_name (asm_out_file, label);
503 putc ('\n', asm_out_file);
506 /* Write out the difference of two labels, LABEL - BASE, as the value
507 of a stab. */
508 void
509 dbxout_stab_value_label_diff (const char *label, const char *base)
511 assemble_name (asm_out_file, label);
512 putc ('-', asm_out_file);
513 assemble_name (asm_out_file, base);
514 putc ('\n', asm_out_file);
517 /* Write out an internal label as the value of a stab, and immediately
518 emit that internal label. This should be used only when
519 dbxout_stabd will not work. STEM is the name stem of the label,
520 COUNTERP is a pointer to a counter variable which will be used to
521 guarantee label uniqueness. */
522 void
523 dbxout_stab_value_internal_label (const char *stem, int *counterp)
525 char label[100];
526 int counter = counterp ? (*counterp)++ : 0;
528 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
529 dbxout_stab_value_label (label);
530 targetm.asm_out.internal_label (asm_out_file, stem, counter);
533 /* Write out the difference between BASE and an internal label as the
534 value of a stab, and immediately emit that internal label. STEM and
535 COUNTERP are as for dbxout_stab_value_internal_label. */
536 void
537 dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
538 const char *base)
540 char label[100];
541 int counter = counterp ? (*counterp)++ : 0;
543 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
544 dbxout_stab_value_label_diff (label, base);
545 targetm.asm_out.internal_label (asm_out_file, stem, counter);
548 /* The following functions produce specific kinds of stab directives. */
550 /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
551 void
552 dbxout_stabd (int stype, int sdesc)
554 fputs (ASM_STABD_OP, asm_out_file);
555 dbxout_int (stype);
556 fputs (",0,", asm_out_file);
557 dbxout_int (sdesc);
558 putc ('\n', asm_out_file);
561 /* Write a .stabn directive with type STYPE. This function stops
562 short of emitting the value field, which is the responsibility of
563 the caller (normally it will be either a symbol or the difference
564 of two symbols). */
566 void
567 dbxout_begin_stabn (int stype)
569 fputs (ASM_STABN_OP, asm_out_file);
570 dbxout_int (stype);
571 fputs (",0,0,", asm_out_file);
574 /* Write a .stabn directive with type N_SLINE and desc LINE. As above,
575 the value field is the responsibility of the caller. */
576 void
577 dbxout_begin_stabn_sline (int lineno)
579 fputs (ASM_STABN_OP, asm_out_file);
580 dbxout_int (N_SLINE);
581 fputs (",0,", asm_out_file);
582 dbxout_int (lineno);
583 putc (',', asm_out_file);
586 /* Begin a .stabs directive with string "", type STYPE, and desc and
587 other fields 0. The value field is the responsibility of the
588 caller. This function cannot be used for .stabx directives. */
589 void
590 dbxout_begin_empty_stabs (int stype)
592 fputs (ASM_STABS_OP, asm_out_file);
593 fputs ("\"\",", asm_out_file);
594 dbxout_int (stype);
595 fputs (",0,0,", asm_out_file);
598 /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
599 The value field is the responsibility of the caller. */
600 void
601 dbxout_begin_simple_stabs (const char *str, int stype)
603 fputs (ASM_STABS_OP, asm_out_file);
604 output_quoted_string (asm_out_file, str);
605 putc (',', asm_out_file);
606 dbxout_int (stype);
607 fputs (",0,0,", asm_out_file);
610 /* As above but use SDESC for the desc field. */
611 void
612 dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
614 fputs (ASM_STABS_OP, asm_out_file);
615 output_quoted_string (asm_out_file, str);
616 putc (',', asm_out_file);
617 dbxout_int (stype);
618 fputs (",0,", asm_out_file);
619 dbxout_int (sdesc);
620 putc (',', asm_out_file);
623 /* The next set of functions are entirely concerned with production of
624 "complex" .stabs directives: that is, .stabs directives whose
625 strings have to be constructed piecemeal. dbxout_type,
626 dbxout_symbol, etc. use these routines heavily. The string is queued
627 up in an obstack, then written out by dbxout_finish_complex_stabs, which
628 is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
629 (You might think it would be more efficient to go straight to stdio
630 when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
631 out not to be the case, and anyway this needs fewer #ifdefs.) */
633 /* Begin a complex .stabs directive. If we can, write the initial
634 ASM_STABS_OP to the asm_out_file. */
636 static void
637 dbxout_begin_complex_stabs (void)
639 emit_pending_bincls_if_required ();
640 FORCE_TEXT;
641 fputs (ASM_STABS_OP, asm_out_file);
642 putc ('"', asm_out_file);
643 gcc_assert (stabstr_last_contin_point == 0);
646 /* As above, but do not force text or emit pending bincls. This is
647 used by dbxout_symbol_location, which needs to do something else. */
648 static void
649 dbxout_begin_complex_stabs_noforcetext (void)
651 fputs (ASM_STABS_OP, asm_out_file);
652 putc ('"', asm_out_file);
653 gcc_assert (stabstr_last_contin_point == 0);
656 /* Add CHR, a single character, to the string being built. */
657 #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
659 /* Add STR, a normal C string, to the string being built. */
660 #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen (str))
662 /* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
663 #define stabstr_I(id) obstack_grow (&stabstr_ob, \
664 IDENTIFIER_POINTER (id), \
665 IDENTIFIER_LENGTH (id))
667 /* Add NUM, a signed decimal number, to the string being built. */
668 static void
669 stabstr_D (HOST_WIDE_INT num)
671 char buf[64];
672 char *p = buf + sizeof buf;
673 unsigned int unum;
675 if (num == 0)
677 stabstr_C ('0');
678 return;
680 if (num < 0)
682 stabstr_C ('-');
683 unum = -num;
685 else
686 unum = num;
688 NUMBER_FMT_LOOP (p, unum, 10);
690 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
693 /* Add NUM, an unsigned decimal number, to the string being built. */
694 static void
695 stabstr_U (unsigned HOST_WIDE_INT num)
697 char buf[64];
698 char *p = buf + sizeof buf;
699 if (num == 0)
701 stabstr_C ('0');
702 return;
704 NUMBER_FMT_LOOP (p, num, 10);
705 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
708 /* Add CST, an INTEGER_CST tree, to the string being built as an
709 unsigned octal number. This routine handles values which are
710 larger than a single HOST_WIDE_INT. */
711 static void
712 stabstr_O (tree cst)
714 int prec = TYPE_PRECISION (TREE_TYPE (cst));
715 int res_pres = prec % 3;
716 int i;
717 unsigned int digit;
719 /* Leading zero for base indicator. */
720 stabstr_C ('0');
722 /* If the value is zero, the base indicator will serve as the value
723 all by itself. */
724 if (wi::to_wide (cst) == 0)
725 return;
727 /* GDB wants constants with no extra leading "1" bits, so
728 we need to remove any sign-extension that might be
729 present. */
730 if (res_pres == 1)
732 digit = wi::extract_uhwi (wi::to_wide (cst), prec - 1, 1);
733 stabstr_C ('0' + digit);
735 else if (res_pres == 2)
737 digit = wi::extract_uhwi (wi::to_wide (cst), prec - 2, 2);
738 stabstr_C ('0' + digit);
741 prec -= res_pres;
742 for (i = prec - 3; i >= 0; i = i - 3)
744 digit = wi::extract_uhwi (wi::to_wide (cst), i, 3);
745 stabstr_C ('0' + digit);
749 /* Called whenever it is safe to break a stabs string into multiple
750 .stabs directives. If the current string has exceeded the limit
751 set by DBX_CONTIN_LENGTH, mark the current position in the buffer
752 as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
753 it is a backslash) and a null character. */
754 static inline void
755 stabstr_continue (void)
757 if (DBX_CONTIN_LENGTH > 0
758 && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
759 > DBX_CONTIN_LENGTH)
761 if (DBX_CONTIN_CHAR == '\\')
762 obstack_1grow (&stabstr_ob, '\\');
763 obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
764 obstack_1grow (&stabstr_ob, '\0');
765 stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
768 #define CONTIN stabstr_continue ()
770 /* Macro subroutine of dbxout_finish_complex_stabs, which emits
771 all of the arguments to the .stabs directive after the string.
772 Overridden by xcoffout.h. CODE is the stabs code for this symbol;
773 LINE is the source line to write into the desc field (in extended
774 mode); SYM is the symbol itself.
776 ADDR, LABEL, and NUMBER are three different ways to represent the
777 stabs value field. At most one of these should be nonzero.
779 ADDR is used most of the time; it represents the value as an
780 RTL address constant.
782 LABEL is used (currently) only for N_CATCH stabs; it represents
783 the value as a string suitable for assemble_name.
785 NUMBER is used when the value is an offset from an implicit base
786 pointer (e.g. for a stack variable), or an index (e.g. for a
787 register variable). It represents the value as a decimal integer. */
789 #ifndef DBX_FINISH_STABS
790 #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \
791 do { \
792 int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
794 dbxout_int (CODE); \
795 fputs (",0,", asm_out_file); \
796 dbxout_int (line_); \
797 putc (',', asm_out_file); \
798 if (ADDR) \
799 output_addr_const (asm_out_file, ADDR); \
800 else if (LABEL) \
801 assemble_name (asm_out_file, LABEL); \
802 else \
803 dbxout_int (NUMBER); \
804 putc ('\n', asm_out_file); \
805 } while (0)
806 #endif
808 /* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
809 is zero, this has only to emit the close quote and the remainder of
810 the arguments. When it is nonzero, the string has been marshalled in
811 stabstr_ob, and this routine is responsible for breaking it up into
812 DBX_CONTIN_LENGTH-sized chunks.
814 SYM is the DECL of the symbol under consideration; it is used only
815 for its DECL_SOURCE_LINE. The other arguments are all passed directly
816 to DBX_FINISH_STABS; see above for details. */
818 static void
819 dbxout_finish_complex_stabs (tree sym, stab_code_type code,
820 rtx addr, const char *label, int number)
822 int line ATTRIBUTE_UNUSED;
823 char *str;
824 size_t len;
826 line = sym ? DECL_SOURCE_LINE (sym) : 0;
827 if (DBX_CONTIN_LENGTH > 0)
829 char *chunk;
830 size_t chunklen;
832 /* Nul-terminate the growing string, then get its size and
833 address. */
834 obstack_1grow (&stabstr_ob, '\0');
836 len = obstack_object_size (&stabstr_ob);
837 chunk = str = XOBFINISH (&stabstr_ob, char *);
839 /* Within the buffer are a sequence of NUL-separated strings,
840 each of which is to be written out as a separate stab
841 directive. */
842 for (;;)
844 chunklen = strlen (chunk);
845 fwrite (chunk, 1, chunklen, asm_out_file);
846 fputs ("\",", asm_out_file);
848 /* Must add an extra byte to account for the NUL separator. */
849 chunk += chunklen + 1;
850 len -= chunklen + 1;
852 /* Only put a line number on the last stab in the sequence. */
853 DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
854 addr, label, number);
855 if (len == 0)
856 break;
858 fputs (ASM_STABS_OP, asm_out_file);
859 putc ('"', asm_out_file);
861 stabstr_last_contin_point = 0;
863 else
865 /* No continuations - we can put the whole string out at once.
866 It is faster to augment the string with the close quote and
867 comma than to do a two-character fputs. */
868 obstack_grow (&stabstr_ob, "\",", 2);
869 len = obstack_object_size (&stabstr_ob);
870 str = XOBFINISH (&stabstr_ob, char *);
872 fwrite (str, 1, len, asm_out_file);
873 DBX_FINISH_STABS (sym, code, line, addr, label, number);
875 obstack_free (&stabstr_ob, str);
878 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
880 /* When -gused is used, emit debug info for only used symbols. But in
881 addition to the standard intercepted debug_hooks there are some
882 direct calls into this file, i.e., dbxout_symbol, dbxout_parms, and
883 dbxout_reg_params. Those routines may also be called from a higher
884 level intercepted routine. So to prevent recording data for an inner
885 call to one of these for an intercept, we maintain an intercept
886 nesting counter (debug_nesting). We only save the intercepted
887 arguments if the nesting is 1. */
888 static int debug_nesting = 0;
890 static tree *symbol_queue;
891 static int symbol_queue_index = 0;
892 static int symbol_queue_size = 0;
894 #define DBXOUT_DECR_NESTING \
895 if (--debug_nesting == 0 && symbol_queue_index > 0) \
896 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
898 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
899 do {--debug_nesting; return (x);} while (0)
901 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
903 #if defined (DBX_DEBUGGING_INFO)
905 static void
906 dbxout_function_end (tree decl ATTRIBUTE_UNUSED)
908 char lscope_label_name[100];
910 /* The Lscope label must be emitted even if we aren't doing anything
911 else; dbxout_block needs it. */
912 switch_to_section (current_function_section ());
914 /* Convert Lscope into the appropriate format for local labels in case
915 the system doesn't insert underscores in front of user generated
916 labels. */
917 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
918 targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
920 /* The N_FUN tag at the end of the function is a GNU extension,
921 which may be undesirable, and is unnecessary if we do not have
922 named sections. */
923 if (!use_gnu_debug_info_extensions
924 || NO_DBX_FUNCTION_END
925 || !targetm_common.have_named_sections)
926 return;
928 /* By convention, GCC will mark the end of a function with an N_FUN
929 symbol and an empty string. */
930 if (crtl->has_bb_partition)
932 dbxout_begin_empty_stabs (N_FUN);
933 if (in_cold_section_p)
934 dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label,
935 crtl->subsections.cold_section_label);
936 else
937 dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label,
938 crtl->subsections.hot_section_label);
940 else
942 char begin_label[20];
943 /* Reference current function start using LFBB. */
944 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
945 dbxout_begin_empty_stabs (N_FUN);
946 dbxout_stab_value_label_diff (lscope_label_name, begin_label);
949 if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
950 dbxout_stabd (N_ENSYM, 0);
952 #endif /* DBX_DEBUGGING_INFO */
954 /* Get lang description for N_SO stab. */
955 static unsigned int ATTRIBUTE_UNUSED
956 get_lang_number (void)
958 const char *language_string = lang_hooks.name;
959 if (lang_GNU_C ())
960 return N_SO_C;
961 else if (lang_GNU_CXX ())
962 return N_SO_CC;
963 else if (strcmp (language_string, "GNU F77") == 0)
964 return N_SO_FORTRAN;
965 else if (lang_GNU_Fortran ())
966 return N_SO_FORTRAN90; /* CHECKME */
967 else if (strcmp (language_string, "GNU Objective-C") == 0)
968 return N_SO_OBJC;
969 else if (strcmp (language_string, "GNU Objective-C++") == 0)
970 return N_SO_OBJCPLUS;
971 else
972 return 0;
976 static bool
977 is_fortran (void)
979 unsigned int lang = get_lang_number ();
981 return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90);
984 /* At the beginning of compilation, start writing the symbol table.
985 Initialize `typevec' and output the standard data types of C. */
987 static void
988 dbxout_init (const char *input_file_name)
990 char ltext_label_name[100];
991 bool used_ltext_label_name = false;
992 tree syms = lang_hooks.decls.getdecls ();
993 const char *mapped_name;
995 typevec_len = 100;
996 typevec = ggc_cleared_vec_alloc<typeinfo> (typevec_len);
998 /* stabstr_ob contains one string, which will be just fine with
999 1-byte alignment. */
1000 obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
1002 /* Convert Ltext into the appropriate format for local labels in case
1003 the system doesn't insert underscores in front of user generated
1004 labels. */
1005 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
1007 /* Put the current working directory in an N_SO symbol. */
1008 if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
1010 static const char *cwd;
1012 if (!cwd)
1014 cwd = get_src_pwd ();
1015 if (cwd[0] == '\0')
1016 cwd = "/";
1017 else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
1018 cwd = concat (cwd, "/", NULL);
1019 cwd = remap_debug_filename (cwd);
1021 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
1022 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
1023 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1024 dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
1025 dbxout_stab_value_label (ltext_label_name);
1026 used_ltext_label_name = true;
1027 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1030 mapped_name = remap_debug_filename (input_file_name);
1031 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1032 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, mapped_name);
1033 #else
1034 dbxout_begin_simple_stabs_desc (mapped_name, N_SO, get_lang_number ());
1035 dbxout_stab_value_label (ltext_label_name);
1036 used_ltext_label_name = true;
1037 #endif
1039 if (used_ltext_label_name)
1041 switch_to_section (text_section);
1042 targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1045 /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1046 The string used is historical. */
1047 #ifndef NO_DBX_GCC_MARKER
1048 dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1049 dbxout_stab_value_zero ();
1050 #endif
1052 base_input_file = lastfile = input_file_name;
1054 next_type_number = 1;
1056 #ifdef DBX_USE_BINCL
1057 current_file = XNEW (struct dbx_file);
1058 current_file->next = NULL;
1059 current_file->file_number = 0;
1060 current_file->next_type_number = 1;
1061 next_file_number = 1;
1062 current_file->prev = NULL;
1063 current_file->bincl_status = BINCL_NOT_REQUIRED;
1064 current_file->pending_bincl_name = NULL;
1065 #endif
1067 /* Get all permanent types that have typedef names, and output them
1068 all, except for those already output. Some language front ends
1069 put these declarations in the top-level scope; some do not;
1070 the latter are responsible for calling debug_hooks->type_decl from
1071 their record_builtin_type function. */
1072 dbxout_typedefs (syms);
1074 if (preinit_symbols)
1076 tree t;
1077 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1078 dbxout_symbol (TREE_VALUE (t), 0);
1079 preinit_symbols = 0;
1083 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
1085 static void
1086 dbxout_typedefs (tree syms)
1088 for (; syms != NULL_TREE; syms = DECL_CHAIN (syms))
1090 if (TREE_CODE (syms) == TYPE_DECL)
1092 tree type = TREE_TYPE (syms);
1093 if (TYPE_NAME (type)
1094 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1095 && COMPLETE_OR_VOID_TYPE_P (type)
1096 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
1097 dbxout_symbol (TYPE_NAME (type), 0);
1102 #ifdef DBX_USE_BINCL
1103 /* Emit BINCL stab using given name. */
1104 static void
1105 emit_bincl_stab (const char *name)
1107 dbxout_begin_simple_stabs (name, N_BINCL);
1108 dbxout_stab_value_zero ();
1111 /* If there are pending bincls then it is time to emit all of them. */
1113 static inline void
1114 emit_pending_bincls_if_required (void)
1116 if (pending_bincls)
1117 emit_pending_bincls ();
1120 /* Emit all pending bincls. */
1122 static void
1123 emit_pending_bincls (void)
1125 struct dbx_file *f = current_file;
1127 /* Find first pending bincl. */
1128 while (f->bincl_status == BINCL_PENDING)
1129 f = f->next;
1131 /* Now emit all bincls. */
1132 f = f->prev;
1134 while (f)
1136 if (f->bincl_status == BINCL_PENDING)
1138 emit_bincl_stab (f->pending_bincl_name);
1140 /* Update file number and status. */
1141 f->file_number = next_file_number++;
1142 f->bincl_status = BINCL_PROCESSED;
1144 if (f == current_file)
1145 break;
1146 f = f->prev;
1149 /* All pending bincls have been emitted. */
1150 pending_bincls = 0;
1153 #else
1155 static inline void
1156 emit_pending_bincls_if_required (void) {}
1157 #endif
1159 /* Change to reading from a new source file. Generate a N_BINCL stab. */
1161 static void
1162 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1163 const char *filename ATTRIBUTE_UNUSED)
1165 #ifdef DBX_USE_BINCL
1166 struct dbx_file *n = XNEW (struct dbx_file);
1168 n->next = current_file;
1169 n->next_type_number = 1;
1170 /* Do not assign file number now.
1171 Delay it until we actually emit BINCL. */
1172 n->file_number = 0;
1173 n->prev = NULL;
1174 current_file->prev = n;
1175 n->bincl_status = BINCL_PENDING;
1176 n->pending_bincl_name = remap_debug_filename (filename);
1177 pending_bincls = 1;
1178 current_file = n;
1179 #endif
1182 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
1184 static void
1185 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1187 #ifdef DBX_USE_BINCL
1188 /* Emit EINCL stab only if BINCL is not pending. */
1189 if (current_file->bincl_status == BINCL_PROCESSED)
1191 dbxout_begin_stabn (N_EINCL);
1192 dbxout_stab_value_zero ();
1194 current_file->bincl_status = BINCL_NOT_REQUIRED;
1195 current_file = current_file->next;
1196 #endif
1199 /* Handle a few odd cases that occur when trying to make PCH files work. */
1201 static void
1202 dbxout_handle_pch (unsigned at_end)
1204 if (! at_end)
1206 /* When using the PCH, this file will be included, so we need to output
1207 a BINCL. */
1208 dbxout_start_source_file (0, lastfile);
1210 /* The base file when using the PCH won't be the same as
1211 the base file when it's being generated. */
1212 lastfile = NULL;
1214 else
1216 /* ... and an EINCL. */
1217 dbxout_end_source_file (0);
1219 /* Deal with cases where 'lastfile' was never actually changed. */
1220 lastfile_is_base = lastfile == NULL;
1224 #if defined (DBX_DEBUGGING_INFO)
1226 static bool dbxout_block (tree, int, tree, int);
1228 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
1230 static void
1231 dbxout_source_file (const char *filename)
1233 if (lastfile == 0 && lastfile_is_base)
1235 lastfile = base_input_file;
1236 lastfile_is_base = 0;
1239 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
1241 /* Don't change section amid function. */
1242 if (current_function_decl == NULL_TREE)
1243 switch_to_section (text_section);
1245 dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL);
1246 dbxout_stab_value_internal_label ("Ltext", &source_label_number);
1247 lastfile = filename;
1251 /* Output N_BNSYM, line number symbol entry, and local symbol at
1252 function scope */
1254 static void
1255 dbxout_begin_prologue (unsigned int lineno,
1256 unsigned int column ATTRIBUTE_UNUSED,
1257 const char *filename)
1259 if (use_gnu_debug_info_extensions
1260 && !NO_DBX_FUNCTION_END
1261 && !NO_DBX_BNSYM_ENSYM
1262 && !flag_debug_only_used_symbols)
1263 dbxout_stabd (N_BNSYM, 0);
1265 /* pre-increment the scope counter */
1266 scope_labelno++;
1268 dbxout_source_line (lineno, 0, filename, 0, true);
1269 /* Output function begin block at function scope, referenced
1270 by dbxout_block, dbxout_source_line and dbxout_function_end. */
1271 emit_pending_bincls_if_required ();
1272 targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno);
1275 /* Output a line number symbol entry for source file FILENAME and line
1276 number LINENO. */
1278 static void
1279 dbxout_source_line (unsigned int lineno, unsigned int column ATTRIBUTE_UNUSED,
1280 const char *filename, int discriminator ATTRIBUTE_UNUSED,
1281 bool is_stmt ATTRIBUTE_UNUSED)
1283 dbxout_source_file (filename);
1285 #ifdef DBX_OUTPUT_SOURCE_LINE
1286 DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
1287 #else
1288 if (DBX_LINES_FUNCTION_RELATIVE)
1290 char begin_label[20];
1291 dbxout_begin_stabn_sline (lineno);
1292 /* Reference current function start using LFBB. */
1293 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
1294 dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
1295 begin_label);
1297 else
1298 dbxout_stabd (N_SLINE, lineno);
1299 #endif
1300 lastlineno = lineno;
1303 /* Unfortunately, at least when emitting relative addresses, STABS
1304 has no way to express multiple partitions. Represent a function
1305 as two functions in this case. */
1307 static void
1308 dbxout_switch_text_section (void)
1310 /* The N_FUN tag at the end of the function is a GNU extension,
1311 which may be undesirable, and is unnecessary if we do not have
1312 named sections. */
1313 in_cold_section_p = !in_cold_section_p;
1314 switch_to_section (current_function_section ());
1315 dbxout_block (DECL_INITIAL (current_function_decl), 0,
1316 DECL_ARGUMENTS (current_function_decl), -1);
1317 dbxout_function_end (current_function_decl);
1318 in_cold_section_p = !in_cold_section_p;
1320 switch_to_section (current_function_section ());
1322 tree context = decl_function_context (current_function_decl);
1323 extern tree cold_function_name;
1325 dbxout_begin_complex_stabs ();
1326 stabstr_I (cold_function_name);
1327 stabstr_S (":f");
1329 tree type = TREE_TYPE (current_function_decl);
1330 if (TREE_TYPE (type))
1331 dbxout_type (TREE_TYPE (type), 0);
1332 else
1333 dbxout_type (void_type_node, 0);
1335 if (context != 0)
1337 stabstr_C (',');
1338 stabstr_I (cold_function_name);
1339 stabstr_C (',');
1340 stabstr_I (DECL_NAME (context));
1343 dbxout_finish_complex_stabs (current_function_decl, N_FUN, 0,
1344 crtl->subsections.cold_section_label, 0);
1346 /* pre-increment the scope counter */
1347 scope_labelno++;
1349 dbxout_source_line (lastlineno, 0, lastfile, 0, true);
1350 /* Output function begin block at function scope, referenced
1351 by dbxout_block, dbxout_source_line and dbxout_function_end. */
1352 emit_pending_bincls_if_required ();
1353 targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno);
1356 /* Describe the beginning of an internal block within a function. */
1358 static void
1359 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1361 emit_pending_bincls_if_required ();
1362 targetm.asm_out.internal_label (asm_out_file, "LBB", n);
1365 /* Describe the end line-number of an internal block within a function. */
1367 static void
1368 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1370 emit_pending_bincls_if_required ();
1371 targetm.asm_out.internal_label (asm_out_file, "LBE", n);
1374 /* Output dbx data for a function definition.
1375 This includes a definition of the function name itself (a symbol),
1376 definitions of the parameters (locating them in the parameter list)
1377 and then output the block that makes up the function's body
1378 (including all the auto variables of the function). */
1380 static void
1381 dbxout_function_decl (tree decl)
1383 emit_pending_bincls_if_required ();
1384 #ifndef DBX_FUNCTION_FIRST
1385 dbxout_begin_function (decl);
1386 #endif
1387 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl), -1);
1388 dbxout_function_end (decl);
1391 #endif /* DBX_DEBUGGING_INFO */
1393 static void
1394 dbxout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1396 /* NYI for non-dwarf. */
1399 /* Debug information for a global DECL. Called from toplev.c after
1400 compilation proper has finished. */
1401 static void
1402 dbxout_late_global_decl (tree decl)
1404 if (VAR_P (decl) && !DECL_EXTERNAL (decl))
1406 int saved_tree_used = TREE_USED (decl);
1407 TREE_USED (decl) = 1;
1408 dbxout_symbol (decl, 0);
1409 TREE_USED (decl) = saved_tree_used;
1413 /* This is just a function-type adapter; dbxout_symbol does exactly
1414 what we want but returns an int. */
1415 static void
1416 dbxout_type_decl (tree decl, int local)
1418 dbxout_symbol (decl, local);
1421 /* At the end of compilation, finish writing the symbol table.
1422 The default is to call debug_free_queue but do nothing else. */
1424 static void
1425 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
1427 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1428 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1429 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1431 switch_to_section (text_section);
1432 dbxout_begin_empty_stabs (N_SO);
1433 dbxout_stab_value_internal_label ("Letext", 0);
1435 #endif
1436 debug_free_queue ();
1439 /* Output the index of a type. */
1441 static void
1442 dbxout_type_index (tree type)
1444 #ifndef DBX_USE_BINCL
1445 stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1446 #else
1447 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1448 stabstr_C ('(');
1449 stabstr_D (t->file_number);
1450 stabstr_C (',');
1451 stabstr_D (t->type_number);
1452 stabstr_C (')');
1453 #endif
1457 /* Generate the symbols for any queued up type symbols we encountered
1458 while generating the type info for some originally used symbol.
1459 This might generate additional entries in the queue. Only when
1460 the nesting depth goes to 0 is this routine called. */
1462 static void
1463 debug_flush_symbol_queue (void)
1465 int i;
1467 /* Make sure that additionally queued items are not flushed
1468 prematurely. */
1470 ++debug_nesting;
1472 for (i = 0; i < symbol_queue_index; ++i)
1474 /* If we pushed queued symbols then such symbols must be
1475 output no matter what anyone else says. Specifically,
1476 we need to make sure dbxout_symbol() thinks the symbol was
1477 used and also we need to override TYPE_DECL_SUPPRESS_DEBUG
1478 which may be set for outside reasons. */
1479 int saved_tree_used = TREE_USED (symbol_queue[i]);
1480 int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]);
1481 TREE_USED (symbol_queue[i]) = 1;
1482 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0;
1484 #ifdef DBX_DEBUGGING_INFO
1485 dbxout_symbol (symbol_queue[i], 0);
1486 #endif
1488 TREE_USED (symbol_queue[i]) = saved_tree_used;
1489 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug;
1492 symbol_queue_index = 0;
1493 --debug_nesting;
1496 /* Queue a type symbol needed as part of the definition of a decl
1497 symbol. These symbols are generated when debug_flush_symbol_queue()
1498 is called. */
1500 static void
1501 debug_queue_symbol (tree decl)
1503 if (symbol_queue_index >= symbol_queue_size)
1505 symbol_queue_size += 10;
1506 symbol_queue = XRESIZEVEC (tree, symbol_queue, symbol_queue_size);
1509 symbol_queue[symbol_queue_index++] = decl;
1512 /* Free symbol queue. */
1513 static void
1514 debug_free_queue (void)
1516 if (symbol_queue)
1518 free (symbol_queue);
1519 symbol_queue = NULL;
1520 symbol_queue_size = 0;
1524 /* Used in several places: evaluates to '0' for a private decl,
1525 '1' for a protected decl, '2' for a public decl. */
1526 #define DECL_ACCESSIBILITY_CHAR(DECL) \
1527 (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1529 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
1530 This must be a separate function because anonymous unions require
1531 recursive calls. */
1533 static void
1534 dbxout_type_fields (tree type)
1536 tree tem;
1538 /* Output the name, type, position (in bits), size (in bits) of each
1539 field that we can support. */
1540 for (tem = TYPE_FIELDS (type); tem; tem = DECL_CHAIN (tem))
1542 /* If one of the nodes is an error_mark or its type is then
1543 return early. */
1544 if (error_operand_p (tem))
1545 return;
1547 /* Omit here local type decls until we know how to support them. */
1548 if (TREE_CODE (tem) == TYPE_DECL
1549 || TREE_CODE (tem) == TEMPLATE_DECL
1550 /* Member functions emitted after fields. */
1551 || TREE_CODE (tem) == FUNCTION_DECL
1552 /* Omit here the nameless fields that are used to skip bits. */
1553 || DECL_IGNORED_P (tem)
1554 /* Omit fields whose position or size are variable or too large to
1555 represent. */
1556 || (TREE_CODE (tem) == FIELD_DECL
1557 && (! tree_fits_shwi_p (bit_position (tem))
1558 || ! DECL_SIZE (tem)
1559 || ! tree_fits_uhwi_p (DECL_SIZE (tem)))))
1560 continue;
1562 else if (TREE_CODE (tem) != CONST_DECL)
1564 /* Continue the line if necessary,
1565 but not before the first field. */
1566 if (tem != TYPE_FIELDS (type))
1567 CONTIN;
1569 if (DECL_NAME (tem))
1570 stabstr_I (DECL_NAME (tem));
1571 stabstr_C (':');
1573 if (use_gnu_debug_info_extensions
1574 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1575 || TREE_CODE (tem) != FIELD_DECL))
1577 stabstr_C ('/');
1578 stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
1581 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
1582 && DECL_BIT_FIELD_TYPE (tem))
1583 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
1585 if (VAR_P (tem))
1587 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
1589 tree name = DECL_ASSEMBLER_NAME (tem);
1591 stabstr_C (':');
1592 stabstr_I (name);
1593 stabstr_C (';');
1595 else
1596 /* If TEM is non-static, GDB won't understand it. */
1597 stabstr_S (",0,0;");
1599 else
1601 stabstr_C (',');
1602 stabstr_D (int_bit_position (tem));
1603 stabstr_C (',');
1604 stabstr_D (tree_to_uhwi (DECL_SIZE (tem)));
1605 stabstr_C (';');
1611 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1612 method described DECL. */
1614 static void
1615 dbxout_type_method_1 (tree decl)
1617 char c1 = 'A', c2;
1619 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1620 c2 = '?';
1621 else /* it's a METHOD_TYPE. */
1623 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1624 /* A for normal functions.
1625 B for `const' member functions.
1626 C for `volatile' member functions.
1627 D for `const volatile' member functions. */
1628 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1629 c1 += 1;
1630 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1631 c1 += 2;
1633 if (DECL_VINDEX (decl))
1634 c2 = '*';
1635 else
1636 c2 = '.';
1639 /* ??? Output the mangled name, which contains an encoding of the
1640 method's type signature. May not be necessary anymore. */
1641 stabstr_C (':');
1642 stabstr_I (DECL_ASSEMBLER_NAME (decl));
1643 stabstr_C (';');
1644 stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1645 stabstr_C (c1);
1646 stabstr_C (c2);
1648 if (DECL_VINDEX (decl) && tree_fits_shwi_p (DECL_VINDEX (decl)))
1650 stabstr_D (tree_to_shwi (DECL_VINDEX (decl)));
1651 stabstr_C (';');
1652 dbxout_type (DECL_CONTEXT (decl), 0);
1653 stabstr_C (';');
1657 /* Subroutine of `dbxout_type'. Output debug info about the member
1658 functions defined in TYPE. */
1660 static void
1661 dbxout_type_methods (tree type)
1663 for (tree fndecl = TYPE_FIELDS (type); fndecl;)
1665 int need_prefix = 1;
1667 /* Group together all the methods for the same operation.
1668 These differ in the types of the arguments. */
1669 for (tree last = NULL_TREE;
1670 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1671 fndecl = DECL_CHAIN (fndecl))
1672 /* Output the name of the field (after overloading), as
1673 well as the name of the field before overloading, along
1674 with its parameter list */
1676 /* Skip non-functions. */
1677 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1678 continue;
1680 /* Also ignore abstract methods; those are only interesting to
1681 the DWARF backends. */
1682 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT_P (fndecl))
1683 continue;
1685 CONTIN;
1687 last = fndecl;
1689 /* Redundantly output the plain name, since that's what gdb
1690 expects. */
1691 if (need_prefix)
1693 stabstr_I (DECL_NAME (fndecl));
1694 stabstr_S ("::");
1695 need_prefix = 0;
1698 dbxout_type (TREE_TYPE (fndecl), 0);
1699 dbxout_type_method_1 (fndecl);
1701 if (!need_prefix)
1702 stabstr_C (';');
1706 /* Emit a "range" type specification, which has the form:
1707 "r<index type>;<lower bound>;<upper bound>;".
1708 TYPE is an INTEGER_TYPE, LOW and HIGH are the bounds. */
1710 static void
1711 dbxout_range_type (tree type, tree low, tree high)
1713 stabstr_C ('r');
1714 if (TREE_TYPE (type))
1715 dbxout_type (TREE_TYPE (type), 0);
1716 else if (TREE_CODE (type) != INTEGER_TYPE)
1717 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1718 else
1720 /* Traditionally, we made sure 'int' was type 1, and builtin types
1721 were defined to be sub-ranges of int. Unfortunately, this
1722 does not allow us to distinguish true sub-ranges from integer
1723 types. So, instead we define integer (non-sub-range) types as
1724 sub-ranges of themselves. This matters for Chill. If this isn't
1725 a subrange type, then we want to define it in terms of itself.
1726 However, in C, this may be an anonymous integer type, and we don't
1727 want to emit debug info referring to it. Just calling
1728 dbxout_type_index won't work anyways, because the type hasn't been
1729 defined yet. We make this work for both cases by checked to see
1730 whether this is a defined type, referring to it if it is, and using
1731 'int' otherwise. */
1732 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1733 dbxout_type_index (type);
1734 else
1735 dbxout_type_index (integer_type_node);
1738 stabstr_C (';');
1739 if (low && tree_fits_shwi_p (low))
1741 if (print_int_cst_bounds_in_octal_p (type, low, high))
1742 stabstr_O (low);
1743 else
1744 stabstr_D (tree_to_shwi (low));
1746 else
1747 stabstr_C ('0');
1749 stabstr_C (';');
1750 if (high && tree_fits_shwi_p (high))
1752 if (print_int_cst_bounds_in_octal_p (type, low, high))
1753 stabstr_O (high);
1754 else
1755 stabstr_D (tree_to_shwi (high));
1756 stabstr_C (';');
1758 else
1759 stabstr_S ("-1;");
1763 /* Output a reference to a type. If the type has not yet been
1764 described in the dbx output, output its definition now.
1765 For a type already defined, just refer to its definition
1766 using the type number.
1768 If FULL is nonzero, and the type has been described only with
1769 a forward-reference, output the definition now.
1770 If FULL is zero in this case, just refer to the forward-reference
1771 using the number previously allocated. */
1773 static void
1774 dbxout_type (tree type, int full)
1776 static int anonymous_type_number = 0;
1777 tree tem, main_variant, low, high;
1779 if (TREE_CODE (type) == INTEGER_TYPE)
1781 if (TREE_TYPE (type) == 0)
1783 low = TYPE_MIN_VALUE (type);
1784 high = TYPE_MAX_VALUE (type);
1787 else if (subrange_type_for_debug_p (type, &low, &high))
1790 /* If this is a subtype that should not be emitted as a subrange type,
1791 use the base type. */
1792 else
1794 type = TREE_TYPE (type);
1795 low = TYPE_MIN_VALUE (type);
1796 high = TYPE_MAX_VALUE (type);
1800 /* If there was an input error and we don't really have a type,
1801 avoid crashing and write something that is at least valid
1802 by assuming `int'. */
1803 if (type == error_mark_node)
1804 type = integer_type_node;
1805 else
1807 if (TYPE_NAME (type)
1808 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1809 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1810 full = 0;
1813 /* Try to find the "main variant" with the same name. */
1814 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1815 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1816 main_variant = TREE_TYPE (TYPE_NAME (type));
1817 else
1818 main_variant = TYPE_MAIN_VARIANT (type);
1820 /* If we are not using extensions, stabs does not distinguish const and
1821 volatile, so there is no need to make them separate types. */
1822 if (!use_gnu_debug_info_extensions)
1823 type = main_variant;
1825 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1827 /* Type has no dbx number assigned. Assign next available number. */
1828 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1830 /* Make sure type vector is long enough to record about this type. */
1832 if (next_type_number == typevec_len)
1834 typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2);
1835 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1836 typevec_len *= 2;
1839 #ifdef DBX_USE_BINCL
1840 emit_pending_bincls_if_required ();
1841 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1842 = current_file->file_number;
1843 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1844 = current_file->next_type_number++;
1845 #endif
1848 if (flag_debug_only_used_symbols)
1850 if ((TREE_CODE (type) == RECORD_TYPE
1851 || TREE_CODE (type) == UNION_TYPE
1852 || TREE_CODE (type) == QUAL_UNION_TYPE
1853 || TREE_CODE (type) == ENUMERAL_TYPE)
1854 && TYPE_STUB_DECL (type)
1855 && DECL_P (TYPE_STUB_DECL (type))
1856 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1857 debug_queue_symbol (TYPE_STUB_DECL (type));
1858 else if (TYPE_NAME (type)
1859 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1860 debug_queue_symbol (TYPE_NAME (type));
1863 /* Output the number of this type, to refer to it. */
1864 dbxout_type_index (type);
1866 #ifdef DBX_TYPE_DEFINED
1867 if (DBX_TYPE_DEFINED (type))
1868 return;
1869 #endif
1871 /* If this type's definition has been output or is now being output,
1872 that is all. */
1874 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1876 case TYPE_UNSEEN:
1877 break;
1878 case TYPE_XREF:
1879 /* If we have already had a cross reference,
1880 and either that's all we want or that's the best we could do,
1881 don't repeat the cross reference.
1882 Sun dbx crashes if we do. */
1883 if (! full || !COMPLETE_TYPE_P (type)
1884 /* No way in DBX fmt to describe a variable size. */
1885 || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
1886 return;
1887 break;
1888 case TYPE_DEFINED:
1889 return;
1892 #ifdef DBX_NO_XREFS
1893 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1894 leave the type-number completely undefined rather than output
1895 a cross-reference. If we have already used GNU debug info extensions,
1896 then it is OK to output a cross reference. This is necessary to get
1897 proper C++ debug output. */
1898 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1899 || TREE_CODE (type) == QUAL_UNION_TYPE
1900 || TREE_CODE (type) == ENUMERAL_TYPE)
1901 && ! use_gnu_debug_info_extensions)
1902 /* We must use the same test here as we use twice below when deciding
1903 whether to emit a cross-reference. */
1904 if ((TYPE_NAME (type) != 0
1905 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1906 && DECL_IGNORED_P (TYPE_NAME (type)))
1907 && !full)
1908 || !COMPLETE_TYPE_P (type)
1909 /* No way in DBX fmt to describe a variable size. */
1910 || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
1912 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1913 return;
1915 #endif
1917 /* Output a definition now. */
1918 stabstr_C ('=');
1920 /* Mark it as defined, so that if it is self-referent
1921 we will not get into an infinite recursion of definitions. */
1923 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1925 /* If this type is a variant of some other, hand off. Types with
1926 different names are usefully distinguished. We only distinguish
1927 cv-qualified types if we're using extensions. */
1928 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1930 stabstr_C ('k');
1931 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1932 return;
1934 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1936 stabstr_C ('B');
1937 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1938 return;
1940 else if (main_variant != TYPE_MAIN_VARIANT (type))
1942 if (flag_debug_only_used_symbols)
1944 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1946 if ((TREE_CODE (orig_type) == RECORD_TYPE
1947 || TREE_CODE (orig_type) == UNION_TYPE
1948 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1949 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1950 && TYPE_STUB_DECL (orig_type)
1951 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1952 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1954 /* 'type' is a typedef; output the type it refers to. */
1955 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1956 return;
1958 /* else continue. */
1960 switch (TREE_CODE (type))
1962 case VOID_TYPE:
1963 case NULLPTR_TYPE:
1964 case LANG_TYPE:
1965 /* For a void type, just define it as itself; i.e., "5=5".
1966 This makes us consider it defined
1967 without saying what it is. The debugger will make it
1968 a void type when the reference is seen, and nothing will
1969 ever override that default. */
1970 dbxout_type_index (type);
1971 break;
1973 case INTEGER_TYPE:
1974 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1976 /* Output the type `char' as a subrange of itself!
1977 I don't understand this definition, just copied it
1978 from the output of pcc.
1979 This used to use `r2' explicitly and we used to
1980 take care to make sure that `char' was type number 2. */
1981 stabstr_C ('r');
1982 dbxout_type_index (type);
1983 stabstr_S (";0;127;");
1986 /* If this is a subtype of another integer type, always prefer to
1987 write it as a subtype. */
1988 else if (TREE_TYPE (type) != 0
1989 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1991 /* If the size is non-standard, say what it is if we can use
1992 GDB extensions. */
1994 if (use_gnu_debug_info_extensions
1995 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1997 stabstr_S ("@s");
1998 stabstr_D (TYPE_PRECISION (type));
1999 stabstr_C (';');
2002 dbxout_range_type (type, low, high);
2005 else
2007 /* If the size is non-standard, say what it is if we can use
2008 GDB extensions. */
2010 if (use_gnu_debug_info_extensions
2011 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2013 stabstr_S ("@s");
2014 stabstr_D (TYPE_PRECISION (type));
2015 stabstr_C (';');
2018 if (print_int_cst_bounds_in_octal_p (type, low, high))
2020 stabstr_C ('r');
2022 /* If this type derives from another type, output type index of
2023 parent type. This is particularly important when parent type
2024 is an enumerated type, because not generating the parent type
2025 index would transform the definition of this enumerated type
2026 into a plain unsigned type. */
2027 if (TREE_TYPE (type) != 0)
2028 dbxout_type_index (TREE_TYPE (type));
2029 else
2030 dbxout_type_index (type);
2032 stabstr_C (';');
2033 stabstr_O (low);
2034 stabstr_C (';');
2035 stabstr_O (high);
2036 stabstr_C (';');
2039 else
2040 /* Output other integer types as subranges of `int'. */
2041 dbxout_range_type (type, low, high);
2044 break;
2046 case REAL_TYPE:
2047 case FIXED_POINT_TYPE:
2048 /* This used to say `r1' and we used to take care
2049 to make sure that `int' was type number 1. */
2050 stabstr_C ('r');
2051 dbxout_type_index (integer_type_node);
2052 stabstr_C (';');
2053 stabstr_D (int_size_in_bytes (type));
2054 stabstr_S (";0;");
2055 break;
2057 case BOOLEAN_TYPE:
2058 if (use_gnu_debug_info_extensions)
2060 stabstr_S ("@s");
2061 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2062 stabstr_S (";-16;");
2064 else /* Define as enumeral type (False, True) */
2065 stabstr_S ("eFalse:0,True:1,;");
2066 break;
2068 case COMPLEX_TYPE:
2069 /* Differs from the REAL_TYPE by its new data type number.
2070 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
2071 codes since gdb doesn't care anyway. */
2073 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
2075 stabstr_S ("R3;");
2076 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
2077 stabstr_S (";0;");
2079 else
2081 /* Output a complex integer type as a structure,
2082 pending some other way to do it. */
2083 stabstr_C ('s');
2084 stabstr_D (int_size_in_bytes (type));
2086 stabstr_S ("real:");
2087 dbxout_type (TREE_TYPE (type), 0);
2088 stabstr_S (",0,");
2089 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2091 stabstr_S (";imag:");
2092 dbxout_type (TREE_TYPE (type), 0);
2093 stabstr_C (',');
2094 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2095 stabstr_C (',');
2096 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2097 stabstr_S (";;");
2099 break;
2101 case ARRAY_TYPE:
2102 /* Make arrays of packed bits look like bitstrings for chill. */
2103 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
2105 stabstr_S ("@s");
2106 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2107 stabstr_S (";@S;S");
2108 dbxout_type (TYPE_DOMAIN (type), 0);
2109 break;
2112 /* Output "a" followed by a range type definition
2113 for the index type of the array
2114 followed by a reference to the target-type.
2115 ar1;0;N;M for a C array of type M and size N+1. */
2116 /* Check if a character string type, which in Chill is
2117 different from an array of characters. */
2118 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
2120 stabstr_S ("@S;");
2122 tem = TYPE_DOMAIN (type);
2123 if (tem == NULL)
2125 stabstr_S ("ar");
2126 dbxout_type_index (integer_type_node);
2127 stabstr_S (";0;-1;");
2129 else
2131 stabstr_C ('a');
2132 dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem));
2135 dbxout_type (TREE_TYPE (type), 0);
2136 break;
2138 case VECTOR_TYPE:
2139 /* Make vectors look like an array. */
2140 if (use_gnu_debug_info_extensions)
2141 stabstr_S ("@V;");
2143 /* Output "a" followed by a range type definition
2144 for the index type of the array
2145 followed by a reference to the target-type.
2146 ar1;0;N;M for a C array of type M and size N+1. */
2147 stabstr_C ('a');
2148 dbxout_range_type (integer_type_node, size_zero_node,
2149 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
2151 dbxout_type (TREE_TYPE (type), 0);
2152 break;
2154 case RECORD_TYPE:
2155 case UNION_TYPE:
2156 case QUAL_UNION_TYPE:
2158 tree binfo = TYPE_BINFO (type);
2160 /* Output a structure type. We must use the same test here as we
2161 use in the DBX_NO_XREFS case above. */
2162 if ((TYPE_NAME (type) != 0
2163 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2164 && DECL_IGNORED_P (TYPE_NAME (type)))
2165 && !full)
2166 || !COMPLETE_TYPE_P (type)
2167 /* No way in DBX fmt to describe a variable size. */
2168 || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
2170 /* If the type is just a cross reference, output one
2171 and mark the type as partially described.
2172 If it later becomes defined, we will output
2173 its real definition.
2174 If the type has a name, don't nest its definition within
2175 another type's definition; instead, output an xref
2176 and let the definition come when the name is defined. */
2177 stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2178 if (TYPE_IDENTIFIER (type))
2180 /* Note that the C frontend creates for anonymous variable
2181 length records/unions TYPE_NAME with DECL_NAME NULL. */
2182 dbxout_type_name (type);
2184 else
2186 stabstr_S ("$$");
2187 stabstr_D (anonymous_type_number++);
2190 stabstr_C (':');
2191 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2192 break;
2195 /* Identify record or union, and print its size. */
2196 stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2197 stabstr_D (int_size_in_bytes (type));
2199 if (binfo)
2201 int i;
2202 tree child;
2203 vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
2205 if (use_gnu_debug_info_extensions)
2207 if (BINFO_N_BASE_BINFOS (binfo))
2209 stabstr_C ('!');
2210 stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2211 stabstr_C (',');
2214 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2216 tree access = (accesses ? (*accesses)[i] : access_public_node);
2218 if (use_gnu_debug_info_extensions)
2220 stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2221 stabstr_C (access == access_public_node ? '2' :
2222 access == access_protected_node
2223 ? '1' :'0');
2224 if (BINFO_VIRTUAL_P (child)
2225 && (lang_GNU_CXX ()
2226 || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
2227 /* For a virtual base, print the (negative)
2228 offset within the vtable where we must look
2229 to find the necessary adjustment. */
2230 stabstr_D
2231 (tree_to_shwi (BINFO_VPTR_FIELD (child))
2232 * BITS_PER_UNIT);
2233 else
2234 stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
2235 * BITS_PER_UNIT);
2236 stabstr_C (',');
2237 dbxout_type (BINFO_TYPE (child), 0);
2238 stabstr_C (';');
2240 else
2242 /* Print out the base class information with
2243 fields which have the same names at the types
2244 they hold. */
2245 dbxout_type_name (BINFO_TYPE (child));
2246 stabstr_C (':');
2247 dbxout_type (BINFO_TYPE (child), full);
2248 stabstr_C (',');
2249 stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
2250 * BITS_PER_UNIT);
2251 stabstr_C (',');
2252 stabstr_D
2253 (tree_to_shwi (TYPE_SIZE (BINFO_TYPE (child)))
2254 * BITS_PER_UNIT);
2255 stabstr_C (';');
2261 /* Write out the field declarations. */
2262 dbxout_type_fields (type);
2263 if (use_gnu_debug_info_extensions)
2264 dbxout_type_methods (type);
2266 stabstr_C (';');
2268 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2269 /* Avoid the ~ if we don't really need it--it confuses dbx. */
2270 && TYPE_VFIELD (type))
2273 /* We need to write out info about what field this class
2274 uses as its "main" vtable pointer field, because if this
2275 field is inherited from a base class, GDB cannot necessarily
2276 figure out which field it's using in time. */
2277 stabstr_S ("~%");
2278 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2279 stabstr_C (';');
2281 break;
2283 case ENUMERAL_TYPE:
2284 /* We must use the same test here as we use in the DBX_NO_XREFS case
2285 above. We simplify it a bit since an enum will never have a variable
2286 size. */
2287 if ((TYPE_NAME (type) != 0
2288 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2289 && DECL_IGNORED_P (TYPE_NAME (type)))
2290 && !full)
2291 || !COMPLETE_TYPE_P (type))
2293 stabstr_S ("xe");
2294 dbxout_type_name (type);
2295 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2296 stabstr_C (':');
2297 return;
2299 if (use_gnu_debug_info_extensions
2300 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2302 stabstr_S ("@s");
2303 stabstr_D (TYPE_PRECISION (type));
2304 stabstr_C (';');
2307 stabstr_C ('e');
2308 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2310 tree value = TREE_VALUE (tem);
2312 stabstr_I (TREE_PURPOSE (tem));
2313 stabstr_C (':');
2315 if (TREE_CODE (value) == CONST_DECL)
2316 value = DECL_INITIAL (value);
2318 if (cst_and_fits_in_hwi (value))
2319 stabstr_D (TREE_INT_CST_LOW (value));
2320 else
2321 stabstr_O (value);
2323 stabstr_C (',');
2324 if (TREE_CHAIN (tem) != 0)
2325 CONTIN;
2328 stabstr_C (';');
2329 break;
2331 case POINTER_TYPE:
2332 stabstr_C ('*');
2333 dbxout_type (TREE_TYPE (type), 0);
2334 break;
2336 case METHOD_TYPE:
2337 if (use_gnu_debug_info_extensions)
2339 stabstr_C ('#');
2341 /* Write the argument types out longhand. */
2342 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2343 stabstr_C (',');
2344 dbxout_type (TREE_TYPE (type), 0);
2345 dbxout_args (TYPE_ARG_TYPES (type));
2346 stabstr_C (';');
2348 else
2349 /* Treat it as a function type. */
2350 dbxout_type (TREE_TYPE (type), 0);
2351 break;
2353 case OFFSET_TYPE:
2354 if (use_gnu_debug_info_extensions)
2356 stabstr_C ('@');
2357 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2358 stabstr_C (',');
2359 dbxout_type (TREE_TYPE (type), 0);
2361 else
2362 /* Should print as an int, because it is really just an offset. */
2363 dbxout_type (integer_type_node, 0);
2364 break;
2366 case REFERENCE_TYPE:
2367 if (use_gnu_debug_info_extensions)
2369 stabstr_C ('&');
2371 else
2372 stabstr_C ('*');
2373 dbxout_type (TREE_TYPE (type), 0);
2374 break;
2376 case FUNCTION_TYPE:
2377 stabstr_C ('f');
2378 dbxout_type (TREE_TYPE (type), 0);
2379 break;
2381 case POINTER_BOUNDS_TYPE:
2382 /* No debug info for pointer bounds type supported yet. */
2383 break;
2385 default:
2386 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
2387 named 'auto' in its type.
2388 No debug info for TEMPLATE_TYPE_PARM type supported yet. */
2389 if (lang_GNU_CXX ())
2391 tree name = TYPE_IDENTIFIER (type);
2392 if (name == get_identifier ("auto")
2393 || name == get_identifier ("decltype(auto)"))
2394 break;
2397 gcc_unreachable ();
2401 /* Return nonzero if the given type represents an integer whose bounds
2402 should be printed in octal format. */
2404 static bool
2405 print_int_cst_bounds_in_octal_p (tree type, tree low, tree high)
2407 /* If we can use GDB extensions and the size is wider than a long
2408 (the size used by GDB to read them) or we may have trouble writing
2409 the bounds the usual way, write them in octal. Note the test is for
2410 the *target's* size of "long", not that of the host. The host test
2411 is just to make sure we can write it out in case the host wide int
2412 is narrower than the target "long".
2414 For unsigned types, we use octal if they are the same size or larger.
2415 This is because we print the bounds as signed decimal, and hence they
2416 can't span same size unsigned types. */
2418 if (use_gnu_debug_info_extensions
2419 && low && TREE_CODE (low) == INTEGER_CST
2420 && high && TREE_CODE (high) == INTEGER_CST
2421 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2422 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2423 && TYPE_UNSIGNED (type))
2424 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2425 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2426 && TYPE_UNSIGNED (type))))
2427 return TRUE;
2428 else
2429 return FALSE;
2432 /* Output the name of type TYPE, with no punctuation.
2433 Such names can be set up either by typedef declarations
2434 or by struct, enum and union tags. */
2436 static void
2437 dbxout_type_name (tree type)
2439 tree t = TYPE_NAME (type);
2441 gcc_assert (t);
2442 switch (TREE_CODE (t))
2444 case IDENTIFIER_NODE:
2445 break;
2446 case TYPE_DECL:
2447 t = DECL_NAME (t);
2448 break;
2449 default:
2450 gcc_unreachable ();
2453 stabstr_I (t);
2456 /* Output leading struct or class names needed for qualifying type
2457 whose scope is limited to a struct or class. */
2459 static void
2460 dbxout_class_name_qualifiers (tree decl)
2462 tree context = decl_type_context (decl);
2464 if (context != NULL_TREE
2465 && TREE_CODE (context) == RECORD_TYPE
2466 && TYPE_NAME (context) != 0
2467 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2468 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2470 tree name = TYPE_NAME (context);
2472 if (TREE_CODE (name) == TYPE_DECL)
2474 dbxout_class_name_qualifiers (name);
2475 name = DECL_NAME (name);
2477 stabstr_I (name);
2478 stabstr_S ("::");
2482 /* This is a specialized subset of expand_expr for use by dbxout_symbol in
2483 evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that
2484 haven't been expanded, or if the expression is getting so complex we won't
2485 be able to represent it in stabs anyway. Returns NULL on failure. */
2487 static rtx
2488 dbxout_expand_expr (tree expr)
2490 switch (TREE_CODE (expr))
2492 case VAR_DECL:
2493 /* We can't handle emulated tls variables, because the address is an
2494 offset to the return value of __emutls_get_address, and there is no
2495 way to express that in stabs. Also, there are name mangling issues
2496 here. We end up with references to undefined symbols if we don't
2497 disable debug info for these variables. */
2498 if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr))
2499 return NULL;
2500 if (TREE_STATIC (expr)
2501 && !TREE_ASM_WRITTEN (expr)
2502 && !DECL_HAS_VALUE_EXPR_P (expr)
2503 && !TREE_PUBLIC (expr)
2504 && DECL_RTL_SET_P (expr)
2505 && MEM_P (DECL_RTL (expr)))
2507 /* If this is a var that might not be actually output,
2508 return NULL, otherwise stabs might reference an undefined
2509 symbol. */
2510 varpool_node *node = varpool_node::get (expr);
2511 if (!node || !node->definition)
2512 return NULL;
2514 /* FALLTHRU */
2516 case PARM_DECL:
2517 case RESULT_DECL:
2518 if (DECL_HAS_VALUE_EXPR_P (expr))
2519 return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2520 /* FALLTHRU */
2522 case CONST_DECL:
2523 return DECL_RTL_IF_SET (expr);
2525 case INTEGER_CST:
2526 return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2528 case COMPONENT_REF:
2529 case ARRAY_REF:
2530 case ARRAY_RANGE_REF:
2531 case BIT_FIELD_REF:
2533 machine_mode mode;
2534 poly_int64 bitsize, bitpos;
2535 tree offset, tem;
2536 int unsignedp, reversep, volatilep = 0;
2537 rtx x;
2539 tem = get_inner_reference (expr, &bitsize, &bitpos, &offset, &mode,
2540 &unsignedp, &reversep, &volatilep);
2542 x = dbxout_expand_expr (tem);
2543 if (x == NULL || !MEM_P (x))
2544 return NULL;
2545 if (offset != NULL)
2547 if (!tree_fits_shwi_p (offset))
2548 return NULL;
2549 x = adjust_address_nv (x, mode, tree_to_shwi (offset));
2551 if (maybe_ne (bitpos, 0))
2552 x = adjust_address_nv (x, mode, bits_to_bytes_round_down (bitpos));
2554 return x;
2557 default:
2558 return NULL;
2562 /* Helper function for output_used_types. Queue one entry from the
2563 used types hash to be output. */
2565 bool
2566 output_used_types_helper (tree const &type, vec<tree> *types_p)
2568 if ((TREE_CODE (type) == RECORD_TYPE
2569 || TREE_CODE (type) == UNION_TYPE
2570 || TREE_CODE (type) == QUAL_UNION_TYPE
2571 || TREE_CODE (type) == ENUMERAL_TYPE)
2572 && TYPE_STUB_DECL (type)
2573 && DECL_P (TYPE_STUB_DECL (type))
2574 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
2575 types_p->quick_push (TYPE_STUB_DECL (type));
2576 else if (TYPE_NAME (type)
2577 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2578 types_p->quick_push (TYPE_NAME (type));
2580 return true;
2583 /* This is a qsort callback which sorts types and declarations into a
2584 predictable order (types, then declarations, sorted by UID
2585 within). */
2587 static int
2588 output_types_sort (const void *pa, const void *pb)
2590 const tree lhs = *((const tree *)pa);
2591 const tree rhs = *((const tree *)pb);
2593 if (TYPE_P (lhs))
2595 if (TYPE_P (rhs))
2596 return TYPE_UID (lhs) - TYPE_UID (rhs);
2597 else
2598 return 1;
2600 else
2602 if (TYPE_P (rhs))
2603 return -1;
2604 else
2605 return DECL_UID (lhs) - DECL_UID (rhs);
2610 /* Force all types used by this function to be output in debug
2611 information. */
2613 static void
2614 output_used_types (void)
2616 if (cfun && cfun->used_types_hash)
2618 vec<tree> types;
2619 int i;
2620 tree type;
2622 types.create (cfun->used_types_hash->elements ());
2623 cfun->used_types_hash->traverse<vec<tree> *, output_used_types_helper>
2624 (&types);
2626 /* Sort by UID to prevent dependence on hash table ordering. */
2627 types.qsort (output_types_sort);
2629 FOR_EACH_VEC_ELT (types, i, type)
2630 debug_queue_symbol (type);
2632 types.release ();
2636 /* Output a .stabs for the symbol defined by DECL,
2637 which must be a ..._DECL node in the normal namespace.
2638 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2639 LOCAL is nonzero if the scope is less than the entire file.
2640 Return 1 if a stabs might have been emitted. */
2643 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2645 tree type = TREE_TYPE (decl);
2646 tree context = NULL_TREE;
2647 int result = 0;
2648 rtx decl_rtl;
2650 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2651 ++debug_nesting;
2653 /* Ignore nameless syms, but don't ignore type tags. */
2655 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2656 || DECL_IGNORED_P (decl))
2657 DBXOUT_DECR_NESTING_AND_RETURN (0);
2659 /* If we are to generate only the symbols actually used then such
2660 symbol nodes are flagged with TREE_USED. Ignore any that
2661 aren't flagged as TREE_USED. */
2663 if (flag_debug_only_used_symbols
2664 && (!TREE_USED (decl)
2665 && (!VAR_P (decl) || !DECL_INITIAL (decl))))
2666 DBXOUT_DECR_NESTING_AND_RETURN (0);
2668 /* If dbxout_init has not yet run, queue this symbol for later. */
2669 if (!typevec)
2671 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2672 DBXOUT_DECR_NESTING_AND_RETURN (0);
2675 if (flag_debug_only_used_symbols)
2677 tree t;
2679 /* We now have a used symbol. We need to generate the info for
2680 the symbol's type in addition to the symbol itself. These
2681 type symbols are queued to be generated after were done with
2682 the symbol itself (otherwise they would fight over the
2683 stabstr obstack).
2685 Note, because the TREE_TYPE(type) might be something like a
2686 pointer to a named type we need to look for the first name
2687 we see following the TREE_TYPE chain. */
2689 t = type;
2690 while (POINTER_TYPE_P (t))
2691 t = TREE_TYPE (t);
2693 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2694 need special treatment. The TYPE_STUB_DECL field in these
2695 types generally represents the tag name type we want to
2696 output. In addition there could be a typedef type with
2697 a different name. In that case we also want to output
2698 that. */
2700 if (TREE_CODE (t) == RECORD_TYPE
2701 || TREE_CODE (t) == UNION_TYPE
2702 || TREE_CODE (t) == QUAL_UNION_TYPE
2703 || TREE_CODE (t) == ENUMERAL_TYPE)
2705 if (TYPE_STUB_DECL (t)
2706 && TYPE_STUB_DECL (t) != decl
2707 && DECL_P (TYPE_STUB_DECL (t))
2708 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2710 debug_queue_symbol (TYPE_STUB_DECL (t));
2711 if (TYPE_NAME (t)
2712 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2713 && TYPE_NAME (t) != decl
2714 && DECL_P (TYPE_NAME (t)))
2715 debug_queue_symbol (TYPE_NAME (t));
2718 else if (TYPE_NAME (t)
2719 && TYPE_NAME (t) != decl
2720 && DECL_P (TYPE_NAME (t)))
2721 debug_queue_symbol (TYPE_NAME (t));
2724 emit_pending_bincls_if_required ();
2726 switch (TREE_CODE (decl))
2728 case CONST_DECL:
2729 /* Enum values are defined by defining the enum type. */
2730 break;
2732 case FUNCTION_DECL:
2733 decl_rtl = DECL_RTL_IF_SET (decl);
2734 if (!decl_rtl)
2735 DBXOUT_DECR_NESTING_AND_RETURN (0);
2736 if (DECL_EXTERNAL (decl))
2737 break;
2738 /* Don't mention a nested function under its parent. */
2739 context = decl_function_context (decl);
2740 if (context == current_function_decl)
2741 break;
2742 /* Don't mention an inline instance of a nested function. */
2743 if (context && DECL_FROM_INLINE (decl))
2744 break;
2745 if (!MEM_P (decl_rtl)
2746 || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
2747 break;
2749 if (flag_debug_only_used_symbols)
2750 output_used_types ();
2752 dbxout_begin_complex_stabs ();
2753 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2754 stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2755 result = 1;
2757 if (TREE_TYPE (type))
2758 dbxout_type (TREE_TYPE (type), 0);
2759 else
2760 dbxout_type (void_type_node, 0);
2762 /* For a nested function, when that function is compiled,
2763 mention the containing function name
2764 as well as (since dbx wants it) our own assembler-name. */
2765 if (context != 0)
2767 stabstr_C (',');
2768 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2769 stabstr_C (',');
2770 stabstr_I (DECL_NAME (context));
2773 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
2774 break;
2776 case TYPE_DECL:
2777 /* Don't output the same typedef twice.
2778 And don't output what language-specific stuff doesn't want output. */
2779 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2780 DBXOUT_DECR_NESTING_AND_RETURN (0);
2782 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2783 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2785 int fundamental_type_number =
2786 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2788 if (fundamental_type_number != 0)
2790 TREE_ASM_WRITTEN (decl) = 1;
2791 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2792 DBXOUT_DECR_NESTING_AND_RETURN (0);
2795 #endif
2796 FORCE_TEXT;
2797 result = 1;
2799 int tag_needed = 1;
2800 int did_output = 0;
2802 if (DECL_NAME (decl))
2804 /* Nonzero means we must output a tag as well as a typedef. */
2805 tag_needed = 0;
2807 /* Handle the case of a C++ structure or union
2808 where the TYPE_NAME is a TYPE_DECL
2809 which gives both a typedef name and a tag. */
2810 /* dbx requires the tag first and the typedef second. */
2811 if ((TREE_CODE (type) == RECORD_TYPE
2812 || TREE_CODE (type) == UNION_TYPE
2813 || TREE_CODE (type) == QUAL_UNION_TYPE)
2814 && TYPE_NAME (type) == decl
2815 && !use_gnu_debug_info_extensions
2816 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2817 /* Distinguish the implicit typedefs of C++
2818 from explicit ones that might be found in C. */
2819 && DECL_ARTIFICIAL (decl)
2820 /* Do not generate a tag for incomplete records. */
2821 && COMPLETE_TYPE_P (type)
2822 /* Do not generate a tag for records of variable size,
2823 since this type can not be properly described in the
2824 DBX format, and it confuses some tools such as objdump. */
2825 && tree_fits_uhwi_p (TYPE_SIZE (type)))
2827 tree name = TYPE_IDENTIFIER (type);
2829 dbxout_begin_complex_stabs ();
2830 stabstr_I (name);
2831 stabstr_S (":T");
2832 dbxout_type (type, 1);
2833 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2834 0, 0, 0);
2837 dbxout_begin_complex_stabs ();
2839 /* Output leading class/struct qualifiers. */
2840 if (use_gnu_debug_info_extensions)
2841 dbxout_class_name_qualifiers (decl);
2843 /* Output typedef name. */
2844 stabstr_I (DECL_NAME (decl));
2845 stabstr_C (':');
2847 /* Short cut way to output a tag also. */
2848 if ((TREE_CODE (type) == RECORD_TYPE
2849 || TREE_CODE (type) == UNION_TYPE
2850 || TREE_CODE (type) == QUAL_UNION_TYPE)
2851 && TYPE_NAME (type) == decl
2852 /* Distinguish the implicit typedefs of C++
2853 from explicit ones that might be found in C. */
2854 && DECL_ARTIFICIAL (decl))
2856 if (use_gnu_debug_info_extensions)
2858 stabstr_C ('T');
2859 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2863 stabstr_C ('t');
2864 dbxout_type (type, 1);
2865 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2866 0, 0, 0);
2867 did_output = 1;
2870 /* Don't output a tag if this is an incomplete type. This prevents
2871 the sun4 Sun OS 4.x dbx from crashing. */
2873 if (tag_needed && TYPE_NAME (type) != 0
2874 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2875 || (DECL_NAME (TYPE_NAME (type)) != 0))
2876 && COMPLETE_TYPE_P (type)
2877 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2879 /* For a TYPE_DECL with no name, but the type has a name,
2880 output a tag.
2881 This is what represents `struct foo' with no typedef. */
2882 /* In C++, the name of a type is the corresponding typedef.
2883 In C, it is an IDENTIFIER_NODE. */
2884 tree name = TYPE_IDENTIFIER (type);
2886 dbxout_begin_complex_stabs ();
2887 stabstr_I (name);
2888 stabstr_S (":T");
2889 dbxout_type (type, 1);
2890 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2891 did_output = 1;
2894 /* If an enum type has no name, it cannot be referred to, but
2895 we must output it anyway, to record the enumeration
2896 constants. */
2898 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2900 dbxout_begin_complex_stabs ();
2901 /* Some debuggers fail when given NULL names, so give this a
2902 harmless name of " " (Why not "(anon)"?). */
2903 stabstr_S (" :T");
2904 dbxout_type (type, 1);
2905 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2908 /* Prevent duplicate output of a typedef. */
2909 TREE_ASM_WRITTEN (decl) = 1;
2910 break;
2913 case PARM_DECL:
2914 if (DECL_HAS_VALUE_EXPR_P (decl))
2915 decl = DECL_VALUE_EXPR (decl);
2917 /* PARM_DECLs go in their own separate chain and are output by
2918 dbxout_reg_parms and dbxout_parms, except for those that are
2919 disguised VAR_DECLs like Out parameters in Ada. */
2920 gcc_assert (VAR_P (decl));
2922 /* fall through */
2924 case RESULT_DECL:
2925 case VAR_DECL:
2926 /* Don't mention a variable that is external.
2927 Let the file that defines it describe it. */
2928 if (DECL_EXTERNAL (decl))
2929 break;
2931 /* If the variable is really a constant
2932 and not written in memory, inform the debugger.
2934 ??? Why do we skip emitting the type and location in this case? */
2935 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2936 && DECL_INITIAL (decl) != 0
2937 && tree_fits_shwi_p (DECL_INITIAL (decl))
2938 && ! TREE_ASM_WRITTEN (decl)
2939 && (DECL_FILE_SCOPE_P (decl)
2940 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
2941 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
2942 && TREE_PUBLIC (decl) == 0)
2944 /* The sun4 assembler does not grok this. */
2946 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2947 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2949 HOST_WIDE_INT ival = tree_to_shwi (DECL_INITIAL (decl));
2951 dbxout_begin_complex_stabs ();
2952 dbxout_symbol_name (decl, NULL, 'c');
2953 stabstr_S ("=i");
2954 stabstr_D (ival);
2955 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2956 DBXOUT_DECR_NESTING;
2957 return 1;
2959 else
2960 break;
2962 /* else it is something we handle like a normal variable. */
2964 decl_rtl = dbxout_expand_expr (decl);
2965 if (!decl_rtl)
2966 DBXOUT_DECR_NESTING_AND_RETURN (0);
2968 if (!is_global_var (decl))
2969 decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX);
2970 #ifdef LEAF_REG_REMAP
2971 if (crtl->uses_only_leaf_regs)
2972 leaf_renumber_regs_insn (decl_rtl);
2973 #endif
2975 result = dbxout_symbol_location (decl, type, 0, decl_rtl);
2976 break;
2978 default:
2979 break;
2981 DBXOUT_DECR_NESTING;
2982 return result;
2985 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2986 Add SUFFIX to its name, if SUFFIX is not 0.
2987 Describe the variable as residing in HOME
2988 (usually HOME is DECL_RTL (DECL), but not always).
2989 Returns 1 if the stab was really emitted. */
2991 static int
2992 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2994 int letter = 0;
2995 stab_code_type code;
2996 rtx addr = 0;
2997 int number = 0;
2998 int regno = -1;
3000 /* Don't mention a variable at all
3001 if it was completely optimized into nothingness.
3003 If the decl was from an inline function, then its rtl
3004 is not identically the rtl that was used in this
3005 particular compilation. */
3006 if (GET_CODE (home) == SUBREG)
3008 rtx value = home;
3010 while (GET_CODE (value) == SUBREG)
3011 value = SUBREG_REG (value);
3012 if (REG_P (value))
3014 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
3015 return 0;
3017 home = alter_subreg (&home, true);
3019 if (REG_P (home))
3021 regno = REGNO (home);
3022 if (regno >= FIRST_PSEUDO_REGISTER)
3023 return 0;
3026 /* The kind-of-variable letter depends on where
3027 the variable is and on the scope of its name:
3028 G and N_GSYM for static storage and global scope,
3029 S for static storage and file scope,
3030 V for static storage and local scope,
3031 for those two, use N_LCSYM if data is in bss segment,
3032 N_STSYM if in data segment, N_FUN otherwise.
3033 (We used N_FUN originally, then changed to N_STSYM
3034 to please GDB. However, it seems that confused ld.
3035 Now GDB has been fixed to like N_FUN, says Kingdon.)
3036 no letter at all, and N_LSYM, for auto variable,
3037 r and N_RSYM for register variable. */
3039 if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
3041 if (TREE_PUBLIC (decl))
3043 int offs;
3044 letter = 'G';
3045 code = N_GSYM;
3046 if (dbxout_common_check (decl, &offs) != NULL)
3048 letter = 'V';
3049 addr = 0;
3050 number = offs;
3053 else
3055 addr = XEXP (home, 0);
3057 letter = decl_function_context (decl) ? 'V' : 'S';
3059 /* Some ports can transform a symbol ref into a label ref,
3060 because the symbol ref is too far away and has to be
3061 dumped into a constant pool. Alternatively, the symbol
3062 in the constant pool might be referenced by a different
3063 symbol. */
3064 if (GET_CODE (addr) == SYMBOL_REF
3065 && CONSTANT_POOL_ADDRESS_P (addr))
3067 bool marked;
3068 rtx tmp = get_pool_constant_mark (addr, &marked);
3070 if (GET_CODE (tmp) == SYMBOL_REF)
3072 addr = tmp;
3073 if (CONSTANT_POOL_ADDRESS_P (addr))
3074 get_pool_constant_mark (addr, &marked);
3075 else
3076 marked = true;
3078 else if (GET_CODE (tmp) == LABEL_REF)
3080 addr = tmp;
3081 marked = true;
3084 /* If all references to the constant pool were optimized
3085 out, we just ignore the symbol. */
3086 if (!marked)
3087 return 0;
3090 /* This should be the same condition as in assemble_variable, but
3091 we don't have access to dont_output_data here. So, instead,
3092 we rely on the fact that error_mark_node initializers always
3093 end up in bss for C++ and never end up in bss for C. */
3094 if (DECL_INITIAL (decl) == 0
3095 || (lang_GNU_CXX ()
3096 && DECL_INITIAL (decl) == error_mark_node))
3098 int offs;
3099 code = N_LCSYM;
3100 if (dbxout_common_check (decl, &offs) != NULL)
3102 addr = 0;
3103 number = offs;
3104 letter = 'V';
3105 code = N_GSYM;
3108 else if (DECL_IN_TEXT_SECTION (decl))
3109 /* This is not quite right, but it's the closest
3110 of all the codes that Unix defines. */
3111 code = DBX_STATIC_CONST_VAR_CODE;
3112 else
3114 /* Ultrix `as' seems to need this. */
3115 #ifdef DBX_STATIC_STAB_DATA_SECTION
3116 switch_to_section (data_section);
3117 #endif
3118 code = N_STSYM;
3122 else if (regno >= 0)
3124 letter = 'r';
3125 code = N_RSYM;
3126 number = DBX_REGISTER_NUMBER (regno);
3128 else if (MEM_P (home)
3129 && (MEM_P (XEXP (home, 0))
3130 || (REG_P (XEXP (home, 0))
3131 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
3132 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
3133 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3134 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
3135 #endif
3137 /* If the value is indirect by memory or by a register
3138 that isn't the frame pointer
3139 then it means the object is variable-sized and address through
3140 that register or stack slot. DBX has no way to represent this
3141 so all we can do is output the variable as a pointer.
3142 If it's not a parameter, ignore it. */
3144 if (REG_P (XEXP (home, 0)))
3146 letter = 'r';
3147 code = N_RSYM;
3148 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
3149 return 0;
3150 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
3152 else
3154 code = N_LSYM;
3155 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
3156 We want the value of that CONST_INT. */
3157 number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
3160 /* Effectively do build_pointer_type, but don't cache this type,
3161 since it might be temporary whereas the type it points to
3162 might have been saved for inlining. */
3163 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
3164 type = make_node (POINTER_TYPE);
3165 TREE_TYPE (type) = TREE_TYPE (decl);
3167 else if (MEM_P (home)
3168 && REG_P (XEXP (home, 0)))
3170 code = N_LSYM;
3171 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3173 else if (MEM_P (home)
3174 && GET_CODE (XEXP (home, 0)) == PLUS
3175 && CONST_INT_P (XEXP (XEXP (home, 0), 1)))
3177 code = N_LSYM;
3178 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
3179 We want the value of that CONST_INT. */
3180 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3182 else if (MEM_P (home)
3183 && GET_CODE (XEXP (home, 0)) == CONST)
3185 /* Handle an obscure case which can arise when optimizing and
3186 when there are few available registers. (This is *always*
3187 the case for i386/i486 targets). The RTL looks like
3188 (MEM (CONST ...)) even though this variable is a local `auto'
3189 or a local `register' variable. In effect, what has happened
3190 is that the reload pass has seen that all assignments and
3191 references for one such a local variable can be replaced by
3192 equivalent assignments and references to some static storage
3193 variable, thereby avoiding the need for a register. In such
3194 cases we're forced to lie to debuggers and tell them that
3195 this variable was itself `static'. */
3196 int offs;
3197 code = N_LCSYM;
3198 letter = 'V';
3199 if (dbxout_common_check (decl, &offs) == NULL)
3200 addr = XEXP (XEXP (home, 0), 0);
3201 else
3203 addr = 0;
3204 number = offs;
3205 code = N_GSYM;
3208 else if (GET_CODE (home) == CONCAT)
3210 tree subtype;
3212 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
3213 for example), then there is no easy way to figure out
3214 what SUBTYPE should be. So, we give up. */
3215 if (TREE_CODE (type) != COMPLEX_TYPE)
3216 return 0;
3218 subtype = TREE_TYPE (type);
3220 /* If the variable's storage is in two parts,
3221 output each as a separate stab with a modified name. */
3222 if (WORDS_BIG_ENDIAN)
3223 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
3224 else
3225 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
3227 if (WORDS_BIG_ENDIAN)
3228 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
3229 else
3230 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
3231 return 1;
3233 else
3234 /* Address might be a MEM, when DECL is a variable-sized object.
3235 Or it might be const0_rtx, meaning previous passes
3236 want us to ignore this variable. */
3237 return 0;
3239 /* Ok, start a symtab entry and output the variable name. */
3240 emit_pending_bincls_if_required ();
3241 FORCE_TEXT;
3243 #ifdef DBX_STATIC_BLOCK_START
3244 DBX_STATIC_BLOCK_START (asm_out_file, code);
3245 #endif
3247 dbxout_begin_complex_stabs_noforcetext ();
3248 dbxout_symbol_name (decl, suffix, letter);
3249 dbxout_type (type, 0);
3250 dbxout_finish_complex_stabs (decl, code, addr, 0, number);
3252 #ifdef DBX_STATIC_BLOCK_END
3253 DBX_STATIC_BLOCK_END (asm_out_file, code);
3254 #endif
3255 return 1;
3258 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
3259 Then output LETTER to indicate the kind of location the symbol has. */
3261 static void
3262 dbxout_symbol_name (tree decl, const char *suffix, int letter)
3264 tree name;
3266 if (DECL_CONTEXT (decl)
3267 && (TYPE_P (DECL_CONTEXT (decl))
3268 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
3269 /* One slight hitch: if this is a VAR_DECL which is a class member
3270 or a namespace member, we must put out the mangled name instead of the
3271 DECL_NAME. Note also that static member (variable) names DO NOT begin
3272 with underscores in .stabs directives. */
3273 name = DECL_ASSEMBLER_NAME (decl);
3274 else
3275 /* ...but if we're function-local, we don't want to include the junk
3276 added by ASM_FORMAT_PRIVATE_NAME. */
3277 name = DECL_NAME (decl);
3279 if (name)
3280 stabstr_I (name);
3281 else
3282 stabstr_S ("(anon)");
3284 if (suffix)
3285 stabstr_S (suffix);
3286 stabstr_C (':');
3287 if (letter)
3288 stabstr_C (letter);
3292 /* Output the common block name for DECL in a stabs.
3294 Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair
3295 around each group of symbols in the same .comm area. The N_GSYM stabs
3296 that are emitted only contain the offset in the common area. This routine
3297 emits the N_BCOMM and N_ECOMM stabs. */
3299 static void
3300 dbxout_common_name (tree decl, const char *name, stab_code_type op)
3302 dbxout_begin_complex_stabs ();
3303 stabstr_S (name);
3304 dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0);
3307 /* Check decl to determine whether it is a VAR_DECL destined for storage in a
3308 common area. If it is, the return value will be a non-null string giving
3309 the name of the common storage block it will go into. If non-null, the
3310 value is the offset into the common block for that symbol's storage. */
3312 static const char *
3313 dbxout_common_check (tree decl, int *value)
3315 rtx home;
3316 rtx sym_addr;
3317 const char *name = NULL;
3319 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
3320 it does not have a value (the offset into the common area), or if it
3321 is thread local (as opposed to global) then it isn't common, and shouldn't
3322 be handled as such.
3324 ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs
3325 for thread-local symbols. Can be handled via same mechanism as used
3326 in dwarf2out.c. */
3327 if (!VAR_P (decl)
3328 || !TREE_STATIC (decl)
3329 || !DECL_HAS_VALUE_EXPR_P (decl)
3330 || DECL_THREAD_LOCAL_P (decl)
3331 || !is_fortran ())
3332 return NULL;
3334 home = DECL_RTL (decl);
3335 if (home == NULL_RTX || GET_CODE (home) != MEM)
3336 return NULL;
3338 sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl));
3339 if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM)
3340 return NULL;
3342 sym_addr = XEXP (sym_addr, 0);
3343 if (GET_CODE (sym_addr) == CONST)
3344 sym_addr = XEXP (sym_addr, 0);
3345 if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS)
3346 && DECL_INITIAL (decl) == 0)
3349 /* We have a sym that will go into a common area, meaning that it
3350 will get storage reserved with a .comm/.lcomm assembler pseudo-op.
3352 Determine name of common area this symbol will be an offset into,
3353 and offset into that area. Also retrieve the decl for the area
3354 that the symbol is offset into. */
3355 tree cdecl = NULL;
3357 switch (GET_CODE (sym_addr))
3359 case PLUS:
3360 if (CONST_INT_P (XEXP (sym_addr, 0)))
3362 name =
3363 targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 1), 0));
3364 *value = INTVAL (XEXP (sym_addr, 0));
3365 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1));
3367 else
3369 name =
3370 targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 0), 0));
3371 *value = INTVAL (XEXP (sym_addr, 1));
3372 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0));
3374 break;
3376 case SYMBOL_REF:
3377 name = targetm.strip_name_encoding (XSTR (sym_addr, 0));
3378 *value = 0;
3379 cdecl = SYMBOL_REF_DECL (sym_addr);
3380 break;
3382 default:
3383 error ("common symbol debug info is not structured as "
3384 "symbol+offset");
3387 /* Check area common symbol is offset into. If this is not public, then
3388 it is not a symbol in a common block. It must be a .lcomm symbol, not
3389 a .comm symbol. */
3390 if (cdecl == NULL || !TREE_PUBLIC (cdecl))
3391 name = NULL;
3393 else
3394 name = NULL;
3396 return name;
3399 /* Output definitions of all the decls in a chain. Return nonzero if
3400 anything was output */
3403 dbxout_syms (tree syms)
3405 int result = 0;
3406 const char *comm_prev = NULL;
3407 tree syms_prev = NULL;
3409 while (syms)
3411 int temp, copen, cclos;
3412 const char *comm_new;
3414 /* Check for common symbol, and then progression into a new/different
3415 block of common symbols. Emit closing/opening common bracket if
3416 necessary. */
3417 comm_new = dbxout_common_check (syms, &temp);
3418 copen = comm_new != NULL
3419 && (comm_prev == NULL || strcmp (comm_new, comm_prev));
3420 cclos = comm_prev != NULL
3421 && (comm_new == NULL || strcmp (comm_new, comm_prev));
3422 if (cclos)
3423 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3424 if (copen)
3426 dbxout_common_name (syms, comm_new, N_BCOMM);
3427 syms_prev = syms;
3429 comm_prev = comm_new;
3431 result += dbxout_symbol (syms, 1);
3432 syms = DECL_CHAIN (syms);
3435 if (comm_prev != NULL)
3436 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3438 return result;
3441 /* The following two functions output definitions of function parameters.
3442 Each parameter gets a definition locating it in the parameter list.
3443 Each parameter that is a register variable gets a second definition
3444 locating it in the register.
3446 Printing or argument lists in gdb uses the definitions that
3447 locate in the parameter list. But reference to the variable in
3448 expressions uses preferentially the definition as a register. */
3450 /* Output definitions, referring to storage in the parmlist,
3451 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
3453 void
3454 dbxout_parms (tree parms)
3456 ++debug_nesting;
3457 emit_pending_bincls_if_required ();
3458 fixed_size_mode rtl_mode, type_mode;
3460 for (; parms; parms = DECL_CHAIN (parms))
3461 if (DECL_NAME (parms)
3462 && TREE_TYPE (parms) != error_mark_node
3463 && DECL_RTL_SET_P (parms)
3464 && DECL_INCOMING_RTL (parms)
3465 /* We can't represent variable-sized types in this format. */
3466 && is_a <fixed_size_mode> (TYPE_MODE (TREE_TYPE (parms)), &type_mode)
3467 && is_a <fixed_size_mode> (GET_MODE (DECL_RTL (parms)), &rtl_mode))
3469 tree eff_type;
3470 char letter;
3471 stab_code_type code;
3472 int number;
3474 /* Perform any necessary register eliminations on the parameter's rtl,
3475 so that the debugging output will be accurate. */
3476 DECL_INCOMING_RTL (parms)
3477 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
3478 SET_DECL_RTL (parms,
3479 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
3480 #ifdef LEAF_REG_REMAP
3481 if (crtl->uses_only_leaf_regs)
3483 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3484 leaf_renumber_regs_insn (DECL_RTL (parms));
3486 #endif
3488 if (PARM_PASSED_IN_MEMORY (parms))
3490 rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3492 /* ??? Here we assume that the parm address is indexed
3493 off the frame pointer or arg pointer.
3494 If that is not true, we produce meaningless results,
3495 but do not crash. */
3496 if (GET_CODE (inrtl) == PLUS
3497 && CONST_INT_P (XEXP (inrtl, 1)))
3498 number = INTVAL (XEXP (inrtl, 1));
3499 else
3500 number = 0;
3502 code = N_PSYM;
3503 number = DEBUGGER_ARG_OFFSET (number, inrtl);
3504 letter = 'p';
3506 /* It is quite tempting to use TREE_TYPE (parms) instead
3507 of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3508 reports the actual type of the parameter, rather than
3509 the promoted type. This certainly makes GDB's life
3510 easier, at least for some ports. The change is a bad
3511 idea however, since GDB expects to be able access the
3512 type without performing any conversions. So for
3513 example, if we were passing a float to an unprototyped
3514 function, gcc will store a double on the stack, but if
3515 we emit a stab saying the type is a float, then gdb
3516 will only read in a single value, and this will produce
3517 an erroneous value. */
3518 eff_type = DECL_ARG_TYPE (parms);
3520 else if (REG_P (DECL_RTL (parms)))
3522 rtx best_rtl;
3524 /* Parm passed in registers and lives in registers or nowhere. */
3525 code = DBX_REGPARM_STABS_CODE;
3526 letter = DBX_REGPARM_STABS_LETTER;
3528 /* For parms passed in registers, it is better to use the
3529 declared type of the variable, not the type it arrived in. */
3530 eff_type = TREE_TYPE (parms);
3532 /* If parm lives in a register, use that register; pretend
3533 the parm was passed there. It would be more consistent
3534 to describe the register where the parm was passed, but
3535 in practice that register usually holds something else.
3536 If the parm lives nowhere, use the register where it
3537 was passed. */
3538 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3539 best_rtl = DECL_RTL (parms);
3540 else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL)
3541 best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0);
3542 else
3543 best_rtl = DECL_INCOMING_RTL (parms);
3545 number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3547 else if (MEM_P (DECL_RTL (parms))
3548 && REG_P (XEXP (DECL_RTL (parms), 0))
3549 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3550 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3551 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3552 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3553 #endif
3556 /* Parm was passed via invisible reference.
3557 That is, its address was passed in a register.
3558 Output it as if it lived in that register.
3559 The debugger will know from the type
3560 that it was actually passed by invisible reference. */
3562 code = DBX_REGPARM_STABS_CODE;
3564 /* GDB likes this marked with a special letter. */
3565 letter = (use_gnu_debug_info_extensions
3566 ? 'a' : DBX_REGPARM_STABS_LETTER);
3567 eff_type = TREE_TYPE (parms);
3569 /* DECL_RTL looks like (MEM (REG...). Get the register number.
3570 If it is an unallocated pseudo-reg, then use the register where
3571 it was passed instead.
3572 ??? Why is DBX_REGISTER_NUMBER not used here? */
3574 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3575 number = REGNO (XEXP (DECL_RTL (parms), 0));
3576 else
3577 number = REGNO (DECL_INCOMING_RTL (parms));
3579 else if (MEM_P (DECL_RTL (parms))
3580 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3582 /* Parm was passed via invisible reference, with the reference
3583 living on the stack. DECL_RTL looks like
3584 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3585 could look like (MEM (MEM (REG))). */
3587 code = N_PSYM;
3588 letter = 'v';
3589 eff_type = TREE_TYPE (parms);
3591 if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3592 number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3593 else
3594 number = 0;
3596 number = DEBUGGER_ARG_OFFSET (number,
3597 XEXP (XEXP (DECL_RTL (parms), 0), 0));
3599 else if (MEM_P (DECL_RTL (parms))
3600 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3601 /* ??? A constant address for a parm can happen
3602 when the reg it lives in is equiv to a constant in memory.
3603 Should make this not happen, after 2.4. */
3604 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3606 /* Parm was passed in registers but lives on the stack. */
3608 code = N_PSYM;
3609 letter = 'p';
3610 eff_type = TREE_TYPE (parms);
3612 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3613 in which case we want the value of that CONST_INT,
3614 or (MEM (REG ...)),
3615 in which case we use a value of zero. */
3616 if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3617 number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3618 else
3619 number = 0;
3621 /* Make a big endian correction if the mode of the type of the
3622 parameter is not the same as the mode of the rtl. */
3623 if (BYTES_BIG_ENDIAN
3624 && type_mode != rtl_mode
3625 && GET_MODE_SIZE (type_mode) < UNITS_PER_WORD)
3626 number += GET_MODE_SIZE (rtl_mode) - GET_MODE_SIZE (type_mode);
3628 else
3629 /* ??? We don't know how to represent this argument. */
3630 continue;
3632 dbxout_begin_complex_stabs ();
3634 if (DECL_NAME (parms))
3636 stabstr_I (DECL_NAME (parms));
3637 stabstr_C (':');
3639 else
3640 stabstr_S ("(anon):");
3641 stabstr_C (letter);
3642 dbxout_type (eff_type, 0);
3643 dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3645 DBXOUT_DECR_NESTING;
3648 /* Output definitions for the places where parms live during the function,
3649 when different from where they were passed, when the parms were passed
3650 in memory.
3652 It is not useful to do this for parms passed in registers
3653 that live during the function in different registers, because it is
3654 impossible to look in the passed register for the passed value,
3655 so we use the within-the-function register to begin with.
3657 PARMS is a chain of PARM_DECL nodes. */
3659 void
3660 dbxout_reg_parms (tree parms)
3662 ++debug_nesting;
3664 for (; parms; parms = DECL_CHAIN (parms))
3665 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3667 /* Report parms that live in registers during the function
3668 but were passed in memory. */
3669 if (REG_P (DECL_RTL (parms))
3670 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3671 dbxout_symbol_location (parms, TREE_TYPE (parms),
3672 0, DECL_RTL (parms));
3673 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3674 dbxout_symbol_location (parms, TREE_TYPE (parms),
3675 0, DECL_RTL (parms));
3676 /* Report parms that live in memory but not where they were passed. */
3677 else if (MEM_P (DECL_RTL (parms))
3678 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3679 dbxout_symbol_location (parms, TREE_TYPE (parms),
3680 0, DECL_RTL (parms));
3682 DBXOUT_DECR_NESTING;
3685 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3686 output definitions of those names, in raw form */
3688 static void
3689 dbxout_args (tree args)
3691 while (args)
3693 stabstr_C (',');
3694 dbxout_type (TREE_VALUE (args), 0);
3695 args = TREE_CHAIN (args);
3699 #if defined (DBX_DEBUGGING_INFO)
3701 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3702 BEGIN_LABEL is the name of the beginning of the function, which may
3703 be required. */
3704 static void
3705 dbx_output_lbrac (const char *label,
3706 const char *begin_label ATTRIBUTE_UNUSED)
3708 dbxout_begin_stabn (N_LBRAC);
3709 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3710 dbxout_stab_value_label_diff (label, begin_label);
3711 else
3712 dbxout_stab_value_label (label);
3715 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3716 BEGIN_LABEL is the name of the beginning of the function, which may
3717 be required. */
3718 static void
3719 dbx_output_rbrac (const char *label,
3720 const char *begin_label ATTRIBUTE_UNUSED)
3722 dbxout_begin_stabn (N_RBRAC);
3723 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3724 dbxout_stab_value_label_diff (label, begin_label);
3725 else
3726 dbxout_stab_value_label (label);
3729 /* Return true if at least one block among BLOCK, its children or siblings
3730 has TREE_USED, TREE_ASM_WRITTEN and BLOCK_IN_COLD_SECTION_P
3731 set. If there is none, clear TREE_USED bit on such blocks. */
3733 static bool
3734 dbx_block_with_cold_children (tree block)
3736 bool ret = false;
3737 for (; block; block = BLOCK_CHAIN (block))
3738 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3740 bool children = dbx_block_with_cold_children (BLOCK_SUBBLOCKS (block));
3741 if (BLOCK_IN_COLD_SECTION_P (block) || children)
3742 ret = true;
3743 else
3744 TREE_USED (block) = false;
3746 return ret;
3749 /* Output everything about a symbol block (a BLOCK node
3750 that represents a scope level),
3751 including recursive output of contained blocks.
3753 BLOCK is the BLOCK node.
3754 DEPTH is its depth within containing symbol blocks.
3755 ARGS is usually zero; but for the outermost block of the
3756 body of a function, it is a chain of PARM_DECLs for the function parameters.
3757 We output definitions of all the register parms
3758 as if they were local variables of that block.
3760 If -g1 was used, we count blocks just the same, but output nothing
3761 except for the outermost block.
3763 Actually, BLOCK may be several blocks chained together.
3764 We handle them all in sequence.
3766 Return true if we emitted any LBRAC/RBRAC. */
3768 static bool
3769 dbxout_block (tree block, int depth, tree args, int parent_blocknum)
3771 bool ret = false;
3772 char begin_label[20];
3773 /* Reference current function start using LFBB. */
3774 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
3776 /* If called for the second partition, ignore blocks that don't have
3777 any children in the second partition. */
3778 if (crtl->has_bb_partition && in_cold_section_p && depth == 0)
3779 dbx_block_with_cold_children (block);
3781 for (; block; block = BLOCK_CHAIN (block))
3783 /* Ignore blocks never expanded or otherwise marked as real. */
3784 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3786 int did_output;
3787 int blocknum = BLOCK_NUMBER (block);
3788 int this_parent = parent_blocknum;
3790 /* In dbx format, the syms of a block come before the N_LBRAC.
3791 If nothing is output, we don't need the N_LBRAC, either. */
3792 did_output = 0;
3793 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3794 did_output = dbxout_syms (BLOCK_VARS (block));
3795 if (args)
3796 dbxout_reg_parms (args);
3798 /* Now output an N_LBRAC symbol to represent the beginning of
3799 the block. Use the block's tree-walk order to generate
3800 the assembler symbols LBBn and LBEn
3801 that final will define around the code in this block. */
3802 if (did_output
3803 && BLOCK_IN_COLD_SECTION_P (block) == in_cold_section_p)
3805 char buf[20];
3806 const char *scope_start;
3808 ret = true;
3809 if (depth == 0)
3810 /* The outermost block doesn't get LBB labels; use
3811 the LFBB local symbol emitted by dbxout_begin_prologue. */
3812 scope_start = begin_label;
3813 else
3815 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3816 scope_start = buf;
3817 this_parent = blocknum;
3820 dbx_output_lbrac (scope_start, begin_label);
3823 /* Output the subblocks. */
3824 bool children
3825 = dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE,
3826 this_parent);
3827 ret |= children;
3829 /* Refer to the marker for the end of the block. */
3830 if (did_output
3831 && BLOCK_IN_COLD_SECTION_P (block) == in_cold_section_p)
3833 char buf[100];
3834 if (depth == 0)
3835 /* The outermost block doesn't get LBE labels;
3836 use the "scope" label which will be emitted
3837 by dbxout_function_end. */
3838 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3839 else
3840 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3842 dbx_output_rbrac (buf, begin_label);
3844 else if (did_output && !children)
3846 /* If we emitted any vars and didn't output any LBRAC/RBRAC,
3847 either at this level or any lower level, we need to emit
3848 an empty LBRAC/RBRAC pair now. */
3849 char buf[30];
3850 const char *scope_start;
3852 ret = true;
3853 if (parent_blocknum == -1)
3854 scope_start = begin_label;
3855 else
3857 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", parent_blocknum);
3858 scope_start = buf;
3861 dbx_output_lbrac (scope_start, begin_label);
3862 dbx_output_rbrac (scope_start, begin_label);
3866 return ret;
3869 /* Output the information about a function and its arguments and result.
3870 Usually this follows the function's code,
3871 but on some systems, it comes before. */
3873 static void
3874 dbxout_begin_function (tree decl)
3876 int saved_tree_used1;
3878 saved_tree_used1 = TREE_USED (decl);
3879 TREE_USED (decl) = 1;
3880 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3882 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3883 TREE_USED (DECL_RESULT (decl)) = 1;
3884 dbxout_symbol (decl, 0);
3885 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3887 else
3888 dbxout_symbol (decl, 0);
3889 TREE_USED (decl) = saved_tree_used1;
3891 dbxout_parms (DECL_ARGUMENTS (decl));
3892 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3893 dbxout_symbol (DECL_RESULT (decl), 1);
3895 #endif /* DBX_DEBUGGING_INFO */
3897 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3899 /* Record an element in the table of global destructors. SYMBOL is
3900 a SYMBOL_REF of the function to be called; PRIORITY is a number
3901 between 0 and MAX_INIT_PRIORITY. */
3903 void
3904 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
3905 int priority ATTRIBUTE_UNUSED)
3907 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
3908 /* Tell GNU LD that this is part of the static destructor set.
3909 This will work for any system that uses stabs, most usefully
3910 aout systems. */
3911 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
3912 dbxout_stab_value_label (XSTR (symbol, 0));
3913 #else
3914 sorry ("global destructors not supported on this target");
3915 #endif
3918 /* Likewise for global constructors. */
3920 void
3921 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
3922 int priority ATTRIBUTE_UNUSED)
3924 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
3925 /* Tell GNU LD that this is part of the static destructor set.
3926 This will work for any system that uses stabs, most usefully
3927 aout systems. */
3928 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
3929 dbxout_stab_value_label (XSTR (symbol, 0));
3930 #else
3931 sorry ("global constructors not supported on this target");
3932 #endif
3935 #include "gt-dbxout.h"