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
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
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
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.
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'. */
71 #include "coretypes.h"
77 #include "fold-const.h"
79 #include "stor-layout.h"
83 #include "insn-config.h"
87 #include "diagnostic-core.h"
91 #include "hard-reg-set.h"
94 #include "common/common-target.h"
95 #include "langhooks.h"
101 #include "emit-rtl.h"
105 #include "plugin-api.h"
108 #include "stringpool.h"
110 #ifdef XCOFF_DEBUGGING_INFO
111 #include "xcoffout.h"
115 # ifdef XCOFF_DEBUGGING_INFO
116 # define ASM_STABS_OP "\t.stabx\t"
118 # define ASM_STABS_OP "\t.stabs\t"
123 #define ASM_STABN_OP "\t.stabn\t"
127 #define ASM_STABD_OP "\t.stabd\t"
130 #ifndef DBX_TYPE_DECL_STABS_CODE
131 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
134 #ifndef DBX_STATIC_CONST_VAR_CODE
135 #define DBX_STATIC_CONST_VAR_CODE N_FUN
138 #ifndef DBX_REGPARM_STABS_CODE
139 #define DBX_REGPARM_STABS_CODE N_RSYM
142 #ifndef DBX_REGPARM_STABS_LETTER
143 #define DBX_REGPARM_STABS_LETTER 'P'
146 #ifndef NO_DBX_FUNCTION_END
147 #define NO_DBX_FUNCTION_END 0
150 #ifndef NO_DBX_BNSYM_ENSYM
151 #define NO_DBX_BNSYM_ENSYM 0
154 #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
155 #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
158 #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
159 #define DBX_BLOCKS_FUNCTION_RELATIVE 0
162 #ifndef DBX_LINES_FUNCTION_RELATIVE
163 #define DBX_LINES_FUNCTION_RELATIVE 0
166 #ifndef DBX_CONTIN_LENGTH
167 #define DBX_CONTIN_LENGTH 80
170 #ifndef DBX_CONTIN_CHAR
171 #define DBX_CONTIN_CHAR '\\'
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
183 struct GTY(()) typeinfo {
184 enum typestatus status;
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
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. */
220 struct dbx_file *next;
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
236 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
237 && defined (DBX_USE_BINCL)
238 static struct dbx_file *current_file;
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
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)
272 /* If zero then there is no pending BINCL. */
273 static int pending_bincls = 0;
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 ())
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)
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)
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;
315 static void emit_bincl_stab (const char *c);
316 static void emit_pending_bincls (void);
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 =
365 debug_nothing_int_charstar,
366 debug_nothing_int_charstar,
367 dbxout_start_source_file,
368 dbxout_end_source_file,
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,
380 debug_nothing_tree, /* begin_function */
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 =
408 debug_nothing_int_charstar,
409 debug_nothing_int_charstar,
410 dbxout_start_source_file,
411 dbxout_end_source_file,
412 xcoffout_begin_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
442 #define NUMBER_FMT_LOOP(P, NUM, BASE) \
445 int digit = NUM % BASE; \
447 *--P = digit + '0'; \
451 /* Utility: write a decimal integer NUM to asm_out_file. */
456 char *p = buf + sizeof buf;
461 putc ('0', asm_out_file);
466 putc ('-', asm_out_file);
472 NUMBER_FMT_LOOP (p, unum, 10);
474 while (p < buf + sizeof buf)
476 putc (*p, asm_out_file);
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. */
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. */
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
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. */
524 dbxout_stab_value_internal_label (const char *stem, int *counterp)
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. */
538 dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
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. */
553 dbxout_stabd (int stype, int sdesc)
555 fputs (ASM_STABD_OP, asm_out_file);
557 fputs (",0,", asm_out_file);
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
568 dbxout_begin_stabn (int stype)
570 fputs (ASM_STABN_OP, asm_out_file);
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. */
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);
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. */
591 dbxout_begin_empty_stabs (int stype)
593 fputs (ASM_STABS_OP, asm_out_file);
594 fputs ("\"\",", asm_out_file);
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. */
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);
608 fputs (",0,0,", asm_out_file);
611 /* As above but use SDESC for the desc field. */
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);
619 fputs (",0,", asm_out_file);
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. */
638 dbxout_begin_complex_stabs (void)
640 emit_pending_bincls_if_required ();
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. */
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. */
670 stabstr_D (HOST_WIDE_INT num)
673 char *p = buf + sizeof buf;
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. */
696 stabstr_U (unsigned HOST_WIDE_INT num)
699 char *p = buf + sizeof buf;
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. */
715 int prec = TYPE_PRECISION (TREE_TYPE (cst));
716 int res_pres = prec % 3;
720 /* Leading zero for base indicator. */
723 /* If the value is zero, the base indicator will serve as the value
725 if (wi::eq_p (cst, 0))
728 /* GDB wants constants with no extra leading "1" bits, so
729 we need to remove any sign-extension that might be
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);
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. */
756 stabstr_continue (void)
758 if (DBX_CONTIN_LENGTH > 0
759 && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
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) \
793 int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
796 fputs (",0,", asm_out_file); \
797 dbxout_int (line_); \
798 putc (',', asm_out_file); \
800 output_addr_const (asm_out_file, ADDR); \
802 assemble_name (asm_out_file, LABEL); \
804 dbxout_int (NUMBER); \
805 putc ('\n', asm_out_file); \
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. */
820 dbxout_finish_complex_stabs (tree sym, stab_code_type code,
821 rtx addr, const char *label, int number)
823 int line ATTRIBUTE_UNUSED;
827 line = sym ? DECL_SOURCE_LINE (sym) : 0;
828 if (DBX_CONTIN_LENGTH > 0)
833 /* Nul-terminate the growing string, then get its size and
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
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;
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);
859 fputs (ASM_STABS_OP, asm_out_file);
860 putc ('"', asm_out_file);
862 stabstr_last_contin_point = 0;
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)
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
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
924 if (!use_gnu_debug_info_extensions
925 || NO_DBX_FUNCTION_END
926 || !targetm_common.have_named_sections)
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);
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;
961 else if (lang_GNU_CXX ())
963 else if (strcmp (language_string, "GNU F77") == 0)
965 else if (lang_GNU_Fortran ())
966 return N_SO_FORTRAN90; /* CHECKME */
967 else if (strcmp (language_string, "GNU Pascal") == 0)
969 else if (strcmp (language_string, "GNU Objective-C") == 0)
971 else if (strcmp (language_string, "GNU Objective-C++") == 0)
972 return N_SO_OBJCPLUS;
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. */
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;
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
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;
1016 cwd = get_src_pwd ();
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);
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;
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 ();
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;
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)
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. */
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. */
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. */
1116 emit_pending_bincls_if_required (void)
1119 emit_pending_bincls ();
1122 /* Emit all pending bincls. */
1125 emit_pending_bincls (void)
1127 struct dbx_file *f = current_file;
1129 /* Find first pending bincl. */
1130 while (f->bincl_status == BINCL_PENDING)
1133 /* Now emit all bincls. */
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)
1151 /* All pending bincls have been emitted. */
1158 emit_pending_bincls_if_required (void) {}
1161 /* Change to reading from a new source file. Generate a N_BINCL stab. */
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. */
1176 current_file->prev = n;
1177 n->bincl_status = BINCL_PENDING;
1178 n->pending_bincl_name = remap_debug_filename (filename);
1184 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
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;
1201 /* Handle a few odd cases that occur when trying to make PCH files work. */
1204 dbxout_handle_pch (unsigned at_end)
1208 /* When using the PCH, this file will be included, so we need to output
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. */
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. */
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
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 */
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
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);
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,
1298 dbxout_stabd (N_SLINE, lineno);
1302 /* Describe the beginning of an internal block within a function. */
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. */
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). */
1327 dbxout_function_decl (tree decl)
1329 emit_pending_bincls_if_required ();
1330 #ifndef DBX_FUNCTION_FIRST
1331 dbxout_begin_function (decl);
1333 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1334 dbxout_function_end (decl);
1337 #endif /* DBX_DEBUGGING_INFO */
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. */
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. */
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. */
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);
1382 debug_free_queue ();
1385 /* Output the index of a type. */
1388 dbxout_type_index (tree type)
1390 #ifndef DBX_USE_BINCL
1391 stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1393 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1395 stabstr_D (t->file_number);
1397 stabstr_D (t->type_number);
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. */
1409 debug_flush_symbol_queue (void)
1413 /* Make sure that additionally queued items are not flushed
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);
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;
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()
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. */
1460 debug_free_queue (void)
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
1480 dbxout_type_fields (tree type)
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
1490 if (error_operand_p (tem))
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
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)))))
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))
1512 if (DECL_NAME (tem))
1513 stabstr_I (DECL_NAME (tem));
1516 if (use_gnu_debug_info_extensions
1517 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1518 || TREE_CODE (tem) != FIELD_DECL))
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);
1539 /* If TEM is non-static, GDB won't understand it. */
1540 stabstr_S (",0,0;");
1545 stabstr_D (int_bit_position (tem));
1547 stabstr_D (tree_to_uhwi (DECL_SIZE (tem)));
1554 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1555 method described DECL. */
1558 dbxout_type_method_1 (tree decl)
1562 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
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)))
1573 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1576 if (DECL_VINDEX (decl))
1582 /* ??? Output the mangled name, which contains an encoding of the
1583 method's type signature. May not be necessary anymore. */
1585 stabstr_I (DECL_ASSEMBLER_NAME (decl));
1587 stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1591 if (DECL_VINDEX (decl) && tree_fits_shwi_p (DECL_VINDEX (decl)))
1593 stabstr_D (tree_to_shwi (DECL_VINDEX (decl)));
1595 dbxout_type (DECL_CONTEXT (decl), 0);
1600 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1604 dbxout_type_methods (tree type)
1606 /* C++: put out the method names and their parameter lists */
1607 tree methods = TYPE_METHODS (type);
1611 if (methods == NULL_TREE)
1614 if (TREE_CODE (methods) != TREE_VEC)
1616 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1617 fndecl = TREE_VEC_ELT (methods, 0);
1619 fndecl = TREE_VEC_ELT (methods, 1);
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)
1644 /* Also ignore abstract methods; those are only interesting to
1645 the DWARF backends. */
1646 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT_P (fndecl))
1649 /* Redundantly output the plain name, since that's what gdb
1653 stabstr_I (DECL_NAME (fndecl));
1658 dbxout_type (TREE_TYPE (fndecl), 0);
1659 dbxout_type_method_1 (fndecl);
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. */
1671 dbxout_range_type (tree type, tree low, tree high)
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 */
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
1692 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1693 dbxout_type_index (type);
1695 dbxout_type_index (integer_type_node);
1699 if (low && tree_fits_shwi_p (low))
1701 if (print_int_cst_bounds_in_octal_p (type, low, high))
1704 stabstr_D (tree_to_shwi (low));
1710 if (high && tree_fits_shwi_p (high))
1712 if (print_int_cst_bounds_in_octal_p (type, low, high))
1715 stabstr_D (tree_to_shwi (high));
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. */
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. */
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;
1767 if (TYPE_NAME (type)
1768 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1769 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
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));
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]);
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++;
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))
1831 /* If this type's definition has been output or is now being output,
1834 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
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)))
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)))
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;
1877 /* Output a definition now. */
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))
1891 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1894 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1897 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
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);
1918 /* else continue. */
1920 switch (TREE_CODE (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);
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. */
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
1954 if (use_gnu_debug_info_extensions
1955 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1958 stabstr_D (TYPE_PRECISION (type));
1962 dbxout_range_type (type, low, high);
1967 /* If the size is non-standard, say what it is if we can use
1970 if (use_gnu_debug_info_extensions
1971 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1974 stabstr_D (TYPE_PRECISION (type));
1978 if (print_int_cst_bounds_in_octal_p (type, low, high))
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));
1990 dbxout_type_index (type);
2000 /* Output other integer types as subranges of `int'. */
2001 dbxout_range_type (type, low, high);
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. */
2011 dbxout_type_index (integer_type_node);
2013 stabstr_D (int_size_in_bytes (type));
2018 if (use_gnu_debug_info_extensions)
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,;");
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)
2036 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
2041 /* Output a complex integer type as a structure,
2042 pending some other way to do it. */
2044 stabstr_D (int_size_in_bytes (type));
2046 stabstr_S ("real:");
2047 dbxout_type (TREE_TYPE (type), 0);
2049 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2051 stabstr_S (";imag:");
2052 dbxout_type (TREE_TYPE (type), 0);
2054 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2056 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2062 /* Make arrays of packed bits look like bitstrings for chill. */
2063 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
2066 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2067 stabstr_S (";@S;S");
2068 dbxout_type (TYPE_DOMAIN (type), 0);
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)
2082 tem = TYPE_DOMAIN (type);
2086 dbxout_type_index (integer_type_node);
2087 stabstr_S (";0;-1;");
2092 dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem));
2095 dbxout_type (TREE_TYPE (type), 0);
2099 /* Make vectors look like an array. */
2100 if (use_gnu_debug_info_extensions)
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. */
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);
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)))
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);
2147 stabstr_D (anonymous_type_number++);
2151 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
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));
2163 vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
2165 if (use_gnu_debug_info_extensions)
2167 if (BINFO_N_BASE_BINFOS (binfo))
2170 stabstr_U (BINFO_N_BASE_BINFOS (binfo));
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
2184 if (BINFO_VIRTUAL_P (child)
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. */
2191 (tree_to_shwi (BINFO_VPTR_FIELD (child))
2194 stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
2197 dbxout_type (BINFO_TYPE (child), 0);
2202 /* Print out the base class information with
2203 fields which have the same names at the types
2205 dbxout_type_name (BINFO_TYPE (child));
2207 dbxout_type (BINFO_TYPE (child), full);
2209 stabstr_D (tree_to_shwi (BINFO_OFFSET (child))
2213 (tree_to_shwi (TYPE_SIZE (BINFO_TYPE (child)))
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);
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. */
2240 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
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
2249 if ((TYPE_NAME (type) != 0
2250 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2251 && DECL_IGNORED_P (TYPE_NAME (type)))
2253 || !COMPLETE_TYPE_P (type))
2256 dbxout_type_name (type);
2257 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2261 if (use_gnu_debug_info_extensions
2262 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2265 stabstr_D (TYPE_PRECISION (type));
2270 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2272 tree value = TREE_VALUE (tem);
2274 stabstr_I (TREE_PURPOSE (tem));
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));
2286 if (TREE_CHAIN (tem) != 0)
2295 dbxout_type (TREE_TYPE (type), 0);
2299 if (use_gnu_debug_info_extensions)
2303 /* Write the argument types out longhand. */
2304 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2306 dbxout_type (TREE_TYPE (type), 0);
2307 dbxout_args (TYPE_ARG_TYPES (type));
2311 /* Treat it as a function type. */
2312 dbxout_type (TREE_TYPE (type), 0);
2316 if (use_gnu_debug_info_extensions)
2319 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2321 dbxout_type (TREE_TYPE (type), 0);
2324 /* Should print as an int, because it is really just an offset. */
2325 dbxout_type (integer_type_node, 0);
2328 case REFERENCE_TYPE:
2329 if (use_gnu_debug_info_extensions)
2335 dbxout_type (TREE_TYPE (type), 0);
2340 dbxout_type (TREE_TYPE (type), 0);
2343 case POINTER_BOUNDS_TYPE:
2344 /* No debug info for pointer bounds type supported yet. */
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)"))
2363 /* Return nonzero if the given type represents an integer whose bounds
2364 should be printed in octal format. */
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))))
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. */
2399 dbxout_type_name (tree type)
2401 tree t = TYPE_NAME (type);
2404 switch (TREE_CODE (t))
2406 case IDENTIFIER_NODE:
2418 /* Output leading leading struct or class names needed for qualifying
2419 type whose scope is limited to a struct or class. */
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);
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. */
2450 dbxout_expand_expr (tree expr)
2452 switch (TREE_CODE (expr))
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))
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
2472 varpool_node *node = varpool_node::get (expr);
2473 if (!node || !node->definition)
2480 if (DECL_HAS_VALUE_EXPR_P (expr))
2481 return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2485 return DECL_RTL_IF_SET (expr);
2488 return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2492 case ARRAY_RANGE_REF:
2496 HOST_WIDE_INT bitsize, bitpos;
2498 int volatilep = 0, unsignedp = 0;
2501 tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
2502 &mode, &unsignedp, &volatilep, true);
2504 x = dbxout_expand_expr (tem);
2505 if (x == NULL || !MEM_P (x))
2509 if (!tree_fits_shwi_p (offset))
2511 x = adjust_address_nv (x, mode, tree_to_shwi (offset));
2514 x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
2524 /* Helper function for output_used_types. Queue one entry from the
2525 used types hash to be output. */
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));
2545 /* This is a qsort callback which sorts types and declarations into a
2546 predictable order (types, then declarations, sorted by UID
2550 output_types_sort (const void *pa, const void *pb)
2552 const tree lhs = *((const tree *)pa);
2553 const tree rhs = *((const tree *)pb);
2558 return TYPE_UID (lhs) - TYPE_UID (rhs);
2567 return DECL_UID (lhs) - DECL_UID (rhs);
2572 /* Force all types used by this function to be output in debug
2576 output_used_types (void)
2578 if (cfun && cfun->used_types_hash)
2584 types.create (cfun->used_types_hash->elements ());
2585 cfun->used_types_hash->traverse<vec<tree> *, output_used_types_helper>
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);
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;
2612 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
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. */
2633 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2634 DBXOUT_DECR_NESTING_AND_RETURN (0);
2637 if (flag_debug_only_used_symbols)
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
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. */
2652 while (POINTER_TYPE_P (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
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));
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))
2691 /* Enum values are defined by defining the enum type. */
2695 decl_rtl = DECL_RTL_IF_SET (decl);
2697 DBXOUT_DECR_NESTING_AND_RETURN (0);
2698 if (DECL_EXTERNAL (decl))
2700 /* Don't mention a nested function under its parent. */
2701 context = decl_function_context (decl);
2702 if (context == current_function_decl)
2704 /* Don't mention an inline instance of a nested function. */
2705 if (context && DECL_FROM_INLINE (decl))
2707 if (!MEM_P (decl_rtl)
2708 || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
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");
2719 if (TREE_TYPE (type))
2720 dbxout_type (TREE_TYPE (type), 0);
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. */
2730 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2732 stabstr_I (DECL_NAME (context));
2735 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
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);
2764 if (DECL_NAME (decl))
2766 /* Nonzero means we must output a tag as well as a typedef. */
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 ();
2794 dbxout_type (type, 1);
2795 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
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));
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)
2821 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2826 dbxout_type (type, 1);
2827 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
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,
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 ();
2851 dbxout_type (type, 1);
2852 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2856 /* If an enum type has no name, it cannot be referred to, but
2857 we must output it anyway, to record the enumeration
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)"?). */
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;
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 ... */
2888 /* Don't mention a variable that is external.
2889 Let the file that defines it describe it. */
2890 if (DECL_EXTERNAL (decl))
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');
2917 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2918 DBXOUT_DECR_NESTING;
2924 /* else it is something we handle like a normal variable. */
2926 decl_rtl = dbxout_expand_expr (decl);
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);
2937 result = dbxout_symbol_location (decl, type, 0, decl_rtl);
2943 DBXOUT_DECR_NESTING;
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. */
2954 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2957 stab_code_type code;
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)
2972 while (GET_CODE (value) == SUBREG)
2973 value = SUBREG_REG (value);
2976 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2979 home = alter_subreg (&home, true);
2983 regno = REGNO (home);
2984 if (regno >= FIRST_PSEUDO_REGISTER)
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))
3008 if (NULL != dbxout_common_check (decl, &offs))
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
3026 if (GET_CODE (addr) == SYMBOL_REF
3027 && CONSTANT_POOL_ADDRESS_P (addr))
3030 rtx tmp = get_pool_constant_mark (addr, &marked);
3032 if (GET_CODE (tmp) == SYMBOL_REF)
3035 if (CONSTANT_POOL_ADDRESS_P (addr))
3036 get_pool_constant_mark (addr, &marked);
3040 else if (GET_CODE (tmp) == LABEL_REF)
3046 /* If all references to the constant pool were optimized
3047 out, we just ignore the symbol. */
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
3058 && DECL_INITIAL (decl) == error_mark_node))
3062 if (NULL != dbxout_common_check (decl, &offs))
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;
3076 /* Ultrix `as' seems to need this. */
3077 #ifdef DBX_STATIC_STAB_DATA_SECTION
3078 switch_to_section (data_section);
3084 else if (regno >= 0)
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
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)))
3110 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
3112 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
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)))
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)))
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'. */
3161 if (NULL == dbxout_common_check (decl, &offs))
3162 addr = XEXP (XEXP (home, 0), 0);
3170 else if (GET_CODE (home) == CONCAT)
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)
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));
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));
3192 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
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. */
3201 /* Ok, start a symtab entry and output the variable name. */
3202 emit_pending_bincls_if_required ();
3205 #ifdef DBX_STATIC_BLOCK_START
3206 DBX_STATIC_BLOCK_START (asm_out_file, code);
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);
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. */
3224 dbxout_symbol_name (tree decl, const char *suffix, int letter)
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);
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);
3244 stabstr_S ("(anon)");
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. */
3262 dbxout_common_name (tree decl, const char *name, stab_code_type op)
3264 dbxout_begin_complex_stabs ();
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. */
3275 dbxout_common_check (tree decl, int *value)
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
3286 ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs
3287 for thread-local symbols. Can be handled via same mechanism as used
3289 if (TREE_CODE (decl) != VAR_DECL
3290 || !TREE_STATIC (decl)
3291 || !DECL_HAS_VALUE_EXPR_P (decl)
3292 || DECL_THREAD_LOCAL_P (decl)
3296 home = DECL_RTL (decl);
3297 if (home == NULL_RTX || GET_CODE (home) != MEM)
3300 sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl));
3301 if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM)
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. */
3319 switch (GET_CODE (sym_addr))
3322 if (CONST_INT_P (XEXP (sym_addr, 0)))
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));
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));
3339 name = targetm.strip_name_encoding (XSTR (sym_addr, 0));
3341 cdecl = SYMBOL_REF_DECL (sym_addr);
3345 error ("common symbol debug info is not structured as "
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
3352 if (cdecl == NULL || !TREE_PUBLIC (cdecl))
3361 /* Output definitions of all the decls in a chain. Return nonzero if
3362 anything was output */
3365 dbxout_syms (tree syms)
3368 const char *comm_prev = NULL;
3369 tree syms_prev = NULL;
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
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));
3385 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3388 dbxout_common_name (syms, comm_new, N_BCOMM);
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);
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. */
3416 dbxout_parms (tree parms)
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))
3429 stab_code_type code;
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));
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));
3461 number = DEBUGGER_ARG_OFFSET (number, inrtl);
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)))
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
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);
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
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));
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))). */
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));
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. */
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,
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));
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))));
3588 /* ??? We don't know how to represent this argument. */
3591 dbxout_begin_complex_stabs ();
3593 if (DECL_NAME (parms))
3595 stabstr_I (DECL_NAME (parms));
3599 stabstr_S ("(anon):");
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
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. */
3619 dbxout_reg_parms (tree parms)
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 */
3648 dbxout_args (tree args)
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
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);
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
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);
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. */
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);
3714 /* Ignore blocks never expanded or otherwise marked as real. */
3715 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
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. */
3723 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3724 did_output = dbxout_syms (BLOCK_VARS (block));
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. */
3735 const char *scope_start;
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;
3743 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
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. */
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);
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. */
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;
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. */
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
3814 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
3815 dbxout_stab_value_label (XSTR (symbol, 0));
3817 sorry ("global destructors not supported on this target");
3821 /* Likewise for global constructors. */
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
3831 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
3832 dbxout_stab_value_label (XSTR (symbol, 0));
3834 sorry ("global constructors not supported on this target");
3838 #include "gt-dbxout.h"