In libobjc/: 2011-05-24 Nicola Pero <nicola.pero@meta-innovation.com>
[official-gcc.git] / gcc / dbxout.c
blobbe43ed3dae7251eceae6a24907e04a542c64494f
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, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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 "diagnostic-core.h"
85 #include "toplev.h"
86 #include "tm_p.h"
87 #include "ggc.h"
88 #include "debug.h"
89 #include "function.h"
90 #include "target.h"
91 #include "langhooks.h"
92 #include "obstack.h"
93 #include "expr.h"
94 #include "cgraph.h"
96 #ifdef XCOFF_DEBUGGING_INFO
97 #include "xcoffout.h"
98 #endif
100 #ifndef ASM_STABS_OP
101 # ifdef XCOFF_DEBUGGING_INFO
102 # define ASM_STABS_OP "\t.stabx\t"
103 # else
104 # define ASM_STABS_OP "\t.stabs\t"
105 # endif
106 #endif
108 #ifndef ASM_STABN_OP
109 #define ASM_STABN_OP "\t.stabn\t"
110 #endif
112 #ifndef ASM_STABD_OP
113 #define ASM_STABD_OP "\t.stabd\t"
114 #endif
116 #ifndef DBX_TYPE_DECL_STABS_CODE
117 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
118 #endif
120 #ifndef DBX_STATIC_CONST_VAR_CODE
121 #define DBX_STATIC_CONST_VAR_CODE N_FUN
122 #endif
124 #ifndef DBX_REGPARM_STABS_CODE
125 #define DBX_REGPARM_STABS_CODE N_RSYM
126 #endif
128 #ifndef DBX_REGPARM_STABS_LETTER
129 #define DBX_REGPARM_STABS_LETTER 'P'
130 #endif
132 #ifndef NO_DBX_FUNCTION_END
133 #define NO_DBX_FUNCTION_END 0
134 #endif
136 #ifndef NO_DBX_BNSYM_ENSYM
137 #define NO_DBX_BNSYM_ENSYM 0
138 #endif
140 #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
141 #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
142 #endif
144 #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
145 #define DBX_BLOCKS_FUNCTION_RELATIVE 0
146 #endif
148 #ifndef DBX_LINES_FUNCTION_RELATIVE
149 #define DBX_LINES_FUNCTION_RELATIVE 0
150 #endif
152 #ifndef DBX_CONTIN_LENGTH
153 #define DBX_CONTIN_LENGTH 80
154 #endif
156 #ifndef DBX_CONTIN_CHAR
157 #define DBX_CONTIN_CHAR '\\'
158 #endif
160 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
162 /* Structure recording information about a C data type.
163 The status element says whether we have yet output
164 the definition of the type. TYPE_XREF says we have
165 output it as a cross-reference only.
166 The file_number and type_number elements are used if DBX_USE_BINCL
167 is defined. */
169 struct GTY(()) typeinfo {
170 enum typestatus status;
171 int file_number;
172 int type_number;
175 /* Vector recording information about C data types.
176 When we first notice a data type (a tree node),
177 we assign it a number using next_type_number.
178 That is its index in this vector. */
180 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
182 /* Number of elements of space allocated in `typevec'. */
184 static GTY(()) int typevec_len;
186 /* In dbx output, each type gets a unique number.
187 This is the number for the next type output.
188 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
190 static GTY(()) int next_type_number;
192 /* The C front end may call dbxout_symbol before dbxout_init runs.
193 We save all such decls in this list and output them when we get
194 to dbxout_init. */
196 static GTY(()) tree preinit_symbols;
198 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
200 /* When using N_BINCL in dbx output, each type number is actually a
201 pair of the file number and the type number within the file.
202 This is a stack of input files. */
204 struct dbx_file
206 struct dbx_file *next;
207 int file_number;
208 int next_type_number;
209 enum binclstatus bincl_status; /* Keep track of lazy bincl. */
210 const char *pending_bincl_name; /* Name of bincl. */
211 struct dbx_file *prev; /* Chain to traverse all pending bincls. */
214 /* This is the top of the stack.
216 This is not saved for PCH, because restoring a PCH should not change it.
217 next_file_number does have to be saved, because the PCH may use some
218 file numbers; however, just before restoring a PCH, next_file_number
219 should always be 0 because we should not have needed any file numbers
220 yet. */
222 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
223 && defined (DBX_USE_BINCL)
224 static struct dbx_file *current_file;
225 #endif
227 /* This is the next file number to use. */
229 static GTY(()) int next_file_number;
231 /* A counter for dbxout_function_end. */
233 static GTY(()) int scope_labelno;
235 /* A counter for dbxout_source_line. */
237 static GTY(()) int dbxout_source_line_counter;
239 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
240 for the N_SO filename stabs label. */
242 static GTY(()) int source_label_number = 1;
244 /* Last source file name mentioned in a NOTE insn. */
246 static GTY(()) const char *lastfile;
248 /* Used by PCH machinery to detect if 'lastfile' should be reset to
249 base_input_file. */
250 static GTY(()) int lastfile_is_base;
252 /* Typical USG systems don't have stab.h, and they also have
253 no use for DBX-format debugging info. */
255 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
257 #ifdef DBX_USE_BINCL
258 /* If zero then there is no pending BINCL. */
259 static int pending_bincls = 0;
260 #endif
262 /* The original input file name. */
263 static const char *base_input_file;
265 #ifdef DEBUG_SYMS_TEXT
266 #define FORCE_TEXT switch_to_section (current_function_section ())
267 #else
268 #define FORCE_TEXT
269 #endif
271 #include "gstab.h"
273 /* 1 if PARM is passed to this function in memory. */
275 #define PARM_PASSED_IN_MEMORY(PARM) \
276 (MEM_P (DECL_INCOMING_RTL (PARM)))
278 /* A C expression for the integer offset value of an automatic variable
279 (N_LSYM) having address X (an RTX). */
280 #ifndef DEBUGGER_AUTO_OFFSET
281 #define DEBUGGER_AUTO_OFFSET(X) \
282 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
283 #endif
285 /* A C expression for the integer offset value of an argument (N_PSYM)
286 having address X (an RTX). The nominal offset is OFFSET.
287 Note that we use OFFSET + 0 here to avoid the self-assign warning
288 when the macro is called in a context like
289 number = DEBUGGER_ARG_OFFSET(number, X) */
290 #ifndef DEBUGGER_ARG_OFFSET
291 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0)
292 #endif
294 /* This obstack holds the stab string currently being constructed. We
295 build it up here, then write it out, so we can split long lines up
296 properly (see dbxout_finish_complex_stabs). */
297 static struct obstack stabstr_ob;
298 static size_t stabstr_last_contin_point;
300 #ifdef DBX_USE_BINCL
301 static void emit_bincl_stab (const char *c);
302 static void emit_pending_bincls (void);
303 #endif
304 static inline void emit_pending_bincls_if_required (void);
306 static void dbxout_init (const char *);
308 static void dbxout_finish (const char *);
309 static void dbxout_start_source_file (unsigned, const char *);
310 static void dbxout_end_source_file (unsigned);
311 static void dbxout_typedefs (tree);
312 static void dbxout_type_index (tree);
313 static void dbxout_args (tree);
314 static void dbxout_type_fields (tree);
315 static void dbxout_type_method_1 (tree);
316 static void dbxout_type_methods (tree);
317 static void dbxout_range_type (tree, tree, tree);
318 static void dbxout_type (tree, int);
319 static bool print_int_cst_bounds_in_octal_p (tree, tree, tree);
320 static bool is_fortran (void);
321 static void dbxout_type_name (tree);
322 static void dbxout_class_name_qualifiers (tree);
323 static int dbxout_symbol_location (tree, tree, const char *, rtx);
324 static void dbxout_symbol_name (tree, const char *, int);
325 static void dbxout_common_name (tree, const char *, stab_code_type);
326 static const char *dbxout_common_check (tree, int *);
327 static void dbxout_global_decl (tree);
328 static void dbxout_type_decl (tree, int);
329 static void dbxout_handle_pch (unsigned);
330 static void debug_free_queue (void);
332 /* The debug hooks structure. */
333 #if defined (DBX_DEBUGGING_INFO)
335 static void dbxout_source_line (unsigned int, const char *, int, bool);
336 static void dbxout_begin_prologue (unsigned int, const char *);
337 static void dbxout_source_file (const char *);
338 static void dbxout_function_end (tree);
339 static void dbxout_begin_function (tree);
340 static void dbxout_begin_block (unsigned, unsigned);
341 static void dbxout_end_block (unsigned, unsigned);
342 static void dbxout_function_decl (tree);
344 const struct gcc_debug_hooks dbx_debug_hooks =
346 dbxout_init,
347 dbxout_finish,
348 debug_nothing_void,
349 debug_nothing_int_charstar,
350 debug_nothing_int_charstar,
351 dbxout_start_source_file,
352 dbxout_end_source_file,
353 dbxout_begin_block,
354 dbxout_end_block,
355 debug_true_const_tree, /* ignore_block */
356 dbxout_source_line, /* source_line */
357 dbxout_begin_prologue, /* begin_prologue */
358 debug_nothing_int_charstar, /* end_prologue */
359 debug_nothing_int_charstar, /* begin_epilogue */
360 debug_nothing_int_charstar, /* end_epilogue */
361 #ifdef DBX_FUNCTION_FIRST
362 dbxout_begin_function,
363 #else
364 debug_nothing_tree, /* begin_function */
365 #endif
366 debug_nothing_int, /* end_function */
367 dbxout_function_decl,
368 dbxout_global_decl, /* global_decl */
369 dbxout_type_decl, /* type_decl */
370 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
371 debug_nothing_tree, /* deferred_inline_function */
372 debug_nothing_tree, /* outlining_inline_function */
373 debug_nothing_rtx, /* label */
374 dbxout_handle_pch, /* handle_pch */
375 debug_nothing_rtx, /* var_location */
376 debug_nothing_void, /* switch_text_section */
377 debug_nothing_tree_tree, /* set_name */
378 0, /* start_end_main_source_file */
379 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
381 #endif /* DBX_DEBUGGING_INFO */
383 #if defined (XCOFF_DEBUGGING_INFO)
384 const struct gcc_debug_hooks xcoff_debug_hooks =
386 dbxout_init,
387 dbxout_finish,
388 debug_nothing_void,
389 debug_nothing_int_charstar,
390 debug_nothing_int_charstar,
391 dbxout_start_source_file,
392 dbxout_end_source_file,
393 xcoffout_begin_block,
394 xcoffout_end_block,
395 debug_true_const_tree, /* ignore_block */
396 xcoffout_source_line,
397 xcoffout_begin_prologue, /* begin_prologue */
398 debug_nothing_int_charstar, /* end_prologue */
399 debug_nothing_int_charstar, /* begin_epilogue */
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_tree_bool, /* 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 */
412 debug_nothing_void, /* switch_text_section */
413 debug_nothing_tree_tree, /* set_name */
414 0, /* start_end_main_source_file */
415 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
417 #endif /* XCOFF_DEBUGGING_INFO */
419 /* Numeric formatting helper macro. Note that this does not handle
420 hexadecimal. */
421 #define NUMBER_FMT_LOOP(P, NUM, BASE) \
422 do \
424 int digit = NUM % BASE; \
425 NUM /= BASE; \
426 *--P = digit + '0'; \
428 while (NUM > 0)
430 /* Utility: write a decimal integer NUM to asm_out_file. */
431 void
432 dbxout_int (int num)
434 char buf[64];
435 char *p = buf + sizeof buf;
436 unsigned int unum;
438 if (num == 0)
440 putc ('0', asm_out_file);
441 return;
443 if (num < 0)
445 putc ('-', asm_out_file);
446 unum = -num;
448 else
449 unum = num;
451 NUMBER_FMT_LOOP (p, unum, 10);
453 while (p < buf + sizeof buf)
455 putc (*p, asm_out_file);
456 p++;
461 /* Primitives for emitting simple stabs directives. All other stabs
462 routines should use these functions instead of directly emitting
463 stabs. They are exported because machine-dependent code may need
464 to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
465 forwards to code in CPU.c. */
467 /* The following functions should all be called immediately after one
468 of the dbxout_begin_stab* functions (below). They write out
469 various things as the value of a stab. */
471 /* Write out a literal zero as the value of a stab. */
472 void
473 dbxout_stab_value_zero (void)
475 fputs ("0\n", asm_out_file);
478 /* Write out the label LABEL as the value of a stab. */
479 void
480 dbxout_stab_value_label (const char *label)
482 assemble_name (asm_out_file, label);
483 putc ('\n', asm_out_file);
486 /* Write out the difference of two labels, LABEL - BASE, as the value
487 of a stab. */
488 void
489 dbxout_stab_value_label_diff (const char *label, const char *base)
491 assemble_name (asm_out_file, label);
492 putc ('-', asm_out_file);
493 assemble_name (asm_out_file, base);
494 putc ('\n', asm_out_file);
497 /* Write out an internal label as the value of a stab, and immediately
498 emit that internal label. This should be used only when
499 dbxout_stabd will not work. STEM is the name stem of the label,
500 COUNTERP is a pointer to a counter variable which will be used to
501 guarantee label uniqueness. */
502 void
503 dbxout_stab_value_internal_label (const char *stem, int *counterp)
505 char label[100];
506 int counter = counterp ? (*counterp)++ : 0;
508 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
509 dbxout_stab_value_label (label);
510 targetm.asm_out.internal_label (asm_out_file, stem, counter);
513 /* Write out the difference between BASE and an internal label as the
514 value of a stab, and immediately emit that internal label. STEM and
515 COUNTERP are as for dbxout_stab_value_internal_label. */
516 void
517 dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
518 const char *base)
520 char label[100];
521 int counter = counterp ? (*counterp)++ : 0;
523 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
524 dbxout_stab_value_label_diff (label, base);
525 targetm.asm_out.internal_label (asm_out_file, stem, counter);
528 /* The following functions produce specific kinds of stab directives. */
530 /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
531 void
532 dbxout_stabd (int stype, int sdesc)
534 fputs (ASM_STABD_OP, asm_out_file);
535 dbxout_int (stype);
536 fputs (",0,", asm_out_file);
537 dbxout_int (sdesc);
538 putc ('\n', asm_out_file);
541 /* Write a .stabn directive with type STYPE. This function stops
542 short of emitting the value field, which is the responsibility of
543 the caller (normally it will be either a symbol or the difference
544 of two symbols). */
546 void
547 dbxout_begin_stabn (int stype)
549 fputs (ASM_STABN_OP, asm_out_file);
550 dbxout_int (stype);
551 fputs (",0,0,", asm_out_file);
554 /* Write a .stabn directive with type N_SLINE and desc LINE. As above,
555 the value field is the responsibility of the caller. */
556 void
557 dbxout_begin_stabn_sline (int lineno)
559 fputs (ASM_STABN_OP, asm_out_file);
560 dbxout_int (N_SLINE);
561 fputs (",0,", asm_out_file);
562 dbxout_int (lineno);
563 putc (',', asm_out_file);
566 /* Begin a .stabs directive with string "", type STYPE, and desc and
567 other fields 0. The value field is the responsibility of the
568 caller. This function cannot be used for .stabx directives. */
569 void
570 dbxout_begin_empty_stabs (int stype)
572 fputs (ASM_STABS_OP, asm_out_file);
573 fputs ("\"\",", asm_out_file);
574 dbxout_int (stype);
575 fputs (",0,0,", asm_out_file);
578 /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
579 The value field is the responsibility of the caller. */
580 void
581 dbxout_begin_simple_stabs (const char *str, int stype)
583 fputs (ASM_STABS_OP, asm_out_file);
584 output_quoted_string (asm_out_file, str);
585 putc (',', asm_out_file);
586 dbxout_int (stype);
587 fputs (",0,0,", asm_out_file);
590 /* As above but use SDESC for the desc field. */
591 void
592 dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
594 fputs (ASM_STABS_OP, asm_out_file);
595 output_quoted_string (asm_out_file, str);
596 putc (',', asm_out_file);
597 dbxout_int (stype);
598 fputs (",0,", asm_out_file);
599 dbxout_int (sdesc);
600 putc (',', asm_out_file);
603 /* The next set of functions are entirely concerned with production of
604 "complex" .stabs directives: that is, .stabs directives whose
605 strings have to be constructed piecemeal. dbxout_type,
606 dbxout_symbol, etc. use these routines heavily. The string is queued
607 up in an obstack, then written out by dbxout_finish_complex_stabs, which
608 is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
609 (You might think it would be more efficient to go straight to stdio
610 when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
611 out not to be the case, and anyway this needs fewer #ifdefs.) */
613 /* Begin a complex .stabs directive. If we can, write the initial
614 ASM_STABS_OP to the asm_out_file. */
616 static void
617 dbxout_begin_complex_stabs (void)
619 emit_pending_bincls_if_required ();
620 FORCE_TEXT;
621 fputs (ASM_STABS_OP, asm_out_file);
622 putc ('"', asm_out_file);
623 gcc_assert (stabstr_last_contin_point == 0);
626 /* As above, but do not force text or emit pending bincls. This is
627 used by dbxout_symbol_location, which needs to do something else. */
628 static void
629 dbxout_begin_complex_stabs_noforcetext (void)
631 fputs (ASM_STABS_OP, asm_out_file);
632 putc ('"', asm_out_file);
633 gcc_assert (stabstr_last_contin_point == 0);
636 /* Add CHR, a single character, to the string being built. */
637 #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
639 /* Add STR, a normal C string, to the string being built. */
640 #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen(str))
642 /* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
643 #define stabstr_I(id) obstack_grow (&stabstr_ob, \
644 IDENTIFIER_POINTER (id), \
645 IDENTIFIER_LENGTH (id))
647 /* Add NUM, a signed decimal number, to the string being built. */
648 static void
649 stabstr_D (HOST_WIDE_INT num)
651 char buf[64];
652 char *p = buf + sizeof buf;
653 unsigned int unum;
655 if (num == 0)
657 stabstr_C ('0');
658 return;
660 if (num < 0)
662 stabstr_C ('-');
663 unum = -num;
665 else
666 unum = num;
668 NUMBER_FMT_LOOP (p, unum, 10);
670 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
673 /* Add NUM, an unsigned decimal number, to the string being built. */
674 static void
675 stabstr_U (unsigned HOST_WIDE_INT num)
677 char buf[64];
678 char *p = buf + sizeof buf;
679 if (num == 0)
681 stabstr_C ('0');
682 return;
684 NUMBER_FMT_LOOP (p, num, 10);
685 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
688 /* Add CST, an INTEGER_CST tree, to the string being built as an
689 unsigned octal number. This routine handles values which are
690 larger than a single HOST_WIDE_INT. */
691 static void
692 stabstr_O (tree cst)
694 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (cst);
695 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
697 char buf[128];
698 char *p = buf + sizeof buf;
700 /* GDB wants constants with no extra leading "1" bits, so
701 we need to remove any sign-extension that might be
702 present. */
704 const unsigned int width = TYPE_PRECISION (TREE_TYPE (cst));
705 if (width == HOST_BITS_PER_WIDE_INT * 2)
707 else if (width > HOST_BITS_PER_WIDE_INT)
708 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
709 else if (width == HOST_BITS_PER_WIDE_INT)
710 high = 0;
711 else
712 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
715 /* Leading zero for base indicator. */
716 stabstr_C ('0');
718 /* If the value is zero, the base indicator will serve as the value
719 all by itself. */
720 if (high == 0 && low == 0)
721 return;
723 /* If the high half is zero, we need only print the low half normally. */
724 if (high == 0)
725 NUMBER_FMT_LOOP (p, low, 8);
726 else
728 /* When high != 0, we need to print enough zeroes from low to
729 give the digits from high their proper place-values. Hence
730 NUMBER_FMT_LOOP cannot be used. */
731 const int n_digits = HOST_BITS_PER_WIDE_INT / 3;
732 int i;
734 for (i = 1; i <= n_digits; i++)
736 unsigned int digit = low % 8;
737 low /= 8;
738 *--p = '0' + digit;
741 /* Octal digits carry exactly three bits of information. The
742 width of a HOST_WIDE_INT is not normally a multiple of three.
743 Therefore, the next digit printed probably needs to carry
744 information from both low and high. */
745 if (HOST_BITS_PER_WIDE_INT % 3 != 0)
747 const int n_leftover_bits = HOST_BITS_PER_WIDE_INT % 3;
748 const int n_bits_from_high = 3 - n_leftover_bits;
750 const unsigned HOST_WIDE_INT
751 low_mask = (((unsigned HOST_WIDE_INT)1) << n_leftover_bits) - 1;
752 const unsigned HOST_WIDE_INT
753 high_mask = (((unsigned HOST_WIDE_INT)1) << n_bits_from_high) - 1;
755 unsigned int digit;
757 /* At this point, only the bottom n_leftover_bits bits of low
758 should be set. */
759 gcc_assert (!(low & ~low_mask));
761 digit = (low | ((high & high_mask) << n_leftover_bits));
762 high >>= n_bits_from_high;
764 *--p = '0' + digit;
767 /* Now we can format high in the normal manner. However, if
768 the only bits of high that were set were handled by the
769 digit split between low and high, high will now be zero, and
770 we don't want to print extra digits in that case. */
771 if (high)
772 NUMBER_FMT_LOOP (p, high, 8);
775 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
778 /* Called whenever it is safe to break a stabs string into multiple
779 .stabs directives. If the current string has exceeded the limit
780 set by DBX_CONTIN_LENGTH, mark the current position in the buffer
781 as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
782 it is a backslash) and a null character. */
783 static inline void
784 stabstr_continue (void)
786 if (DBX_CONTIN_LENGTH > 0
787 && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
788 > DBX_CONTIN_LENGTH)
790 if (DBX_CONTIN_CHAR == '\\')
791 obstack_1grow (&stabstr_ob, '\\');
792 obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
793 obstack_1grow (&stabstr_ob, '\0');
794 stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
797 #define CONTIN stabstr_continue ()
799 /* Macro subroutine of dbxout_finish_complex_stabs, which emits
800 all of the arguments to the .stabs directive after the string.
801 Overridden by xcoffout.h. CODE is the stabs code for this symbol;
802 LINE is the source line to write into the desc field (in extended
803 mode); SYM is the symbol itself.
805 ADDR, LABEL, and NUMBER are three different ways to represent the
806 stabs value field. At most one of these should be nonzero.
808 ADDR is used most of the time; it represents the value as an
809 RTL address constant.
811 LABEL is used (currently) only for N_CATCH stabs; it represents
812 the value as a string suitable for assemble_name.
814 NUMBER is used when the value is an offset from an implicit base
815 pointer (e.g. for a stack variable), or an index (e.g. for a
816 register variable). It represents the value as a decimal integer. */
818 #ifndef DBX_FINISH_STABS
819 #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \
820 do { \
821 int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
823 dbxout_int (CODE); \
824 fputs (",0,", asm_out_file); \
825 dbxout_int (line_); \
826 putc (',', asm_out_file); \
827 if (ADDR) \
828 output_addr_const (asm_out_file, ADDR); \
829 else if (LABEL) \
830 assemble_name (asm_out_file, LABEL); \
831 else \
832 dbxout_int (NUMBER); \
833 putc ('\n', asm_out_file); \
834 } while (0)
835 #endif
837 /* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
838 is zero, this has only to emit the close quote and the remainder of
839 the arguments. When it is nonzero, the string has been marshalled in
840 stabstr_ob, and this routine is responsible for breaking it up into
841 DBX_CONTIN_LENGTH-sized chunks.
843 SYM is the DECL of the symbol under consideration; it is used only
844 for its DECL_SOURCE_LINE. The other arguments are all passed directly
845 to DBX_FINISH_STABS; see above for details. */
847 static void
848 dbxout_finish_complex_stabs (tree sym, stab_code_type code,
849 rtx addr, const char *label, int number)
851 int line ATTRIBUTE_UNUSED;
852 char *str;
853 size_t len;
855 line = sym ? DECL_SOURCE_LINE (sym) : 0;
856 if (DBX_CONTIN_LENGTH > 0)
858 char *chunk;
859 size_t chunklen;
861 /* Nul-terminate the growing string, then get its size and
862 address. */
863 obstack_1grow (&stabstr_ob, '\0');
865 len = obstack_object_size (&stabstr_ob);
866 chunk = str = XOBFINISH (&stabstr_ob, char *);
868 /* Within the buffer are a sequence of NUL-separated strings,
869 each of which is to be written out as a separate stab
870 directive. */
871 for (;;)
873 chunklen = strlen (chunk);
874 fwrite (chunk, 1, chunklen, asm_out_file);
875 fputs ("\",", asm_out_file);
877 /* Must add an extra byte to account for the NUL separator. */
878 chunk += chunklen + 1;
879 len -= chunklen + 1;
881 /* Only put a line number on the last stab in the sequence. */
882 DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
883 addr, label, number);
884 if (len == 0)
885 break;
887 fputs (ASM_STABS_OP, asm_out_file);
888 putc ('"', asm_out_file);
890 stabstr_last_contin_point = 0;
892 else
894 /* No continuations - we can put the whole string out at once.
895 It is faster to augment the string with the close quote and
896 comma than to do a two-character fputs. */
897 obstack_grow (&stabstr_ob, "\",", 2);
898 len = obstack_object_size (&stabstr_ob);
899 str = XOBFINISH (&stabstr_ob, char *);
901 fwrite (str, 1, len, asm_out_file);
902 DBX_FINISH_STABS (sym, code, line, addr, label, number);
904 obstack_free (&stabstr_ob, str);
907 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
909 /* When -gused is used, emit debug info for only used symbols. But in
910 addition to the standard intercepted debug_hooks there are some
911 direct calls into this file, i.e., dbxout_symbol, dbxout_parms, and
912 dbxout_reg_params. Those routines may also be called from a higher
913 level intercepted routine. So to prevent recording data for an inner
914 call to one of these for an intercept, we maintain an intercept
915 nesting counter (debug_nesting). We only save the intercepted
916 arguments if the nesting is 1. */
917 static int debug_nesting = 0;
919 static tree *symbol_queue;
920 static int symbol_queue_index = 0;
921 static int symbol_queue_size = 0;
923 #define DBXOUT_DECR_NESTING \
924 if (--debug_nesting == 0 && symbol_queue_index > 0) \
925 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
927 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
928 do {--debug_nesting; return (x);} while (0)
930 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
932 #if defined (DBX_DEBUGGING_INFO)
934 static void
935 dbxout_function_end (tree decl ATTRIBUTE_UNUSED)
937 char lscope_label_name[100];
939 /* The Lscope label must be emitted even if we aren't doing anything
940 else; dbxout_block needs it. */
941 switch_to_section (function_section (current_function_decl));
943 /* Convert Lscope into the appropriate format for local labels in case
944 the system doesn't insert underscores in front of user generated
945 labels. */
946 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
947 targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
949 /* The N_FUN tag at the end of the function is a GNU extension,
950 which may be undesirable, and is unnecessary if we do not have
951 named sections. */
952 if (!use_gnu_debug_info_extensions
953 || NO_DBX_FUNCTION_END
954 || !targetm.have_named_sections)
955 return;
957 /* By convention, GCC will mark the end of a function with an N_FUN
958 symbol and an empty string. */
959 if (flag_reorder_blocks_and_partition)
961 dbxout_begin_empty_stabs (N_FUN);
962 dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label,
963 crtl->subsections.hot_section_label);
964 dbxout_begin_empty_stabs (N_FUN);
965 dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label,
966 crtl->subsections.cold_section_label);
968 else
970 char begin_label[20];
971 /* Reference current function start using LFBB. */
972 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
973 dbxout_begin_empty_stabs (N_FUN);
974 dbxout_stab_value_label_diff (lscope_label_name, begin_label);
977 if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
978 dbxout_stabd (N_ENSYM, 0);
980 #endif /* DBX_DEBUGGING_INFO */
982 /* Get lang description for N_SO stab. */
983 static unsigned int ATTRIBUTE_UNUSED
984 get_lang_number (void)
986 const char *language_string = lang_hooks.name;
988 if (strcmp (language_string, "GNU C") == 0)
989 return N_SO_C;
990 else if (strcmp (language_string, "GNU C++") == 0)
991 return N_SO_CC;
992 else if (strcmp (language_string, "GNU F77") == 0)
993 return N_SO_FORTRAN;
994 else if (strcmp (language_string, "GNU Fortran") == 0)
995 return N_SO_FORTRAN90; /* CHECKME */
996 else if (strcmp (language_string, "GNU Pascal") == 0)
997 return N_SO_PASCAL;
998 else if (strcmp (language_string, "GNU Objective-C") == 0)
999 return N_SO_OBJC;
1000 else if (strcmp (language_string, "GNU Objective-C++") == 0)
1001 return N_SO_OBJCPLUS;
1002 else
1003 return 0;
1007 static bool
1008 is_fortran (void)
1010 unsigned int lang = get_lang_number ();
1012 return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90);
1015 /* At the beginning of compilation, start writing the symbol table.
1016 Initialize `typevec' and output the standard data types of C. */
1018 static void
1019 dbxout_init (const char *input_file_name)
1021 char ltext_label_name[100];
1022 bool used_ltext_label_name = false;
1023 tree syms = lang_hooks.decls.getdecls ();
1024 const char *mapped_name;
1026 typevec_len = 100;
1027 typevec = ggc_alloc_cleared_vec_typeinfo (typevec_len);
1029 /* stabstr_ob contains one string, which will be just fine with
1030 1-byte alignment. */
1031 obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
1033 /* Convert Ltext into the appropriate format for local labels in case
1034 the system doesn't insert underscores in front of user generated
1035 labels. */
1036 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
1038 /* Put the current working directory in an N_SO symbol. */
1039 if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
1041 static const char *cwd;
1043 if (!cwd)
1045 cwd = get_src_pwd ();
1046 if (cwd[0] == '\0')
1047 cwd = "/";
1048 else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
1049 cwd = concat (cwd, "/", NULL);
1050 cwd = remap_debug_filename (cwd);
1052 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
1053 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
1054 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1055 dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
1056 dbxout_stab_value_label (ltext_label_name);
1057 used_ltext_label_name = true;
1058 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1061 mapped_name = remap_debug_filename (input_file_name);
1062 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1063 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, mapped_name);
1064 #else
1065 dbxout_begin_simple_stabs_desc (mapped_name, N_SO, get_lang_number ());
1066 dbxout_stab_value_label (ltext_label_name);
1067 used_ltext_label_name = true;
1068 #endif
1070 if (used_ltext_label_name)
1072 switch_to_section (text_section);
1073 targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1076 /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1077 The string used is historical. */
1078 #ifndef NO_DBX_GCC_MARKER
1079 dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1080 dbxout_stab_value_zero ();
1081 #endif
1083 base_input_file = lastfile = input_file_name;
1085 next_type_number = 1;
1087 #ifdef DBX_USE_BINCL
1088 current_file = XNEW (struct dbx_file);
1089 current_file->next = NULL;
1090 current_file->file_number = 0;
1091 current_file->next_type_number = 1;
1092 next_file_number = 1;
1093 current_file->prev = NULL;
1094 current_file->bincl_status = BINCL_NOT_REQUIRED;
1095 current_file->pending_bincl_name = NULL;
1096 #endif
1098 /* Get all permanent types that have typedef names, and output them
1099 all, except for those already output. Some language front ends
1100 put these declarations in the top-level scope; some do not;
1101 the latter are responsible for calling debug_hooks->type_decl from
1102 their record_builtin_type function. */
1103 dbxout_typedefs (syms);
1105 if (preinit_symbols)
1107 tree t;
1108 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1109 dbxout_symbol (TREE_VALUE (t), 0);
1110 preinit_symbols = 0;
1114 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
1116 static void
1117 dbxout_typedefs (tree syms)
1119 for (; syms != NULL_TREE; syms = DECL_CHAIN (syms))
1121 if (TREE_CODE (syms) == TYPE_DECL)
1123 tree type = TREE_TYPE (syms);
1124 if (TYPE_NAME (type)
1125 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1126 && COMPLETE_OR_VOID_TYPE_P (type)
1127 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
1128 dbxout_symbol (TYPE_NAME (type), 0);
1133 #ifdef DBX_USE_BINCL
1134 /* Emit BINCL stab using given name. */
1135 static void
1136 emit_bincl_stab (const char *name)
1138 dbxout_begin_simple_stabs (name, N_BINCL);
1139 dbxout_stab_value_zero ();
1142 /* If there are pending bincls then it is time to emit all of them. */
1144 static inline void
1145 emit_pending_bincls_if_required (void)
1147 if (pending_bincls)
1148 emit_pending_bincls ();
1151 /* Emit all pending bincls. */
1153 static void
1154 emit_pending_bincls (void)
1156 struct dbx_file *f = current_file;
1158 /* Find first pending bincl. */
1159 while (f->bincl_status == BINCL_PENDING)
1160 f = f->next;
1162 /* Now emit all bincls. */
1163 f = f->prev;
1165 while (f)
1167 if (f->bincl_status == BINCL_PENDING)
1169 emit_bincl_stab (f->pending_bincl_name);
1171 /* Update file number and status. */
1172 f->file_number = next_file_number++;
1173 f->bincl_status = BINCL_PROCESSED;
1175 if (f == current_file)
1176 break;
1177 f = f->prev;
1180 /* All pending bincls have been emitted. */
1181 pending_bincls = 0;
1184 #else
1186 static inline void
1187 emit_pending_bincls_if_required (void) {}
1188 #endif
1190 /* Change to reading from a new source file. Generate a N_BINCL stab. */
1192 static void
1193 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1194 const char *filename ATTRIBUTE_UNUSED)
1196 #ifdef DBX_USE_BINCL
1197 struct dbx_file *n = XNEW (struct dbx_file);
1199 n->next = current_file;
1200 n->next_type_number = 1;
1201 /* Do not assign file number now.
1202 Delay it until we actually emit BINCL. */
1203 n->file_number = 0;
1204 n->prev = NULL;
1205 current_file->prev = n;
1206 n->bincl_status = BINCL_PENDING;
1207 n->pending_bincl_name = remap_debug_filename (filename);
1208 pending_bincls = 1;
1209 current_file = n;
1210 #endif
1213 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
1215 static void
1216 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1218 #ifdef DBX_USE_BINCL
1219 /* Emit EINCL stab only if BINCL is not pending. */
1220 if (current_file->bincl_status == BINCL_PROCESSED)
1222 dbxout_begin_stabn (N_EINCL);
1223 dbxout_stab_value_zero ();
1225 current_file->bincl_status = BINCL_NOT_REQUIRED;
1226 current_file = current_file->next;
1227 #endif
1230 /* Handle a few odd cases that occur when trying to make PCH files work. */
1232 static void
1233 dbxout_handle_pch (unsigned at_end)
1235 if (! at_end)
1237 /* When using the PCH, this file will be included, so we need to output
1238 a BINCL. */
1239 dbxout_start_source_file (0, lastfile);
1241 /* The base file when using the PCH won't be the same as
1242 the base file when it's being generated. */
1243 lastfile = NULL;
1245 else
1247 /* ... and an EINCL. */
1248 dbxout_end_source_file (0);
1250 /* Deal with cases where 'lastfile' was never actually changed. */
1251 lastfile_is_base = lastfile == NULL;
1255 #if defined (DBX_DEBUGGING_INFO)
1257 static void dbxout_block (tree, int, tree);
1259 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
1261 static void
1262 dbxout_source_file (const char *filename)
1264 if (lastfile == 0 && lastfile_is_base)
1266 lastfile = base_input_file;
1267 lastfile_is_base = 0;
1270 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
1272 /* Don't change section amid function. */
1273 if (current_function_decl == NULL_TREE)
1274 switch_to_section (text_section);
1276 dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL);
1277 dbxout_stab_value_internal_label ("Ltext", &source_label_number);
1278 lastfile = filename;
1282 /* Output N_BNSYM, line number symbol entry, and local symbol at
1283 function scope */
1285 static void
1286 dbxout_begin_prologue (unsigned int lineno, const char *filename)
1288 if (use_gnu_debug_info_extensions
1289 && !NO_DBX_FUNCTION_END
1290 && !NO_DBX_BNSYM_ENSYM
1291 && !flag_debug_only_used_symbols)
1292 dbxout_stabd (N_BNSYM, 0);
1294 /* pre-increment the scope counter */
1295 scope_labelno++;
1297 dbxout_source_line (lineno, filename, 0, true);
1298 /* Output function begin block at function scope, referenced
1299 by dbxout_block, dbxout_source_line and dbxout_function_end. */
1300 emit_pending_bincls_if_required ();
1301 targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno);
1304 /* Output a line number symbol entry for source file FILENAME and line
1305 number LINENO. */
1307 static void
1308 dbxout_source_line (unsigned int lineno, const char *filename,
1309 int discriminator ATTRIBUTE_UNUSED,
1310 bool is_stmt ATTRIBUTE_UNUSED)
1312 dbxout_source_file (filename);
1314 #ifdef DBX_OUTPUT_SOURCE_LINE
1315 DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
1316 #else
1317 if (DBX_LINES_FUNCTION_RELATIVE)
1319 char begin_label[20];
1320 dbxout_begin_stabn_sline (lineno);
1321 /* Reference current function start using LFBB. */
1322 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
1323 dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
1324 begin_label);
1326 else
1327 dbxout_stabd (N_SLINE, lineno);
1328 #endif
1331 /* Describe the beginning of an internal block within a function. */
1333 static void
1334 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1336 emit_pending_bincls_if_required ();
1337 targetm.asm_out.internal_label (asm_out_file, "LBB", n);
1340 /* Describe the end line-number of an internal block within a function. */
1342 static void
1343 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1345 emit_pending_bincls_if_required ();
1346 targetm.asm_out.internal_label (asm_out_file, "LBE", n);
1349 /* Output dbx data for a function definition.
1350 This includes a definition of the function name itself (a symbol),
1351 definitions of the parameters (locating them in the parameter list)
1352 and then output the block that makes up the function's body
1353 (including all the auto variables of the function). */
1355 static void
1356 dbxout_function_decl (tree decl)
1358 emit_pending_bincls_if_required ();
1359 #ifndef DBX_FUNCTION_FIRST
1360 dbxout_begin_function (decl);
1361 #endif
1362 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1363 dbxout_function_end (decl);
1366 #endif /* DBX_DEBUGGING_INFO */
1368 /* Debug information for a global DECL. Called from toplev.c after
1369 compilation proper has finished. */
1370 static void
1371 dbxout_global_decl (tree decl)
1373 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
1375 int saved_tree_used = TREE_USED (decl);
1376 TREE_USED (decl) = 1;
1377 dbxout_symbol (decl, 0);
1378 TREE_USED (decl) = saved_tree_used;
1382 /* This is just a function-type adapter; dbxout_symbol does exactly
1383 what we want but returns an int. */
1384 static void
1385 dbxout_type_decl (tree decl, int local)
1387 dbxout_symbol (decl, local);
1390 /* At the end of compilation, finish writing the symbol table.
1391 The default is to call debug_free_queue but do nothing else. */
1393 static void
1394 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
1396 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1397 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1398 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1400 switch_to_section (text_section);
1401 dbxout_begin_empty_stabs (N_SO);
1402 dbxout_stab_value_internal_label ("Letext", 0);
1404 #endif
1405 debug_free_queue ();
1408 /* Output the index of a type. */
1410 static void
1411 dbxout_type_index (tree type)
1413 #ifndef DBX_USE_BINCL
1414 stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1415 #else
1416 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1417 stabstr_C ('(');
1418 stabstr_D (t->file_number);
1419 stabstr_C (',');
1420 stabstr_D (t->type_number);
1421 stabstr_C (')');
1422 #endif
1426 /* Generate the symbols for any queued up type symbols we encountered
1427 while generating the type info for some originally used symbol.
1428 This might generate additional entries in the queue. Only when
1429 the nesting depth goes to 0 is this routine called. */
1431 static void
1432 debug_flush_symbol_queue (void)
1434 int i;
1436 /* Make sure that additionally queued items are not flushed
1437 prematurely. */
1439 ++debug_nesting;
1441 for (i = 0; i < symbol_queue_index; ++i)
1443 /* If we pushed queued symbols then such symbols must be
1444 output no matter what anyone else says. Specifically,
1445 we need to make sure dbxout_symbol() thinks the symbol was
1446 used and also we need to override TYPE_DECL_SUPPRESS_DEBUG
1447 which may be set for outside reasons. */
1448 int saved_tree_used = TREE_USED (symbol_queue[i]);
1449 int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]);
1450 TREE_USED (symbol_queue[i]) = 1;
1451 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0;
1453 #ifdef DBX_DEBUGGING_INFO
1454 dbxout_symbol (symbol_queue[i], 0);
1455 #endif
1457 TREE_USED (symbol_queue[i]) = saved_tree_used;
1458 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug;
1461 symbol_queue_index = 0;
1462 --debug_nesting;
1465 /* Queue a type symbol needed as part of the definition of a decl
1466 symbol. These symbols are generated when debug_flush_symbol_queue()
1467 is called. */
1469 static void
1470 debug_queue_symbol (tree decl)
1472 if (symbol_queue_index >= symbol_queue_size)
1474 symbol_queue_size += 10;
1475 symbol_queue = XRESIZEVEC (tree, symbol_queue, symbol_queue_size);
1478 symbol_queue[symbol_queue_index++] = decl;
1481 /* Free symbol queue. */
1482 static void
1483 debug_free_queue (void)
1485 if (symbol_queue)
1487 free (symbol_queue);
1488 symbol_queue = NULL;
1489 symbol_queue_size = 0;
1493 /* Used in several places: evaluates to '0' for a private decl,
1494 '1' for a protected decl, '2' for a public decl. */
1495 #define DECL_ACCESSIBILITY_CHAR(DECL) \
1496 (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1498 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
1499 This must be a separate function because anonymous unions require
1500 recursive calls. */
1502 static void
1503 dbxout_type_fields (tree type)
1505 tree tem;
1507 /* Output the name, type, position (in bits), size (in bits) of each
1508 field that we can support. */
1509 for (tem = TYPE_FIELDS (type); tem; tem = DECL_CHAIN (tem))
1511 /* If one of the nodes is an error_mark or its type is then
1512 return early. */
1513 if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
1514 return;
1516 /* Omit here local type decls until we know how to support them. */
1517 if (TREE_CODE (tem) == TYPE_DECL
1518 /* Omit here the nameless fields that are used to skip bits. */
1519 || DECL_IGNORED_P (tem)
1520 /* Omit fields whose position or size are variable or too large to
1521 represent. */
1522 || (TREE_CODE (tem) == FIELD_DECL
1523 && (! host_integerp (bit_position (tem), 0)
1524 || ! DECL_SIZE (tem)
1525 || ! host_integerp (DECL_SIZE (tem), 1))))
1526 continue;
1528 else if (TREE_CODE (tem) != CONST_DECL)
1530 /* Continue the line if necessary,
1531 but not before the first field. */
1532 if (tem != TYPE_FIELDS (type))
1533 CONTIN;
1535 if (DECL_NAME (tem))
1536 stabstr_I (DECL_NAME (tem));
1537 stabstr_C (':');
1539 if (use_gnu_debug_info_extensions
1540 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1541 || TREE_CODE (tem) != FIELD_DECL))
1543 stabstr_C ('/');
1544 stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
1547 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
1548 && DECL_BIT_FIELD_TYPE (tem))
1549 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
1551 if (TREE_CODE (tem) == VAR_DECL)
1553 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
1555 tree name = DECL_ASSEMBLER_NAME (tem);
1557 stabstr_C (':');
1558 stabstr_I (name);
1559 stabstr_C (';');
1561 else
1562 /* If TEM is non-static, GDB won't understand it. */
1563 stabstr_S (",0,0;");
1565 else
1567 stabstr_C (',');
1568 stabstr_D (int_bit_position (tem));
1569 stabstr_C (',');
1570 stabstr_D (tree_low_cst (DECL_SIZE (tem), 1));
1571 stabstr_C (';');
1577 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1578 method described DECL. */
1580 static void
1581 dbxout_type_method_1 (tree decl)
1583 char c1 = 'A', c2;
1585 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1586 c2 = '?';
1587 else /* it's a METHOD_TYPE. */
1589 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1590 /* A for normal functions.
1591 B for `const' member functions.
1592 C for `volatile' member functions.
1593 D for `const volatile' member functions. */
1594 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1595 c1 += 1;
1596 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1597 c1 += 2;
1599 if (DECL_VINDEX (decl))
1600 c2 = '*';
1601 else
1602 c2 = '.';
1605 /* ??? Output the mangled name, which contains an encoding of the
1606 method's type signature. May not be necessary anymore. */
1607 stabstr_C (':');
1608 stabstr_I (DECL_ASSEMBLER_NAME (decl));
1609 stabstr_C (';');
1610 stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1611 stabstr_C (c1);
1612 stabstr_C (c2);
1614 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1616 stabstr_D (tree_low_cst (DECL_VINDEX (decl), 0));
1617 stabstr_C (';');
1618 dbxout_type (DECL_CONTEXT (decl), 0);
1619 stabstr_C (';');
1623 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1624 in TYPE. */
1626 static void
1627 dbxout_type_methods (tree type)
1629 /* C++: put out the method names and their parameter lists */
1630 tree methods = TYPE_METHODS (type);
1631 tree fndecl;
1632 tree last;
1634 if (methods == NULL_TREE)
1635 return;
1637 if (TREE_CODE (methods) != TREE_VEC)
1638 fndecl = methods;
1639 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1640 fndecl = TREE_VEC_ELT (methods, 0);
1641 else
1642 fndecl = TREE_VEC_ELT (methods, 1);
1644 while (fndecl)
1646 int need_prefix = 1;
1648 /* Group together all the methods for the same operation.
1649 These differ in the types of the arguments. */
1650 for (last = NULL_TREE;
1651 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1652 fndecl = DECL_CHAIN (fndecl))
1653 /* Output the name of the field (after overloading), as
1654 well as the name of the field before overloading, along
1655 with its parameter list */
1657 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1658 include TEMPLATE_DECLs.) The debugger doesn't know what
1659 to do with such entities anyhow. */
1660 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1661 continue;
1663 CONTIN;
1665 last = fndecl;
1667 /* Also ignore abstract methods; those are only interesting to
1668 the DWARF backends. */
1669 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1670 continue;
1672 /* Redundantly output the plain name, since that's what gdb
1673 expects. */
1674 if (need_prefix)
1676 stabstr_I (DECL_NAME (fndecl));
1677 stabstr_S ("::");
1678 need_prefix = 0;
1681 dbxout_type (TREE_TYPE (fndecl), 0);
1682 dbxout_type_method_1 (fndecl);
1684 if (!need_prefix)
1685 stabstr_C (';');
1689 /* Emit a "range" type specification, which has the form:
1690 "r<index type>;<lower bound>;<upper bound>;".
1691 TYPE is an INTEGER_TYPE, LOW and HIGH are the bounds. */
1693 static void
1694 dbxout_range_type (tree type, tree low, tree high)
1696 stabstr_C ('r');
1697 if (TREE_TYPE (type))
1698 dbxout_type (TREE_TYPE (type), 0);
1699 else if (TREE_CODE (type) != INTEGER_TYPE)
1700 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1701 else
1703 /* Traditionally, we made sure 'int' was type 1, and builtin types
1704 were defined to be sub-ranges of int. Unfortunately, this
1705 does not allow us to distinguish true sub-ranges from integer
1706 types. So, instead we define integer (non-sub-range) types as
1707 sub-ranges of themselves. This matters for Chill. If this isn't
1708 a subrange type, then we want to define it in terms of itself.
1709 However, in C, this may be an anonymous integer type, and we don't
1710 want to emit debug info referring to it. Just calling
1711 dbxout_type_index won't work anyways, because the type hasn't been
1712 defined yet. We make this work for both cases by checked to see
1713 whether this is a defined type, referring to it if it is, and using
1714 'int' otherwise. */
1715 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1716 dbxout_type_index (type);
1717 else
1718 dbxout_type_index (integer_type_node);
1721 stabstr_C (';');
1722 if (low && host_integerp (low, 0))
1724 if (print_int_cst_bounds_in_octal_p (type, low, high))
1725 stabstr_O (low);
1726 else
1727 stabstr_D (tree_low_cst (low, 0));
1729 else
1730 stabstr_C ('0');
1732 stabstr_C (';');
1733 if (high && host_integerp (high, 0))
1735 if (print_int_cst_bounds_in_octal_p (type, low, high))
1736 stabstr_O (high);
1737 else
1738 stabstr_D (tree_low_cst (high, 0));
1739 stabstr_C (';');
1741 else
1742 stabstr_S ("-1;");
1746 /* Output a reference to a type. If the type has not yet been
1747 described in the dbx output, output its definition now.
1748 For a type already defined, just refer to its definition
1749 using the type number.
1751 If FULL is nonzero, and the type has been described only with
1752 a forward-reference, output the definition now.
1753 If FULL is zero in this case, just refer to the forward-reference
1754 using the number previously allocated. */
1756 static void
1757 dbxout_type (tree type, int full)
1759 static int anonymous_type_number = 0;
1760 tree tem, main_variant, low, high;
1762 if (TREE_CODE (type) == INTEGER_TYPE)
1764 if (TREE_TYPE (type) == 0)
1766 low = TYPE_MIN_VALUE (type);
1767 high = TYPE_MAX_VALUE (type);
1770 else if (subrange_type_for_debug_p (type, &low, &high))
1773 /* If this is a subtype that should not be emitted as a subrange type,
1774 use the base type. */
1775 else
1777 type = TREE_TYPE (type);
1778 low = TYPE_MIN_VALUE (type);
1779 high = TYPE_MAX_VALUE (type);
1783 /* If there was an input error and we don't really have a type,
1784 avoid crashing and write something that is at least valid
1785 by assuming `int'. */
1786 if (type == error_mark_node)
1787 type = integer_type_node;
1788 else
1790 if (TYPE_NAME (type)
1791 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1792 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1793 full = 0;
1796 /* Try to find the "main variant" with the same name. */
1797 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1798 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1799 main_variant = TREE_TYPE (TYPE_NAME (type));
1800 else
1801 main_variant = TYPE_MAIN_VARIANT (type);
1803 /* If we are not using extensions, stabs does not distinguish const and
1804 volatile, so there is no need to make them separate types. */
1805 if (!use_gnu_debug_info_extensions)
1806 type = main_variant;
1808 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1810 /* Type has no dbx number assigned. Assign next available number. */
1811 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1813 /* Make sure type vector is long enough to record about this type. */
1815 if (next_type_number == typevec_len)
1817 typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2);
1818 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1819 typevec_len *= 2;
1822 #ifdef DBX_USE_BINCL
1823 emit_pending_bincls_if_required ();
1824 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1825 = current_file->file_number;
1826 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1827 = current_file->next_type_number++;
1828 #endif
1831 if (flag_debug_only_used_symbols)
1833 if ((TREE_CODE (type) == RECORD_TYPE
1834 || TREE_CODE (type) == UNION_TYPE
1835 || TREE_CODE (type) == QUAL_UNION_TYPE
1836 || TREE_CODE (type) == ENUMERAL_TYPE)
1837 && TYPE_STUB_DECL (type)
1838 && DECL_P (TYPE_STUB_DECL (type))
1839 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1840 debug_queue_symbol (TYPE_STUB_DECL (type));
1841 else if (TYPE_NAME (type)
1842 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1843 debug_queue_symbol (TYPE_NAME (type));
1846 /* Output the number of this type, to refer to it. */
1847 dbxout_type_index (type);
1849 #ifdef DBX_TYPE_DEFINED
1850 if (DBX_TYPE_DEFINED (type))
1851 return;
1852 #endif
1854 /* If this type's definition has been output or is now being output,
1855 that is all. */
1857 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1859 case TYPE_UNSEEN:
1860 break;
1861 case TYPE_XREF:
1862 /* If we have already had a cross reference,
1863 and either that's all we want or that's the best we could do,
1864 don't repeat the cross reference.
1865 Sun dbx crashes if we do. */
1866 if (! full || !COMPLETE_TYPE_P (type)
1867 /* No way in DBX fmt to describe a variable size. */
1868 || ! host_integerp (TYPE_SIZE (type), 1))
1869 return;
1870 break;
1871 case TYPE_DEFINED:
1872 return;
1875 #ifdef DBX_NO_XREFS
1876 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1877 leave the type-number completely undefined rather than output
1878 a cross-reference. If we have already used GNU debug info extensions,
1879 then it is OK to output a cross reference. This is necessary to get
1880 proper C++ debug output. */
1881 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1882 || TREE_CODE (type) == QUAL_UNION_TYPE
1883 || TREE_CODE (type) == ENUMERAL_TYPE)
1884 && ! use_gnu_debug_info_extensions)
1885 /* We must use the same test here as we use twice below when deciding
1886 whether to emit a cross-reference. */
1887 if ((TYPE_NAME (type) != 0
1888 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1889 && DECL_IGNORED_P (TYPE_NAME (type)))
1890 && !full)
1891 || !COMPLETE_TYPE_P (type)
1892 /* No way in DBX fmt to describe a variable size. */
1893 || ! host_integerp (TYPE_SIZE (type), 1))
1895 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1896 return;
1898 #endif
1900 /* Output a definition now. */
1901 stabstr_C ('=');
1903 /* Mark it as defined, so that if it is self-referent
1904 we will not get into an infinite recursion of definitions. */
1906 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1908 /* If this type is a variant of some other, hand off. Types with
1909 different names are usefully distinguished. We only distinguish
1910 cv-qualified types if we're using extensions. */
1911 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1913 stabstr_C ('k');
1914 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1915 return;
1917 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1919 stabstr_C ('B');
1920 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1921 return;
1923 else if (main_variant != TYPE_MAIN_VARIANT (type))
1925 if (flag_debug_only_used_symbols)
1927 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1929 if ((TREE_CODE (orig_type) == RECORD_TYPE
1930 || TREE_CODE (orig_type) == UNION_TYPE
1931 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1932 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1933 && TYPE_STUB_DECL (orig_type)
1934 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1935 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1937 /* 'type' is a typedef; output the type it refers to. */
1938 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1939 return;
1941 /* else continue. */
1943 switch (TREE_CODE (type))
1945 case VOID_TYPE:
1946 case NULLPTR_TYPE:
1947 case LANG_TYPE:
1948 /* For a void type, just define it as itself; i.e., "5=5".
1949 This makes us consider it defined
1950 without saying what it is. The debugger will make it
1951 a void type when the reference is seen, and nothing will
1952 ever override that default. */
1953 dbxout_type_index (type);
1954 break;
1956 case INTEGER_TYPE:
1957 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1959 /* Output the type `char' as a subrange of itself!
1960 I don't understand this definition, just copied it
1961 from the output of pcc.
1962 This used to use `r2' explicitly and we used to
1963 take care to make sure that `char' was type number 2. */
1964 stabstr_C ('r');
1965 dbxout_type_index (type);
1966 stabstr_S (";0;127;");
1969 /* If this is a subtype of another integer type, always prefer to
1970 write it as a subtype. */
1971 else if (TREE_TYPE (type) != 0
1972 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1974 /* If the size is non-standard, say what it is if we can use
1975 GDB extensions. */
1977 if (use_gnu_debug_info_extensions
1978 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1980 stabstr_S ("@s");
1981 stabstr_D (TYPE_PRECISION (type));
1982 stabstr_C (';');
1985 dbxout_range_type (type, low, high);
1988 else
1990 /* If the size is non-standard, say what it is if we can use
1991 GDB extensions. */
1993 if (use_gnu_debug_info_extensions
1994 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1996 stabstr_S ("@s");
1997 stabstr_D (TYPE_PRECISION (type));
1998 stabstr_C (';');
2001 if (print_int_cst_bounds_in_octal_p (type, low, high))
2003 stabstr_C ('r');
2005 /* If this type derives from another type, output type index of
2006 parent type. This is particularly important when parent type
2007 is an enumerated type, because not generating the parent type
2008 index would transform the definition of this enumerated type
2009 into a plain unsigned type. */
2010 if (TREE_TYPE (type) != 0)
2011 dbxout_type_index (TREE_TYPE (type));
2012 else
2013 dbxout_type_index (type);
2015 stabstr_C (';');
2016 stabstr_O (low);
2017 stabstr_C (';');
2018 stabstr_O (high);
2019 stabstr_C (';');
2022 else
2023 /* Output other integer types as subranges of `int'. */
2024 dbxout_range_type (type, low, high);
2027 break;
2029 case REAL_TYPE:
2030 case FIXED_POINT_TYPE:
2031 /* This used to say `r1' and we used to take care
2032 to make sure that `int' was type number 1. */
2033 stabstr_C ('r');
2034 dbxout_type_index (integer_type_node);
2035 stabstr_C (';');
2036 stabstr_D (int_size_in_bytes (type));
2037 stabstr_S (";0;");
2038 break;
2040 case BOOLEAN_TYPE:
2041 if (use_gnu_debug_info_extensions)
2043 stabstr_S ("@s");
2044 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2045 stabstr_S (";-16;");
2047 else /* Define as enumeral type (False, True) */
2048 stabstr_S ("eFalse:0,True:1,;");
2049 break;
2051 case COMPLEX_TYPE:
2052 /* Differs from the REAL_TYPE by its new data type number.
2053 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
2054 codes since gdb doesn't care anyway. */
2056 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
2058 stabstr_S ("R3;");
2059 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
2060 stabstr_S (";0;");
2062 else
2064 /* Output a complex integer type as a structure,
2065 pending some other way to do it. */
2066 stabstr_C ('s');
2067 stabstr_D (int_size_in_bytes (type));
2069 stabstr_S ("real:");
2070 dbxout_type (TREE_TYPE (type), 0);
2071 stabstr_S (",0,");
2072 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2074 stabstr_S (";imag:");
2075 dbxout_type (TREE_TYPE (type), 0);
2076 stabstr_C (',');
2077 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2078 stabstr_C (',');
2079 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2080 stabstr_S (";;");
2082 break;
2084 case ARRAY_TYPE:
2085 /* Make arrays of packed bits look like bitstrings for chill. */
2086 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
2088 stabstr_S ("@s");
2089 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2090 stabstr_S (";@S;S");
2091 dbxout_type (TYPE_DOMAIN (type), 0);
2092 break;
2095 /* Output "a" followed by a range type definition
2096 for the index type of the array
2097 followed by a reference to the target-type.
2098 ar1;0;N;M for a C array of type M and size N+1. */
2099 /* Check if a character string type, which in Chill is
2100 different from an array of characters. */
2101 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
2103 stabstr_S ("@S;");
2105 tem = TYPE_DOMAIN (type);
2106 if (tem == NULL)
2108 stabstr_S ("ar");
2109 dbxout_type_index (integer_type_node);
2110 stabstr_S (";0;-1;");
2112 else
2114 stabstr_C ('a');
2115 dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem));
2118 dbxout_type (TREE_TYPE (type), 0);
2119 break;
2121 case VECTOR_TYPE:
2122 /* Make vectors look like an array. */
2123 if (use_gnu_debug_info_extensions)
2124 stabstr_S ("@V;");
2126 /* Output "a" followed by a range type definition
2127 for the index type of the array
2128 followed by a reference to the target-type.
2129 ar1;0;N;M for a C array of type M and size N+1. */
2130 stabstr_C ('a');
2131 dbxout_range_type (integer_type_node, size_zero_node,
2132 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
2134 dbxout_type (TREE_TYPE (type), 0);
2135 break;
2137 case RECORD_TYPE:
2138 case UNION_TYPE:
2139 case QUAL_UNION_TYPE:
2141 tree binfo = TYPE_BINFO (type);
2143 /* Output a structure type. We must use the same test here as we
2144 use in the DBX_NO_XREFS case above. */
2145 if ((TYPE_NAME (type) != 0
2146 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2147 && DECL_IGNORED_P (TYPE_NAME (type)))
2148 && !full)
2149 || !COMPLETE_TYPE_P (type)
2150 /* No way in DBX fmt to describe a variable size. */
2151 || ! host_integerp (TYPE_SIZE (type), 1))
2153 /* If the type is just a cross reference, output one
2154 and mark the type as partially described.
2155 If it later becomes defined, we will output
2156 its real definition.
2157 If the type has a name, don't nest its definition within
2158 another type's definition; instead, output an xref
2159 and let the definition come when the name is defined. */
2160 stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2161 if (TYPE_NAME (type) != 0
2162 /* The C frontend creates for anonymous variable length
2163 records/unions TYPE_NAME with DECL_NAME NULL. */
2164 && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
2165 || DECL_NAME (TYPE_NAME (type))))
2166 dbxout_type_name (type);
2167 else
2169 stabstr_S ("$$");
2170 stabstr_D (anonymous_type_number++);
2173 stabstr_C (':');
2174 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2175 break;
2178 /* Identify record or union, and print its size. */
2179 stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2180 stabstr_D (int_size_in_bytes (type));
2182 if (binfo)
2184 int i;
2185 tree child;
2186 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
2188 if (use_gnu_debug_info_extensions)
2190 if (BINFO_N_BASE_BINFOS (binfo))
2192 stabstr_C ('!');
2193 stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2194 stabstr_C (',');
2197 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2199 tree access = (accesses ? VEC_index (tree, accesses, i)
2200 : access_public_node);
2202 if (use_gnu_debug_info_extensions)
2204 stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2205 stabstr_C (access == access_public_node ? '2' :
2206 access == access_protected_node
2207 ? '1' :'0');
2208 if (BINFO_VIRTUAL_P (child)
2209 && (strcmp (lang_hooks.name, "GNU C++") == 0
2210 || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
2211 /* For a virtual base, print the (negative)
2212 offset within the vtable where we must look
2213 to find the necessary adjustment. */
2214 stabstr_D
2215 (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2216 * BITS_PER_UNIT);
2217 else
2218 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2219 * BITS_PER_UNIT);
2220 stabstr_C (',');
2221 dbxout_type (BINFO_TYPE (child), 0);
2222 stabstr_C (';');
2224 else
2226 /* Print out the base class information with
2227 fields which have the same names at the types
2228 they hold. */
2229 dbxout_type_name (BINFO_TYPE (child));
2230 stabstr_C (':');
2231 dbxout_type (BINFO_TYPE (child), full);
2232 stabstr_C (',');
2233 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2234 * BITS_PER_UNIT);
2235 stabstr_C (',');
2236 stabstr_D
2237 (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2238 * BITS_PER_UNIT);
2239 stabstr_C (';');
2245 /* Write out the field declarations. */
2246 dbxout_type_fields (type);
2247 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2249 dbxout_type_methods (type);
2252 stabstr_C (';');
2254 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2255 /* Avoid the ~ if we don't really need it--it confuses dbx. */
2256 && TYPE_VFIELD (type))
2259 /* We need to write out info about what field this class
2260 uses as its "main" vtable pointer field, because if this
2261 field is inherited from a base class, GDB cannot necessarily
2262 figure out which field it's using in time. */
2263 stabstr_S ("~%");
2264 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2265 stabstr_C (';');
2267 break;
2269 case ENUMERAL_TYPE:
2270 /* We must use the same test here as we use in the DBX_NO_XREFS case
2271 above. We simplify it a bit since an enum will never have a variable
2272 size. */
2273 if ((TYPE_NAME (type) != 0
2274 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2275 && DECL_IGNORED_P (TYPE_NAME (type)))
2276 && !full)
2277 || !COMPLETE_TYPE_P (type))
2279 stabstr_S ("xe");
2280 dbxout_type_name (type);
2281 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2282 stabstr_C (':');
2283 return;
2285 if (use_gnu_debug_info_extensions
2286 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2288 stabstr_S ("@s");
2289 stabstr_D (TYPE_PRECISION (type));
2290 stabstr_C (';');
2293 stabstr_C ('e');
2294 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2296 tree value = TREE_VALUE (tem);
2298 stabstr_I (TREE_PURPOSE (tem));
2299 stabstr_C (':');
2301 if (TREE_CODE (value) == CONST_DECL)
2302 value = DECL_INITIAL (value);
2304 if (TREE_INT_CST_HIGH (value) == 0)
2305 stabstr_D (TREE_INT_CST_LOW (value));
2306 else if (TREE_INT_CST_HIGH (value) == -1
2307 && (HOST_WIDE_INT) TREE_INT_CST_LOW (value) < 0)
2308 stabstr_D (TREE_INT_CST_LOW (value));
2309 else
2310 stabstr_O (value);
2312 stabstr_C (',');
2313 if (TREE_CHAIN (tem) != 0)
2314 CONTIN;
2317 stabstr_C (';');
2318 break;
2320 case POINTER_TYPE:
2321 stabstr_C ('*');
2322 dbxout_type (TREE_TYPE (type), 0);
2323 break;
2325 case METHOD_TYPE:
2326 if (use_gnu_debug_info_extensions)
2328 stabstr_C ('#');
2330 /* Write the argument types out longhand. */
2331 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2332 stabstr_C (',');
2333 dbxout_type (TREE_TYPE (type), 0);
2334 dbxout_args (TYPE_ARG_TYPES (type));
2335 stabstr_C (';');
2337 else
2338 /* Treat it as a function type. */
2339 dbxout_type (TREE_TYPE (type), 0);
2340 break;
2342 case OFFSET_TYPE:
2343 if (use_gnu_debug_info_extensions)
2345 stabstr_C ('@');
2346 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2347 stabstr_C (',');
2348 dbxout_type (TREE_TYPE (type), 0);
2350 else
2351 /* Should print as an int, because it is really just an offset. */
2352 dbxout_type (integer_type_node, 0);
2353 break;
2355 case REFERENCE_TYPE:
2356 if (use_gnu_debug_info_extensions)
2358 stabstr_C ('&');
2360 else
2361 stabstr_C ('*');
2362 dbxout_type (TREE_TYPE (type), 0);
2363 break;
2365 case FUNCTION_TYPE:
2366 stabstr_C ('f');
2367 dbxout_type (TREE_TYPE (type), 0);
2368 break;
2370 default:
2371 gcc_unreachable ();
2375 /* Return nonzero if the given type represents an integer whose bounds
2376 should be printed in octal format. */
2378 static bool
2379 print_int_cst_bounds_in_octal_p (tree type, tree low, tree high)
2381 /* If we can use GDB extensions and the size is wider than a long
2382 (the size used by GDB to read them) or we may have trouble writing
2383 the bounds the usual way, write them in octal. Note the test is for
2384 the *target's* size of "long", not that of the host. The host test
2385 is just to make sure we can write it out in case the host wide int
2386 is narrower than the target "long".
2388 For unsigned types, we use octal if they are the same size or larger.
2389 This is because we print the bounds as signed decimal, and hence they
2390 can't span same size unsigned types. */
2392 if (use_gnu_debug_info_extensions
2393 && low && TREE_CODE (low) == INTEGER_CST
2394 && high && TREE_CODE (high) == INTEGER_CST
2395 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2396 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2397 && TYPE_UNSIGNED (type))
2398 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2399 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2400 && TYPE_UNSIGNED (type))))
2401 return TRUE;
2402 else
2403 return FALSE;
2406 /* Output the name of type TYPE, with no punctuation.
2407 Such names can be set up either by typedef declarations
2408 or by struct, enum and union tags. */
2410 static void
2411 dbxout_type_name (tree type)
2413 tree t = TYPE_NAME (type);
2415 gcc_assert (t);
2416 switch (TREE_CODE (t))
2418 case IDENTIFIER_NODE:
2419 break;
2420 case TYPE_DECL:
2421 t = DECL_NAME (t);
2422 break;
2423 default:
2424 gcc_unreachable ();
2427 stabstr_I (t);
2430 /* Output leading leading struct or class names needed for qualifying
2431 type whose scope is limited to a struct or class. */
2433 static void
2434 dbxout_class_name_qualifiers (tree decl)
2436 tree context = decl_type_context (decl);
2438 if (context != NULL_TREE
2439 && TREE_CODE(context) == RECORD_TYPE
2440 && TYPE_NAME (context) != 0
2441 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2442 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2444 tree name = TYPE_NAME (context);
2446 if (TREE_CODE (name) == TYPE_DECL)
2448 dbxout_class_name_qualifiers (name);
2449 name = DECL_NAME (name);
2451 stabstr_I (name);
2452 stabstr_S ("::");
2456 /* This is a specialized subset of expand_expr for use by dbxout_symbol in
2457 evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that
2458 haven't been expanded, or if the expression is getting so complex we won't
2459 be able to represent it in stabs anyway. Returns NULL on failure. */
2461 static rtx
2462 dbxout_expand_expr (tree expr)
2464 switch (TREE_CODE (expr))
2466 case VAR_DECL:
2467 /* We can't handle emulated tls variables, because the address is an
2468 offset to the return value of __emutls_get_address, and there is no
2469 way to express that in stabs. Also, there are name mangling issues
2470 here. We end up with references to undefined symbols if we don't
2471 disable debug info for these variables. */
2472 if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr))
2473 return NULL;
2474 if (TREE_STATIC (expr)
2475 && !TREE_ASM_WRITTEN (expr)
2476 && !DECL_HAS_VALUE_EXPR_P (expr)
2477 && !TREE_PUBLIC (expr)
2478 && DECL_RTL_SET_P (expr)
2479 && MEM_P (DECL_RTL (expr)))
2481 /* If this is a var that might not be actually output,
2482 return NULL, otherwise stabs might reference an undefined
2483 symbol. */
2484 struct varpool_node *node = varpool_get_node (expr);
2485 if (!node || !node->needed)
2486 return NULL;
2488 /* FALLTHRU */
2490 case PARM_DECL:
2491 case RESULT_DECL:
2492 if (DECL_HAS_VALUE_EXPR_P (expr))
2493 return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2494 /* FALLTHRU */
2496 case CONST_DECL:
2497 return DECL_RTL_IF_SET (expr);
2499 case INTEGER_CST:
2500 return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2502 case COMPONENT_REF:
2503 case ARRAY_REF:
2504 case ARRAY_RANGE_REF:
2505 case BIT_FIELD_REF:
2507 enum machine_mode mode;
2508 HOST_WIDE_INT bitsize, bitpos;
2509 tree offset, tem;
2510 int volatilep = 0, unsignedp = 0;
2511 rtx x;
2513 tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
2514 &mode, &unsignedp, &volatilep, true);
2516 x = dbxout_expand_expr (tem);
2517 if (x == NULL || !MEM_P (x))
2518 return NULL;
2519 if (offset != NULL)
2521 if (!host_integerp (offset, 0))
2522 return NULL;
2523 x = adjust_address_nv (x, mode, tree_low_cst (offset, 0));
2525 if (bitpos != 0)
2526 x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
2528 return x;
2531 default:
2532 return NULL;
2536 /* Helper function for output_used_types. Queue one entry from the
2537 used types hash to be output. */
2539 static int
2540 output_used_types_helper (void **slot, void *data)
2542 tree type = (tree) *slot;
2543 VEC(tree, heap) **types_p = (VEC(tree, heap) **) data;
2545 if ((TREE_CODE (type) == RECORD_TYPE
2546 || TREE_CODE (type) == UNION_TYPE
2547 || TREE_CODE (type) == QUAL_UNION_TYPE
2548 || TREE_CODE (type) == ENUMERAL_TYPE)
2549 && TYPE_STUB_DECL (type)
2550 && DECL_P (TYPE_STUB_DECL (type))
2551 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
2552 VEC_quick_push (tree, *types_p, TYPE_STUB_DECL (type));
2553 else if (TYPE_NAME (type)
2554 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2555 VEC_quick_push (tree, *types_p, TYPE_NAME (type));
2557 return 1;
2560 /* This is a qsort callback which sorts types and declarations into a
2561 predictable order (types, then declarations, sorted by UID
2562 within). */
2564 static int
2565 output_types_sort (const void *pa, const void *pb)
2567 const tree lhs = *((const tree *)pa);
2568 const tree rhs = *((const tree *)pb);
2570 if (TYPE_P (lhs))
2572 if (TYPE_P (rhs))
2573 return TYPE_UID (lhs) - TYPE_UID (rhs);
2574 else
2575 return 1;
2577 else
2579 if (TYPE_P (rhs))
2580 return -1;
2581 else
2582 return DECL_UID (lhs) - DECL_UID (rhs);
2587 /* Force all types used by this function to be output in debug
2588 information. */
2590 static void
2591 output_used_types (void)
2593 if (cfun && cfun->used_types_hash)
2595 VEC(tree, heap) *types;
2596 int i;
2597 tree type;
2599 types = VEC_alloc (tree, heap, htab_elements (cfun->used_types_hash));
2600 htab_traverse (cfun->used_types_hash, output_used_types_helper, &types);
2602 /* Sort by UID to prevent dependence on hash table ordering. */
2603 VEC_qsort (tree, types, output_types_sort);
2605 FOR_EACH_VEC_ELT (tree, types, i, type)
2606 debug_queue_symbol (type);
2608 VEC_free (tree, heap, types);
2612 /* Output a .stabs for the symbol defined by DECL,
2613 which must be a ..._DECL node in the normal namespace.
2614 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2615 LOCAL is nonzero if the scope is less than the entire file.
2616 Return 1 if a stabs might have been emitted. */
2619 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2621 tree type = TREE_TYPE (decl);
2622 tree context = NULL_TREE;
2623 int result = 0;
2624 rtx decl_rtl;
2626 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2627 ++debug_nesting;
2629 /* Ignore nameless syms, but don't ignore type tags. */
2631 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2632 || DECL_IGNORED_P (decl))
2633 DBXOUT_DECR_NESTING_AND_RETURN (0);
2635 /* If we are to generate only the symbols actually used then such
2636 symbol nodes are flagged with TREE_USED. Ignore any that
2637 aren't flagged as TREE_USED. */
2639 if (flag_debug_only_used_symbols
2640 && (!TREE_USED (decl)
2641 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2642 DBXOUT_DECR_NESTING_AND_RETURN (0);
2644 /* If dbxout_init has not yet run, queue this symbol for later. */
2645 if (!typevec)
2647 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2648 DBXOUT_DECR_NESTING_AND_RETURN (0);
2651 if (flag_debug_only_used_symbols)
2653 tree t;
2655 /* We now have a used symbol. We need to generate the info for
2656 the symbol's type in addition to the symbol itself. These
2657 type symbols are queued to be generated after were done with
2658 the symbol itself (otherwise they would fight over the
2659 stabstr obstack).
2661 Note, because the TREE_TYPE(type) might be something like a
2662 pointer to a named type we need to look for the first name
2663 we see following the TREE_TYPE chain. */
2665 t = type;
2666 while (POINTER_TYPE_P (t))
2667 t = TREE_TYPE (t);
2669 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2670 need special treatment. The TYPE_STUB_DECL field in these
2671 types generally represents the tag name type we want to
2672 output. In addition there could be a typedef type with
2673 a different name. In that case we also want to output
2674 that. */
2676 if (TREE_CODE (t) == RECORD_TYPE
2677 || TREE_CODE (t) == UNION_TYPE
2678 || TREE_CODE (t) == QUAL_UNION_TYPE
2679 || TREE_CODE (t) == ENUMERAL_TYPE)
2681 if (TYPE_STUB_DECL (t)
2682 && TYPE_STUB_DECL (t) != decl
2683 && DECL_P (TYPE_STUB_DECL (t))
2684 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2686 debug_queue_symbol (TYPE_STUB_DECL (t));
2687 if (TYPE_NAME (t)
2688 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2689 && TYPE_NAME (t) != decl
2690 && DECL_P (TYPE_NAME (t)))
2691 debug_queue_symbol (TYPE_NAME (t));
2694 else if (TYPE_NAME (t)
2695 && TYPE_NAME (t) != decl
2696 && DECL_P (TYPE_NAME (t)))
2697 debug_queue_symbol (TYPE_NAME (t));
2700 emit_pending_bincls_if_required ();
2702 switch (TREE_CODE (decl))
2704 case CONST_DECL:
2705 /* Enum values are defined by defining the enum type. */
2706 break;
2708 case FUNCTION_DECL:
2709 decl_rtl = DECL_RTL_IF_SET (decl);
2710 if (!decl_rtl)
2711 DBXOUT_DECR_NESTING_AND_RETURN (0);
2712 if (DECL_EXTERNAL (decl))
2713 break;
2714 /* Don't mention a nested function under its parent. */
2715 context = decl_function_context (decl);
2716 if (context == current_function_decl)
2717 break;
2718 /* Don't mention an inline instance of a nested function. */
2719 if (context && DECL_FROM_INLINE (decl))
2720 break;
2721 if (!MEM_P (decl_rtl)
2722 || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
2723 break;
2725 if (flag_debug_only_used_symbols)
2726 output_used_types ();
2728 dbxout_begin_complex_stabs ();
2729 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2730 stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2731 result = 1;
2733 if (TREE_TYPE (type))
2734 dbxout_type (TREE_TYPE (type), 0);
2735 else
2736 dbxout_type (void_type_node, 0);
2738 /* For a nested function, when that function is compiled,
2739 mention the containing function name
2740 as well as (since dbx wants it) our own assembler-name. */
2741 if (context != 0)
2743 stabstr_C (',');
2744 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2745 stabstr_C (',');
2746 stabstr_I (DECL_NAME (context));
2749 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
2750 break;
2752 case TYPE_DECL:
2753 /* Don't output the same typedef twice.
2754 And don't output what language-specific stuff doesn't want output. */
2755 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2756 DBXOUT_DECR_NESTING_AND_RETURN (0);
2758 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2759 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2761 int fundamental_type_number =
2762 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2764 if (fundamental_type_number != 0)
2766 TREE_ASM_WRITTEN (decl) = 1;
2767 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2768 DBXOUT_DECR_NESTING_AND_RETURN (0);
2771 #endif
2772 FORCE_TEXT;
2773 result = 1;
2775 int tag_needed = 1;
2776 int did_output = 0;
2778 if (DECL_NAME (decl))
2780 /* Nonzero means we must output a tag as well as a typedef. */
2781 tag_needed = 0;
2783 /* Handle the case of a C++ structure or union
2784 where the TYPE_NAME is a TYPE_DECL
2785 which gives both a typedef name and a tag. */
2786 /* dbx requires the tag first and the typedef second. */
2787 if ((TREE_CODE (type) == RECORD_TYPE
2788 || TREE_CODE (type) == UNION_TYPE
2789 || TREE_CODE (type) == QUAL_UNION_TYPE)
2790 && TYPE_NAME (type) == decl
2791 && !use_gnu_debug_info_extensions
2792 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2793 /* Distinguish the implicit typedefs of C++
2794 from explicit ones that might be found in C. */
2795 && DECL_ARTIFICIAL (decl)
2796 /* Do not generate a tag for incomplete records. */
2797 && COMPLETE_TYPE_P (type)
2798 /* Do not generate a tag for records of variable size,
2799 since this type can not be properly described in the
2800 DBX format, and it confuses some tools such as objdump. */
2801 && host_integerp (TYPE_SIZE (type), 1))
2803 tree name = TYPE_NAME (type);
2804 if (TREE_CODE (name) == TYPE_DECL)
2805 name = DECL_NAME (name);
2807 dbxout_begin_complex_stabs ();
2808 stabstr_I (name);
2809 stabstr_S (":T");
2810 dbxout_type (type, 1);
2811 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2812 0, 0, 0);
2815 dbxout_begin_complex_stabs ();
2817 /* Output leading class/struct qualifiers. */
2818 if (use_gnu_debug_info_extensions)
2819 dbxout_class_name_qualifiers (decl);
2821 /* Output typedef name. */
2822 stabstr_I (DECL_NAME (decl));
2823 stabstr_C (':');
2825 /* Short cut way to output a tag also. */
2826 if ((TREE_CODE (type) == RECORD_TYPE
2827 || TREE_CODE (type) == UNION_TYPE
2828 || TREE_CODE (type) == QUAL_UNION_TYPE)
2829 && TYPE_NAME (type) == decl
2830 /* Distinguish the implicit typedefs of C++
2831 from explicit ones that might be found in C. */
2832 && DECL_ARTIFICIAL (decl))
2834 if (use_gnu_debug_info_extensions)
2836 stabstr_C ('T');
2837 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2841 stabstr_C ('t');
2842 dbxout_type (type, 1);
2843 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2844 0, 0, 0);
2845 did_output = 1;
2848 /* Don't output a tag if this is an incomplete type. This prevents
2849 the sun4 Sun OS 4.x dbx from crashing. */
2851 if (tag_needed && TYPE_NAME (type) != 0
2852 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2853 || (DECL_NAME (TYPE_NAME (type)) != 0))
2854 && COMPLETE_TYPE_P (type)
2855 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2857 /* For a TYPE_DECL with no name, but the type has a name,
2858 output a tag.
2859 This is what represents `struct foo' with no typedef. */
2860 /* In C++, the name of a type is the corresponding typedef.
2861 In C, it is an IDENTIFIER_NODE. */
2862 tree name = TYPE_NAME (type);
2863 if (TREE_CODE (name) == TYPE_DECL)
2864 name = DECL_NAME (name);
2866 dbxout_begin_complex_stabs ();
2867 stabstr_I (name);
2868 stabstr_S (":T");
2869 dbxout_type (type, 1);
2870 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2871 did_output = 1;
2874 /* If an enum type has no name, it cannot be referred to, but
2875 we must output it anyway, to record the enumeration
2876 constants. */
2878 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2880 dbxout_begin_complex_stabs ();
2881 /* Some debuggers fail when given NULL names, so give this a
2882 harmless name of " " (Why not "(anon)"?). */
2883 stabstr_S (" :T");
2884 dbxout_type (type, 1);
2885 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2888 /* Prevent duplicate output of a typedef. */
2889 TREE_ASM_WRITTEN (decl) = 1;
2890 break;
2893 case PARM_DECL:
2894 if (DECL_HAS_VALUE_EXPR_P (decl))
2895 decl = DECL_VALUE_EXPR (decl);
2897 /* PARM_DECLs go in their own separate chain and are output by
2898 dbxout_reg_parms and dbxout_parms, except for those that are
2899 disguised VAR_DECLs like Out parameters in Ada. */
2900 gcc_assert (TREE_CODE (decl) == VAR_DECL);
2902 /* ... fall through ... */
2904 case RESULT_DECL:
2905 case VAR_DECL:
2906 /* Don't mention a variable that is external.
2907 Let the file that defines it describe it. */
2908 if (DECL_EXTERNAL (decl))
2909 break;
2911 /* If the variable is really a constant
2912 and not written in memory, inform the debugger.
2914 ??? Why do we skip emitting the type and location in this case? */
2915 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2916 && DECL_INITIAL (decl) != 0
2917 && host_integerp (DECL_INITIAL (decl), 0)
2918 && ! TREE_ASM_WRITTEN (decl)
2919 && (DECL_FILE_SCOPE_P (decl)
2920 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
2921 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
2922 && TREE_PUBLIC (decl) == 0)
2924 /* The sun4 assembler does not grok this. */
2926 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2927 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2929 HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
2931 dbxout_begin_complex_stabs ();
2932 dbxout_symbol_name (decl, NULL, 'c');
2933 stabstr_S ("=i");
2934 stabstr_D (ival);
2935 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2936 DBXOUT_DECR_NESTING;
2937 return 1;
2939 else
2940 break;
2942 /* else it is something we handle like a normal variable. */
2944 decl_rtl = dbxout_expand_expr (decl);
2945 if (!decl_rtl)
2946 DBXOUT_DECR_NESTING_AND_RETURN (0);
2948 decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX);
2949 #ifdef LEAF_REG_REMAP
2950 if (current_function_uses_only_leaf_regs)
2951 leaf_renumber_regs_insn (decl_rtl);
2952 #endif
2954 result = dbxout_symbol_location (decl, type, 0, decl_rtl);
2955 break;
2957 default:
2958 break;
2960 DBXOUT_DECR_NESTING;
2961 return result;
2964 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2965 Add SUFFIX to its name, if SUFFIX is not 0.
2966 Describe the variable as residing in HOME
2967 (usually HOME is DECL_RTL (DECL), but not always).
2968 Returns 1 if the stab was really emitted. */
2970 static int
2971 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2973 int letter = 0;
2974 stab_code_type code;
2975 rtx addr = 0;
2976 int number = 0;
2977 int regno = -1;
2979 /* Don't mention a variable at all
2980 if it was completely optimized into nothingness.
2982 If the decl was from an inline function, then its rtl
2983 is not identically the rtl that was used in this
2984 particular compilation. */
2985 if (GET_CODE (home) == SUBREG)
2987 rtx value = home;
2989 while (GET_CODE (value) == SUBREG)
2990 value = SUBREG_REG (value);
2991 if (REG_P (value))
2993 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2994 return 0;
2996 home = alter_subreg (&home);
2998 if (REG_P (home))
3000 regno = REGNO (home);
3001 if (regno >= FIRST_PSEUDO_REGISTER)
3002 return 0;
3005 /* The kind-of-variable letter depends on where
3006 the variable is and on the scope of its name:
3007 G and N_GSYM for static storage and global scope,
3008 S for static storage and file scope,
3009 V for static storage and local scope,
3010 for those two, use N_LCSYM if data is in bss segment,
3011 N_STSYM if in data segment, N_FUN otherwise.
3012 (We used N_FUN originally, then changed to N_STSYM
3013 to please GDB. However, it seems that confused ld.
3014 Now GDB has been fixed to like N_FUN, says Kingdon.)
3015 no letter at all, and N_LSYM, for auto variable,
3016 r and N_RSYM for register variable. */
3018 if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
3020 if (TREE_PUBLIC (decl))
3022 int offs;
3023 letter = 'G';
3024 code = N_GSYM;
3025 if (NULL != dbxout_common_check (decl, &offs))
3027 letter = 'V';
3028 addr = 0;
3029 number = offs;
3032 else
3034 addr = XEXP (home, 0);
3036 letter = decl_function_context (decl) ? 'V' : 'S';
3038 /* Some ports can transform a symbol ref into a label ref,
3039 because the symbol ref is too far away and has to be
3040 dumped into a constant pool. Alternatively, the symbol
3041 in the constant pool might be referenced by a different
3042 symbol. */
3043 if (GET_CODE (addr) == SYMBOL_REF
3044 && CONSTANT_POOL_ADDRESS_P (addr))
3046 bool marked;
3047 rtx tmp = get_pool_constant_mark (addr, &marked);
3049 if (GET_CODE (tmp) == SYMBOL_REF)
3051 addr = tmp;
3052 if (CONSTANT_POOL_ADDRESS_P (addr))
3053 get_pool_constant_mark (addr, &marked);
3054 else
3055 marked = true;
3057 else if (GET_CODE (tmp) == LABEL_REF)
3059 addr = tmp;
3060 marked = true;
3063 /* If all references to the constant pool were optimized
3064 out, we just ignore the symbol. */
3065 if (!marked)
3066 return 0;
3069 /* This should be the same condition as in assemble_variable, but
3070 we don't have access to dont_output_data here. So, instead,
3071 we rely on the fact that error_mark_node initializers always
3072 end up in bss for C++ and never end up in bss for C. */
3073 if (DECL_INITIAL (decl) == 0
3074 || (!strcmp (lang_hooks.name, "GNU C++")
3075 && DECL_INITIAL (decl) == error_mark_node))
3077 int offs;
3078 code = N_LCSYM;
3079 if (NULL != dbxout_common_check (decl, &offs))
3081 addr = 0;
3082 number = offs;
3083 letter = 'V';
3084 code = N_GSYM;
3087 else if (DECL_IN_TEXT_SECTION (decl))
3088 /* This is not quite right, but it's the closest
3089 of all the codes that Unix defines. */
3090 code = DBX_STATIC_CONST_VAR_CODE;
3091 else
3093 /* Ultrix `as' seems to need this. */
3094 #ifdef DBX_STATIC_STAB_DATA_SECTION
3095 switch_to_section (data_section);
3096 #endif
3097 code = N_STSYM;
3101 else if (regno >= 0)
3103 letter = 'r';
3104 code = N_RSYM;
3105 number = DBX_REGISTER_NUMBER (regno);
3107 else if (MEM_P (home)
3108 && (MEM_P (XEXP (home, 0))
3109 || (REG_P (XEXP (home, 0))
3110 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
3111 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
3112 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3113 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
3114 #endif
3116 /* If the value is indirect by memory or by a register
3117 that isn't the frame pointer
3118 then it means the object is variable-sized and address through
3119 that register or stack slot. DBX has no way to represent this
3120 so all we can do is output the variable as a pointer.
3121 If it's not a parameter, ignore it. */
3123 if (REG_P (XEXP (home, 0)))
3125 letter = 'r';
3126 code = N_RSYM;
3127 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
3128 return 0;
3129 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
3131 else
3133 code = N_LSYM;
3134 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
3135 We want the value of that CONST_INT. */
3136 number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
3139 /* Effectively do build_pointer_type, but don't cache this type,
3140 since it might be temporary whereas the type it points to
3141 might have been saved for inlining. */
3142 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
3143 type = make_node (POINTER_TYPE);
3144 TREE_TYPE (type) = TREE_TYPE (decl);
3146 else if (MEM_P (home)
3147 && REG_P (XEXP (home, 0)))
3149 code = N_LSYM;
3150 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3152 else if (MEM_P (home)
3153 && GET_CODE (XEXP (home, 0)) == PLUS
3154 && CONST_INT_P (XEXP (XEXP (home, 0), 1)))
3156 code = N_LSYM;
3157 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
3158 We want the value of that CONST_INT. */
3159 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3161 else if (MEM_P (home)
3162 && GET_CODE (XEXP (home, 0)) == CONST)
3164 /* Handle an obscure case which can arise when optimizing and
3165 when there are few available registers. (This is *always*
3166 the case for i386/i486 targets). The RTL looks like
3167 (MEM (CONST ...)) even though this variable is a local `auto'
3168 or a local `register' variable. In effect, what has happened
3169 is that the reload pass has seen that all assignments and
3170 references for one such a local variable can be replaced by
3171 equivalent assignments and references to some static storage
3172 variable, thereby avoiding the need for a register. In such
3173 cases we're forced to lie to debuggers and tell them that
3174 this variable was itself `static'. */
3175 int offs;
3176 code = N_LCSYM;
3177 letter = 'V';
3178 if (NULL == dbxout_common_check (decl, &offs))
3179 addr = XEXP (XEXP (home, 0), 0);
3180 else
3182 addr = 0;
3183 number = offs;
3184 code = N_GSYM;
3187 else if (GET_CODE (home) == CONCAT)
3189 tree subtype;
3191 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
3192 for example), then there is no easy way to figure out
3193 what SUBTYPE should be. So, we give up. */
3194 if (TREE_CODE (type) != COMPLEX_TYPE)
3195 return 0;
3197 subtype = TREE_TYPE (type);
3199 /* If the variable's storage is in two parts,
3200 output each as a separate stab with a modified name. */
3201 if (WORDS_BIG_ENDIAN)
3202 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
3203 else
3204 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
3206 if (WORDS_BIG_ENDIAN)
3207 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
3208 else
3209 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
3210 return 1;
3212 else
3213 /* Address might be a MEM, when DECL is a variable-sized object.
3214 Or it might be const0_rtx, meaning previous passes
3215 want us to ignore this variable. */
3216 return 0;
3218 /* Ok, start a symtab entry and output the variable name. */
3219 emit_pending_bincls_if_required ();
3220 FORCE_TEXT;
3222 #ifdef DBX_STATIC_BLOCK_START
3223 DBX_STATIC_BLOCK_START (asm_out_file, code);
3224 #endif
3226 dbxout_begin_complex_stabs_noforcetext ();
3227 dbxout_symbol_name (decl, suffix, letter);
3228 dbxout_type (type, 0);
3229 dbxout_finish_complex_stabs (decl, code, addr, 0, number);
3231 #ifdef DBX_STATIC_BLOCK_END
3232 DBX_STATIC_BLOCK_END (asm_out_file, code);
3233 #endif
3234 return 1;
3237 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
3238 Then output LETTER to indicate the kind of location the symbol has. */
3240 static void
3241 dbxout_symbol_name (tree decl, const char *suffix, int letter)
3243 tree name;
3245 if (DECL_CONTEXT (decl)
3246 && (TYPE_P (DECL_CONTEXT (decl))
3247 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
3248 /* One slight hitch: if this is a VAR_DECL which is a class member
3249 or a namespace member, we must put out the mangled name instead of the
3250 DECL_NAME. Note also that static member (variable) names DO NOT begin
3251 with underscores in .stabs directives. */
3252 name = DECL_ASSEMBLER_NAME (decl);
3253 else
3254 /* ...but if we're function-local, we don't want to include the junk
3255 added by ASM_FORMAT_PRIVATE_NAME. */
3256 name = DECL_NAME (decl);
3258 if (name)
3259 stabstr_I (name);
3260 else
3261 stabstr_S ("(anon)");
3263 if (suffix)
3264 stabstr_S (suffix);
3265 stabstr_C (':');
3266 if (letter)
3267 stabstr_C (letter);
3271 /* Output the common block name for DECL in a stabs.
3273 Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair
3274 around each group of symbols in the same .comm area. The N_GSYM stabs
3275 that are emitted only contain the offset in the common area. This routine
3276 emits the N_BCOMM and N_ECOMM stabs. */
3278 static void
3279 dbxout_common_name (tree decl, const char *name, stab_code_type op)
3281 dbxout_begin_complex_stabs ();
3282 stabstr_S (name);
3283 dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0);
3286 /* Check decl to determine whether it is a VAR_DECL destined for storage in a
3287 common area. If it is, the return value will be a non-null string giving
3288 the name of the common storage block it will go into. If non-null, the
3289 value is the offset into the common block for that symbol's storage. */
3291 static const char *
3292 dbxout_common_check (tree decl, int *value)
3294 rtx home;
3295 rtx sym_addr;
3296 const char *name = NULL;
3298 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
3299 it does not have a value (the offset into the common area), or if it
3300 is thread local (as opposed to global) then it isn't common, and shouldn't
3301 be handled as such.
3303 ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs
3304 for thread-local symbols. Can be handled via same mechanism as used
3305 in dwarf2out.c. */
3306 if (TREE_CODE (decl) != VAR_DECL
3307 || !TREE_STATIC(decl)
3308 || !DECL_HAS_VALUE_EXPR_P(decl)
3309 || DECL_THREAD_LOCAL_P (decl)
3310 || !is_fortran ())
3311 return NULL;
3313 home = DECL_RTL (decl);
3314 if (home == NULL_RTX || GET_CODE (home) != MEM)
3315 return NULL;
3317 sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl));
3318 if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM)
3319 return NULL;
3321 sym_addr = XEXP (sym_addr, 0);
3322 if (GET_CODE (sym_addr) == CONST)
3323 sym_addr = XEXP (sym_addr, 0);
3324 if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS)
3325 && DECL_INITIAL (decl) == 0)
3328 /* We have a sym that will go into a common area, meaning that it
3329 will get storage reserved with a .comm/.lcomm assembler pseudo-op.
3331 Determine name of common area this symbol will be an offset into,
3332 and offset into that area. Also retrieve the decl for the area
3333 that the symbol is offset into. */
3334 tree cdecl = NULL;
3336 switch (GET_CODE (sym_addr))
3338 case PLUS:
3339 if (CONST_INT_P (XEXP (sym_addr, 0)))
3341 name =
3342 targetm.strip_name_encoding(XSTR (XEXP (sym_addr, 1), 0));
3343 *value = INTVAL (XEXP (sym_addr, 0));
3344 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1));
3346 else
3348 name =
3349 targetm.strip_name_encoding(XSTR (XEXP (sym_addr, 0), 0));
3350 *value = INTVAL (XEXP (sym_addr, 1));
3351 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0));
3353 break;
3355 case SYMBOL_REF:
3356 name = targetm.strip_name_encoding(XSTR (sym_addr, 0));
3357 *value = 0;
3358 cdecl = SYMBOL_REF_DECL (sym_addr);
3359 break;
3361 default:
3362 error ("common symbol debug info is not structured as "
3363 "symbol+offset");
3366 /* Check area common symbol is offset into. If this is not public, then
3367 it is not a symbol in a common block. It must be a .lcomm symbol, not
3368 a .comm symbol. */
3369 if (cdecl == NULL || !TREE_PUBLIC(cdecl))
3370 name = NULL;
3372 else
3373 name = NULL;
3375 return name;
3378 /* Output definitions of all the decls in a chain. Return nonzero if
3379 anything was output */
3382 dbxout_syms (tree syms)
3384 int result = 0;
3385 const char *comm_prev = NULL;
3386 tree syms_prev = NULL;
3388 while (syms)
3390 int temp, copen, cclos;
3391 const char *comm_new;
3393 /* Check for common symbol, and then progression into a new/different
3394 block of common symbols. Emit closing/opening common bracket if
3395 necessary. */
3396 comm_new = dbxout_common_check (syms, &temp);
3397 copen = comm_new != NULL
3398 && (comm_prev == NULL || strcmp (comm_new, comm_prev));
3399 cclos = comm_prev != NULL
3400 && (comm_new == NULL || strcmp (comm_new, comm_prev));
3401 if (cclos)
3402 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3403 if (copen)
3405 dbxout_common_name (syms, comm_new, N_BCOMM);
3406 syms_prev = syms;
3408 comm_prev = comm_new;
3410 result += dbxout_symbol (syms, 1);
3411 syms = DECL_CHAIN (syms);
3414 if (comm_prev != NULL)
3415 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3417 return result;
3420 /* The following two functions output definitions of function parameters.
3421 Each parameter gets a definition locating it in the parameter list.
3422 Each parameter that is a register variable gets a second definition
3423 locating it in the register.
3425 Printing or argument lists in gdb uses the definitions that
3426 locate in the parameter list. But reference to the variable in
3427 expressions uses preferentially the definition as a register. */
3429 /* Output definitions, referring to storage in the parmlist,
3430 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
3432 void
3433 dbxout_parms (tree parms)
3435 ++debug_nesting;
3436 emit_pending_bincls_if_required ();
3438 for (; parms; parms = DECL_CHAIN (parms))
3439 if (DECL_NAME (parms)
3440 && TREE_TYPE (parms) != error_mark_node
3441 && DECL_RTL_SET_P (parms)
3442 && DECL_INCOMING_RTL (parms))
3444 tree eff_type;
3445 char letter;
3446 stab_code_type code;
3447 int number;
3449 /* Perform any necessary register eliminations on the parameter's rtl,
3450 so that the debugging output will be accurate. */
3451 DECL_INCOMING_RTL (parms)
3452 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
3453 SET_DECL_RTL (parms,
3454 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
3455 #ifdef LEAF_REG_REMAP
3456 if (current_function_uses_only_leaf_regs)
3458 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3459 leaf_renumber_regs_insn (DECL_RTL (parms));
3461 #endif
3463 if (PARM_PASSED_IN_MEMORY (parms))
3465 rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3467 /* ??? Here we assume that the parm address is indexed
3468 off the frame pointer or arg pointer.
3469 If that is not true, we produce meaningless results,
3470 but do not crash. */
3471 if (GET_CODE (inrtl) == PLUS
3472 && CONST_INT_P (XEXP (inrtl, 1)))
3473 number = INTVAL (XEXP (inrtl, 1));
3474 else
3475 number = 0;
3477 code = N_PSYM;
3478 number = DEBUGGER_ARG_OFFSET (number, inrtl);
3479 letter = 'p';
3481 /* It is quite tempting to use TREE_TYPE (parms) instead
3482 of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3483 reports the actual type of the parameter, rather than
3484 the promoted type. This certainly makes GDB's life
3485 easier, at least for some ports. The change is a bad
3486 idea however, since GDB expects to be able access the
3487 type without performing any conversions. So for
3488 example, if we were passing a float to an unprototyped
3489 function, gcc will store a double on the stack, but if
3490 we emit a stab saying the type is a float, then gdb
3491 will only read in a single value, and this will produce
3492 an erroneous value. */
3493 eff_type = DECL_ARG_TYPE (parms);
3495 else if (REG_P (DECL_RTL (parms)))
3497 rtx best_rtl;
3499 /* Parm passed in registers and lives in registers or nowhere. */
3500 code = DBX_REGPARM_STABS_CODE;
3501 letter = DBX_REGPARM_STABS_LETTER;
3503 /* For parms passed in registers, it is better to use the
3504 declared type of the variable, not the type it arrived in. */
3505 eff_type = TREE_TYPE (parms);
3507 /* If parm lives in a register, use that register; pretend
3508 the parm was passed there. It would be more consistent
3509 to describe the register where the parm was passed, but
3510 in practice that register usually holds something else.
3511 If the parm lives nowhere, use the register where it
3512 was passed. */
3513 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3514 best_rtl = DECL_RTL (parms);
3515 else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL)
3516 best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0);
3517 else
3518 best_rtl = DECL_INCOMING_RTL (parms);
3520 number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3522 else if (MEM_P (DECL_RTL (parms))
3523 && REG_P (XEXP (DECL_RTL (parms), 0))
3524 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3525 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3526 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3527 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3528 #endif
3531 /* Parm was passed via invisible reference.
3532 That is, its address was passed in a register.
3533 Output it as if it lived in that register.
3534 The debugger will know from the type
3535 that it was actually passed by invisible reference. */
3537 code = DBX_REGPARM_STABS_CODE;
3539 /* GDB likes this marked with a special letter. */
3540 letter = (use_gnu_debug_info_extensions
3541 ? 'a' : DBX_REGPARM_STABS_LETTER);
3542 eff_type = TREE_TYPE (parms);
3544 /* DECL_RTL looks like (MEM (REG...). Get the register number.
3545 If it is an unallocated pseudo-reg, then use the register where
3546 it was passed instead.
3547 ??? Why is DBX_REGISTER_NUMBER not used here? */
3549 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3550 number = REGNO (XEXP (DECL_RTL (parms), 0));
3551 else
3552 number = REGNO (DECL_INCOMING_RTL (parms));
3554 else if (MEM_P (DECL_RTL (parms))
3555 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3557 /* Parm was passed via invisible reference, with the reference
3558 living on the stack. DECL_RTL looks like
3559 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3560 could look like (MEM (MEM (REG))). */
3562 code = N_PSYM;
3563 letter = 'v';
3564 eff_type = TREE_TYPE (parms);
3566 if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3567 number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3568 else
3569 number = 0;
3571 number = DEBUGGER_ARG_OFFSET (number,
3572 XEXP (XEXP (DECL_RTL (parms), 0), 0));
3574 else if (MEM_P (DECL_RTL (parms))
3575 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3576 /* ??? A constant address for a parm can happen
3577 when the reg it lives in is equiv to a constant in memory.
3578 Should make this not happen, after 2.4. */
3579 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3581 /* Parm was passed in registers but lives on the stack. */
3583 code = N_PSYM;
3584 letter = 'p';
3585 eff_type = TREE_TYPE (parms);
3587 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3588 in which case we want the value of that CONST_INT,
3589 or (MEM (REG ...)),
3590 in which case we use a value of zero. */
3591 if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3592 number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3593 else
3594 number = 0;
3596 /* Make a big endian correction if the mode of the type of the
3597 parameter is not the same as the mode of the rtl. */
3598 if (BYTES_BIG_ENDIAN
3599 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3600 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3601 number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3602 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3604 else
3605 /* ??? We don't know how to represent this argument. */
3606 continue;
3608 dbxout_begin_complex_stabs ();
3610 if (DECL_NAME (parms))
3612 stabstr_I (DECL_NAME (parms));
3613 stabstr_C (':');
3615 else
3616 stabstr_S ("(anon):");
3617 stabstr_C (letter);
3618 dbxout_type (eff_type, 0);
3619 dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3621 DBXOUT_DECR_NESTING;
3624 /* Output definitions for the places where parms live during the function,
3625 when different from where they were passed, when the parms were passed
3626 in memory.
3628 It is not useful to do this for parms passed in registers
3629 that live during the function in different registers, because it is
3630 impossible to look in the passed register for the passed value,
3631 so we use the within-the-function register to begin with.
3633 PARMS is a chain of PARM_DECL nodes. */
3635 void
3636 dbxout_reg_parms (tree parms)
3638 ++debug_nesting;
3640 for (; parms; parms = DECL_CHAIN (parms))
3641 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3643 /* Report parms that live in registers during the function
3644 but were passed in memory. */
3645 if (REG_P (DECL_RTL (parms))
3646 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3647 dbxout_symbol_location (parms, TREE_TYPE (parms),
3648 0, DECL_RTL (parms));
3649 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3650 dbxout_symbol_location (parms, TREE_TYPE (parms),
3651 0, DECL_RTL (parms));
3652 /* Report parms that live in memory but not where they were passed. */
3653 else if (MEM_P (DECL_RTL (parms))
3654 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3655 dbxout_symbol_location (parms, TREE_TYPE (parms),
3656 0, DECL_RTL (parms));
3658 DBXOUT_DECR_NESTING;
3661 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3662 output definitions of those names, in raw form */
3664 static void
3665 dbxout_args (tree args)
3667 while (args)
3669 stabstr_C (',');
3670 dbxout_type (TREE_VALUE (args), 0);
3671 args = TREE_CHAIN (args);
3675 #if defined (DBX_DEBUGGING_INFO)
3677 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3678 BEGIN_LABEL is the name of the beginning of the function, which may
3679 be required. */
3680 static void
3681 dbx_output_lbrac (const char *label,
3682 const char *begin_label ATTRIBUTE_UNUSED)
3684 dbxout_begin_stabn (N_LBRAC);
3685 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3686 dbxout_stab_value_label_diff (label, begin_label);
3687 else
3688 dbxout_stab_value_label (label);
3691 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3692 BEGIN_LABEL is the name of the beginning of the function, which may
3693 be required. */
3694 static void
3695 dbx_output_rbrac (const char *label,
3696 const char *begin_label ATTRIBUTE_UNUSED)
3698 dbxout_begin_stabn (N_RBRAC);
3699 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3700 dbxout_stab_value_label_diff (label, begin_label);
3701 else
3702 dbxout_stab_value_label (label);
3705 /* Output everything about a symbol block (a BLOCK node
3706 that represents a scope level),
3707 including recursive output of contained blocks.
3709 BLOCK is the BLOCK node.
3710 DEPTH is its depth within containing symbol blocks.
3711 ARGS is usually zero; but for the outermost block of the
3712 body of a function, it is a chain of PARM_DECLs for the function parameters.
3713 We output definitions of all the register parms
3714 as if they were local variables of that block.
3716 If -g1 was used, we count blocks just the same, but output nothing
3717 except for the outermost block.
3719 Actually, BLOCK may be several blocks chained together.
3720 We handle them all in sequence. */
3722 static void
3723 dbxout_block (tree block, int depth, tree args)
3725 char begin_label[20];
3726 /* Reference current function start using LFBB. */
3727 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
3729 while (block)
3731 /* Ignore blocks never expanded or otherwise marked as real. */
3732 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3734 int did_output;
3735 int blocknum = BLOCK_NUMBER (block);
3737 /* In dbx format, the syms of a block come before the N_LBRAC.
3738 If nothing is output, we don't need the N_LBRAC, either. */
3739 did_output = 0;
3740 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3741 did_output = dbxout_syms (BLOCK_VARS (block));
3742 if (args)
3743 dbxout_reg_parms (args);
3745 /* Now output an N_LBRAC symbol to represent the beginning of
3746 the block. Use the block's tree-walk order to generate
3747 the assembler symbols LBBn and LBEn
3748 that final will define around the code in this block. */
3749 if (did_output)
3751 char buf[20];
3752 const char *scope_start;
3754 if (depth == 0)
3755 /* The outermost block doesn't get LBB labels; use
3756 the LFBB local symbol emitted by dbxout_begin_prologue. */
3757 scope_start = begin_label;
3758 else
3760 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3761 scope_start = buf;
3764 dbx_output_lbrac (scope_start, begin_label);
3767 /* Output the subblocks. */
3768 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3770 /* Refer to the marker for the end of the block. */
3771 if (did_output)
3773 char buf[100];
3774 if (depth == 0)
3775 /* The outermost block doesn't get LBE labels;
3776 use the "scope" label which will be emitted
3777 by dbxout_function_end. */
3778 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3779 else
3780 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3782 dbx_output_rbrac (buf, begin_label);
3785 block = BLOCK_CHAIN (block);
3789 /* Output the information about a function and its arguments and result.
3790 Usually this follows the function's code,
3791 but on some systems, it comes before. */
3793 static void
3794 dbxout_begin_function (tree decl)
3796 int saved_tree_used1;
3798 saved_tree_used1 = TREE_USED (decl);
3799 TREE_USED (decl) = 1;
3800 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3802 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3803 TREE_USED (DECL_RESULT (decl)) = 1;
3804 dbxout_symbol (decl, 0);
3805 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3807 else
3808 dbxout_symbol (decl, 0);
3809 TREE_USED (decl) = saved_tree_used1;
3811 dbxout_parms (DECL_ARGUMENTS (decl));
3812 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3813 dbxout_symbol (DECL_RESULT (decl), 1);
3815 #endif /* DBX_DEBUGGING_INFO */
3817 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3819 #include "gt-dbxout.h"