2010-07-27 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / gcc / dbxout.c
blob2de3fcbda3693a6d909785fa6f3f677ad6509310
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 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"
95 #ifdef XCOFF_DEBUGGING_INFO
96 #include "xcoffout.h"
97 #endif
99 #define DBXOUT_DECR_NESTING \
100 if (--debug_nesting == 0 && symbol_queue_index > 0) \
101 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
103 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
104 do {--debug_nesting; return (x);} while (0)
106 #ifndef ASM_STABS_OP
107 # ifdef XCOFF_DEBUGGING_INFO
108 # define ASM_STABS_OP "\t.stabx\t"
109 # else
110 # define ASM_STABS_OP "\t.stabs\t"
111 # endif
112 #endif
114 #ifndef ASM_STABN_OP
115 #define ASM_STABN_OP "\t.stabn\t"
116 #endif
118 #ifndef ASM_STABD_OP
119 #define ASM_STABD_OP "\t.stabd\t"
120 #endif
122 #ifndef DBX_TYPE_DECL_STABS_CODE
123 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
124 #endif
126 #ifndef DBX_STATIC_CONST_VAR_CODE
127 #define DBX_STATIC_CONST_VAR_CODE N_FUN
128 #endif
130 #ifndef DBX_REGPARM_STABS_CODE
131 #define DBX_REGPARM_STABS_CODE N_RSYM
132 #endif
134 #ifndef DBX_REGPARM_STABS_LETTER
135 #define DBX_REGPARM_STABS_LETTER 'P'
136 #endif
138 #ifndef NO_DBX_FUNCTION_END
139 #define NO_DBX_FUNCTION_END 0
140 #endif
142 #ifndef NO_DBX_BNSYM_ENSYM
143 #define NO_DBX_BNSYM_ENSYM 0
144 #endif
146 #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
147 #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
148 #endif
150 #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
151 #define DBX_BLOCKS_FUNCTION_RELATIVE 0
152 #endif
154 #ifndef DBX_LINES_FUNCTION_RELATIVE
155 #define DBX_LINES_FUNCTION_RELATIVE 0
156 #endif
158 #ifndef DBX_CONTIN_LENGTH
159 #define DBX_CONTIN_LENGTH 80
160 #endif
162 #ifndef DBX_CONTIN_CHAR
163 #define DBX_CONTIN_CHAR '\\'
164 #endif
166 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
168 /* Structure recording information about a C data type.
169 The status element says whether we have yet output
170 the definition of the type. TYPE_XREF says we have
171 output it as a cross-reference only.
172 The file_number and type_number elements are used if DBX_USE_BINCL
173 is defined. */
175 struct GTY(()) typeinfo {
176 enum typestatus status;
177 int file_number;
178 int type_number;
181 /* Vector recording information about C data types.
182 When we first notice a data type (a tree node),
183 we assign it a number using next_type_number.
184 That is its index in this vector. */
186 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
188 /* Number of elements of space allocated in `typevec'. */
190 static GTY(()) int typevec_len;
192 /* In dbx output, each type gets a unique number.
193 This is the number for the next type output.
194 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
196 static GTY(()) int next_type_number;
198 /* The C front end may call dbxout_symbol before dbxout_init runs.
199 We save all such decls in this list and output them when we get
200 to dbxout_init. */
202 static GTY(()) tree preinit_symbols;
204 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
206 /* When using N_BINCL in dbx output, each type number is actually a
207 pair of the file number and the type number within the file.
208 This is a stack of input files. */
210 struct dbx_file
212 struct dbx_file *next;
213 int file_number;
214 int next_type_number;
215 enum binclstatus bincl_status; /* Keep track of lazy bincl. */
216 const char *pending_bincl_name; /* Name of bincl. */
217 struct dbx_file *prev; /* Chain to traverse all pending bincls. */
220 /* This is the top of the stack.
222 This is not saved for PCH, because restoring a PCH should not change it.
223 next_file_number does have to be saved, because the PCH may use some
224 file numbers; however, just before restoring a PCH, next_file_number
225 should always be 0 because we should not have needed any file numbers
226 yet. */
228 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
229 && defined (DBX_USE_BINCL)
230 static struct dbx_file *current_file;
231 #endif
233 /* This is the next file number to use. */
235 static GTY(()) int next_file_number;
237 /* A counter for dbxout_function_end. */
239 static GTY(()) int scope_labelno;
241 /* A counter for dbxout_source_line. */
243 static GTY(()) int dbxout_source_line_counter;
245 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
246 for the N_SO filename stabs label. */
248 static GTY(()) int source_label_number = 1;
250 /* Last source file name mentioned in a NOTE insn. */
252 static GTY(()) const char *lastfile;
254 /* Used by PCH machinery to detect if 'lastfile' should be reset to
255 base_input_file. */
256 static GTY(()) int lastfile_is_base;
258 /* Typical USG systems don't have stab.h, and they also have
259 no use for DBX-format debugging info. */
261 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
263 #ifdef DBX_USE_BINCL
264 /* If zero then there is no pending BINCL. */
265 static int pending_bincls = 0;
266 #endif
268 /* The original input file name. */
269 static const char *base_input_file;
271 #ifdef DEBUG_SYMS_TEXT
272 #define FORCE_TEXT switch_to_section (current_function_section ())
273 #else
274 #define FORCE_TEXT
275 #endif
277 #include "gstab.h"
279 /* 1 if PARM is passed to this function in memory. */
281 #define PARM_PASSED_IN_MEMORY(PARM) \
282 (MEM_P (DECL_INCOMING_RTL (PARM)))
284 /* A C expression for the integer offset value of an automatic variable
285 (N_LSYM) having address X (an RTX). */
286 #ifndef DEBUGGER_AUTO_OFFSET
287 #define DEBUGGER_AUTO_OFFSET(X) \
288 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
289 #endif
291 /* A C expression for the integer offset value of an argument (N_PSYM)
292 having address X (an RTX). The nominal offset is OFFSET.
293 Note that we use OFFSET + 0 here to avoid the self-assign warning
294 when the macro is called in a context like
295 number = DEBUGGER_ARG_OFFSET(number, X) */
296 #ifndef DEBUGGER_ARG_OFFSET
297 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0)
298 #endif
300 /* This obstack holds the stab string currently being constructed. We
301 build it up here, then write it out, so we can split long lines up
302 properly (see dbxout_finish_complex_stabs). */
303 static struct obstack stabstr_ob;
304 static size_t stabstr_last_contin_point;
306 #ifdef DBX_USE_BINCL
307 static void emit_bincl_stab (const char *c);
308 static void emit_pending_bincls (void);
309 #endif
310 static inline void emit_pending_bincls_if_required (void);
312 static void dbxout_init (const char *);
314 static void dbxout_finish (const char *);
315 static void dbxout_start_source_file (unsigned, const char *);
316 static void dbxout_end_source_file (unsigned);
317 static void dbxout_typedefs (tree);
318 static void dbxout_type_index (tree);
319 static void dbxout_args (tree);
320 static void dbxout_type_fields (tree);
321 static void dbxout_type_method_1 (tree);
322 static void dbxout_type_methods (tree);
323 static void dbxout_range_type (tree, tree, tree);
324 static void dbxout_type (tree, int);
325 static bool print_int_cst_bounds_in_octal_p (tree, tree, tree);
326 static bool is_fortran (void);
327 static void dbxout_type_name (tree);
328 static void dbxout_class_name_qualifiers (tree);
329 static int dbxout_symbol_location (tree, tree, const char *, rtx);
330 static void dbxout_symbol_name (tree, const char *, int);
331 static void dbxout_common_name (tree, const char *, stab_code_type);
332 static const char *dbxout_common_check (tree, int *);
333 static void dbxout_global_decl (tree);
334 static void dbxout_type_decl (tree, int);
335 static void dbxout_handle_pch (unsigned);
337 /* The debug hooks structure. */
338 #if defined (DBX_DEBUGGING_INFO)
340 static void dbxout_source_line (unsigned int, const char *, int, bool);
341 static void dbxout_begin_prologue (unsigned int, const char *);
342 static void dbxout_source_file (const char *);
343 static void dbxout_function_end (tree);
344 static void dbxout_begin_function (tree);
345 static void dbxout_begin_block (unsigned, unsigned);
346 static void dbxout_end_block (unsigned, unsigned);
347 static void dbxout_function_decl (tree);
349 const struct gcc_debug_hooks dbx_debug_hooks =
351 dbxout_init,
352 dbxout_finish,
353 debug_nothing_void,
354 debug_nothing_int_charstar,
355 debug_nothing_int_charstar,
356 dbxout_start_source_file,
357 dbxout_end_source_file,
358 dbxout_begin_block,
359 dbxout_end_block,
360 debug_true_const_tree, /* ignore_block */
361 dbxout_source_line, /* source_line */
362 dbxout_begin_prologue, /* begin_prologue */
363 debug_nothing_int_charstar, /* end_prologue */
364 debug_nothing_int_charstar, /* begin_epilogue */
365 debug_nothing_int_charstar, /* end_epilogue */
366 #ifdef DBX_FUNCTION_FIRST
367 dbxout_begin_function,
368 #else
369 debug_nothing_tree, /* begin_function */
370 #endif
371 debug_nothing_int, /* end_function */
372 dbxout_function_decl,
373 dbxout_global_decl, /* global_decl */
374 dbxout_type_decl, /* type_decl */
375 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
376 debug_nothing_tree, /* deferred_inline_function */
377 debug_nothing_tree, /* outlining_inline_function */
378 debug_nothing_rtx, /* label */
379 dbxout_handle_pch, /* handle_pch */
380 debug_nothing_rtx, /* var_location */
381 debug_nothing_void, /* switch_text_section */
382 debug_nothing_tree, /* direct_call */
383 debug_nothing_tree_int, /* virtual_call_token */
384 debug_nothing_rtx_rtx, /* copy_call_info */
385 debug_nothing_uid, /* virtual_call */
386 debug_nothing_tree_tree, /* set_name */
387 0 /* start_end_main_source_file */
389 #endif /* DBX_DEBUGGING_INFO */
391 #if defined (XCOFF_DEBUGGING_INFO)
392 const struct gcc_debug_hooks xcoff_debug_hooks =
394 dbxout_init,
395 dbxout_finish,
396 debug_nothing_void,
397 debug_nothing_int_charstar,
398 debug_nothing_int_charstar,
399 dbxout_start_source_file,
400 dbxout_end_source_file,
401 xcoffout_begin_block,
402 xcoffout_end_block,
403 debug_true_const_tree, /* ignore_block */
404 xcoffout_source_line,
405 xcoffout_begin_prologue, /* begin_prologue */
406 debug_nothing_int_charstar, /* end_prologue */
407 debug_nothing_int_charstar, /* begin_epilogue */
408 xcoffout_end_epilogue,
409 debug_nothing_tree, /* begin_function */
410 xcoffout_end_function,
411 debug_nothing_tree, /* function_decl */
412 dbxout_global_decl, /* global_decl */
413 dbxout_type_decl, /* type_decl */
414 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
415 debug_nothing_tree, /* deferred_inline_function */
416 debug_nothing_tree, /* outlining_inline_function */
417 debug_nothing_rtx, /* label */
418 dbxout_handle_pch, /* handle_pch */
419 debug_nothing_rtx, /* var_location */
420 debug_nothing_void, /* switch_text_section */
421 debug_nothing_tree, /* direct_call */
422 debug_nothing_tree_int, /* virtual_call_token */
423 debug_nothing_rtx_rtx, /* copy_call_info */
424 debug_nothing_uid, /* virtual_call */
425 debug_nothing_tree_tree, /* set_name */
426 0 /* start_end_main_source_file */
428 #endif /* XCOFF_DEBUGGING_INFO */
430 /* Numeric formatting helper macro. Note that this does not handle
431 hexadecimal. */
432 #define NUMBER_FMT_LOOP(P, NUM, BASE) \
433 do \
435 int digit = NUM % BASE; \
436 NUM /= BASE; \
437 *--P = digit + '0'; \
439 while (NUM > 0)
441 /* Utility: write a decimal integer NUM to asm_out_file. */
442 void
443 dbxout_int (int num)
445 char buf[64];
446 char *p = buf + sizeof buf;
447 unsigned int unum;
449 if (num == 0)
451 putc ('0', asm_out_file);
452 return;
454 if (num < 0)
456 putc ('-', asm_out_file);
457 unum = -num;
459 else
460 unum = num;
462 NUMBER_FMT_LOOP (p, unum, 10);
464 while (p < buf + sizeof buf)
466 putc (*p, asm_out_file);
467 p++;
472 /* Primitives for emitting simple stabs directives. All other stabs
473 routines should use these functions instead of directly emitting
474 stabs. They are exported because machine-dependent code may need
475 to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
476 forwards to code in CPU.c. */
478 /* The following functions should all be called immediately after one
479 of the dbxout_begin_stab* functions (below). They write out
480 various things as the value of a stab. */
482 /* Write out a literal zero as the value of a stab. */
483 void
484 dbxout_stab_value_zero (void)
486 fputs ("0\n", asm_out_file);
489 /* Write out the label LABEL as the value of a stab. */
490 void
491 dbxout_stab_value_label (const char *label)
493 assemble_name (asm_out_file, label);
494 putc ('\n', asm_out_file);
497 /* Write out the difference of two labels, LABEL - BASE, as the value
498 of a stab. */
499 void
500 dbxout_stab_value_label_diff (const char *label, const char *base)
502 assemble_name (asm_out_file, label);
503 putc ('-', asm_out_file);
504 assemble_name (asm_out_file, base);
505 putc ('\n', asm_out_file);
508 /* Write out an internal label as the value of a stab, and immediately
509 emit that internal label. This should be used only when
510 dbxout_stabd will not work. STEM is the name stem of the label,
511 COUNTERP is a pointer to a counter variable which will be used to
512 guarantee label uniqueness. */
513 void
514 dbxout_stab_value_internal_label (const char *stem, int *counterp)
516 char label[100];
517 int counter = counterp ? (*counterp)++ : 0;
519 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
520 dbxout_stab_value_label (label);
521 targetm.asm_out.internal_label (asm_out_file, stem, counter);
524 /* Write out the difference between BASE and an internal label as the
525 value of a stab, and immediately emit that internal label. STEM and
526 COUNTERP are as for dbxout_stab_value_internal_label. */
527 void
528 dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
529 const char *base)
531 char label[100];
532 int counter = counterp ? (*counterp)++ : 0;
534 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
535 dbxout_stab_value_label_diff (label, base);
536 targetm.asm_out.internal_label (asm_out_file, stem, counter);
539 /* The following functions produce specific kinds of stab directives. */
541 /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
542 void
543 dbxout_stabd (int stype, int sdesc)
545 fputs (ASM_STABD_OP, asm_out_file);
546 dbxout_int (stype);
547 fputs (",0,", asm_out_file);
548 dbxout_int (sdesc);
549 putc ('\n', asm_out_file);
552 /* Write a .stabn directive with type STYPE. This function stops
553 short of emitting the value field, which is the responsibility of
554 the caller (normally it will be either a symbol or the difference
555 of two symbols). */
557 void
558 dbxout_begin_stabn (int stype)
560 fputs (ASM_STABN_OP, asm_out_file);
561 dbxout_int (stype);
562 fputs (",0,0,", asm_out_file);
565 /* Write a .stabn directive with type N_SLINE and desc LINE. As above,
566 the value field is the responsibility of the caller. */
567 void
568 dbxout_begin_stabn_sline (int lineno)
570 fputs (ASM_STABN_OP, asm_out_file);
571 dbxout_int (N_SLINE);
572 fputs (",0,", asm_out_file);
573 dbxout_int (lineno);
574 putc (',', asm_out_file);
577 /* Begin a .stabs directive with string "", type STYPE, and desc and
578 other fields 0. The value field is the responsibility of the
579 caller. This function cannot be used for .stabx directives. */
580 void
581 dbxout_begin_empty_stabs (int stype)
583 fputs (ASM_STABS_OP, asm_out_file);
584 fputs ("\"\",", asm_out_file);
585 dbxout_int (stype);
586 fputs (",0,0,", asm_out_file);
589 /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
590 The value field is the responsibility of the caller. */
591 void
592 dbxout_begin_simple_stabs (const char *str, int stype)
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,0,", asm_out_file);
601 /* As above but use SDESC for the desc field. */
602 void
603 dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
605 fputs (ASM_STABS_OP, asm_out_file);
606 output_quoted_string (asm_out_file, str);
607 putc (',', asm_out_file);
608 dbxout_int (stype);
609 fputs (",0,", asm_out_file);
610 dbxout_int (sdesc);
611 putc (',', asm_out_file);
614 /* The next set of functions are entirely concerned with production of
615 "complex" .stabs directives: that is, .stabs directives whose
616 strings have to be constructed piecemeal. dbxout_type,
617 dbxout_symbol, etc. use these routines heavily. The string is queued
618 up in an obstack, then written out by dbxout_finish_complex_stabs, which
619 is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
620 (You might think it would be more efficient to go straight to stdio
621 when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
622 out not to be the case, and anyway this needs fewer #ifdefs.) */
624 /* Begin a complex .stabs directive. If we can, write the initial
625 ASM_STABS_OP to the asm_out_file. */
627 static void
628 dbxout_begin_complex_stabs (void)
630 emit_pending_bincls_if_required ();
631 FORCE_TEXT;
632 fputs (ASM_STABS_OP, asm_out_file);
633 putc ('"', asm_out_file);
634 gcc_assert (stabstr_last_contin_point == 0);
637 /* As above, but do not force text or emit pending bincls. This is
638 used by dbxout_symbol_location, which needs to do something else. */
639 static void
640 dbxout_begin_complex_stabs_noforcetext (void)
642 fputs (ASM_STABS_OP, asm_out_file);
643 putc ('"', asm_out_file);
644 gcc_assert (stabstr_last_contin_point == 0);
647 /* Add CHR, a single character, to the string being built. */
648 #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
650 /* Add STR, a normal C string, to the string being built. */
651 #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen(str))
653 /* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
654 #define stabstr_I(id) obstack_grow (&stabstr_ob, \
655 IDENTIFIER_POINTER (id), \
656 IDENTIFIER_LENGTH (id))
658 /* Add NUM, a signed decimal number, to the string being built. */
659 static void
660 stabstr_D (HOST_WIDE_INT num)
662 char buf[64];
663 char *p = buf + sizeof buf;
664 unsigned int unum;
666 if (num == 0)
668 stabstr_C ('0');
669 return;
671 if (num < 0)
673 stabstr_C ('-');
674 unum = -num;
676 else
677 unum = num;
679 NUMBER_FMT_LOOP (p, unum, 10);
681 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
684 /* Add NUM, an unsigned decimal number, to the string being built. */
685 static void
686 stabstr_U (unsigned HOST_WIDE_INT num)
688 char buf[64];
689 char *p = buf + sizeof buf;
690 if (num == 0)
692 stabstr_C ('0');
693 return;
695 NUMBER_FMT_LOOP (p, num, 10);
696 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
699 /* Add CST, an INTEGER_CST tree, to the string being built as an
700 unsigned octal number. This routine handles values which are
701 larger than a single HOST_WIDE_INT. */
702 static void
703 stabstr_O (tree cst)
705 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (cst);
706 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
708 char buf[128];
709 char *p = buf + sizeof buf;
711 /* GDB wants constants with no extra leading "1" bits, so
712 we need to remove any sign-extension that might be
713 present. */
715 const unsigned int width = TYPE_PRECISION (TREE_TYPE (cst));
716 if (width == HOST_BITS_PER_WIDE_INT * 2)
718 else if (width > HOST_BITS_PER_WIDE_INT)
719 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
720 else if (width == HOST_BITS_PER_WIDE_INT)
721 high = 0;
722 else
723 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
726 /* Leading zero for base indicator. */
727 stabstr_C ('0');
729 /* If the value is zero, the base indicator will serve as the value
730 all by itself. */
731 if (high == 0 && low == 0)
732 return;
734 /* If the high half is zero, we need only print the low half normally. */
735 if (high == 0)
736 NUMBER_FMT_LOOP (p, low, 8);
737 else
739 /* When high != 0, we need to print enough zeroes from low to
740 give the digits from high their proper place-values. Hence
741 NUMBER_FMT_LOOP cannot be used. */
742 const int n_digits = HOST_BITS_PER_WIDE_INT / 3;
743 int i;
745 for (i = 1; i <= n_digits; i++)
747 unsigned int digit = low % 8;
748 low /= 8;
749 *--p = '0' + digit;
752 /* Octal digits carry exactly three bits of information. The
753 width of a HOST_WIDE_INT is not normally a multiple of three.
754 Therefore, the next digit printed probably needs to carry
755 information from both low and high. */
756 if (HOST_BITS_PER_WIDE_INT % 3 != 0)
758 const int n_leftover_bits = HOST_BITS_PER_WIDE_INT % 3;
759 const int n_bits_from_high = 3 - n_leftover_bits;
761 const unsigned HOST_WIDE_INT
762 low_mask = (((unsigned HOST_WIDE_INT)1) << n_leftover_bits) - 1;
763 const unsigned HOST_WIDE_INT
764 high_mask = (((unsigned HOST_WIDE_INT)1) << n_bits_from_high) - 1;
766 unsigned int digit;
768 /* At this point, only the bottom n_leftover_bits bits of low
769 should be set. */
770 gcc_assert (!(low & ~low_mask));
772 digit = (low | ((high & high_mask) << n_leftover_bits));
773 high >>= n_bits_from_high;
775 *--p = '0' + digit;
778 /* Now we can format high in the normal manner. However, if
779 the only bits of high that were set were handled by the
780 digit split between low and high, high will now be zero, and
781 we don't want to print extra digits in that case. */
782 if (high)
783 NUMBER_FMT_LOOP (p, high, 8);
786 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
789 /* Called whenever it is safe to break a stabs string into multiple
790 .stabs directives. If the current string has exceeded the limit
791 set by DBX_CONTIN_LENGTH, mark the current position in the buffer
792 as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
793 it is a backslash) and a null character. */
794 static inline void
795 stabstr_continue (void)
797 if (DBX_CONTIN_LENGTH > 0
798 && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
799 > DBX_CONTIN_LENGTH)
801 if (DBX_CONTIN_CHAR == '\\')
802 obstack_1grow (&stabstr_ob, '\\');
803 obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
804 obstack_1grow (&stabstr_ob, '\0');
805 stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
808 #define CONTIN stabstr_continue ()
810 /* Macro subroutine of dbxout_finish_complex_stabs, which emits
811 all of the arguments to the .stabs directive after the string.
812 Overridden by xcoffout.h. CODE is the stabs code for this symbol;
813 LINE is the source line to write into the desc field (in extended
814 mode); SYM is the symbol itself.
816 ADDR, LABEL, and NUMBER are three different ways to represent the
817 stabs value field. At most one of these should be nonzero.
819 ADDR is used most of the time; it represents the value as an
820 RTL address constant.
822 LABEL is used (currently) only for N_CATCH stabs; it represents
823 the value as a string suitable for assemble_name.
825 NUMBER is used when the value is an offset from an implicit base
826 pointer (e.g. for a stack variable), or an index (e.g. for a
827 register variable). It represents the value as a decimal integer. */
829 #ifndef DBX_FINISH_STABS
830 #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \
831 do { \
832 int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
834 dbxout_int (CODE); \
835 fputs (",0,", asm_out_file); \
836 dbxout_int (line_); \
837 putc (',', asm_out_file); \
838 if (ADDR) \
839 output_addr_const (asm_out_file, ADDR); \
840 else if (LABEL) \
841 assemble_name (asm_out_file, LABEL); \
842 else \
843 dbxout_int (NUMBER); \
844 putc ('\n', asm_out_file); \
845 } while (0)
846 #endif
848 /* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
849 is zero, this has only to emit the close quote and the remainder of
850 the arguments. When it is nonzero, the string has been marshalled in
851 stabstr_ob, and this routine is responsible for breaking it up into
852 DBX_CONTIN_LENGTH-sized chunks.
854 SYM is the DECL of the symbol under consideration; it is used only
855 for its DECL_SOURCE_LINE. The other arguments are all passed directly
856 to DBX_FINISH_STABS; see above for details. */
858 static void
859 dbxout_finish_complex_stabs (tree sym, stab_code_type code,
860 rtx addr, const char *label, int number)
862 int line ATTRIBUTE_UNUSED;
863 char *str;
864 size_t len;
866 line = sym ? DECL_SOURCE_LINE (sym) : 0;
867 if (DBX_CONTIN_LENGTH > 0)
869 char *chunk;
870 size_t chunklen;
872 /* Nul-terminate the growing string, then get its size and
873 address. */
874 obstack_1grow (&stabstr_ob, '\0');
876 len = obstack_object_size (&stabstr_ob);
877 chunk = str = XOBFINISH (&stabstr_ob, char *);
879 /* Within the buffer are a sequence of NUL-separated strings,
880 each of which is to be written out as a separate stab
881 directive. */
882 for (;;)
884 chunklen = strlen (chunk);
885 fwrite (chunk, 1, chunklen, asm_out_file);
886 fputs ("\",", asm_out_file);
888 /* Must add an extra byte to account for the NUL separator. */
889 chunk += chunklen + 1;
890 len -= chunklen + 1;
892 /* Only put a line number on the last stab in the sequence. */
893 DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
894 addr, label, number);
895 if (len == 0)
896 break;
898 fputs (ASM_STABS_OP, asm_out_file);
899 putc ('"', asm_out_file);
901 stabstr_last_contin_point = 0;
903 else
905 /* No continuations - we can put the whole string out at once.
906 It is faster to augment the string with the close quote and
907 comma than to do a two-character fputs. */
908 obstack_grow (&stabstr_ob, "\",", 2);
909 len = obstack_object_size (&stabstr_ob);
910 str = XOBFINISH (&stabstr_ob, char *);
912 fwrite (str, 1, len, asm_out_file);
913 DBX_FINISH_STABS (sym, code, line, addr, label, number);
915 obstack_free (&stabstr_ob, str);
918 #if defined (DBX_DEBUGGING_INFO)
920 static void
921 dbxout_function_end (tree decl ATTRIBUTE_UNUSED)
923 char lscope_label_name[100];
925 /* The Lscope label must be emitted even if we aren't doing anything
926 else; dbxout_block needs it. */
927 switch_to_section (function_section (current_function_decl));
929 /* Convert Lscope into the appropriate format for local labels in case
930 the system doesn't insert underscores in front of user generated
931 labels. */
932 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
933 targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
935 /* The N_FUN tag at the end of the function is a GNU extension,
936 which may be undesirable, and is unnecessary if we do not have
937 named sections. */
938 if (!use_gnu_debug_info_extensions
939 || NO_DBX_FUNCTION_END
940 || !targetm.have_named_sections)
941 return;
943 /* By convention, GCC will mark the end of a function with an N_FUN
944 symbol and an empty string. */
945 if (flag_reorder_blocks_and_partition)
947 dbxout_begin_empty_stabs (N_FUN);
948 dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label,
949 crtl->subsections.hot_section_label);
950 dbxout_begin_empty_stabs (N_FUN);
951 dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label,
952 crtl->subsections.cold_section_label);
954 else
956 char begin_label[20];
957 /* Reference current function start using LFBB. */
958 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
959 dbxout_begin_empty_stabs (N_FUN);
960 dbxout_stab_value_label_diff (lscope_label_name, begin_label);
963 if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
964 dbxout_stabd (N_ENSYM, 0);
966 #endif /* DBX_DEBUGGING_INFO */
968 /* Get lang description for N_SO stab. */
969 static unsigned int ATTRIBUTE_UNUSED
970 get_lang_number (void)
972 const char *language_string = lang_hooks.name;
974 if (strcmp (language_string, "GNU C") == 0)
975 return N_SO_C;
976 else if (strcmp (language_string, "GNU C++") == 0)
977 return N_SO_CC;
978 else if (strcmp (language_string, "GNU F77") == 0)
979 return N_SO_FORTRAN;
980 else if (strcmp (language_string, "GNU Fortran") == 0)
981 return N_SO_FORTRAN90; /* CHECKME */
982 else if (strcmp (language_string, "GNU Pascal") == 0)
983 return N_SO_PASCAL;
984 else if (strcmp (language_string, "GNU Objective-C") == 0)
985 return N_SO_OBJC;
986 else if (strcmp (language_string, "GNU Objective-C++") == 0)
987 return N_SO_OBJCPLUS;
988 else
989 return 0;
993 static bool
994 is_fortran (void)
996 unsigned int lang = get_lang_number ();
998 return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90);
1001 /* At the beginning of compilation, start writing the symbol table.
1002 Initialize `typevec' and output the standard data types of C. */
1004 static void
1005 dbxout_init (const char *input_file_name)
1007 char ltext_label_name[100];
1008 bool used_ltext_label_name = false;
1009 tree syms = lang_hooks.decls.getdecls ();
1010 const char *mapped_name;
1012 typevec_len = 100;
1013 typevec = ggc_alloc_cleared_vec_typeinfo (typevec_len);
1015 /* stabstr_ob contains one string, which will be just fine with
1016 1-byte alignment. */
1017 obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
1019 /* Convert Ltext into the appropriate format for local labels in case
1020 the system doesn't insert underscores in front of user generated
1021 labels. */
1022 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
1024 /* Put the current working directory in an N_SO symbol. */
1025 if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
1027 static const char *cwd;
1029 if (!cwd)
1031 cwd = get_src_pwd ();
1032 if (cwd[0] == '\0')
1033 cwd = "/";
1034 else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
1035 cwd = concat (cwd, "/", NULL);
1036 cwd = remap_debug_filename (cwd);
1038 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
1039 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
1040 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1041 dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
1042 dbxout_stab_value_label (ltext_label_name);
1043 used_ltext_label_name = true;
1044 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1047 mapped_name = remap_debug_filename (input_file_name);
1048 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1049 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, mapped_name);
1050 #else
1051 dbxout_begin_simple_stabs_desc (mapped_name, N_SO, get_lang_number ());
1052 dbxout_stab_value_label (ltext_label_name);
1053 used_ltext_label_name = true;
1054 #endif
1056 if (used_ltext_label_name)
1058 switch_to_section (text_section);
1059 targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1062 /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1063 The string used is historical. */
1064 #ifndef NO_DBX_GCC_MARKER
1065 dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1066 dbxout_stab_value_zero ();
1067 #endif
1069 base_input_file = lastfile = input_file_name;
1071 next_type_number = 1;
1073 #ifdef DBX_USE_BINCL
1074 current_file = XNEW (struct dbx_file);
1075 current_file->next = NULL;
1076 current_file->file_number = 0;
1077 current_file->next_type_number = 1;
1078 next_file_number = 1;
1079 current_file->prev = NULL;
1080 current_file->bincl_status = BINCL_NOT_REQUIRED;
1081 current_file->pending_bincl_name = NULL;
1082 #endif
1084 /* Get all permanent types that have typedef names, and output them
1085 all, except for those already output. Some language front ends
1086 put these declarations in the top-level scope; some do not;
1087 the latter are responsible for calling debug_hooks->type_decl from
1088 their record_builtin_type function. */
1089 dbxout_typedefs (syms);
1091 if (preinit_symbols)
1093 tree t;
1094 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1095 dbxout_symbol (TREE_VALUE (t), 0);
1096 preinit_symbols = 0;
1100 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
1102 static void
1103 dbxout_typedefs (tree syms)
1105 for (; syms != NULL_TREE; syms = DECL_CHAIN (syms))
1107 if (TREE_CODE (syms) == TYPE_DECL)
1109 tree type = TREE_TYPE (syms);
1110 if (TYPE_NAME (type)
1111 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1112 && COMPLETE_OR_VOID_TYPE_P (type)
1113 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
1114 dbxout_symbol (TYPE_NAME (type), 0);
1119 #ifdef DBX_USE_BINCL
1120 /* Emit BINCL stab using given name. */
1121 static void
1122 emit_bincl_stab (const char *name)
1124 dbxout_begin_simple_stabs (name, N_BINCL);
1125 dbxout_stab_value_zero ();
1128 /* If there are pending bincls then it is time to emit all of them. */
1130 static inline void
1131 emit_pending_bincls_if_required (void)
1133 if (pending_bincls)
1134 emit_pending_bincls ();
1137 /* Emit all pending bincls. */
1139 static void
1140 emit_pending_bincls (void)
1142 struct dbx_file *f = current_file;
1144 /* Find first pending bincl. */
1145 while (f->bincl_status == BINCL_PENDING)
1146 f = f->next;
1148 /* Now emit all bincls. */
1149 f = f->prev;
1151 while (f)
1153 if (f->bincl_status == BINCL_PENDING)
1155 emit_bincl_stab (f->pending_bincl_name);
1157 /* Update file number and status. */
1158 f->file_number = next_file_number++;
1159 f->bincl_status = BINCL_PROCESSED;
1161 if (f == current_file)
1162 break;
1163 f = f->prev;
1166 /* All pending bincls have been emitted. */
1167 pending_bincls = 0;
1170 #else
1172 static inline void
1173 emit_pending_bincls_if_required (void) {}
1174 #endif
1176 /* Change to reading from a new source file. Generate a N_BINCL stab. */
1178 static void
1179 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1180 const char *filename ATTRIBUTE_UNUSED)
1182 #ifdef DBX_USE_BINCL
1183 struct dbx_file *n = XNEW (struct dbx_file);
1185 n->next = current_file;
1186 n->next_type_number = 1;
1187 /* Do not assign file number now.
1188 Delay it until we actually emit BINCL. */
1189 n->file_number = 0;
1190 n->prev = NULL;
1191 current_file->prev = n;
1192 n->bincl_status = BINCL_PENDING;
1193 n->pending_bincl_name = remap_debug_filename (filename);
1194 pending_bincls = 1;
1195 current_file = n;
1196 #endif
1199 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
1201 static void
1202 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1204 #ifdef DBX_USE_BINCL
1205 /* Emit EINCL stab only if BINCL is not pending. */
1206 if (current_file->bincl_status == BINCL_PROCESSED)
1208 dbxout_begin_stabn (N_EINCL);
1209 dbxout_stab_value_zero ();
1211 current_file->bincl_status = BINCL_NOT_REQUIRED;
1212 current_file = current_file->next;
1213 #endif
1216 /* Handle a few odd cases that occur when trying to make PCH files work. */
1218 static void
1219 dbxout_handle_pch (unsigned at_end)
1221 if (! at_end)
1223 /* When using the PCH, this file will be included, so we need to output
1224 a BINCL. */
1225 dbxout_start_source_file (0, lastfile);
1227 /* The base file when using the PCH won't be the same as
1228 the base file when it's being generated. */
1229 lastfile = NULL;
1231 else
1233 /* ... and an EINCL. */
1234 dbxout_end_source_file (0);
1236 /* Deal with cases where 'lastfile' was never actually changed. */
1237 lastfile_is_base = lastfile == NULL;
1241 #if defined (DBX_DEBUGGING_INFO)
1243 static void dbxout_block (tree, int, tree);
1245 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
1247 static void
1248 dbxout_source_file (const char *filename)
1250 if (lastfile == 0 && lastfile_is_base)
1252 lastfile = base_input_file;
1253 lastfile_is_base = 0;
1256 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
1258 /* Don't change section amid function. */
1259 if (current_function_decl == NULL_TREE)
1260 switch_to_section (text_section);
1262 dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL);
1263 dbxout_stab_value_internal_label ("Ltext", &source_label_number);
1264 lastfile = filename;
1268 /* Output N_BNSYM, line number symbol entry, and local symbol at
1269 function scope */
1271 static void
1272 dbxout_begin_prologue (unsigned int lineno, const char *filename)
1274 if (use_gnu_debug_info_extensions
1275 && !NO_DBX_FUNCTION_END
1276 && !NO_DBX_BNSYM_ENSYM
1277 && !flag_debug_only_used_symbols)
1278 dbxout_stabd (N_BNSYM, 0);
1280 /* pre-increment the scope counter */
1281 scope_labelno++;
1283 dbxout_source_line (lineno, filename, 0, true);
1284 /* Output function begin block at function scope, referenced
1285 by dbxout_block, dbxout_source_line and dbxout_function_end. */
1286 emit_pending_bincls_if_required ();
1287 targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno);
1290 /* Output a line number symbol entry for source file FILENAME and line
1291 number LINENO. */
1293 static void
1294 dbxout_source_line (unsigned int lineno, const char *filename,
1295 int discriminator ATTRIBUTE_UNUSED,
1296 bool is_stmt ATTRIBUTE_UNUSED)
1298 dbxout_source_file (filename);
1300 #ifdef DBX_OUTPUT_SOURCE_LINE
1301 DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
1302 #else
1303 if (DBX_LINES_FUNCTION_RELATIVE)
1305 char begin_label[20];
1306 dbxout_begin_stabn_sline (lineno);
1307 /* Reference current function start using LFBB. */
1308 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
1309 dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
1310 begin_label);
1312 else
1313 dbxout_stabd (N_SLINE, lineno);
1314 #endif
1317 /* Describe the beginning of an internal block within a function. */
1319 static void
1320 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1322 emit_pending_bincls_if_required ();
1323 targetm.asm_out.internal_label (asm_out_file, "LBB", n);
1326 /* Describe the end line-number of an internal block within a function. */
1328 static void
1329 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1331 emit_pending_bincls_if_required ();
1332 targetm.asm_out.internal_label (asm_out_file, "LBE", n);
1335 /* Output dbx data for a function definition.
1336 This includes a definition of the function name itself (a symbol),
1337 definitions of the parameters (locating them in the parameter list)
1338 and then output the block that makes up the function's body
1339 (including all the auto variables of the function). */
1341 static void
1342 dbxout_function_decl (tree decl)
1344 emit_pending_bincls_if_required ();
1345 #ifndef DBX_FUNCTION_FIRST
1346 dbxout_begin_function (decl);
1347 #endif
1348 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1349 dbxout_function_end (decl);
1352 #endif /* DBX_DEBUGGING_INFO */
1354 /* Debug information for a global DECL. Called from toplev.c after
1355 compilation proper has finished. */
1356 static void
1357 dbxout_global_decl (tree decl)
1359 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
1361 int saved_tree_used = TREE_USED (decl);
1362 TREE_USED (decl) = 1;
1363 dbxout_symbol (decl, 0);
1364 TREE_USED (decl) = saved_tree_used;
1368 /* This is just a function-type adapter; dbxout_symbol does exactly
1369 what we want but returns an int. */
1370 static void
1371 dbxout_type_decl (tree decl, int local)
1373 dbxout_symbol (decl, local);
1376 /* At the end of compilation, finish writing the symbol table.
1377 The default is to call debug_free_queue but do nothing else. */
1379 static void
1380 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
1382 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1383 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1384 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1386 switch_to_section (text_section);
1387 dbxout_begin_empty_stabs (N_SO);
1388 dbxout_stab_value_internal_label ("Letext", 0);
1390 #endif
1391 debug_free_queue ();
1394 /* Output the index of a type. */
1396 static void
1397 dbxout_type_index (tree type)
1399 #ifndef DBX_USE_BINCL
1400 stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1401 #else
1402 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1403 stabstr_C ('(');
1404 stabstr_D (t->file_number);
1405 stabstr_C (',');
1406 stabstr_D (t->type_number);
1407 stabstr_C (')');
1408 #endif
1413 /* Used in several places: evaluates to '0' for a private decl,
1414 '1' for a protected decl, '2' for a public decl. */
1415 #define DECL_ACCESSIBILITY_CHAR(DECL) \
1416 (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1418 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
1419 This must be a separate function because anonymous unions require
1420 recursive calls. */
1422 static void
1423 dbxout_type_fields (tree type)
1425 tree tem;
1427 /* Output the name, type, position (in bits), size (in bits) of each
1428 field that we can support. */
1429 for (tem = TYPE_FIELDS (type); tem; tem = DECL_CHAIN (tem))
1431 /* If one of the nodes is an error_mark or its type is then
1432 return early. */
1433 if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
1434 return;
1436 /* Omit here local type decls until we know how to support them. */
1437 if (TREE_CODE (tem) == TYPE_DECL
1438 /* Omit here the nameless fields that are used to skip bits. */
1439 || DECL_IGNORED_P (tem)
1440 /* Omit fields whose position or size are variable or too large to
1441 represent. */
1442 || (TREE_CODE (tem) == FIELD_DECL
1443 && (! host_integerp (bit_position (tem), 0)
1444 || ! DECL_SIZE (tem)
1445 || ! host_integerp (DECL_SIZE (tem), 1))))
1446 continue;
1448 else if (TREE_CODE (tem) != CONST_DECL)
1450 /* Continue the line if necessary,
1451 but not before the first field. */
1452 if (tem != TYPE_FIELDS (type))
1453 CONTIN;
1455 if (DECL_NAME (tem))
1456 stabstr_I (DECL_NAME (tem));
1457 stabstr_C (':');
1459 if (use_gnu_debug_info_extensions
1460 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1461 || TREE_CODE (tem) != FIELD_DECL))
1463 stabstr_C ('/');
1464 stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
1467 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
1468 && DECL_BIT_FIELD_TYPE (tem))
1469 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
1471 if (TREE_CODE (tem) == VAR_DECL)
1473 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
1475 tree name = DECL_ASSEMBLER_NAME (tem);
1477 stabstr_C (':');
1478 stabstr_I (name);
1479 stabstr_C (';');
1481 else
1482 /* If TEM is non-static, GDB won't understand it. */
1483 stabstr_S (",0,0;");
1485 else
1487 stabstr_C (',');
1488 stabstr_D (int_bit_position (tem));
1489 stabstr_C (',');
1490 stabstr_D (tree_low_cst (DECL_SIZE (tem), 1));
1491 stabstr_C (';');
1497 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1498 method described DECL. */
1500 static void
1501 dbxout_type_method_1 (tree decl)
1503 char c1 = 'A', c2;
1505 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1506 c2 = '?';
1507 else /* it's a METHOD_TYPE. */
1509 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1510 /* A for normal functions.
1511 B for `const' member functions.
1512 C for `volatile' member functions.
1513 D for `const volatile' member functions. */
1514 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1515 c1 += 1;
1516 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1517 c1 += 2;
1519 if (DECL_VINDEX (decl))
1520 c2 = '*';
1521 else
1522 c2 = '.';
1525 /* ??? Output the mangled name, which contains an encoding of the
1526 method's type signature. May not be necessary anymore. */
1527 stabstr_C (':');
1528 stabstr_I (DECL_ASSEMBLER_NAME (decl));
1529 stabstr_C (';');
1530 stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1531 stabstr_C (c1);
1532 stabstr_C (c2);
1534 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1536 stabstr_D (tree_low_cst (DECL_VINDEX (decl), 0));
1537 stabstr_C (';');
1538 dbxout_type (DECL_CONTEXT (decl), 0);
1539 stabstr_C (';');
1543 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1544 in TYPE. */
1546 static void
1547 dbxout_type_methods (tree type)
1549 /* C++: put out the method names and their parameter lists */
1550 tree methods = TYPE_METHODS (type);
1551 tree fndecl;
1552 tree last;
1554 if (methods == NULL_TREE)
1555 return;
1557 if (TREE_CODE (methods) != TREE_VEC)
1558 fndecl = methods;
1559 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1560 fndecl = TREE_VEC_ELT (methods, 0);
1561 else
1562 fndecl = TREE_VEC_ELT (methods, 1);
1564 while (fndecl)
1566 int need_prefix = 1;
1568 /* Group together all the methods for the same operation.
1569 These differ in the types of the arguments. */
1570 for (last = NULL_TREE;
1571 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1572 fndecl = DECL_CHAIN (fndecl))
1573 /* Output the name of the field (after overloading), as
1574 well as the name of the field before overloading, along
1575 with its parameter list */
1577 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1578 include TEMPLATE_DECLs.) The debugger doesn't know what
1579 to do with such entities anyhow. */
1580 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1581 continue;
1583 CONTIN;
1585 last = fndecl;
1587 /* Also ignore abstract methods; those are only interesting to
1588 the DWARF backends. */
1589 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1590 continue;
1592 /* Redundantly output the plain name, since that's what gdb
1593 expects. */
1594 if (need_prefix)
1596 stabstr_I (DECL_NAME (fndecl));
1597 stabstr_S ("::");
1598 need_prefix = 0;
1601 dbxout_type (TREE_TYPE (fndecl), 0);
1602 dbxout_type_method_1 (fndecl);
1604 if (!need_prefix)
1605 stabstr_C (';');
1609 /* Emit a "range" type specification, which has the form:
1610 "r<index type>;<lower bound>;<upper bound>;".
1611 TYPE is an INTEGER_TYPE, LOW and HIGH are the bounds. */
1613 static void
1614 dbxout_range_type (tree type, tree low, tree high)
1616 stabstr_C ('r');
1617 if (TREE_TYPE (type))
1618 dbxout_type (TREE_TYPE (type), 0);
1619 else if (TREE_CODE (type) != INTEGER_TYPE)
1620 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1621 else
1623 /* Traditionally, we made sure 'int' was type 1, and builtin types
1624 were defined to be sub-ranges of int. Unfortunately, this
1625 does not allow us to distinguish true sub-ranges from integer
1626 types. So, instead we define integer (non-sub-range) types as
1627 sub-ranges of themselves. This matters for Chill. If this isn't
1628 a subrange type, then we want to define it in terms of itself.
1629 However, in C, this may be an anonymous integer type, and we don't
1630 want to emit debug info referring to it. Just calling
1631 dbxout_type_index won't work anyways, because the type hasn't been
1632 defined yet. We make this work for both cases by checked to see
1633 whether this is a defined type, referring to it if it is, and using
1634 'int' otherwise. */
1635 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1636 dbxout_type_index (type);
1637 else
1638 dbxout_type_index (integer_type_node);
1641 stabstr_C (';');
1642 if (low && host_integerp (low, 0))
1644 if (print_int_cst_bounds_in_octal_p (type, low, high))
1645 stabstr_O (low);
1646 else
1647 stabstr_D (tree_low_cst (low, 0));
1649 else
1650 stabstr_C ('0');
1652 stabstr_C (';');
1653 if (high && host_integerp (high, 0))
1655 if (print_int_cst_bounds_in_octal_p (type, low, high))
1656 stabstr_O (high);
1657 else
1658 stabstr_D (tree_low_cst (high, 0));
1659 stabstr_C (';');
1661 else
1662 stabstr_S ("-1;");
1666 /* Output a reference to a type. If the type has not yet been
1667 described in the dbx output, output its definition now.
1668 For a type already defined, just refer to its definition
1669 using the type number.
1671 If FULL is nonzero, and the type has been described only with
1672 a forward-reference, output the definition now.
1673 If FULL is zero in this case, just refer to the forward-reference
1674 using the number previously allocated. */
1676 static void
1677 dbxout_type (tree type, int full)
1679 static int anonymous_type_number = 0;
1680 bool vector_type = false;
1681 tree tem, main_variant, low, high;
1683 if (TREE_CODE (type) == VECTOR_TYPE)
1685 /* The frontend feeds us a representation for the vector as a struct
1686 containing an array. Pull out the array type. */
1687 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1688 vector_type = true;
1691 if (TREE_CODE (type) == INTEGER_TYPE)
1693 if (TREE_TYPE (type) == 0)
1695 low = TYPE_MIN_VALUE (type);
1696 high = TYPE_MAX_VALUE (type);
1699 else if (subrange_type_for_debug_p (type, &low, &high))
1702 /* If this is a subtype that should not be emitted as a subrange type,
1703 use the base type. */
1704 else
1706 type = TREE_TYPE (type);
1707 low = TYPE_MIN_VALUE (type);
1708 high = TYPE_MAX_VALUE (type);
1712 /* If there was an input error and we don't really have a type,
1713 avoid crashing and write something that is at least valid
1714 by assuming `int'. */
1715 if (type == error_mark_node)
1716 type = integer_type_node;
1717 else
1719 if (TYPE_NAME (type)
1720 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1721 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1722 full = 0;
1725 /* Try to find the "main variant" with the same name. */
1726 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1727 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1728 main_variant = TREE_TYPE (TYPE_NAME (type));
1729 else
1730 main_variant = TYPE_MAIN_VARIANT (type);
1732 /* If we are not using extensions, stabs does not distinguish const and
1733 volatile, so there is no need to make them separate types. */
1734 if (!use_gnu_debug_info_extensions)
1735 type = main_variant;
1737 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1739 /* Type has no dbx number assigned. Assign next available number. */
1740 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1742 /* Make sure type vector is long enough to record about this type. */
1744 if (next_type_number == typevec_len)
1746 typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2);
1747 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1748 typevec_len *= 2;
1751 #ifdef DBX_USE_BINCL
1752 emit_pending_bincls_if_required ();
1753 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1754 = current_file->file_number;
1755 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1756 = current_file->next_type_number++;
1757 #endif
1760 if (flag_debug_only_used_symbols)
1762 if ((TREE_CODE (type) == RECORD_TYPE
1763 || TREE_CODE (type) == UNION_TYPE
1764 || TREE_CODE (type) == QUAL_UNION_TYPE
1765 || TREE_CODE (type) == ENUMERAL_TYPE)
1766 && TYPE_STUB_DECL (type)
1767 && DECL_P (TYPE_STUB_DECL (type))
1768 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1769 debug_queue_symbol (TYPE_STUB_DECL (type));
1770 else if (TYPE_NAME (type)
1771 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1772 debug_queue_symbol (TYPE_NAME (type));
1775 /* Output the number of this type, to refer to it. */
1776 dbxout_type_index (type);
1778 #ifdef DBX_TYPE_DEFINED
1779 if (DBX_TYPE_DEFINED (type))
1780 return;
1781 #endif
1783 /* If this type's definition has been output or is now being output,
1784 that is all. */
1786 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1788 case TYPE_UNSEEN:
1789 break;
1790 case TYPE_XREF:
1791 /* If we have already had a cross reference,
1792 and either that's all we want or that's the best we could do,
1793 don't repeat the cross reference.
1794 Sun dbx crashes if we do. */
1795 if (! full || !COMPLETE_TYPE_P (type)
1796 /* No way in DBX fmt to describe a variable size. */
1797 || ! host_integerp (TYPE_SIZE (type), 1))
1798 return;
1799 break;
1800 case TYPE_DEFINED:
1801 return;
1804 #ifdef DBX_NO_XREFS
1805 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1806 leave the type-number completely undefined rather than output
1807 a cross-reference. If we have already used GNU debug info extensions,
1808 then it is OK to output a cross reference. This is necessary to get
1809 proper C++ debug output. */
1810 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1811 || TREE_CODE (type) == QUAL_UNION_TYPE
1812 || TREE_CODE (type) == ENUMERAL_TYPE)
1813 && ! use_gnu_debug_info_extensions)
1814 /* We must use the same test here as we use twice below when deciding
1815 whether to emit a cross-reference. */
1816 if ((TYPE_NAME (type) != 0
1817 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1818 && DECL_IGNORED_P (TYPE_NAME (type)))
1819 && !full)
1820 || !COMPLETE_TYPE_P (type)
1821 /* No way in DBX fmt to describe a variable size. */
1822 || ! host_integerp (TYPE_SIZE (type), 1))
1824 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1825 return;
1827 #endif
1829 /* Output a definition now. */
1830 stabstr_C ('=');
1832 /* Mark it as defined, so that if it is self-referent
1833 we will not get into an infinite recursion of definitions. */
1835 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1837 /* If this type is a variant of some other, hand off. Types with
1838 different names are usefully distinguished. We only distinguish
1839 cv-qualified types if we're using extensions. */
1840 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1842 stabstr_C ('k');
1843 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1844 return;
1846 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1848 stabstr_C ('B');
1849 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1850 return;
1852 else if (main_variant != TYPE_MAIN_VARIANT (type))
1854 if (flag_debug_only_used_symbols)
1856 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1858 if ((TREE_CODE (orig_type) == RECORD_TYPE
1859 || TREE_CODE (orig_type) == UNION_TYPE
1860 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1861 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1862 && TYPE_STUB_DECL (orig_type)
1863 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1864 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1866 /* 'type' is a typedef; output the type it refers to. */
1867 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1868 return;
1870 /* else continue. */
1872 switch (TREE_CODE (type))
1874 case VOID_TYPE:
1875 case LANG_TYPE:
1876 /* For a void type, just define it as itself; i.e., "5=5".
1877 This makes us consider it defined
1878 without saying what it is. The debugger will make it
1879 a void type when the reference is seen, and nothing will
1880 ever override that default. */
1881 dbxout_type_index (type);
1882 break;
1884 case INTEGER_TYPE:
1885 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1887 /* Output the type `char' as a subrange of itself!
1888 I don't understand this definition, just copied it
1889 from the output of pcc.
1890 This used to use `r2' explicitly and we used to
1891 take care to make sure that `char' was type number 2. */
1892 stabstr_C ('r');
1893 dbxout_type_index (type);
1894 stabstr_S (";0;127;");
1897 /* If this is a subtype of another integer type, always prefer to
1898 write it as a subtype. */
1899 else if (TREE_TYPE (type) != 0
1900 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1902 /* If the size is non-standard, say what it is if we can use
1903 GDB extensions. */
1905 if (use_gnu_debug_info_extensions
1906 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1908 stabstr_S ("@s");
1909 stabstr_D (TYPE_PRECISION (type));
1910 stabstr_C (';');
1913 dbxout_range_type (type, low, high);
1916 else
1918 /* If the size is non-standard, say what it is if we can use
1919 GDB extensions. */
1921 if (use_gnu_debug_info_extensions
1922 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1924 stabstr_S ("@s");
1925 stabstr_D (TYPE_PRECISION (type));
1926 stabstr_C (';');
1929 if (print_int_cst_bounds_in_octal_p (type, low, high))
1931 stabstr_C ('r');
1933 /* If this type derives from another type, output type index of
1934 parent type. This is particularly important when parent type
1935 is an enumerated type, because not generating the parent type
1936 index would transform the definition of this enumerated type
1937 into a plain unsigned type. */
1938 if (TREE_TYPE (type) != 0)
1939 dbxout_type_index (TREE_TYPE (type));
1940 else
1941 dbxout_type_index (type);
1943 stabstr_C (';');
1944 stabstr_O (low);
1945 stabstr_C (';');
1946 stabstr_O (high);
1947 stabstr_C (';');
1950 else
1951 /* Output other integer types as subranges of `int'. */
1952 dbxout_range_type (type, low, high);
1955 break;
1957 case REAL_TYPE:
1958 case FIXED_POINT_TYPE:
1959 /* This used to say `r1' and we used to take care
1960 to make sure that `int' was type number 1. */
1961 stabstr_C ('r');
1962 dbxout_type_index (integer_type_node);
1963 stabstr_C (';');
1964 stabstr_D (int_size_in_bytes (type));
1965 stabstr_S (";0;");
1966 break;
1968 case BOOLEAN_TYPE:
1969 if (use_gnu_debug_info_extensions)
1971 stabstr_S ("@s");
1972 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1973 stabstr_S (";-16;");
1975 else /* Define as enumeral type (False, True) */
1976 stabstr_S ("eFalse:0,True:1,;");
1977 break;
1979 case COMPLEX_TYPE:
1980 /* Differs from the REAL_TYPE by its new data type number.
1981 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
1982 codes since gdb doesn't care anyway. */
1984 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1986 stabstr_S ("R3;");
1987 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
1988 stabstr_S (";0;");
1990 else
1992 /* Output a complex integer type as a structure,
1993 pending some other way to do it. */
1994 stabstr_C ('s');
1995 stabstr_D (int_size_in_bytes (type));
1997 stabstr_S ("real:");
1998 dbxout_type (TREE_TYPE (type), 0);
1999 stabstr_S (",0,");
2000 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2002 stabstr_S (";imag:");
2003 dbxout_type (TREE_TYPE (type), 0);
2004 stabstr_C (',');
2005 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2006 stabstr_C (',');
2007 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
2008 stabstr_S (";;");
2010 break;
2012 case ARRAY_TYPE:
2013 /* Make arrays of packed bits look like bitstrings for chill. */
2014 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
2016 stabstr_S ("@s");
2017 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2018 stabstr_S (";@S;S");
2019 dbxout_type (TYPE_DOMAIN (type), 0);
2020 break;
2023 if (use_gnu_debug_info_extensions && vector_type)
2024 stabstr_S ("@V;");
2026 /* Output "a" followed by a range type definition
2027 for the index type of the array
2028 followed by a reference to the target-type.
2029 ar1;0;N;M for a C array of type M and size N+1. */
2030 /* Check if a character string type, which in Chill is
2031 different from an array of characters. */
2032 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
2034 stabstr_S ("@S;");
2036 tem = TYPE_DOMAIN (type);
2037 if (tem == NULL)
2039 stabstr_S ("ar");
2040 dbxout_type_index (integer_type_node);
2041 stabstr_S (";0;-1;");
2043 else
2045 stabstr_C ('a');
2046 dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem));
2049 dbxout_type (TREE_TYPE (type), 0);
2050 break;
2052 case RECORD_TYPE:
2053 case UNION_TYPE:
2054 case QUAL_UNION_TYPE:
2056 tree binfo = TYPE_BINFO (type);
2058 /* Output a structure type. We must use the same test here as we
2059 use in the DBX_NO_XREFS case above. */
2060 if ((TYPE_NAME (type) != 0
2061 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2062 && DECL_IGNORED_P (TYPE_NAME (type)))
2063 && !full)
2064 || !COMPLETE_TYPE_P (type)
2065 /* No way in DBX fmt to describe a variable size. */
2066 || ! host_integerp (TYPE_SIZE (type), 1))
2068 /* If the type is just a cross reference, output one
2069 and mark the type as partially described.
2070 If it later becomes defined, we will output
2071 its real definition.
2072 If the type has a name, don't nest its definition within
2073 another type's definition; instead, output an xref
2074 and let the definition come when the name is defined. */
2075 stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2076 if (TYPE_NAME (type) != 0
2077 /* The C frontend creates for anonymous variable length
2078 records/unions TYPE_NAME with DECL_NAME NULL. */
2079 && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
2080 || DECL_NAME (TYPE_NAME (type))))
2081 dbxout_type_name (type);
2082 else
2084 stabstr_S ("$$");
2085 stabstr_D (anonymous_type_number++);
2088 stabstr_C (':');
2089 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2090 break;
2093 /* Identify record or union, and print its size. */
2094 stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2095 stabstr_D (int_size_in_bytes (type));
2097 if (binfo)
2099 int i;
2100 tree child;
2101 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
2103 if (use_gnu_debug_info_extensions)
2105 if (BINFO_N_BASE_BINFOS (binfo))
2107 stabstr_C ('!');
2108 stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2109 stabstr_C (',');
2112 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2114 tree access = (accesses ? VEC_index (tree, accesses, i)
2115 : access_public_node);
2117 if (use_gnu_debug_info_extensions)
2119 stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2120 stabstr_C (access == access_public_node ? '2' :
2121 access == access_protected_node
2122 ? '1' :'0');
2123 if (BINFO_VIRTUAL_P (child)
2124 && (strcmp (lang_hooks.name, "GNU C++") == 0
2125 || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
2126 /* For a virtual base, print the (negative)
2127 offset within the vtable where we must look
2128 to find the necessary adjustment. */
2129 stabstr_D
2130 (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2131 * BITS_PER_UNIT);
2132 else
2133 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2134 * BITS_PER_UNIT);
2135 stabstr_C (',');
2136 dbxout_type (BINFO_TYPE (child), 0);
2137 stabstr_C (';');
2139 else
2141 /* Print out the base class information with
2142 fields which have the same names at the types
2143 they hold. */
2144 dbxout_type_name (BINFO_TYPE (child));
2145 stabstr_C (':');
2146 dbxout_type (BINFO_TYPE (child), full);
2147 stabstr_C (',');
2148 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2149 * BITS_PER_UNIT);
2150 stabstr_C (',');
2151 stabstr_D
2152 (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2153 * BITS_PER_UNIT);
2154 stabstr_C (';');
2160 /* Write out the field declarations. */
2161 dbxout_type_fields (type);
2162 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2164 dbxout_type_methods (type);
2167 stabstr_C (';');
2169 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2170 /* Avoid the ~ if we don't really need it--it confuses dbx. */
2171 && TYPE_VFIELD (type))
2174 /* We need to write out info about what field this class
2175 uses as its "main" vtable pointer field, because if this
2176 field is inherited from a base class, GDB cannot necessarily
2177 figure out which field it's using in time. */
2178 stabstr_S ("~%");
2179 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2180 stabstr_C (';');
2182 break;
2184 case ENUMERAL_TYPE:
2185 /* We must use the same test here as we use in the DBX_NO_XREFS case
2186 above. We simplify it a bit since an enum will never have a variable
2187 size. */
2188 if ((TYPE_NAME (type) != 0
2189 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2190 && DECL_IGNORED_P (TYPE_NAME (type)))
2191 && !full)
2192 || !COMPLETE_TYPE_P (type))
2194 stabstr_S ("xe");
2195 dbxout_type_name (type);
2196 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2197 stabstr_C (':');
2198 return;
2200 if (use_gnu_debug_info_extensions
2201 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2203 stabstr_S ("@s");
2204 stabstr_D (TYPE_PRECISION (type));
2205 stabstr_C (';');
2208 stabstr_C ('e');
2209 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2211 tree value = TREE_VALUE (tem);
2213 stabstr_I (TREE_PURPOSE (tem));
2214 stabstr_C (':');
2216 if (TREE_CODE (value) == CONST_DECL)
2217 value = DECL_INITIAL (value);
2219 if (TREE_INT_CST_HIGH (value) == 0)
2220 stabstr_D (TREE_INT_CST_LOW (value));
2221 else if (TREE_INT_CST_HIGH (value) == -1
2222 && (HOST_WIDE_INT) TREE_INT_CST_LOW (value) < 0)
2223 stabstr_D (TREE_INT_CST_LOW (value));
2224 else
2225 stabstr_O (value);
2227 stabstr_C (',');
2228 if (TREE_CHAIN (tem) != 0)
2229 CONTIN;
2232 stabstr_C (';');
2233 break;
2235 case POINTER_TYPE:
2236 stabstr_C ('*');
2237 dbxout_type (TREE_TYPE (type), 0);
2238 break;
2240 case METHOD_TYPE:
2241 if (use_gnu_debug_info_extensions)
2243 stabstr_C ('#');
2245 /* Write the argument types out longhand. */
2246 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2247 stabstr_C (',');
2248 dbxout_type (TREE_TYPE (type), 0);
2249 dbxout_args (TYPE_ARG_TYPES (type));
2250 stabstr_C (';');
2252 else
2253 /* Treat it as a function type. */
2254 dbxout_type (TREE_TYPE (type), 0);
2255 break;
2257 case OFFSET_TYPE:
2258 if (use_gnu_debug_info_extensions)
2260 stabstr_C ('@');
2261 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2262 stabstr_C (',');
2263 dbxout_type (TREE_TYPE (type), 0);
2265 else
2266 /* Should print as an int, because it is really just an offset. */
2267 dbxout_type (integer_type_node, 0);
2268 break;
2270 case REFERENCE_TYPE:
2271 if (use_gnu_debug_info_extensions)
2273 stabstr_C ('&');
2275 else
2276 stabstr_C ('*');
2277 dbxout_type (TREE_TYPE (type), 0);
2278 break;
2280 case FUNCTION_TYPE:
2281 stabstr_C ('f');
2282 dbxout_type (TREE_TYPE (type), 0);
2283 break;
2285 default:
2286 gcc_unreachable ();
2290 /* Return nonzero if the given type represents an integer whose bounds
2291 should be printed in octal format. */
2293 static bool
2294 print_int_cst_bounds_in_octal_p (tree type, tree low, tree high)
2296 /* If we can use GDB extensions and the size is wider than a long
2297 (the size used by GDB to read them) or we may have trouble writing
2298 the bounds the usual way, write them in octal. Note the test is for
2299 the *target's* size of "long", not that of the host. The host test
2300 is just to make sure we can write it out in case the host wide int
2301 is narrower than the target "long".
2303 For unsigned types, we use octal if they are the same size or larger.
2304 This is because we print the bounds as signed decimal, and hence they
2305 can't span same size unsigned types. */
2307 if (use_gnu_debug_info_extensions
2308 && low && TREE_CODE (low) == INTEGER_CST
2309 && high && TREE_CODE (high) == INTEGER_CST
2310 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2311 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2312 && TYPE_UNSIGNED (type))
2313 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2314 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2315 && TYPE_UNSIGNED (type))))
2316 return TRUE;
2317 else
2318 return FALSE;
2321 /* Output the name of type TYPE, with no punctuation.
2322 Such names can be set up either by typedef declarations
2323 or by struct, enum and union tags. */
2325 static void
2326 dbxout_type_name (tree type)
2328 tree t = TYPE_NAME (type);
2330 gcc_assert (t);
2331 switch (TREE_CODE (t))
2333 case IDENTIFIER_NODE:
2334 break;
2335 case TYPE_DECL:
2336 t = DECL_NAME (t);
2337 break;
2338 default:
2339 gcc_unreachable ();
2342 stabstr_I (t);
2345 /* Output leading leading struct or class names needed for qualifying
2346 type whose scope is limited to a struct or class. */
2348 static void
2349 dbxout_class_name_qualifiers (tree decl)
2351 tree context = decl_type_context (decl);
2353 if (context != NULL_TREE
2354 && TREE_CODE(context) == RECORD_TYPE
2355 && TYPE_NAME (context) != 0
2356 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2357 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2359 tree name = TYPE_NAME (context);
2361 if (TREE_CODE (name) == TYPE_DECL)
2363 dbxout_class_name_qualifiers (name);
2364 name = DECL_NAME (name);
2366 stabstr_I (name);
2367 stabstr_S ("::");
2371 /* This is a specialized subset of expand_expr for use by dbxout_symbol in
2372 evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that
2373 haven't been expanded, or if the expression is getting so complex we won't
2374 be able to represent it in stabs anyway. Returns NULL on failure. */
2376 static rtx
2377 dbxout_expand_expr (tree expr)
2379 switch (TREE_CODE (expr))
2381 case VAR_DECL:
2382 /* We can't handle emulated tls variables, because the address is an
2383 offset to the return value of __emutls_get_address, and there is no
2384 way to express that in stabs. Also, there are name mangling issues
2385 here. We end up with references to undefined symbols if we don't
2386 disable debug info for these variables. */
2387 if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr))
2388 return NULL;
2389 /* FALLTHRU */
2391 case PARM_DECL:
2392 if (DECL_HAS_VALUE_EXPR_P (expr))
2393 return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2394 /* FALLTHRU */
2396 case CONST_DECL:
2397 case RESULT_DECL:
2398 return DECL_RTL_IF_SET (expr);
2400 case INTEGER_CST:
2401 return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2403 case COMPONENT_REF:
2404 case ARRAY_REF:
2405 case ARRAY_RANGE_REF:
2406 case BIT_FIELD_REF:
2408 enum machine_mode mode;
2409 HOST_WIDE_INT bitsize, bitpos;
2410 tree offset, tem;
2411 int volatilep = 0, unsignedp = 0;
2412 rtx x;
2414 tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
2415 &mode, &unsignedp, &volatilep, true);
2417 x = dbxout_expand_expr (tem);
2418 if (x == NULL || !MEM_P (x))
2419 return NULL;
2420 if (offset != NULL)
2422 if (!host_integerp (offset, 0))
2423 return NULL;
2424 x = adjust_address_nv (x, mode, tree_low_cst (offset, 0));
2426 if (bitpos != 0)
2427 x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
2429 return x;
2432 default:
2433 return NULL;
2437 /* Helper function for output_used_types. Queue one entry from the
2438 used types hash to be output. */
2440 static int
2441 output_used_types_helper (void **slot, void *data)
2443 tree type = (tree) *slot;
2444 VEC(tree, heap) **types_p = (VEC(tree, heap) **) data;
2446 if ((TREE_CODE (type) == RECORD_TYPE
2447 || TREE_CODE (type) == UNION_TYPE
2448 || TREE_CODE (type) == QUAL_UNION_TYPE
2449 || TREE_CODE (type) == ENUMERAL_TYPE)
2450 && TYPE_STUB_DECL (type)
2451 && DECL_P (TYPE_STUB_DECL (type))
2452 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
2453 VEC_quick_push (tree, *types_p, TYPE_STUB_DECL (type));
2454 else if (TYPE_NAME (type)
2455 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2456 VEC_quick_push (tree, *types_p, TYPE_NAME (type));
2458 return 1;
2461 /* This is a qsort callback which sorts types and declarations into a
2462 predictable order (types, then declarations, sorted by UID
2463 within). */
2465 static int
2466 output_types_sort (const void *pa, const void *pb)
2468 const tree lhs = *((const tree *)pa);
2469 const tree rhs = *((const tree *)pb);
2471 if (TYPE_P (lhs))
2473 if (TYPE_P (rhs))
2474 return TYPE_UID (lhs) - TYPE_UID (rhs);
2475 else
2476 return 1;
2478 else
2480 if (TYPE_P (rhs))
2481 return -1;
2482 else
2483 return DECL_UID (lhs) - DECL_UID (rhs);
2488 /* Force all types used by this function to be output in debug
2489 information. */
2491 static void
2492 output_used_types (void)
2494 if (cfun && cfun->used_types_hash)
2496 VEC(tree, heap) *types;
2497 int i;
2498 tree type;
2500 types = VEC_alloc (tree, heap, htab_elements (cfun->used_types_hash));
2501 htab_traverse (cfun->used_types_hash, output_used_types_helper, &types);
2503 /* Sort by UID to prevent dependence on hash table ordering. */
2504 qsort (VEC_address (tree, types), VEC_length (tree, types),
2505 sizeof (tree), output_types_sort);
2507 for (i = 0; VEC_iterate (tree, types, i, type); i++)
2508 debug_queue_symbol (type);
2510 VEC_free (tree, heap, types);
2514 /* Output a .stabs for the symbol defined by DECL,
2515 which must be a ..._DECL node in the normal namespace.
2516 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2517 LOCAL is nonzero if the scope is less than the entire file.
2518 Return 1 if a stabs might have been emitted. */
2521 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2523 tree type = TREE_TYPE (decl);
2524 tree context = NULL_TREE;
2525 int result = 0;
2526 rtx decl_rtl;
2528 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2529 ++debug_nesting;
2531 /* Ignore nameless syms, but don't ignore type tags. */
2533 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2534 || DECL_IGNORED_P (decl))
2535 DBXOUT_DECR_NESTING_AND_RETURN (0);
2537 /* If we are to generate only the symbols actually used then such
2538 symbol nodes are flagged with TREE_USED. Ignore any that
2539 aren't flagged as TREE_USED. */
2541 if (flag_debug_only_used_symbols
2542 && (!TREE_USED (decl)
2543 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2544 DBXOUT_DECR_NESTING_AND_RETURN (0);
2546 /* If dbxout_init has not yet run, queue this symbol for later. */
2547 if (!typevec)
2549 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2550 DBXOUT_DECR_NESTING_AND_RETURN (0);
2553 if (flag_debug_only_used_symbols)
2555 tree t;
2557 /* We now have a used symbol. We need to generate the info for
2558 the symbol's type in addition to the symbol itself. These
2559 type symbols are queued to be generated after were done with
2560 the symbol itself (otherwise they would fight over the
2561 stabstr obstack).
2563 Note, because the TREE_TYPE(type) might be something like a
2564 pointer to a named type we need to look for the first name
2565 we see following the TREE_TYPE chain. */
2567 t = type;
2568 while (POINTER_TYPE_P (t))
2569 t = TREE_TYPE (t);
2571 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2572 need special treatment. The TYPE_STUB_DECL field in these
2573 types generally represents the tag name type we want to
2574 output. In addition there could be a typedef type with
2575 a different name. In that case we also want to output
2576 that. */
2578 if (TREE_CODE (t) == RECORD_TYPE
2579 || TREE_CODE (t) == UNION_TYPE
2580 || TREE_CODE (t) == QUAL_UNION_TYPE
2581 || TREE_CODE (t) == ENUMERAL_TYPE)
2583 if (TYPE_STUB_DECL (t)
2584 && TYPE_STUB_DECL (t) != decl
2585 && DECL_P (TYPE_STUB_DECL (t))
2586 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2588 debug_queue_symbol (TYPE_STUB_DECL (t));
2589 if (TYPE_NAME (t)
2590 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2591 && TYPE_NAME (t) != decl
2592 && DECL_P (TYPE_NAME (t)))
2593 debug_queue_symbol (TYPE_NAME (t));
2596 else if (TYPE_NAME (t)
2597 && TYPE_NAME (t) != decl
2598 && DECL_P (TYPE_NAME (t)))
2599 debug_queue_symbol (TYPE_NAME (t));
2602 emit_pending_bincls_if_required ();
2604 switch (TREE_CODE (decl))
2606 case CONST_DECL:
2607 /* Enum values are defined by defining the enum type. */
2608 break;
2610 case FUNCTION_DECL:
2611 decl_rtl = DECL_RTL_IF_SET (decl);
2612 if (!decl_rtl)
2613 DBXOUT_DECR_NESTING_AND_RETURN (0);
2614 if (DECL_EXTERNAL (decl))
2615 break;
2616 /* Don't mention a nested function under its parent. */
2617 context = decl_function_context (decl);
2618 if (context == current_function_decl)
2619 break;
2620 /* Don't mention an inline instance of a nested function. */
2621 if (context && DECL_FROM_INLINE (decl))
2622 break;
2623 if (!MEM_P (decl_rtl)
2624 || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
2625 break;
2627 if (flag_debug_only_used_symbols)
2628 output_used_types ();
2630 dbxout_begin_complex_stabs ();
2631 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2632 stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2633 result = 1;
2635 if (TREE_TYPE (type))
2636 dbxout_type (TREE_TYPE (type), 0);
2637 else
2638 dbxout_type (void_type_node, 0);
2640 /* For a nested function, when that function is compiled,
2641 mention the containing function name
2642 as well as (since dbx wants it) our own assembler-name. */
2643 if (context != 0)
2645 stabstr_C (',');
2646 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2647 stabstr_C (',');
2648 stabstr_I (DECL_NAME (context));
2651 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
2652 break;
2654 case TYPE_DECL:
2655 /* Don't output the same typedef twice.
2656 And don't output what language-specific stuff doesn't want output. */
2657 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2658 DBXOUT_DECR_NESTING_AND_RETURN (0);
2660 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2661 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2663 int fundamental_type_number =
2664 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2666 if (fundamental_type_number != 0)
2668 TREE_ASM_WRITTEN (decl) = 1;
2669 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2670 DBXOUT_DECR_NESTING_AND_RETURN (0);
2673 #endif
2674 FORCE_TEXT;
2675 result = 1;
2677 int tag_needed = 1;
2678 int did_output = 0;
2680 if (DECL_NAME (decl))
2682 /* Nonzero means we must output a tag as well as a typedef. */
2683 tag_needed = 0;
2685 /* Handle the case of a C++ structure or union
2686 where the TYPE_NAME is a TYPE_DECL
2687 which gives both a typedef name and a tag. */
2688 /* dbx requires the tag first and the typedef second. */
2689 if ((TREE_CODE (type) == RECORD_TYPE
2690 || TREE_CODE (type) == UNION_TYPE
2691 || TREE_CODE (type) == QUAL_UNION_TYPE)
2692 && TYPE_NAME (type) == decl
2693 && !use_gnu_debug_info_extensions
2694 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2695 /* Distinguish the implicit typedefs of C++
2696 from explicit ones that might be found in C. */
2697 && DECL_ARTIFICIAL (decl)
2698 /* Do not generate a tag for incomplete records. */
2699 && COMPLETE_TYPE_P (type)
2700 /* Do not generate a tag for records of variable size,
2701 since this type can not be properly described in the
2702 DBX format, and it confuses some tools such as objdump. */
2703 && host_integerp (TYPE_SIZE (type), 1))
2705 tree name = TYPE_NAME (type);
2706 if (TREE_CODE (name) == TYPE_DECL)
2707 name = DECL_NAME (name);
2709 dbxout_begin_complex_stabs ();
2710 stabstr_I (name);
2711 stabstr_S (":T");
2712 dbxout_type (type, 1);
2713 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2714 0, 0, 0);
2717 dbxout_begin_complex_stabs ();
2719 /* Output leading class/struct qualifiers. */
2720 if (use_gnu_debug_info_extensions)
2721 dbxout_class_name_qualifiers (decl);
2723 /* Output typedef name. */
2724 stabstr_I (DECL_NAME (decl));
2725 stabstr_C (':');
2727 /* Short cut way to output a tag also. */
2728 if ((TREE_CODE (type) == RECORD_TYPE
2729 || TREE_CODE (type) == UNION_TYPE
2730 || TREE_CODE (type) == QUAL_UNION_TYPE)
2731 && TYPE_NAME (type) == decl
2732 /* Distinguish the implicit typedefs of C++
2733 from explicit ones that might be found in C. */
2734 && DECL_ARTIFICIAL (decl))
2736 if (use_gnu_debug_info_extensions)
2738 stabstr_C ('T');
2739 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2743 stabstr_C ('t');
2744 dbxout_type (type, 1);
2745 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2746 0, 0, 0);
2747 did_output = 1;
2750 /* Don't output a tag if this is an incomplete type. This prevents
2751 the sun4 Sun OS 4.x dbx from crashing. */
2753 if (tag_needed && TYPE_NAME (type) != 0
2754 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2755 || (DECL_NAME (TYPE_NAME (type)) != 0))
2756 && COMPLETE_TYPE_P (type)
2757 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2759 /* For a TYPE_DECL with no name, but the type has a name,
2760 output a tag.
2761 This is what represents `struct foo' with no typedef. */
2762 /* In C++, the name of a type is the corresponding typedef.
2763 In C, it is an IDENTIFIER_NODE. */
2764 tree name = TYPE_NAME (type);
2765 if (TREE_CODE (name) == TYPE_DECL)
2766 name = DECL_NAME (name);
2768 dbxout_begin_complex_stabs ();
2769 stabstr_I (name);
2770 stabstr_S (":T");
2771 dbxout_type (type, 1);
2772 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2773 did_output = 1;
2776 /* If an enum type has no name, it cannot be referred to, but
2777 we must output it anyway, to record the enumeration
2778 constants. */
2780 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2782 dbxout_begin_complex_stabs ();
2783 /* Some debuggers fail when given NULL names, so give this a
2784 harmless name of " " (Why not "(anon)"?). */
2785 stabstr_S (" :T");
2786 dbxout_type (type, 1);
2787 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2790 /* Prevent duplicate output of a typedef. */
2791 TREE_ASM_WRITTEN (decl) = 1;
2792 break;
2795 case PARM_DECL:
2796 if (DECL_HAS_VALUE_EXPR_P (decl))
2797 decl = DECL_VALUE_EXPR (decl);
2799 /* PARM_DECLs go in their own separate chain and are output by
2800 dbxout_reg_parms and dbxout_parms, except for those that are
2801 disguised VAR_DECLs like Out parameters in Ada. */
2802 gcc_assert (TREE_CODE (decl) == VAR_DECL);
2804 /* ... fall through ... */
2806 case RESULT_DECL:
2807 case VAR_DECL:
2808 /* Don't mention a variable that is external.
2809 Let the file that defines it describe it. */
2810 if (DECL_EXTERNAL (decl))
2811 break;
2813 /* If the variable is really a constant
2814 and not written in memory, inform the debugger.
2816 ??? Why do we skip emitting the type and location in this case? */
2817 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2818 && DECL_INITIAL (decl) != 0
2819 && host_integerp (DECL_INITIAL (decl), 0)
2820 && ! TREE_ASM_WRITTEN (decl)
2821 && (DECL_CONTEXT (decl) == NULL_TREE
2822 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
2823 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
2824 && TREE_PUBLIC (decl) == 0)
2826 /* The sun4 assembler does not grok this. */
2828 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2829 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2831 HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
2833 dbxout_begin_complex_stabs ();
2834 dbxout_symbol_name (decl, NULL, 'c');
2835 stabstr_S ("=i");
2836 stabstr_D (ival);
2837 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2838 DBXOUT_DECR_NESTING;
2839 return 1;
2841 else
2842 break;
2844 /* else it is something we handle like a normal variable. */
2846 decl_rtl = dbxout_expand_expr (decl);
2847 if (!decl_rtl)
2848 DBXOUT_DECR_NESTING_AND_RETURN (0);
2850 decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX);
2851 #ifdef LEAF_REG_REMAP
2852 if (current_function_uses_only_leaf_regs)
2853 leaf_renumber_regs_insn (decl_rtl);
2854 #endif
2856 result = dbxout_symbol_location (decl, type, 0, decl_rtl);
2857 break;
2859 default:
2860 break;
2862 DBXOUT_DECR_NESTING;
2863 return result;
2866 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2867 Add SUFFIX to its name, if SUFFIX is not 0.
2868 Describe the variable as residing in HOME
2869 (usually HOME is DECL_RTL (DECL), but not always).
2870 Returns 1 if the stab was really emitted. */
2872 static int
2873 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2875 int letter = 0;
2876 stab_code_type code;
2877 rtx addr = 0;
2878 int number = 0;
2879 int regno = -1;
2881 /* Don't mention a variable at all
2882 if it was completely optimized into nothingness.
2884 If the decl was from an inline function, then its rtl
2885 is not identically the rtl that was used in this
2886 particular compilation. */
2887 if (GET_CODE (home) == SUBREG)
2889 rtx value = home;
2891 while (GET_CODE (value) == SUBREG)
2892 value = SUBREG_REG (value);
2893 if (REG_P (value))
2895 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2896 return 0;
2898 home = alter_subreg (&home);
2900 if (REG_P (home))
2902 regno = REGNO (home);
2903 if (regno >= FIRST_PSEUDO_REGISTER)
2904 return 0;
2907 /* The kind-of-variable letter depends on where
2908 the variable is and on the scope of its name:
2909 G and N_GSYM for static storage and global scope,
2910 S for static storage and file scope,
2911 V for static storage and local scope,
2912 for those two, use N_LCSYM if data is in bss segment,
2913 N_STSYM if in data segment, N_FUN otherwise.
2914 (We used N_FUN originally, then changed to N_STSYM
2915 to please GDB. However, it seems that confused ld.
2916 Now GDB has been fixed to like N_FUN, says Kingdon.)
2917 no letter at all, and N_LSYM, for auto variable,
2918 r and N_RSYM for register variable. */
2920 if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2922 if (TREE_PUBLIC (decl))
2924 int offs;
2925 letter = 'G';
2926 code = N_GSYM;
2927 if (NULL != dbxout_common_check (decl, &offs))
2929 letter = 'V';
2930 addr = 0;
2931 number = offs;
2934 else
2936 addr = XEXP (home, 0);
2938 letter = decl_function_context (decl) ? 'V' : 'S';
2940 /* Some ports can transform a symbol ref into a label ref,
2941 because the symbol ref is too far away and has to be
2942 dumped into a constant pool. Alternatively, the symbol
2943 in the constant pool might be referenced by a different
2944 symbol. */
2945 if (GET_CODE (addr) == SYMBOL_REF
2946 && CONSTANT_POOL_ADDRESS_P (addr))
2948 bool marked;
2949 rtx tmp = get_pool_constant_mark (addr, &marked);
2951 if (GET_CODE (tmp) == SYMBOL_REF)
2953 addr = tmp;
2954 if (CONSTANT_POOL_ADDRESS_P (addr))
2955 get_pool_constant_mark (addr, &marked);
2956 else
2957 marked = true;
2959 else if (GET_CODE (tmp) == LABEL_REF)
2961 addr = tmp;
2962 marked = true;
2965 /* If all references to the constant pool were optimized
2966 out, we just ignore the symbol. */
2967 if (!marked)
2968 return 0;
2971 /* This should be the same condition as in assemble_variable, but
2972 we don't have access to dont_output_data here. So, instead,
2973 we rely on the fact that error_mark_node initializers always
2974 end up in bss for C++ and never end up in bss for C. */
2975 if (DECL_INITIAL (decl) == 0
2976 || (!strcmp (lang_hooks.name, "GNU C++")
2977 && DECL_INITIAL (decl) == error_mark_node))
2979 int offs;
2980 code = N_LCSYM;
2981 if (NULL != dbxout_common_check (decl, &offs))
2983 addr = 0;
2984 number = offs;
2985 letter = 'V';
2986 code = N_GSYM;
2989 else if (DECL_IN_TEXT_SECTION (decl))
2990 /* This is not quite right, but it's the closest
2991 of all the codes that Unix defines. */
2992 code = DBX_STATIC_CONST_VAR_CODE;
2993 else
2995 /* Ultrix `as' seems to need this. */
2996 #ifdef DBX_STATIC_STAB_DATA_SECTION
2997 switch_to_section (data_section);
2998 #endif
2999 code = N_STSYM;
3003 else if (regno >= 0)
3005 letter = 'r';
3006 code = N_RSYM;
3007 number = DBX_REGISTER_NUMBER (regno);
3009 else if (MEM_P (home)
3010 && (MEM_P (XEXP (home, 0))
3011 || (REG_P (XEXP (home, 0))
3012 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
3013 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
3014 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3015 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
3016 #endif
3018 /* If the value is indirect by memory or by a register
3019 that isn't the frame pointer
3020 then it means the object is variable-sized and address through
3021 that register or stack slot. DBX has no way to represent this
3022 so all we can do is output the variable as a pointer.
3023 If it's not a parameter, ignore it. */
3025 if (REG_P (XEXP (home, 0)))
3027 letter = 'r';
3028 code = N_RSYM;
3029 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
3030 return 0;
3031 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
3033 else
3035 code = N_LSYM;
3036 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
3037 We want the value of that CONST_INT. */
3038 number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
3041 /* Effectively do build_pointer_type, but don't cache this type,
3042 since it might be temporary whereas the type it points to
3043 might have been saved for inlining. */
3044 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
3045 type = make_node (POINTER_TYPE);
3046 TREE_TYPE (type) = TREE_TYPE (decl);
3048 else if (MEM_P (home)
3049 && REG_P (XEXP (home, 0)))
3051 code = N_LSYM;
3052 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3054 else if (MEM_P (home)
3055 && GET_CODE (XEXP (home, 0)) == PLUS
3056 && CONST_INT_P (XEXP (XEXP (home, 0), 1)))
3058 code = N_LSYM;
3059 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
3060 We want the value of that CONST_INT. */
3061 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3063 else if (MEM_P (home)
3064 && GET_CODE (XEXP (home, 0)) == CONST)
3066 /* Handle an obscure case which can arise when optimizing and
3067 when there are few available registers. (This is *always*
3068 the case for i386/i486 targets). The RTL looks like
3069 (MEM (CONST ...)) even though this variable is a local `auto'
3070 or a local `register' variable. In effect, what has happened
3071 is that the reload pass has seen that all assignments and
3072 references for one such a local variable can be replaced by
3073 equivalent assignments and references to some static storage
3074 variable, thereby avoiding the need for a register. In such
3075 cases we're forced to lie to debuggers and tell them that
3076 this variable was itself `static'. */
3077 int offs;
3078 code = N_LCSYM;
3079 letter = 'V';
3080 if (NULL == dbxout_common_check (decl, &offs))
3081 addr = XEXP (XEXP (home, 0), 0);
3082 else
3084 addr = 0;
3085 number = offs;
3086 code = N_GSYM;
3089 else if (GET_CODE (home) == CONCAT)
3091 tree subtype;
3093 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
3094 for example), then there is no easy way to figure out
3095 what SUBTYPE should be. So, we give up. */
3096 if (TREE_CODE (type) != COMPLEX_TYPE)
3097 return 0;
3099 subtype = TREE_TYPE (type);
3101 /* If the variable's storage is in two parts,
3102 output each as a separate stab with a modified name. */
3103 if (WORDS_BIG_ENDIAN)
3104 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
3105 else
3106 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
3108 if (WORDS_BIG_ENDIAN)
3109 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
3110 else
3111 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
3112 return 1;
3114 else
3115 /* Address might be a MEM, when DECL is a variable-sized object.
3116 Or it might be const0_rtx, meaning previous passes
3117 want us to ignore this variable. */
3118 return 0;
3120 /* Ok, start a symtab entry and output the variable name. */
3121 emit_pending_bincls_if_required ();
3122 FORCE_TEXT;
3124 #ifdef DBX_STATIC_BLOCK_START
3125 DBX_STATIC_BLOCK_START (asm_out_file, code);
3126 #endif
3128 dbxout_begin_complex_stabs_noforcetext ();
3129 dbxout_symbol_name (decl, suffix, letter);
3130 dbxout_type (type, 0);
3131 dbxout_finish_complex_stabs (decl, code, addr, 0, number);
3133 #ifdef DBX_STATIC_BLOCK_END
3134 DBX_STATIC_BLOCK_END (asm_out_file, code);
3135 #endif
3136 return 1;
3139 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
3140 Then output LETTER to indicate the kind of location the symbol has. */
3142 static void
3143 dbxout_symbol_name (tree decl, const char *suffix, int letter)
3145 tree name;
3147 if (DECL_CONTEXT (decl)
3148 && (TYPE_P (DECL_CONTEXT (decl))
3149 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
3150 /* One slight hitch: if this is a VAR_DECL which is a class member
3151 or a namespace member, we must put out the mangled name instead of the
3152 DECL_NAME. Note also that static member (variable) names DO NOT begin
3153 with underscores in .stabs directives. */
3154 name = DECL_ASSEMBLER_NAME (decl);
3155 else
3156 /* ...but if we're function-local, we don't want to include the junk
3157 added by ASM_FORMAT_PRIVATE_NAME. */
3158 name = DECL_NAME (decl);
3160 if (name)
3161 stabstr_I (name);
3162 else
3163 stabstr_S ("(anon)");
3165 if (suffix)
3166 stabstr_S (suffix);
3167 stabstr_C (':');
3168 if (letter)
3169 stabstr_C (letter);
3173 /* Output the common block name for DECL in a stabs.
3175 Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair
3176 around each group of symbols in the same .comm area. The N_GSYM stabs
3177 that are emitted only contain the offset in the common area. This routine
3178 emits the N_BCOMM and N_ECOMM stabs. */
3180 static void
3181 dbxout_common_name (tree decl, const char *name, stab_code_type op)
3183 dbxout_begin_complex_stabs ();
3184 stabstr_S (name);
3185 dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0);
3188 /* Check decl to determine whether it is a VAR_DECL destined for storage in a
3189 common area. If it is, the return value will be a non-null string giving
3190 the name of the common storage block it will go into. If non-null, the
3191 value is the offset into the common block for that symbol's storage. */
3193 static const char *
3194 dbxout_common_check (tree decl, int *value)
3196 rtx home;
3197 rtx sym_addr;
3198 const char *name = NULL;
3200 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
3201 it does not have a value (the offset into the common area), or if it
3202 is thread local (as opposed to global) then it isn't common, and shouldn't
3203 be handled as such.
3205 ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs
3206 for thread-local symbols. Can be handled via same mechanism as used
3207 in dwarf2out.c. */
3208 if (TREE_CODE (decl) != VAR_DECL
3209 || !TREE_STATIC(decl)
3210 || !DECL_HAS_VALUE_EXPR_P(decl)
3211 || DECL_THREAD_LOCAL_P (decl)
3212 || !is_fortran ())
3213 return NULL;
3215 home = DECL_RTL (decl);
3216 if (home == NULL_RTX || GET_CODE (home) != MEM)
3217 return NULL;
3219 sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl));
3220 if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM)
3221 return NULL;
3223 sym_addr = XEXP (sym_addr, 0);
3224 if (GET_CODE (sym_addr) == CONST)
3225 sym_addr = XEXP (sym_addr, 0);
3226 if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS)
3227 && DECL_INITIAL (decl) == 0)
3230 /* We have a sym that will go into a common area, meaning that it
3231 will get storage reserved with a .comm/.lcomm assembler pseudo-op.
3233 Determine name of common area this symbol will be an offset into,
3234 and offset into that area. Also retrieve the decl for the area
3235 that the symbol is offset into. */
3236 tree cdecl = NULL;
3238 switch (GET_CODE (sym_addr))
3240 case PLUS:
3241 if (CONST_INT_P (XEXP (sym_addr, 0)))
3243 name =
3244 targetm.strip_name_encoding(XSTR (XEXP (sym_addr, 1), 0));
3245 *value = INTVAL (XEXP (sym_addr, 0));
3246 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1));
3248 else
3250 name =
3251 targetm.strip_name_encoding(XSTR (XEXP (sym_addr, 0), 0));
3252 *value = INTVAL (XEXP (sym_addr, 1));
3253 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0));
3255 break;
3257 case SYMBOL_REF:
3258 name = targetm.strip_name_encoding(XSTR (sym_addr, 0));
3259 *value = 0;
3260 cdecl = SYMBOL_REF_DECL (sym_addr);
3261 break;
3263 default:
3264 error ("common symbol debug info is not structured as "
3265 "symbol+offset");
3268 /* Check area common symbol is offset into. If this is not public, then
3269 it is not a symbol in a common block. It must be a .lcomm symbol, not
3270 a .comm symbol. */
3271 if (cdecl == NULL || !TREE_PUBLIC(cdecl))
3272 name = NULL;
3274 else
3275 name = NULL;
3277 return name;
3280 /* Output definitions of all the decls in a chain. Return nonzero if
3281 anything was output */
3284 dbxout_syms (tree syms)
3286 int result = 0;
3287 const char *comm_prev = NULL;
3288 tree syms_prev = NULL;
3290 while (syms)
3292 int temp, copen, cclos;
3293 const char *comm_new;
3295 /* Check for common symbol, and then progression into a new/different
3296 block of common symbols. Emit closing/opening common bracket if
3297 necessary. */
3298 comm_new = dbxout_common_check (syms, &temp);
3299 copen = comm_new != NULL
3300 && (comm_prev == NULL || strcmp (comm_new, comm_prev));
3301 cclos = comm_prev != NULL
3302 && (comm_new == NULL || strcmp (comm_new, comm_prev));
3303 if (cclos)
3304 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3305 if (copen)
3307 dbxout_common_name (syms, comm_new, N_BCOMM);
3308 syms_prev = syms;
3310 comm_prev = comm_new;
3312 result += dbxout_symbol (syms, 1);
3313 syms = DECL_CHAIN (syms);
3316 if (comm_prev != NULL)
3317 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3319 return result;
3322 /* The following two functions output definitions of function parameters.
3323 Each parameter gets a definition locating it in the parameter list.
3324 Each parameter that is a register variable gets a second definition
3325 locating it in the register.
3327 Printing or argument lists in gdb uses the definitions that
3328 locate in the parameter list. But reference to the variable in
3329 expressions uses preferentially the definition as a register. */
3331 /* Output definitions, referring to storage in the parmlist,
3332 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
3334 void
3335 dbxout_parms (tree parms)
3337 ++debug_nesting;
3338 emit_pending_bincls_if_required ();
3340 for (; parms; parms = DECL_CHAIN (parms))
3341 if (DECL_NAME (parms)
3342 && TREE_TYPE (parms) != error_mark_node
3343 && DECL_RTL_SET_P (parms)
3344 && DECL_INCOMING_RTL (parms))
3346 tree eff_type;
3347 char letter;
3348 stab_code_type code;
3349 int number;
3351 /* Perform any necessary register eliminations on the parameter's rtl,
3352 so that the debugging output will be accurate. */
3353 DECL_INCOMING_RTL (parms)
3354 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
3355 SET_DECL_RTL (parms,
3356 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
3357 #ifdef LEAF_REG_REMAP
3358 if (current_function_uses_only_leaf_regs)
3360 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3361 leaf_renumber_regs_insn (DECL_RTL (parms));
3363 #endif
3365 if (PARM_PASSED_IN_MEMORY (parms))
3367 rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3369 /* ??? Here we assume that the parm address is indexed
3370 off the frame pointer or arg pointer.
3371 If that is not true, we produce meaningless results,
3372 but do not crash. */
3373 if (GET_CODE (inrtl) == PLUS
3374 && CONST_INT_P (XEXP (inrtl, 1)))
3375 number = INTVAL (XEXP (inrtl, 1));
3376 else
3377 number = 0;
3379 code = N_PSYM;
3380 number = DEBUGGER_ARG_OFFSET (number, inrtl);
3381 letter = 'p';
3383 /* It is quite tempting to use TREE_TYPE (parms) instead
3384 of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3385 reports the actual type of the parameter, rather than
3386 the promoted type. This certainly makes GDB's life
3387 easier, at least for some ports. The change is a bad
3388 idea however, since GDB expects to be able access the
3389 type without performing any conversions. So for
3390 example, if we were passing a float to an unprototyped
3391 function, gcc will store a double on the stack, but if
3392 we emit a stab saying the type is a float, then gdb
3393 will only read in a single value, and this will produce
3394 an erroneous value. */
3395 eff_type = DECL_ARG_TYPE (parms);
3397 else if (REG_P (DECL_RTL (parms)))
3399 rtx best_rtl;
3401 /* Parm passed in registers and lives in registers or nowhere. */
3402 code = DBX_REGPARM_STABS_CODE;
3403 letter = DBX_REGPARM_STABS_LETTER;
3405 /* For parms passed in registers, it is better to use the
3406 declared type of the variable, not the type it arrived in. */
3407 eff_type = TREE_TYPE (parms);
3409 /* If parm lives in a register, use that register; pretend
3410 the parm was passed there. It would be more consistent
3411 to describe the register where the parm was passed, but
3412 in practice that register usually holds something else.
3413 If the parm lives nowhere, use the register where it
3414 was passed. */
3415 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3416 best_rtl = DECL_RTL (parms);
3417 else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL)
3418 best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0);
3419 else
3420 best_rtl = DECL_INCOMING_RTL (parms);
3422 number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3424 else if (MEM_P (DECL_RTL (parms))
3425 && REG_P (XEXP (DECL_RTL (parms), 0))
3426 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3427 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3428 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3429 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3430 #endif
3433 /* Parm was passed via invisible reference.
3434 That is, its address was passed in a register.
3435 Output it as if it lived in that register.
3436 The debugger will know from the type
3437 that it was actually passed by invisible reference. */
3439 code = DBX_REGPARM_STABS_CODE;
3441 /* GDB likes this marked with a special letter. */
3442 letter = (use_gnu_debug_info_extensions
3443 ? 'a' : DBX_REGPARM_STABS_LETTER);
3444 eff_type = TREE_TYPE (parms);
3446 /* DECL_RTL looks like (MEM (REG...). Get the register number.
3447 If it is an unallocated pseudo-reg, then use the register where
3448 it was passed instead.
3449 ??? Why is DBX_REGISTER_NUMBER not used here? */
3451 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3452 number = REGNO (XEXP (DECL_RTL (parms), 0));
3453 else
3454 number = REGNO (DECL_INCOMING_RTL (parms));
3456 else if (MEM_P (DECL_RTL (parms))
3457 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3459 /* Parm was passed via invisible reference, with the reference
3460 living on the stack. DECL_RTL looks like
3461 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3462 could look like (MEM (MEM (REG))). */
3464 code = N_PSYM;
3465 letter = 'v';
3466 eff_type = TREE_TYPE (parms);
3468 if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3469 number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3470 else
3471 number = 0;
3473 number = DEBUGGER_ARG_OFFSET (number,
3474 XEXP (XEXP (DECL_RTL (parms), 0), 0));
3476 else if (MEM_P (DECL_RTL (parms))
3477 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3478 /* ??? A constant address for a parm can happen
3479 when the reg it lives in is equiv to a constant in memory.
3480 Should make this not happen, after 2.4. */
3481 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3483 /* Parm was passed in registers but lives on the stack. */
3485 code = N_PSYM;
3486 letter = 'p';
3487 eff_type = TREE_TYPE (parms);
3489 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3490 in which case we want the value of that CONST_INT,
3491 or (MEM (REG ...)),
3492 in which case we use a value of zero. */
3493 if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3494 number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3495 else
3496 number = 0;
3498 /* Make a big endian correction if the mode of the type of the
3499 parameter is not the same as the mode of the rtl. */
3500 if (BYTES_BIG_ENDIAN
3501 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3502 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3503 number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3504 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3506 else
3507 /* ??? We don't know how to represent this argument. */
3508 continue;
3510 dbxout_begin_complex_stabs ();
3512 if (DECL_NAME (parms))
3514 stabstr_I (DECL_NAME (parms));
3515 stabstr_C (':');
3517 else
3518 stabstr_S ("(anon):");
3519 stabstr_C (letter);
3520 dbxout_type (eff_type, 0);
3521 dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3523 DBXOUT_DECR_NESTING;
3526 /* Output definitions for the places where parms live during the function,
3527 when different from where they were passed, when the parms were passed
3528 in memory.
3530 It is not useful to do this for parms passed in registers
3531 that live during the function in different registers, because it is
3532 impossible to look in the passed register for the passed value,
3533 so we use the within-the-function register to begin with.
3535 PARMS is a chain of PARM_DECL nodes. */
3537 void
3538 dbxout_reg_parms (tree parms)
3540 ++debug_nesting;
3542 for (; parms; parms = DECL_CHAIN (parms))
3543 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3545 /* Report parms that live in registers during the function
3546 but were passed in memory. */
3547 if (REG_P (DECL_RTL (parms))
3548 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3549 dbxout_symbol_location (parms, TREE_TYPE (parms),
3550 0, DECL_RTL (parms));
3551 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3552 dbxout_symbol_location (parms, TREE_TYPE (parms),
3553 0, DECL_RTL (parms));
3554 /* Report parms that live in memory but not where they were passed. */
3555 else if (MEM_P (DECL_RTL (parms))
3556 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3557 dbxout_symbol_location (parms, TREE_TYPE (parms),
3558 0, DECL_RTL (parms));
3560 DBXOUT_DECR_NESTING;
3563 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3564 output definitions of those names, in raw form */
3566 static void
3567 dbxout_args (tree args)
3569 while (args)
3571 stabstr_C (',');
3572 dbxout_type (TREE_VALUE (args), 0);
3573 args = TREE_CHAIN (args);
3577 #if defined (DBX_DEBUGGING_INFO)
3579 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3580 BEGIN_LABEL is the name of the beginning of the function, which may
3581 be required. */
3582 static void
3583 dbx_output_lbrac (const char *label,
3584 const char *begin_label ATTRIBUTE_UNUSED)
3586 dbxout_begin_stabn (N_LBRAC);
3587 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3588 dbxout_stab_value_label_diff (label, begin_label);
3589 else
3590 dbxout_stab_value_label (label);
3593 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3594 BEGIN_LABEL is the name of the beginning of the function, which may
3595 be required. */
3596 static void
3597 dbx_output_rbrac (const char *label,
3598 const char *begin_label ATTRIBUTE_UNUSED)
3600 dbxout_begin_stabn (N_RBRAC);
3601 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3602 dbxout_stab_value_label_diff (label, begin_label);
3603 else
3604 dbxout_stab_value_label (label);
3607 /* Output everything about a symbol block (a BLOCK node
3608 that represents a scope level),
3609 including recursive output of contained blocks.
3611 BLOCK is the BLOCK node.
3612 DEPTH is its depth within containing symbol blocks.
3613 ARGS is usually zero; but for the outermost block of the
3614 body of a function, it is a chain of PARM_DECLs for the function parameters.
3615 We output definitions of all the register parms
3616 as if they were local variables of that block.
3618 If -g1 was used, we count blocks just the same, but output nothing
3619 except for the outermost block.
3621 Actually, BLOCK may be several blocks chained together.
3622 We handle them all in sequence. */
3624 static void
3625 dbxout_block (tree block, int depth, tree args)
3627 char begin_label[20];
3628 /* Reference current function start using LFBB. */
3629 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
3631 while (block)
3633 /* Ignore blocks never expanded or otherwise marked as real. */
3634 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3636 int did_output;
3637 int blocknum = BLOCK_NUMBER (block);
3639 /* In dbx format, the syms of a block come before the N_LBRAC.
3640 If nothing is output, we don't need the N_LBRAC, either. */
3641 did_output = 0;
3642 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3643 did_output = dbxout_syms (BLOCK_VARS (block));
3644 if (args)
3645 dbxout_reg_parms (args);
3647 /* Now output an N_LBRAC symbol to represent the beginning of
3648 the block. Use the block's tree-walk order to generate
3649 the assembler symbols LBBn and LBEn
3650 that final will define around the code in this block. */
3651 if (did_output)
3653 char buf[20];
3654 const char *scope_start;
3656 if (depth == 0)
3657 /* The outermost block doesn't get LBB labels; use
3658 the LFBB local symbol emitted by dbxout_begin_prologue. */
3659 scope_start = begin_label;
3660 else
3662 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3663 scope_start = buf;
3666 dbx_output_lbrac (scope_start, begin_label);
3669 /* Output the subblocks. */
3670 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3672 /* Refer to the marker for the end of the block. */
3673 if (did_output)
3675 char buf[100];
3676 if (depth == 0)
3677 /* The outermost block doesn't get LBE labels;
3678 use the "scope" label which will be emitted
3679 by dbxout_function_end. */
3680 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3681 else
3682 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3684 dbx_output_rbrac (buf, begin_label);
3687 block = BLOCK_CHAIN (block);
3691 /* Output the information about a function and its arguments and result.
3692 Usually this follows the function's code,
3693 but on some systems, it comes before. */
3695 static void
3696 dbxout_begin_function (tree decl)
3698 int saved_tree_used1;
3700 saved_tree_used1 = TREE_USED (decl);
3701 TREE_USED (decl) = 1;
3702 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3704 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3705 TREE_USED (DECL_RESULT (decl)) = 1;
3706 dbxout_symbol (decl, 0);
3707 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3709 else
3710 dbxout_symbol (decl, 0);
3711 TREE_USED (decl) = saved_tree_used1;
3713 dbxout_parms (DECL_ARGUMENTS (decl));
3714 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3715 dbxout_symbol (DECL_RESULT (decl), 1);
3717 #endif /* DBX_DEBUGGING_INFO */
3719 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3721 #include "gt-dbxout.h"