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