* config.gcc (c_target_objs)[i?86-*-pe|i?86-*-cygwin*]: Don't add
[official-gcc.git] / gcc / dbxout.c
blobe5396b2a1d84e774212d1e83984bd3cc19676157
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 tree tem, main_variant, low, high;
1682 if (TREE_CODE (type) == INTEGER_TYPE)
1684 if (TREE_TYPE (type) == 0)
1686 low = TYPE_MIN_VALUE (type);
1687 high = TYPE_MAX_VALUE (type);
1690 else if (subrange_type_for_debug_p (type, &low, &high))
1693 /* If this is a subtype that should not be emitted as a subrange type,
1694 use the base type. */
1695 else
1697 type = TREE_TYPE (type);
1698 low = TYPE_MIN_VALUE (type);
1699 high = TYPE_MAX_VALUE (type);
1703 /* If there was an input error and we don't really have a type,
1704 avoid crashing and write something that is at least valid
1705 by assuming `int'. */
1706 if (type == error_mark_node)
1707 type = integer_type_node;
1708 else
1710 if (TYPE_NAME (type)
1711 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1712 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1713 full = 0;
1716 /* Try to find the "main variant" with the same name. */
1717 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1718 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1719 main_variant = TREE_TYPE (TYPE_NAME (type));
1720 else
1721 main_variant = TYPE_MAIN_VARIANT (type);
1723 /* If we are not using extensions, stabs does not distinguish const and
1724 volatile, so there is no need to make them separate types. */
1725 if (!use_gnu_debug_info_extensions)
1726 type = main_variant;
1728 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1730 /* Type has no dbx number assigned. Assign next available number. */
1731 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1733 /* Make sure type vector is long enough to record about this type. */
1735 if (next_type_number == typevec_len)
1737 typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2);
1738 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1739 typevec_len *= 2;
1742 #ifdef DBX_USE_BINCL
1743 emit_pending_bincls_if_required ();
1744 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1745 = current_file->file_number;
1746 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1747 = current_file->next_type_number++;
1748 #endif
1751 if (flag_debug_only_used_symbols)
1753 if ((TREE_CODE (type) == RECORD_TYPE
1754 || TREE_CODE (type) == UNION_TYPE
1755 || TREE_CODE (type) == QUAL_UNION_TYPE
1756 || TREE_CODE (type) == ENUMERAL_TYPE)
1757 && TYPE_STUB_DECL (type)
1758 && DECL_P (TYPE_STUB_DECL (type))
1759 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1760 debug_queue_symbol (TYPE_STUB_DECL (type));
1761 else if (TYPE_NAME (type)
1762 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1763 debug_queue_symbol (TYPE_NAME (type));
1766 /* Output the number of this type, to refer to it. */
1767 dbxout_type_index (type);
1769 #ifdef DBX_TYPE_DEFINED
1770 if (DBX_TYPE_DEFINED (type))
1771 return;
1772 #endif
1774 /* If this type's definition has been output or is now being output,
1775 that is all. */
1777 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1779 case TYPE_UNSEEN:
1780 break;
1781 case TYPE_XREF:
1782 /* If we have already had a cross reference,
1783 and either that's all we want or that's the best we could do,
1784 don't repeat the cross reference.
1785 Sun dbx crashes if we do. */
1786 if (! full || !COMPLETE_TYPE_P (type)
1787 /* No way in DBX fmt to describe a variable size. */
1788 || ! host_integerp (TYPE_SIZE (type), 1))
1789 return;
1790 break;
1791 case TYPE_DEFINED:
1792 return;
1795 #ifdef DBX_NO_XREFS
1796 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1797 leave the type-number completely undefined rather than output
1798 a cross-reference. If we have already used GNU debug info extensions,
1799 then it is OK to output a cross reference. This is necessary to get
1800 proper C++ debug output. */
1801 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1802 || TREE_CODE (type) == QUAL_UNION_TYPE
1803 || TREE_CODE (type) == ENUMERAL_TYPE)
1804 && ! use_gnu_debug_info_extensions)
1805 /* We must use the same test here as we use twice below when deciding
1806 whether to emit a cross-reference. */
1807 if ((TYPE_NAME (type) != 0
1808 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1809 && DECL_IGNORED_P (TYPE_NAME (type)))
1810 && !full)
1811 || !COMPLETE_TYPE_P (type)
1812 /* No way in DBX fmt to describe a variable size. */
1813 || ! host_integerp (TYPE_SIZE (type), 1))
1815 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1816 return;
1818 #endif
1820 /* Output a definition now. */
1821 stabstr_C ('=');
1823 /* Mark it as defined, so that if it is self-referent
1824 we will not get into an infinite recursion of definitions. */
1826 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1828 /* If this type is a variant of some other, hand off. Types with
1829 different names are usefully distinguished. We only distinguish
1830 cv-qualified types if we're using extensions. */
1831 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1833 stabstr_C ('k');
1834 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1835 return;
1837 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1839 stabstr_C ('B');
1840 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1841 return;
1843 else if (main_variant != TYPE_MAIN_VARIANT (type))
1845 if (flag_debug_only_used_symbols)
1847 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1849 if ((TREE_CODE (orig_type) == RECORD_TYPE
1850 || TREE_CODE (orig_type) == UNION_TYPE
1851 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1852 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1853 && TYPE_STUB_DECL (orig_type)
1854 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1855 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1857 /* 'type' is a typedef; output the type it refers to. */
1858 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1859 return;
1861 /* else continue. */
1863 switch (TREE_CODE (type))
1865 case VOID_TYPE:
1866 case LANG_TYPE:
1867 /* For a void type, just define it as itself; i.e., "5=5".
1868 This makes us consider it defined
1869 without saying what it is. The debugger will make it
1870 a void type when the reference is seen, and nothing will
1871 ever override that default. */
1872 dbxout_type_index (type);
1873 break;
1875 case INTEGER_TYPE:
1876 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1878 /* Output the type `char' as a subrange of itself!
1879 I don't understand this definition, just copied it
1880 from the output of pcc.
1881 This used to use `r2' explicitly and we used to
1882 take care to make sure that `char' was type number 2. */
1883 stabstr_C ('r');
1884 dbxout_type_index (type);
1885 stabstr_S (";0;127;");
1888 /* If this is a subtype of another integer type, always prefer to
1889 write it as a subtype. */
1890 else if (TREE_TYPE (type) != 0
1891 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1893 /* If the size is non-standard, say what it is if we can use
1894 GDB extensions. */
1896 if (use_gnu_debug_info_extensions
1897 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1899 stabstr_S ("@s");
1900 stabstr_D (TYPE_PRECISION (type));
1901 stabstr_C (';');
1904 dbxout_range_type (type, low, high);
1907 else
1909 /* If the size is non-standard, say what it is if we can use
1910 GDB extensions. */
1912 if (use_gnu_debug_info_extensions
1913 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1915 stabstr_S ("@s");
1916 stabstr_D (TYPE_PRECISION (type));
1917 stabstr_C (';');
1920 if (print_int_cst_bounds_in_octal_p (type, low, high))
1922 stabstr_C ('r');
1924 /* If this type derives from another type, output type index of
1925 parent type. This is particularly important when parent type
1926 is an enumerated type, because not generating the parent type
1927 index would transform the definition of this enumerated type
1928 into a plain unsigned type. */
1929 if (TREE_TYPE (type) != 0)
1930 dbxout_type_index (TREE_TYPE (type));
1931 else
1932 dbxout_type_index (type);
1934 stabstr_C (';');
1935 stabstr_O (low);
1936 stabstr_C (';');
1937 stabstr_O (high);
1938 stabstr_C (';');
1941 else
1942 /* Output other integer types as subranges of `int'. */
1943 dbxout_range_type (type, low, high);
1946 break;
1948 case REAL_TYPE:
1949 case FIXED_POINT_TYPE:
1950 /* This used to say `r1' and we used to take care
1951 to make sure that `int' was type number 1. */
1952 stabstr_C ('r');
1953 dbxout_type_index (integer_type_node);
1954 stabstr_C (';');
1955 stabstr_D (int_size_in_bytes (type));
1956 stabstr_S (";0;");
1957 break;
1959 case BOOLEAN_TYPE:
1960 if (use_gnu_debug_info_extensions)
1962 stabstr_S ("@s");
1963 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1964 stabstr_S (";-16;");
1966 else /* Define as enumeral type (False, True) */
1967 stabstr_S ("eFalse:0,True:1,;");
1968 break;
1970 case COMPLEX_TYPE:
1971 /* Differs from the REAL_TYPE by its new data type number.
1972 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
1973 codes since gdb doesn't care anyway. */
1975 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1977 stabstr_S ("R3;");
1978 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
1979 stabstr_S (";0;");
1981 else
1983 /* Output a complex integer type as a structure,
1984 pending some other way to do it. */
1985 stabstr_C ('s');
1986 stabstr_D (int_size_in_bytes (type));
1988 stabstr_S ("real:");
1989 dbxout_type (TREE_TYPE (type), 0);
1990 stabstr_S (",0,");
1991 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1993 stabstr_S (";imag:");
1994 dbxout_type (TREE_TYPE (type), 0);
1995 stabstr_C (',');
1996 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1997 stabstr_C (',');
1998 stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1999 stabstr_S (";;");
2001 break;
2003 case ARRAY_TYPE:
2004 /* Make arrays of packed bits look like bitstrings for chill. */
2005 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
2007 stabstr_S ("@s");
2008 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
2009 stabstr_S (";@S;S");
2010 dbxout_type (TYPE_DOMAIN (type), 0);
2011 break;
2014 /* Output "a" followed by a range type definition
2015 for the index type of the array
2016 followed by a reference to the target-type.
2017 ar1;0;N;M for a C array of type M and size N+1. */
2018 /* Check if a character string type, which in Chill is
2019 different from an array of characters. */
2020 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
2022 stabstr_S ("@S;");
2024 tem = TYPE_DOMAIN (type);
2025 if (tem == NULL)
2027 stabstr_S ("ar");
2028 dbxout_type_index (integer_type_node);
2029 stabstr_S (";0;-1;");
2031 else
2033 stabstr_C ('a');
2034 dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem));
2037 dbxout_type (TREE_TYPE (type), 0);
2038 break;
2040 case VECTOR_TYPE:
2041 /* Make vectors look like an array. */
2042 if (use_gnu_debug_info_extensions)
2043 stabstr_S ("@V;");
2045 /* Output "a" followed by a range type definition
2046 for the index type of the array
2047 followed by a reference to the target-type.
2048 ar1;0;N;M for a C array of type M and size N+1. */
2049 stabstr_C ('a');
2050 dbxout_range_type (integer_type_node, size_zero_node,
2051 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
2053 dbxout_type (TREE_TYPE (type), 0);
2054 break;
2056 case RECORD_TYPE:
2057 case UNION_TYPE:
2058 case QUAL_UNION_TYPE:
2060 tree binfo = TYPE_BINFO (type);
2062 /* Output a structure type. We must use the same test here as we
2063 use in the DBX_NO_XREFS case above. */
2064 if ((TYPE_NAME (type) != 0
2065 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2066 && DECL_IGNORED_P (TYPE_NAME (type)))
2067 && !full)
2068 || !COMPLETE_TYPE_P (type)
2069 /* No way in DBX fmt to describe a variable size. */
2070 || ! host_integerp (TYPE_SIZE (type), 1))
2072 /* If the type is just a cross reference, output one
2073 and mark the type as partially described.
2074 If it later becomes defined, we will output
2075 its real definition.
2076 If the type has a name, don't nest its definition within
2077 another type's definition; instead, output an xref
2078 and let the definition come when the name is defined. */
2079 stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2080 if (TYPE_NAME (type) != 0
2081 /* The C frontend creates for anonymous variable length
2082 records/unions TYPE_NAME with DECL_NAME NULL. */
2083 && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
2084 || DECL_NAME (TYPE_NAME (type))))
2085 dbxout_type_name (type);
2086 else
2088 stabstr_S ("$$");
2089 stabstr_D (anonymous_type_number++);
2092 stabstr_C (':');
2093 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2094 break;
2097 /* Identify record or union, and print its size. */
2098 stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2099 stabstr_D (int_size_in_bytes (type));
2101 if (binfo)
2103 int i;
2104 tree child;
2105 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
2107 if (use_gnu_debug_info_extensions)
2109 if (BINFO_N_BASE_BINFOS (binfo))
2111 stabstr_C ('!');
2112 stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2113 stabstr_C (',');
2116 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2118 tree access = (accesses ? VEC_index (tree, accesses, i)
2119 : access_public_node);
2121 if (use_gnu_debug_info_extensions)
2123 stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2124 stabstr_C (access == access_public_node ? '2' :
2125 access == access_protected_node
2126 ? '1' :'0');
2127 if (BINFO_VIRTUAL_P (child)
2128 && (strcmp (lang_hooks.name, "GNU C++") == 0
2129 || strcmp (lang_hooks.name, "GNU Objective-C++") == 0))
2130 /* For a virtual base, print the (negative)
2131 offset within the vtable where we must look
2132 to find the necessary adjustment. */
2133 stabstr_D
2134 (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2135 * BITS_PER_UNIT);
2136 else
2137 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2138 * BITS_PER_UNIT);
2139 stabstr_C (',');
2140 dbxout_type (BINFO_TYPE (child), 0);
2141 stabstr_C (';');
2143 else
2145 /* Print out the base class information with
2146 fields which have the same names at the types
2147 they hold. */
2148 dbxout_type_name (BINFO_TYPE (child));
2149 stabstr_C (':');
2150 dbxout_type (BINFO_TYPE (child), full);
2151 stabstr_C (',');
2152 stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2153 * BITS_PER_UNIT);
2154 stabstr_C (',');
2155 stabstr_D
2156 (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2157 * BITS_PER_UNIT);
2158 stabstr_C (';');
2164 /* Write out the field declarations. */
2165 dbxout_type_fields (type);
2166 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2168 dbxout_type_methods (type);
2171 stabstr_C (';');
2173 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2174 /* Avoid the ~ if we don't really need it--it confuses dbx. */
2175 && TYPE_VFIELD (type))
2178 /* We need to write out info about what field this class
2179 uses as its "main" vtable pointer field, because if this
2180 field is inherited from a base class, GDB cannot necessarily
2181 figure out which field it's using in time. */
2182 stabstr_S ("~%");
2183 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2184 stabstr_C (';');
2186 break;
2188 case ENUMERAL_TYPE:
2189 /* We must use the same test here as we use in the DBX_NO_XREFS case
2190 above. We simplify it a bit since an enum will never have a variable
2191 size. */
2192 if ((TYPE_NAME (type) != 0
2193 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2194 && DECL_IGNORED_P (TYPE_NAME (type)))
2195 && !full)
2196 || !COMPLETE_TYPE_P (type))
2198 stabstr_S ("xe");
2199 dbxout_type_name (type);
2200 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2201 stabstr_C (':');
2202 return;
2204 if (use_gnu_debug_info_extensions
2205 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2207 stabstr_S ("@s");
2208 stabstr_D (TYPE_PRECISION (type));
2209 stabstr_C (';');
2212 stabstr_C ('e');
2213 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2215 tree value = TREE_VALUE (tem);
2217 stabstr_I (TREE_PURPOSE (tem));
2218 stabstr_C (':');
2220 if (TREE_CODE (value) == CONST_DECL)
2221 value = DECL_INITIAL (value);
2223 if (TREE_INT_CST_HIGH (value) == 0)
2224 stabstr_D (TREE_INT_CST_LOW (value));
2225 else if (TREE_INT_CST_HIGH (value) == -1
2226 && (HOST_WIDE_INT) TREE_INT_CST_LOW (value) < 0)
2227 stabstr_D (TREE_INT_CST_LOW (value));
2228 else
2229 stabstr_O (value);
2231 stabstr_C (',');
2232 if (TREE_CHAIN (tem) != 0)
2233 CONTIN;
2236 stabstr_C (';');
2237 break;
2239 case POINTER_TYPE:
2240 stabstr_C ('*');
2241 dbxout_type (TREE_TYPE (type), 0);
2242 break;
2244 case METHOD_TYPE:
2245 if (use_gnu_debug_info_extensions)
2247 stabstr_C ('#');
2249 /* Write the argument types out longhand. */
2250 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2251 stabstr_C (',');
2252 dbxout_type (TREE_TYPE (type), 0);
2253 dbxout_args (TYPE_ARG_TYPES (type));
2254 stabstr_C (';');
2256 else
2257 /* Treat it as a function type. */
2258 dbxout_type (TREE_TYPE (type), 0);
2259 break;
2261 case OFFSET_TYPE:
2262 if (use_gnu_debug_info_extensions)
2264 stabstr_C ('@');
2265 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2266 stabstr_C (',');
2267 dbxout_type (TREE_TYPE (type), 0);
2269 else
2270 /* Should print as an int, because it is really just an offset. */
2271 dbxout_type (integer_type_node, 0);
2272 break;
2274 case REFERENCE_TYPE:
2275 if (use_gnu_debug_info_extensions)
2277 stabstr_C ('&');
2279 else
2280 stabstr_C ('*');
2281 dbxout_type (TREE_TYPE (type), 0);
2282 break;
2284 case FUNCTION_TYPE:
2285 stabstr_C ('f');
2286 dbxout_type (TREE_TYPE (type), 0);
2287 break;
2289 default:
2290 gcc_unreachable ();
2294 /* Return nonzero if the given type represents an integer whose bounds
2295 should be printed in octal format. */
2297 static bool
2298 print_int_cst_bounds_in_octal_p (tree type, tree low, tree high)
2300 /* If we can use GDB extensions and the size is wider than a long
2301 (the size used by GDB to read them) or we may have trouble writing
2302 the bounds the usual way, write them in octal. Note the test is for
2303 the *target's* size of "long", not that of the host. The host test
2304 is just to make sure we can write it out in case the host wide int
2305 is narrower than the target "long".
2307 For unsigned types, we use octal if they are the same size or larger.
2308 This is because we print the bounds as signed decimal, and hence they
2309 can't span same size unsigned types. */
2311 if (use_gnu_debug_info_extensions
2312 && low && TREE_CODE (low) == INTEGER_CST
2313 && high && TREE_CODE (high) == INTEGER_CST
2314 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2315 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2316 && TYPE_UNSIGNED (type))
2317 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2318 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2319 && TYPE_UNSIGNED (type))))
2320 return TRUE;
2321 else
2322 return FALSE;
2325 /* Output the name of type TYPE, with no punctuation.
2326 Such names can be set up either by typedef declarations
2327 or by struct, enum and union tags. */
2329 static void
2330 dbxout_type_name (tree type)
2332 tree t = TYPE_NAME (type);
2334 gcc_assert (t);
2335 switch (TREE_CODE (t))
2337 case IDENTIFIER_NODE:
2338 break;
2339 case TYPE_DECL:
2340 t = DECL_NAME (t);
2341 break;
2342 default:
2343 gcc_unreachable ();
2346 stabstr_I (t);
2349 /* Output leading leading struct or class names needed for qualifying
2350 type whose scope is limited to a struct or class. */
2352 static void
2353 dbxout_class_name_qualifiers (tree decl)
2355 tree context = decl_type_context (decl);
2357 if (context != NULL_TREE
2358 && TREE_CODE(context) == RECORD_TYPE
2359 && TYPE_NAME (context) != 0
2360 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2361 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2363 tree name = TYPE_NAME (context);
2365 if (TREE_CODE (name) == TYPE_DECL)
2367 dbxout_class_name_qualifiers (name);
2368 name = DECL_NAME (name);
2370 stabstr_I (name);
2371 stabstr_S ("::");
2375 /* This is a specialized subset of expand_expr for use by dbxout_symbol in
2376 evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that
2377 haven't been expanded, or if the expression is getting so complex we won't
2378 be able to represent it in stabs anyway. Returns NULL on failure. */
2380 static rtx
2381 dbxout_expand_expr (tree expr)
2383 switch (TREE_CODE (expr))
2385 case VAR_DECL:
2386 /* We can't handle emulated tls variables, because the address is an
2387 offset to the return value of __emutls_get_address, and there is no
2388 way to express that in stabs. Also, there are name mangling issues
2389 here. We end up with references to undefined symbols if we don't
2390 disable debug info for these variables. */
2391 if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr))
2392 return NULL;
2393 /* FALLTHRU */
2395 case PARM_DECL:
2396 if (DECL_HAS_VALUE_EXPR_P (expr))
2397 return dbxout_expand_expr (DECL_VALUE_EXPR (expr));
2398 /* FALLTHRU */
2400 case CONST_DECL:
2401 case RESULT_DECL:
2402 return DECL_RTL_IF_SET (expr);
2404 case INTEGER_CST:
2405 return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
2407 case COMPONENT_REF:
2408 case ARRAY_REF:
2409 case ARRAY_RANGE_REF:
2410 case BIT_FIELD_REF:
2412 enum machine_mode mode;
2413 HOST_WIDE_INT bitsize, bitpos;
2414 tree offset, tem;
2415 int volatilep = 0, unsignedp = 0;
2416 rtx x;
2418 tem = get_inner_reference (expr, &bitsize, &bitpos, &offset,
2419 &mode, &unsignedp, &volatilep, true);
2421 x = dbxout_expand_expr (tem);
2422 if (x == NULL || !MEM_P (x))
2423 return NULL;
2424 if (offset != NULL)
2426 if (!host_integerp (offset, 0))
2427 return NULL;
2428 x = adjust_address_nv (x, mode, tree_low_cst (offset, 0));
2430 if (bitpos != 0)
2431 x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT);
2433 return x;
2436 default:
2437 return NULL;
2441 /* Helper function for output_used_types. Queue one entry from the
2442 used types hash to be output. */
2444 static int
2445 output_used_types_helper (void **slot, void *data)
2447 tree type = (tree) *slot;
2448 VEC(tree, heap) **types_p = (VEC(tree, heap) **) data;
2450 if ((TREE_CODE (type) == RECORD_TYPE
2451 || TREE_CODE (type) == UNION_TYPE
2452 || TREE_CODE (type) == QUAL_UNION_TYPE
2453 || TREE_CODE (type) == ENUMERAL_TYPE)
2454 && TYPE_STUB_DECL (type)
2455 && DECL_P (TYPE_STUB_DECL (type))
2456 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
2457 VEC_quick_push (tree, *types_p, TYPE_STUB_DECL (type));
2458 else if (TYPE_NAME (type)
2459 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2460 VEC_quick_push (tree, *types_p, TYPE_NAME (type));
2462 return 1;
2465 /* This is a qsort callback which sorts types and declarations into a
2466 predictable order (types, then declarations, sorted by UID
2467 within). */
2469 static int
2470 output_types_sort (const void *pa, const void *pb)
2472 const tree lhs = *((const tree *)pa);
2473 const tree rhs = *((const tree *)pb);
2475 if (TYPE_P (lhs))
2477 if (TYPE_P (rhs))
2478 return TYPE_UID (lhs) - TYPE_UID (rhs);
2479 else
2480 return 1;
2482 else
2484 if (TYPE_P (rhs))
2485 return -1;
2486 else
2487 return DECL_UID (lhs) - DECL_UID (rhs);
2492 /* Force all types used by this function to be output in debug
2493 information. */
2495 static void
2496 output_used_types (void)
2498 if (cfun && cfun->used_types_hash)
2500 VEC(tree, heap) *types;
2501 int i;
2502 tree type;
2504 types = VEC_alloc (tree, heap, htab_elements (cfun->used_types_hash));
2505 htab_traverse (cfun->used_types_hash, output_used_types_helper, &types);
2507 /* Sort by UID to prevent dependence on hash table ordering. */
2508 qsort (VEC_address (tree, types), VEC_length (tree, types),
2509 sizeof (tree), output_types_sort);
2511 FOR_EACH_VEC_ELT (tree, types, i, type)
2512 debug_queue_symbol (type);
2514 VEC_free (tree, heap, types);
2518 /* Output a .stabs for the symbol defined by DECL,
2519 which must be a ..._DECL node in the normal namespace.
2520 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2521 LOCAL is nonzero if the scope is less than the entire file.
2522 Return 1 if a stabs might have been emitted. */
2525 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2527 tree type = TREE_TYPE (decl);
2528 tree context = NULL_TREE;
2529 int result = 0;
2530 rtx decl_rtl;
2532 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2533 ++debug_nesting;
2535 /* Ignore nameless syms, but don't ignore type tags. */
2537 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2538 || DECL_IGNORED_P (decl))
2539 DBXOUT_DECR_NESTING_AND_RETURN (0);
2541 /* If we are to generate only the symbols actually used then such
2542 symbol nodes are flagged with TREE_USED. Ignore any that
2543 aren't flagged as TREE_USED. */
2545 if (flag_debug_only_used_symbols
2546 && (!TREE_USED (decl)
2547 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2548 DBXOUT_DECR_NESTING_AND_RETURN (0);
2550 /* If dbxout_init has not yet run, queue this symbol for later. */
2551 if (!typevec)
2553 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2554 DBXOUT_DECR_NESTING_AND_RETURN (0);
2557 if (flag_debug_only_used_symbols)
2559 tree t;
2561 /* We now have a used symbol. We need to generate the info for
2562 the symbol's type in addition to the symbol itself. These
2563 type symbols are queued to be generated after were done with
2564 the symbol itself (otherwise they would fight over the
2565 stabstr obstack).
2567 Note, because the TREE_TYPE(type) might be something like a
2568 pointer to a named type we need to look for the first name
2569 we see following the TREE_TYPE chain. */
2571 t = type;
2572 while (POINTER_TYPE_P (t))
2573 t = TREE_TYPE (t);
2575 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2576 need special treatment. The TYPE_STUB_DECL field in these
2577 types generally represents the tag name type we want to
2578 output. In addition there could be a typedef type with
2579 a different name. In that case we also want to output
2580 that. */
2582 if (TREE_CODE (t) == RECORD_TYPE
2583 || TREE_CODE (t) == UNION_TYPE
2584 || TREE_CODE (t) == QUAL_UNION_TYPE
2585 || TREE_CODE (t) == ENUMERAL_TYPE)
2587 if (TYPE_STUB_DECL (t)
2588 && TYPE_STUB_DECL (t) != decl
2589 && DECL_P (TYPE_STUB_DECL (t))
2590 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2592 debug_queue_symbol (TYPE_STUB_DECL (t));
2593 if (TYPE_NAME (t)
2594 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2595 && TYPE_NAME (t) != decl
2596 && DECL_P (TYPE_NAME (t)))
2597 debug_queue_symbol (TYPE_NAME (t));
2600 else if (TYPE_NAME (t)
2601 && TYPE_NAME (t) != decl
2602 && DECL_P (TYPE_NAME (t)))
2603 debug_queue_symbol (TYPE_NAME (t));
2606 emit_pending_bincls_if_required ();
2608 switch (TREE_CODE (decl))
2610 case CONST_DECL:
2611 /* Enum values are defined by defining the enum type. */
2612 break;
2614 case FUNCTION_DECL:
2615 decl_rtl = DECL_RTL_IF_SET (decl);
2616 if (!decl_rtl)
2617 DBXOUT_DECR_NESTING_AND_RETURN (0);
2618 if (DECL_EXTERNAL (decl))
2619 break;
2620 /* Don't mention a nested function under its parent. */
2621 context = decl_function_context (decl);
2622 if (context == current_function_decl)
2623 break;
2624 /* Don't mention an inline instance of a nested function. */
2625 if (context && DECL_FROM_INLINE (decl))
2626 break;
2627 if (!MEM_P (decl_rtl)
2628 || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF)
2629 break;
2631 if (flag_debug_only_used_symbols)
2632 output_used_types ();
2634 dbxout_begin_complex_stabs ();
2635 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2636 stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2637 result = 1;
2639 if (TREE_TYPE (type))
2640 dbxout_type (TREE_TYPE (type), 0);
2641 else
2642 dbxout_type (void_type_node, 0);
2644 /* For a nested function, when that function is compiled,
2645 mention the containing function name
2646 as well as (since dbx wants it) our own assembler-name. */
2647 if (context != 0)
2649 stabstr_C (',');
2650 stabstr_I (DECL_ASSEMBLER_NAME (decl));
2651 stabstr_C (',');
2652 stabstr_I (DECL_NAME (context));
2655 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0);
2656 break;
2658 case TYPE_DECL:
2659 /* Don't output the same typedef twice.
2660 And don't output what language-specific stuff doesn't want output. */
2661 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2662 DBXOUT_DECR_NESTING_AND_RETURN (0);
2664 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2665 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2667 int fundamental_type_number =
2668 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2670 if (fundamental_type_number != 0)
2672 TREE_ASM_WRITTEN (decl) = 1;
2673 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2674 DBXOUT_DECR_NESTING_AND_RETURN (0);
2677 #endif
2678 FORCE_TEXT;
2679 result = 1;
2681 int tag_needed = 1;
2682 int did_output = 0;
2684 if (DECL_NAME (decl))
2686 /* Nonzero means we must output a tag as well as a typedef. */
2687 tag_needed = 0;
2689 /* Handle the case of a C++ structure or union
2690 where the TYPE_NAME is a TYPE_DECL
2691 which gives both a typedef name and a tag. */
2692 /* dbx requires the tag first and the typedef second. */
2693 if ((TREE_CODE (type) == RECORD_TYPE
2694 || TREE_CODE (type) == UNION_TYPE
2695 || TREE_CODE (type) == QUAL_UNION_TYPE)
2696 && TYPE_NAME (type) == decl
2697 && !use_gnu_debug_info_extensions
2698 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2699 /* Distinguish the implicit typedefs of C++
2700 from explicit ones that might be found in C. */
2701 && DECL_ARTIFICIAL (decl)
2702 /* Do not generate a tag for incomplete records. */
2703 && COMPLETE_TYPE_P (type)
2704 /* Do not generate a tag for records of variable size,
2705 since this type can not be properly described in the
2706 DBX format, and it confuses some tools such as objdump. */
2707 && host_integerp (TYPE_SIZE (type), 1))
2709 tree name = TYPE_NAME (type);
2710 if (TREE_CODE (name) == TYPE_DECL)
2711 name = DECL_NAME (name);
2713 dbxout_begin_complex_stabs ();
2714 stabstr_I (name);
2715 stabstr_S (":T");
2716 dbxout_type (type, 1);
2717 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2718 0, 0, 0);
2721 dbxout_begin_complex_stabs ();
2723 /* Output leading class/struct qualifiers. */
2724 if (use_gnu_debug_info_extensions)
2725 dbxout_class_name_qualifiers (decl);
2727 /* Output typedef name. */
2728 stabstr_I (DECL_NAME (decl));
2729 stabstr_C (':');
2731 /* Short cut way to output a tag also. */
2732 if ((TREE_CODE (type) == RECORD_TYPE
2733 || TREE_CODE (type) == UNION_TYPE
2734 || TREE_CODE (type) == QUAL_UNION_TYPE)
2735 && TYPE_NAME (type) == decl
2736 /* Distinguish the implicit typedefs of C++
2737 from explicit ones that might be found in C. */
2738 && DECL_ARTIFICIAL (decl))
2740 if (use_gnu_debug_info_extensions)
2742 stabstr_C ('T');
2743 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2747 stabstr_C ('t');
2748 dbxout_type (type, 1);
2749 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2750 0, 0, 0);
2751 did_output = 1;
2754 /* Don't output a tag if this is an incomplete type. This prevents
2755 the sun4 Sun OS 4.x dbx from crashing. */
2757 if (tag_needed && TYPE_NAME (type) != 0
2758 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2759 || (DECL_NAME (TYPE_NAME (type)) != 0))
2760 && COMPLETE_TYPE_P (type)
2761 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2763 /* For a TYPE_DECL with no name, but the type has a name,
2764 output a tag.
2765 This is what represents `struct foo' with no typedef. */
2766 /* In C++, the name of a type is the corresponding typedef.
2767 In C, it is an IDENTIFIER_NODE. */
2768 tree name = TYPE_NAME (type);
2769 if (TREE_CODE (name) == TYPE_DECL)
2770 name = DECL_NAME (name);
2772 dbxout_begin_complex_stabs ();
2773 stabstr_I (name);
2774 stabstr_S (":T");
2775 dbxout_type (type, 1);
2776 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2777 did_output = 1;
2780 /* If an enum type has no name, it cannot be referred to, but
2781 we must output it anyway, to record the enumeration
2782 constants. */
2784 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2786 dbxout_begin_complex_stabs ();
2787 /* Some debuggers fail when given NULL names, so give this a
2788 harmless name of " " (Why not "(anon)"?). */
2789 stabstr_S (" :T");
2790 dbxout_type (type, 1);
2791 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2794 /* Prevent duplicate output of a typedef. */
2795 TREE_ASM_WRITTEN (decl) = 1;
2796 break;
2799 case PARM_DECL:
2800 if (DECL_HAS_VALUE_EXPR_P (decl))
2801 decl = DECL_VALUE_EXPR (decl);
2803 /* PARM_DECLs go in their own separate chain and are output by
2804 dbxout_reg_parms and dbxout_parms, except for those that are
2805 disguised VAR_DECLs like Out parameters in Ada. */
2806 gcc_assert (TREE_CODE (decl) == VAR_DECL);
2808 /* ... fall through ... */
2810 case RESULT_DECL:
2811 case VAR_DECL:
2812 /* Don't mention a variable that is external.
2813 Let the file that defines it describe it. */
2814 if (DECL_EXTERNAL (decl))
2815 break;
2817 /* If the variable is really a constant
2818 and not written in memory, inform the debugger.
2820 ??? Why do we skip emitting the type and location in this case? */
2821 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2822 && DECL_INITIAL (decl) != 0
2823 && host_integerp (DECL_INITIAL (decl), 0)
2824 && ! TREE_ASM_WRITTEN (decl)
2825 && (DECL_FILE_SCOPE_P (decl)
2826 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK
2827 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
2828 && TREE_PUBLIC (decl) == 0)
2830 /* The sun4 assembler does not grok this. */
2832 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2833 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2835 HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
2837 dbxout_begin_complex_stabs ();
2838 dbxout_symbol_name (decl, NULL, 'c');
2839 stabstr_S ("=i");
2840 stabstr_D (ival);
2841 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2842 DBXOUT_DECR_NESTING;
2843 return 1;
2845 else
2846 break;
2848 /* else it is something we handle like a normal variable. */
2850 decl_rtl = dbxout_expand_expr (decl);
2851 if (!decl_rtl)
2852 DBXOUT_DECR_NESTING_AND_RETURN (0);
2854 decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX);
2855 #ifdef LEAF_REG_REMAP
2856 if (current_function_uses_only_leaf_regs)
2857 leaf_renumber_regs_insn (decl_rtl);
2858 #endif
2860 result = dbxout_symbol_location (decl, type, 0, decl_rtl);
2861 break;
2863 default:
2864 break;
2866 DBXOUT_DECR_NESTING;
2867 return result;
2870 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2871 Add SUFFIX to its name, if SUFFIX is not 0.
2872 Describe the variable as residing in HOME
2873 (usually HOME is DECL_RTL (DECL), but not always).
2874 Returns 1 if the stab was really emitted. */
2876 static int
2877 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2879 int letter = 0;
2880 stab_code_type code;
2881 rtx addr = 0;
2882 int number = 0;
2883 int regno = -1;
2885 /* Don't mention a variable at all
2886 if it was completely optimized into nothingness.
2888 If the decl was from an inline function, then its rtl
2889 is not identically the rtl that was used in this
2890 particular compilation. */
2891 if (GET_CODE (home) == SUBREG)
2893 rtx value = home;
2895 while (GET_CODE (value) == SUBREG)
2896 value = SUBREG_REG (value);
2897 if (REG_P (value))
2899 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2900 return 0;
2902 home = alter_subreg (&home);
2904 if (REG_P (home))
2906 regno = REGNO (home);
2907 if (regno >= FIRST_PSEUDO_REGISTER)
2908 return 0;
2911 /* The kind-of-variable letter depends on where
2912 the variable is and on the scope of its name:
2913 G and N_GSYM for static storage and global scope,
2914 S for static storage and file scope,
2915 V for static storage and local scope,
2916 for those two, use N_LCSYM if data is in bss segment,
2917 N_STSYM if in data segment, N_FUN otherwise.
2918 (We used N_FUN originally, then changed to N_STSYM
2919 to please GDB. However, it seems that confused ld.
2920 Now GDB has been fixed to like N_FUN, says Kingdon.)
2921 no letter at all, and N_LSYM, for auto variable,
2922 r and N_RSYM for register variable. */
2924 if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2926 if (TREE_PUBLIC (decl))
2928 int offs;
2929 letter = 'G';
2930 code = N_GSYM;
2931 if (NULL != dbxout_common_check (decl, &offs))
2933 letter = 'V';
2934 addr = 0;
2935 number = offs;
2938 else
2940 addr = XEXP (home, 0);
2942 letter = decl_function_context (decl) ? 'V' : 'S';
2944 /* Some ports can transform a symbol ref into a label ref,
2945 because the symbol ref is too far away and has to be
2946 dumped into a constant pool. Alternatively, the symbol
2947 in the constant pool might be referenced by a different
2948 symbol. */
2949 if (GET_CODE (addr) == SYMBOL_REF
2950 && CONSTANT_POOL_ADDRESS_P (addr))
2952 bool marked;
2953 rtx tmp = get_pool_constant_mark (addr, &marked);
2955 if (GET_CODE (tmp) == SYMBOL_REF)
2957 addr = tmp;
2958 if (CONSTANT_POOL_ADDRESS_P (addr))
2959 get_pool_constant_mark (addr, &marked);
2960 else
2961 marked = true;
2963 else if (GET_CODE (tmp) == LABEL_REF)
2965 addr = tmp;
2966 marked = true;
2969 /* If all references to the constant pool were optimized
2970 out, we just ignore the symbol. */
2971 if (!marked)
2972 return 0;
2975 /* This should be the same condition as in assemble_variable, but
2976 we don't have access to dont_output_data here. So, instead,
2977 we rely on the fact that error_mark_node initializers always
2978 end up in bss for C++ and never end up in bss for C. */
2979 if (DECL_INITIAL (decl) == 0
2980 || (!strcmp (lang_hooks.name, "GNU C++")
2981 && DECL_INITIAL (decl) == error_mark_node))
2983 int offs;
2984 code = N_LCSYM;
2985 if (NULL != dbxout_common_check (decl, &offs))
2987 addr = 0;
2988 number = offs;
2989 letter = 'V';
2990 code = N_GSYM;
2993 else if (DECL_IN_TEXT_SECTION (decl))
2994 /* This is not quite right, but it's the closest
2995 of all the codes that Unix defines. */
2996 code = DBX_STATIC_CONST_VAR_CODE;
2997 else
2999 /* Ultrix `as' seems to need this. */
3000 #ifdef DBX_STATIC_STAB_DATA_SECTION
3001 switch_to_section (data_section);
3002 #endif
3003 code = N_STSYM;
3007 else if (regno >= 0)
3009 letter = 'r';
3010 code = N_RSYM;
3011 number = DBX_REGISTER_NUMBER (regno);
3013 else if (MEM_P (home)
3014 && (MEM_P (XEXP (home, 0))
3015 || (REG_P (XEXP (home, 0))
3016 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
3017 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
3018 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3019 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
3020 #endif
3022 /* If the value is indirect by memory or by a register
3023 that isn't the frame pointer
3024 then it means the object is variable-sized and address through
3025 that register or stack slot. DBX has no way to represent this
3026 so all we can do is output the variable as a pointer.
3027 If it's not a parameter, ignore it. */
3029 if (REG_P (XEXP (home, 0)))
3031 letter = 'r';
3032 code = N_RSYM;
3033 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
3034 return 0;
3035 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
3037 else
3039 code = N_LSYM;
3040 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
3041 We want the value of that CONST_INT. */
3042 number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
3045 /* Effectively do build_pointer_type, but don't cache this type,
3046 since it might be temporary whereas the type it points to
3047 might have been saved for inlining. */
3048 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
3049 type = make_node (POINTER_TYPE);
3050 TREE_TYPE (type) = TREE_TYPE (decl);
3052 else if (MEM_P (home)
3053 && REG_P (XEXP (home, 0)))
3055 code = N_LSYM;
3056 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3058 else if (MEM_P (home)
3059 && GET_CODE (XEXP (home, 0)) == PLUS
3060 && CONST_INT_P (XEXP (XEXP (home, 0), 1)))
3062 code = N_LSYM;
3063 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
3064 We want the value of that CONST_INT. */
3065 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
3067 else if (MEM_P (home)
3068 && GET_CODE (XEXP (home, 0)) == CONST)
3070 /* Handle an obscure case which can arise when optimizing and
3071 when there are few available registers. (This is *always*
3072 the case for i386/i486 targets). The RTL looks like
3073 (MEM (CONST ...)) even though this variable is a local `auto'
3074 or a local `register' variable. In effect, what has happened
3075 is that the reload pass has seen that all assignments and
3076 references for one such a local variable can be replaced by
3077 equivalent assignments and references to some static storage
3078 variable, thereby avoiding the need for a register. In such
3079 cases we're forced to lie to debuggers and tell them that
3080 this variable was itself `static'. */
3081 int offs;
3082 code = N_LCSYM;
3083 letter = 'V';
3084 if (NULL == dbxout_common_check (decl, &offs))
3085 addr = XEXP (XEXP (home, 0), 0);
3086 else
3088 addr = 0;
3089 number = offs;
3090 code = N_GSYM;
3093 else if (GET_CODE (home) == CONCAT)
3095 tree subtype;
3097 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
3098 for example), then there is no easy way to figure out
3099 what SUBTYPE should be. So, we give up. */
3100 if (TREE_CODE (type) != COMPLEX_TYPE)
3101 return 0;
3103 subtype = TREE_TYPE (type);
3105 /* If the variable's storage is in two parts,
3106 output each as a separate stab with a modified name. */
3107 if (WORDS_BIG_ENDIAN)
3108 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
3109 else
3110 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
3112 if (WORDS_BIG_ENDIAN)
3113 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
3114 else
3115 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
3116 return 1;
3118 else
3119 /* Address might be a MEM, when DECL is a variable-sized object.
3120 Or it might be const0_rtx, meaning previous passes
3121 want us to ignore this variable. */
3122 return 0;
3124 /* Ok, start a symtab entry and output the variable name. */
3125 emit_pending_bincls_if_required ();
3126 FORCE_TEXT;
3128 #ifdef DBX_STATIC_BLOCK_START
3129 DBX_STATIC_BLOCK_START (asm_out_file, code);
3130 #endif
3132 dbxout_begin_complex_stabs_noforcetext ();
3133 dbxout_symbol_name (decl, suffix, letter);
3134 dbxout_type (type, 0);
3135 dbxout_finish_complex_stabs (decl, code, addr, 0, number);
3137 #ifdef DBX_STATIC_BLOCK_END
3138 DBX_STATIC_BLOCK_END (asm_out_file, code);
3139 #endif
3140 return 1;
3143 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
3144 Then output LETTER to indicate the kind of location the symbol has. */
3146 static void
3147 dbxout_symbol_name (tree decl, const char *suffix, int letter)
3149 tree name;
3151 if (DECL_CONTEXT (decl)
3152 && (TYPE_P (DECL_CONTEXT (decl))
3153 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
3154 /* One slight hitch: if this is a VAR_DECL which is a class member
3155 or a namespace member, we must put out the mangled name instead of the
3156 DECL_NAME. Note also that static member (variable) names DO NOT begin
3157 with underscores in .stabs directives. */
3158 name = DECL_ASSEMBLER_NAME (decl);
3159 else
3160 /* ...but if we're function-local, we don't want to include the junk
3161 added by ASM_FORMAT_PRIVATE_NAME. */
3162 name = DECL_NAME (decl);
3164 if (name)
3165 stabstr_I (name);
3166 else
3167 stabstr_S ("(anon)");
3169 if (suffix)
3170 stabstr_S (suffix);
3171 stabstr_C (':');
3172 if (letter)
3173 stabstr_C (letter);
3177 /* Output the common block name for DECL in a stabs.
3179 Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair
3180 around each group of symbols in the same .comm area. The N_GSYM stabs
3181 that are emitted only contain the offset in the common area. This routine
3182 emits the N_BCOMM and N_ECOMM stabs. */
3184 static void
3185 dbxout_common_name (tree decl, const char *name, stab_code_type op)
3187 dbxout_begin_complex_stabs ();
3188 stabstr_S (name);
3189 dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0);
3192 /* Check decl to determine whether it is a VAR_DECL destined for storage in a
3193 common area. If it is, the return value will be a non-null string giving
3194 the name of the common storage block it will go into. If non-null, the
3195 value is the offset into the common block for that symbol's storage. */
3197 static const char *
3198 dbxout_common_check (tree decl, int *value)
3200 rtx home;
3201 rtx sym_addr;
3202 const char *name = NULL;
3204 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
3205 it does not have a value (the offset into the common area), or if it
3206 is thread local (as opposed to global) then it isn't common, and shouldn't
3207 be handled as such.
3209 ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs
3210 for thread-local symbols. Can be handled via same mechanism as used
3211 in dwarf2out.c. */
3212 if (TREE_CODE (decl) != VAR_DECL
3213 || !TREE_STATIC(decl)
3214 || !DECL_HAS_VALUE_EXPR_P(decl)
3215 || DECL_THREAD_LOCAL_P (decl)
3216 || !is_fortran ())
3217 return NULL;
3219 home = DECL_RTL (decl);
3220 if (home == NULL_RTX || GET_CODE (home) != MEM)
3221 return NULL;
3223 sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl));
3224 if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM)
3225 return NULL;
3227 sym_addr = XEXP (sym_addr, 0);
3228 if (GET_CODE (sym_addr) == CONST)
3229 sym_addr = XEXP (sym_addr, 0);
3230 if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS)
3231 && DECL_INITIAL (decl) == 0)
3234 /* We have a sym that will go into a common area, meaning that it
3235 will get storage reserved with a .comm/.lcomm assembler pseudo-op.
3237 Determine name of common area this symbol will be an offset into,
3238 and offset into that area. Also retrieve the decl for the area
3239 that the symbol is offset into. */
3240 tree cdecl = NULL;
3242 switch (GET_CODE (sym_addr))
3244 case PLUS:
3245 if (CONST_INT_P (XEXP (sym_addr, 0)))
3247 name =
3248 targetm.strip_name_encoding(XSTR (XEXP (sym_addr, 1), 0));
3249 *value = INTVAL (XEXP (sym_addr, 0));
3250 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1));
3252 else
3254 name =
3255 targetm.strip_name_encoding(XSTR (XEXP (sym_addr, 0), 0));
3256 *value = INTVAL (XEXP (sym_addr, 1));
3257 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0));
3259 break;
3261 case SYMBOL_REF:
3262 name = targetm.strip_name_encoding(XSTR (sym_addr, 0));
3263 *value = 0;
3264 cdecl = SYMBOL_REF_DECL (sym_addr);
3265 break;
3267 default:
3268 error ("common symbol debug info is not structured as "
3269 "symbol+offset");
3272 /* Check area common symbol is offset into. If this is not public, then
3273 it is not a symbol in a common block. It must be a .lcomm symbol, not
3274 a .comm symbol. */
3275 if (cdecl == NULL || !TREE_PUBLIC(cdecl))
3276 name = NULL;
3278 else
3279 name = NULL;
3281 return name;
3284 /* Output definitions of all the decls in a chain. Return nonzero if
3285 anything was output */
3288 dbxout_syms (tree syms)
3290 int result = 0;
3291 const char *comm_prev = NULL;
3292 tree syms_prev = NULL;
3294 while (syms)
3296 int temp, copen, cclos;
3297 const char *comm_new;
3299 /* Check for common symbol, and then progression into a new/different
3300 block of common symbols. Emit closing/opening common bracket if
3301 necessary. */
3302 comm_new = dbxout_common_check (syms, &temp);
3303 copen = comm_new != NULL
3304 && (comm_prev == NULL || strcmp (comm_new, comm_prev));
3305 cclos = comm_prev != NULL
3306 && (comm_new == NULL || strcmp (comm_new, comm_prev));
3307 if (cclos)
3308 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3309 if (copen)
3311 dbxout_common_name (syms, comm_new, N_BCOMM);
3312 syms_prev = syms;
3314 comm_prev = comm_new;
3316 result += dbxout_symbol (syms, 1);
3317 syms = DECL_CHAIN (syms);
3320 if (comm_prev != NULL)
3321 dbxout_common_name (syms_prev, comm_prev, N_ECOMM);
3323 return result;
3326 /* The following two functions output definitions of function parameters.
3327 Each parameter gets a definition locating it in the parameter list.
3328 Each parameter that is a register variable gets a second definition
3329 locating it in the register.
3331 Printing or argument lists in gdb uses the definitions that
3332 locate in the parameter list. But reference to the variable in
3333 expressions uses preferentially the definition as a register. */
3335 /* Output definitions, referring to storage in the parmlist,
3336 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
3338 void
3339 dbxout_parms (tree parms)
3341 ++debug_nesting;
3342 emit_pending_bincls_if_required ();
3344 for (; parms; parms = DECL_CHAIN (parms))
3345 if (DECL_NAME (parms)
3346 && TREE_TYPE (parms) != error_mark_node
3347 && DECL_RTL_SET_P (parms)
3348 && DECL_INCOMING_RTL (parms))
3350 tree eff_type;
3351 char letter;
3352 stab_code_type code;
3353 int number;
3355 /* Perform any necessary register eliminations on the parameter's rtl,
3356 so that the debugging output will be accurate. */
3357 DECL_INCOMING_RTL (parms)
3358 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
3359 SET_DECL_RTL (parms,
3360 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
3361 #ifdef LEAF_REG_REMAP
3362 if (current_function_uses_only_leaf_regs)
3364 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3365 leaf_renumber_regs_insn (DECL_RTL (parms));
3367 #endif
3369 if (PARM_PASSED_IN_MEMORY (parms))
3371 rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3373 /* ??? Here we assume that the parm address is indexed
3374 off the frame pointer or arg pointer.
3375 If that is not true, we produce meaningless results,
3376 but do not crash. */
3377 if (GET_CODE (inrtl) == PLUS
3378 && CONST_INT_P (XEXP (inrtl, 1)))
3379 number = INTVAL (XEXP (inrtl, 1));
3380 else
3381 number = 0;
3383 code = N_PSYM;
3384 number = DEBUGGER_ARG_OFFSET (number, inrtl);
3385 letter = 'p';
3387 /* It is quite tempting to use TREE_TYPE (parms) instead
3388 of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3389 reports the actual type of the parameter, rather than
3390 the promoted type. This certainly makes GDB's life
3391 easier, at least for some ports. The change is a bad
3392 idea however, since GDB expects to be able access the
3393 type without performing any conversions. So for
3394 example, if we were passing a float to an unprototyped
3395 function, gcc will store a double on the stack, but if
3396 we emit a stab saying the type is a float, then gdb
3397 will only read in a single value, and this will produce
3398 an erroneous value. */
3399 eff_type = DECL_ARG_TYPE (parms);
3401 else if (REG_P (DECL_RTL (parms)))
3403 rtx best_rtl;
3405 /* Parm passed in registers and lives in registers or nowhere. */
3406 code = DBX_REGPARM_STABS_CODE;
3407 letter = DBX_REGPARM_STABS_LETTER;
3409 /* For parms passed in registers, it is better to use the
3410 declared type of the variable, not the type it arrived in. */
3411 eff_type = TREE_TYPE (parms);
3413 /* If parm lives in a register, use that register; pretend
3414 the parm was passed there. It would be more consistent
3415 to describe the register where the parm was passed, but
3416 in practice that register usually holds something else.
3417 If the parm lives nowhere, use the register where it
3418 was passed. */
3419 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3420 best_rtl = DECL_RTL (parms);
3421 else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL)
3422 best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0);
3423 else
3424 best_rtl = DECL_INCOMING_RTL (parms);
3426 number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3428 else if (MEM_P (DECL_RTL (parms))
3429 && REG_P (XEXP (DECL_RTL (parms), 0))
3430 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3431 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3432 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
3433 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3434 #endif
3437 /* Parm was passed via invisible reference.
3438 That is, its address was passed in a register.
3439 Output it as if it lived in that register.
3440 The debugger will know from the type
3441 that it was actually passed by invisible reference. */
3443 code = DBX_REGPARM_STABS_CODE;
3445 /* GDB likes this marked with a special letter. */
3446 letter = (use_gnu_debug_info_extensions
3447 ? 'a' : DBX_REGPARM_STABS_LETTER);
3448 eff_type = TREE_TYPE (parms);
3450 /* DECL_RTL looks like (MEM (REG...). Get the register number.
3451 If it is an unallocated pseudo-reg, then use the register where
3452 it was passed instead.
3453 ??? Why is DBX_REGISTER_NUMBER not used here? */
3455 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3456 number = REGNO (XEXP (DECL_RTL (parms), 0));
3457 else
3458 number = REGNO (DECL_INCOMING_RTL (parms));
3460 else if (MEM_P (DECL_RTL (parms))
3461 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3463 /* Parm was passed via invisible reference, with the reference
3464 living on the stack. DECL_RTL looks like
3465 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3466 could look like (MEM (MEM (REG))). */
3468 code = N_PSYM;
3469 letter = 'v';
3470 eff_type = TREE_TYPE (parms);
3472 if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3473 number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3474 else
3475 number = 0;
3477 number = DEBUGGER_ARG_OFFSET (number,
3478 XEXP (XEXP (DECL_RTL (parms), 0), 0));
3480 else if (MEM_P (DECL_RTL (parms))
3481 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3482 /* ??? A constant address for a parm can happen
3483 when the reg it lives in is equiv to a constant in memory.
3484 Should make this not happen, after 2.4. */
3485 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3487 /* Parm was passed in registers but lives on the stack. */
3489 code = N_PSYM;
3490 letter = 'p';
3491 eff_type = TREE_TYPE (parms);
3493 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3494 in which case we want the value of that CONST_INT,
3495 or (MEM (REG ...)),
3496 in which case we use a value of zero. */
3497 if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3498 number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3499 else
3500 number = 0;
3502 /* Make a big endian correction if the mode of the type of the
3503 parameter is not the same as the mode of the rtl. */
3504 if (BYTES_BIG_ENDIAN
3505 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3506 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3507 number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3508 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3510 else
3511 /* ??? We don't know how to represent this argument. */
3512 continue;
3514 dbxout_begin_complex_stabs ();
3516 if (DECL_NAME (parms))
3518 stabstr_I (DECL_NAME (parms));
3519 stabstr_C (':');
3521 else
3522 stabstr_S ("(anon):");
3523 stabstr_C (letter);
3524 dbxout_type (eff_type, 0);
3525 dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3527 DBXOUT_DECR_NESTING;
3530 /* Output definitions for the places where parms live during the function,
3531 when different from where they were passed, when the parms were passed
3532 in memory.
3534 It is not useful to do this for parms passed in registers
3535 that live during the function in different registers, because it is
3536 impossible to look in the passed register for the passed value,
3537 so we use the within-the-function register to begin with.
3539 PARMS is a chain of PARM_DECL nodes. */
3541 void
3542 dbxout_reg_parms (tree parms)
3544 ++debug_nesting;
3546 for (; parms; parms = DECL_CHAIN (parms))
3547 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3549 /* Report parms that live in registers during the function
3550 but were passed in memory. */
3551 if (REG_P (DECL_RTL (parms))
3552 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3553 dbxout_symbol_location (parms, TREE_TYPE (parms),
3554 0, DECL_RTL (parms));
3555 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3556 dbxout_symbol_location (parms, TREE_TYPE (parms),
3557 0, DECL_RTL (parms));
3558 /* Report parms that live in memory but not where they were passed. */
3559 else if (MEM_P (DECL_RTL (parms))
3560 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3561 dbxout_symbol_location (parms, TREE_TYPE (parms),
3562 0, DECL_RTL (parms));
3564 DBXOUT_DECR_NESTING;
3567 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3568 output definitions of those names, in raw form */
3570 static void
3571 dbxout_args (tree args)
3573 while (args)
3575 stabstr_C (',');
3576 dbxout_type (TREE_VALUE (args), 0);
3577 args = TREE_CHAIN (args);
3581 #if defined (DBX_DEBUGGING_INFO)
3583 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3584 BEGIN_LABEL is the name of the beginning of the function, which may
3585 be required. */
3586 static void
3587 dbx_output_lbrac (const char *label,
3588 const char *begin_label ATTRIBUTE_UNUSED)
3590 dbxout_begin_stabn (N_LBRAC);
3591 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3592 dbxout_stab_value_label_diff (label, begin_label);
3593 else
3594 dbxout_stab_value_label (label);
3597 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3598 BEGIN_LABEL is the name of the beginning of the function, which may
3599 be required. */
3600 static void
3601 dbx_output_rbrac (const char *label,
3602 const char *begin_label ATTRIBUTE_UNUSED)
3604 dbxout_begin_stabn (N_RBRAC);
3605 if (DBX_BLOCKS_FUNCTION_RELATIVE)
3606 dbxout_stab_value_label_diff (label, begin_label);
3607 else
3608 dbxout_stab_value_label (label);
3611 /* Output everything about a symbol block (a BLOCK node
3612 that represents a scope level),
3613 including recursive output of contained blocks.
3615 BLOCK is the BLOCK node.
3616 DEPTH is its depth within containing symbol blocks.
3617 ARGS is usually zero; but for the outermost block of the
3618 body of a function, it is a chain of PARM_DECLs for the function parameters.
3619 We output definitions of all the register parms
3620 as if they were local variables of that block.
3622 If -g1 was used, we count blocks just the same, but output nothing
3623 except for the outermost block.
3625 Actually, BLOCK may be several blocks chained together.
3626 We handle them all in sequence. */
3628 static void
3629 dbxout_block (tree block, int depth, tree args)
3631 char begin_label[20];
3632 /* Reference current function start using LFBB. */
3633 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
3635 while (block)
3637 /* Ignore blocks never expanded or otherwise marked as real. */
3638 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3640 int did_output;
3641 int blocknum = BLOCK_NUMBER (block);
3643 /* In dbx format, the syms of a block come before the N_LBRAC.
3644 If nothing is output, we don't need the N_LBRAC, either. */
3645 did_output = 0;
3646 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3647 did_output = dbxout_syms (BLOCK_VARS (block));
3648 if (args)
3649 dbxout_reg_parms (args);
3651 /* Now output an N_LBRAC symbol to represent the beginning of
3652 the block. Use the block's tree-walk order to generate
3653 the assembler symbols LBBn and LBEn
3654 that final will define around the code in this block. */
3655 if (did_output)
3657 char buf[20];
3658 const char *scope_start;
3660 if (depth == 0)
3661 /* The outermost block doesn't get LBB labels; use
3662 the LFBB local symbol emitted by dbxout_begin_prologue. */
3663 scope_start = begin_label;
3664 else
3666 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3667 scope_start = buf;
3670 dbx_output_lbrac (scope_start, begin_label);
3673 /* Output the subblocks. */
3674 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3676 /* Refer to the marker for the end of the block. */
3677 if (did_output)
3679 char buf[100];
3680 if (depth == 0)
3681 /* The outermost block doesn't get LBE labels;
3682 use the "scope" label which will be emitted
3683 by dbxout_function_end. */
3684 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3685 else
3686 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3688 dbx_output_rbrac (buf, begin_label);
3691 block = BLOCK_CHAIN (block);
3695 /* Output the information about a function and its arguments and result.
3696 Usually this follows the function's code,
3697 but on some systems, it comes before. */
3699 static void
3700 dbxout_begin_function (tree decl)
3702 int saved_tree_used1;
3704 saved_tree_used1 = TREE_USED (decl);
3705 TREE_USED (decl) = 1;
3706 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3708 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3709 TREE_USED (DECL_RESULT (decl)) = 1;
3710 dbxout_symbol (decl, 0);
3711 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3713 else
3714 dbxout_symbol (decl, 0);
3715 TREE_USED (decl) = saved_tree_used1;
3717 dbxout_parms (DECL_ARGUMENTS (decl));
3718 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3719 dbxout_symbol (DECL_RESULT (decl), 1);
3721 #endif /* DBX_DEBUGGING_INFO */
3723 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3725 #include "gt-dbxout.h"