* config/i386/i386.c (output_fp_compare): Add generation
[official-gcc.git] / gcc / dbxout.c
blob9527c1de26dfc4a72f61bfb639bc5a4ac98f7401
1 /* Output dbx-format symbol table information from GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 /* Output dbx-format symbol table data.
24 This consists of many symbol table entries, each of them
25 a .stabs assembler pseudo-op with four operands:
26 a "name" which is really a description of one symbol and its type,
27 a "code", which is a symbol defined in stab.h whose name starts with N_,
28 an unused operand always 0,
29 and a "value" which is an address or an offset.
30 The name is enclosed in doublequote characters.
32 Each function, variable, typedef, and structure tag
33 has a symbol table entry to define it.
34 The beginning and end of each level of name scoping within
35 a function are also marked by special symbol table entries.
37 The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
38 and a data type number. The data type number may be followed by
39 "=" and a type definition; normally this will happen the first time
40 the type number is mentioned. The type definition may refer to
41 other types by number, and those type numbers may be followed
42 by "=" and nested definitions.
44 This can make the "name" quite long.
45 When a name is more than 80 characters, we split the .stabs pseudo-op
46 into two .stabs pseudo-ops, both sharing the same "code" and "value".
47 The first one is marked as continued with a double-backslash at the
48 end of its "name".
50 The kind-of-symbol letter distinguished function names from global
51 variables from file-scope variables from parameters from auto
52 variables in memory from typedef names from register variables.
53 See `dbxout_symbol'.
55 The "code" is mostly redundant with the kind-of-symbol letter
56 that goes in the "name", but not entirely: for symbols located
57 in static storage, the "code" says which segment the address is in,
58 which controls how it is relocated.
60 The "value" for a symbol in static storage
61 is the core address of the symbol (actually, the assembler
62 label for the symbol). For a symbol located in a stack slot
63 it is the stack offset; for one in a register, the register number.
64 For a typedef symbol, it is zero.
66 If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
67 output while in the text section.
69 For more on data type definitions, see `dbxout_type'. */
71 #include "config.h"
72 #include "system.h"
73 #include "coretypes.h"
74 #include "tm.h"
76 #include "tree.h"
77 #include "rtl.h"
78 #include "flags.h"
79 #include "regs.h"
80 #include "insn-config.h"
81 #include "reload.h"
82 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions. */
83 #include "dbxout.h"
84 #include "toplev.h"
85 #include "tm_p.h"
86 #include "ggc.h"
87 #include "debug.h"
88 #include "function.h"
89 #include "target.h"
90 #include "langhooks.h"
92 #ifdef XCOFF_DEBUGGING_INFO
93 #include "xcoffout.h"
94 #endif
96 #undef DBXOUT_DECR_NESTING
97 #define DBXOUT_DECR_NESTING \
98 if (--debug_nesting == 0 && symbol_queue_index > 0) \
99 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
101 #undef DBXOUT_DECR_NESTING_AND_RETURN
102 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
103 do {--debug_nesting; return (x);} while (0)
105 #ifndef ASM_STABS_OP
106 #define ASM_STABS_OP "\t.stabs\t"
107 #endif
109 #ifndef ASM_STABN_OP
110 #define ASM_STABN_OP "\t.stabn\t"
111 #endif
113 #ifndef DBX_TYPE_DECL_STABS_CODE
114 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
115 #endif
117 #ifndef DBX_STATIC_CONST_VAR_CODE
118 #define DBX_STATIC_CONST_VAR_CODE N_FUN
119 #endif
121 #ifndef DBX_REGPARM_STABS_CODE
122 #define DBX_REGPARM_STABS_CODE N_RSYM
123 #endif
125 #ifndef DBX_REGPARM_STABS_LETTER
126 #define DBX_REGPARM_STABS_LETTER 'P'
127 #endif
129 /* This is used for parameters passed by invisible reference in a register. */
130 #ifndef GDB_INV_REF_REGPARM_STABS_LETTER
131 #define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
132 #endif
134 #ifndef DBX_MEMPARM_STABS_LETTER
135 #define DBX_MEMPARM_STABS_LETTER 'p'
136 #endif
138 #ifndef FILE_NAME_JOINER
139 #define FILE_NAME_JOINER "/"
140 #endif
142 /* GDB needs to know that the stabs were generated by GCC. We emit an
143 N_OPT stab at the beginning of the source file to indicate this.
144 The string is historical, and different on a very few targets. */
145 #ifndef STABS_GCC_MARKER
146 #define STABS_GCC_MARKER "gcc2_compiled."
147 #endif
149 #ifndef NO_DBX_FUNCTION_END
150 #define NO_DBX_FUNCTION_END 0
151 #endif
153 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
155 /* Structure recording information about a C data type.
156 The status element says whether we have yet output
157 the definition of the type. TYPE_XREF says we have
158 output it as a cross-reference only.
159 The file_number and type_number elements are used if DBX_USE_BINCL
160 is defined. */
162 struct typeinfo GTY(())
164 enum typestatus status;
165 int file_number;
166 int type_number;
169 /* Vector recording information about C data types.
170 When we first notice a data type (a tree node),
171 we assign it a number using next_type_number.
172 That is its index in this vector. */
174 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
176 /* Number of elements of space allocated in `typevec'. */
178 static GTY(()) int typevec_len;
180 /* In dbx output, each type gets a unique number.
181 This is the number for the next type output.
182 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
184 static GTY(()) int next_type_number;
186 /* The C front end may call dbxout_symbol before dbxout_init runs.
187 We save all such decls in this list and output them when we get
188 to dbxout_init. */
190 static GTY(()) tree preinit_symbols;
192 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
194 /* When using N_BINCL in dbx output, each type number is actually a
195 pair of the file number and the type number within the file.
196 This is a stack of input files. */
198 struct dbx_file
200 struct dbx_file *next;
201 int file_number;
202 int next_type_number;
203 enum binclstatus bincl_status; /* Keep track of lazy bincl. */
204 const char *pending_bincl_name; /* Name of bincl. */
205 struct dbx_file *prev; /* Chain to traverse all pending bincls. */
208 /* This is the top of the stack.
210 This is not saved for PCH, because restoring a PCH should not change it.
211 next_file_number does have to be saved, because the PCH may use some
212 file numbers; however, just before restoring a PCH, next_file_number
213 should always be 0 because we should not have needed any file numbers
214 yet. */
216 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
217 && defined (DBX_USE_BINCL)
218 static struct dbx_file *current_file;
219 #endif
221 /* This is the next file number to use. */
223 static GTY(()) int next_file_number;
225 /* A counter for dbxout_function_end. */
227 static GTY(()) int scope_labelno;
229 /* A counter for dbxout_source_line. */
231 static GTY(()) int dbxout_source_line_counter;
233 /* Nonzero if we have actually used any of the GDB extensions
234 to the debugging format. The idea is that we use them for the
235 first time only if there's a strong reason, but once we have done that,
236 we use them whenever convenient. */
238 static GTY(()) int have_used_extensions = 0;
240 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
241 for the N_SO filename stabs label. */
243 static GTY(()) int source_label_number = 1;
245 /* Last source file name mentioned in a NOTE insn. */
247 static GTY(()) const char *lastfile;
249 /* Used by PCH machinery to detect if 'lastfile' should be reset to
250 base_input_file. */
251 static GTY(()) int lastfile_is_base;
253 /* Typical USG systems don't have stab.h, and they also have
254 no use for DBX-format debugging info. */
256 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
258 #ifdef DBX_USE_BINCL
259 /* If zero then there is no pending BINCL. */
260 static int pending_bincls = 0;
261 #endif
263 /* The original input file name. */
264 static const char *base_input_file;
266 /* Current working directory. */
268 static const char *cwd;
270 #ifdef DEBUG_SYMS_TEXT
271 #define FORCE_TEXT function_section (current_function_decl);
272 #else
273 #define FORCE_TEXT
274 #endif
276 #include "gstab.h"
278 #define STAB_CODE_TYPE enum __stab_debug_code
280 /* 1 if PARM is passed to this function in memory. */
282 #define PARM_PASSED_IN_MEMORY(PARM) \
283 (MEM_P (DECL_INCOMING_RTL (PARM)))
285 /* A C expression for the integer offset value of an automatic variable
286 (N_LSYM) having address X (an RTX). */
287 #ifndef DEBUGGER_AUTO_OFFSET
288 #define DEBUGGER_AUTO_OFFSET(X) \
289 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
290 #endif
292 /* A C expression for the integer offset value of an argument (N_PSYM)
293 having address X (an RTX). The nominal offset is OFFSET. */
294 #ifndef DEBUGGER_ARG_OFFSET
295 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
296 #endif
298 /* Stream for writing to assembler file. */
300 static FILE *asmfile;
302 /* These variables are for dbxout_symbol to communicate to
303 dbxout_finish_symbol.
304 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
305 current_sym_value and current_sym_addr are two ways to address the
306 value to store in the symtab entry.
307 current_sym_addr if nonzero represents the value as an rtx.
308 If that is zero, current_sym_value is used. This is used
309 when the value is an offset (such as for auto variables,
310 register variables and parms). */
312 static STAB_CODE_TYPE current_sym_code;
313 static int current_sym_value;
314 static rtx current_sym_addr;
316 /* Number of chars of symbol-description generated so far for the
317 current symbol. Used by CHARS and CONTIN. */
319 static int current_sym_nchars;
321 /* Report having output N chars of the current symbol-description. */
323 #define CHARS(N) (current_sym_nchars += (N))
325 /* Break the current symbol-description, generating a continuation,
326 if it has become long. */
328 #ifndef DBX_CONTIN_LENGTH
329 #define DBX_CONTIN_LENGTH 80
330 #endif
332 #if DBX_CONTIN_LENGTH > 0
333 #define CONTIN \
334 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
335 #else
336 #define CONTIN do { } while (0)
337 #endif
339 #ifdef DBX_USE_BINCL
340 static void emit_bincl_stab (const char *c);
341 static void emit_pending_bincls (void);
342 #endif
343 static inline void emit_pending_bincls_if_required (void);
345 static void dbxout_init (const char *);
346 static void dbxout_finish (const char *);
347 static void dbxout_start_source_file (unsigned, const char *);
348 static void dbxout_end_source_file (unsigned);
349 static void dbxout_typedefs (tree);
350 static void dbxout_type_index (tree);
351 #if DBX_CONTIN_LENGTH > 0
352 static void dbxout_continue (void);
353 #endif
354 static void dbxout_args (tree);
355 static void dbxout_type_fields (tree);
356 static void dbxout_type_method_1 (tree, const char *);
357 static void dbxout_type_methods (tree);
358 static void dbxout_range_type (tree);
359 static void dbxout_type (tree, int);
360 static bool print_int_cst_bounds_in_octal_p (tree);
361 static void print_int_cst_octal (tree);
362 static void print_octal (unsigned HOST_WIDE_INT, int);
363 static void print_wide_int (HOST_WIDE_INT);
364 static void dbxout_type_name (tree);
365 static void dbxout_class_name_qualifiers (tree);
366 static int dbxout_symbol_location (tree, tree, const char *, rtx);
367 static void dbxout_symbol_name (tree, const char *, int);
368 static void dbxout_prepare_symbol (tree);
369 static void dbxout_finish_symbol (tree);
370 static void dbxout_block (tree, int, tree);
371 static void dbxout_global_decl (tree);
372 static void dbxout_type_decl (tree, int);
373 static void dbxout_handle_pch (unsigned);
375 /* The debug hooks structure. */
376 #if defined (DBX_DEBUGGING_INFO)
378 static void dbxout_source_line (unsigned int, const char *);
379 static void dbxout_begin_prologue (unsigned int, const char *);
380 static void dbxout_source_file (FILE *, const char *);
381 static void dbxout_function_end (void);
382 static void dbxout_begin_function (tree);
383 static void dbxout_begin_block (unsigned, unsigned);
384 static void dbxout_end_block (unsigned, unsigned);
385 static void dbxout_function_decl (tree);
387 const struct gcc_debug_hooks dbx_debug_hooks =
389 dbxout_init,
390 dbxout_finish,
391 debug_nothing_int_charstar,
392 debug_nothing_int_charstar,
393 dbxout_start_source_file,
394 dbxout_end_source_file,
395 dbxout_begin_block,
396 dbxout_end_block,
397 debug_true_tree, /* ignore_block */
398 dbxout_source_line, /* source_line */
399 dbxout_begin_prologue, /* begin_prologue */
400 debug_nothing_int_charstar, /* end_prologue */
401 debug_nothing_int_charstar, /* end_epilogue */
402 #ifdef DBX_FUNCTION_FIRST
403 dbxout_begin_function,
404 #else
405 debug_nothing_tree, /* begin_function */
406 #endif
407 debug_nothing_int, /* end_function */
408 dbxout_function_decl,
409 dbxout_global_decl, /* global_decl */
410 dbxout_type_decl, /* type_decl */
411 debug_nothing_tree_tree, /* imported_module_or_decl */
412 debug_nothing_tree, /* deferred_inline_function */
413 debug_nothing_tree, /* outlining_inline_function */
414 debug_nothing_rtx, /* label */
415 dbxout_handle_pch, /* handle_pch */
416 debug_nothing_rtx /* var_location */
418 #endif /* DBX_DEBUGGING_INFO */
420 #if defined (XCOFF_DEBUGGING_INFO)
421 const struct gcc_debug_hooks xcoff_debug_hooks =
423 dbxout_init,
424 dbxout_finish,
425 debug_nothing_int_charstar,
426 debug_nothing_int_charstar,
427 dbxout_start_source_file,
428 dbxout_end_source_file,
429 xcoffout_begin_block,
430 xcoffout_end_block,
431 debug_true_tree, /* ignore_block */
432 xcoffout_source_line,
433 xcoffout_begin_prologue, /* begin_prologue */
434 debug_nothing_int_charstar, /* end_prologue */
435 xcoffout_end_epilogue,
436 debug_nothing_tree, /* begin_function */
437 xcoffout_end_function,
438 debug_nothing_tree, /* function_decl */
439 dbxout_global_decl, /* global_decl */
440 dbxout_type_decl, /* type_decl */
441 debug_nothing_tree_tree, /* imported_module_or_decl */
442 debug_nothing_tree, /* deferred_inline_function */
443 debug_nothing_tree, /* outlining_inline_function */
444 debug_nothing_rtx, /* label */
445 dbxout_handle_pch, /* handle_pch */
446 debug_nothing_rtx /* var_location */
448 #endif /* XCOFF_DEBUGGING_INFO */
450 #if defined (DBX_DEBUGGING_INFO)
451 static void
452 dbxout_function_end (void)
454 char lscope_label_name[100];
456 /* The Lscope label must be emitted even if we aren't doing anything
457 else; dbxout_block needs it. */
458 function_section (current_function_decl);
460 /* Convert Ltext into the appropriate format for local labels in case
461 the system doesn't insert underscores in front of user generated
462 labels. */
463 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
464 targetm.asm_out.internal_label (asmfile, "Lscope", scope_labelno);
465 scope_labelno++;
467 /* The N_FUN tag at the end of the function is a GNU extension,
468 which may be undesirable, and is unnecessary if we do not have
469 named sections. */
470 if (!use_gnu_debug_info_extensions
471 || NO_DBX_FUNCTION_END
472 || !targetm.have_named_sections)
473 return;
475 /* By convention, GCC will mark the end of a function with an N_FUN
476 symbol and an empty string. */
477 #ifdef DBX_OUTPUT_NFUN
478 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
479 #else
480 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
481 assemble_name (asmfile, lscope_label_name);
482 putc ('-', asmfile);
483 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
484 fprintf (asmfile, "\n");
485 #endif
487 if (!flag_debug_only_used_symbols)
488 fprintf (asmfile, "%s%d,0,0\n", ASM_STABD_OP, N_ENSYM);
490 #endif /* DBX_DEBUGGING_INFO */
492 /* At the beginning of compilation, start writing the symbol table.
493 Initialize `typevec' and output the standard data types of C. */
495 static void
496 dbxout_init (const char *input_file_name)
498 char ltext_label_name[100];
499 tree syms = lang_hooks.decls.getdecls ();
501 asmfile = asm_out_file;
503 typevec_len = 100;
504 typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
506 /* Convert Ltext into the appropriate format for local labels in case
507 the system doesn't insert underscores in front of user generated
508 labels. */
509 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
511 /* Put the current working directory in an N_SO symbol. */
512 if (use_gnu_debug_info_extensions)
514 if (!cwd && (cwd = get_src_pwd ())
515 && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
516 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
517 if (cwd)
519 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
520 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
521 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
522 fprintf (asmfile, "%s", ASM_STABS_OP);
523 output_quoted_string (asmfile, cwd);
524 fprintf (asmfile, ",%d,0,0,", N_SO);
525 assemble_name (asmfile, ltext_label_name);
526 fputc ('\n', asmfile);
527 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
531 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
532 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
533 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
534 /* We include outputting `Ltext:' here,
535 because that gives you a way to override it. */
536 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
537 fprintf (asmfile, "%s", ASM_STABS_OP);
538 output_quoted_string (asmfile, input_file_name);
539 fprintf (asmfile, ",%d,0,0,", N_SO);
540 assemble_name (asmfile, ltext_label_name);
541 fputc ('\n', asmfile);
542 text_section ();
543 targetm.asm_out.internal_label (asmfile, "Ltext", 0);
544 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
546 #ifdef DBX_OUTPUT_GCC_MARKER
547 DBX_OUTPUT_GCC_MARKER (asmfile);
548 #else
549 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
550 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
551 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
552 #endif
554 base_input_file = lastfile = input_file_name;
556 next_type_number = 1;
558 #ifdef DBX_USE_BINCL
559 current_file = xmalloc (sizeof *current_file);
560 current_file->next = NULL;
561 current_file->file_number = 0;
562 current_file->next_type_number = 1;
563 next_file_number = 1;
564 current_file->prev = NULL;
565 current_file->bincl_status = BINCL_NOT_REQUIRED;
566 current_file->pending_bincl_name = NULL;
567 #endif
569 /* Get all permanent types that have typedef names, and output them
570 all, except for those already output. Some language front ends
571 put these declarations in the top-level scope; some do not;
572 the latter are responsible for calling debug_hooks->type_decl from
573 their record_builtin_type function. */
574 dbxout_typedefs (syms);
576 if (preinit_symbols)
578 tree t;
579 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
580 dbxout_symbol (TREE_VALUE (t), 0);
581 preinit_symbols = 0;
585 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
587 static void
588 dbxout_typedefs (tree syms)
590 for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
592 if (TREE_CODE (syms) == TYPE_DECL)
594 tree type = TREE_TYPE (syms);
595 if (TYPE_NAME (type)
596 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
597 && COMPLETE_OR_VOID_TYPE_P (type)
598 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
599 dbxout_symbol (TYPE_NAME (type), 0);
604 #ifdef DBX_USE_BINCL
605 /* Emit BINCL stab using given name. */
606 static void
607 emit_bincl_stab (const char *name)
609 fprintf (asmfile, "%s", ASM_STABS_OP);
610 output_quoted_string (asmfile, name);
611 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
614 /* If there are pending bincls then it is time to emit all of them. */
616 static inline void
617 emit_pending_bincls_if_required (void)
619 if (pending_bincls)
620 emit_pending_bincls ();
623 /* Emit all pending bincls. */
625 static void
626 emit_pending_bincls (void)
628 struct dbx_file *f = current_file;
630 /* Find first pending bincl. */
631 while (f->bincl_status == BINCL_PENDING)
632 f = f->next;
634 /* Now emit all bincls. */
635 f = f->prev;
637 while (f)
639 if (f->bincl_status == BINCL_PENDING)
641 emit_bincl_stab (f->pending_bincl_name);
643 /* Update file number and status. */
644 f->file_number = next_file_number++;
645 f->bincl_status = BINCL_PROCESSED;
647 if (f == current_file)
648 break;
649 f = f->prev;
652 /* All pending bincls have been emitted. */
653 pending_bincls = 0;
656 #else
658 static inline void
659 emit_pending_bincls_if_required (void) {}
660 #endif
662 /* Change to reading from a new source file. Generate a N_BINCL stab. */
664 static void
665 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
666 const char *filename ATTRIBUTE_UNUSED)
668 #ifdef DBX_USE_BINCL
669 struct dbx_file *n = xmalloc (sizeof *n);
671 n->next = current_file;
672 n->next_type_number = 1;
673 /* Do not assign file number now.
674 Delay it until we actually emit BINCL. */
675 n->file_number = 0;
676 n->prev = NULL;
677 current_file->prev = n;
678 n->bincl_status = BINCL_PENDING;
679 n->pending_bincl_name = filename;
680 pending_bincls = 1;
681 current_file = n;
682 #endif
685 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
687 static void
688 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
690 #ifdef DBX_USE_BINCL
691 /* Emit EINCL stab only if BINCL is not pending. */
692 if (current_file->bincl_status == BINCL_PROCESSED)
693 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
694 current_file->bincl_status = BINCL_NOT_REQUIRED;
695 current_file = current_file->next;
696 #endif
699 /* Handle a few odd cases that occur when trying to make PCH files work. */
701 static void
702 dbxout_handle_pch (unsigned at_end)
704 if (! at_end)
706 /* When using the PCH, this file will be included, so we need to output
707 a BINCL. */
708 dbxout_start_source_file (0, lastfile);
710 /* The base file when using the PCH won't be the same as
711 the base file when it's being generated. */
712 lastfile = NULL;
714 else
716 /* ... and an EINCL. */
717 dbxout_end_source_file (0);
719 /* Deal with cases where 'lastfile' was never actually changed. */
720 lastfile_is_base = lastfile == NULL;
724 #if defined (DBX_DEBUGGING_INFO)
725 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
727 static void
728 dbxout_source_file (FILE *file, const char *filename)
730 if (lastfile == 0 && lastfile_is_base)
732 lastfile = base_input_file;
733 lastfile_is_base = 0;
736 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
738 char ltext_label_name[100];
740 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
741 source_label_number);
742 fprintf (file, "%s", ASM_STABS_OP);
743 output_quoted_string (file, filename);
744 fprintf (asmfile, ",%d,0,0,", N_SOL);
745 assemble_name (asmfile, ltext_label_name);
746 fputc ('\n', asmfile);
747 if (current_function_decl != NULL_TREE
748 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
749 ; /* Don't change section amid function. */
750 else
752 if (!in_text_section () && !in_unlikely_text_section ())
753 text_section ();
755 targetm.asm_out.internal_label (file, "Ltext", source_label_number);
756 source_label_number++;
757 lastfile = filename;
761 /* Output N_BNSYM and line number symbol entry. */
763 static void
764 dbxout_begin_prologue (unsigned int lineno, const char *filename)
766 if (use_gnu_debug_info_extensions
767 && !NO_DBX_FUNCTION_END
768 && !flag_debug_only_used_symbols)
769 fprintf (asmfile, "%s%d,0,0\n", ASM_STABD_OP, N_BNSYM);
771 dbxout_source_line (lineno, filename);
774 /* Output a line number symbol entry for source file FILENAME and line
775 number LINENO. */
777 static void
778 dbxout_source_line (unsigned int lineno, const char *filename)
780 dbxout_source_file (asmfile, filename);
782 #ifdef ASM_OUTPUT_SOURCE_LINE
783 dbxout_source_line_counter += 1;
784 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno, dbxout_source_line_counter);
785 #else
786 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
787 #endif
790 /* Describe the beginning of an internal block within a function. */
792 static void
793 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
795 emit_pending_bincls_if_required ();
796 targetm.asm_out.internal_label (asmfile, "LBB", n);
799 /* Describe the end line-number of an internal block within a function. */
801 static void
802 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
804 emit_pending_bincls_if_required ();
805 targetm.asm_out.internal_label (asmfile, "LBE", n);
808 /* Output dbx data for a function definition.
809 This includes a definition of the function name itself (a symbol),
810 definitions of the parameters (locating them in the parameter list)
811 and then output the block that makes up the function's body
812 (including all the auto variables of the function). */
814 static void
815 dbxout_function_decl (tree decl)
817 emit_pending_bincls_if_required ();
818 #ifndef DBX_FUNCTION_FIRST
819 dbxout_begin_function (decl);
820 #endif
821 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
822 #ifdef DBX_OUTPUT_FUNCTION_END
823 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
824 #endif
825 dbxout_function_end ();
828 #endif /* DBX_DEBUGGING_INFO */
830 /* Debug information for a global DECL. Called from toplev.c after
831 compilation proper has finished. */
832 static void
833 dbxout_global_decl (tree decl)
835 if (TREE_CODE (decl) == VAR_DECL
836 && ! DECL_EXTERNAL (decl)
837 && DECL_RTL_SET_P (decl)) /* Not necessary? */
839 int saved_tree_used = TREE_USED (decl);
840 TREE_USED (decl) = 1;
841 dbxout_symbol (decl, 0);
842 TREE_USED (decl) = saved_tree_used;
846 /* This is just a function-type adapter; dbxout_symbol does exactly
847 what we want but returns an int. */
848 static void
849 dbxout_type_decl (tree decl, int local)
851 dbxout_symbol (decl, local);
854 /* At the end of compilation, finish writing the symbol table.
855 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
856 to do nothing. */
858 static void
859 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
861 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
862 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
863 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
865 debug_free_queue ();
868 /* Output the index of a type. */
870 static void
871 dbxout_type_index (tree type)
873 #ifndef DBX_USE_BINCL
874 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
875 CHARS (3);
876 #else
877 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
878 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
879 CHARS (9);
880 #endif
883 #if DBX_CONTIN_LENGTH > 0
884 /* Continue a symbol-description that gets too big.
885 End one symbol table entry with a double-backslash
886 and start a new one, eventually producing something like
887 .stabs "start......\\",code,0,value
888 .stabs "...rest",code,0,value */
890 static void
891 dbxout_continue (void)
893 emit_pending_bincls_if_required ();
894 #ifdef DBX_CONTIN_CHAR
895 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
896 #else
897 fprintf (asmfile, "\\\\");
898 #endif
899 dbxout_finish_symbol (NULL_TREE);
900 fprintf (asmfile, "%s\"", ASM_STABS_OP);
901 current_sym_nchars = 0;
903 #endif /* DBX_CONTIN_LENGTH > 0 */
905 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
906 This must be a separate function because anonymous unions require
907 recursive calls. */
909 static void
910 dbxout_type_fields (tree type)
912 tree tem;
914 /* Output the name, type, position (in bits), size (in bits) of each
915 field that we can support. */
916 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
918 /* If one of the nodes is an error_mark or its type is then
919 return early. */
920 if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
921 return;
923 /* Omit here local type decls until we know how to support them. */
924 if (TREE_CODE (tem) == TYPE_DECL
925 /* Omit fields whose position or size are variable or too large to
926 represent. */
927 || (TREE_CODE (tem) == FIELD_DECL
928 && (! host_integerp (bit_position (tem), 0)
929 || ! DECL_SIZE (tem)
930 || ! host_integerp (DECL_SIZE (tem), 1)))
931 /* Omit here the nameless fields that are used to skip bits. */
932 || DECL_IGNORED_P (tem))
933 continue;
935 else if (TREE_CODE (tem) != CONST_DECL)
937 /* Continue the line if necessary,
938 but not before the first field. */
939 if (tem != TYPE_FIELDS (type))
940 CONTIN;
942 if (DECL_NAME (tem))
944 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
945 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
947 else
949 fprintf (asmfile, ":");
950 CHARS (1);
953 if (use_gnu_debug_info_extensions
954 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
955 || TREE_CODE (tem) != FIELD_DECL))
957 have_used_extensions = 1;
958 putc ('/', asmfile);
959 putc ((TREE_PRIVATE (tem) ? '0'
960 : TREE_PROTECTED (tem) ? '1' : '2'),
961 asmfile);
962 CHARS (2);
965 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
966 && DECL_BIT_FIELD_TYPE (tem))
967 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
969 if (TREE_CODE (tem) == VAR_DECL)
971 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
973 tree name = DECL_ASSEMBLER_NAME (tem);
975 have_used_extensions = 1;
976 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
977 CHARS (IDENTIFIER_LENGTH (name) + 2);
979 else
981 /* If TEM is non-static, GDB won't understand it. */
982 fprintf (asmfile, ",0,0;");
983 CHARS (5);
986 else
988 putc (',', asmfile);
989 print_wide_int (int_bit_position (tem));
990 putc (',', asmfile);
991 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
992 putc (';', asmfile);
993 CHARS (3);
999 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1000 method described DECL. DEBUG_NAME is an encoding of the method's
1001 type signature. ??? We may be able to do without DEBUG_NAME altogether
1002 now. */
1004 static void
1005 dbxout_type_method_1 (tree decl, const char *debug_name)
1007 char c1 = 'A', c2;
1009 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1010 c2 = '?';
1011 else /* it's a METHOD_TYPE. */
1013 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1014 /* A for normal functions.
1015 B for `const' member functions.
1016 C for `volatile' member functions.
1017 D for `const volatile' member functions. */
1018 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1019 c1 += 1;
1020 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1021 c1 += 2;
1023 if (DECL_VINDEX (decl))
1024 c2 = '*';
1025 else
1026 c2 = '.';
1029 fprintf (asmfile, ":%s;%c%c%c", debug_name,
1030 TREE_PRIVATE (decl) ? '0'
1031 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
1032 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
1033 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1035 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1037 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
1038 putc (';', asmfile);
1039 CHARS (1);
1040 dbxout_type (DECL_CONTEXT (decl), 0);
1041 fprintf (asmfile, ";");
1042 CHARS (1);
1046 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1047 in TYPE. */
1049 static void
1050 dbxout_type_methods (tree type)
1052 /* C++: put out the method names and their parameter lists */
1053 tree methods = TYPE_METHODS (type);
1054 tree type_encoding;
1055 tree fndecl;
1056 tree last;
1057 char formatted_type_identifier_length[16];
1058 int type_identifier_length;
1060 if (methods == NULL_TREE)
1061 return;
1063 type_encoding = DECL_NAME (TYPE_NAME (type));
1065 #if 0
1066 /* C++: Template classes break some assumptions made by this code about
1067 the class names, constructor names, and encodings for assembler
1068 label names. For now, disable output of dbx info for them. */
1070 const char *ptr = IDENTIFIER_POINTER (type_encoding);
1071 /* This should use index. (mrs) */
1072 while (*ptr && *ptr != '<') ptr++;
1073 if (*ptr != 0)
1075 static int warned;
1076 if (!warned)
1077 warned = 1;
1078 return;
1081 #endif
1083 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
1085 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
1087 if (TREE_CODE (methods) != TREE_VEC)
1088 fndecl = methods;
1089 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1090 fndecl = TREE_VEC_ELT (methods, 0);
1091 else
1092 fndecl = TREE_VEC_ELT (methods, 1);
1094 while (fndecl)
1096 int need_prefix = 1;
1098 /* Group together all the methods for the same operation.
1099 These differ in the types of the arguments. */
1100 for (last = NULL_TREE;
1101 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1102 fndecl = TREE_CHAIN (fndecl))
1103 /* Output the name of the field (after overloading), as
1104 well as the name of the field before overloading, along
1105 with its parameter list */
1107 /* This is the "mangled" name of the method.
1108 It encodes the argument types. */
1109 const char *debug_name;
1111 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1112 include TEMPLATE_DECLs.) The debugger doesn't know what
1113 to do with such entities anyhow. */
1114 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1115 continue;
1117 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1119 CONTIN;
1121 last = fndecl;
1123 /* Also ignore abstract methods; those are only interesting to
1124 the DWARF backends. */
1125 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1126 continue;
1128 /* Redundantly output the plain name, since that's what gdb
1129 expects. */
1130 if (need_prefix)
1132 tree name = DECL_NAME (fndecl);
1133 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1134 CHARS (IDENTIFIER_LENGTH (name) + 2);
1135 need_prefix = 0;
1138 dbxout_type (TREE_TYPE (fndecl), 0);
1140 dbxout_type_method_1 (fndecl, debug_name);
1142 if (!need_prefix)
1144 putc (';', asmfile);
1145 CHARS (1);
1150 /* Emit a "range" type specification, which has the form:
1151 "r<index type>;<lower bound>;<upper bound>;".
1152 TYPE is an INTEGER_TYPE. */
1154 static void
1155 dbxout_range_type (tree type)
1157 fprintf (asmfile, "r");
1158 if (TREE_TYPE (type))
1159 dbxout_type (TREE_TYPE (type), 0);
1160 else if (TREE_CODE (type) != INTEGER_TYPE)
1161 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1162 else
1164 /* Traditionally, we made sure 'int' was type 1, and builtin types
1165 were defined to be sub-ranges of int. Unfortunately, this
1166 does not allow us to distinguish true sub-ranges from integer
1167 types. So, instead we define integer (non-sub-range) types as
1168 sub-ranges of themselves. This matters for Chill. If this isn't
1169 a subrange type, then we want to define it in terms of itself.
1170 However, in C, this may be an anonymous integer type, and we don't
1171 want to emit debug info referring to it. Just calling
1172 dbxout_type_index won't work anyways, because the type hasn't been
1173 defined yet. We make this work for both cases by checked to see
1174 whether this is a defined type, referring to it if it is, and using
1175 'int' otherwise. */
1176 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1177 dbxout_type_index (type);
1178 else
1179 dbxout_type_index (integer_type_node);
1182 if (TYPE_MIN_VALUE (type) != 0
1183 && host_integerp (TYPE_MIN_VALUE (type), 0))
1185 putc (';', asmfile);
1186 CHARS (1);
1187 if (print_int_cst_bounds_in_octal_p (type))
1188 print_int_cst_octal (TYPE_MIN_VALUE (type));
1189 else
1190 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1192 else
1194 fprintf (asmfile, ";0");
1195 CHARS (2);
1198 if (TYPE_MAX_VALUE (type) != 0
1199 && host_integerp (TYPE_MAX_VALUE (type), 0))
1201 putc (';', asmfile);
1202 CHARS (1);
1203 if (print_int_cst_bounds_in_octal_p (type))
1204 print_int_cst_octal (TYPE_MAX_VALUE (type));
1205 else
1206 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1207 putc (';', asmfile);
1208 CHARS (1);
1210 else
1212 fprintf (asmfile, ";-1;");
1213 CHARS (4);
1218 /* Output a reference to a type. If the type has not yet been
1219 described in the dbx output, output its definition now.
1220 For a type already defined, just refer to its definition
1221 using the type number.
1223 If FULL is nonzero, and the type has been described only with
1224 a forward-reference, output the definition now.
1225 If FULL is zero in this case, just refer to the forward-reference
1226 using the number previously allocated. */
1228 static void
1229 dbxout_type (tree type, int full)
1231 tree tem;
1232 tree main_variant;
1233 static int anonymous_type_number = 0;
1235 if (TREE_CODE (type) == VECTOR_TYPE)
1236 /* The frontend feeds us a representation for the vector as a struct
1237 containing an array. Pull out the array type. */
1238 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1240 /* If there was an input error and we don't really have a type,
1241 avoid crashing and write something that is at least valid
1242 by assuming `int'. */
1243 if (type == error_mark_node)
1244 type = integer_type_node;
1245 else
1247 if (TYPE_NAME (type)
1248 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1249 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1250 full = 0;
1253 /* Try to find the "main variant" with the same name. */
1254 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1255 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1256 main_variant = TREE_TYPE (TYPE_NAME (type));
1257 else
1258 main_variant = TYPE_MAIN_VARIANT (type);
1260 /* If we are not using extensions, stabs does not distinguish const and
1261 volatile, so there is no need to make them separate types. */
1262 if (!use_gnu_debug_info_extensions)
1263 type = main_variant;
1265 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1267 /* Type has no dbx number assigned. Assign next available number. */
1268 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1270 /* Make sure type vector is long enough to record about this type. */
1272 if (next_type_number == typevec_len)
1274 typevec
1275 = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1276 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1277 typevec_len *= 2;
1280 #ifdef DBX_USE_BINCL
1281 emit_pending_bincls_if_required ();
1282 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1283 = current_file->file_number;
1284 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1285 = current_file->next_type_number++;
1286 #endif
1289 if (flag_debug_only_used_symbols)
1291 if ((TREE_CODE (type) == RECORD_TYPE
1292 || TREE_CODE (type) == UNION_TYPE
1293 || TREE_CODE (type) == QUAL_UNION_TYPE
1294 || TREE_CODE (type) == ENUMERAL_TYPE)
1295 && TYPE_STUB_DECL (type)
1296 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (type))) == 'd'
1297 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1298 debug_queue_symbol (TYPE_STUB_DECL (type));
1299 else if (TYPE_NAME (type)
1300 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1301 debug_queue_symbol (TYPE_NAME (type));
1304 /* Output the number of this type, to refer to it. */
1305 dbxout_type_index (type);
1307 #ifdef DBX_TYPE_DEFINED
1308 if (DBX_TYPE_DEFINED (type))
1309 return;
1310 #endif
1312 /* If this type's definition has been output or is now being output,
1313 that is all. */
1315 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1317 case TYPE_UNSEEN:
1318 break;
1319 case TYPE_XREF:
1320 /* If we have already had a cross reference,
1321 and either that's all we want or that's the best we could do,
1322 don't repeat the cross reference.
1323 Sun dbx crashes if we do. */
1324 if (! full || !COMPLETE_TYPE_P (type)
1325 /* No way in DBX fmt to describe a variable size. */
1326 || ! host_integerp (TYPE_SIZE (type), 1))
1327 return;
1328 break;
1329 case TYPE_DEFINED:
1330 return;
1333 #ifdef DBX_NO_XREFS
1334 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1335 leave the type-number completely undefined rather than output
1336 a cross-reference. If we have already used GNU debug info extensions,
1337 then it is OK to output a cross reference. This is necessary to get
1338 proper C++ debug output. */
1339 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1340 || TREE_CODE (type) == QUAL_UNION_TYPE
1341 || TREE_CODE (type) == ENUMERAL_TYPE)
1342 && ! use_gnu_debug_info_extensions)
1343 /* We must use the same test here as we use twice below when deciding
1344 whether to emit a cross-reference. */
1345 if ((TYPE_NAME (type) != 0
1346 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1347 && DECL_IGNORED_P (TYPE_NAME (type)))
1348 && !full)
1349 || !COMPLETE_TYPE_P (type)
1350 /* No way in DBX fmt to describe a variable size. */
1351 || ! host_integerp (TYPE_SIZE (type), 1))
1353 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1354 return;
1356 #endif
1358 /* Output a definition now. */
1360 fprintf (asmfile, "=");
1361 CHARS (1);
1363 /* Mark it as defined, so that if it is self-referent
1364 we will not get into an infinite recursion of definitions. */
1366 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1368 /* If this type is a variant of some other, hand off. Types with
1369 different names are usefully distinguished. We only distinguish
1370 cv-qualified types if we're using extensions. */
1371 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1373 putc ('k', asmfile);
1374 CHARS (1);
1375 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1376 return;
1378 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1380 putc ('B', asmfile);
1381 CHARS (1);
1382 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1383 return;
1385 else if (main_variant != TYPE_MAIN_VARIANT (type))
1387 if (flag_debug_only_used_symbols)
1389 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1391 if ((TREE_CODE (orig_type) == RECORD_TYPE
1392 || TREE_CODE (orig_type) == UNION_TYPE
1393 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1394 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1395 && TYPE_STUB_DECL (orig_type)
1396 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1397 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1399 /* 'type' is a typedef; output the type it refers to. */
1400 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1401 return;
1403 /* else continue. */
1405 switch (TREE_CODE (type))
1407 case VOID_TYPE:
1408 case LANG_TYPE:
1409 /* For a void type, just define it as itself; ie, "5=5".
1410 This makes us consider it defined
1411 without saying what it is. The debugger will make it
1412 a void type when the reference is seen, and nothing will
1413 ever override that default. */
1414 dbxout_type_index (type);
1415 break;
1417 case INTEGER_TYPE:
1418 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1420 /* Output the type `char' as a subrange of itself!
1421 I don't understand this definition, just copied it
1422 from the output of pcc.
1423 This used to use `r2' explicitly and we used to
1424 take care to make sure that `char' was type number 2. */
1425 fprintf (asmfile, "r");
1426 CHARS (1);
1427 dbxout_type_index (type);
1428 fprintf (asmfile, ";0;127;");
1429 CHARS (7);
1432 /* If this is a subtype of another integer type, always prefer to
1433 write it as a subtype. */
1434 else if (TREE_TYPE (type) != 0
1435 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1437 /* If the size is non-standard, say what it is if we can use
1438 GDB extensions. */
1440 if (use_gnu_debug_info_extensions
1441 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1443 have_used_extensions = 1;
1444 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1445 CHARS (5);
1448 dbxout_range_type (type);
1451 else
1453 /* If the size is non-standard, say what it is if we can use
1454 GDB extensions. */
1456 if (use_gnu_debug_info_extensions
1457 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1459 have_used_extensions = 1;
1460 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1461 CHARS (5);
1464 if (print_int_cst_bounds_in_octal_p (type))
1466 fprintf (asmfile, "r");
1467 CHARS (1);
1469 /* If this type derives from another type, output type index of
1470 parent type. This is particularly important when parent type
1471 is an enumerated type, because not generating the parent type
1472 index would transform the definition of this enumerated type
1473 into a plain unsigned type. */
1474 if (TREE_TYPE (type) != 0)
1475 dbxout_type_index (TREE_TYPE (type));
1476 else
1477 dbxout_type_index (type);
1479 fprintf (asmfile, ";");
1480 CHARS (1);
1481 print_int_cst_octal (TYPE_MIN_VALUE (type));
1482 fprintf (asmfile, ";");
1483 CHARS (1);
1484 print_int_cst_octal (TYPE_MAX_VALUE (type));
1485 fprintf (asmfile, ";");
1486 CHARS (1);
1489 else
1490 /* Output other integer types as subranges of `int'. */
1491 dbxout_range_type (type);
1494 break;
1496 case REAL_TYPE:
1497 /* This used to say `r1' and we used to take care
1498 to make sure that `int' was type number 1. */
1499 fprintf (asmfile, "r");
1500 CHARS (1);
1501 dbxout_type_index (integer_type_node);
1502 putc (';', asmfile);
1503 CHARS (1);
1504 print_wide_int (int_size_in_bytes (type));
1505 fputs (";0;", asmfile);
1506 CHARS (3);
1507 break;
1509 case CHAR_TYPE:
1510 if (use_gnu_debug_info_extensions)
1512 have_used_extensions = 1;
1513 fputs ("@s", asmfile);
1514 CHARS (2);
1515 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1516 fputs (";-20;", asmfile);
1517 CHARS (4);
1519 else
1521 /* Output the type `char' as a subrange of itself.
1522 That is what pcc seems to do. */
1523 fprintf (asmfile, "r");
1524 CHARS (1);
1525 dbxout_type_index (char_type_node);
1526 fprintf (asmfile, ";0;%d;", TYPE_UNSIGNED (type) ? 255 : 127);
1527 CHARS (7);
1529 break;
1531 case BOOLEAN_TYPE:
1532 if (use_gnu_debug_info_extensions)
1534 have_used_extensions = 1;
1535 fputs ("@s", asmfile);
1536 CHARS (2);
1537 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1538 fputs (";-16;", asmfile);
1539 CHARS (4);
1541 else /* Define as enumeral type (False, True) */
1543 fprintf (asmfile, "eFalse:0,True:1,;");
1544 CHARS (17);
1546 break;
1548 case FILE_TYPE:
1549 putc ('d', asmfile);
1550 CHARS (1);
1551 dbxout_type (TREE_TYPE (type), 0);
1552 break;
1554 case COMPLEX_TYPE:
1555 /* Differs from the REAL_TYPE by its new data type number.
1556 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
1557 codes since gdb doesn't care anyway. */
1559 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1561 fputs ("R3;", asmfile);
1562 CHARS (3);
1563 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1564 fputs (";0;", asmfile);
1565 CHARS (3);
1567 else
1569 /* Output a complex integer type as a structure,
1570 pending some other way to do it. */
1571 putc ('s', asmfile);
1572 CHARS (1);
1573 print_wide_int (int_size_in_bytes (type));
1574 fprintf (asmfile, "real:");
1575 CHARS (5);
1577 dbxout_type (TREE_TYPE (type), 0);
1578 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1579 CHARS (7);
1580 fprintf (asmfile, "imag:");
1581 CHARS (5);
1582 dbxout_type (TREE_TYPE (type), 0);
1583 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1584 TYPE_PRECISION (TREE_TYPE (type)));
1585 CHARS (10);
1587 break;
1589 case SET_TYPE:
1590 if (use_gnu_debug_info_extensions)
1592 have_used_extensions = 1;
1593 fputs ("@s", asmfile);
1594 CHARS (2);
1595 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1596 putc (';', asmfile);
1597 CHARS (1);
1599 /* Check if a bitstring type, which in Chill is
1600 different from a [power]set. */
1601 if (TYPE_STRING_FLAG (type))
1603 fprintf (asmfile, "@S;");
1604 CHARS (3);
1607 putc ('S', asmfile);
1608 CHARS (1);
1609 dbxout_type (TYPE_DOMAIN (type), 0);
1610 break;
1612 case ARRAY_TYPE:
1613 /* Make arrays of packed bits look like bitstrings for chill. */
1614 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1616 have_used_extensions = 1;
1617 fputs ("@s", asmfile);
1618 CHARS (2);
1619 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1620 fprintf (asmfile, ";@S;S");
1621 CHARS (5);
1622 dbxout_type (TYPE_DOMAIN (type), 0);
1623 break;
1626 /* Output "a" followed by a range type definition
1627 for the index type of the array
1628 followed by a reference to the target-type.
1629 ar1;0;N;M for a C array of type M and size N+1. */
1630 /* Check if a character string type, which in Chill is
1631 different from an array of characters. */
1632 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1634 have_used_extensions = 1;
1635 fprintf (asmfile, "@S;");
1636 CHARS (3);
1638 tem = TYPE_DOMAIN (type);
1639 if (tem == NULL)
1641 fprintf (asmfile, "ar");
1642 CHARS (2);
1643 dbxout_type_index (integer_type_node);
1644 fprintf (asmfile, ";0;-1;");
1645 CHARS (6);
1647 else
1649 fprintf (asmfile, "a");
1650 CHARS (1);
1651 dbxout_range_type (tem);
1654 dbxout_type (TREE_TYPE (type), 0);
1655 break;
1657 case RECORD_TYPE:
1658 case UNION_TYPE:
1659 case QUAL_UNION_TYPE:
1661 tree binfo = TYPE_BINFO (type);
1663 /* Output a structure type. We must use the same test here as we
1664 use in the DBX_NO_XREFS case above. */
1665 if ((TYPE_NAME (type) != 0
1666 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1667 && DECL_IGNORED_P (TYPE_NAME (type)))
1668 && !full)
1669 || !COMPLETE_TYPE_P (type)
1670 /* No way in DBX fmt to describe a variable size. */
1671 || ! host_integerp (TYPE_SIZE (type), 1))
1673 /* If the type is just a cross reference, output one
1674 and mark the type as partially described.
1675 If it later becomes defined, we will output
1676 its real definition.
1677 If the type has a name, don't nest its definition within
1678 another type's definition; instead, output an xref
1679 and let the definition come when the name is defined. */
1680 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1681 CHARS (2);
1682 #if 0 /* This assertion is legitimately false in C++. */
1683 /* We shouldn't be outputting a reference to a type before its
1684 definition unless the type has a tag name.
1685 A typedef name without a tag name should be impossible. */
1686 gcc_assert (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE);
1687 #endif
1688 if (TYPE_NAME (type) != 0)
1689 dbxout_type_name (type);
1690 else
1692 fprintf (asmfile, "$$%d", anonymous_type_number++);
1693 CHARS (5);
1696 fprintf (asmfile, ":");
1697 CHARS (1);
1698 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1699 break;
1702 /* Identify record or union, and print its size. */
1703 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1704 CHARS (1);
1705 print_wide_int (int_size_in_bytes (type));
1707 if (binfo)
1709 int i;
1710 tree child;
1711 VEC (tree) *accesses = BINFO_BASE_ACCESSES (binfo);
1713 if (use_gnu_debug_info_extensions)
1715 if (BINFO_N_BASE_BINFOS (binfo))
1717 have_used_extensions = 1;
1718 fprintf (asmfile, "!%u,", BINFO_N_BASE_BINFOS (binfo));
1719 CHARS (8);
1722 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
1724 tree access = (accesses ? VEC_index (tree, accesses, i)
1725 : access_public_node);
1727 if (use_gnu_debug_info_extensions)
1729 have_used_extensions = 1;
1730 putc (BINFO_VIRTUAL_P (child) ? '1' : '0', asmfile);
1731 putc (access == access_public_node ? '2' :
1732 (access == access_protected_node ? '1' :'0'),
1733 asmfile);
1734 CHARS (2);
1735 if (BINFO_VIRTUAL_P (child)
1736 && strcmp (lang_hooks.name, "GNU C++") == 0)
1737 /* For a virtual base, print the (negative)
1738 offset within the vtable where we must look
1739 to find the necessary adjustment. */
1740 print_wide_int
1741 (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1742 * BITS_PER_UNIT);
1743 else
1744 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1745 * BITS_PER_UNIT);
1746 putc (',', asmfile);
1747 CHARS (1);
1748 dbxout_type (BINFO_TYPE (child), 0);
1749 putc (';', asmfile);
1750 CHARS (1);
1752 else
1754 /* Print out the base class information with
1755 fields which have the same names at the types
1756 they hold. */
1757 dbxout_type_name (BINFO_TYPE (child));
1758 putc (':', asmfile);
1759 CHARS (1);
1760 dbxout_type (BINFO_TYPE (child), full);
1761 putc (',', asmfile);
1762 CHARS (1);
1763 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1764 * BITS_PER_UNIT);
1765 putc (',', asmfile);
1766 CHARS (1);
1767 print_wide_int
1768 (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
1769 * BITS_PER_UNIT);
1770 putc (';', asmfile);
1771 CHARS (1);
1777 /* Write out the field declarations. */
1778 dbxout_type_fields (type);
1779 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1781 have_used_extensions = 1;
1782 dbxout_type_methods (type);
1785 putc (';', asmfile);
1786 CHARS (1);
1788 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1789 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1790 && TYPE_VFIELD (type))
1792 have_used_extensions = 1;
1794 /* Tell GDB+ that it may keep reading. */
1795 putc ('~', asmfile);
1796 CHARS (1);
1798 /* We need to write out info about what field this class
1799 uses as its "main" vtable pointer field, because if this
1800 field is inherited from a base class, GDB cannot necessarily
1801 figure out which field it's using in time. */
1802 if (TYPE_VFIELD (type))
1804 putc ('%', asmfile);
1805 CHARS (1);
1806 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1809 putc (';', asmfile);
1810 CHARS (1);
1812 break;
1814 case ENUMERAL_TYPE:
1815 /* We must use the same test here as we use in the DBX_NO_XREFS case
1816 above. We simplify it a bit since an enum will never have a variable
1817 size. */
1818 if ((TYPE_NAME (type) != 0
1819 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1820 && DECL_IGNORED_P (TYPE_NAME (type)))
1821 && !full)
1822 || !COMPLETE_TYPE_P (type))
1824 fprintf (asmfile, "xe");
1825 CHARS (2);
1826 dbxout_type_name (type);
1827 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1828 putc (':', asmfile);
1829 CHARS (1);
1830 return;
1832 if (use_gnu_debug_info_extensions
1833 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1835 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1836 CHARS (5);
1839 putc ('e', asmfile);
1840 CHARS (1);
1841 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1843 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1844 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1845 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1846 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1847 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1848 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1849 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1850 else
1851 print_int_cst_octal (TREE_VALUE (tem));
1853 putc (',', asmfile);
1854 CHARS (1);
1855 if (TREE_CHAIN (tem) != 0)
1856 CONTIN;
1859 putc (';', asmfile);
1860 CHARS (1);
1861 break;
1863 case POINTER_TYPE:
1864 putc ('*', asmfile);
1865 CHARS (1);
1866 dbxout_type (TREE_TYPE (type), 0);
1867 break;
1869 case METHOD_TYPE:
1870 if (use_gnu_debug_info_extensions)
1872 have_used_extensions = 1;
1873 putc ('#', asmfile);
1874 CHARS (1);
1876 /* Write the argument types out longhand. */
1877 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1878 putc (',', asmfile);
1879 CHARS (1);
1880 dbxout_type (TREE_TYPE (type), 0);
1881 dbxout_args (TYPE_ARG_TYPES (type));
1882 putc (';', asmfile);
1883 CHARS (1);
1885 else
1886 /* Treat it as a function type. */
1887 dbxout_type (TREE_TYPE (type), 0);
1888 break;
1890 case OFFSET_TYPE:
1891 if (use_gnu_debug_info_extensions)
1893 have_used_extensions = 1;
1894 putc ('@', asmfile);
1895 CHARS (1);
1896 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1897 putc (',', asmfile);
1898 CHARS (1);
1899 dbxout_type (TREE_TYPE (type), 0);
1901 else
1902 /* Should print as an int, because it is really just an offset. */
1903 dbxout_type (integer_type_node, 0);
1904 break;
1906 case REFERENCE_TYPE:
1907 if (use_gnu_debug_info_extensions)
1908 have_used_extensions = 1;
1909 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1910 CHARS (1);
1911 dbxout_type (TREE_TYPE (type), 0);
1912 break;
1914 case FUNCTION_TYPE:
1915 putc ('f', asmfile);
1916 CHARS (1);
1917 dbxout_type (TREE_TYPE (type), 0);
1918 break;
1920 default:
1921 gcc_unreachable ();
1925 /* Return nonzero if the given type represents an integer whose bounds
1926 should be printed in octal format. */
1928 static bool
1929 print_int_cst_bounds_in_octal_p (tree type)
1931 /* If we can use GDB extensions and the size is wider than a long
1932 (the size used by GDB to read them) or we may have trouble writing
1933 the bounds the usual way, write them in octal. Note the test is for
1934 the *target's* size of "long", not that of the host. The host test
1935 is just to make sure we can write it out in case the host wide int
1936 is narrower than the target "long".
1938 For unsigned types, we use octal if they are the same size or larger.
1939 This is because we print the bounds as signed decimal, and hence they
1940 can't span same size unsigned types. */
1942 if (use_gnu_debug_info_extensions
1943 && TYPE_MIN_VALUE (type) != 0
1944 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1945 && TYPE_MAX_VALUE (type) != 0
1946 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1947 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1948 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1949 && TYPE_UNSIGNED (type))
1950 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1951 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1952 && TYPE_UNSIGNED (type))))
1953 return TRUE;
1954 else
1955 return FALSE;
1958 /* Print the value of integer constant C, in octal,
1959 handling double precision. */
1961 static void
1962 print_int_cst_octal (tree c)
1964 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1965 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1966 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1967 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1969 /* GDB wants constants with no extra leading "1" bits, so
1970 we need to remove any sign-extension that might be
1971 present. */
1972 if (width == HOST_BITS_PER_WIDE_INT * 2)
1974 else if (width > HOST_BITS_PER_WIDE_INT)
1975 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1976 else if (width == HOST_BITS_PER_WIDE_INT)
1977 high = 0;
1978 else
1979 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1981 fprintf (asmfile, "0");
1982 CHARS (1);
1984 if (excess == 3)
1986 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1987 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1989 else
1991 unsigned HOST_WIDE_INT beg = high >> excess;
1992 unsigned HOST_WIDE_INT middle
1993 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1994 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1995 unsigned HOST_WIDE_INT end
1996 = low & (((unsigned HOST_WIDE_INT) 1
1997 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1998 - 1);
2000 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
2001 CHARS (2);
2002 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
2006 static void
2007 print_octal (unsigned HOST_WIDE_INT value, int digits)
2009 int i;
2011 for (i = digits - 1; i >= 0; i--)
2012 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
2014 CHARS (digits);
2017 /* Output C in decimal while adjusting the number of digits written. */
2019 static void
2020 print_wide_int (HOST_WIDE_INT c)
2022 int digs = 0;
2024 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
2026 if (c < 0)
2027 digs++, c = -c;
2029 while (c > 0)
2030 c /= 10; digs++;
2032 CHARS (digs);
2035 /* Output the name of type TYPE, with no punctuation.
2036 Such names can be set up either by typedef declarations
2037 or by struct, enum and union tags. */
2039 static void
2040 dbxout_type_name (tree type)
2042 tree t = TYPE_NAME (type);
2044 gcc_assert (t);
2045 switch (TREE_CODE (t))
2047 case IDENTIFIER_NODE:
2048 break;
2049 case TYPE_DECL:
2050 t = DECL_NAME (t);
2051 break;
2052 default:
2053 gcc_unreachable ();
2056 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
2057 CHARS (IDENTIFIER_LENGTH (t));
2060 /* Output leading leading struct or class names needed for qualifying
2061 type whose scope is limited to a struct or class. */
2063 static void
2064 dbxout_class_name_qualifiers (tree decl)
2066 tree context = decl_type_context (decl);
2068 if (context != NULL_TREE
2069 && TREE_CODE(context) == RECORD_TYPE
2070 && TYPE_NAME (context) != 0
2071 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2072 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2074 tree name = TYPE_NAME (context);
2076 emit_pending_bincls_if_required ();
2078 if (TREE_CODE (name) == TYPE_DECL)
2080 dbxout_class_name_qualifiers (name);
2081 name = DECL_NAME (name);
2083 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
2084 CHARS (IDENTIFIER_LENGTH (name) + 2);
2088 /* Output a .stabs for the symbol defined by DECL,
2089 which must be a ..._DECL node in the normal namespace.
2090 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2091 LOCAL is nonzero if the scope is less than the entire file.
2092 Return 1 if a stabs might have been emitted. */
2095 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2097 tree type = TREE_TYPE (decl);
2098 tree context = NULL_TREE;
2099 int result = 0;
2101 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2102 ++debug_nesting;
2104 /* Ignore nameless syms, but don't ignore type tags. */
2106 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2107 || DECL_IGNORED_P (decl))
2108 DBXOUT_DECR_NESTING_AND_RETURN (0);
2110 /* If we are to generate only the symbols actually used then such
2111 symbol nodees are flagged with TREE_USED. Ignore any that
2112 aren't flaged as TREE_USED. */
2114 if (flag_debug_only_used_symbols
2115 && (!TREE_USED (decl)
2116 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2117 DBXOUT_DECR_NESTING_AND_RETURN (0);
2119 /* If dbxout_init has not yet run, queue this symbol for later. */
2120 if (!typevec)
2122 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2123 DBXOUT_DECR_NESTING_AND_RETURN (0);
2126 if (flag_debug_only_used_symbols)
2128 tree t;
2130 /* We now have a used symbol. We need to generate the info for
2131 the symbol's type in addition to the symbol itself. These
2132 type symbols are queued to be generated after were done with
2133 the symbol itself (done because the symbol's info is generated
2134 with fprintf's, etc. as it determines what's needed).
2136 Note, because the TREE_TYPE(type) might be something like a
2137 pointer to a named type we need to look for the first name
2138 we see following the TREE_TYPE chain. */
2140 t = type;
2141 while (POINTER_TYPE_P (t))
2142 t = TREE_TYPE (t);
2144 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2145 need special treatment. The TYPE_STUB_DECL field in these
2146 types generally represents the tag name type we want to
2147 output. In addition there could be a typedef type with
2148 a different name. In that case we also want to output
2149 that. */
2151 if ((TREE_CODE (t) == RECORD_TYPE
2152 || TREE_CODE (t) == UNION_TYPE
2153 || TREE_CODE (t) == QUAL_UNION_TYPE
2154 || TREE_CODE (t) == ENUMERAL_TYPE)
2155 && TYPE_STUB_DECL (t)
2156 && TYPE_STUB_DECL (t) != decl
2157 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (t))) == 'd'
2158 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2160 debug_queue_symbol (TYPE_STUB_DECL (t));
2161 if (TYPE_NAME (t)
2162 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2163 && TYPE_NAME (t) != decl
2164 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2165 debug_queue_symbol (TYPE_NAME (t));
2167 else if (TYPE_NAME (t)
2168 && TYPE_NAME (t) != decl
2169 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2170 debug_queue_symbol (TYPE_NAME (t));
2173 emit_pending_bincls_if_required ();
2175 dbxout_prepare_symbol (decl);
2177 /* The output will always start with the symbol name,
2178 so always count that in the length-output-so-far. */
2180 if (DECL_NAME (decl) != 0)
2181 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2183 switch (TREE_CODE (decl))
2185 case CONST_DECL:
2186 /* Enum values are defined by defining the enum type. */
2187 break;
2189 case FUNCTION_DECL:
2190 if (DECL_RTL (decl) == 0)
2191 DBXOUT_DECR_NESTING_AND_RETURN (0);
2192 if (DECL_EXTERNAL (decl))
2193 break;
2194 /* Don't mention a nested function under its parent. */
2195 context = decl_function_context (decl);
2196 if (context == current_function_decl)
2197 break;
2198 if (!MEM_P (DECL_RTL (decl))
2199 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2200 break;
2201 FORCE_TEXT;
2203 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2204 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2205 TREE_PUBLIC (decl) ? 'F' : 'f');
2206 result = 1;
2208 current_sym_code = N_FUN;
2209 current_sym_addr = XEXP (DECL_RTL (decl), 0);
2211 if (TREE_TYPE (type))
2212 dbxout_type (TREE_TYPE (type), 0);
2213 else
2214 dbxout_type (void_type_node, 0);
2216 /* For a nested function, when that function is compiled,
2217 mention the containing function name
2218 as well as (since dbx wants it) our own assembler-name. */
2219 if (context != 0)
2220 fprintf (asmfile, ",%s,%s",
2221 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2222 IDENTIFIER_POINTER (DECL_NAME (context)));
2224 dbxout_finish_symbol (decl);
2225 break;
2227 case TYPE_DECL:
2228 /* Don't output the same typedef twice.
2229 And don't output what language-specific stuff doesn't want output. */
2230 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2231 DBXOUT_DECR_NESTING_AND_RETURN (0);
2233 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2234 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2236 int fundamental_type_number =
2237 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2239 if (fundamental_type_number != 0)
2241 TREE_ASM_WRITTEN (decl) = 1;
2242 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2243 DBXOUT_DECR_NESTING_AND_RETURN (0);
2246 #endif
2247 FORCE_TEXT;
2248 result = 1;
2250 int tag_needed = 1;
2251 int did_output = 0;
2253 if (DECL_NAME (decl))
2255 /* Nonzero means we must output a tag as well as a typedef. */
2256 tag_needed = 0;
2258 /* Handle the case of a C++ structure or union
2259 where the TYPE_NAME is a TYPE_DECL
2260 which gives both a typedef name and a tag. */
2261 /* dbx requires the tag first and the typedef second. */
2262 if ((TREE_CODE (type) == RECORD_TYPE
2263 || TREE_CODE (type) == UNION_TYPE
2264 || TREE_CODE (type) == QUAL_UNION_TYPE)
2265 && TYPE_NAME (type) == decl
2266 && !(use_gnu_debug_info_extensions && have_used_extensions)
2267 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2268 /* Distinguish the implicit typedefs of C++
2269 from explicit ones that might be found in C. */
2270 && DECL_ARTIFICIAL (decl)
2271 /* Do not generate a tag for incomplete records. */
2272 && COMPLETE_TYPE_P (type)
2273 /* Do not generate a tag for records of variable size,
2274 since this type can not be properly described in the
2275 DBX format, and it confuses some tools such as objdump. */
2276 && host_integerp (TYPE_SIZE (type), 1))
2278 tree name = TYPE_NAME (type);
2279 if (TREE_CODE (name) == TYPE_DECL)
2280 name = DECL_NAME (name);
2282 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2283 current_sym_value = 0;
2284 current_sym_addr = 0;
2285 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2287 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2288 IDENTIFIER_POINTER (name));
2289 dbxout_type (type, 1);
2290 dbxout_finish_symbol (NULL_TREE);
2293 /* Output .stabs (or whatever) and leading double quote. */
2294 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2296 if (use_gnu_debug_info_extensions)
2298 /* Output leading class/struct qualifiers. */
2299 dbxout_class_name_qualifiers (decl);
2302 /* Output typedef name. */
2303 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2305 /* Short cut way to output a tag also. */
2306 if ((TREE_CODE (type) == RECORD_TYPE
2307 || TREE_CODE (type) == UNION_TYPE
2308 || TREE_CODE (type) == QUAL_UNION_TYPE)
2309 && TYPE_NAME (type) == decl
2310 /* Distinguish the implicit typedefs of C++
2311 from explicit ones that might be found in C. */
2312 && DECL_ARTIFICIAL (decl))
2314 if (use_gnu_debug_info_extensions && have_used_extensions)
2316 putc ('T', asmfile);
2317 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2319 #if 0 /* Now we generate the tag for this case up above. */
2320 else
2321 tag_needed = 1;
2322 #endif
2325 putc ('t', asmfile);
2326 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2328 dbxout_type (type, 1);
2329 dbxout_finish_symbol (decl);
2330 did_output = 1;
2333 /* Don't output a tag if this is an incomplete type. This prevents
2334 the sun4 Sun OS 4.x dbx from crashing. */
2336 if (tag_needed && TYPE_NAME (type) != 0
2337 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2338 || (DECL_NAME (TYPE_NAME (type)) != 0))
2339 && COMPLETE_TYPE_P (type)
2340 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2342 /* For a TYPE_DECL with no name, but the type has a name,
2343 output a tag.
2344 This is what represents `struct foo' with no typedef. */
2345 /* In C++, the name of a type is the corresponding typedef.
2346 In C, it is an IDENTIFIER_NODE. */
2347 tree name = TYPE_NAME (type);
2348 if (TREE_CODE (name) == TYPE_DECL)
2349 name = DECL_NAME (name);
2351 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2352 current_sym_value = 0;
2353 current_sym_addr = 0;
2354 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2356 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2357 IDENTIFIER_POINTER (name));
2358 dbxout_type (type, 1);
2359 dbxout_finish_symbol (NULL_TREE);
2360 did_output = 1;
2363 /* If an enum type has no name, it cannot be referred to,
2364 but we must output it anyway, since the enumeration constants
2365 can be referred to. */
2366 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2368 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2369 current_sym_value = 0;
2370 current_sym_addr = 0;
2371 current_sym_nchars = 2;
2373 /* Some debuggers fail when given NULL names, so give this a
2374 harmless name of ` '. */
2375 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2376 dbxout_type (type, 1);
2377 dbxout_finish_symbol (NULL_TREE);
2380 /* Prevent duplicate output of a typedef. */
2381 TREE_ASM_WRITTEN (decl) = 1;
2382 break;
2385 case PARM_DECL:
2386 /* Parm decls go in their own separate chains
2387 and are output by dbxout_reg_parms and dbxout_parms. */
2388 gcc_unreachable ();
2390 case RESULT_DECL:
2391 /* Named return value, treat like a VAR_DECL. */
2392 case VAR_DECL:
2393 if (! DECL_RTL_SET_P (decl))
2394 DBXOUT_DECR_NESTING_AND_RETURN (0);
2395 /* Don't mention a variable that is external.
2396 Let the file that defines it describe it. */
2397 if (DECL_EXTERNAL (decl))
2398 break;
2400 /* If the variable is really a constant
2401 and not written in memory, inform the debugger. */
2402 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2403 && DECL_INITIAL (decl) != 0
2404 && host_integerp (DECL_INITIAL (decl), 0)
2405 && ! TREE_ASM_WRITTEN (decl)
2406 && (DECL_CONTEXT (decl) == NULL_TREE
2407 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2409 if (TREE_PUBLIC (decl) == 0)
2411 /* The sun4 assembler does not grok this. */
2412 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2414 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2415 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2417 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2418 fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2419 "\",0x%x,0,0,0\n",
2420 ASM_STABS_OP, name, ival, N_LSYM);
2421 DBXOUT_DECR_NESTING;
2422 return 1;
2424 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2426 /* Don't know how to do this yet. */
2428 break;
2430 /* else it is something we handle like a normal variable. */
2433 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2434 #ifdef LEAF_REG_REMAP
2435 if (current_function_uses_only_leaf_regs)
2436 leaf_renumber_regs_insn (DECL_RTL (decl));
2437 #endif
2439 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2440 break;
2442 default:
2443 break;
2445 DBXOUT_DECR_NESTING;
2446 return result;
2449 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2450 Add SUFFIX to its name, if SUFFIX is not 0.
2451 Describe the variable as residing in HOME
2452 (usually HOME is DECL_RTL (DECL), but not always).
2453 Returns 1 if the stab was really emitted. */
2455 static int
2456 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2458 int letter = 0;
2459 int regno = -1;
2461 emit_pending_bincls_if_required ();
2463 /* Don't mention a variable at all
2464 if it was completely optimized into nothingness.
2466 If the decl was from an inline function, then its rtl
2467 is not identically the rtl that was used in this
2468 particular compilation. */
2469 if (GET_CODE (home) == SUBREG)
2471 rtx value = home;
2473 while (GET_CODE (value) == SUBREG)
2474 value = SUBREG_REG (value);
2475 if (REG_P (value))
2477 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2478 return 0;
2480 home = alter_subreg (&home);
2482 if (REG_P (home))
2484 regno = REGNO (home);
2485 if (regno >= FIRST_PSEUDO_REGISTER)
2486 return 0;
2489 /* The kind-of-variable letter depends on where
2490 the variable is and on the scope of its name:
2491 G and N_GSYM for static storage and global scope,
2492 S for static storage and file scope,
2493 V for static storage and local scope,
2494 for those two, use N_LCSYM if data is in bss segment,
2495 N_STSYM if in data segment, N_FUN otherwise.
2496 (We used N_FUN originally, then changed to N_STSYM
2497 to please GDB. However, it seems that confused ld.
2498 Now GDB has been fixed to like N_FUN, says Kingdon.)
2499 no letter at all, and N_LSYM, for auto variable,
2500 r and N_RSYM for register variable. */
2502 if (MEM_P (home)
2503 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2505 if (TREE_PUBLIC (decl))
2507 letter = 'G';
2508 current_sym_code = N_GSYM;
2510 else
2512 current_sym_addr = XEXP (home, 0);
2514 letter = decl_function_context (decl) ? 'V' : 'S';
2516 /* This should be the same condition as in assemble_variable, but
2517 we don't have access to dont_output_data here. So, instead,
2518 we rely on the fact that error_mark_node initializers always
2519 end up in bss for C++ and never end up in bss for C. */
2520 if (DECL_INITIAL (decl) == 0
2521 || (!strcmp (lang_hooks.name, "GNU C++")
2522 && DECL_INITIAL (decl) == error_mark_node))
2523 current_sym_code = N_LCSYM;
2524 else if (DECL_IN_TEXT_SECTION (decl))
2525 /* This is not quite right, but it's the closest
2526 of all the codes that Unix defines. */
2527 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2528 else
2530 /* Some ports can transform a symbol ref into a label ref,
2531 because the symbol ref is too far away and has to be
2532 dumped into a constant pool. Alternatively, the symbol
2533 in the constant pool might be referenced by a different
2534 symbol. */
2535 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2536 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2538 bool marked;
2539 rtx tmp = get_pool_constant_mark (current_sym_addr, &marked);
2541 if (GET_CODE (tmp) == SYMBOL_REF)
2543 current_sym_addr = tmp;
2544 if (CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2545 get_pool_constant_mark (current_sym_addr, &marked);
2546 else
2547 marked = true;
2549 else if (GET_CODE (tmp) == LABEL_REF)
2551 current_sym_addr = tmp;
2552 marked = true;
2555 /* If all references to the constant pool were optimized
2556 out, we just ignore the symbol. */
2557 if (!marked)
2558 return 0;
2561 /* Ultrix `as' seems to need this. */
2562 #ifdef DBX_STATIC_STAB_DATA_SECTION
2563 data_section ();
2564 #endif
2565 current_sym_code = N_STSYM;
2569 else if (regno >= 0)
2571 letter = 'r';
2572 current_sym_code = N_RSYM;
2573 current_sym_value = DBX_REGISTER_NUMBER (regno);
2575 else if (MEM_P (home)
2576 && (MEM_P (XEXP (home, 0))
2577 || (REG_P (XEXP (home, 0))
2578 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2579 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2580 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2581 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2582 #endif
2584 /* If the value is indirect by memory or by a register
2585 that isn't the frame pointer
2586 then it means the object is variable-sized and address through
2587 that register or stack slot. DBX has no way to represent this
2588 so all we can do is output the variable as a pointer.
2589 If it's not a parameter, ignore it. */
2591 if (REG_P (XEXP (home, 0)))
2593 letter = 'r';
2594 current_sym_code = N_RSYM;
2595 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2596 return 0;
2597 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2599 else
2601 current_sym_code = N_LSYM;
2602 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2603 We want the value of that CONST_INT. */
2604 current_sym_value
2605 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2608 /* Effectively do build_pointer_type, but don't cache this type,
2609 since it might be temporary whereas the type it points to
2610 might have been saved for inlining. */
2611 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2612 type = make_node (POINTER_TYPE);
2613 TREE_TYPE (type) = TREE_TYPE (decl);
2615 else if (MEM_P (home)
2616 && REG_P (XEXP (home, 0)))
2618 current_sym_code = N_LSYM;
2619 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2621 else if (MEM_P (home)
2622 && GET_CODE (XEXP (home, 0)) == PLUS
2623 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2625 current_sym_code = N_LSYM;
2626 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2627 We want the value of that CONST_INT. */
2628 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2630 else if (MEM_P (home)
2631 && GET_CODE (XEXP (home, 0)) == CONST)
2633 /* Handle an obscure case which can arise when optimizing and
2634 when there are few available registers. (This is *always*
2635 the case for i386/i486 targets). The RTL looks like
2636 (MEM (CONST ...)) even though this variable is a local `auto'
2637 or a local `register' variable. In effect, what has happened
2638 is that the reload pass has seen that all assignments and
2639 references for one such a local variable can be replaced by
2640 equivalent assignments and references to some static storage
2641 variable, thereby avoiding the need for a register. In such
2642 cases we're forced to lie to debuggers and tell them that
2643 this variable was itself `static'. */
2644 current_sym_code = N_LCSYM;
2645 letter = 'V';
2646 current_sym_addr = XEXP (XEXP (home, 0), 0);
2648 else if (GET_CODE (home) == CONCAT)
2650 tree subtype;
2652 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2653 for example), then there is no easy way to figure out
2654 what SUBTYPE should be. So, we give up. */
2655 if (TREE_CODE (type) != COMPLEX_TYPE)
2656 return 0;
2658 subtype = TREE_TYPE (type);
2660 /* If the variable's storage is in two parts,
2661 output each as a separate stab with a modified name. */
2662 if (WORDS_BIG_ENDIAN)
2663 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2664 else
2665 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2667 dbxout_prepare_symbol (decl);
2669 if (WORDS_BIG_ENDIAN)
2670 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2671 else
2672 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2673 return 1;
2675 else
2676 /* Address might be a MEM, when DECL is a variable-sized object.
2677 Or it might be const0_rtx, meaning previous passes
2678 want us to ignore this variable. */
2679 return 0;
2681 /* Ok, start a symtab entry and output the variable name. */
2682 FORCE_TEXT;
2684 #ifdef DBX_STATIC_BLOCK_START
2685 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2686 #endif
2688 dbxout_symbol_name (decl, suffix, letter);
2689 dbxout_type (type, 0);
2690 dbxout_finish_symbol (decl);
2692 #ifdef DBX_STATIC_BLOCK_END
2693 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2694 #endif
2695 return 1;
2698 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2699 Then output LETTER to indicate the kind of location the symbol has. */
2701 static void
2702 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2704 const char *name;
2706 if (DECL_CONTEXT (decl)
2707 && (TYPE_P (DECL_CONTEXT (decl))
2708 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
2709 /* One slight hitch: if this is a VAR_DECL which is a class member
2710 or a namespace member, we must put out the mangled name instead of the
2711 DECL_NAME. Note also that static member (variable) names DO NOT begin
2712 with underscores in .stabs directives. */
2713 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2714 else
2715 /* ...but if we're function-local, we don't want to include the junk
2716 added by ASM_FORMAT_PRIVATE_NAME. */
2717 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2719 if (name == 0)
2720 name = "(anon)";
2721 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2722 (suffix ? suffix : ""));
2724 if (letter)
2725 putc (letter, asmfile);
2728 static void
2729 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)
2731 #ifdef WINNING_GDB
2732 const char *filename = DECL_SOURCE_FILE (decl);
2734 dbxout_source_file (asmfile, filename);
2735 #endif
2737 /* Initialize variables used to communicate each symbol's debug
2738 information to dbxout_finish_symbol with zeroes. */
2740 /* Cast avoids warning in old compilers. */
2741 current_sym_code = (STAB_CODE_TYPE) 0;
2742 current_sym_value = 0;
2743 current_sym_addr = 0;
2746 static void
2747 dbxout_finish_symbol (tree sym)
2749 #ifdef DBX_FINISH_SYMBOL
2750 DBX_FINISH_SYMBOL (sym);
2751 #else
2752 int line = 0;
2753 if (use_gnu_debug_info_extensions && sym != 0)
2754 line = DECL_SOURCE_LINE (sym);
2756 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2757 if (current_sym_addr)
2758 output_addr_const (asmfile, current_sym_addr);
2759 else
2760 fprintf (asmfile, "%d", current_sym_value);
2761 putc ('\n', asmfile);
2762 #endif
2765 /* Output definitions of all the decls in a chain. Return nonzero if
2766 anything was output */
2769 dbxout_syms (tree syms)
2771 int result = 0;
2772 while (syms)
2774 result += dbxout_symbol (syms, 1);
2775 syms = TREE_CHAIN (syms);
2777 return result;
2780 /* The following two functions output definitions of function parameters.
2781 Each parameter gets a definition locating it in the parameter list.
2782 Each parameter that is a register variable gets a second definition
2783 locating it in the register.
2785 Printing or argument lists in gdb uses the definitions that
2786 locate in the parameter list. But reference to the variable in
2787 expressions uses preferentially the definition as a register. */
2789 /* Output definitions, referring to storage in the parmlist,
2790 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2792 void
2793 dbxout_parms (tree parms)
2795 ++debug_nesting;
2797 emit_pending_bincls_if_required ();
2799 for (; parms; parms = TREE_CHAIN (parms))
2800 if (DECL_NAME (parms)
2801 && TREE_TYPE (parms) != error_mark_node
2802 && DECL_RTL_SET_P (parms)
2803 && DECL_INCOMING_RTL (parms))
2805 dbxout_prepare_symbol (parms);
2807 /* Perform any necessary register eliminations on the parameter's rtl,
2808 so that the debugging output will be accurate. */
2809 DECL_INCOMING_RTL (parms)
2810 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2811 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2812 #ifdef LEAF_REG_REMAP
2813 if (current_function_uses_only_leaf_regs)
2815 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2816 leaf_renumber_regs_insn (DECL_RTL (parms));
2818 #endif
2820 if (PARM_PASSED_IN_MEMORY (parms))
2822 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2824 /* ??? Here we assume that the parm address is indexed
2825 off the frame pointer or arg pointer.
2826 If that is not true, we produce meaningless results,
2827 but do not crash. */
2828 if (GET_CODE (addr) == PLUS
2829 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2830 current_sym_value = INTVAL (XEXP (addr, 1));
2831 else
2832 current_sym_value = 0;
2834 current_sym_code = N_PSYM;
2835 current_sym_addr = 0;
2837 FORCE_TEXT;
2838 if (DECL_NAME (parms))
2840 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2842 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2843 IDENTIFIER_POINTER (DECL_NAME (parms)),
2844 DBX_MEMPARM_STABS_LETTER);
2846 else
2848 current_sym_nchars = 8;
2849 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2850 DBX_MEMPARM_STABS_LETTER);
2853 /* It is quite tempting to use:
2855 dbxout_type (TREE_TYPE (parms), 0);
2857 as the next statement, rather than using DECL_ARG_TYPE(), so
2858 that gcc reports the actual type of the parameter, rather
2859 than the promoted type. This certainly makes GDB's life
2860 easier, at least for some ports. The change is a bad idea
2861 however, since GDB expects to be able access the type without
2862 performing any conversions. So for example, if we were
2863 passing a float to an unprototyped function, gcc will store a
2864 double on the stack, but if we emit a stab saying the type is a
2865 float, then gdb will only read in a single value, and this will
2866 produce an erroneous value. */
2867 dbxout_type (DECL_ARG_TYPE (parms), 0);
2868 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2869 dbxout_finish_symbol (parms);
2871 else if (REG_P (DECL_RTL (parms)))
2873 rtx best_rtl;
2874 char regparm_letter;
2875 tree parm_type;
2876 /* Parm passed in registers and lives in registers or nowhere. */
2878 current_sym_code = DBX_REGPARM_STABS_CODE;
2879 regparm_letter = DBX_REGPARM_STABS_LETTER;
2880 current_sym_addr = 0;
2882 /* If parm lives in a register, use that register;
2883 pretend the parm was passed there. It would be more consistent
2884 to describe the register where the parm was passed,
2885 but in practice that register usually holds something else.
2887 If we use DECL_RTL, then we must use the declared type of
2888 the variable, not the type that it arrived in. */
2889 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2891 best_rtl = DECL_RTL (parms);
2892 parm_type = TREE_TYPE (parms);
2894 /* If the parm lives nowhere, use the register where it was
2895 passed. It is also better to use the declared type here. */
2896 else
2898 best_rtl = DECL_INCOMING_RTL (parms);
2899 parm_type = TREE_TYPE (parms);
2901 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2903 FORCE_TEXT;
2904 if (DECL_NAME (parms))
2906 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2907 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2908 IDENTIFIER_POINTER (DECL_NAME (parms)),
2909 regparm_letter);
2911 else
2913 current_sym_nchars = 8;
2914 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2915 regparm_letter);
2918 dbxout_type (parm_type, 0);
2919 dbxout_finish_symbol (parms);
2921 else if (MEM_P (DECL_RTL (parms))
2922 && REG_P (XEXP (DECL_RTL (parms), 0))
2923 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2924 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2925 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2926 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2927 #endif
2930 /* Parm was passed via invisible reference.
2931 That is, its address was passed in a register.
2932 Output it as if it lived in that register.
2933 The debugger will know from the type
2934 that it was actually passed by invisible reference. */
2936 char regparm_letter;
2937 /* Parm passed in registers and lives in registers or nowhere. */
2939 current_sym_code = DBX_REGPARM_STABS_CODE;
2940 if (use_gnu_debug_info_extensions)
2941 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2942 else
2943 regparm_letter = DBX_REGPARM_STABS_LETTER;
2945 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2946 If it is an unallocated pseudo-reg, then use the register where
2947 it was passed instead. */
2948 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2949 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2950 else
2951 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2953 current_sym_addr = 0;
2955 FORCE_TEXT;
2956 if (DECL_NAME (parms))
2958 current_sym_nchars
2959 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2961 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2962 IDENTIFIER_POINTER (DECL_NAME (parms)),
2963 regparm_letter);
2965 else
2967 current_sym_nchars = 8;
2968 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2969 regparm_letter);
2972 dbxout_type (TREE_TYPE (parms), 0);
2973 dbxout_finish_symbol (parms);
2975 else if (MEM_P (DECL_RTL (parms))
2976 && MEM_P (XEXP (DECL_RTL (parms), 0)))
2978 /* Parm was passed via invisible reference, with the reference
2979 living on the stack. DECL_RTL looks like
2980 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2981 could look like (MEM (MEM (REG))). */
2982 const char *const decl_name = (DECL_NAME (parms)
2983 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2984 : "(anon)");
2985 if (REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
2986 current_sym_value = 0;
2987 else
2988 current_sym_value
2989 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2990 current_sym_addr = 0;
2991 current_sym_code = N_PSYM;
2993 FORCE_TEXT;
2994 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2996 current_sym_value
2997 = DEBUGGER_ARG_OFFSET (current_sym_value,
2998 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2999 dbxout_type (TREE_TYPE (parms), 0);
3000 dbxout_finish_symbol (parms);
3002 else if (MEM_P (DECL_RTL (parms))
3003 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3004 /* ??? A constant address for a parm can happen
3005 when the reg it lives in is equiv to a constant in memory.
3006 Should make this not happen, after 2.4. */
3007 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3009 /* Parm was passed in registers but lives on the stack. */
3011 current_sym_code = N_PSYM;
3012 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3013 in which case we want the value of that CONST_INT,
3014 or (MEM (REG ...)),
3015 in which case we use a value of zero. */
3016 if (REG_P (XEXP (DECL_RTL (parms), 0)))
3017 current_sym_value = 0;
3018 else
3019 current_sym_value
3020 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3022 current_sym_addr = 0;
3024 /* Make a big endian correction if the mode of the type of the
3025 parameter is not the same as the mode of the rtl. */
3026 if (BYTES_BIG_ENDIAN
3027 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3028 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3030 current_sym_value +=
3031 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3032 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
3035 FORCE_TEXT;
3036 if (DECL_NAME (parms))
3038 current_sym_nchars
3039 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
3041 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
3042 IDENTIFIER_POINTER (DECL_NAME (parms)),
3043 DBX_MEMPARM_STABS_LETTER);
3045 else
3047 current_sym_nchars = 8;
3048 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
3049 DBX_MEMPARM_STABS_LETTER);
3052 current_sym_value
3053 = DEBUGGER_ARG_OFFSET (current_sym_value,
3054 XEXP (DECL_RTL (parms), 0));
3055 dbxout_type (TREE_TYPE (parms), 0);
3056 dbxout_finish_symbol (parms);
3059 DBXOUT_DECR_NESTING;
3062 /* Output definitions for the places where parms live during the function,
3063 when different from where they were passed, when the parms were passed
3064 in memory.
3066 It is not useful to do this for parms passed in registers
3067 that live during the function in different registers, because it is
3068 impossible to look in the passed register for the passed value,
3069 so we use the within-the-function register to begin with.
3071 PARMS is a chain of PARM_DECL nodes. */
3073 void
3074 dbxout_reg_parms (tree parms)
3076 ++debug_nesting;
3078 for (; parms; parms = TREE_CHAIN (parms))
3079 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3081 dbxout_prepare_symbol (parms);
3083 /* Report parms that live in registers during the function
3084 but were passed in memory. */
3085 if (REG_P (DECL_RTL (parms))
3086 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3087 dbxout_symbol_location (parms, TREE_TYPE (parms),
3088 0, DECL_RTL (parms));
3089 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3090 dbxout_symbol_location (parms, TREE_TYPE (parms),
3091 0, DECL_RTL (parms));
3092 /* Report parms that live in memory but not where they were passed. */
3093 else if (MEM_P (DECL_RTL (parms))
3094 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3095 dbxout_symbol_location (parms, TREE_TYPE (parms),
3096 0, DECL_RTL (parms));
3098 DBXOUT_DECR_NESTING;
3101 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3102 output definitions of those names, in raw form */
3104 static void
3105 dbxout_args (tree args)
3107 while (args)
3109 putc (',', asmfile);
3110 dbxout_type (TREE_VALUE (args), 0);
3111 CHARS (1);
3112 args = TREE_CHAIN (args);
3116 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3117 BEGIN_LABEL is the name of the beginning of the function, which may
3118 be required. */
3119 static void
3120 dbx_output_lbrac (const char *label,
3121 const char *begin_label ATTRIBUTE_UNUSED)
3123 #ifdef DBX_OUTPUT_LBRAC
3124 DBX_OUTPUT_LBRAC (asmfile, label);
3125 #else
3126 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
3127 assemble_name (asmfile, label);
3128 #if DBX_BLOCKS_FUNCTION_RELATIVE
3129 putc ('-', asmfile);
3130 assemble_name (asmfile, begin_label);
3131 #endif
3132 fprintf (asmfile, "\n");
3133 #endif
3136 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3137 BEGIN_LABEL is the name of the beginning of the function, which may
3138 be required. */
3139 static void
3140 dbx_output_rbrac (const char *label,
3141 const char *begin_label ATTRIBUTE_UNUSED)
3143 #ifdef DBX_OUTPUT_RBRAC
3144 DBX_OUTPUT_RBRAC (asmfile, label);
3145 #else
3146 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3147 assemble_name (asmfile, label);
3148 #if DBX_BLOCKS_FUNCTION_RELATIVE
3149 putc ('-', asmfile);
3150 assemble_name (asmfile, begin_label);
3151 #endif
3152 fprintf (asmfile, "\n");
3153 #endif
3156 /* Output everything about a symbol block (a BLOCK node
3157 that represents a scope level),
3158 including recursive output of contained blocks.
3160 BLOCK is the BLOCK node.
3161 DEPTH is its depth within containing symbol blocks.
3162 ARGS is usually zero; but for the outermost block of the
3163 body of a function, it is a chain of PARM_DECLs for the function parameters.
3164 We output definitions of all the register parms
3165 as if they were local variables of that block.
3167 If -g1 was used, we count blocks just the same, but output nothing
3168 except for the outermost block.
3170 Actually, BLOCK may be several blocks chained together.
3171 We handle them all in sequence. */
3173 static void
3174 dbxout_block (tree block, int depth, tree args)
3176 const char *begin_label;
3177 if (current_function_func_begin_label != NULL)
3178 begin_label = current_function_func_begin_label;
3179 else
3180 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3182 while (block)
3184 /* Ignore blocks never expanded or otherwise marked as real. */
3185 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3187 int did_output;
3188 int blocknum = BLOCK_NUMBER (block);
3190 /* In dbx format, the syms of a block come before the N_LBRAC.
3191 If nothing is output, we don't need the N_LBRAC, either. */
3192 did_output = 0;
3193 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3194 did_output = dbxout_syms (BLOCK_VARS (block));
3195 if (args)
3196 dbxout_reg_parms (args);
3198 /* Now output an N_LBRAC symbol to represent the beginning of
3199 the block. Use the block's tree-walk order to generate
3200 the assembler symbols LBBn and LBEn
3201 that final will define around the code in this block. */
3202 if (did_output)
3204 char buf[20];
3205 const char *scope_start;
3207 if (depth == 0)
3208 /* The outermost block doesn't get LBB labels; use
3209 the function symbol. */
3210 scope_start = begin_label;
3211 else
3213 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3214 scope_start = buf;
3217 if (BLOCK_HANDLER_BLOCK (block))
3219 /* A catch block. Must precede N_LBRAC. */
3220 tree decl = BLOCK_VARS (block);
3221 while (decl)
3223 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
3224 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
3225 assemble_name (asmfile, scope_start);
3226 fprintf (asmfile, "\n");
3227 decl = TREE_CHAIN (decl);
3230 dbx_output_lbrac (scope_start, begin_label);
3233 /* Output the subblocks. */
3234 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3236 /* Refer to the marker for the end of the block. */
3237 if (did_output)
3239 char buf[100];
3240 if (depth == 0)
3241 /* The outermost block doesn't get LBE labels;
3242 use the "scope" label which will be emitted
3243 by dbxout_function_end. */
3244 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3245 else
3246 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3248 dbx_output_rbrac (buf, begin_label);
3251 block = BLOCK_CHAIN (block);
3255 /* Output the information about a function and its arguments and result.
3256 Usually this follows the function's code,
3257 but on some systems, it comes before. */
3259 #if defined (DBX_DEBUGGING_INFO)
3260 static void
3261 dbxout_begin_function (tree decl)
3263 int saved_tree_used1 = TREE_USED (decl);
3264 TREE_USED (decl) = 1;
3265 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3267 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3268 TREE_USED (DECL_RESULT (decl)) = 1;
3269 dbxout_symbol (decl, 0);
3270 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3272 else
3273 dbxout_symbol (decl, 0);
3274 TREE_USED (decl) = saved_tree_used1;
3276 dbxout_parms (DECL_ARGUMENTS (decl));
3277 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3278 dbxout_symbol (DECL_RESULT (decl), 1);
3280 #endif /* DBX_DEBUGGING_INFO */
3282 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3284 #include "gt-dbxout.h"