* ipa-prop.c (ipa_modify_expr): Set REF_REVERSE_STORAGE_ORDER on the
[official-gcc.git] / gcc / dbxout.c
blob8e0425463aabe259357a81e4ee0ba7d4aef19afc
1 /* Output dbx-format symbol table information from GNU compiler.
2 Copyright (C) 1987-2015 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 "tm.h"
73 #include "input.h"
74 #include "alias.h"
75 #include "symtab.h"
76 #include "tree.h"
77 #include "fold-const.h"
78 #include "varasm.h"
79 #include "stor-layout.h"
80 #include "rtl.h"
81 #include "flags.h"
82 #include "regs.h"
83 #include "insn-config.h"
84 #include "reload.h"
85 #include "output.h"
86 #include "dbxout.h"
87 #include "diagnostic-core.h"
88 #include "toplev.h"
89 #include "tm_p.h"
90 #include "debug.h"
91 #include "hard-reg-set.h"
92 #include "function.h"
93 #include "target.h"
94 #include "common/common-target.h"
95 #include "langhooks.h"
96 #include "obstack.h"
97 #include "expmed.h"
98 #include "dojump.h"
99 #include "explow.h"
100 #include "calls.h"
101 #include "emit-rtl.h"
102 #include "stmt.h"
103 #include "expr.h"
104 #include "is-a.h"
105 #include "plugin-api.h"
106 #include "ipa-ref.h"
107 #include "cgraph.h"
108 #include "stringpool.h"
110 #ifdef XCOFF_DEBUGGING_INFO
111 #include "xcoffout.h"
112 #endif
114 #ifndef ASM_STABS_OP
115 # ifdef XCOFF_DEBUGGING_INFO
116 # define ASM_STABS_OP "\t.stabx\t"
117 # else
118 # define ASM_STABS_OP "\t.stabs\t"
119 # endif
120 #endif
122 #ifndef ASM_STABN_OP
123 #define ASM_STABN_OP "\t.stabn\t"
124 #endif
126 #ifndef ASM_STABD_OP
127 #define ASM_STABD_OP "\t.stabd\t"
128 #endif
130 #ifndef DBX_TYPE_DECL_STABS_CODE
131 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
132 #endif
134 #ifndef DBX_STATIC_CONST_VAR_CODE
135 #define DBX_STATIC_CONST_VAR_CODE N_FUN
136 #endif
138 #ifndef DBX_REGPARM_STABS_CODE
139 #define DBX_REGPARM_STABS_CODE N_RSYM
140 #endif
142 #ifndef DBX_REGPARM_STABS_LETTER
143 #define DBX_REGPARM_STABS_LETTER 'P'
144 #endif
146 #ifndef NO_DBX_FUNCTION_END
147 #define NO_DBX_FUNCTION_END 0
148 #endif
150 #ifndef NO_DBX_BNSYM_ENSYM
151 #define NO_DBX_BNSYM_ENSYM 0
152 #endif
154 #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
155 #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
156 #endif
158 #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
159 #define DBX_BLOCKS_FUNCTION_RELATIVE 0
160 #endif
162 #ifndef DBX_LINES_FUNCTION_RELATIVE
163 #define DBX_LINES_FUNCTION_RELATIVE 0
164 #endif
166 #ifndef DBX_CONTIN_LENGTH
167 #define DBX_CONTIN_LENGTH 80
168 #endif
170 #ifndef DBX_CONTIN_CHAR
171 #define DBX_CONTIN_CHAR '\\'
172 #endif
174 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
176 /* Structure recording information about a C data type.
177 The status element says whether we have yet output
178 the definition of the type. TYPE_XREF says we have
179 output it as a cross-reference only.
180 The file_number and type_number elements are used if DBX_USE_BINCL
181 is defined. */
183 struct GTY(()) typeinfo {
184 enum typestatus status;
185 int file_number;
186 int type_number;
189 /* Vector recording information about C data types.
190 When we first notice a data type (a tree node),
191 we assign it a number using next_type_number.
192 That is its index in this vector. */
194 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
196 /* Number of elements of space allocated in `typevec'. */
198 static GTY(()) int typevec_len;
200 /* In dbx output, each type gets a unique number.
201 This is the number for the next type output.
202 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
204 static GTY(()) int next_type_number;
206 /* The C front end may call dbxout_symbol before dbxout_init runs.
207 We save all such decls in this list and output them when we get
208 to dbxout_init. */
210 static GTY(()) tree preinit_symbols;
212 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
214 /* When using N_BINCL in dbx output, each type number is actually a
215 pair of the file number and the type number within the file.
216 This is a stack of input files. */
218 struct dbx_file
220 struct dbx_file *next;
221 int file_number;
222 int next_type_number;
223 enum binclstatus bincl_status; /* Keep track of lazy bincl. */
224 const char *pending_bincl_name; /* Name of bincl. */
225 struct dbx_file *prev; /* Chain to traverse all pending bincls. */
228 /* This is the top of the stack.
230 This is not saved for PCH, because restoring a PCH should not change it.
231 next_file_number does have to be saved, because the PCH may use some
232 file numbers; however, just before restoring a PCH, next_file_number
233 should always be 0 because we should not have needed any file numbers
234 yet. */
236 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
237 && defined (DBX_USE_BINCL)
238 static struct dbx_file *current_file;
239 #endif
241 /* This is the next file number to use. */
243 static GTY(()) int next_file_number;
245 /* A counter for dbxout_function_end. */
247 static GTY(()) int scope_labelno;
249 /* A counter for dbxout_source_line. */
251 static GTY(()) int dbxout_source_line_counter;
253 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
254 for the N_SO filename stabs label. */
256 static GTY(()) int source_label_number = 1;
258 /* Last source file name mentioned in a NOTE insn. */
260 static GTY(()) const char *lastfile;
262 /* Used by PCH machinery to detect if 'lastfile' should be reset to
263 base_input_file. */
264 static GTY(()) int lastfile_is_base;
266 /* Typical USG systems don't have stab.h, and they also have
267 no use for DBX-format debugging info. */
269 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
271 #ifdef DBX_USE_BINCL
272 /* If zero then there is no pending BINCL. */
273 static int pending_bincls = 0;
274 #endif
276 /* The original input file name. */
277 static const char *base_input_file;
279 #ifdef DEBUG_SYMS_TEXT
280 #define FORCE_TEXT switch_to_section (current_function_section ())
281 #else
282 #define FORCE_TEXT
283 #endif
285 #include "gstab.h"
287 /* 1 if PARM is passed to this function in memory. */
289 #define PARM_PASSED_IN_MEMORY(PARM) \
290 (MEM_P (DECL_INCOMING_RTL (PARM)))
292 /* A C expression for the integer offset value of an automatic variable
293 (N_LSYM) having address X (an RTX). */
294 #ifndef DEBUGGER_AUTO_OFFSET
295 #define DEBUGGER_AUTO_OFFSET(X) \
296 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
297 #endif
299 /* A C expression for the integer offset value of an argument (N_PSYM)
300 having address X (an RTX). The nominal offset is OFFSET.
301 Note that we use OFFSET + 0 here to avoid the self-assign warning
302 when the macro is called in a context like
303 number = DEBUGGER_ARG_OFFSET(number, X) */
304 #ifndef DEBUGGER_ARG_OFFSET
305 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0)
306 #endif
308 /* This obstack holds the stab string currently being constructed. We
309 build it up here, then write it out, so we can split long lines up
310 properly (see dbxout_finish_complex_stabs). */
311 static struct obstack stabstr_ob;
312 static size_t stabstr_last_contin_point;
314 #ifdef DBX_USE_BINCL
315 static void emit_bincl_stab (const char *c);
316 static void emit_pending_bincls (void);
317 #endif
318 static inline void emit_pending_bincls_if_required (void);
320 static void dbxout_init (const char *);
322 static void dbxout_finish (const char *);
323 static void dbxout_start_source_file (unsigned, const char *);
324 static void dbxout_end_source_file (unsigned);
325 static void dbxout_typedefs (tree);
326 static void dbxout_type_index (tree);
327 static void dbxout_args (tree);
328 static void dbxout_type_fields (tree);
329 static void dbxout_type_method_1 (tree);
330 static void dbxout_type_methods (tree);
331 static void dbxout_range_type (tree, tree, tree);
332 static void dbxout_type (tree, int);
333 static bool print_int_cst_bounds_in_octal_p (tree, tree, tree);
334 static bool is_fortran (void);
335 static void dbxout_type_name (tree);
336 static void dbxout_class_name_qualifiers (tree);
337 static int dbxout_symbol_location (tree, tree, const char *, rtx);
338 static void dbxout_symbol_name (tree, const char *, int);
339 static void dbxout_common_name (tree, const char *, stab_code_type);
340 static const char *dbxout_common_check (tree, int *);
341 static void dbxout_early_global_decl (tree);
342 static void dbxout_late_global_decl (tree);
343 static void dbxout_type_decl (tree, int);
344 static void dbxout_handle_pch (unsigned);
345 static void debug_free_queue (void);
347 /* The debug hooks structure. */
348 #if defined (DBX_DEBUGGING_INFO)
350 static void dbxout_source_line (unsigned int, const char *, int, bool);
351 static void dbxout_begin_prologue (unsigned int, const char *);
352 static void dbxout_source_file (const char *);
353 static void dbxout_function_end (tree);
354 static void dbxout_begin_function (tree);
355 static void dbxout_begin_block (unsigned, unsigned);
356 static void dbxout_end_block (unsigned, unsigned);
357 static void dbxout_function_decl (tree);
359 const struct gcc_debug_hooks dbx_debug_hooks =
361 dbxout_init,
362 dbxout_finish,
363 debug_nothing_void,
364 debug_nothing_void,
365 debug_nothing_int_charstar,
366 debug_nothing_int_charstar,
367 dbxout_start_source_file,
368 dbxout_end_source_file,
369 dbxout_begin_block,
370 dbxout_end_block,
371 debug_true_const_tree, /* ignore_block */
372 dbxout_source_line, /* source_line */
373 dbxout_begin_prologue, /* begin_prologue */
374 debug_nothing_int_charstar, /* end_prologue */
375 debug_nothing_int_charstar, /* begin_epilogue */
376 debug_nothing_int_charstar, /* end_epilogue */
377 #ifdef DBX_FUNCTION_FIRST
378 dbxout_begin_function,
379 #else
380 debug_nothing_tree, /* begin_function */
381 #endif
382 debug_nothing_int, /* end_function */
383 debug_nothing_tree, /* register_main_translation_unit */
384 dbxout_function_decl,
385 dbxout_early_global_decl, /* early_global_decl */
386 dbxout_late_global_decl, /* late_global_decl */
387 dbxout_type_decl, /* type_decl */
388 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
389 debug_nothing_tree, /* deferred_inline_function */
390 debug_nothing_tree, /* outlining_inline_function */
391 debug_nothing_rtx_code_label, /* label */
392 dbxout_handle_pch, /* handle_pch */
393 debug_nothing_rtx_insn, /* var_location */
394 debug_nothing_void, /* switch_text_section */
395 debug_nothing_tree_tree, /* set_name */
396 0, /* start_end_main_source_file */
397 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
399 #endif /* DBX_DEBUGGING_INFO */
401 #if defined (XCOFF_DEBUGGING_INFO)
402 const struct gcc_debug_hooks xcoff_debug_hooks =
404 dbxout_init,
405 dbxout_finish,
406 debug_nothing_void,
407 debug_nothing_void,
408 debug_nothing_int_charstar,
409 debug_nothing_int_charstar,
410 dbxout_start_source_file,
411 dbxout_end_source_file,
412 xcoffout_begin_block,
413 xcoffout_end_block,
414 debug_true_const_tree, /* ignore_block */
415 xcoffout_source_line,
416 xcoffout_begin_prologue, /* begin_prologue */
417 debug_nothing_int_charstar, /* end_prologue */
418 debug_nothing_int_charstar, /* begin_epilogue */
419 xcoffout_end_epilogue,
420 debug_nothing_tree, /* begin_function */
421 xcoffout_end_function,
422 debug_nothing_tree, /* register_main_translation_unit */
423 debug_nothing_tree, /* function_decl */
424 dbxout_early_global_decl, /* early_global_decl */
425 dbxout_late_global_decl, /* late_global_decl */
426 dbxout_type_decl, /* type_decl */
427 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
428 debug_nothing_tree, /* deferred_inline_function */
429 debug_nothing_tree, /* outlining_inline_function */
430 debug_nothing_rtx_code_label, /* label */
431 dbxout_handle_pch, /* handle_pch */
432 debug_nothing_rtx_insn, /* var_location */
433 debug_nothing_void, /* switch_text_section */
434 debug_nothing_tree_tree, /* set_name */
435 0, /* start_end_main_source_file */
436 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
438 #endif /* XCOFF_DEBUGGING_INFO */
440 /* Numeric formatting helper macro. Note that this does not handle
441 hexadecimal. */
442 #define NUMBER_FMT_LOOP(P, NUM, BASE) \
443 do \
445 int digit = NUM % BASE; \
446 NUM /= BASE; \
447 *--P = digit + '0'; \
449 while (NUM > 0)
451 /* Utility: write a decimal integer NUM to asm_out_file. */
452 void
453 dbxout_int (int num)
455 char buf[64];
456 char *p = buf + sizeof buf;
457 unsigned int unum;
459 if (num == 0)
461 putc ('0', asm_out_file);
462 return;
464 if (num < 0)
466 putc ('-', asm_out_file);
467 unum = -num;
469 else
470 unum = num;
472 NUMBER_FMT_LOOP (p, unum, 10);
474 while (p < buf + sizeof buf)
476 putc (*p, asm_out_file);
477 p++;
482 /* Primitives for emitting simple stabs directives. All other stabs
483 routines should use these functions instead of directly emitting
484 stabs. They are exported because machine-dependent code may need
485 to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
486 forwards to code in CPU.c. */
488 /* The following functions should all be called immediately after one
489 of the dbxout_begin_stab* functions (below). They write out
490 various things as the value of a stab. */
492 /* Write out a literal zero as the value of a stab. */
493 void
494 dbxout_stab_value_zero (void)
496 fputs ("0\n", asm_out_file);
499 /* Write out the label LABEL as the value of a stab. */
500 void
501 dbxout_stab_value_label (const char *label)
503 assemble_name (asm_out_file, label);
504 putc ('\n', asm_out_file);
507 /* Write out the difference of two labels, LABEL - BASE, as the value
508 of a stab. */
509 void
510 dbxout_stab_value_label_diff (const char *label, const char *base)
512 assemble_name (asm_out_file, label);
513 putc ('-', asm_out_file);
514 assemble_name (asm_out_file, base);
515 putc ('\n', asm_out_file);
518 /* Write out an internal label as the value of a stab, and immediately
519 emit that internal label. This should be used only when
520 dbxout_stabd will not work. STEM is the name stem of the label,
521 COUNTERP is a pointer to a counter variable which will be used to
522 guarantee label uniqueness. */
523 void
524 dbxout_stab_value_internal_label (const char *stem, int *counterp)
526 char label[100];
527 int counter = counterp ? (*counterp)++ : 0;
529 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
530 dbxout_stab_value_label (label);
531 targetm.asm_out.internal_label (asm_out_file, stem, counter);
534 /* Write out the difference between BASE and an internal label as the
535 value of a stab, and immediately emit that internal label. STEM and
536 COUNTERP are as for dbxout_stab_value_internal_label. */
537 void
538 dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
539 const char *base)
541 char label[100];
542 int counter = counterp ? (*counterp)++ : 0;
544 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
545 dbxout_stab_value_label_diff (label, base);
546 targetm.asm_out.internal_label (asm_out_file, stem, counter);
549 /* The following functions produce specific kinds of stab directives. */
551 /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
552 void
553 dbxout_stabd (int stype, int sdesc)
555 fputs (ASM_STABD_OP, asm_out_file);
556 dbxout_int (stype);
557 fputs (",0,", asm_out_file);
558 dbxout_int (sdesc);
559 putc ('\n', asm_out_file);
562 /* Write a .stabn directive with type STYPE. This function stops
563 short of emitting the value field, which is the responsibility of
564 the caller (normally it will be either a symbol or the difference
565 of two symbols). */
567 void
568 dbxout_begin_stabn (int stype)
570 fputs (ASM_STABN_OP, asm_out_file);
571 dbxout_int (stype);
572 fputs (",0,0,", asm_out_file);
575 /* Write a .stabn directive with type N_SLINE and desc LINE. As above,
576 the value field is the responsibility of the caller. */
577 void
578 dbxout_begin_stabn_sline (int lineno)
580 fputs (ASM_STABN_OP, asm_out_file);
581 dbxout_int (N_SLINE);
582 fputs (",0,", asm_out_file);
583 dbxout_int (lineno);
584 putc (',', asm_out_file);
587 /* Begin a .stabs directive with string "", type STYPE, and desc and
588 other fields 0. The value field is the responsibility of the
589 caller. This function cannot be used for .stabx directives. */
590 void
591 dbxout_begin_empty_stabs (int stype)
593 fputs (ASM_STABS_OP, asm_out_file);
594 fputs ("\"\",", asm_out_file);
595 dbxout_int (stype);
596 fputs (",0,0,", asm_out_file);
599 /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
600 The value field is the responsibility of the caller. */
601 void
602 dbxout_begin_simple_stabs (const char *str, int stype)
604 fputs (ASM_STABS_OP, asm_out_file);
605 output_quoted_string (asm_out_file, str);
606 putc (',', asm_out_file);
607 dbxout_int (stype);
608 fputs (",0,0,", asm_out_file);
611 /* As above but use SDESC for the desc field. */
612 void
613 dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
615 fputs (ASM_STABS_OP, asm_out_file);
616 output_quoted_string (asm_out_file, str);
617 putc (',', asm_out_file);
618 dbxout_int (stype);
619 fputs (",0,", asm_out_file);
620 dbxout_int (sdesc);
621 putc (',', asm_out_file);
624 /* The next set of functions are entirely concerned with production of
625 "complex" .stabs directives: that is, .stabs directives whose
626 strings have to be constructed piecemeal. dbxout_type,
627 dbxout_symbol, etc. use these routines heavily. The string is queued
628 up in an obstack, then written out by dbxout_finish_complex_stabs, which
629 is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
630 (You might think it would be more efficient to go straight to stdio
631 when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
632 out not to be the case, and anyway this needs fewer #ifdefs.) */
634 /* Begin a complex .stabs directive. If we can, write the initial
635 ASM_STABS_OP to the asm_out_file. */
637 static void
638 dbxout_begin_complex_stabs (void)
640 emit_pending_bincls_if_required ();
641 FORCE_TEXT;
642 fputs (ASM_STABS_OP, asm_out_file);
643 putc ('"', asm_out_file);
644 gcc_assert (stabstr_last_contin_point == 0);
647 /* As above, but do not force text or emit pending bincls. This is
648 used by dbxout_symbol_location, which needs to do something else. */
649 static void
650 dbxout_begin_complex_stabs_noforcetext (void)
652 fputs (ASM_STABS_OP, asm_out_file);
653 putc ('"', asm_out_file);
654 gcc_assert (stabstr_last_contin_point == 0);
657 /* Add CHR, a single character, to the string being built. */
658 #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
660 /* Add STR, a normal C string, to the string being built. */
661 #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen (str))
663 /* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
664 #define stabstr_I(id) obstack_grow (&stabstr_ob, \
665 IDENTIFIER_POINTER (id), \
666 IDENTIFIER_LENGTH (id))
668 /* Add NUM, a signed decimal number, to the string being built. */
669 static void
670 stabstr_D (HOST_WIDE_INT num)
672 char buf[64];
673 char *p = buf + sizeof buf;
674 unsigned int unum;
676 if (num == 0)
678 stabstr_C ('0');
679 return;
681 if (num < 0)
683 stabstr_C ('-');
684 unum = -num;
686 else
687 unum = num;
689 NUMBER_FMT_LOOP (p, unum, 10);
691 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
694 /* Add NUM, an unsigned decimal number, to the string being built. */
695 static void
696 stabstr_U (unsigned HOST_WIDE_INT num)
698 char buf[64];
699 char *p = buf + sizeof buf;
700 if (num == 0)
702 stabstr_C ('0');
703 return;
705 NUMBER_FMT_LOOP (p, num, 10);
706 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
709 /* Add CST, an INTEGER_CST tree, to the string being built as an
710 unsigned octal number. This routine handles values which are
711 larger than a single HOST_WIDE_INT. */
712 static void
713 stabstr_O (tree cst)
715 int prec = TYPE_PRECISION (TREE_TYPE (cst));
716 int res_pres = prec % 3;
717 int i;
718 unsigned int digit;
720 /* Leading zero for base indicator. */
721 stabstr_C ('0');
723 /* If the value is zero, the base indicator will serve as the value
724 all by itself. */
725 if (wi::eq_p (cst, 0))
726 return;
728 /* GDB wants constants with no extra leading "1" bits, so
729 we need to remove any sign-extension that might be
730 present. */
731 if (res_pres == 1)
733 digit = wi::extract_uhwi (cst, prec - 1, 1);
734 stabstr_C ('0' + digit);
736 else if (res_pres == 2)
738 digit = wi::extract_uhwi (cst, prec - 2, 2);
739 stabstr_C ('0' + digit);
742 prec -= res_pres;
743 for (i = prec - 3; i >= 0; i = i - 3)
745 digit = wi::extract_uhwi (cst, i, 3);
746 stabstr_C ('0' + digit);
750 /* Called whenever it is safe to break a stabs string into multiple
751 .stabs directives. If the current string has exceeded the limit
752 set by DBX_CONTIN_LENGTH, mark the current position in the buffer
753 as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
754 it is a backslash) and a null character. */
755 static inline void
756 stabstr_continue (void)
758 if (DBX_CONTIN_LENGTH > 0
759 && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
760 > DBX_CONTIN_LENGTH)
762 if (DBX_CONTIN_CHAR == '\\')
763 obstack_1grow (&stabstr_ob, '\\');
764 obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
765 obstack_1grow (&stabstr_ob, '\0');
766 stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
769 #define CONTIN stabstr_continue ()
771 /* Macro subroutine of dbxout_finish_complex_stabs, which emits
772 all of the arguments to the .stabs directive after the string.
773 Overridden by xcoffout.h. CODE is the stabs code for this symbol;
774 LINE is the source line to write into the desc field (in extended
775 mode); SYM is the symbol itself.
777 ADDR, LABEL, and NUMBER are three different ways to represent the
778 stabs value field. At most one of these should be nonzero.
780 ADDR is used most of the time; it represents the value as an
781 RTL address constant.
783 LABEL is used (currently) only for N_CATCH stabs; it represents
784 the value as a string suitable for assemble_name.
786 NUMBER is used when the value is an offset from an implicit base
787 pointer (e.g. for a stack variable), or an index (e.g. for a
788 register variable). It represents the value as a decimal integer. */
790 #ifndef DBX_FINISH_STABS
791 #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \
792 do { \
793 int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
795 dbxout_int (CODE); \
796 fputs (",0,", asm_out_file); \
797 dbxout_int (line_); \
798 putc (',', asm_out_file); \
799 if (ADDR) \
800 output_addr_const (asm_out_file, ADDR); \
801 else if (LABEL) \
802 assemble_name (asm_out_file, LABEL); \
803 else \
804 dbxout_int (NUMBER); \
805 putc ('\n', asm_out_file); \
806 } while (0)
807 #endif
809 /* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
810 is zero, this has only to emit the close quote and the remainder of
811 the arguments. When it is nonzero, the string has been marshalled in
812 stabstr_ob, and this routine is responsible for breaking it up into
813 DBX_CONTIN_LENGTH-sized chunks.
815 SYM is the DECL of the symbol under consideration; it is used only
816 for its DECL_SOURCE_LINE. The other arguments are all passed directly
817 to DBX_FINISH_STABS; see above for details. */
819 static void
820 dbxout_finish_complex_stabs (tree sym, stab_code_type code,
821 rtx addr, const char *label, int number)
823 int line ATTRIBUTE_UNUSED;
824 char *str;
825 size_t len;
827 line = sym ? DECL_SOURCE_LINE (sym) : 0;
828 if (DBX_CONTIN_LENGTH > 0)
830 char *chunk;
831 size_t chunklen;
833 /* Nul-terminate the growing string, then get its size and
834 address. */
835 obstack_1grow (&stabstr_ob, '\0');
837 len = obstack_object_size (&stabstr_ob);
838 chunk = str = XOBFINISH (&stabstr_ob, char *);
840 /* Within the buffer are a sequence of NUL-separated strings,
841 each of which is to be written out as a separate stab
842 directive. */
843 for (;;)
845 chunklen = strlen (chunk);
846 fwrite (chunk, 1, chunklen, asm_out_file);
847 fputs ("\",", asm_out_file);
849 /* Must add an extra byte to account for the NUL separator. */
850 chunk += chunklen + 1;
851 len -= chunklen + 1;
853 /* Only put a line number on the last stab in the sequence. */
854 DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
855 addr, label, number);
856 if (len == 0)
857 break;
859 fputs (ASM_STABS_OP, asm_out_file);
860 putc ('"', asm_out_file);
862 stabstr_last_contin_point = 0;
864 else
866 /* No continuations - we can put the whole string out at once.
867 It is faster to augment the string with the close quote and
868 comma than to do a two-character fputs. */
869 obstack_grow (&stabstr_ob, "\",", 2);
870 len = obstack_object_size (&stabstr_ob);
871 str = XOBFINISH (&stabstr_ob, char *);
873 fwrite (str, 1, len, asm_out_file);
874 DBX_FINISH_STABS (sym, code, line, addr, label, number);
876 obstack_free (&stabstr_ob, str);
879 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
881 /* When -gused is used, emit debug info for only used symbols. But in
882 addition to the standard intercepted debug_hooks there are some
883 direct calls into this file, i.e., dbxout_symbol, dbxout_parms, and
884 dbxout_reg_params. Those routines may also be called from a higher
885 level intercepted routine. So to prevent recording data for an inner
886 call to one of these for an intercept, we maintain an intercept
887 nesting counter (debug_nesting). We only save the intercepted
888 arguments if the nesting is 1. */
889 static int debug_nesting = 0;
891 static tree *symbol_queue;
892 static int symbol_queue_index = 0;
893 static int symbol_queue_size = 0;
895 #define DBXOUT_DECR_NESTING \
896 if (--debug_nesting == 0 && symbol_queue_index > 0) \
897 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
899 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
900 do {--debug_nesting; return (x);} while (0)
902 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
904 #if defined (DBX_DEBUGGING_INFO)
906 static void
907 dbxout_function_end (tree decl ATTRIBUTE_UNUSED)
909 char lscope_label_name[100];
911 /* The Lscope label must be emitted even if we aren't doing anything
912 else; dbxout_block needs it. */
913 switch_to_section (function_section (current_function_decl));
915 /* Convert Lscope into the appropriate format for local labels in case
916 the system doesn't insert underscores in front of user generated
917 labels. */
918 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
919 targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
921 /* The N_FUN tag at the end of the function is a GNU extension,
922 which may be undesirable, and is unnecessary if we do not have
923 named sections. */
924 if (!use_gnu_debug_info_extensions
925 || NO_DBX_FUNCTION_END
926 || !targetm_common.have_named_sections)
927 return;
929 /* By convention, GCC will mark the end of a function with an N_FUN
930 symbol and an empty string. */
931 if (flag_reorder_blocks_and_partition)
933 dbxout_begin_empty_stabs (N_FUN);
934 dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label,
935 crtl->subsections.hot_section_label);
936 dbxout_begin_empty_stabs (N_FUN);
937 dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label,
938 crtl->subsections.cold_section_label);
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 Pascal") == 0)
968 return N_SO_PASCAL;
969 else if (strcmp (language_string, "GNU Objective-C") == 0)
970 return N_SO_OBJC;
971 else if (strcmp (language_string, "GNU Objective-C++") == 0)
972 return N_SO_OBJCPLUS;
973 else
974 return 0;
978 static bool
979 is_fortran (void)
981 unsigned int lang = get_lang_number ();
983 return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90);
986 /* At the beginning of compilation, start writing the symbol table.
987 Initialize `typevec' and output the standard data types of C. */
989 static void
990 dbxout_init (const char *input_file_name)
992 char ltext_label_name[100];
993 bool used_ltext_label_name = false;
994 tree syms = lang_hooks.decls.getdecls ();
995 const char *mapped_name;
997 typevec_len = 100;
998 typevec = ggc_cleared_vec_alloc<typeinfo> (typevec_len);
1000 /* stabstr_ob contains one string, which will be just fine with
1001 1-byte alignment. */
1002 obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
1004 /* Convert Ltext into the appropriate format for local labels in case
1005 the system doesn't insert underscores in front of user generated
1006 labels. */
1007 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
1009 /* Put the current working directory in an N_SO symbol. */
1010 if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
1012 static const char *cwd;
1014 if (!cwd)
1016 cwd = get_src_pwd ();
1017 if (cwd[0] == '\0')
1018 cwd = "/";
1019 else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
1020 cwd = concat (cwd, "/", NULL);
1021 cwd = remap_debug_filename (cwd);
1023 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
1024 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
1025 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1026 dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
1027 dbxout_stab_value_label (ltext_label_name);
1028 used_ltext_label_name = true;
1029 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1032 mapped_name = remap_debug_filename (input_file_name);
1033 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1034 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, mapped_name);
1035 #else
1036 dbxout_begin_simple_stabs_desc (mapped_name, N_SO, get_lang_number ());
1037 dbxout_stab_value_label (ltext_label_name);
1038 used_ltext_label_name = true;
1039 #endif
1041 if (used_ltext_label_name)
1043 switch_to_section (text_section);
1044 targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1047 /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1048 The string used is historical. */
1049 #ifndef NO_DBX_GCC_MARKER
1050 dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1051 dbxout_stab_value_zero ();
1052 #endif
1054 base_input_file = lastfile = input_file_name;
1056 next_type_number = 1;
1058 #ifdef DBX_USE_BINCL
1059 current_file = XNEW (struct dbx_file);
1060 current_file->next = NULL;
1061 current_file->file_number = 0;
1062 current_file->next_type_number = 1;
1063 next_file_number = 1;
1064 current_file->prev = NULL;
1065 current_file->bincl_status = BINCL_NOT_REQUIRED;
1066 current_file->pending_bincl_name = NULL;
1067 #endif
1069 /* Get all permanent types that have typedef names, and output them
1070 all, except for those already output. Some language front ends
1071 put these declarations in the top-level scope; some do not;
1072 the latter are responsible for calling debug_hooks->type_decl from
1073 their record_builtin_type function. */
1074 dbxout_typedefs (syms);
1076 if (preinit_symbols)
1078 tree t;
1079 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1080 dbxout_symbol (TREE_VALUE (t), 0);
1081 preinit_symbols = 0;
1085 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
1087 static void
1088 dbxout_typedefs (tree syms)
1090 for (; syms != NULL_TREE; syms = DECL_CHAIN (syms))
1092 if (TREE_CODE (syms) == TYPE_DECL)
1094 tree type = TREE_TYPE (syms);
1095 if (TYPE_NAME (type)
1096 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1097 && COMPLETE_OR_VOID_TYPE_P (type)
1098 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
1099 dbxout_symbol (TYPE_NAME (type), 0);
1104 #ifdef DBX_USE_BINCL
1105 /* Emit BINCL stab using given name. */
1106 static void
1107 emit_bincl_stab (const char *name)
1109 dbxout_begin_simple_stabs (name, N_BINCL);
1110 dbxout_stab_value_zero ();
1113 /* If there are pending bincls then it is time to emit all of them. */
1115 static inline void
1116 emit_pending_bincls_if_required (void)
1118 if (pending_bincls)
1119 emit_pending_bincls ();
1122 /* Emit all pending bincls. */
1124 static void
1125 emit_pending_bincls (void)
1127 struct dbx_file *f = current_file;
1129 /* Find first pending bincl. */
1130 while (f->bincl_status == BINCL_PENDING)
1131 f = f->next;
1133 /* Now emit all bincls. */
1134 f = f->prev;
1136 while (f)
1138 if (f->bincl_status == BINCL_PENDING)
1140 emit_bincl_stab (f->pending_bincl_name);
1142 /* Update file number and status. */
1143 f->file_number = next_file_number++;
1144 f->bincl_status = BINCL_PROCESSED;
1146 if (f == current_file)
1147 break;
1148 f = f->prev;
1151 /* All pending bincls have been emitted. */
1152 pending_bincls = 0;
1155 #else
1157 static inline void
1158 emit_pending_bincls_if_required (void) {}
1159 #endif
1161 /* Change to reading from a new source file. Generate a N_BINCL stab. */
1163 static void
1164 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1165 const char *filename ATTRIBUTE_UNUSED)
1167 #ifdef DBX_USE_BINCL
1168 struct dbx_file *n = XNEW (struct dbx_file);
1170 n->next = current_file;
1171 n->next_type_number = 1;
1172 /* Do not assign file number now.
1173 Delay it until we actually emit BINCL. */
1174 n->file_number = 0;
1175 n->prev = NULL;
1176 current_file->prev = n;
1177 n->bincl_status = BINCL_PENDING;
1178 n->pending_bincl_name = remap_debug_filename (filename);
1179 pending_bincls = 1;
1180 current_file = n;
1181 #endif
1184 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
1186 static void
1187 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1189 #ifdef DBX_USE_BINCL
1190 /* Emit EINCL stab only if BINCL is not pending. */
1191 if (current_file->bincl_status == BINCL_PROCESSED)
1193 dbxout_begin_stabn (N_EINCL);
1194 dbxout_stab_value_zero ();
1196 current_file->bincl_status = BINCL_NOT_REQUIRED;
1197 current_file = current_file->next;
1198 #endif
1201 /* Handle a few odd cases that occur when trying to make PCH files work. */
1203 static void
1204 dbxout_handle_pch (unsigned at_end)
1206 if (! at_end)
1208 /* When using the PCH, this file will be included, so we need to output
1209 a BINCL. */
1210 dbxout_start_source_file (0, lastfile);
1212 /* The base file when using the PCH won't be the same as
1213 the base file when it's being generated. */
1214 lastfile = NULL;
1216 else
1218 /* ... and an EINCL. */
1219 dbxout_end_source_file (0);
1221 /* Deal with cases where 'lastfile' was never actually changed. */
1222 lastfile_is_base = lastfile == NULL;
1226 #if defined (DBX_DEBUGGING_INFO)
1228 static void dbxout_block (tree, int, tree);
1230 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
1232 static void
1233 dbxout_source_file (const char *filename)
1235 if (lastfile == 0 && lastfile_is_base)
1237 lastfile = base_input_file;
1238 lastfile_is_base = 0;
1241 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
1243 /* Don't change section amid function. */
1244 if (current_function_decl == NULL_TREE)
1245 switch_to_section (text_section);
1247 dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL);
1248 dbxout_stab_value_internal_label ("Ltext", &source_label_number);
1249 lastfile = filename;
1253 /* Output N_BNSYM, line number symbol entry, and local symbol at
1254 function scope */
1256 static void
1257 dbxout_begin_prologue (unsigned int lineno, 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, 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, const char *filename,
1280 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
1302 /* Describe the beginning of an internal block within a function. */
1304 static void
1305 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1307 emit_pending_bincls_if_required ();
1308 targetm.asm_out.internal_label (asm_out_file, "LBB", n);
1311 /* Describe the end line-number of an internal block within a function. */
1313 static void
1314 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1316 emit_pending_bincls_if_required ();
1317 targetm.asm_out.internal_label (asm_out_file, "LBE", n);
1320 /* Output dbx data for a function definition.
1321 This includes a definition of the function name itself (a symbol),
1322 definitions of the parameters (locating them in the parameter list)
1323 and then output the block that makes up the function's body
1324 (including all the auto variables of the function). */
1326 static void
1327 dbxout_function_decl (tree decl)
1329 emit_pending_bincls_if_required ();
1330 #ifndef DBX_FUNCTION_FIRST
1331 dbxout_begin_function (decl);
1332 #endif
1333 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1334 dbxout_function_end (decl);
1337 #endif /* DBX_DEBUGGING_INFO */
1339 static void
1340 dbxout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1342 /* NYI for non-dwarf. */
1345 /* Debug information for a global DECL. Called from toplev.c after
1346 compilation proper has finished. */
1347 static void
1348 dbxout_late_global_decl (tree decl)
1350 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
1352 int saved_tree_used = TREE_USED (decl);
1353 TREE_USED (decl) = 1;
1354 dbxout_symbol (decl, 0);
1355 TREE_USED (decl) = saved_tree_used;
1359 /* This is just a function-type adapter; dbxout_symbol does exactly
1360 what we want but returns an int. */
1361 static void
1362 dbxout_type_decl (tree decl, int local)
1364 dbxout_symbol (decl, local);
1367 /* At the end of compilation, finish writing the symbol table.
1368 The default is to call debug_free_queue but do nothing else. */
1370 static void
1371 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
1373 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1374 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1375 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1377 switch_to_section (text_section);
1378 dbxout_begin_empty_stabs (N_SO);
1379 dbxout_stab_value_internal_label ("Letext", 0);
1381 #endif
1382 debug_free_queue ();
1385 /* Output the index of a type. */
1387 static void
1388 dbxout_type_index (tree type)
1390 #ifndef DBX_USE_BINCL
1391 stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1392 #else
1393 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1394 stabstr_C ('(');
1395 stabstr_D (t->file_number);
1396 stabstr_C (',');
1397 stabstr_D (t->type_number);
1398 stabstr_C (')');
1399 #endif
1403 /* Generate the symbols for any queued up type symbols we encountered
1404 while generating the type info for some originally used symbol.
1405 This might generate additional entries in the queue. Only when
1406 the nesting depth goes to 0 is this routine called. */
1408 static void
1409 debug_flush_symbol_queue (void)
1411 int i;
1413 /* Make sure that additionally queued items are not flushed
1414 prematurely. */
1416 ++debug_nesting;
1418 for (i = 0; i < symbol_queue_index; ++i)
1420 /* If we pushed queued symbols then such symbols must be
1421 output no matter what anyone else says. Specifically,
1422 we need to make sure dbxout_symbol() thinks the symbol was
1423 used and also we need to override TYPE_DECL_SUPPRESS_DEBUG
1424 which may be set for outside reasons. */
1425 int saved_tree_used = TREE_USED (symbol_queue[i]);
1426 int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]);
1427 TREE_USED (symbol_queue[i]) = 1;
1428 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0;
1430 #ifdef DBX_DEBUGGING_INFO
1431 dbxout_symbol (symbol_queue[i], 0);
1432 #endif
1434 TREE_USED (symbol_queue[i]) = saved_tree_used;
1435 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug;
1438 symbol_queue_index = 0;
1439 --debug_nesting;
1442 /* Queue a type symbol needed as part of the definition of a decl
1443 symbol. These symbols are generated when debug_flush_symbol_queue()
1444 is called. */
1446 static void
1447 debug_queue_symbol (tree decl)
1449 if (symbol_queue_index >= symbol_queue_size)
1451 symbol_queue_size += 10;
1452 symbol_queue = XRESIZEVEC (tree, symbol_queue, symbol_queue_size);
1455 symbol_queue[symbol_queue_index++] = decl;
1458 /* Free symbol queue. */
1459 static void
1460 debug_free_queue (void)
1462 if (symbol_queue)
1464 free (symbol_queue);
1465 symbol_queue = NULL;
1466 symbol_queue_size = 0;
1470 /* Used in several places: evaluates to '0' for a private decl,
1471 '1' for a protected decl, '2' for a public decl. */
1472 #define DECL_ACCESSIBILITY_CHAR(DECL) \
1473 (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1475 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
1476 This must be a separate function because anonymous unions require
1477 recursive calls. */
1479 static void
1480 dbxout_type_fields (tree type)
1482 tree tem;
1484 /* Output the name, type, position (in bits), size (in bits) of each
1485 field that we can support. */
1486 for (tem = TYPE_FIELDS (type); tem; tem = DECL_CHAIN (tem))
1488 /* If one of the nodes is an error_mark or its type is then
1489 return early. */
1490 if (error_operand_p (tem))
1491 return;
1493 /* Omit here local type decls until we know how to support them. */
1494 if (TREE_CODE (tem) == TYPE_DECL
1495 /* Omit here the nameless fields that are used to skip bits. */
1496 || DECL_IGNORED_P (tem)
1497 /* Omit fields whose position or size are variable or too large to
1498 represent. */
1499 || (TREE_CODE (tem) == FIELD_DECL
1500 && (! tree_fits_shwi_p (bit_position (tem))
1501 || ! DECL_SIZE (tem)
1502 || ! tree_fits_uhwi_p (DECL_SIZE (tem)))))
1503 continue;
1505 else if (TREE_CODE (tem) != CONST_DECL)
1507 /* Continue the line if necessary,
1508 but not before the first field. */
1509 if (tem != TYPE_FIELDS (type))
1510 CONTIN;
1512 if (DECL_NAME (tem))
1513 stabstr_I (DECL_NAME (tem));
1514 stabstr_C (':');
1516 if (use_gnu_debug_info_extensions
1517 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1518 || TREE_CODE (tem) != FIELD_DECL))
1520 stabstr_C ('/');
1521 stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
1524 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
1525 && DECL_BIT_FIELD_TYPE (tem))
1526 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
1528 if (TREE_CODE (tem) == VAR_DECL)
1530 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
1532 tree name = DECL_ASSEMBLER_NAME (tem);
1534 stabstr_C (':');
1535 stabstr_I (name);
1536 stabstr_C (';');
1538 else
1539 /* If TEM is non-static, GDB won't understand it. */
1540 stabstr_S (",0,0;");
1542 else
1544 stabstr_C (',');
1545 stabstr_D (int_bit_position (tem));
1546 stabstr_C (',');
1547 stabstr_D (tree_to_uhwi (DECL_SIZE (tem)));
1548 stabstr_C (';');
1554 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1555 method described DECL. */
1557 static void
1558 dbxout_type_method_1 (tree decl)
1560 char c1 = 'A', c2;
1562 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1563 c2 = '?';
1564 else /* it's a METHOD_TYPE. */
1566 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1567 /* A for normal functions.
1568 B for `const' member functions.
1569 C for `volatile' member functions.
1570 D for `const volatile' member functions. */
1571 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1572 c1 += 1;
1573 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1574 c1 += 2;
1576 if (DECL_VINDEX (decl))
1577 c2 = '*';
1578 else
1579 c2 = '.';
1582 /* ??? Output the mangled name, which contains an encoding of the
1583 method's type signature. May not be necessary anymore. */
1584 stabstr_C (':');
1585 stabstr_I (DECL_ASSEMBLER_NAME (decl));
1586 stabstr_C (';');
1587 stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1588 stabstr_C (c1);
1589 stabstr_C (c2);
1591 if (DECL_VINDEX (decl) && tree_fits_shwi_p (DECL_VINDEX (decl)))
1593 stabstr_D (tree_to_shwi (DECL_VINDEX (decl)));
1594 stabstr_C (';');
1595 dbxout_type (DECL_CONTEXT (decl), 0);
1596 stabstr_C (';');
1600 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1601 in TYPE. */
1603 static void
1604 dbxout_type_methods (tree type)
1606 /* C++: put out the method names and their parameter lists */
1607 tree methods = TYPE_METHODS (type);
1608 tree fndecl;
1609 tree last;
1611 if (methods == NULL_TREE)
1612 return;
1614 if (TREE_CODE (methods) != TREE_VEC)
1615 fndecl = methods;
1616 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1617 fndecl = TREE_VEC_ELT (methods, 0);
1618 else
1619 fndecl = TREE_VEC_ELT (methods, 1);
1621 while (fndecl)
1623 int need_prefix = 1;
1625 /* Group together all the methods for the same operation.
1626 These differ in the types of the arguments. */
1627 for (last = NULL_TREE;
1628 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1629 fndecl = DECL_CHAIN (fndecl))
1630 /* Output the name of the field (after overloading), as
1631 well as the name of the field before overloading, along
1632 with its parameter list */
1634 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1635 include TEMPLATE_DECLs.) The debugger doesn't know what
1636 to do with such entities anyhow. */
1637 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1638 continue;
1640 CONTIN;
1642 last = fndecl;
1644 /* Also ignore abstract methods; those are only interesting to
1645 the DWARF backends. */
1646 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT_P (fndecl))
1647 continue;
1649 /* Redundantly output the plain name, since that's what gdb
1650 expects. */
1651 if (need_prefix)
1653 stabstr_I (DECL_NAME (fndecl));
1654 stabstr_S ("::");
1655 need_prefix = 0;
1658 dbxout_type (TREE_TYPE (fndecl), 0);
1659 dbxout_type_method_1 (fndecl);
1661 if (!need_prefix)
1662 stabstr_C (';');
1666 /* Emit a "range" type specification, which has the form:
1667 "r<index type>;<lower bound>;<upper bound>;".
1668 TYPE is an INTEGER_TYPE, LOW and HIGH are the bounds. */
1670 static void
1671 dbxout_range_type (tree type, tree low, tree high)
1673 stabstr_C ('r');
1674 if (TREE_TYPE (type))
1675 dbxout_type (TREE_TYPE (type), 0);
1676 else if (TREE_CODE (type) != INTEGER_TYPE)
1677 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1678 else
1680 /* Traditionally, we made sure 'int' was type 1, and builtin types
1681 were defined to be sub-ranges of int. Unfortunately, this
1682 does not allow us to distinguish true sub-ranges from integer
1683 types. So, instead we define integer (non-sub-range) types as
1684 sub-ranges of themselves. This matters for Chill. If this isn't
1685 a subrange type, then we want to define it in terms of itself.
1686 However, in C, this may be an anonymous integer type, and we don't
1687 want to emit debug info referring to it. Just calling
1688 dbxout_type_index won't work anyways, because the type hasn't been
1689 defined yet. We make this work for both cases by checked to see
1690 whether this is a defined type, referring to it if it is, and using
1691 'int' otherwise. */
1692 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1693 dbxout_type_index (type);
1694 else
1695 dbxout_type_index (integer_type_node);
1698 stabstr_C (';');
1699 if (low && tree_fits_shwi_p (low))
1701 if (print_int_cst_bounds_in_octal_p (type, low, high))
1702 stabstr_O (low);
1703 else
1704 stabstr_D (tree_to_shwi (low));
1706 else
1707 stabstr_C ('0');
1709 stabstr_C (';');
1710 if (high && tree_fits_shwi_p (high))
1712 if (print_int_cst_bounds_in_octal_p (type, low, high))
1713 stabstr_O (high);
1714 else
1715 stabstr_D (tree_to_shwi (high));
1716 stabstr_C (';');
1718 else
1719 stabstr_S ("-1;");
1723 /* Output a reference to a type. If the type has not yet been
1724 described in the dbx output, output its definition now.
1725 For a type already defined, just refer to its definition
1726 using the type number.
1728 If FULL is nonzero, and the type has been described only with
1729 a forward-reference, output the definition now.
1730 If FULL is zero in this case, just refer to the forward-reference
1731 using the number previously allocated. */
1733 static void
1734 dbxout_type (tree type, int full)
1736 static int anonymous_type_number = 0;
1737 tree tem, main_variant, low, high;
1739 if (TREE_CODE (type) == INTEGER_TYPE)
1741 if (TREE_TYPE (type) == 0)
1743 low = TYPE_MIN_VALUE (type);
1744 high = TYPE_MAX_VALUE (type);
1747 else if (subrange_type_for_debug_p (type, &low, &high))
1750 /* If this is a subtype that should not be emitted as a subrange type,
1751 use the base type. */
1752 else
1754 type = TREE_TYPE (type);
1755 low = TYPE_MIN_VALUE (type);
1756 high = TYPE_MAX_VALUE (type);
1760 /* If there was an input error and we don't really have a type,
1761 avoid crashing and write something that is at least valid
1762 by assuming `int'. */
1763 if (type == error_mark_node)
1764 type = integer_type_node;
1765 else
1767 if (TYPE_NAME (type)
1768 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1769 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1770 full = 0;
1773 /* Try to find the "main variant" with the same name. */
1774 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1775 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1776 main_variant = TREE_TYPE (TYPE_NAME (type));
1777 else
1778 main_variant = TYPE_MAIN_VARIANT (type);
1780 /* If we are not using extensions, stabs does not distinguish const and
1781 volatile, so there is no need to make them separate types. */
1782 if (!use_gnu_debug_info_extensions)
1783 type = main_variant;
1785 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1787 /* Type has no dbx number assigned. Assign next available number. */
1788 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1790 /* Make sure type vector is long enough to record about this type. */
1792 if (next_type_number == typevec_len)
1794 typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2);
1795 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1796 typevec_len *= 2;
1799 #ifdef DBX_USE_BINCL
1800 emit_pending_bincls_if_required ();
1801 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1802 = current_file->file_number;
1803 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1804 = current_file->next_type_number++;
1805 #endif
1808 if (flag_debug_only_used_symbols)
1810 if ((TREE_CODE (type) == RECORD_TYPE
1811 || TREE_CODE (type) == UNION_TYPE
1812 || TREE_CODE (type) == QUAL_UNION_TYPE
1813 || TREE_CODE (type) == ENUMERAL_TYPE)
1814 && TYPE_STUB_DECL (type)
1815 && DECL_P (TYPE_STUB_DECL (type))
1816 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1817 debug_queue_symbol (TYPE_STUB_DECL (type));
1818 else if (TYPE_NAME (type)
1819 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1820 debug_queue_symbol (TYPE_NAME (type));
1823 /* Output the number of this type, to refer to it. */
1824 dbxout_type_index (type);
1826 #ifdef DBX_TYPE_DEFINED
1827 if (DBX_TYPE_DEFINED (type))
1828 return;
1829 #endif
1831 /* If this type's definition has been output or is now being output,
1832 that is all. */
1834 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1836 case TYPE_UNSEEN:
1837 break;
1838 case TYPE_XREF:
1839 /* If we have already had a cross reference,
1840 and either that's all we want or that's the best we could do,
1841 don't repeat the cross reference.
1842 Sun dbx crashes if we do. */
1843 if (! full || !COMPLETE_TYPE_P (type)
1844 /* No way in DBX fmt to describe a variable size. */
1845 || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
1846 return;
1847 break;
1848 case TYPE_DEFINED:
1849 return;
1852 #ifdef DBX_NO_XREFS
1853 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1854 leave the type-number completely undefined rather than output
1855 a cross-reference. If we have already used GNU debug info extensions,
1856 then it is OK to output a cross reference. This is necessary to get
1857 proper C++ debug output. */
1858 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1859 || TREE_CODE (type) == QUAL_UNION_TYPE
1860 || TREE_CODE (type) == ENUMERAL_TYPE)
1861 && ! use_gnu_debug_info_extensions)
1862 /* We must use the same test here as we use twice below when deciding
1863 whether to emit a cross-reference. */
1864 if ((TYPE_NAME (type) != 0
1865 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1866 && DECL_IGNORED_P (TYPE_NAME (type)))
1867 && !full)
1868 || !COMPLETE_TYPE_P (type)
1869 /* No way in DBX fmt to describe a variable size. */
1870 || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
1872 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1873 return;
1875 #endif
1877 /* Output a definition now. */
1878 stabstr_C ('=');
1880 /* Mark it as defined, so that if it is self-referent
1881 we will not get into an infinite recursion of definitions. */
1883 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1885 /* If this type is a variant of some other, hand off. Types with
1886 different names are usefully distinguished. We only distinguish
1887 cv-qualified types if we're using extensions. */
1888 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1890 stabstr_C ('k');
1891 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1892 return;
1894 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1896 stabstr_C ('B');
1897 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1898 return;
1900 else if (main_variant != TYPE_MAIN_VARIANT (type))
1902 if (flag_debug_only_used_symbols)
1904 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1906 if ((TREE_CODE (orig_type) == RECORD_TYPE
1907 || TREE_CODE (orig_type) == UNION_TYPE
1908 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1909 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1910 && TYPE_STUB_DECL (orig_type)
1911 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1912 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1914 /* 'type' is a typedef; output the type it refers to. */
1915 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1916 return;
1918 /* else continue. */
1920 switch (TREE_CODE (type))
1922 case VOID_TYPE:
1923 case NULLPTR_TYPE:
1924 case LANG_TYPE:
1925 /* For a void type, just define it as itself; i.e., "5=5".
1926 This makes us consider it defined
1927 without saying what it is. The debugger will make it
1928 a void type when the reference is seen, and nothing will
1929 ever override that default. */
1930 dbxout_type_index (type);
1931 break;
1933 case INTEGER_TYPE:
1934 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1936 /* Output the type `char' as a subrange of itself!
1937 I don't understand this definition, just copied it
1938 from the output of pcc.
1939 This used to use `r2' explicitly and we used to
1940 take care to make sure that `char' was type number 2. */
1941 stabstr_C ('r');
1942 dbxout_type_index (type);
1943 stabstr_S (";0;127;");
1946 /* If this is a subtype of another integer type, always prefer to
1947 write it as a subtype. */
1948 else if (TREE_TYPE (type) != 0
1949 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1951 /* If the size is non-standard, say what it is if we can use
1952 GDB extensions. */
1954 if (use_gnu_debug_info_extensions
1955 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1957 stabstr_S ("@s");
1958 stabstr_D (TYPE_PRECISION (type));
1959 stabstr_C (';');
1962 dbxout_range_type (type, low, high);
1965 else
1967 /* If the size is non-standard, say what it is if we can use
1968 GDB extensions. */
1970 if (use_gnu_debug_info_extensions
1971 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1973 stabstr_S ("@s");
1974 stabstr_D (TYPE_PRECISION (type));
1975 stabstr_C (';');
1978 if (print_int_cst_bounds_in_octal_p (type, low, high))
1980 stabstr_C ('r');
1982 /* If this type derives from another type, output type index of
1983 parent type. This is particularly important when parent type
1984 is an enumerated type, because not generating the parent type
1985 index would transform the definition of this enumerated type
1986 into a plain unsigned type. */
1987 if (TREE_TYPE (type) != 0)
1988 dbxout_type_index (TREE_TYPE (type));
1989 else
1990 dbxout_type_index (type);
1992 stabstr_C (';');
1993 stabstr_O (low);
1994 stabstr_C (';');
1995 stabstr_O (high);
1996 stabstr_C (';');
1999 else
2000 /* Output other integer types as subranges of `int'. */
2001 dbxout_range_type (type, low, high);
2004 break;
2006 case REAL_TYPE:
2007 case FIXED_POINT_TYPE:
2008 /* This used to say `r1' and we used to take care
2009 to make sure that `int' was type number 1. */
2010 stabstr_C ('r');
2011 dbxout_type_index (integer_type_node);
2012 stabstr_C (';');
2013 stabstr_D (int_size_in_bytes (type));
2014 stabstr_S (";0;");
2015 break;
2017 case BOOLEAN_TYPE:
2018 if (use_gnu_debug_info_extensions)
2020 stabstr_S ("@s");
2021 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2022 stabstr_S (";-16;");
2024 else /* Define as enumeral type (False, True) */
2025 stabstr_S ("eFalse:0,True:1,;");
2026 break;
2028 case COMPLEX_TYPE:
2029 /* Differs from the REAL_TYPE by its new data type number.
2030 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
2031 codes since gdb doesn't care anyway. */
2033 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
2035 stabstr_S ("R3;");
2036 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
2037 stabstr_S (";0;");
2039 else
2041 /* Output a complex integer type as a structure,
2042 pending some other way to do it. */
2043 stabstr_C ('s');
2044 stabstr_D (int_size_in_bytes (type));
2046 stabstr_S ("real:");
2047 dbxout_type (TREE_TYPE (type), 0);
2048 stabstr_S (",0,");
2049 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2051 stabstr_S (";imag:");
2052 dbxout_type (TREE_TYPE (type), 0);
2053 stabstr_C (',');
2054 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2055 stabstr_C (',');
2056 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2057 stabstr_S (";;");
2059 break;
2061 case ARRAY_TYPE:
2062 /* Make arrays of packed bits look like bitstrings for chill. */
2063 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
2065 stabstr_S ("@s");
2066 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2067 stabstr_S (";@S;S");
2068 dbxout_type (TYPE_DOMAIN (type), 0);
2069 break;
2072 /* Output "a" followed by a range type definition
2073 for the index type of the array
2074 followed by a reference to the target-type.
2075 ar1;0;N;M for a C array of type M and size N+1. */
2076 /* Check if a character string type, which in Chill is
2077 different from an array of characters. */
2078 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
2080 stabstr_S ("@S;");
2082 tem = TYPE_DOMAIN (type);
2083 if (tem == NULL)
2085 stabstr_S ("ar");
2086 dbxout_type_index (integer_type_node);
2087 stabstr_S (";0;-1;");
2089 else
2091 stabstr_C ('a');
2092 dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem));
2095 dbxout_type (TREE_TYPE (type), 0);
2096 break;
2098 case VECTOR_TYPE:
2099 /* Make vectors look like an array. */
2100 if (use_gnu_debug_info_extensions)
2101 stabstr_S ("@V;");
2103 /* Output "a" followed by a range type definition
2104 for the index type of the array
2105 followed by a reference to the target-type.
2106 ar1;0;N;M for a C array of type M and size N+1. */
2107 stabstr_C ('a');
2108 dbxout_range_type (integer_type_node, size_zero_node,
2109 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
2111 dbxout_type (TREE_TYPE (type), 0);
2112 break;
2114 case RECORD_TYPE:
2115 case UNION_TYPE:
2116 case QUAL_UNION_TYPE:
2118 tree binfo = TYPE_BINFO (type);
2120 /* Output a structure type. We must use the same test here as we
2121 use in the DBX_NO_XREFS case above. */
2122 if ((TYPE_NAME (type) != 0
2123 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2124 && DECL_IGNORED_P (TYPE_NAME (type)))
2125 && !full)
2126 || !COMPLETE_TYPE_P (type)
2127 /* No way in DBX fmt to describe a variable size. */
2128 || ! tree_fits_uhwi_p (TYPE_SIZE (type)))
2130 /* If the type is just a cross reference, output one
2131 and mark the type as partially described.
2132 If it later becomes defined, we will output
2133 its real definition.
2134 If the type has a name, don't nest its definition within
2135 another type's definition; instead, output an xref
2136 and let the definition come when the name is defined. */
2137 stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2138 if (TYPE_IDENTIFIER (type))
2140 /* Note that the C frontend creates for anonymous variable
2141 length records/unions TYPE_NAME with DECL_NAME NULL. */
2142 dbxout_type_name (type);
2144 else
2146 stabstr_S ("$$");
2147 stabstr_D (anonymous_type_number++);
2150 stabstr_C (':');
2151 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2152 break;
2155 /* Identify record or union, and print its size. */
2156 stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2157 stabstr_D (int_size_in_bytes (type));
2159 if (binfo)
2161 int i;
2162 tree child;
2163 vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
2165 if (use_gnu_debug_info_extensions)
2167 if (BINFO_N_BASE_BINFOS (binfo))
2169 stabstr_C ('!');
2170 stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2171 stabstr_C (',');
2174 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2176 tree access = (accesses ? (*accesses)[i] : access_public_node);
2178 if (use_gnu_debug_info_extensions)
2180 stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2181 stabstr_C (access == access_public_node ? '2' :
2182 access == access_protected_node
2183 ? '1' :'0');
2184 if (BINFO_VIRTUAL_P (child)
2185 && (lang_GNU_CXX ()
2186 || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
2187 /* For a virtual base, print the (negative)
2188 offset within the vtable where we must look
2189 to find the necessary adjustment. */
2190 stabstr_D
2191 (tree_to_shwi (BINFO_VPTR_FIELD (child))
2192 * BITS_PER_UNIT);
2193 else
2194 stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
2195 * BITS_PER_UNIT);
2196 stabstr_C (',');
2197 dbxout_type (BINFO_TYPE (child), 0);
2198 stabstr_C (';');
2200 else
2202 /* Print out the base class information with
2203 fields which have the same names at the types
2204 they hold. */
2205 dbxout_type_name (BINFO_TYPE (child));
2206 stabstr_C (':');
2207 dbxout_type (BINFO_TYPE (child), full);
2208 stabstr_C (',');
2209 stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
2210 * BITS_PER_UNIT);
2211 stabstr_C (',');
2212 stabstr_D
2213 (tree_to_shwi (TYPE_SIZE (BINFO_TYPE (child)))
2214 * BITS_PER_UNIT);
2215 stabstr_C (';');
2221 /* Write out the field declarations. */
2222 dbxout_type_fields (type);
2223 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2225 dbxout_type_methods (type);
2228 stabstr_C (';');
2230 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2231 /* Avoid the ~ if we don't really need it--it confuses dbx. */
2232 && TYPE_VFIELD (type))
2235 /* We need to write out info about what field this class
2236 uses as its "main" vtable pointer field, because if this
2237 field is inherited from a base class, GDB cannot necessarily
2238 figure out which field it's using in time. */
2239 stabstr_S ("~%");
2240 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2241 stabstr_C (';');
2243 break;
2245 case ENUMERAL_TYPE:
2246 /* We must use the same test here as we use in the DBX_NO_XREFS case
2247 above. We simplify it a bit since an enum will never have a variable
2248 size. */
2249 if ((TYPE_NAME (type) != 0
2250 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2251 && DECL_IGNORED_P (TYPE_NAME (type)))
2252 && !full)
2253 || !COMPLETE_TYPE_P (type))
2255 stabstr_S ("xe");
2256 dbxout_type_name (type);
2257 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2258 stabstr_C (':');
2259 return;
2261 if (use_gnu_debug_info_extensions
2262 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2264 stabstr_S ("@s");
2265 stabstr_D (TYPE_PRECISION (type));
2266 stabstr_C (';');
2269 stabstr_C ('e');
2270 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2272 tree value = TREE_VALUE (tem);
2274 stabstr_I (TREE_PURPOSE (tem));
2275 stabstr_C (':');
2277 if (TREE_CODE (value) == CONST_DECL)
2278 value = DECL_INITIAL (value);
2280 if (cst_and_fits_in_hwi (value))
2281 stabstr_D (TREE_INT_CST_LOW (value));
2282 else
2283 stabstr_O (value);
2285 stabstr_C (',');
2286 if (TREE_CHAIN (tem) != 0)
2287 CONTIN;
2290 stabstr_C (';');
2291 break;
2293 case POINTER_TYPE:
2294 stabstr_C ('*');
2295 dbxout_type (TREE_TYPE (type), 0);
2296 break;
2298 case METHOD_TYPE:
2299 if (use_gnu_debug_info_extensions)
2301 stabstr_C ('#');
2303 /* Write the argument types out longhand. */
2304 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2305 stabstr_C (',');
2306 dbxout_type (TREE_TYPE (type), 0);
2307 dbxout_args (TYPE_ARG_TYPES (type));
2308 stabstr_C (';');
2310 else
2311 /* Treat it as a function type. */
2312 dbxout_type (TREE_TYPE (type), 0);
2313 break;
2315 case OFFSET_TYPE:
2316 if (use_gnu_debug_info_extensions)
2318 stabstr_C ('@');
2319 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2320 stabstr_C (',');
2321 dbxout_type (TREE_TYPE (type), 0);
2323 else
2324 /* Should print as an int, because it is really just an offset. */
2325 dbxout_type (integer_type_node, 0);
2326 break;
2328 case REFERENCE_TYPE:
2329 if (use_gnu_debug_info_extensions)
2331 stabstr_C ('&');
2333 else
2334 stabstr_C ('*');
2335 dbxout_type (TREE_TYPE (type), 0);
2336 break;
2338 case FUNCTION_TYPE:
2339 stabstr_C ('f');
2340 dbxout_type (TREE_TYPE (type), 0);
2341 break;
2343 case POINTER_BOUNDS_TYPE:
2344 /* No debug info for pointer bounds type supported yet. */
2345 break;
2347 default:
2348 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
2349 named 'auto' in its type.
2350 No debug info for TEMPLATE_TYPE_PARM type supported yet. */
2351 if (lang_GNU_CXX ())
2353 tree name = TYPE_IDENTIFIER (type);
2354 if (name == get_identifier ("auto")
2355 || name == get_identifier ("decltype(auto)"))
2356 break;
2359 gcc_unreachable ();
2363 /* Return nonzero if the given type represents an integer whose bounds
2364 should be printed in octal format. */
2366 static bool
2367 print_int_cst_bounds_in_octal_p (tree type, tree low, tree high)
2369 /* If we can use GDB extensions and the size is wider than a long
2370 (the size used by GDB to read them) or we may have trouble writing
2371 the bounds the usual way, write them in octal. Note the test is for
2372 the *target's* size of "long", not that of the host. The host test
2373 is just to make sure we can write it out in case the host wide int
2374 is narrower than the target "long".
2376 For unsigned types, we use octal if they are the same size or larger.
2377 This is because we print the bounds as signed decimal, and hence they
2378 can't span same size unsigned types. */
2380 if (use_gnu_debug_info_extensions
2381 && low && TREE_CODE (low) == INTEGER_CST
2382 && high && TREE_CODE (high) == INTEGER_CST
2383 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2384 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2385 && TYPE_UNSIGNED (type))
2386 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2387 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2388 && TYPE_UNSIGNED (type))))
2389 return TRUE;
2390 else
2391 return FALSE;
2394 /* Output the name of type TYPE, with no punctuation.
2395 Such names can be set up either by typedef declarations
2396 or by struct, enum and union tags. */
2398 static void
2399 dbxout_type_name (tree type)
2401 tree t = TYPE_NAME (type);
2403 gcc_assert (t);
2404 switch (TREE_CODE (t))
2406 case IDENTIFIER_NODE:
2407 break;
2408 case TYPE_DECL:
2409 t = DECL_NAME (t);
2410 break;
2411 default:
2412 gcc_unreachable ();
2415 stabstr_I (t);
2418 /* Output leading leading struct or class names needed for qualifying
2419 type whose scope is limited to a struct or class. */
2421 static void
2422 dbxout_class_name_qualifiers (tree decl)
2424 tree context = decl_type_context (decl);
2426 if (context != NULL_TREE
2427 && TREE_CODE (context) == RECORD_TYPE
2428 && TYPE_NAME (context) != 0
2429 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2430 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2432 tree name = TYPE_NAME (context);
2434 if (TREE_CODE (name) == TYPE_DECL)
2436 dbxout_class_name_qualifiers (name);
2437 name = DECL_NAME (name);
2439 stabstr_I (name);
2440 stabstr_S ("::");
2444 /* This is a specialized subset of expand_expr for use by dbxout_symbol in
2445 evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that
2446 haven't been expanded, or if the expression is getting so complex we won't
2447 be able to represent it in stabs anyway. Returns NULL on failure. */
2449 static rtx
2450 dbxout_expand_expr (tree expr)
2452 switch (TREE_CODE (expr))
2454 case VAR_DECL:
2455 /* We can't handle emulated tls variables, because the address is an
2456 offset to the return value of __emutls_get_address, and there is no
2457 way to express that in stabs. Also, there are name mangling issues
2458 here. We end up with references to undefined symbols if we don't
2459 disable debug info for these variables. */
2460 if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr))
2461 return NULL;
2462 if (TREE_STATIC (expr)
2463 && !TREE_ASM_WRITTEN (expr)
2464 && !DECL_HAS_VALUE_EXPR_P (expr)
2465 && !TREE_PUBLIC (expr)
2466 && DECL_RTL_SET_P (expr)
2467 && MEM_P (DECL_RTL (expr)))
2469 /* If this is a var that might not be actually output,
2470 return NULL, otherwise stabs might reference an undefined
2471 symbol. */
2472 varpool_node *node = varpool_node::get (expr);
2473 if (!node || !node->definition)
2474 return NULL;
2476 /* FALLTHRU */
2478 case PARM_DECL:
2479 case RESULT_DECL:
2480 if (DECL_HAS_VALUE_EXPR_P (expr))
2481 return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2482 /* FALLTHRU */
2484 case CONST_DECL:
2485 return DECL_RTL_IF_SET (expr);
2487 case INTEGER_CST:
2488 return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2490 case COMPONENT_REF:
2491 case ARRAY_REF:
2492 case ARRAY_RANGE_REF:
2493 case BIT_FIELD_REF:
2495 machine_mode mode;
2496 HOST_WIDE_INT bitsize, bitpos;
2497 tree offset, tem;
2498 int unsignedp, reversep, volatilep = 0;
2499 rtx x;
2501 tem = get_inner_reference (expr, &bitsize, &bitpos, &offset, &mode,
2502 &unsignedp, &reversep, &volatilep, true);
2504 x = dbxout_expand_expr (tem);
2505 if (x == NULL || !MEM_P (x))
2506 return NULL;
2507 if (offset != NULL)
2509 if (!tree_fits_shwi_p (offset))
2510 return NULL;
2511 x = adjust_address_nv (x, mode, tree_to_shwi (offset));
2513 if (bitpos != 0)
2514 x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
2516 return x;
2519 default:
2520 return NULL;
2524 /* Helper function for output_used_types. Queue one entry from the
2525 used types hash to be output. */
2527 bool
2528 output_used_types_helper (tree const &type, vec<tree> *types_p)
2530 if ((TREE_CODE (type) == RECORD_TYPE
2531 || TREE_CODE (type) == UNION_TYPE
2532 || TREE_CODE (type) == QUAL_UNION_TYPE
2533 || TREE_CODE (type) == ENUMERAL_TYPE)
2534 && TYPE_STUB_DECL (type)
2535 && DECL_P (TYPE_STUB_DECL (type))
2536 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
2537 types_p->quick_push (TYPE_STUB_DECL (type));
2538 else if (TYPE_NAME (type)
2539 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2540 types_p->quick_push (TYPE_NAME (type));
2542 return true;
2545 /* This is a qsort callback which sorts types and declarations into a
2546 predictable order (types, then declarations, sorted by UID
2547 within). */
2549 static int
2550 output_types_sort (const void *pa, const void *pb)
2552 const tree lhs = *((const tree *)pa);
2553 const tree rhs = *((const tree *)pb);
2555 if (TYPE_P (lhs))
2557 if (TYPE_P (rhs))
2558 return TYPE_UID (lhs) - TYPE_UID (rhs);
2559 else
2560 return 1;
2562 else
2564 if (TYPE_P (rhs))
2565 return -1;
2566 else
2567 return DECL_UID (lhs) - DECL_UID (rhs);
2572 /* Force all types used by this function to be output in debug
2573 information. */
2575 static void
2576 output_used_types (void)
2578 if (cfun && cfun->used_types_hash)
2580 vec<tree> types;
2581 int i;
2582 tree type;
2584 types.create (cfun->used_types_hash->elements ());
2585 cfun->used_types_hash->traverse<vec<tree> *, output_used_types_helper>
2586 (&types);
2588 /* Sort by UID to prevent dependence on hash table ordering. */
2589 types.qsort (output_types_sort);
2591 FOR_EACH_VEC_ELT (types, i, type)
2592 debug_queue_symbol (type);
2594 types.release ();
2598 /* Output a .stabs for the symbol defined by DECL,
2599 which must be a ..._DECL node in the normal namespace.
2600 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2601 LOCAL is nonzero if the scope is less than the entire file.
2602 Return 1 if a stabs might have been emitted. */
2605 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2607 tree type = TREE_TYPE (decl);
2608 tree context = NULL_TREE;
2609 int result = 0;
2610 rtx decl_rtl;
2612 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2613 ++debug_nesting;
2615 /* Ignore nameless syms, but don't ignore type tags. */
2617 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2618 || DECL_IGNORED_P (decl))
2619 DBXOUT_DECR_NESTING_AND_RETURN (0);
2621 /* If we are to generate only the symbols actually used then such
2622 symbol nodes are flagged with TREE_USED. Ignore any that
2623 aren't flagged as TREE_USED. */
2625 if (flag_debug_only_used_symbols
2626 && (!TREE_USED (decl)
2627 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2628 DBXOUT_DECR_NESTING_AND_RETURN (0);
2630 /* If dbxout_init has not yet run, queue this symbol for later. */
2631 if (!typevec)
2633 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2634 DBXOUT_DECR_NESTING_AND_RETURN (0);
2637 if (flag_debug_only_used_symbols)
2639 tree t;
2641 /* We now have a used symbol. We need to generate the info for
2642 the symbol's type in addition to the symbol itself. These
2643 type symbols are queued to be generated after were done with
2644 the symbol itself (otherwise they would fight over the
2645 stabstr obstack).
2647 Note, because the TREE_TYPE(type) might be something like a
2648 pointer to a named type we need to look for the first name
2649 we see following the TREE_TYPE chain. */
2651 t = type;
2652 while (POINTER_TYPE_P (t))
2653 t = TREE_TYPE (t);
2655 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2656 need special treatment. The TYPE_STUB_DECL field in these
2657 types generally represents the tag name type we want to
2658 output. In addition there could be a typedef type with
2659 a different name. In that case we also want to output
2660 that. */
2662 if (TREE_CODE (t) == RECORD_TYPE
2663 || TREE_CODE (t) == UNION_TYPE
2664 || TREE_CODE (t) == QUAL_UNION_TYPE
2665 || TREE_CODE (t) == ENUMERAL_TYPE)
2667 if (TYPE_STUB_DECL (t)
2668 && TYPE_STUB_DECL (t) != decl
2669 && DECL_P (TYPE_STUB_DECL (t))
2670 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2672 debug_queue_symbol (TYPE_STUB_DECL (t));
2673 if (TYPE_NAME (t)
2674 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2675 && TYPE_NAME (t) != decl
2676 && DECL_P (TYPE_NAME (t)))
2677 debug_queue_symbol (TYPE_NAME (t));
2680 else if (TYPE_NAME (t)
2681 && TYPE_NAME (t) != decl
2682 && DECL_P (TYPE_NAME (t)))
2683 debug_queue_symbol (TYPE_NAME (t));
2686 emit_pending_bincls_if_required ();
2688 switch (TREE_CODE (decl))
2690 case CONST_DECL:
2691 /* Enum values are defined by defining the enum type. */
2692 break;
2694 case FUNCTION_DECL:
2695 decl_rtl = DECL_RTL_IF_SET (decl);
2696 if (!decl_rtl)
2697 DBXOUT_DECR_NESTING_AND_RETURN (0);
2698 if (DECL_EXTERNAL (decl))
2699 break;
2700 /* Don't mention a nested function under its parent. */
2701 context = decl_function_context (decl);
2702 if (context == current_function_decl)
2703 break;
2704 /* Don't mention an inline instance of a nested function. */
2705 if (context && DECL_FROM_INLINE (decl))
2706 break;
2707 if (!MEM_P (decl_rtl)
2708 || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
2709 break;
2711 if (flag_debug_only_used_symbols)
2712 output_used_types ();
2714 dbxout_begin_complex_stabs ();
2715 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2716 stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2717 result = 1;
2719 if (TREE_TYPE (type))
2720 dbxout_type (TREE_TYPE (type), 0);
2721 else
2722 dbxout_type (void_type_node, 0);
2724 /* For a nested function, when that function is compiled,
2725 mention the containing function name
2726 as well as (since dbx wants it) our own assembler-name. */
2727 if (context != 0)
2729 stabstr_C (',');
2730 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2731 stabstr_C (',');
2732 stabstr_I (DECL_NAME (context));
2735 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
2736 break;
2738 case TYPE_DECL:
2739 /* Don't output the same typedef twice.
2740 And don't output what language-specific stuff doesn't want output. */
2741 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2742 DBXOUT_DECR_NESTING_AND_RETURN (0);
2744 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2745 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2747 int fundamental_type_number =
2748 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2750 if (fundamental_type_number != 0)
2752 TREE_ASM_WRITTEN (decl) = 1;
2753 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2754 DBXOUT_DECR_NESTING_AND_RETURN (0);
2757 #endif
2758 FORCE_TEXT;
2759 result = 1;
2761 int tag_needed = 1;
2762 int did_output = 0;
2764 if (DECL_NAME (decl))
2766 /* Nonzero means we must output a tag as well as a typedef. */
2767 tag_needed = 0;
2769 /* Handle the case of a C++ structure or union
2770 where the TYPE_NAME is a TYPE_DECL
2771 which gives both a typedef name and a tag. */
2772 /* dbx requires the tag first and the typedef second. */
2773 if ((TREE_CODE (type) == RECORD_TYPE
2774 || TREE_CODE (type) == UNION_TYPE
2775 || TREE_CODE (type) == QUAL_UNION_TYPE)
2776 && TYPE_NAME (type) == decl
2777 && !use_gnu_debug_info_extensions
2778 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2779 /* Distinguish the implicit typedefs of C++
2780 from explicit ones that might be found in C. */
2781 && DECL_ARTIFICIAL (decl)
2782 /* Do not generate a tag for incomplete records. */
2783 && COMPLETE_TYPE_P (type)
2784 /* Do not generate a tag for records of variable size,
2785 since this type can not be properly described in the
2786 DBX format, and it confuses some tools such as objdump. */
2787 && tree_fits_uhwi_p (TYPE_SIZE (type)))
2789 tree name = TYPE_IDENTIFIER (type);
2791 dbxout_begin_complex_stabs ();
2792 stabstr_I (name);
2793 stabstr_S (":T");
2794 dbxout_type (type, 1);
2795 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2796 0, 0, 0);
2799 dbxout_begin_complex_stabs ();
2801 /* Output leading class/struct qualifiers. */
2802 if (use_gnu_debug_info_extensions)
2803 dbxout_class_name_qualifiers (decl);
2805 /* Output typedef name. */
2806 stabstr_I (DECL_NAME (decl));
2807 stabstr_C (':');
2809 /* Short cut way to output a tag also. */
2810 if ((TREE_CODE (type) == RECORD_TYPE
2811 || TREE_CODE (type) == UNION_TYPE
2812 || TREE_CODE (type) == QUAL_UNION_TYPE)
2813 && TYPE_NAME (type) == decl
2814 /* Distinguish the implicit typedefs of C++
2815 from explicit ones that might be found in C. */
2816 && DECL_ARTIFICIAL (decl))
2818 if (use_gnu_debug_info_extensions)
2820 stabstr_C ('T');
2821 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2825 stabstr_C ('t');
2826 dbxout_type (type, 1);
2827 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2828 0, 0, 0);
2829 did_output = 1;
2832 /* Don't output a tag if this is an incomplete type. This prevents
2833 the sun4 Sun OS 4.x dbx from crashing. */
2835 if (tag_needed && TYPE_NAME (type) != 0
2836 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2837 || (DECL_NAME (TYPE_NAME (type)) != 0))
2838 && COMPLETE_TYPE_P (type)
2839 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2841 /* For a TYPE_DECL with no name, but the type has a name,
2842 output a tag.
2843 This is what represents `struct foo' with no typedef. */
2844 /* In C++, the name of a type is the corresponding typedef.
2845 In C, it is an IDENTIFIER_NODE. */
2846 tree name = TYPE_IDENTIFIER (type);
2848 dbxout_begin_complex_stabs ();
2849 stabstr_I (name);
2850 stabstr_S (":T");
2851 dbxout_type (type, 1);
2852 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2853 did_output = 1;
2856 /* If an enum type has no name, it cannot be referred to, but
2857 we must output it anyway, to record the enumeration
2858 constants. */
2860 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2862 dbxout_begin_complex_stabs ();
2863 /* Some debuggers fail when given NULL names, so give this a
2864 harmless name of " " (Why not "(anon)"?). */
2865 stabstr_S (" :T");
2866 dbxout_type (type, 1);
2867 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2870 /* Prevent duplicate output of a typedef. */
2871 TREE_ASM_WRITTEN (decl) = 1;
2872 break;
2875 case PARM_DECL:
2876 if (DECL_HAS_VALUE_EXPR_P (decl))
2877 decl = DECL_VALUE_EXPR (decl);
2879 /* PARM_DECLs go in their own separate chain and are output by
2880 dbxout_reg_parms and dbxout_parms, except for those that are
2881 disguised VAR_DECLs like Out parameters in Ada. */
2882 gcc_assert (TREE_CODE (decl) == VAR_DECL);
2884 /* ... fall through ... */
2886 case RESULT_DECL:
2887 case VAR_DECL:
2888 /* Don't mention a variable that is external.
2889 Let the file that defines it describe it. */
2890 if (DECL_EXTERNAL (decl))
2891 break;
2893 /* If the variable is really a constant
2894 and not written in memory, inform the debugger.
2896 ??? Why do we skip emitting the type and location in this case? */
2897 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2898 && DECL_INITIAL (decl) != 0
2899 && tree_fits_shwi_p (DECL_INITIAL (decl))
2900 && ! TREE_ASM_WRITTEN (decl)
2901 && (DECL_FILE_SCOPE_P (decl)
2902 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
2903 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
2904 && TREE_PUBLIC (decl) == 0)
2906 /* The sun4 assembler does not grok this. */
2908 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2909 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2911 HOST_WIDE_INT ival = tree_to_shwi (DECL_INITIAL (decl));
2913 dbxout_begin_complex_stabs ();
2914 dbxout_symbol_name (decl, NULL, 'c');
2915 stabstr_S ("=i");
2916 stabstr_D (ival);
2917 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2918 DBXOUT_DECR_NESTING;
2919 return 1;
2921 else
2922 break;
2924 /* else it is something we handle like a normal variable. */
2926 decl_rtl = dbxout_expand_expr (decl);
2927 if (!decl_rtl)
2928 DBXOUT_DECR_NESTING_AND_RETURN (0);
2930 if (!is_global_var (decl))
2931 decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX);
2932 #ifdef LEAF_REG_REMAP
2933 if (crtl->uses_only_leaf_regs)
2934 leaf_renumber_regs_insn (decl_rtl);
2935 #endif
2937 result = dbxout_symbol_location (decl, type, 0, decl_rtl);
2938 break;
2940 default:
2941 break;
2943 DBXOUT_DECR_NESTING;
2944 return result;
2947 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2948 Add SUFFIX to its name, if SUFFIX is not 0.
2949 Describe the variable as residing in HOME
2950 (usually HOME is DECL_RTL (DECL), but not always).
2951 Returns 1 if the stab was really emitted. */
2953 static int
2954 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2956 int letter = 0;
2957 stab_code_type code;
2958 rtx addr = 0;
2959 int number = 0;
2960 int regno = -1;
2962 /* Don't mention a variable at all
2963 if it was completely optimized into nothingness.
2965 If the decl was from an inline function, then its rtl
2966 is not identically the rtl that was used in this
2967 particular compilation. */
2968 if (GET_CODE (home) == SUBREG)
2970 rtx value = home;
2972 while (GET_CODE (value) == SUBREG)
2973 value = SUBREG_REG (value);
2974 if (REG_P (value))
2976 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2977 return 0;
2979 home = alter_subreg (&home, true);
2981 if (REG_P (home))
2983 regno = REGNO (home);
2984 if (regno >= FIRST_PSEUDO_REGISTER)
2985 return 0;
2988 /* The kind-of-variable letter depends on where
2989 the variable is and on the scope of its name:
2990 G and N_GSYM for static storage and global scope,
2991 S for static storage and file scope,
2992 V for static storage and local scope,
2993 for those two, use N_LCSYM if data is in bss segment,
2994 N_STSYM if in data segment, N_FUN otherwise.
2995 (We used N_FUN originally, then changed to N_STSYM
2996 to please GDB. However, it seems that confused ld.
2997 Now GDB has been fixed to like N_FUN, says Kingdon.)
2998 no letter at all, and N_LSYM, for auto variable,
2999 r and N_RSYM for register variable. */
3001 if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
3003 if (TREE_PUBLIC (decl))
3005 int offs;
3006 letter = 'G';
3007 code = N_GSYM;
3008 if (NULL != dbxout_common_check (decl, &offs))
3010 letter = 'V';
3011 addr = 0;
3012 number = offs;
3015 else
3017 addr = XEXP (home, 0);
3019 letter = decl_function_context (decl) ? 'V' : 'S';
3021 /* Some ports can transform a symbol ref into a label ref,
3022 because the symbol ref is too far away and has to be
3023 dumped into a constant pool. Alternatively, the symbol
3024 in the constant pool might be referenced by a different
3025 symbol. */
3026 if (GET_CODE (addr) == SYMBOL_REF
3027 && CONSTANT_POOL_ADDRESS_P (addr))
3029 bool marked;
3030 rtx tmp = get_pool_constant_mark (addr, &marked);
3032 if (GET_CODE (tmp) == SYMBOL_REF)
3034 addr = tmp;
3035 if (CONSTANT_POOL_ADDRESS_P (addr))
3036 get_pool_constant_mark (addr, &marked);
3037 else
3038 marked = true;
3040 else if (GET_CODE (tmp) == LABEL_REF)
3042 addr = tmp;
3043 marked = true;
3046 /* If all references to the constant pool were optimized
3047 out, we just ignore the symbol. */
3048 if (!marked)
3049 return 0;
3052 /* This should be the same condition as in assemble_variable, but
3053 we don't have access to dont_output_data here. So, instead,
3054 we rely on the fact that error_mark_node initializers always
3055 end up in bss for C++ and never end up in bss for C. */
3056 if (DECL_INITIAL (decl) == 0
3057 || (lang_GNU_CXX ()
3058 && DECL_INITIAL (decl) == error_mark_node))
3060 int offs;
3061 code = N_LCSYM;
3062 if (NULL != dbxout_common_check (decl, &offs))
3064 addr = 0;
3065 number = offs;
3066 letter = 'V';
3067 code = N_GSYM;
3070 else if (DECL_IN_TEXT_SECTION (decl))
3071 /* This is not quite right, but it's the closest
3072 of all the codes that Unix defines. */
3073 code = DBX_STATIC_CONST_VAR_CODE;
3074 else
3076 /* Ultrix `as' seems to need this. */
3077 #ifdef DBX_STATIC_STAB_DATA_SECTION
3078 switch_to_section (data_section);
3079 #endif
3080 code = N_STSYM;
3084 else if (regno >= 0)
3086 letter = 'r';
3087 code = N_RSYM;
3088 number = DBX_REGISTER_NUMBER (regno);
3090 else if (MEM_P (home)
3091 && (MEM_P (XEXP (home, 0))
3092 || (REG_P (XEXP (home, 0))
3093 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
3094 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
3095 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3096 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
3097 #endif
3099 /* If the value is indirect by memory or by a register
3100 that isn't the frame pointer
3101 then it means the object is variable-sized and address through
3102 that register or stack slot. DBX has no way to represent this
3103 so all we can do is output the variable as a pointer.
3104 If it's not a parameter, ignore it. */
3106 if (REG_P (XEXP (home, 0)))
3108 letter = 'r';
3109 code = N_RSYM;
3110 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
3111 return 0;
3112 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
3114 else
3116 code = N_LSYM;
3117 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
3118 We want the value of that CONST_INT. */
3119 number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
3122 /* Effectively do build_pointer_type, but don't cache this type,
3123 since it might be temporary whereas the type it points to
3124 might have been saved for inlining. */
3125 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
3126 type = make_node (POINTER_TYPE);
3127 TREE_TYPE (type) = TREE_TYPE (decl);
3129 else if (MEM_P (home)
3130 && REG_P (XEXP (home, 0)))
3132 code = N_LSYM;
3133 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3135 else if (MEM_P (home)
3136 && GET_CODE (XEXP (home, 0)) == PLUS
3137 && CONST_INT_P (XEXP (XEXP (home, 0), 1)))
3139 code = N_LSYM;
3140 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
3141 We want the value of that CONST_INT. */
3142 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3144 else if (MEM_P (home)
3145 && GET_CODE (XEXP (home, 0)) == CONST)
3147 /* Handle an obscure case which can arise when optimizing and
3148 when there are few available registers. (This is *always*
3149 the case for i386/i486 targets). The RTL looks like
3150 (MEM (CONST ...)) even though this variable is a local `auto'
3151 or a local `register' variable. In effect, what has happened
3152 is that the reload pass has seen that all assignments and
3153 references for one such a local variable can be replaced by
3154 equivalent assignments and references to some static storage
3155 variable, thereby avoiding the need for a register. In such
3156 cases we're forced to lie to debuggers and tell them that
3157 this variable was itself `static'. */
3158 int offs;
3159 code = N_LCSYM;
3160 letter = 'V';
3161 if (NULL == dbxout_common_check (decl, &offs))
3162 addr = XEXP (XEXP (home, 0), 0);
3163 else
3165 addr = 0;
3166 number = offs;
3167 code = N_GSYM;
3170 else if (GET_CODE (home) == CONCAT)
3172 tree subtype;
3174 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
3175 for example), then there is no easy way to figure out
3176 what SUBTYPE should be. So, we give up. */
3177 if (TREE_CODE (type) != COMPLEX_TYPE)
3178 return 0;
3180 subtype = TREE_TYPE (type);
3182 /* If the variable's storage is in two parts,
3183 output each as a separate stab with a modified name. */
3184 if (WORDS_BIG_ENDIAN)
3185 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
3186 else
3187 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
3189 if (WORDS_BIG_ENDIAN)
3190 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
3191 else
3192 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
3193 return 1;
3195 else
3196 /* Address might be a MEM, when DECL is a variable-sized object.
3197 Or it might be const0_rtx, meaning previous passes
3198 want us to ignore this variable. */
3199 return 0;
3201 /* Ok, start a symtab entry and output the variable name. */
3202 emit_pending_bincls_if_required ();
3203 FORCE_TEXT;
3205 #ifdef DBX_STATIC_BLOCK_START
3206 DBX_STATIC_BLOCK_START (asm_out_file, code);
3207 #endif
3209 dbxout_begin_complex_stabs_noforcetext ();
3210 dbxout_symbol_name (decl, suffix, letter);
3211 dbxout_type (type, 0);
3212 dbxout_finish_complex_stabs (decl, code, addr, 0, number);
3214 #ifdef DBX_STATIC_BLOCK_END
3215 DBX_STATIC_BLOCK_END (asm_out_file, code);
3216 #endif
3217 return 1;
3220 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
3221 Then output LETTER to indicate the kind of location the symbol has. */
3223 static void
3224 dbxout_symbol_name (tree decl, const char *suffix, int letter)
3226 tree name;
3228 if (DECL_CONTEXT (decl)
3229 && (TYPE_P (DECL_CONTEXT (decl))
3230 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
3231 /* One slight hitch: if this is a VAR_DECL which is a class member
3232 or a namespace member, we must put out the mangled name instead of the
3233 DECL_NAME. Note also that static member (variable) names DO NOT begin
3234 with underscores in .stabs directives. */
3235 name = DECL_ASSEMBLER_NAME (decl);
3236 else
3237 /* ...but if we're function-local, we don't want to include the junk
3238 added by ASM_FORMAT_PRIVATE_NAME. */
3239 name = DECL_NAME (decl);
3241 if (name)
3242 stabstr_I (name);
3243 else
3244 stabstr_S ("(anon)");
3246 if (suffix)
3247 stabstr_S (suffix);
3248 stabstr_C (':');
3249 if (letter)
3250 stabstr_C (letter);
3254 /* Output the common block name for DECL in a stabs.
3256 Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair
3257 around each group of symbols in the same .comm area. The N_GSYM stabs
3258 that are emitted only contain the offset in the common area. This routine
3259 emits the N_BCOMM and N_ECOMM stabs. */
3261 static void
3262 dbxout_common_name (tree decl, const char *name, stab_code_type op)
3264 dbxout_begin_complex_stabs ();
3265 stabstr_S (name);
3266 dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0);
3269 /* Check decl to determine whether it is a VAR_DECL destined for storage in a
3270 common area. If it is, the return value will be a non-null string giving
3271 the name of the common storage block it will go into. If non-null, the
3272 value is the offset into the common block for that symbol's storage. */
3274 static const char *
3275 dbxout_common_check (tree decl, int *value)
3277 rtx home;
3278 rtx sym_addr;
3279 const char *name = NULL;
3281 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
3282 it does not have a value (the offset into the common area), or if it
3283 is thread local (as opposed to global) then it isn't common, and shouldn't
3284 be handled as such.
3286 ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs
3287 for thread-local symbols. Can be handled via same mechanism as used
3288 in dwarf2out.c. */
3289 if (TREE_CODE (decl) != VAR_DECL
3290 || !TREE_STATIC (decl)
3291 || !DECL_HAS_VALUE_EXPR_P (decl)
3292 || DECL_THREAD_LOCAL_P (decl)
3293 || !is_fortran ())
3294 return NULL;
3296 home = DECL_RTL (decl);
3297 if (home == NULL_RTX || GET_CODE (home) != MEM)
3298 return NULL;
3300 sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl));
3301 if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM)
3302 return NULL;
3304 sym_addr = XEXP (sym_addr, 0);
3305 if (GET_CODE (sym_addr) == CONST)
3306 sym_addr = XEXP (sym_addr, 0);
3307 if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS)
3308 && DECL_INITIAL (decl) == 0)
3311 /* We have a sym that will go into a common area, meaning that it
3312 will get storage reserved with a .comm/.lcomm assembler pseudo-op.
3314 Determine name of common area this symbol will be an offset into,
3315 and offset into that area. Also retrieve the decl for the area
3316 that the symbol is offset into. */
3317 tree cdecl = NULL;
3319 switch (GET_CODE (sym_addr))
3321 case PLUS:
3322 if (CONST_INT_P (XEXP (sym_addr, 0)))
3324 name =
3325 targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 1), 0));
3326 *value = INTVAL (XEXP (sym_addr, 0));
3327 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1));
3329 else
3331 name =
3332 targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 0), 0));
3333 *value = INTVAL (XEXP (sym_addr, 1));
3334 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0));
3336 break;
3338 case SYMBOL_REF:
3339 name = targetm.strip_name_encoding (XSTR (sym_addr, 0));
3340 *value = 0;
3341 cdecl = SYMBOL_REF_DECL (sym_addr);
3342 break;
3344 default:
3345 error ("common symbol debug info is not structured as "
3346 "symbol+offset");
3349 /* Check area common symbol is offset into. If this is not public, then
3350 it is not a symbol in a common block. It must be a .lcomm symbol, not
3351 a .comm symbol. */
3352 if (cdecl == NULL || !TREE_PUBLIC (cdecl))
3353 name = NULL;
3355 else
3356 name = NULL;
3358 return name;
3361 /* Output definitions of all the decls in a chain. Return nonzero if
3362 anything was output */
3365 dbxout_syms (tree syms)
3367 int result = 0;
3368 const char *comm_prev = NULL;
3369 tree syms_prev = NULL;
3371 while (syms)
3373 int temp, copen, cclos;
3374 const char *comm_new;
3376 /* Check for common symbol, and then progression into a new/different
3377 block of common symbols. Emit closing/opening common bracket if
3378 necessary. */
3379 comm_new = dbxout_common_check (syms, &temp);
3380 copen = comm_new != NULL
3381 && (comm_prev == NULL || strcmp (comm_new, comm_prev));
3382 cclos = comm_prev != NULL
3383 && (comm_new == NULL || strcmp (comm_new, comm_prev));
3384 if (cclos)
3385 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3386 if (copen)
3388 dbxout_common_name (syms, comm_new, N_BCOMM);
3389 syms_prev = syms;
3391 comm_prev = comm_new;
3393 result += dbxout_symbol (syms, 1);
3394 syms = DECL_CHAIN (syms);
3397 if (comm_prev != NULL)
3398 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3400 return result;
3403 /* The following two functions output definitions of function parameters.
3404 Each parameter gets a definition locating it in the parameter list.
3405 Each parameter that is a register variable gets a second definition
3406 locating it in the register.
3408 Printing or argument lists in gdb uses the definitions that
3409 locate in the parameter list. But reference to the variable in
3410 expressions uses preferentially the definition as a register. */
3412 /* Output definitions, referring to storage in the parmlist,
3413 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
3415 void
3416 dbxout_parms (tree parms)
3418 ++debug_nesting;
3419 emit_pending_bincls_if_required ();
3421 for (; parms; parms = DECL_CHAIN (parms))
3422 if (DECL_NAME (parms)
3423 && TREE_TYPE (parms) != error_mark_node
3424 && DECL_RTL_SET_P (parms)
3425 && DECL_INCOMING_RTL (parms))
3427 tree eff_type;
3428 char letter;
3429 stab_code_type code;
3430 int number;
3432 /* Perform any necessary register eliminations on the parameter's rtl,
3433 so that the debugging output will be accurate. */
3434 DECL_INCOMING_RTL (parms)
3435 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
3436 SET_DECL_RTL (parms,
3437 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
3438 #ifdef LEAF_REG_REMAP
3439 if (crtl->uses_only_leaf_regs)
3441 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3442 leaf_renumber_regs_insn (DECL_RTL (parms));
3444 #endif
3446 if (PARM_PASSED_IN_MEMORY (parms))
3448 rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3450 /* ??? Here we assume that the parm address is indexed
3451 off the frame pointer or arg pointer.
3452 If that is not true, we produce meaningless results,
3453 but do not crash. */
3454 if (GET_CODE (inrtl) == PLUS
3455 && CONST_INT_P (XEXP (inrtl, 1)))
3456 number = INTVAL (XEXP (inrtl, 1));
3457 else
3458 number = 0;
3460 code = N_PSYM;
3461 number = DEBUGGER_ARG_OFFSET (number, inrtl);
3462 letter = 'p';
3464 /* It is quite tempting to use TREE_TYPE (parms) instead
3465 of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3466 reports the actual type of the parameter, rather than
3467 the promoted type. This certainly makes GDB's life
3468 easier, at least for some ports. The change is a bad
3469 idea however, since GDB expects to be able access the
3470 type without performing any conversions. So for
3471 example, if we were passing a float to an unprototyped
3472 function, gcc will store a double on the stack, but if
3473 we emit a stab saying the type is a float, then gdb
3474 will only read in a single value, and this will produce
3475 an erroneous value. */
3476 eff_type = DECL_ARG_TYPE (parms);
3478 else if (REG_P (DECL_RTL (parms)))
3480 rtx best_rtl;
3482 /* Parm passed in registers and lives in registers or nowhere. */
3483 code = DBX_REGPARM_STABS_CODE;
3484 letter = DBX_REGPARM_STABS_LETTER;
3486 /* For parms passed in registers, it is better to use the
3487 declared type of the variable, not the type it arrived in. */
3488 eff_type = TREE_TYPE (parms);
3490 /* If parm lives in a register, use that register; pretend
3491 the parm was passed there. It would be more consistent
3492 to describe the register where the parm was passed, but
3493 in practice that register usually holds something else.
3494 If the parm lives nowhere, use the register where it
3495 was passed. */
3496 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3497 best_rtl = DECL_RTL (parms);
3498 else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL)
3499 best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0);
3500 else
3501 best_rtl = DECL_INCOMING_RTL (parms);
3503 number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3505 else if (MEM_P (DECL_RTL (parms))
3506 && REG_P (XEXP (DECL_RTL (parms), 0))
3507 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3508 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3509 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3510 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3511 #endif
3514 /* Parm was passed via invisible reference.
3515 That is, its address was passed in a register.
3516 Output it as if it lived in that register.
3517 The debugger will know from the type
3518 that it was actually passed by invisible reference. */
3520 code = DBX_REGPARM_STABS_CODE;
3522 /* GDB likes this marked with a special letter. */
3523 letter = (use_gnu_debug_info_extensions
3524 ? 'a' : DBX_REGPARM_STABS_LETTER);
3525 eff_type = TREE_TYPE (parms);
3527 /* DECL_RTL looks like (MEM (REG...). Get the register number.
3528 If it is an unallocated pseudo-reg, then use the register where
3529 it was passed instead.
3530 ??? Why is DBX_REGISTER_NUMBER not used here? */
3532 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3533 number = REGNO (XEXP (DECL_RTL (parms), 0));
3534 else
3535 number = REGNO (DECL_INCOMING_RTL (parms));
3537 else if (MEM_P (DECL_RTL (parms))
3538 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3540 /* Parm was passed via invisible reference, with the reference
3541 living on the stack. DECL_RTL looks like
3542 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3543 could look like (MEM (MEM (REG))). */
3545 code = N_PSYM;
3546 letter = 'v';
3547 eff_type = TREE_TYPE (parms);
3549 if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3550 number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3551 else
3552 number = 0;
3554 number = DEBUGGER_ARG_OFFSET (number,
3555 XEXP (XEXP (DECL_RTL (parms), 0), 0));
3557 else if (MEM_P (DECL_RTL (parms))
3558 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3559 /* ??? A constant address for a parm can happen
3560 when the reg it lives in is equiv to a constant in memory.
3561 Should make this not happen, after 2.4. */
3562 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3564 /* Parm was passed in registers but lives on the stack. */
3566 code = N_PSYM;
3567 letter = 'p';
3568 eff_type = TREE_TYPE (parms);
3570 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3571 in which case we want the value of that CONST_INT,
3572 or (MEM (REG ...)),
3573 in which case we use a value of zero. */
3574 if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3575 number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3576 else
3577 number = 0;
3579 /* Make a big endian correction if the mode of the type of the
3580 parameter is not the same as the mode of the rtl. */
3581 if (BYTES_BIG_ENDIAN
3582 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3583 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3584 number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3585 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3587 else
3588 /* ??? We don't know how to represent this argument. */
3589 continue;
3591 dbxout_begin_complex_stabs ();
3593 if (DECL_NAME (parms))
3595 stabstr_I (DECL_NAME (parms));
3596 stabstr_C (':');
3598 else
3599 stabstr_S ("(anon):");
3600 stabstr_C (letter);
3601 dbxout_type (eff_type, 0);
3602 dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3604 DBXOUT_DECR_NESTING;
3607 /* Output definitions for the places where parms live during the function,
3608 when different from where they were passed, when the parms were passed
3609 in memory.
3611 It is not useful to do this for parms passed in registers
3612 that live during the function in different registers, because it is
3613 impossible to look in the passed register for the passed value,
3614 so we use the within-the-function register to begin with.
3616 PARMS is a chain of PARM_DECL nodes. */
3618 void
3619 dbxout_reg_parms (tree parms)
3621 ++debug_nesting;
3623 for (; parms; parms = DECL_CHAIN (parms))
3624 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3626 /* Report parms that live in registers during the function
3627 but were passed in memory. */
3628 if (REG_P (DECL_RTL (parms))
3629 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3630 dbxout_symbol_location (parms, TREE_TYPE (parms),
3631 0, DECL_RTL (parms));
3632 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3633 dbxout_symbol_location (parms, TREE_TYPE (parms),
3634 0, DECL_RTL (parms));
3635 /* Report parms that live in memory but not where they were passed. */
3636 else if (MEM_P (DECL_RTL (parms))
3637 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3638 dbxout_symbol_location (parms, TREE_TYPE (parms),
3639 0, DECL_RTL (parms));
3641 DBXOUT_DECR_NESTING;
3644 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3645 output definitions of those names, in raw form */
3647 static void
3648 dbxout_args (tree args)
3650 while (args)
3652 stabstr_C (',');
3653 dbxout_type (TREE_VALUE (args), 0);
3654 args = TREE_CHAIN (args);
3658 #if defined (DBX_DEBUGGING_INFO)
3660 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3661 BEGIN_LABEL is the name of the beginning of the function, which may
3662 be required. */
3663 static void
3664 dbx_output_lbrac (const char *label,
3665 const char *begin_label ATTRIBUTE_UNUSED)
3667 dbxout_begin_stabn (N_LBRAC);
3668 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3669 dbxout_stab_value_label_diff (label, begin_label);
3670 else
3671 dbxout_stab_value_label (label);
3674 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3675 BEGIN_LABEL is the name of the beginning of the function, which may
3676 be required. */
3677 static void
3678 dbx_output_rbrac (const char *label,
3679 const char *begin_label ATTRIBUTE_UNUSED)
3681 dbxout_begin_stabn (N_RBRAC);
3682 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3683 dbxout_stab_value_label_diff (label, begin_label);
3684 else
3685 dbxout_stab_value_label (label);
3688 /* Output everything about a symbol block (a BLOCK node
3689 that represents a scope level),
3690 including recursive output of contained blocks.
3692 BLOCK is the BLOCK node.
3693 DEPTH is its depth within containing symbol blocks.
3694 ARGS is usually zero; but for the outermost block of the
3695 body of a function, it is a chain of PARM_DECLs for the function parameters.
3696 We output definitions of all the register parms
3697 as if they were local variables of that block.
3699 If -g1 was used, we count blocks just the same, but output nothing
3700 except for the outermost block.
3702 Actually, BLOCK may be several blocks chained together.
3703 We handle them all in sequence. */
3705 static void
3706 dbxout_block (tree block, int depth, tree args)
3708 char begin_label[20];
3709 /* Reference current function start using LFBB. */
3710 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
3712 while (block)
3714 /* Ignore blocks never expanded or otherwise marked as real. */
3715 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3717 int did_output;
3718 int blocknum = BLOCK_NUMBER (block);
3720 /* In dbx format, the syms of a block come before the N_LBRAC.
3721 If nothing is output, we don't need the N_LBRAC, either. */
3722 did_output = 0;
3723 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3724 did_output = dbxout_syms (BLOCK_VARS (block));
3725 if (args)
3726 dbxout_reg_parms (args);
3728 /* Now output an N_LBRAC symbol to represent the beginning of
3729 the block. Use the block's tree-walk order to generate
3730 the assembler symbols LBBn and LBEn
3731 that final will define around the code in this block. */
3732 if (did_output)
3734 char buf[20];
3735 const char *scope_start;
3737 if (depth == 0)
3738 /* The outermost block doesn't get LBB labels; use
3739 the LFBB local symbol emitted by dbxout_begin_prologue. */
3740 scope_start = begin_label;
3741 else
3743 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3744 scope_start = buf;
3747 dbx_output_lbrac (scope_start, begin_label);
3750 /* Output the subblocks. */
3751 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3753 /* Refer to the marker for the end of the block. */
3754 if (did_output)
3756 char buf[100];
3757 if (depth == 0)
3758 /* The outermost block doesn't get LBE labels;
3759 use the "scope" label which will be emitted
3760 by dbxout_function_end. */
3761 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3762 else
3763 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3765 dbx_output_rbrac (buf, begin_label);
3768 block = BLOCK_CHAIN (block);
3772 /* Output the information about a function and its arguments and result.
3773 Usually this follows the function's code,
3774 but on some systems, it comes before. */
3776 static void
3777 dbxout_begin_function (tree decl)
3779 int saved_tree_used1;
3781 saved_tree_used1 = TREE_USED (decl);
3782 TREE_USED (decl) = 1;
3783 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3785 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3786 TREE_USED (DECL_RESULT (decl)) = 1;
3787 dbxout_symbol (decl, 0);
3788 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3790 else
3791 dbxout_symbol (decl, 0);
3792 TREE_USED (decl) = saved_tree_used1;
3794 dbxout_parms (DECL_ARGUMENTS (decl));
3795 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3796 dbxout_symbol (DECL_RESULT (decl), 1);
3798 #endif /* DBX_DEBUGGING_INFO */
3800 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3802 /* Record an element in the table of global destructors. SYMBOL is
3803 a SYMBOL_REF of the function to be called; PRIORITY is a number
3804 between 0 and MAX_INIT_PRIORITY. */
3806 void
3807 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
3808 int priority ATTRIBUTE_UNUSED)
3810 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
3811 /* Tell GNU LD that this is part of the static destructor set.
3812 This will work for any system that uses stabs, most usefully
3813 aout systems. */
3814 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
3815 dbxout_stab_value_label (XSTR (symbol, 0));
3816 #else
3817 sorry ("global destructors not supported on this target");
3818 #endif
3821 /* Likewise for global constructors. */
3823 void
3824 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
3825 int priority ATTRIBUTE_UNUSED)
3827 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
3828 /* Tell GNU LD that this is part of the static destructor set.
3829 This will work for any system that uses stabs, most usefully
3830 aout systems. */
3831 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
3832 dbxout_stab_value_label (XSTR (symbol, 0));
3833 #else
3834 sorry ("global constructors not supported on this target");
3835 #endif
3838 #include "gt-dbxout.h"