* configure.ac: Don't test for [build] __cxa_atexit when building a
[official-gcc.git] / gcc / dbxout.c
blobe67008f9ef5346b778178c2dbd118237a6a99d93
1 /* Output dbx-format symbol table information from GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 /* Output dbx-format symbol table data.
24 This consists of many symbol table entries, each of them
25 a .stabs assembler pseudo-op with four operands:
26 a "name" which is really a description of one symbol and its type,
27 a "code", which is a symbol defined in stab.h whose name starts with N_,
28 an unused operand always 0,
29 and a "value" which is an address or an offset.
30 The name is enclosed in doublequote characters.
32 Each function, variable, typedef, and structure tag
33 has a symbol table entry to define it.
34 The beginning and end of each level of name scoping within
35 a function are also marked by special symbol table entries.
37 The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
38 and a data type number. The data type number may be followed by
39 "=" and a type definition; normally this will happen the first time
40 the type number is mentioned. The type definition may refer to
41 other types by number, and those type numbers may be followed
42 by "=" and nested definitions.
44 This can make the "name" quite long.
45 When a name is more than 80 characters, we split the .stabs pseudo-op
46 into two .stabs pseudo-ops, both sharing the same "code" and "value".
47 The first one is marked as continued with a double-backslash at the
48 end of its "name".
50 The kind-of-symbol letter distinguished function names from global
51 variables from file-scope variables from parameters from auto
52 variables in memory from typedef names from register variables.
53 See `dbxout_symbol'.
55 The "code" is mostly redundant with the kind-of-symbol letter
56 that goes in the "name", but not entirely: for symbols located
57 in static storage, the "code" says which segment the address is in,
58 which controls how it is relocated.
60 The "value" for a symbol in static storage
61 is the core address of the symbol (actually, the assembler
62 label for the symbol). For a symbol located in a stack slot
63 it is the stack offset; for one in a register, the register number.
64 For a typedef symbol, it is zero.
66 If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
67 output while in the text section.
69 For more on data type definitions, see `dbxout_type'. */
71 #include "config.h"
72 #include "system.h"
73 #include "coretypes.h"
74 #include "tm.h"
76 #include "tree.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 "toplev.h"
85 #include "tm_p.h"
86 #include "ggc.h"
87 #include "debug.h"
88 #include "function.h"
89 #include "target.h"
90 #include "langhooks.h"
91 #include "obstack.h"
93 #ifdef XCOFF_DEBUGGING_INFO
94 #include "xcoffout.h"
95 #endif
97 #define DBXOUT_DECR_NESTING \
98 if (--debug_nesting == 0 && symbol_queue_index > 0) \
99 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
101 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
102 do {--debug_nesting; return (x);} while (0)
104 #ifndef ASM_STABS_OP
105 # ifdef XCOFF_DEBUGGING_INFO
106 # define ASM_STABS_OP "\t.stabx\t"
107 # else
108 # define ASM_STABS_OP "\t.stabs\t"
109 # endif
110 #endif
112 #ifndef ASM_STABN_OP
113 #define ASM_STABN_OP "\t.stabn\t"
114 #endif
116 #ifndef ASM_STABD_OP
117 #define ASM_STABD_OP "\t.stabd\t"
118 #endif
120 #ifndef DBX_TYPE_DECL_STABS_CODE
121 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
122 #endif
124 #ifndef DBX_STATIC_CONST_VAR_CODE
125 #define DBX_STATIC_CONST_VAR_CODE N_FUN
126 #endif
128 #ifndef DBX_REGPARM_STABS_CODE
129 #define DBX_REGPARM_STABS_CODE N_RSYM
130 #endif
132 #ifndef DBX_REGPARM_STABS_LETTER
133 #define DBX_REGPARM_STABS_LETTER 'P'
134 #endif
136 #ifndef NO_DBX_FUNCTION_END
137 #define NO_DBX_FUNCTION_END 0
138 #endif
140 #ifndef NO_DBX_BNSYM_ENSYM
141 #define NO_DBX_BNSYM_ENSYM 0
142 #endif
144 #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
145 #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
146 #endif
148 #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
149 #define DBX_BLOCKS_FUNCTION_RELATIVE 0
150 #endif
152 #ifndef DBX_LINES_FUNCTION_RELATIVE
153 #define DBX_LINES_FUNCTION_RELATIVE 0
154 #endif
156 #ifndef DBX_CONTIN_LENGTH
157 #define DBX_CONTIN_LENGTH 80
158 #endif
160 #ifndef DBX_CONTIN_CHAR
161 #define DBX_CONTIN_CHAR '\\'
162 #endif
164 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
166 /* Structure recording information about a C data type.
167 The status element says whether we have yet output
168 the definition of the type. TYPE_XREF says we have
169 output it as a cross-reference only.
170 The file_number and type_number elements are used if DBX_USE_BINCL
171 is defined. */
173 struct typeinfo GTY(())
175 enum typestatus status;
176 int file_number;
177 int type_number;
180 /* Vector recording information about C data types.
181 When we first notice a data type (a tree node),
182 we assign it a number using next_type_number.
183 That is its index in this vector. */
185 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
187 /* Number of elements of space allocated in `typevec'. */
189 static GTY(()) int typevec_len;
191 /* In dbx output, each type gets a unique number.
192 This is the number for the next type output.
193 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
195 static GTY(()) int next_type_number;
197 /* The C front end may call dbxout_symbol before dbxout_init runs.
198 We save all such decls in this list and output them when we get
199 to dbxout_init. */
201 static GTY(()) tree preinit_symbols;
203 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
205 /* When using N_BINCL in dbx output, each type number is actually a
206 pair of the file number and the type number within the file.
207 This is a stack of input files. */
209 struct dbx_file
211 struct dbx_file *next;
212 int file_number;
213 int next_type_number;
214 enum binclstatus bincl_status; /* Keep track of lazy bincl. */
215 const char *pending_bincl_name; /* Name of bincl. */
216 struct dbx_file *prev; /* Chain to traverse all pending bincls. */
219 /* This is the top of the stack.
221 This is not saved for PCH, because restoring a PCH should not change it.
222 next_file_number does have to be saved, because the PCH may use some
223 file numbers; however, just before restoring a PCH, next_file_number
224 should always be 0 because we should not have needed any file numbers
225 yet. */
227 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
228 && defined (DBX_USE_BINCL)
229 static struct dbx_file *current_file;
230 #endif
232 /* This is the next file number to use. */
234 static GTY(()) int next_file_number;
236 /* A counter for dbxout_function_end. */
238 static GTY(()) int scope_labelno;
240 /* A counter for dbxout_source_line. */
242 static GTY(()) int dbxout_source_line_counter;
244 /* Nonzero if we have actually used any of the GDB extensions
245 to the debugging format. The idea is that we use them for the
246 first time only if there's a strong reason, but once we have done that,
247 we use them whenever convenient. */
249 static GTY(()) int have_used_extensions = 0;
251 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
252 for the N_SO filename stabs label. */
254 static GTY(()) int source_label_number = 1;
256 /* Last source file name mentioned in a NOTE insn. */
258 static GTY(()) const char *lastfile;
260 /* Used by PCH machinery to detect if 'lastfile' should be reset to
261 base_input_file. */
262 static GTY(()) int lastfile_is_base;
264 /* Typical USG systems don't have stab.h, and they also have
265 no use for DBX-format debugging info. */
267 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
269 #ifdef DBX_USE_BINCL
270 /* If zero then there is no pending BINCL. */
271 static int pending_bincls = 0;
272 #endif
274 /* The original input file name. */
275 static const char *base_input_file;
277 #ifdef DEBUG_SYMS_TEXT
278 #define FORCE_TEXT function_section (current_function_decl);
279 #else
280 #define FORCE_TEXT
281 #endif
283 #include "gstab.h"
285 #define STAB_CODE_TYPE enum __stab_debug_code
287 /* 1 if PARM is passed to this function in memory. */
289 #define PARM_PASSED_IN_MEMORY(PARM) \
290 (MEM_P (DECL_INCOMING_RTL (PARM)))
292 /* A C expression for the integer offset value of an automatic variable
293 (N_LSYM) having address X (an RTX). */
294 #ifndef DEBUGGER_AUTO_OFFSET
295 #define DEBUGGER_AUTO_OFFSET(X) \
296 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
297 #endif
299 /* A C expression for the integer offset value of an argument (N_PSYM)
300 having address X (an RTX). The nominal offset is OFFSET. */
301 #ifndef DEBUGGER_ARG_OFFSET
302 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
303 #endif
305 /* This obstack holds the stab string currently being constructed. We
306 build it up here, then write it out, so we can split long lines up
307 properly (see dbxout_finish_complex_stabs). */
308 static struct obstack stabstr_ob;
309 static size_t stabstr_last_contin_point;
311 #ifdef DBX_USE_BINCL
312 static void emit_bincl_stab (const char *c);
313 static void emit_pending_bincls (void);
314 #endif
315 static inline void emit_pending_bincls_if_required (void);
317 static void dbxout_init (const char *);
319 static void dbxout_finish (const char *);
320 static void dbxout_start_source_file (unsigned, const char *);
321 static void dbxout_end_source_file (unsigned);
322 static void dbxout_typedefs (tree);
323 static void dbxout_type_index (tree);
324 static void dbxout_args (tree);
325 static void dbxout_type_fields (tree);
326 static void dbxout_type_method_1 (tree);
327 static void dbxout_type_methods (tree);
328 static void dbxout_range_type (tree);
329 static void dbxout_type (tree, int);
330 static bool print_int_cst_bounds_in_octal_p (tree);
331 static void dbxout_type_name (tree);
332 static void dbxout_class_name_qualifiers (tree);
333 static int dbxout_symbol_location (tree, tree, const char *, rtx);
334 static void dbxout_symbol_name (tree, const char *, int);
335 static void dbxout_block (tree, int, tree);
336 static void dbxout_global_decl (tree);
337 static void dbxout_type_decl (tree, int);
338 static void dbxout_handle_pch (unsigned);
340 /* The debug hooks structure. */
341 #if defined (DBX_DEBUGGING_INFO)
343 static void dbxout_source_line (unsigned int, const char *);
344 static void dbxout_begin_prologue (unsigned int, const char *);
345 static void dbxout_source_file (const char *);
346 static void dbxout_function_end (void);
347 static void dbxout_begin_function (tree);
348 static void dbxout_begin_block (unsigned, unsigned);
349 static void dbxout_end_block (unsigned, unsigned);
350 static void dbxout_function_decl (tree);
352 const struct gcc_debug_hooks dbx_debug_hooks =
354 dbxout_init,
355 dbxout_finish,
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_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, /* end_epilogue */
367 #ifdef DBX_FUNCTION_FIRST
368 dbxout_begin_function,
369 #else
370 debug_nothing_tree, /* begin_function */
371 #endif
372 debug_nothing_int, /* end_function */
373 dbxout_function_decl,
374 dbxout_global_decl, /* global_decl */
375 dbxout_type_decl, /* type_decl */
376 debug_nothing_tree_tree, /* imported_module_or_decl */
377 debug_nothing_tree, /* deferred_inline_function */
378 debug_nothing_tree, /* outlining_inline_function */
379 debug_nothing_rtx, /* label */
380 dbxout_handle_pch, /* handle_pch */
381 debug_nothing_rtx /* var_location */
383 #endif /* DBX_DEBUGGING_INFO */
385 #if defined (XCOFF_DEBUGGING_INFO)
386 const struct gcc_debug_hooks xcoff_debug_hooks =
388 dbxout_init,
389 dbxout_finish,
390 debug_nothing_int_charstar,
391 debug_nothing_int_charstar,
392 dbxout_start_source_file,
393 dbxout_end_source_file,
394 xcoffout_begin_block,
395 xcoffout_end_block,
396 debug_true_tree, /* ignore_block */
397 xcoffout_source_line,
398 xcoffout_begin_prologue, /* begin_prologue */
399 debug_nothing_int_charstar, /* end_prologue */
400 xcoffout_end_epilogue,
401 debug_nothing_tree, /* begin_function */
402 xcoffout_end_function,
403 debug_nothing_tree, /* function_decl */
404 dbxout_global_decl, /* global_decl */
405 dbxout_type_decl, /* type_decl */
406 debug_nothing_tree_tree, /* imported_module_or_decl */
407 debug_nothing_tree, /* deferred_inline_function */
408 debug_nothing_tree, /* outlining_inline_function */
409 debug_nothing_rtx, /* label */
410 dbxout_handle_pch, /* handle_pch */
411 debug_nothing_rtx /* var_location */
413 #endif /* XCOFF_DEBUGGING_INFO */
415 /* Numeric formatting helper macro. Note that this does not handle
416 hexadecimal. */
417 #define NUMBER_FMT_LOOP(P, NUM, BASE) \
418 do \
420 int digit = NUM % BASE; \
421 NUM /= BASE; \
422 *--P = digit + '0'; \
424 while (NUM > 0)
426 /* Utility: write a decimal integer NUM to asm_out_file. */
427 void
428 dbxout_int (int num)
430 char buf[64];
431 char *p = buf + sizeof buf;
432 unsigned int unum;
434 if (num == 0)
436 putc ('0', asm_out_file);
437 return;
439 if (num < 0)
441 putc ('-', asm_out_file);
442 unum = -num;
444 else
445 unum = num;
447 NUMBER_FMT_LOOP (p, unum, 10);
449 while (p < buf + sizeof buf)
451 putc (*p, asm_out_file);
452 p++;
457 /* Primitives for emitting simple stabs directives. All other stabs
458 routines should use these functions instead of directly emitting
459 stabs. They are exported because machine-dependent code may need
460 to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
461 forwards to code in CPU.c. */
463 /* The following functions should all be called immediately after one
464 of the dbxout_begin_stab* functions (below). They write out
465 various things as the value of a stab. */
467 /* Write out a literal zero as the value of a stab. */
468 void
469 dbxout_stab_value_zero (void)
471 fputs ("0\n", asm_out_file);
474 /* Write out the label LABEL as the value of a stab. */
475 void
476 dbxout_stab_value_label (const char *label)
478 assemble_name (asm_out_file, label);
479 putc ('\n', asm_out_file);
482 /* Write out the difference of two labels, LABEL - BASE, as the value
483 of a stab. */
484 void
485 dbxout_stab_value_label_diff (const char *label, const char *base)
487 assemble_name (asm_out_file, label);
488 putc ('-', asm_out_file);
489 assemble_name (asm_out_file, base);
490 putc ('\n', asm_out_file);
493 /* Write out an internal label as the value of a stab, and immediately
494 emit that internal label. This should be used only when
495 dbxout_stabd will not work. STEM is the name stem of the label,
496 COUNTERP is a pointer to a counter variable which will be used to
497 guarantee label uniqueness. */
498 void
499 dbxout_stab_value_internal_label (const char *stem, int *counterp)
501 char label[100];
502 int counter = counterp ? (*counterp)++ : 0;
504 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
505 dbxout_stab_value_label (label);
506 targetm.asm_out.internal_label (asm_out_file, stem, counter);
509 /* Write out the difference between BASE and an internal label as the
510 value of a stab, and immediately emit that internal label. STEM and
511 COUNTERP are as for dbxout_stab_value_internal_label. */
512 void
513 dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
514 const char *base)
516 char label[100];
517 int counter = counterp ? (*counterp)++ : 0;
519 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
520 dbxout_stab_value_label_diff (label, base);
521 targetm.asm_out.internal_label (asm_out_file, stem, counter);
524 /* The following functions produce specific kinds of stab directives. */
526 /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
527 void
528 dbxout_stabd (int stype, int sdesc)
530 fputs (ASM_STABD_OP, asm_out_file);
531 dbxout_int (stype);
532 fputs (",0,", asm_out_file);
533 dbxout_int (sdesc);
534 putc ('\n', asm_out_file);
537 /* Write a .stabn directive with type STYPE. This function stops
538 short of emitting the value field, which is the responsibility of
539 the caller (normally it will be either a symbol or the difference
540 of two symbols). */
542 void
543 dbxout_begin_stabn (int stype)
545 fputs (ASM_STABN_OP, asm_out_file);
546 dbxout_int (stype);
547 fputs (",0,0,", asm_out_file);
550 /* Write a .stabn directive with type N_SLINE and desc LINE. As above,
551 the value field is the responsibility of the caller. */
552 void
553 dbxout_begin_stabn_sline (int lineno)
555 fputs (ASM_STABN_OP, asm_out_file);
556 dbxout_int (N_SLINE);
557 fputs (",0,", asm_out_file);
558 dbxout_int (lineno);
559 putc (',', asm_out_file);
562 /* Begin a .stabs directive with string "", type STYPE, and desc and
563 other fields 0. The value field is the responsibility of the
564 caller. This function cannot be used for .stabx directives. */
565 void
566 dbxout_begin_empty_stabs (int stype)
568 fputs (ASM_STABS_OP, asm_out_file);
569 fputs ("\"\",", asm_out_file);
570 dbxout_int (stype);
571 fputs (",0,0,", asm_out_file);
574 /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
575 The value field is the responsibility of the caller. */
576 void
577 dbxout_begin_simple_stabs (const char *str, int stype)
579 fputs (ASM_STABS_OP, asm_out_file);
580 output_quoted_string (asm_out_file, str);
581 putc (',', asm_out_file);
582 dbxout_int (stype);
583 fputs (",0,0,", asm_out_file);
586 /* As above but use SDESC for the desc field. */
587 void
588 dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
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,", asm_out_file);
595 dbxout_int (sdesc);
596 putc (',', asm_out_file);
599 /* The next set of functions are entirely concerned with production of
600 "complex" .stabs directives: that is, .stabs directives whose
601 strings have to be constructed piecemeal. dbxout_type,
602 dbxout_symbol, etc. use these routines heavily. The string is queued
603 up in an obstack, then written out by dbxout_finish_complex_stabs, which
604 is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
605 (You might think it would be more efficient to go straight to stdio
606 when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
607 out not to be the case, and anyway this needs fewer #ifdefs.) */
609 /* Begin a complex .stabs directive. If we can, write the initial
610 ASM_STABS_OP to the asm_out_file. */
612 static void
613 dbxout_begin_complex_stabs (void)
615 emit_pending_bincls_if_required ();
616 FORCE_TEXT;
617 fputs (ASM_STABS_OP, asm_out_file);
618 putc ('"', asm_out_file);
619 gcc_assert (stabstr_last_contin_point == 0);
622 /* Add CHR, a single character, to the string being built. */
623 #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
625 /* Add STR, a normal C string, to the string being built. */
626 #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen(str))
628 /* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
629 #define stabstr_I(id) obstack_grow (&stabstr_ob, \
630 IDENTIFIER_POINTER (id), \
631 IDENTIFIER_LENGTH (id))
633 /* Add NUM, a signed decimal number, to the string being built. */
634 static void
635 stabstr_D (HOST_WIDE_INT num)
637 char buf[64];
638 char *p = buf + sizeof buf;
639 unsigned int unum;
641 if (num == 0)
643 stabstr_C ('0');
644 return;
646 if (num < 0)
648 stabstr_C ('-');
649 unum = -num;
651 else
652 unum = num;
654 NUMBER_FMT_LOOP (p, unum, 10);
656 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
659 /* Add NUM, an unsigned decimal number, to the string being built. */
660 static void
661 stabstr_U (unsigned HOST_WIDE_INT num)
663 char buf[64];
664 char *p = buf + sizeof buf;
665 if (num == 0)
667 stabstr_C ('0');
668 return;
670 NUMBER_FMT_LOOP (p, num, 10);
671 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
674 /* Add CST, an INTEGER_CST tree, to the string being built as an
675 unsigned octal number. This routine handles values which are
676 larger than a single HOST_WIDE_INT. */
677 static void
678 stabstr_O (tree cst)
680 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (cst);
681 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
683 char buf[128];
684 char *p = buf + sizeof buf;
686 /* GDB wants constants with no extra leading "1" bits, so
687 we need to remove any sign-extension that might be
688 present. */
690 const unsigned int width = TYPE_PRECISION (TREE_TYPE (cst));
691 if (width == HOST_BITS_PER_WIDE_INT * 2)
693 else if (width > HOST_BITS_PER_WIDE_INT)
694 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
695 else if (width == HOST_BITS_PER_WIDE_INT)
696 high = 0;
697 else
698 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
701 /* Leading zero for base indicator. */
702 stabstr_C ('0');
704 /* If the value is zero, the base indicator will serve as the value
705 all by itself. */
706 if (high == 0 && low == 0)
707 return;
709 /* If the high half is zero, we need only print the low half normally. */
710 if (high == 0)
711 NUMBER_FMT_LOOP (p, low, 8);
712 else
714 /* When high != 0, we need to print enough zeroes from low to
715 give the digits from high their proper place-values. Hence
716 NUMBER_FMT_LOOP cannot be used. */
717 const int n_digits = HOST_BITS_PER_WIDE_INT / 3;
718 int i;
720 for (i = 1; i <= n_digits; i++)
722 unsigned int digit = low % 8;
723 low /= 8;
724 *--p = '0' + digit;
727 /* Octal digits carry exactly three bits of information. The
728 width of a HOST_WIDE_INT is not normally a multiple of three.
729 Therefore, the next digit printed probably needs to carry
730 information from both low and high. */
731 if (HOST_BITS_PER_WIDE_INT % 3 != 0)
733 const int n_leftover_bits = HOST_BITS_PER_WIDE_INT % 3;
734 const int n_bits_from_high = 3 - n_leftover_bits;
736 const unsigned HOST_WIDE_INT
737 low_mask = (((unsigned HOST_WIDE_INT)1) << n_leftover_bits) - 1;
738 const unsigned HOST_WIDE_INT
739 high_mask = (((unsigned HOST_WIDE_INT)1) << n_bits_from_high) - 1;
741 unsigned int digit;
743 /* At this point, only the bottom n_leftover_bits bits of low
744 should be set. */
745 gcc_assert (!(low & ~low_mask));
747 digit = (low | ((high & high_mask) << n_leftover_bits));
748 high >>= n_bits_from_high;
750 *--p = '0' + digit;
753 /* Now we can format high in the normal manner. However, if
754 the only bits of high that were set were handled by the
755 digit split between low and high, high will now be zero, and
756 we don't want to print extra digits in that case. */
757 if (high)
758 NUMBER_FMT_LOOP (p, high, 8);
761 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
764 /* Called whenever it is safe to break a stabs string into multiple
765 .stabs directives. If the current string has exceeded the limit
766 set by DBX_CONTIN_LENGTH, mark the current position in the buffer
767 as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
768 it is a backslash) and a null character. */
769 static inline void
770 stabstr_continue (void)
772 if (DBX_CONTIN_LENGTH > 0
773 && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
774 > DBX_CONTIN_LENGTH)
776 if (DBX_CONTIN_CHAR == '\\')
777 obstack_1grow (&stabstr_ob, '\\');
778 obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
779 obstack_1grow (&stabstr_ob, '\0');
780 stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
783 #define CONTIN stabstr_continue ()
785 /* Macro subroutine of dbxout_finish_complex_stabs, which emits
786 all of the arguments to the .stabs directive after the string.
787 Overridden by xcoffout.h. CODE is the stabs code for this symbol;
788 LINE is the source line to write into the desc field (in extended
789 mode).
791 ADDR, LABEL, and NUMBER are three different ways to represent the
792 stabs value field. At most one of these should be nonzero.
794 ADDR is used most of the time; it represents the value as an
795 RTL address constant.
797 LABEL is used (currently) only for N_CATCH stabs; it represents
798 the value as a string suitable for assemble_name.
800 NUMBER is used when the value is an offset from an implicit base
801 pointer (e.g. for a stack variable), or an index (e.g. for a
802 register variable). It represents the value as a decimal integer. */
804 #ifndef DBX_FINISH_STABS
805 #define DBX_FINISH_STABS(CODE, LINE, ADDR, LABEL, NUMBER) do { \
806 int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
808 dbxout_int (CODE); \
809 fputs (",0,", asm_out_file); \
810 dbxout_int (line_); \
811 putc (',', asm_out_file); \
812 if (ADDR) \
813 output_addr_const (asm_out_file, ADDR); \
814 else if (LABEL) \
815 assemble_name (asm_out_file, LABEL); \
816 else \
817 dbxout_int (NUMBER); \
818 putc ('\n', asm_out_file); \
819 } while (0)
820 #endif
822 /* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
823 is zero, this has only to emit the close quote and the remainder of
824 the arguments. When it is nonzero, the string has been marshalled in
825 stabstr_ob, and this routine is responsible for breaking it up into
826 DBX_CONTIN_LENGTH-sized chunks.
828 SYM is the DECL of the symbol under consideration; it is used only
829 for its DECL_SOURCE_LINE. The other arguments are all passed directly
830 to DBX_FINISH_STABS; see above for details. */
832 static void
833 dbxout_finish_complex_stabs (tree sym, STAB_CODE_TYPE code,
834 rtx addr, const char *label, int number)
836 int line = sym ? DECL_SOURCE_LINE (sym) : 0;
837 char *str;
838 size_t len;
840 if (DBX_CONTIN_LENGTH > 0)
842 char *chunk;
843 size_t chunklen;
845 /* Nul-terminate the growing string, then get its size and
846 address. */
847 obstack_1grow (&stabstr_ob, '\0');
849 len = obstack_object_size (&stabstr_ob);
850 chunk = str = obstack_finish (&stabstr_ob);
852 /* Within the buffer are a sequence of NUL-separated strings,
853 each of which is to be written out as a separate stab
854 directive. */
855 for (;;)
857 chunklen = strlen (chunk);
858 fwrite (chunk, 1, chunklen, asm_out_file);
859 fputs ("\",", asm_out_file);
861 /* Must add an extra byte to account for the NUL separator. */
862 chunk += chunklen + 1;
863 len -= chunklen + 1;
865 /* Only put a line number on the last stab in the sequence. */
866 DBX_FINISH_STABS (code, len == 0 ? line : 0, addr, label, number);
867 if (len == 0)
868 break;
870 fputs (ASM_STABS_OP, asm_out_file);
871 putc ('"', asm_out_file);
873 stabstr_last_contin_point = 0;
875 else
877 /* No continuations - we can put the whole string out at once.
878 It is faster to augment the string with the close quote and
879 comma than to do a two-character fputs. */
880 obstack_grow (&stabstr_ob, "\",", 2);
881 len = obstack_object_size (&stabstr_ob);
882 str = obstack_finish (&stabstr_ob);
884 fwrite (str, 1, len, asm_out_file);
885 DBX_FINISH_STABS (code, line, addr, label, number);
887 obstack_free (&stabstr_ob, str);
890 #if defined (DBX_DEBUGGING_INFO)
892 static void
893 dbxout_function_end (void)
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 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);
906 scope_labelno++;
908 /* The N_FUN tag at the end of the function is a GNU extension,
909 which may be undesirable, and is unnecessary if we do not have
910 named sections. */
911 if (!use_gnu_debug_info_extensions
912 || NO_DBX_FUNCTION_END
913 || !targetm.have_named_sections)
914 return;
916 /* By convention, GCC will mark the end of a function with an N_FUN
917 symbol and an empty string. */
918 #ifdef DBX_OUTPUT_NFUN
919 DBX_OUTPUT_NFUN (asm_out_file, lscope_label_name, current_function_decl);
920 #else
921 dbxout_begin_empty_stabs (N_FUN);
922 dbxout_stab_value_label_diff (lscope_label_name,
923 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
925 #endif
927 if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
928 dbxout_stabd (N_ENSYM, 0);
930 #endif /* DBX_DEBUGGING_INFO */
932 /* Get lang description for N_SO stab. */
933 static unsigned int ATTRIBUTE_UNUSED
934 get_lang_number (void)
936 const char *language_string = lang_hooks.name;
938 if (strcmp (language_string, "GNU C") == 0)
939 return N_SO_C;
940 else if (strcmp (language_string, "GNU C++") == 0)
941 return N_SO_CC;
942 else if (strcmp (language_string, "GNU F77") == 0)
943 return N_SO_FORTRAN;
944 else if (strcmp (language_string, "GNU F95") == 0)
945 return N_SO_FORTRAN90; /* CHECKME */
946 else if (strcmp (language_string, "GNU Pascal") == 0)
947 return N_SO_PASCAL;
948 else if (strcmp (language_string, "GNU Objective-C") == 0)
949 return N_SO_OBJC;
950 else
951 return 0;
955 /* At the beginning of compilation, start writing the symbol table.
956 Initialize `typevec' and output the standard data types of C. */
958 static void
959 dbxout_init (const char *input_file_name)
961 char ltext_label_name[100];
962 bool used_ltext_label_name = false;
963 tree syms = lang_hooks.decls.getdecls ();
965 typevec_len = 100;
966 typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
968 /* stabstr_ob contains one string, which will be just fine with
969 1-byte alignment. */
970 obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
972 /* Convert Ltext into the appropriate format for local labels in case
973 the system doesn't insert underscores in front of user generated
974 labels. */
975 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
977 /* Put the current working directory in an N_SO symbol. */
978 if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
980 static const char *cwd;
982 if (!cwd)
984 cwd = get_src_pwd ();
985 if (cwd[0] == '\0')
986 cwd = "/";
987 else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
988 cwd = concat (cwd, "/", NULL);
990 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
991 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
992 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
993 dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
994 dbxout_stab_value_label (ltext_label_name);
995 used_ltext_label_name = true;
996 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
999 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1000 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, input_file_name);
1001 #else
1002 dbxout_begin_simple_stabs_desc (input_file_name, N_SO, get_lang_number ());
1003 dbxout_stab_value_label (ltext_label_name);
1004 used_ltext_label_name = true;
1005 #endif
1007 if (used_ltext_label_name)
1009 text_section ();
1010 targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1013 /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1014 The string used is historical. */
1015 #ifndef NO_DBX_GCC_MARKER
1016 dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1017 dbxout_stab_value_zero ();
1018 #endif
1020 base_input_file = lastfile = input_file_name;
1022 next_type_number = 1;
1024 #ifdef DBX_USE_BINCL
1025 current_file = xmalloc (sizeof *current_file);
1026 current_file->next = NULL;
1027 current_file->file_number = 0;
1028 current_file->next_type_number = 1;
1029 next_file_number = 1;
1030 current_file->prev = NULL;
1031 current_file->bincl_status = BINCL_NOT_REQUIRED;
1032 current_file->pending_bincl_name = NULL;
1033 #endif
1035 /* Get all permanent types that have typedef names, and output them
1036 all, except for those already output. Some language front ends
1037 put these declarations in the top-level scope; some do not;
1038 the latter are responsible for calling debug_hooks->type_decl from
1039 their record_builtin_type function. */
1040 dbxout_typedefs (syms);
1042 if (preinit_symbols)
1044 tree t;
1045 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1046 dbxout_symbol (TREE_VALUE (t), 0);
1047 preinit_symbols = 0;
1051 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
1053 static void
1054 dbxout_typedefs (tree syms)
1056 for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
1058 if (TREE_CODE (syms) == TYPE_DECL)
1060 tree type = TREE_TYPE (syms);
1061 if (TYPE_NAME (type)
1062 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1063 && COMPLETE_OR_VOID_TYPE_P (type)
1064 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
1065 dbxout_symbol (TYPE_NAME (type), 0);
1070 #ifdef DBX_USE_BINCL
1071 /* Emit BINCL stab using given name. */
1072 static void
1073 emit_bincl_stab (const char *name)
1075 dbxout_begin_simple_stabs (name, N_BINCL);
1076 dbxout_stab_value_zero ();
1079 /* If there are pending bincls then it is time to emit all of them. */
1081 static inline void
1082 emit_pending_bincls_if_required (void)
1084 if (pending_bincls)
1085 emit_pending_bincls ();
1088 /* Emit all pending bincls. */
1090 static void
1091 emit_pending_bincls (void)
1093 struct dbx_file *f = current_file;
1095 /* Find first pending bincl. */
1096 while (f->bincl_status == BINCL_PENDING)
1097 f = f->next;
1099 /* Now emit all bincls. */
1100 f = f->prev;
1102 while (f)
1104 if (f->bincl_status == BINCL_PENDING)
1106 emit_bincl_stab (f->pending_bincl_name);
1108 /* Update file number and status. */
1109 f->file_number = next_file_number++;
1110 f->bincl_status = BINCL_PROCESSED;
1112 if (f == current_file)
1113 break;
1114 f = f->prev;
1117 /* All pending bincls have been emitted. */
1118 pending_bincls = 0;
1121 #else
1123 static inline void
1124 emit_pending_bincls_if_required (void) {}
1125 #endif
1127 /* Change to reading from a new source file. Generate a N_BINCL stab. */
1129 static void
1130 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1131 const char *filename ATTRIBUTE_UNUSED)
1133 #ifdef DBX_USE_BINCL
1134 struct dbx_file *n = xmalloc (sizeof *n);
1136 n->next = current_file;
1137 n->next_type_number = 1;
1138 /* Do not assign file number now.
1139 Delay it until we actually emit BINCL. */
1140 n->file_number = 0;
1141 n->prev = NULL;
1142 current_file->prev = n;
1143 n->bincl_status = BINCL_PENDING;
1144 n->pending_bincl_name = filename;
1145 pending_bincls = 1;
1146 current_file = n;
1147 #endif
1150 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
1152 static void
1153 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1155 #ifdef DBX_USE_BINCL
1156 /* Emit EINCL stab only if BINCL is not pending. */
1157 if (current_file->bincl_status == BINCL_PROCESSED)
1159 dbxout_begin_stabn (N_EINCL);
1160 dbxout_stab_value_zero ();
1162 current_file->bincl_status = BINCL_NOT_REQUIRED;
1163 current_file = current_file->next;
1164 #endif
1167 /* Handle a few odd cases that occur when trying to make PCH files work. */
1169 static void
1170 dbxout_handle_pch (unsigned at_end)
1172 if (! at_end)
1174 /* When using the PCH, this file will be included, so we need to output
1175 a BINCL. */
1176 dbxout_start_source_file (0, lastfile);
1178 /* The base file when using the PCH won't be the same as
1179 the base file when it's being generated. */
1180 lastfile = NULL;
1182 else
1184 /* ... and an EINCL. */
1185 dbxout_end_source_file (0);
1187 /* Deal with cases where 'lastfile' was never actually changed. */
1188 lastfile_is_base = lastfile == NULL;
1192 #if defined (DBX_DEBUGGING_INFO)
1193 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
1195 static void
1196 dbxout_source_file (const char *filename)
1198 if (lastfile == 0 && lastfile_is_base)
1200 lastfile = base_input_file;
1201 lastfile_is_base = 0;
1204 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
1206 /* Don't change section amid function. */
1207 if (current_function_decl == NULL_TREE)
1208 text_section ();
1210 dbxout_begin_simple_stabs (filename, N_SOL);
1211 dbxout_stab_value_internal_label ("Ltext", &source_label_number);
1212 lastfile = filename;
1216 /* Output N_BNSYM and line number symbol entry. */
1218 static void
1219 dbxout_begin_prologue (unsigned int lineno, const char *filename)
1221 if (use_gnu_debug_info_extensions
1222 && !NO_DBX_FUNCTION_END
1223 && !NO_DBX_BNSYM_ENSYM
1224 && !flag_debug_only_used_symbols)
1225 dbxout_stabd (N_BNSYM, 0);
1227 dbxout_source_line (lineno, filename);
1230 /* Output a line number symbol entry for source file FILENAME and line
1231 number LINENO. */
1233 static void
1234 dbxout_source_line (unsigned int lineno, const char *filename)
1236 const char *begin_label = XSTR(XEXP(DECL_RTL(current_function_decl), 0), 0);
1238 dbxout_source_file (filename);
1240 #ifdef DBX_OUTPUT_SOURCE_LINE
1241 DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
1242 #else
1243 if (DBX_LINES_FUNCTION_RELATIVE)
1245 dbxout_begin_stabn_sline (lineno);
1246 dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
1247 begin_label);
1250 else
1251 dbxout_stabd (N_SLINE, lineno);
1252 #endif
1255 /* Describe the beginning of an internal block within a function. */
1257 static void
1258 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1260 emit_pending_bincls_if_required ();
1261 targetm.asm_out.internal_label (asm_out_file, "LBB", n);
1264 /* Describe the end line-number of an internal block within a function. */
1266 static void
1267 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1269 emit_pending_bincls_if_required ();
1270 targetm.asm_out.internal_label (asm_out_file, "LBE", n);
1273 /* Output dbx data for a function definition.
1274 This includes a definition of the function name itself (a symbol),
1275 definitions of the parameters (locating them in the parameter list)
1276 and then output the block that makes up the function's body
1277 (including all the auto variables of the function). */
1279 static void
1280 dbxout_function_decl (tree decl)
1282 emit_pending_bincls_if_required ();
1283 #ifndef DBX_FUNCTION_FIRST
1284 dbxout_begin_function (decl);
1285 #endif
1286 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1287 dbxout_function_end ();
1290 #endif /* DBX_DEBUGGING_INFO */
1292 /* Debug information for a global DECL. Called from toplev.c after
1293 compilation proper has finished. */
1294 static void
1295 dbxout_global_decl (tree decl)
1297 if (TREE_CODE (decl) == VAR_DECL
1298 && ! DECL_EXTERNAL (decl)
1299 && DECL_RTL_SET_P (decl)) /* Not necessary? */
1301 int saved_tree_used = TREE_USED (decl);
1302 TREE_USED (decl) = 1;
1303 dbxout_symbol (decl, 0);
1304 TREE_USED (decl) = saved_tree_used;
1308 /* This is just a function-type adapter; dbxout_symbol does exactly
1309 what we want but returns an int. */
1310 static void
1311 dbxout_type_decl (tree decl, int local)
1313 dbxout_symbol (decl, local);
1316 /* At the end of compilation, finish writing the symbol table.
1317 The default is to call debug_free_queue but do nothing else. */
1319 static void
1320 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
1322 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1323 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1324 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1326 text_section ();
1327 dbxout_begin_empty_stabs (N_SO);
1328 dbxout_stab_value_internal_label ("Letext", 0);
1330 #endif
1331 debug_free_queue ();
1334 /* Output the index of a type. */
1336 static void
1337 dbxout_type_index (tree type)
1339 #ifndef DBX_USE_BINCL
1340 stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1341 #else
1342 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1343 stabstr_C ('(');
1344 stabstr_D (t->file_number);
1345 stabstr_C (',');
1346 stabstr_D (t->type_number);
1347 stabstr_C (')');
1348 #endif
1353 /* Used in several places: evaluates to '0' for a private decl,
1354 '1' for a protected decl, '2' for a public decl. */
1355 #define DECL_ACCESSIBILITY_CHAR(DECL) \
1356 (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1358 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
1359 This must be a separate function because anonymous unions require
1360 recursive calls. */
1362 static void
1363 dbxout_type_fields (tree type)
1365 tree tem;
1367 /* Output the name, type, position (in bits), size (in bits) of each
1368 field that we can support. */
1369 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1371 /* If one of the nodes is an error_mark or its type is then
1372 return early. */
1373 if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
1374 return;
1376 /* Omit here local type decls until we know how to support them. */
1377 if (TREE_CODE (tem) == TYPE_DECL
1378 /* Omit fields whose position or size are variable or too large to
1379 represent. */
1380 || (TREE_CODE (tem) == FIELD_DECL
1381 && (! host_integerp (bit_position (tem), 0)
1382 || ! DECL_SIZE (tem)
1383 || ! host_integerp (DECL_SIZE (tem), 1)))
1384 /* Omit here the nameless fields that are used to skip bits. */
1385 || DECL_IGNORED_P (tem))
1386 continue;
1388 else if (TREE_CODE (tem) != CONST_DECL)
1390 /* Continue the line if necessary,
1391 but not before the first field. */
1392 if (tem != TYPE_FIELDS (type))
1393 CONTIN;
1395 if (DECL_NAME (tem))
1396 stabstr_I (DECL_NAME (tem));
1397 stabstr_C (':');
1399 if (use_gnu_debug_info_extensions
1400 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1401 || TREE_CODE (tem) != FIELD_DECL))
1403 have_used_extensions = 1;
1404 stabstr_C ('/');
1405 stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
1408 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
1409 && DECL_BIT_FIELD_TYPE (tem))
1410 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
1412 if (TREE_CODE (tem) == VAR_DECL)
1414 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
1416 tree name = DECL_ASSEMBLER_NAME (tem);
1418 have_used_extensions = 1;
1419 stabstr_C (':');
1420 stabstr_I (name);
1421 stabstr_C (';');
1423 else
1424 /* If TEM is non-static, GDB won't understand it. */
1425 stabstr_S (",0,0;");
1427 else
1429 stabstr_C (',');
1430 stabstr_D (int_bit_position (tem));
1431 stabstr_C (',');
1432 stabstr_D (tree_low_cst (DECL_SIZE (tem), 1));
1433 stabstr_C (';');
1439 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1440 method described DECL. */
1442 static void
1443 dbxout_type_method_1 (tree decl)
1445 char c1 = 'A', c2;
1447 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1448 c2 = '?';
1449 else /* it's a METHOD_TYPE. */
1451 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1452 /* A for normal functions.
1453 B for `const' member functions.
1454 C for `volatile' member functions.
1455 D for `const volatile' member functions. */
1456 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1457 c1 += 1;
1458 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1459 c1 += 2;
1461 if (DECL_VINDEX (decl))
1462 c2 = '*';
1463 else
1464 c2 = '.';
1467 /* ??? Output the mangled name, which contains an encoding of the
1468 method's type signature. May not be necessary anymore. */
1469 stabstr_C (':');
1470 stabstr_I (DECL_ASSEMBLER_NAME (decl));
1471 stabstr_C (';');
1472 stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1473 stabstr_C (c1);
1474 stabstr_C (c2);
1476 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1478 stabstr_D (tree_low_cst (DECL_VINDEX (decl), 0));
1479 stabstr_C (';');
1480 dbxout_type (DECL_CONTEXT (decl), 0);
1481 stabstr_C (';');
1485 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1486 in TYPE. */
1488 static void
1489 dbxout_type_methods (tree type)
1491 /* C++: put out the method names and their parameter lists */
1492 tree methods = TYPE_METHODS (type);
1493 tree fndecl;
1494 tree last;
1496 if (methods == NULL_TREE)
1497 return;
1499 if (TREE_CODE (methods) != TREE_VEC)
1500 fndecl = methods;
1501 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1502 fndecl = TREE_VEC_ELT (methods, 0);
1503 else
1504 fndecl = TREE_VEC_ELT (methods, 1);
1506 while (fndecl)
1508 int need_prefix = 1;
1510 /* Group together all the methods for the same operation.
1511 These differ in the types of the arguments. */
1512 for (last = NULL_TREE;
1513 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1514 fndecl = TREE_CHAIN (fndecl))
1515 /* Output the name of the field (after overloading), as
1516 well as the name of the field before overloading, along
1517 with its parameter list */
1519 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1520 include TEMPLATE_DECLs.) The debugger doesn't know what
1521 to do with such entities anyhow. */
1522 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1523 continue;
1525 CONTIN;
1527 last = fndecl;
1529 /* Also ignore abstract methods; those are only interesting to
1530 the DWARF backends. */
1531 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1532 continue;
1534 /* Redundantly output the plain name, since that's what gdb
1535 expects. */
1536 if (need_prefix)
1538 stabstr_I (DECL_NAME (fndecl));
1539 stabstr_S ("::");
1540 need_prefix = 0;
1543 dbxout_type (TREE_TYPE (fndecl), 0);
1544 dbxout_type_method_1 (fndecl);
1546 if (!need_prefix)
1547 stabstr_C (';');
1551 /* Emit a "range" type specification, which has the form:
1552 "r<index type>;<lower bound>;<upper bound>;".
1553 TYPE is an INTEGER_TYPE. */
1555 static void
1556 dbxout_range_type (tree type)
1558 stabstr_C ('r');
1559 if (TREE_TYPE (type))
1560 dbxout_type (TREE_TYPE (type), 0);
1561 else if (TREE_CODE (type) != INTEGER_TYPE)
1562 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1563 else
1565 /* Traditionally, we made sure 'int' was type 1, and builtin types
1566 were defined to be sub-ranges of int. Unfortunately, this
1567 does not allow us to distinguish true sub-ranges from integer
1568 types. So, instead we define integer (non-sub-range) types as
1569 sub-ranges of themselves. This matters for Chill. If this isn't
1570 a subrange type, then we want to define it in terms of itself.
1571 However, in C, this may be an anonymous integer type, and we don't
1572 want to emit debug info referring to it. Just calling
1573 dbxout_type_index won't work anyways, because the type hasn't been
1574 defined yet. We make this work for both cases by checked to see
1575 whether this is a defined type, referring to it if it is, and using
1576 'int' otherwise. */
1577 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1578 dbxout_type_index (type);
1579 else
1580 dbxout_type_index (integer_type_node);
1583 stabstr_C (';');
1584 if (TYPE_MIN_VALUE (type) != 0
1585 && host_integerp (TYPE_MIN_VALUE (type), 0))
1587 if (print_int_cst_bounds_in_octal_p (type))
1588 stabstr_O (TYPE_MIN_VALUE (type));
1589 else
1590 stabstr_D (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1592 else
1593 stabstr_C ('0');
1595 stabstr_C (';');
1596 if (TYPE_MAX_VALUE (type) != 0
1597 && host_integerp (TYPE_MAX_VALUE (type), 0))
1599 if (print_int_cst_bounds_in_octal_p (type))
1600 stabstr_O (TYPE_MAX_VALUE (type));
1601 else
1602 stabstr_D (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1603 stabstr_C (';');
1605 else
1606 stabstr_S ("-1;");
1610 /* Output a reference to a type. If the type has not yet been
1611 described in the dbx output, output its definition now.
1612 For a type already defined, just refer to its definition
1613 using the type number.
1615 If FULL is nonzero, and the type has been described only with
1616 a forward-reference, output the definition now.
1617 If FULL is zero in this case, just refer to the forward-reference
1618 using the number previously allocated. */
1620 static void
1621 dbxout_type (tree type, int full)
1623 tree tem;
1624 tree main_variant;
1625 static int anonymous_type_number = 0;
1627 if (TREE_CODE (type) == VECTOR_TYPE)
1628 /* The frontend feeds us a representation for the vector as a struct
1629 containing an array. Pull out the array type. */
1630 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1632 /* If there was an input error and we don't really have a type,
1633 avoid crashing and write something that is at least valid
1634 by assuming `int'. */
1635 if (type == error_mark_node)
1636 type = integer_type_node;
1637 else
1639 if (TYPE_NAME (type)
1640 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1641 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1642 full = 0;
1645 /* Try to find the "main variant" with the same name. */
1646 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1647 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1648 main_variant = TREE_TYPE (TYPE_NAME (type));
1649 else
1650 main_variant = TYPE_MAIN_VARIANT (type);
1652 /* If we are not using extensions, stabs does not distinguish const and
1653 volatile, so there is no need to make them separate types. */
1654 if (!use_gnu_debug_info_extensions)
1655 type = main_variant;
1657 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1659 /* Type has no dbx number assigned. Assign next available number. */
1660 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1662 /* Make sure type vector is long enough to record about this type. */
1664 if (next_type_number == typevec_len)
1666 typevec
1667 = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1668 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1669 typevec_len *= 2;
1672 #ifdef DBX_USE_BINCL
1673 emit_pending_bincls_if_required ();
1674 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1675 = current_file->file_number;
1676 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1677 = current_file->next_type_number++;
1678 #endif
1681 if (flag_debug_only_used_symbols)
1683 if ((TREE_CODE (type) == RECORD_TYPE
1684 || TREE_CODE (type) == UNION_TYPE
1685 || TREE_CODE (type) == QUAL_UNION_TYPE
1686 || TREE_CODE (type) == ENUMERAL_TYPE)
1687 && TYPE_STUB_DECL (type)
1688 && DECL_P (TYPE_STUB_DECL (type))
1689 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1690 debug_queue_symbol (TYPE_STUB_DECL (type));
1691 else if (TYPE_NAME (type)
1692 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1693 debug_queue_symbol (TYPE_NAME (type));
1696 /* Output the number of this type, to refer to it. */
1697 dbxout_type_index (type);
1699 #ifdef DBX_TYPE_DEFINED
1700 if (DBX_TYPE_DEFINED (type))
1701 return;
1702 #endif
1704 /* If this type's definition has been output or is now being output,
1705 that is all. */
1707 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1709 case TYPE_UNSEEN:
1710 break;
1711 case TYPE_XREF:
1712 /* If we have already had a cross reference,
1713 and either that's all we want or that's the best we could do,
1714 don't repeat the cross reference.
1715 Sun dbx crashes if we do. */
1716 if (! full || !COMPLETE_TYPE_P (type)
1717 /* No way in DBX fmt to describe a variable size. */
1718 || ! host_integerp (TYPE_SIZE (type), 1))
1719 return;
1720 break;
1721 case TYPE_DEFINED:
1722 return;
1725 #ifdef DBX_NO_XREFS
1726 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1727 leave the type-number completely undefined rather than output
1728 a cross-reference. If we have already used GNU debug info extensions,
1729 then it is OK to output a cross reference. This is necessary to get
1730 proper C++ debug output. */
1731 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1732 || TREE_CODE (type) == QUAL_UNION_TYPE
1733 || TREE_CODE (type) == ENUMERAL_TYPE)
1734 && ! use_gnu_debug_info_extensions)
1735 /* We must use the same test here as we use twice below when deciding
1736 whether to emit a cross-reference. */
1737 if ((TYPE_NAME (type) != 0
1738 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1739 && DECL_IGNORED_P (TYPE_NAME (type)))
1740 && !full)
1741 || !COMPLETE_TYPE_P (type)
1742 /* No way in DBX fmt to describe a variable size. */
1743 || ! host_integerp (TYPE_SIZE (type), 1))
1745 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1746 return;
1748 #endif
1750 /* Output a definition now. */
1751 stabstr_C ('=');
1753 /* Mark it as defined, so that if it is self-referent
1754 we will not get into an infinite recursion of definitions. */
1756 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1758 /* If this type is a variant of some other, hand off. Types with
1759 different names are usefully distinguished. We only distinguish
1760 cv-qualified types if we're using extensions. */
1761 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1763 stabstr_C ('k');
1764 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1765 return;
1767 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1769 stabstr_C ('B');
1770 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1771 return;
1773 else if (main_variant != TYPE_MAIN_VARIANT (type))
1775 if (flag_debug_only_used_symbols)
1777 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1779 if ((TREE_CODE (orig_type) == RECORD_TYPE
1780 || TREE_CODE (orig_type) == UNION_TYPE
1781 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1782 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1783 && TYPE_STUB_DECL (orig_type)
1784 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1785 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1787 /* 'type' is a typedef; output the type it refers to. */
1788 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1789 return;
1791 /* else continue. */
1793 switch (TREE_CODE (type))
1795 case VOID_TYPE:
1796 case LANG_TYPE:
1797 /* For a void type, just define it as itself; i.e., "5=5".
1798 This makes us consider it defined
1799 without saying what it is. The debugger will make it
1800 a void type when the reference is seen, and nothing will
1801 ever override that default. */
1802 dbxout_type_index (type);
1803 break;
1805 case INTEGER_TYPE:
1806 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1808 /* Output the type `char' as a subrange of itself!
1809 I don't understand this definition, just copied it
1810 from the output of pcc.
1811 This used to use `r2' explicitly and we used to
1812 take care to make sure that `char' was type number 2. */
1813 stabstr_C ('r');
1814 dbxout_type_index (type);
1815 stabstr_S (";0;127;");
1818 /* If this is a subtype of another integer type, always prefer to
1819 write it as a subtype. */
1820 else if (TREE_TYPE (type) != 0
1821 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1823 /* If the size is non-standard, say what it is if we can use
1824 GDB extensions. */
1826 if (use_gnu_debug_info_extensions
1827 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1829 have_used_extensions = 1;
1830 stabstr_S ("@s");
1831 stabstr_D (TYPE_PRECISION (type));
1832 stabstr_C (';');
1835 dbxout_range_type (type);
1838 else
1840 /* If the size is non-standard, say what it is if we can use
1841 GDB extensions. */
1843 if (use_gnu_debug_info_extensions
1844 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1846 have_used_extensions = 1;
1847 stabstr_S ("@s");
1848 stabstr_D (TYPE_PRECISION (type));
1849 stabstr_C (';');
1852 if (print_int_cst_bounds_in_octal_p (type))
1854 stabstr_C ('r');
1856 /* If this type derives from another type, output type index of
1857 parent type. This is particularly important when parent type
1858 is an enumerated type, because not generating the parent type
1859 index would transform the definition of this enumerated type
1860 into a plain unsigned type. */
1861 if (TREE_TYPE (type) != 0)
1862 dbxout_type_index (TREE_TYPE (type));
1863 else
1864 dbxout_type_index (type);
1866 stabstr_C (';');
1867 stabstr_O (TYPE_MIN_VALUE (type));
1868 stabstr_C (';');
1869 stabstr_O (TYPE_MAX_VALUE (type));
1870 stabstr_C (';');
1873 else
1874 /* Output other integer types as subranges of `int'. */
1875 dbxout_range_type (type);
1878 break;
1880 case REAL_TYPE:
1881 /* This used to say `r1' and we used to take care
1882 to make sure that `int' was type number 1. */
1883 stabstr_C ('r');
1884 dbxout_type_index (integer_type_node);
1885 stabstr_C (';');
1886 stabstr_D (int_size_in_bytes (type));
1887 stabstr_S (";0;");
1888 break;
1890 case CHAR_TYPE:
1891 if (use_gnu_debug_info_extensions)
1893 have_used_extensions = 1;
1894 stabstr_S ("@s");
1895 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1896 stabstr_S (";-20;");
1898 else
1900 /* Output the type `char' as a subrange of itself.
1901 That is what pcc seems to do. */
1902 stabstr_C ('r');
1903 dbxout_type_index (char_type_node);
1904 stabstr_S (TYPE_UNSIGNED (type) ? ";0;255;" : ";0;127;");
1906 break;
1908 case BOOLEAN_TYPE:
1909 if (use_gnu_debug_info_extensions)
1911 have_used_extensions = 1;
1912 stabstr_S ("@s");
1913 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1914 stabstr_S (";-16;");
1916 else /* Define as enumeral type (False, True) */
1917 stabstr_S ("eFalse:0,True:1,;");
1918 break;
1920 case FILE_TYPE:
1921 stabstr_C ('d');
1922 dbxout_type (TREE_TYPE (type), 0);
1923 break;
1925 case COMPLEX_TYPE:
1926 /* Differs from the REAL_TYPE by its new data type number.
1927 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
1928 codes since gdb doesn't care anyway. */
1930 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1932 stabstr_S ("R3;");
1933 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
1934 stabstr_S (";0;");
1936 else
1938 /* Output a complex integer type as a structure,
1939 pending some other way to do it. */
1940 stabstr_C ('s');
1941 stabstr_D (int_size_in_bytes (type));
1943 stabstr_S ("real:");
1944 dbxout_type (TREE_TYPE (type), 0);
1945 stabstr_S (",0,");
1946 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1948 stabstr_S (";imag:");
1949 dbxout_type (TREE_TYPE (type), 0);
1950 stabstr_C (',');
1951 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1952 stabstr_C (',');
1953 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1954 stabstr_S (";;");
1956 break;
1958 case SET_TYPE:
1959 if (use_gnu_debug_info_extensions)
1961 have_used_extensions = 1;
1962 stabstr_S ("@s");
1963 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1964 stabstr_C (';');
1966 /* Check if a bitstring type, which in Chill is
1967 different from a [power]set. */
1968 if (TYPE_STRING_FLAG (type))
1969 stabstr_S ("@S;");
1971 stabstr_C ('S');
1972 dbxout_type (TYPE_DOMAIN (type), 0);
1973 break;
1975 case ARRAY_TYPE:
1976 /* Make arrays of packed bits look like bitstrings for chill. */
1977 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1979 have_used_extensions = 1;
1980 stabstr_S ("@s");
1981 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1982 stabstr_S (";@S;S");
1983 dbxout_type (TYPE_DOMAIN (type), 0);
1984 break;
1987 /* Output "a" followed by a range type definition
1988 for the index type of the array
1989 followed by a reference to the target-type.
1990 ar1;0;N;M for a C array of type M and size N+1. */
1991 /* Check if a character string type, which in Chill is
1992 different from an array of characters. */
1993 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1995 have_used_extensions = 1;
1996 stabstr_S ("@S;");
1998 tem = TYPE_DOMAIN (type);
1999 if (tem == NULL)
2001 stabstr_S ("ar");
2002 dbxout_type_index (integer_type_node);
2003 stabstr_S (";0;-1;");
2005 else
2007 stabstr_C ('a');
2008 dbxout_range_type (tem);
2011 dbxout_type (TREE_TYPE (type), 0);
2012 break;
2014 case RECORD_TYPE:
2015 case UNION_TYPE:
2016 case QUAL_UNION_TYPE:
2018 tree binfo = TYPE_BINFO (type);
2020 /* Output a structure type. We must use the same test here as we
2021 use in the DBX_NO_XREFS case above. */
2022 if ((TYPE_NAME (type) != 0
2023 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2024 && DECL_IGNORED_P (TYPE_NAME (type)))
2025 && !full)
2026 || !COMPLETE_TYPE_P (type)
2027 /* No way in DBX fmt to describe a variable size. */
2028 || ! host_integerp (TYPE_SIZE (type), 1))
2030 /* If the type is just a cross reference, output one
2031 and mark the type as partially described.
2032 If it later becomes defined, we will output
2033 its real definition.
2034 If the type has a name, don't nest its definition within
2035 another type's definition; instead, output an xref
2036 and let the definition come when the name is defined. */
2037 stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2038 if (TYPE_NAME (type) != 0)
2039 dbxout_type_name (type);
2040 else
2042 stabstr_S ("$$");
2043 stabstr_D (anonymous_type_number++);
2046 stabstr_C (':');
2047 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2048 break;
2051 /* Identify record or union, and print its size. */
2052 stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2053 stabstr_D (int_size_in_bytes (type));
2055 if (binfo)
2057 int i;
2058 tree child;
2059 VEC (tree) *accesses = BINFO_BASE_ACCESSES (binfo);
2061 if (use_gnu_debug_info_extensions)
2063 if (BINFO_N_BASE_BINFOS (binfo))
2065 have_used_extensions = 1;
2066 stabstr_C ('!');
2067 stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2068 stabstr_C (',');
2071 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2073 tree access = (accesses ? VEC_index (tree, accesses, i)
2074 : access_public_node);
2076 if (use_gnu_debug_info_extensions)
2078 have_used_extensions = 1;
2079 stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2080 stabstr_C (access == access_public_node ? '2' :
2081 access == access_protected_node
2082 ? '1' :'0');
2083 if (BINFO_VIRTUAL_P (child)
2084 && strcmp (lang_hooks.name, "GNU C++") == 0)
2085 /* For a virtual base, print the (negative)
2086 offset within the vtable where we must look
2087 to find the necessary adjustment. */
2088 stabstr_D
2089 (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2090 * BITS_PER_UNIT);
2091 else
2092 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2093 * BITS_PER_UNIT);
2094 stabstr_C (',');
2095 dbxout_type (BINFO_TYPE (child), 0);
2096 stabstr_C (';');
2098 else
2100 /* Print out the base class information with
2101 fields which have the same names at the types
2102 they hold. */
2103 dbxout_type_name (BINFO_TYPE (child));
2104 stabstr_C (':');
2105 dbxout_type (BINFO_TYPE (child), full);
2106 stabstr_C (',');
2107 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2108 * BITS_PER_UNIT);
2109 stabstr_C (',');
2110 stabstr_D
2111 (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2112 * BITS_PER_UNIT);
2113 stabstr_C (';');
2119 /* Write out the field declarations. */
2120 dbxout_type_fields (type);
2121 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2123 have_used_extensions = 1;
2124 dbxout_type_methods (type);
2127 stabstr_C (';');
2129 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2130 /* Avoid the ~ if we don't really need it--it confuses dbx. */
2131 && TYPE_VFIELD (type))
2133 have_used_extensions = 1;
2135 /* We need to write out info about what field this class
2136 uses as its "main" vtable pointer field, because if this
2137 field is inherited from a base class, GDB cannot necessarily
2138 figure out which field it's using in time. */
2139 stabstr_S ("~%");
2140 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2141 stabstr_C (';');
2143 break;
2145 case ENUMERAL_TYPE:
2146 /* We must use the same test here as we use in the DBX_NO_XREFS case
2147 above. We simplify it a bit since an enum will never have a variable
2148 size. */
2149 if ((TYPE_NAME (type) != 0
2150 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2151 && DECL_IGNORED_P (TYPE_NAME (type)))
2152 && !full)
2153 || !COMPLETE_TYPE_P (type))
2155 stabstr_S ("xe");
2156 dbxout_type_name (type);
2157 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2158 stabstr_C (':');
2159 return;
2161 if (use_gnu_debug_info_extensions
2162 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2164 have_used_extensions = 1;
2165 stabstr_S ("@s");
2166 stabstr_D (TYPE_PRECISION (type));
2167 stabstr_C (';');
2170 stabstr_C ('e');
2171 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2173 stabstr_I (TREE_PURPOSE (tem));
2174 stabstr_C (':');
2176 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
2177 stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2178 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
2179 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
2180 stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2181 else
2182 stabstr_O (TREE_VALUE (tem));
2184 stabstr_C (',');
2185 if (TREE_CHAIN (tem) != 0)
2186 CONTIN;
2189 stabstr_C (';');
2190 break;
2192 case POINTER_TYPE:
2193 stabstr_C ('*');
2194 dbxout_type (TREE_TYPE (type), 0);
2195 break;
2197 case METHOD_TYPE:
2198 if (use_gnu_debug_info_extensions)
2200 have_used_extensions = 1;
2201 stabstr_C ('#');
2203 /* Write the argument types out longhand. */
2204 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2205 stabstr_C (',');
2206 dbxout_type (TREE_TYPE (type), 0);
2207 dbxout_args (TYPE_ARG_TYPES (type));
2208 stabstr_C (';');
2210 else
2211 /* Treat it as a function type. */
2212 dbxout_type (TREE_TYPE (type), 0);
2213 break;
2215 case OFFSET_TYPE:
2216 if (use_gnu_debug_info_extensions)
2218 have_used_extensions = 1;
2219 stabstr_C ('@');
2220 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2221 stabstr_C (',');
2222 dbxout_type (TREE_TYPE (type), 0);
2224 else
2225 /* Should print as an int, because it is really just an offset. */
2226 dbxout_type (integer_type_node, 0);
2227 break;
2229 case REFERENCE_TYPE:
2230 if (use_gnu_debug_info_extensions)
2232 have_used_extensions = 1;
2233 stabstr_C ('&');
2235 else
2236 stabstr_C ('*');
2237 dbxout_type (TREE_TYPE (type), 0);
2238 break;
2240 case FUNCTION_TYPE:
2241 stabstr_C ('f');
2242 dbxout_type (TREE_TYPE (type), 0);
2243 break;
2245 default:
2246 gcc_unreachable ();
2250 /* Return nonzero if the given type represents an integer whose bounds
2251 should be printed in octal format. */
2253 static bool
2254 print_int_cst_bounds_in_octal_p (tree type)
2256 /* If we can use GDB extensions and the size is wider than a long
2257 (the size used by GDB to read them) or we may have trouble writing
2258 the bounds the usual way, write them in octal. Note the test is for
2259 the *target's* size of "long", not that of the host. The host test
2260 is just to make sure we can write it out in case the host wide int
2261 is narrower than the target "long".
2263 For unsigned types, we use octal if they are the same size or larger.
2264 This is because we print the bounds as signed decimal, and hence they
2265 can't span same size unsigned types. */
2267 if (use_gnu_debug_info_extensions
2268 && TYPE_MIN_VALUE (type) != 0
2269 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
2270 && TYPE_MAX_VALUE (type) != 0
2271 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
2272 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2273 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2274 && TYPE_UNSIGNED (type))
2275 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2276 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2277 && TYPE_UNSIGNED (type))))
2278 return TRUE;
2279 else
2280 return FALSE;
2283 /* Output the name of type TYPE, with no punctuation.
2284 Such names can be set up either by typedef declarations
2285 or by struct, enum and union tags. */
2287 static void
2288 dbxout_type_name (tree type)
2290 tree t = TYPE_NAME (type);
2292 gcc_assert (t);
2293 switch (TREE_CODE (t))
2295 case IDENTIFIER_NODE:
2296 break;
2297 case TYPE_DECL:
2298 t = DECL_NAME (t);
2299 break;
2300 default:
2301 gcc_unreachable ();
2304 stabstr_I (t);
2307 /* Output leading leading struct or class names needed for qualifying
2308 type whose scope is limited to a struct or class. */
2310 static void
2311 dbxout_class_name_qualifiers (tree decl)
2313 tree context = decl_type_context (decl);
2315 if (context != NULL_TREE
2316 && TREE_CODE(context) == RECORD_TYPE
2317 && TYPE_NAME (context) != 0
2318 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2319 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2321 tree name = TYPE_NAME (context);
2323 if (TREE_CODE (name) == TYPE_DECL)
2325 dbxout_class_name_qualifiers (name);
2326 name = DECL_NAME (name);
2328 stabstr_I (name);
2329 stabstr_S ("::");
2333 /* Output a .stabs for the symbol defined by DECL,
2334 which must be a ..._DECL node in the normal namespace.
2335 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2336 LOCAL is nonzero if the scope is less than the entire file.
2337 Return 1 if a stabs might have been emitted. */
2340 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2342 tree type = TREE_TYPE (decl);
2343 tree context = NULL_TREE;
2344 int result = 0;
2346 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2347 ++debug_nesting;
2349 /* Ignore nameless syms, but don't ignore type tags. */
2351 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2352 || DECL_IGNORED_P (decl))
2353 DBXOUT_DECR_NESTING_AND_RETURN (0);
2355 /* If we are to generate only the symbols actually used then such
2356 symbol nodees are flagged with TREE_USED. Ignore any that
2357 aren't flaged as TREE_USED. */
2359 if (flag_debug_only_used_symbols
2360 && (!TREE_USED (decl)
2361 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2362 DBXOUT_DECR_NESTING_AND_RETURN (0);
2364 /* If dbxout_init has not yet run, queue this symbol for later. */
2365 if (!typevec)
2367 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2368 DBXOUT_DECR_NESTING_AND_RETURN (0);
2371 if (flag_debug_only_used_symbols)
2373 tree t;
2375 /* We now have a used symbol. We need to generate the info for
2376 the symbol's type in addition to the symbol itself. These
2377 type symbols are queued to be generated after were done with
2378 the symbol itself (otherwise they would fight over the
2379 stabstr obstack).
2381 Note, because the TREE_TYPE(type) might be something like a
2382 pointer to a named type we need to look for the first name
2383 we see following the TREE_TYPE chain. */
2385 t = type;
2386 while (POINTER_TYPE_P (t))
2387 t = TREE_TYPE (t);
2389 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2390 need special treatment. The TYPE_STUB_DECL field in these
2391 types generally represents the tag name type we want to
2392 output. In addition there could be a typedef type with
2393 a different name. In that case we also want to output
2394 that. */
2396 if (TREE_CODE (t) == RECORD_TYPE
2397 || TREE_CODE (t) == UNION_TYPE
2398 || TREE_CODE (t) == QUAL_UNION_TYPE
2399 || TREE_CODE (t) == ENUMERAL_TYPE)
2401 if (TYPE_STUB_DECL (t)
2402 && TYPE_STUB_DECL (t) != decl
2403 && DECL_P (TYPE_STUB_DECL (t))
2404 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2406 debug_queue_symbol (TYPE_STUB_DECL (t));
2407 if (TYPE_NAME (t)
2408 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2409 && TYPE_NAME (t) != decl
2410 && DECL_P (TYPE_NAME (t)))
2411 debug_queue_symbol (TYPE_NAME (t));
2414 else if (TYPE_NAME (t)
2415 && TYPE_NAME (t) != decl
2416 && DECL_P (TYPE_NAME (t)))
2417 debug_queue_symbol (TYPE_NAME (t));
2420 emit_pending_bincls_if_required ();
2422 switch (TREE_CODE (decl))
2424 case CONST_DECL:
2425 /* Enum values are defined by defining the enum type. */
2426 break;
2428 case FUNCTION_DECL:
2429 if (DECL_RTL (decl) == 0)
2430 DBXOUT_DECR_NESTING_AND_RETURN (0);
2431 if (DECL_EXTERNAL (decl))
2432 break;
2433 /* Don't mention a nested function under its parent. */
2434 context = decl_function_context (decl);
2435 if (context == current_function_decl)
2436 break;
2437 if (!MEM_P (DECL_RTL (decl))
2438 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2439 break;
2441 dbxout_begin_complex_stabs ();
2442 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2443 stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2444 result = 1;
2446 if (TREE_TYPE (type))
2447 dbxout_type (TREE_TYPE (type), 0);
2448 else
2449 dbxout_type (void_type_node, 0);
2451 /* For a nested function, when that function is compiled,
2452 mention the containing function name
2453 as well as (since dbx wants it) our own assembler-name. */
2454 if (context != 0)
2456 stabstr_C (',');
2457 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2458 stabstr_C (',');
2459 stabstr_I (DECL_NAME (context));
2462 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (DECL_RTL (decl), 0),
2463 0, 0);
2464 break;
2466 case TYPE_DECL:
2467 /* Don't output the same typedef twice.
2468 And don't output what language-specific stuff doesn't want output. */
2469 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2470 DBXOUT_DECR_NESTING_AND_RETURN (0);
2472 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2473 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2475 int fundamental_type_number =
2476 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2478 if (fundamental_type_number != 0)
2480 TREE_ASM_WRITTEN (decl) = 1;
2481 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2482 DBXOUT_DECR_NESTING_AND_RETURN (0);
2485 #endif
2486 FORCE_TEXT;
2487 result = 1;
2489 int tag_needed = 1;
2490 int did_output = 0;
2492 if (DECL_NAME (decl))
2494 /* Nonzero means we must output a tag as well as a typedef. */
2495 tag_needed = 0;
2497 /* Handle the case of a C++ structure or union
2498 where the TYPE_NAME is a TYPE_DECL
2499 which gives both a typedef name and a tag. */
2500 /* dbx requires the tag first and the typedef second. */
2501 if ((TREE_CODE (type) == RECORD_TYPE
2502 || TREE_CODE (type) == UNION_TYPE
2503 || TREE_CODE (type) == QUAL_UNION_TYPE)
2504 && TYPE_NAME (type) == decl
2505 && !(use_gnu_debug_info_extensions && have_used_extensions)
2506 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2507 /* Distinguish the implicit typedefs of C++
2508 from explicit ones that might be found in C. */
2509 && DECL_ARTIFICIAL (decl)
2510 /* Do not generate a tag for incomplete records. */
2511 && COMPLETE_TYPE_P (type)
2512 /* Do not generate a tag for records of variable size,
2513 since this type can not be properly described in the
2514 DBX format, and it confuses some tools such as objdump. */
2515 && host_integerp (TYPE_SIZE (type), 1))
2517 tree name = TYPE_NAME (type);
2518 if (TREE_CODE (name) == TYPE_DECL)
2519 name = DECL_NAME (name);
2521 dbxout_begin_complex_stabs ();
2522 stabstr_I (name);
2523 stabstr_S (":T");
2524 dbxout_type (type, 1);
2525 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2526 0, 0, 0);
2529 dbxout_begin_complex_stabs ();
2531 /* Output leading class/struct qualifiers.
2532 ??? why not set have_used_extensions here ... because
2533 then the test of it below would always be true, I
2534 guess. But it's not clear to me why we shouldn't do
2535 that always in extended mode. */
2536 if (use_gnu_debug_info_extensions)
2537 dbxout_class_name_qualifiers (decl);
2539 /* Output typedef name. */
2540 stabstr_I (DECL_NAME (decl));
2541 stabstr_C (':');
2543 /* Short cut way to output a tag also. */
2544 if ((TREE_CODE (type) == RECORD_TYPE
2545 || TREE_CODE (type) == UNION_TYPE
2546 || TREE_CODE (type) == QUAL_UNION_TYPE)
2547 && TYPE_NAME (type) == decl
2548 /* Distinguish the implicit typedefs of C++
2549 from explicit ones that might be found in C. */
2550 && DECL_ARTIFICIAL (decl))
2552 if (use_gnu_debug_info_extensions && have_used_extensions)
2554 stabstr_C ('T');
2555 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2559 stabstr_C ('t');
2560 dbxout_type (type, 1);
2561 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2562 0, 0, 0);
2563 did_output = 1;
2566 /* Don't output a tag if this is an incomplete type. This prevents
2567 the sun4 Sun OS 4.x dbx from crashing. */
2569 if (tag_needed && TYPE_NAME (type) != 0
2570 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2571 || (DECL_NAME (TYPE_NAME (type)) != 0))
2572 && COMPLETE_TYPE_P (type)
2573 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2575 /* For a TYPE_DECL with no name, but the type has a name,
2576 output a tag.
2577 This is what represents `struct foo' with no typedef. */
2578 /* In C++, the name of a type is the corresponding typedef.
2579 In C, it is an IDENTIFIER_NODE. */
2580 tree name = TYPE_NAME (type);
2581 if (TREE_CODE (name) == TYPE_DECL)
2582 name = DECL_NAME (name);
2584 dbxout_begin_complex_stabs ();
2585 stabstr_I (name);
2586 stabstr_S (":T");
2587 dbxout_type (type, 1);
2588 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2589 did_output = 1;
2592 /* If an enum type has no name, it cannot be referred to, but
2593 we must output it anyway, to record the enumeration
2594 constants. */
2596 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2598 dbxout_begin_complex_stabs ();
2599 /* Some debuggers fail when given NULL names, so give this a
2600 harmless name of " " (Why not "(anon)"?). */
2601 stabstr_S (" :T");
2602 dbxout_type (type, 1);
2603 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2606 /* Prevent duplicate output of a typedef. */
2607 TREE_ASM_WRITTEN (decl) = 1;
2608 break;
2611 case PARM_DECL:
2612 /* Parm decls go in their own separate chains
2613 and are output by dbxout_reg_parms and dbxout_parms. */
2614 gcc_unreachable ();
2616 case RESULT_DECL:
2617 /* Named return value, treat like a VAR_DECL. */
2618 case VAR_DECL:
2619 if (! DECL_RTL_SET_P (decl))
2620 DBXOUT_DECR_NESTING_AND_RETURN (0);
2621 /* Don't mention a variable that is external.
2622 Let the file that defines it describe it. */
2623 if (DECL_EXTERNAL (decl))
2624 break;
2626 /* If the variable is really a constant
2627 and not written in memory, inform the debugger.
2629 ??? Why do we skip emitting the type and location in this case? */
2630 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2631 && DECL_INITIAL (decl) != 0
2632 && host_integerp (DECL_INITIAL (decl), 0)
2633 && ! TREE_ASM_WRITTEN (decl)
2634 && (DECL_CONTEXT (decl) == NULL_TREE
2635 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK)
2636 && TREE_PUBLIC (decl) == 0)
2638 /* The sun4 assembler does not grok this. */
2640 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2641 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2643 HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
2645 dbxout_begin_complex_stabs ();
2646 stabstr_I (DECL_NAME (decl));
2647 stabstr_S (":c=i");
2648 stabstr_D (ival);
2649 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2650 DBXOUT_DECR_NESTING;
2651 return 1;
2653 else
2654 break;
2656 /* else it is something we handle like a normal variable. */
2658 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2659 #ifdef LEAF_REG_REMAP
2660 if (current_function_uses_only_leaf_regs)
2661 leaf_renumber_regs_insn (DECL_RTL (decl));
2662 #endif
2664 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2665 break;
2667 default:
2668 break;
2670 DBXOUT_DECR_NESTING;
2671 return result;
2674 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2675 Add SUFFIX to its name, if SUFFIX is not 0.
2676 Describe the variable as residing in HOME
2677 (usually HOME is DECL_RTL (DECL), but not always).
2678 Returns 1 if the stab was really emitted. */
2680 static int
2681 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2683 int letter = 0;
2684 STAB_CODE_TYPE code;
2685 rtx addr = 0;
2686 int number = 0;
2687 int regno = -1;
2689 /* Don't mention a variable at all
2690 if it was completely optimized into nothingness.
2692 If the decl was from an inline function, then its rtl
2693 is not identically the rtl that was used in this
2694 particular compilation. */
2695 if (GET_CODE (home) == SUBREG)
2697 rtx value = home;
2699 while (GET_CODE (value) == SUBREG)
2700 value = SUBREG_REG (value);
2701 if (REG_P (value))
2703 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2704 return 0;
2706 home = alter_subreg (&home);
2708 if (REG_P (home))
2710 regno = REGNO (home);
2711 if (regno >= FIRST_PSEUDO_REGISTER)
2712 return 0;
2715 /* The kind-of-variable letter depends on where
2716 the variable is and on the scope of its name:
2717 G and N_GSYM for static storage and global scope,
2718 S for static storage and file scope,
2719 V for static storage and local scope,
2720 for those two, use N_LCSYM if data is in bss segment,
2721 N_STSYM if in data segment, N_FUN otherwise.
2722 (We used N_FUN originally, then changed to N_STSYM
2723 to please GDB. However, it seems that confused ld.
2724 Now GDB has been fixed to like N_FUN, says Kingdon.)
2725 no letter at all, and N_LSYM, for auto variable,
2726 r and N_RSYM for register variable. */
2728 if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2730 if (TREE_PUBLIC (decl))
2732 letter = 'G';
2733 code = N_GSYM;
2735 else
2737 addr = XEXP (home, 0);
2739 letter = decl_function_context (decl) ? 'V' : 'S';
2741 /* This should be the same condition as in assemble_variable, but
2742 we don't have access to dont_output_data here. So, instead,
2743 we rely on the fact that error_mark_node initializers always
2744 end up in bss for C++ and never end up in bss for C. */
2745 if (DECL_INITIAL (decl) == 0
2746 || (!strcmp (lang_hooks.name, "GNU C++")
2747 && DECL_INITIAL (decl) == error_mark_node))
2748 code = N_LCSYM;
2749 else if (DECL_IN_TEXT_SECTION (decl))
2750 /* This is not quite right, but it's the closest
2751 of all the codes that Unix defines. */
2752 code = DBX_STATIC_CONST_VAR_CODE;
2753 else
2755 /* Some ports can transform a symbol ref into a label ref,
2756 because the symbol ref is too far away and has to be
2757 dumped into a constant pool. Alternatively, the symbol
2758 in the constant pool might be referenced by a different
2759 symbol. */
2760 if (GET_CODE (addr) == SYMBOL_REF
2761 && CONSTANT_POOL_ADDRESS_P (addr))
2763 bool marked;
2764 rtx tmp = get_pool_constant_mark (addr, &marked);
2766 if (GET_CODE (tmp) == SYMBOL_REF)
2768 addr = tmp;
2769 if (CONSTANT_POOL_ADDRESS_P (addr))
2770 get_pool_constant_mark (addr, &marked);
2771 else
2772 marked = true;
2774 else if (GET_CODE (tmp) == LABEL_REF)
2776 addr = tmp;
2777 marked = true;
2780 /* If all references to the constant pool were optimized
2781 out, we just ignore the symbol. */
2782 if (!marked)
2783 return 0;
2786 /* Ultrix `as' seems to need this. */
2787 #ifdef DBX_STATIC_STAB_DATA_SECTION
2788 data_section ();
2789 #endif
2790 code = N_STSYM;
2794 else if (regno >= 0)
2796 letter = 'r';
2797 code = N_RSYM;
2798 number = DBX_REGISTER_NUMBER (regno);
2800 else if (MEM_P (home)
2801 && (MEM_P (XEXP (home, 0))
2802 || (REG_P (XEXP (home, 0))
2803 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2804 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2805 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2806 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2807 #endif
2809 /* If the value is indirect by memory or by a register
2810 that isn't the frame pointer
2811 then it means the object is variable-sized and address through
2812 that register or stack slot. DBX has no way to represent this
2813 so all we can do is output the variable as a pointer.
2814 If it's not a parameter, ignore it. */
2816 if (REG_P (XEXP (home, 0)))
2818 letter = 'r';
2819 code = N_RSYM;
2820 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2821 return 0;
2822 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2824 else
2826 code = N_LSYM;
2827 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2828 We want the value of that CONST_INT. */
2829 number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2832 /* Effectively do build_pointer_type, but don't cache this type,
2833 since it might be temporary whereas the type it points to
2834 might have been saved for inlining. */
2835 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2836 type = make_node (POINTER_TYPE);
2837 TREE_TYPE (type) = TREE_TYPE (decl);
2839 else if (MEM_P (home)
2840 && REG_P (XEXP (home, 0)))
2842 code = N_LSYM;
2843 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2845 else if (MEM_P (home)
2846 && GET_CODE (XEXP (home, 0)) == PLUS
2847 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2849 code = N_LSYM;
2850 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2851 We want the value of that CONST_INT. */
2852 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2854 else if (MEM_P (home)
2855 && GET_CODE (XEXP (home, 0)) == CONST)
2857 /* Handle an obscure case which can arise when optimizing and
2858 when there are few available registers. (This is *always*
2859 the case for i386/i486 targets). The RTL looks like
2860 (MEM (CONST ...)) even though this variable is a local `auto'
2861 or a local `register' variable. In effect, what has happened
2862 is that the reload pass has seen that all assignments and
2863 references for one such a local variable can be replaced by
2864 equivalent assignments and references to some static storage
2865 variable, thereby avoiding the need for a register. In such
2866 cases we're forced to lie to debuggers and tell them that
2867 this variable was itself `static'. */
2868 code = N_LCSYM;
2869 letter = 'V';
2870 addr = XEXP (XEXP (home, 0), 0);
2872 else if (GET_CODE (home) == CONCAT)
2874 tree subtype;
2876 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2877 for example), then there is no easy way to figure out
2878 what SUBTYPE should be. So, we give up. */
2879 if (TREE_CODE (type) != COMPLEX_TYPE)
2880 return 0;
2882 subtype = TREE_TYPE (type);
2884 /* If the variable's storage is in two parts,
2885 output each as a separate stab with a modified name. */
2886 if (WORDS_BIG_ENDIAN)
2887 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2888 else
2889 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2891 if (WORDS_BIG_ENDIAN)
2892 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2893 else
2894 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2895 return 1;
2897 else
2898 /* Address might be a MEM, when DECL is a variable-sized object.
2899 Or it might be const0_rtx, meaning previous passes
2900 want us to ignore this variable. */
2901 return 0;
2903 /* Ok, start a symtab entry and output the variable name. */
2905 #ifdef DBX_STATIC_BLOCK_START
2906 DBX_STATIC_BLOCK_START (asm_out_file, code);
2907 #endif
2909 dbxout_begin_complex_stabs ();
2910 dbxout_symbol_name (decl, suffix, letter);
2911 dbxout_type (type, 0);
2912 dbxout_finish_complex_stabs (decl, code, addr, 0, number);
2914 #ifdef DBX_STATIC_BLOCK_END
2915 DBX_STATIC_BLOCK_END (asm_out_file, code);
2916 #endif
2917 return 1;
2920 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2921 Then output LETTER to indicate the kind of location the symbol has. */
2923 static void
2924 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2926 tree name;
2928 if (DECL_CONTEXT (decl)
2929 && (TYPE_P (DECL_CONTEXT (decl))
2930 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
2931 /* One slight hitch: if this is a VAR_DECL which is a class member
2932 or a namespace member, we must put out the mangled name instead of the
2933 DECL_NAME. Note also that static member (variable) names DO NOT begin
2934 with underscores in .stabs directives. */
2935 name = DECL_ASSEMBLER_NAME (decl);
2936 else
2937 /* ...but if we're function-local, we don't want to include the junk
2938 added by ASM_FORMAT_PRIVATE_NAME. */
2939 name = DECL_NAME (decl);
2941 if (name)
2942 stabstr_I (name);
2943 else
2944 stabstr_S ("(anon)");
2946 if (suffix)
2947 stabstr_S (suffix);
2948 stabstr_C (':');
2949 if (letter)
2950 stabstr_C (letter);
2953 /* Output definitions of all the decls in a chain. Return nonzero if
2954 anything was output */
2957 dbxout_syms (tree syms)
2959 int result = 0;
2960 while (syms)
2962 result += dbxout_symbol (syms, 1);
2963 syms = TREE_CHAIN (syms);
2965 return result;
2968 /* The following two functions output definitions of function parameters.
2969 Each parameter gets a definition locating it in the parameter list.
2970 Each parameter that is a register variable gets a second definition
2971 locating it in the register.
2973 Printing or argument lists in gdb uses the definitions that
2974 locate in the parameter list. But reference to the variable in
2975 expressions uses preferentially the definition as a register. */
2977 /* Output definitions, referring to storage in the parmlist,
2978 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2980 void
2981 dbxout_parms (tree parms)
2983 ++debug_nesting;
2984 emit_pending_bincls_if_required ();
2986 for (; parms; parms = TREE_CHAIN (parms))
2987 if (DECL_NAME (parms)
2988 && TREE_TYPE (parms) != error_mark_node
2989 && DECL_RTL_SET_P (parms)
2990 && DECL_INCOMING_RTL (parms))
2992 tree eff_type;
2993 char letter;
2994 STAB_CODE_TYPE code;
2995 int number;
2997 /* Perform any necessary register eliminations on the parameter's rtl,
2998 so that the debugging output will be accurate. */
2999 DECL_INCOMING_RTL (parms)
3000 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
3001 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
3002 #ifdef LEAF_REG_REMAP
3003 if (current_function_uses_only_leaf_regs)
3005 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3006 leaf_renumber_regs_insn (DECL_RTL (parms));
3008 #endif
3010 if (PARM_PASSED_IN_MEMORY (parms))
3012 rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3014 /* ??? Here we assume that the parm address is indexed
3015 off the frame pointer or arg pointer.
3016 If that is not true, we produce meaningless results,
3017 but do not crash. */
3018 if (GET_CODE (inrtl) == PLUS
3019 && GET_CODE (XEXP (inrtl, 1)) == CONST_INT)
3020 number = INTVAL (XEXP (inrtl, 1));
3021 else
3022 number = 0;
3024 code = N_PSYM;
3025 number = DEBUGGER_ARG_OFFSET (number, inrtl);
3026 letter = 'p';
3028 /* It is quite tempting to use TREE_TYPE (parms) instead
3029 of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3030 reports the actual type of the parameter, rather than
3031 the promoted type. This certainly makes GDB's life
3032 easier, at least for some ports. The change is a bad
3033 idea however, since GDB expects to be able access the
3034 type without performing any conversions. So for
3035 example, if we were passing a float to an unprototyped
3036 function, gcc will store a double on the stack, but if
3037 we emit a stab saying the type is a float, then gdb
3038 will only read in a single value, and this will produce
3039 an erroneous value. */
3040 eff_type = DECL_ARG_TYPE (parms);
3042 else if (REG_P (DECL_RTL (parms)))
3044 rtx best_rtl;
3046 /* Parm passed in registers and lives in registers or nowhere. */
3047 code = DBX_REGPARM_STABS_CODE;
3048 letter = DBX_REGPARM_STABS_LETTER;
3050 /* For parms passed in registers, it is better to use the
3051 declared type of the variable, not the type it arrived in. */
3052 eff_type = TREE_TYPE (parms);
3054 /* If parm lives in a register, use that register; pretend
3055 the parm was passed there. It would be more consistent
3056 to describe the register where the parm was passed, but
3057 in practice that register usually holds something else.
3058 If the parm lives nowhere, use the register where it
3059 was passed. */
3060 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3061 best_rtl = DECL_RTL (parms);
3062 else
3063 best_rtl = DECL_INCOMING_RTL (parms);
3065 number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3067 else if (MEM_P (DECL_RTL (parms))
3068 && REG_P (XEXP (DECL_RTL (parms), 0))
3069 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3070 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3071 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3072 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3073 #endif
3076 /* Parm was passed via invisible reference.
3077 That is, its address was passed in a register.
3078 Output it as if it lived in that register.
3079 The debugger will know from the type
3080 that it was actually passed by invisible reference. */
3082 code = DBX_REGPARM_STABS_CODE;
3084 /* GDB likes this marked with a special letter. */
3085 letter = (use_gnu_debug_info_extensions
3086 ? 'a' : DBX_REGPARM_STABS_LETTER);
3087 eff_type = TREE_TYPE (parms);
3089 /* DECL_RTL looks like (MEM (REG...). Get the register number.
3090 If it is an unallocated pseudo-reg, then use the register where
3091 it was passed instead.
3092 ??? Why is DBX_REGISTER_NUMBER not used here? */
3094 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3095 number = REGNO (XEXP (DECL_RTL (parms), 0));
3096 else
3097 number = REGNO (DECL_INCOMING_RTL (parms));
3099 else if (MEM_P (DECL_RTL (parms))
3100 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3102 /* Parm was passed via invisible reference, with the reference
3103 living on the stack. DECL_RTL looks like
3104 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3105 could look like (MEM (MEM (REG))). */
3107 code = N_PSYM;
3108 letter = 'v';
3109 eff_type = TREE_TYPE (parms);
3111 if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3112 number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3113 else
3114 number = 0;
3116 number = DEBUGGER_ARG_OFFSET (number,
3117 XEXP (XEXP (DECL_RTL (parms), 0), 0));
3119 else if (MEM_P (DECL_RTL (parms))
3120 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3121 /* ??? A constant address for a parm can happen
3122 when the reg it lives in is equiv to a constant in memory.
3123 Should make this not happen, after 2.4. */
3124 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3126 /* Parm was passed in registers but lives on the stack. */
3128 code = N_PSYM;
3129 letter = 'p';
3130 eff_type = TREE_TYPE (parms);
3132 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3133 in which case we want the value of that CONST_INT,
3134 or (MEM (REG ...)),
3135 in which case we use a value of zero. */
3136 if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3137 number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3138 else
3139 number = 0;
3141 /* Make a big endian correction if the mode of the type of the
3142 parameter is not the same as the mode of the rtl. */
3143 if (BYTES_BIG_ENDIAN
3144 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3145 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3146 number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3147 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3149 else
3150 /* ??? We don't know how to represent this argument. */
3151 continue;
3153 dbxout_begin_complex_stabs ();
3155 if (DECL_NAME (parms))
3157 stabstr_I (DECL_NAME (parms));
3158 stabstr_C (':');
3160 else
3161 stabstr_S ("(anon):");
3162 stabstr_C (letter);
3163 dbxout_type (eff_type, 0);
3164 dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3166 DBXOUT_DECR_NESTING;
3169 /* Output definitions for the places where parms live during the function,
3170 when different from where they were passed, when the parms were passed
3171 in memory.
3173 It is not useful to do this for parms passed in registers
3174 that live during the function in different registers, because it is
3175 impossible to look in the passed register for the passed value,
3176 so we use the within-the-function register to begin with.
3178 PARMS is a chain of PARM_DECL nodes. */
3180 void
3181 dbxout_reg_parms (tree parms)
3183 ++debug_nesting;
3185 for (; parms; parms = TREE_CHAIN (parms))
3186 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3188 /* Report parms that live in registers during the function
3189 but were passed in memory. */
3190 if (REG_P (DECL_RTL (parms))
3191 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3192 dbxout_symbol_location (parms, TREE_TYPE (parms),
3193 0, DECL_RTL (parms));
3194 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3195 dbxout_symbol_location (parms, TREE_TYPE (parms),
3196 0, DECL_RTL (parms));
3197 /* Report parms that live in memory but not where they were passed. */
3198 else if (MEM_P (DECL_RTL (parms))
3199 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3200 dbxout_symbol_location (parms, TREE_TYPE (parms),
3201 0, DECL_RTL (parms));
3203 DBXOUT_DECR_NESTING;
3206 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3207 output definitions of those names, in raw form */
3209 static void
3210 dbxout_args (tree args)
3212 while (args)
3214 stabstr_C (',');
3215 dbxout_type (TREE_VALUE (args), 0);
3216 args = TREE_CHAIN (args);
3220 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3221 BEGIN_LABEL is the name of the beginning of the function, which may
3222 be required. */
3223 static void
3224 dbx_output_lbrac (const char *label,
3225 const char *begin_label ATTRIBUTE_UNUSED)
3227 #ifdef DBX_OUTPUT_LBRAC
3228 DBX_OUTPUT_LBRAC (asm_out_file, label);
3229 #else
3230 dbxout_begin_stabn (N_LBRAC);
3231 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3232 dbxout_stab_value_label_diff (label, begin_label);
3233 else
3234 dbxout_stab_value_label (label);
3235 #endif
3238 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3239 BEGIN_LABEL is the name of the beginning of the function, which may
3240 be required. */
3241 static void
3242 dbx_output_rbrac (const char *label,
3243 const char *begin_label ATTRIBUTE_UNUSED)
3245 #ifdef DBX_OUTPUT_RBRAC
3246 DBX_OUTPUT_RBRAC (asm_out_file, label);
3247 #else
3248 dbxout_begin_stabn (N_RBRAC);
3249 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3250 dbxout_stab_value_label_diff (label, begin_label);
3251 else
3252 dbxout_stab_value_label (label);
3253 #endif
3256 /* Output everything about a symbol block (a BLOCK node
3257 that represents a scope level),
3258 including recursive output of contained blocks.
3260 BLOCK is the BLOCK node.
3261 DEPTH is its depth within containing symbol blocks.
3262 ARGS is usually zero; but for the outermost block of the
3263 body of a function, it is a chain of PARM_DECLs for the function parameters.
3264 We output definitions of all the register parms
3265 as if they were local variables of that block.
3267 If -g1 was used, we count blocks just the same, but output nothing
3268 except for the outermost block.
3270 Actually, BLOCK may be several blocks chained together.
3271 We handle them all in sequence. */
3273 static void
3274 dbxout_block (tree block, int depth, tree args)
3276 const char *begin_label
3277 = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3279 while (block)
3281 /* Ignore blocks never expanded or otherwise marked as real. */
3282 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3284 int did_output;
3285 int blocknum = BLOCK_NUMBER (block);
3287 /* In dbx format, the syms of a block come before the N_LBRAC.
3288 If nothing is output, we don't need the N_LBRAC, either. */
3289 did_output = 0;
3290 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3291 did_output = dbxout_syms (BLOCK_VARS (block));
3292 if (args)
3293 dbxout_reg_parms (args);
3295 /* Now output an N_LBRAC symbol to represent the beginning of
3296 the block. Use the block's tree-walk order to generate
3297 the assembler symbols LBBn and LBEn
3298 that final will define around the code in this block. */
3299 if (did_output)
3301 char buf[20];
3302 const char *scope_start;
3304 if (depth == 0)
3305 /* The outermost block doesn't get LBB labels; use
3306 the function symbol. */
3307 scope_start = begin_label;
3308 else
3310 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3311 scope_start = buf;
3314 if (BLOCK_HANDLER_BLOCK (block))
3316 /* A catch block. Must precede N_LBRAC. */
3317 tree decl = BLOCK_VARS (block);
3318 while (decl)
3320 dbxout_begin_complex_stabs ();
3321 stabstr_I (DECL_NAME (decl));
3322 stabstr_S (":C1");
3323 dbxout_finish_complex_stabs (0, N_CATCH, 0,
3324 scope_start, 0);
3325 decl = TREE_CHAIN (decl);
3328 dbx_output_lbrac (scope_start, begin_label);
3331 /* Output the subblocks. */
3332 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3334 /* Refer to the marker for the end of the block. */
3335 if (did_output)
3337 char buf[100];
3338 if (depth == 0)
3339 /* The outermost block doesn't get LBE labels;
3340 use the "scope" label which will be emitted
3341 by dbxout_function_end. */
3342 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3343 else
3344 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3346 dbx_output_rbrac (buf, begin_label);
3349 block = BLOCK_CHAIN (block);
3353 /* Output the information about a function and its arguments and result.
3354 Usually this follows the function's code,
3355 but on some systems, it comes before. */
3357 #if defined (DBX_DEBUGGING_INFO)
3358 static void
3359 dbxout_begin_function (tree decl)
3361 int saved_tree_used1 = TREE_USED (decl);
3362 TREE_USED (decl) = 1;
3363 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3365 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3366 TREE_USED (DECL_RESULT (decl)) = 1;
3367 dbxout_symbol (decl, 0);
3368 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3370 else
3371 dbxout_symbol (decl, 0);
3372 TREE_USED (decl) = saved_tree_used1;
3374 dbxout_parms (DECL_ARGUMENTS (decl));
3375 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3376 dbxout_symbol (DECL_RESULT (decl), 1);
3378 #endif /* DBX_DEBUGGING_INFO */
3380 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3382 #include "gt-dbxout.h"