* Merge with edge-vector-mergepoint-20040918.
[official-gcc.git] / gcc / dbxout.c
blob62f3102fd1d4c844c9f9af44f0535018275b01ae
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 unsigned int get_lang_number (void);
347 static void dbxout_finish (const char *);
348 static void dbxout_start_source_file (unsigned, const char *);
349 static void dbxout_end_source_file (unsigned);
350 static void dbxout_typedefs (tree);
351 static void dbxout_type_index (tree);
352 #if DBX_CONTIN_LENGTH > 0
353 static void dbxout_continue (void);
354 #endif
355 static void dbxout_args (tree);
356 static void dbxout_type_fields (tree);
357 static void dbxout_type_method_1 (tree, const char *);
358 static void dbxout_type_methods (tree);
359 static void dbxout_range_type (tree);
360 static void dbxout_type (tree, int);
361 static bool print_int_cst_bounds_in_octal_p (tree);
362 static void print_int_cst_octal (tree);
363 static void print_octal (unsigned HOST_WIDE_INT, int);
364 static void print_wide_int (HOST_WIDE_INT);
365 static void dbxout_type_name (tree);
366 static void dbxout_class_name_qualifiers (tree);
367 static int dbxout_symbol_location (tree, tree, const char *, rtx);
368 static void dbxout_symbol_name (tree, const char *, int);
369 static void dbxout_prepare_symbol (tree);
370 static void dbxout_finish_symbol (tree);
371 static void dbxout_block (tree, int, tree);
372 static void dbxout_global_decl (tree);
373 static void dbxout_type_decl (tree, int);
374 static void dbxout_handle_pch (unsigned);
376 /* The debug hooks structure. */
377 #if defined (DBX_DEBUGGING_INFO)
379 static void dbxout_source_line (unsigned int, const char *);
380 static void dbxout_begin_prologue (unsigned int, const char *);
381 static void dbxout_source_file (FILE *, const char *);
382 static void dbxout_function_end (void);
383 static void dbxout_begin_function (tree);
384 static void dbxout_begin_block (unsigned, unsigned);
385 static void dbxout_end_block (unsigned, unsigned);
386 static void dbxout_function_decl (tree);
388 const struct gcc_debug_hooks dbx_debug_hooks =
390 dbxout_init,
391 dbxout_finish,
392 debug_nothing_int_charstar,
393 debug_nothing_int_charstar,
394 dbxout_start_source_file,
395 dbxout_end_source_file,
396 dbxout_begin_block,
397 dbxout_end_block,
398 debug_true_tree, /* ignore_block */
399 dbxout_source_line, /* source_line */
400 dbxout_begin_prologue, /* begin_prologue */
401 debug_nothing_int_charstar, /* end_prologue */
402 debug_nothing_int_charstar, /* end_epilogue */
403 #ifdef DBX_FUNCTION_FIRST
404 dbxout_begin_function,
405 #else
406 debug_nothing_tree, /* begin_function */
407 #endif
408 debug_nothing_int, /* end_function */
409 dbxout_function_decl,
410 dbxout_global_decl, /* global_decl */
411 dbxout_type_decl, /* type_decl */
412 debug_nothing_tree_tree, /* imported_module_or_decl */
413 debug_nothing_tree, /* deferred_inline_function */
414 debug_nothing_tree, /* outlining_inline_function */
415 debug_nothing_rtx, /* label */
416 dbxout_handle_pch, /* handle_pch */
417 debug_nothing_rtx /* var_location */
419 #endif /* DBX_DEBUGGING_INFO */
421 #if defined (XCOFF_DEBUGGING_INFO)
422 const struct gcc_debug_hooks xcoff_debug_hooks =
424 dbxout_init,
425 dbxout_finish,
426 debug_nothing_int_charstar,
427 debug_nothing_int_charstar,
428 dbxout_start_source_file,
429 dbxout_end_source_file,
430 xcoffout_begin_block,
431 xcoffout_end_block,
432 debug_true_tree, /* ignore_block */
433 xcoffout_source_line,
434 xcoffout_begin_prologue, /* begin_prologue */
435 debug_nothing_int_charstar, /* end_prologue */
436 xcoffout_end_epilogue,
437 debug_nothing_tree, /* begin_function */
438 xcoffout_end_function,
439 debug_nothing_tree, /* function_decl */
440 dbxout_global_decl, /* global_decl */
441 dbxout_type_decl, /* type_decl */
442 debug_nothing_tree_tree, /* imported_module_or_decl */
443 debug_nothing_tree, /* deferred_inline_function */
444 debug_nothing_tree, /* outlining_inline_function */
445 debug_nothing_rtx, /* label */
446 dbxout_handle_pch, /* handle_pch */
447 debug_nothing_rtx /* var_location */
449 #endif /* XCOFF_DEBUGGING_INFO */
451 #if defined (DBX_DEBUGGING_INFO)
452 static void
453 dbxout_function_end (void)
455 char lscope_label_name[100];
457 /* The Lscope label must be emitted even if we aren't doing anything
458 else; dbxout_block needs it. */
459 function_section (current_function_decl);
461 /* Convert Ltext into the appropriate format for local labels in case
462 the system doesn't insert underscores in front of user generated
463 labels. */
464 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
465 targetm.asm_out.internal_label (asmfile, "Lscope", scope_labelno);
466 scope_labelno++;
468 /* The N_FUN tag at the end of the function is a GNU extension,
469 which may be undesirable, and is unnecessary if we do not have
470 named sections. */
471 if (!use_gnu_debug_info_extensions
472 || NO_DBX_FUNCTION_END
473 || !targetm.have_named_sections)
474 return;
476 /* By convention, GCC will mark the end of a function with an N_FUN
477 symbol and an empty string. */
478 #ifdef DBX_OUTPUT_NFUN
479 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
480 #else
481 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
482 assemble_name (asmfile, lscope_label_name);
483 putc ('-', asmfile);
484 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
485 fprintf (asmfile, "\n");
486 #endif
488 if (!flag_debug_only_used_symbols)
489 fprintf (asmfile, "%s%d,0,0\n", ASM_STABD_OP, N_ENSYM);
491 #endif /* DBX_DEBUGGING_INFO */
493 /* Get lang description for N_SO stab. */
495 static unsigned int
496 get_lang_number (void)
498 const char *language_string = lang_hooks.name;
500 if (strcmp (language_string, "GNU C") == 0)
501 return N_SO_C;
502 else if (strcmp (language_string, "GNU C++") == 0)
503 return N_SO_CC;
504 else if (strcmp (language_string, "GNU F77") == 0)
505 return N_SO_FORTRAN;
506 else if (strcmp (language_string, "GNU F95") == 0)
507 return N_SO_FORTRAN90; /* CHECKME */
508 else if (strcmp (language_string, "GNU Pascal") == 0)
509 return N_SO_PASCAL;
510 else if (strcmp (language_string, "GNU Objective-C") == 0)
511 return N_SO_OBJC;
512 else
513 return 0;
517 /* At the beginning of compilation, start writing the symbol table.
518 Initialize `typevec' and output the standard data types of C. */
520 static void
521 dbxout_init (const char *input_file_name)
523 char ltext_label_name[100];
524 tree syms = lang_hooks.decls.getdecls ();
526 asmfile = asm_out_file;
528 typevec_len = 100;
529 typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
531 /* Convert Ltext into the appropriate format for local labels in case
532 the system doesn't insert underscores in front of user generated
533 labels. */
534 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
536 /* Put the current working directory in an N_SO symbol. */
537 if (use_gnu_debug_info_extensions)
539 if (!cwd && (cwd = get_src_pwd ())
540 && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
541 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
542 if (cwd)
544 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
545 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
546 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
547 fprintf (asmfile, "%s", ASM_STABS_OP);
548 output_quoted_string (asmfile, cwd);
549 fprintf (asmfile, ",%d,0,%d,", N_SO, get_lang_number ());
550 assemble_name (asmfile, ltext_label_name);
551 fputc ('\n', asmfile);
552 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
556 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
557 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
558 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
559 /* We include outputting `Ltext:' here,
560 because that gives you a way to override it. */
561 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
562 fprintf (asmfile, "%s", ASM_STABS_OP);
563 output_quoted_string (asmfile, input_file_name);
564 fprintf (asmfile, ",%d,0,%d,", N_SO, get_lang_number ());
565 assemble_name (asmfile, ltext_label_name);
566 fputc ('\n', asmfile);
567 text_section ();
568 targetm.asm_out.internal_label (asmfile, "Ltext", 0);
569 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
571 #ifdef DBX_OUTPUT_GCC_MARKER
572 DBX_OUTPUT_GCC_MARKER (asmfile);
573 #else
574 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
575 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
576 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
577 #endif
579 base_input_file = lastfile = input_file_name;
581 next_type_number = 1;
583 #ifdef DBX_USE_BINCL
584 current_file = xmalloc (sizeof *current_file);
585 current_file->next = NULL;
586 current_file->file_number = 0;
587 current_file->next_type_number = 1;
588 next_file_number = 1;
589 current_file->prev = NULL;
590 current_file->bincl_status = BINCL_NOT_REQUIRED;
591 current_file->pending_bincl_name = NULL;
592 #endif
594 /* Get all permanent types that have typedef names, and output them
595 all, except for those already output. Some language front ends
596 put these declarations in the top-level scope; some do not;
597 the latter are responsible for calling debug_hooks->type_decl from
598 their record_builtin_type function. */
599 dbxout_typedefs (syms);
601 if (preinit_symbols)
603 tree t;
604 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
605 dbxout_symbol (TREE_VALUE (t), 0);
606 preinit_symbols = 0;
610 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
612 static void
613 dbxout_typedefs (tree syms)
615 for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
617 if (TREE_CODE (syms) == TYPE_DECL)
619 tree type = TREE_TYPE (syms);
620 if (TYPE_NAME (type)
621 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
622 && COMPLETE_OR_VOID_TYPE_P (type)
623 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
624 dbxout_symbol (TYPE_NAME (type), 0);
629 #ifdef DBX_USE_BINCL
630 /* Emit BINCL stab using given name. */
631 static void
632 emit_bincl_stab (const char *name)
634 fprintf (asmfile, "%s", ASM_STABS_OP);
635 output_quoted_string (asmfile, name);
636 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
639 /* If there are pending bincls then it is time to emit all of them. */
641 static inline void
642 emit_pending_bincls_if_required (void)
644 if (pending_bincls)
645 emit_pending_bincls ();
648 /* Emit all pending bincls. */
650 static void
651 emit_pending_bincls (void)
653 struct dbx_file *f = current_file;
655 /* Find first pending bincl. */
656 while (f->bincl_status == BINCL_PENDING)
657 f = f->next;
659 /* Now emit all bincls. */
660 f = f->prev;
662 while (f)
664 if (f->bincl_status == BINCL_PENDING)
666 emit_bincl_stab (f->pending_bincl_name);
668 /* Update file number and status. */
669 f->file_number = next_file_number++;
670 f->bincl_status = BINCL_PROCESSED;
672 if (f == current_file)
673 break;
674 f = f->prev;
677 /* All pending bincls have been emitted. */
678 pending_bincls = 0;
681 #else
683 static inline void
684 emit_pending_bincls_if_required (void) {}
685 #endif
687 /* Change to reading from a new source file. Generate a N_BINCL stab. */
689 static void
690 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
691 const char *filename ATTRIBUTE_UNUSED)
693 #ifdef DBX_USE_BINCL
694 struct dbx_file *n = xmalloc (sizeof *n);
696 n->next = current_file;
697 n->next_type_number = 1;
698 /* Do not assign file number now.
699 Delay it until we actually emit BINCL. */
700 n->file_number = 0;
701 n->prev = NULL;
702 current_file->prev = n;
703 n->bincl_status = BINCL_PENDING;
704 n->pending_bincl_name = filename;
705 pending_bincls = 1;
706 current_file = n;
707 #endif
710 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
712 static void
713 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
715 #ifdef DBX_USE_BINCL
716 /* Emit EINCL stab only if BINCL is not pending. */
717 if (current_file->bincl_status == BINCL_PROCESSED)
718 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
719 current_file->bincl_status = BINCL_NOT_REQUIRED;
720 current_file = current_file->next;
721 #endif
724 /* Handle a few odd cases that occur when trying to make PCH files work. */
726 static void
727 dbxout_handle_pch (unsigned at_end)
729 if (! at_end)
731 /* When using the PCH, this file will be included, so we need to output
732 a BINCL. */
733 dbxout_start_source_file (0, lastfile);
735 /* The base file when using the PCH won't be the same as
736 the base file when it's being generated. */
737 lastfile = NULL;
739 else
741 /* ... and an EINCL. */
742 dbxout_end_source_file (0);
744 /* Deal with cases where 'lastfile' was never actually changed. */
745 lastfile_is_base = lastfile == NULL;
749 #if defined (DBX_DEBUGGING_INFO)
750 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
752 static void
753 dbxout_source_file (FILE *file, const char *filename)
755 if (lastfile == 0 && lastfile_is_base)
757 lastfile = base_input_file;
758 lastfile_is_base = 0;
761 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
763 char ltext_label_name[100];
765 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
766 source_label_number);
767 fprintf (file, "%s", ASM_STABS_OP);
768 output_quoted_string (file, filename);
769 fprintf (asmfile, ",%d,0,0,", N_SOL);
770 assemble_name (asmfile, ltext_label_name);
771 fputc ('\n', asmfile);
772 if (current_function_decl != NULL_TREE
773 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
774 ; /* Don't change section amid function. */
775 else
777 if (!in_text_section () && !in_unlikely_text_section ())
778 text_section ();
780 targetm.asm_out.internal_label (file, "Ltext", source_label_number);
781 source_label_number++;
782 lastfile = filename;
786 /* Output N_BNSYM and line number symbol entry. */
788 static void
789 dbxout_begin_prologue (unsigned int lineno, const char *filename)
791 if (use_gnu_debug_info_extensions
792 && !NO_DBX_FUNCTION_END
793 && !flag_debug_only_used_symbols)
794 fprintf (asmfile, "%s%d,0,0\n", ASM_STABD_OP, N_BNSYM);
796 dbxout_source_line (lineno, filename);
799 /* Output a line number symbol entry for source file FILENAME and line
800 number LINENO. */
802 static void
803 dbxout_source_line (unsigned int lineno, const char *filename)
805 dbxout_source_file (asmfile, filename);
807 #ifdef ASM_OUTPUT_SOURCE_LINE
808 dbxout_source_line_counter += 1;
809 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno, dbxout_source_line_counter);
810 #else
811 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
812 #endif
815 /* Describe the beginning of an internal block within a function. */
817 static void
818 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
820 emit_pending_bincls_if_required ();
821 targetm.asm_out.internal_label (asmfile, "LBB", n);
824 /* Describe the end line-number of an internal block within a function. */
826 static void
827 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
829 emit_pending_bincls_if_required ();
830 targetm.asm_out.internal_label (asmfile, "LBE", n);
833 /* Output dbx data for a function definition.
834 This includes a definition of the function name itself (a symbol),
835 definitions of the parameters (locating them in the parameter list)
836 and then output the block that makes up the function's body
837 (including all the auto variables of the function). */
839 static void
840 dbxout_function_decl (tree decl)
842 emit_pending_bincls_if_required ();
843 #ifndef DBX_FUNCTION_FIRST
844 dbxout_begin_function (decl);
845 #endif
846 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
847 #ifdef DBX_OUTPUT_FUNCTION_END
848 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
849 #endif
850 dbxout_function_end ();
853 #endif /* DBX_DEBUGGING_INFO */
855 /* Debug information for a global DECL. Called from toplev.c after
856 compilation proper has finished. */
857 static void
858 dbxout_global_decl (tree decl)
860 if (TREE_CODE (decl) == VAR_DECL
861 && ! DECL_EXTERNAL (decl)
862 && DECL_RTL_SET_P (decl)) /* Not necessary? */
864 int saved_tree_used = TREE_USED (decl);
865 TREE_USED (decl) = 1;
866 dbxout_symbol (decl, 0);
867 TREE_USED (decl) = saved_tree_used;
871 /* This is just a function-type adapter; dbxout_symbol does exactly
872 what we want but returns an int. */
873 static void
874 dbxout_type_decl (tree decl, int local)
876 dbxout_symbol (decl, local);
879 /* At the end of compilation, finish writing the symbol table.
880 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
881 to do nothing. */
883 static void
884 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
886 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
887 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
888 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
890 debug_free_queue ();
893 /* Output the index of a type. */
895 static void
896 dbxout_type_index (tree type)
898 #ifndef DBX_USE_BINCL
899 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
900 CHARS (3);
901 #else
902 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
903 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
904 CHARS (9);
905 #endif
908 #if DBX_CONTIN_LENGTH > 0
909 /* Continue a symbol-description that gets too big.
910 End one symbol table entry with a double-backslash
911 and start a new one, eventually producing something like
912 .stabs "start......\\",code,0,value
913 .stabs "...rest",code,0,value */
915 static void
916 dbxout_continue (void)
918 emit_pending_bincls_if_required ();
919 #ifdef DBX_CONTIN_CHAR
920 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
921 #else
922 fprintf (asmfile, "\\\\");
923 #endif
924 dbxout_finish_symbol (NULL_TREE);
925 fprintf (asmfile, "%s\"", ASM_STABS_OP);
926 current_sym_nchars = 0;
928 #endif /* DBX_CONTIN_LENGTH > 0 */
930 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
931 This must be a separate function because anonymous unions require
932 recursive calls. */
934 static void
935 dbxout_type_fields (tree type)
937 tree tem;
939 /* Output the name, type, position (in bits), size (in bits) of each
940 field that we can support. */
941 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
943 /* If one of the nodes is an error_mark or its type is then
944 return early. */
945 if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
946 return;
948 /* Omit here local type decls until we know how to support them. */
949 if (TREE_CODE (tem) == TYPE_DECL
950 /* Omit fields whose position or size are variable or too large to
951 represent. */
952 || (TREE_CODE (tem) == FIELD_DECL
953 && (! host_integerp (bit_position (tem), 0)
954 || ! DECL_SIZE (tem)
955 || ! host_integerp (DECL_SIZE (tem), 1)))
956 /* Omit here the nameless fields that are used to skip bits. */
957 || DECL_IGNORED_P (tem))
958 continue;
960 else if (TREE_CODE (tem) != CONST_DECL)
962 /* Continue the line if necessary,
963 but not before the first field. */
964 if (tem != TYPE_FIELDS (type))
965 CONTIN;
967 if (DECL_NAME (tem))
969 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
970 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
972 else
974 fprintf (asmfile, ":");
975 CHARS (1);
978 if (use_gnu_debug_info_extensions
979 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
980 || TREE_CODE (tem) != FIELD_DECL))
982 have_used_extensions = 1;
983 putc ('/', asmfile);
984 putc ((TREE_PRIVATE (tem) ? '0'
985 : TREE_PROTECTED (tem) ? '1' : '2'),
986 asmfile);
987 CHARS (2);
990 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
991 && DECL_BIT_FIELD_TYPE (tem))
992 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
994 if (TREE_CODE (tem) == VAR_DECL)
996 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
998 tree name = DECL_ASSEMBLER_NAME (tem);
1000 have_used_extensions = 1;
1001 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
1002 CHARS (IDENTIFIER_LENGTH (name) + 2);
1004 else
1006 /* If TEM is non-static, GDB won't understand it. */
1007 fprintf (asmfile, ",0,0;");
1008 CHARS (5);
1011 else
1013 putc (',', asmfile);
1014 print_wide_int (int_bit_position (tem));
1015 putc (',', asmfile);
1016 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
1017 putc (';', asmfile);
1018 CHARS (3);
1024 /* Subroutine of `dbxout_type_methods'. Output debug info about the
1025 method described DECL. DEBUG_NAME is an encoding of the method's
1026 type signature. ??? We may be able to do without DEBUG_NAME altogether
1027 now. */
1029 static void
1030 dbxout_type_method_1 (tree decl, const char *debug_name)
1032 char c1 = 'A', c2;
1034 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1035 c2 = '?';
1036 else /* it's a METHOD_TYPE. */
1038 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1039 /* A for normal functions.
1040 B for `const' member functions.
1041 C for `volatile' member functions.
1042 D for `const volatile' member functions. */
1043 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1044 c1 += 1;
1045 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1046 c1 += 2;
1048 if (DECL_VINDEX (decl))
1049 c2 = '*';
1050 else
1051 c2 = '.';
1054 fprintf (asmfile, ":%s;%c%c%c", debug_name,
1055 TREE_PRIVATE (decl) ? '0'
1056 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
1057 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
1058 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1060 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1062 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
1063 putc (';', asmfile);
1064 CHARS (1);
1065 dbxout_type (DECL_CONTEXT (decl), 0);
1066 fprintf (asmfile, ";");
1067 CHARS (1);
1071 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1072 in TYPE. */
1074 static void
1075 dbxout_type_methods (tree type)
1077 /* C++: put out the method names and their parameter lists */
1078 tree methods = TYPE_METHODS (type);
1079 tree type_encoding;
1080 tree fndecl;
1081 tree last;
1082 char formatted_type_identifier_length[16];
1083 int type_identifier_length;
1085 if (methods == NULL_TREE)
1086 return;
1088 type_encoding = DECL_NAME (TYPE_NAME (type));
1090 #if 0
1091 /* C++: Template classes break some assumptions made by this code about
1092 the class names, constructor names, and encodings for assembler
1093 label names. For now, disable output of dbx info for them. */
1095 const char *ptr = IDENTIFIER_POINTER (type_encoding);
1096 /* This should use index. (mrs) */
1097 while (*ptr && *ptr != '<') ptr++;
1098 if (*ptr != 0)
1100 static int warned;
1101 if (!warned)
1102 warned = 1;
1103 return;
1106 #endif
1108 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
1110 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
1112 if (TREE_CODE (methods) != TREE_VEC)
1113 fndecl = methods;
1114 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1115 fndecl = TREE_VEC_ELT (methods, 0);
1116 else
1117 fndecl = TREE_VEC_ELT (methods, 1);
1119 while (fndecl)
1121 int need_prefix = 1;
1123 /* Group together all the methods for the same operation.
1124 These differ in the types of the arguments. */
1125 for (last = NULL_TREE;
1126 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1127 fndecl = TREE_CHAIN (fndecl))
1128 /* Output the name of the field (after overloading), as
1129 well as the name of the field before overloading, along
1130 with its parameter list */
1132 /* This is the "mangled" name of the method.
1133 It encodes the argument types. */
1134 const char *debug_name;
1136 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1137 include TEMPLATE_DECLs.) The debugger doesn't know what
1138 to do with such entities anyhow. */
1139 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1140 continue;
1142 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1144 CONTIN;
1146 last = fndecl;
1148 /* Also ignore abstract methods; those are only interesting to
1149 the DWARF backends. */
1150 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1151 continue;
1153 /* Redundantly output the plain name, since that's what gdb
1154 expects. */
1155 if (need_prefix)
1157 tree name = DECL_NAME (fndecl);
1158 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1159 CHARS (IDENTIFIER_LENGTH (name) + 2);
1160 need_prefix = 0;
1163 dbxout_type (TREE_TYPE (fndecl), 0);
1165 dbxout_type_method_1 (fndecl, debug_name);
1167 if (!need_prefix)
1169 putc (';', asmfile);
1170 CHARS (1);
1175 /* Emit a "range" type specification, which has the form:
1176 "r<index type>;<lower bound>;<upper bound>;".
1177 TYPE is an INTEGER_TYPE. */
1179 static void
1180 dbxout_range_type (tree type)
1182 fprintf (asmfile, "r");
1183 if (TREE_TYPE (type))
1184 dbxout_type (TREE_TYPE (type), 0);
1185 else if (TREE_CODE (type) != INTEGER_TYPE)
1186 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1187 else
1189 /* Traditionally, we made sure 'int' was type 1, and builtin types
1190 were defined to be sub-ranges of int. Unfortunately, this
1191 does not allow us to distinguish true sub-ranges from integer
1192 types. So, instead we define integer (non-sub-range) types as
1193 sub-ranges of themselves. This matters for Chill. If this isn't
1194 a subrange type, then we want to define it in terms of itself.
1195 However, in C, this may be an anonymous integer type, and we don't
1196 want to emit debug info referring to it. Just calling
1197 dbxout_type_index won't work anyways, because the type hasn't been
1198 defined yet. We make this work for both cases by checked to see
1199 whether this is a defined type, referring to it if it is, and using
1200 'int' otherwise. */
1201 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1202 dbxout_type_index (type);
1203 else
1204 dbxout_type_index (integer_type_node);
1207 if (TYPE_MIN_VALUE (type) != 0
1208 && host_integerp (TYPE_MIN_VALUE (type), 0))
1210 putc (';', asmfile);
1211 CHARS (1);
1212 if (print_int_cst_bounds_in_octal_p (type))
1213 print_int_cst_octal (TYPE_MIN_VALUE (type));
1214 else
1215 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1217 else
1219 fprintf (asmfile, ";0");
1220 CHARS (2);
1223 if (TYPE_MAX_VALUE (type) != 0
1224 && host_integerp (TYPE_MAX_VALUE (type), 0))
1226 putc (';', asmfile);
1227 CHARS (1);
1228 if (print_int_cst_bounds_in_octal_p (type))
1229 print_int_cst_octal (TYPE_MAX_VALUE (type));
1230 else
1231 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1232 putc (';', asmfile);
1233 CHARS (1);
1235 else
1237 fprintf (asmfile, ";-1;");
1238 CHARS (4);
1243 /* Output a reference to a type. If the type has not yet been
1244 described in the dbx output, output its definition now.
1245 For a type already defined, just refer to its definition
1246 using the type number.
1248 If FULL is nonzero, and the type has been described only with
1249 a forward-reference, output the definition now.
1250 If FULL is zero in this case, just refer to the forward-reference
1251 using the number previously allocated. */
1253 static void
1254 dbxout_type (tree type, int full)
1256 tree tem;
1257 tree main_variant;
1258 static int anonymous_type_number = 0;
1260 if (TREE_CODE (type) == VECTOR_TYPE)
1261 /* The frontend feeds us a representation for the vector as a struct
1262 containing an array. Pull out the array type. */
1263 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1265 /* If there was an input error and we don't really have a type,
1266 avoid crashing and write something that is at least valid
1267 by assuming `int'. */
1268 if (type == error_mark_node)
1269 type = integer_type_node;
1270 else
1272 if (TYPE_NAME (type)
1273 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1274 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1275 full = 0;
1278 /* Try to find the "main variant" with the same name. */
1279 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1280 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1281 main_variant = TREE_TYPE (TYPE_NAME (type));
1282 else
1283 main_variant = TYPE_MAIN_VARIANT (type);
1285 /* If we are not using extensions, stabs does not distinguish const and
1286 volatile, so there is no need to make them separate types. */
1287 if (!use_gnu_debug_info_extensions)
1288 type = main_variant;
1290 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1292 /* Type has no dbx number assigned. Assign next available number. */
1293 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1295 /* Make sure type vector is long enough to record about this type. */
1297 if (next_type_number == typevec_len)
1299 typevec
1300 = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1301 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1302 typevec_len *= 2;
1305 #ifdef DBX_USE_BINCL
1306 emit_pending_bincls_if_required ();
1307 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1308 = current_file->file_number;
1309 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1310 = current_file->next_type_number++;
1311 #endif
1314 if (flag_debug_only_used_symbols)
1316 if ((TREE_CODE (type) == RECORD_TYPE
1317 || TREE_CODE (type) == UNION_TYPE
1318 || TREE_CODE (type) == QUAL_UNION_TYPE
1319 || TREE_CODE (type) == ENUMERAL_TYPE)
1320 && TYPE_STUB_DECL (type)
1321 && DECL_P (TYPE_STUB_DECL (type))
1322 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1323 debug_queue_symbol (TYPE_STUB_DECL (type));
1324 else if (TYPE_NAME (type)
1325 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1326 debug_queue_symbol (TYPE_NAME (type));
1329 /* Output the number of this type, to refer to it. */
1330 dbxout_type_index (type);
1332 #ifdef DBX_TYPE_DEFINED
1333 if (DBX_TYPE_DEFINED (type))
1334 return;
1335 #endif
1337 /* If this type's definition has been output or is now being output,
1338 that is all. */
1340 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1342 case TYPE_UNSEEN:
1343 break;
1344 case TYPE_XREF:
1345 /* If we have already had a cross reference,
1346 and either that's all we want or that's the best we could do,
1347 don't repeat the cross reference.
1348 Sun dbx crashes if we do. */
1349 if (! full || !COMPLETE_TYPE_P (type)
1350 /* No way in DBX fmt to describe a variable size. */
1351 || ! host_integerp (TYPE_SIZE (type), 1))
1352 return;
1353 break;
1354 case TYPE_DEFINED:
1355 return;
1358 #ifdef DBX_NO_XREFS
1359 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1360 leave the type-number completely undefined rather than output
1361 a cross-reference. If we have already used GNU debug info extensions,
1362 then it is OK to output a cross reference. This is necessary to get
1363 proper C++ debug output. */
1364 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1365 || TREE_CODE (type) == QUAL_UNION_TYPE
1366 || TREE_CODE (type) == ENUMERAL_TYPE)
1367 && ! use_gnu_debug_info_extensions)
1368 /* We must use the same test here as we use twice below when deciding
1369 whether to emit a cross-reference. */
1370 if ((TYPE_NAME (type) != 0
1371 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1372 && DECL_IGNORED_P (TYPE_NAME (type)))
1373 && !full)
1374 || !COMPLETE_TYPE_P (type)
1375 /* No way in DBX fmt to describe a variable size. */
1376 || ! host_integerp (TYPE_SIZE (type), 1))
1378 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1379 return;
1381 #endif
1383 /* Output a definition now. */
1385 fprintf (asmfile, "=");
1386 CHARS (1);
1388 /* Mark it as defined, so that if it is self-referent
1389 we will not get into an infinite recursion of definitions. */
1391 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1393 /* If this type is a variant of some other, hand off. Types with
1394 different names are usefully distinguished. We only distinguish
1395 cv-qualified types if we're using extensions. */
1396 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1398 putc ('k', asmfile);
1399 CHARS (1);
1400 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1401 return;
1403 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1405 putc ('B', asmfile);
1406 CHARS (1);
1407 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1408 return;
1410 else if (main_variant != TYPE_MAIN_VARIANT (type))
1412 if (flag_debug_only_used_symbols)
1414 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1416 if ((TREE_CODE (orig_type) == RECORD_TYPE
1417 || TREE_CODE (orig_type) == UNION_TYPE
1418 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1419 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1420 && TYPE_STUB_DECL (orig_type)
1421 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1422 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1424 /* 'type' is a typedef; output the type it refers to. */
1425 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1426 return;
1428 /* else continue. */
1430 switch (TREE_CODE (type))
1432 case VOID_TYPE:
1433 case LANG_TYPE:
1434 /* For a void type, just define it as itself; ie, "5=5".
1435 This makes us consider it defined
1436 without saying what it is. The debugger will make it
1437 a void type when the reference is seen, and nothing will
1438 ever override that default. */
1439 dbxout_type_index (type);
1440 break;
1442 case INTEGER_TYPE:
1443 if (type == char_type_node && ! TYPE_UNSIGNED (type))
1445 /* Output the type `char' as a subrange of itself!
1446 I don't understand this definition, just copied it
1447 from the output of pcc.
1448 This used to use `r2' explicitly and we used to
1449 take care to make sure that `char' was type number 2. */
1450 fprintf (asmfile, "r");
1451 CHARS (1);
1452 dbxout_type_index (type);
1453 fprintf (asmfile, ";0;127;");
1454 CHARS (7);
1457 /* If this is a subtype of another integer type, always prefer to
1458 write it as a subtype. */
1459 else if (TREE_TYPE (type) != 0
1460 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1462 /* If the size is non-standard, say what it is if we can use
1463 GDB extensions. */
1465 if (use_gnu_debug_info_extensions
1466 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1468 have_used_extensions = 1;
1469 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1470 CHARS (5);
1473 dbxout_range_type (type);
1476 else
1478 /* If the size is non-standard, say what it is if we can use
1479 GDB extensions. */
1481 if (use_gnu_debug_info_extensions
1482 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1484 have_used_extensions = 1;
1485 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1486 CHARS (5);
1489 if (print_int_cst_bounds_in_octal_p (type))
1491 fprintf (asmfile, "r");
1492 CHARS (1);
1494 /* If this type derives from another type, output type index of
1495 parent type. This is particularly important when parent type
1496 is an enumerated type, because not generating the parent type
1497 index would transform the definition of this enumerated type
1498 into a plain unsigned type. */
1499 if (TREE_TYPE (type) != 0)
1500 dbxout_type_index (TREE_TYPE (type));
1501 else
1502 dbxout_type_index (type);
1504 fprintf (asmfile, ";");
1505 CHARS (1);
1506 print_int_cst_octal (TYPE_MIN_VALUE (type));
1507 fprintf (asmfile, ";");
1508 CHARS (1);
1509 print_int_cst_octal (TYPE_MAX_VALUE (type));
1510 fprintf (asmfile, ";");
1511 CHARS (1);
1514 else
1515 /* Output other integer types as subranges of `int'. */
1516 dbxout_range_type (type);
1519 break;
1521 case REAL_TYPE:
1522 /* This used to say `r1' and we used to take care
1523 to make sure that `int' was type number 1. */
1524 fprintf (asmfile, "r");
1525 CHARS (1);
1526 dbxout_type_index (integer_type_node);
1527 putc (';', asmfile);
1528 CHARS (1);
1529 print_wide_int (int_size_in_bytes (type));
1530 fputs (";0;", asmfile);
1531 CHARS (3);
1532 break;
1534 case CHAR_TYPE:
1535 if (use_gnu_debug_info_extensions)
1537 have_used_extensions = 1;
1538 fputs ("@s", asmfile);
1539 CHARS (2);
1540 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1541 fputs (";-20;", asmfile);
1542 CHARS (4);
1544 else
1546 /* Output the type `char' as a subrange of itself.
1547 That is what pcc seems to do. */
1548 fprintf (asmfile, "r");
1549 CHARS (1);
1550 dbxout_type_index (char_type_node);
1551 fprintf (asmfile, ";0;%d;", TYPE_UNSIGNED (type) ? 255 : 127);
1552 CHARS (7);
1554 break;
1556 case BOOLEAN_TYPE:
1557 if (use_gnu_debug_info_extensions)
1559 have_used_extensions = 1;
1560 fputs ("@s", asmfile);
1561 CHARS (2);
1562 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1563 fputs (";-16;", asmfile);
1564 CHARS (4);
1566 else /* Define as enumeral type (False, True) */
1568 fprintf (asmfile, "eFalse:0,True:1,;");
1569 CHARS (17);
1571 break;
1573 case FILE_TYPE:
1574 putc ('d', asmfile);
1575 CHARS (1);
1576 dbxout_type (TREE_TYPE (type), 0);
1577 break;
1579 case COMPLEX_TYPE:
1580 /* Differs from the REAL_TYPE by its new data type number.
1581 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
1582 codes since gdb doesn't care anyway. */
1584 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1586 fputs ("R3;", asmfile);
1587 CHARS (3);
1588 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1589 fputs (";0;", asmfile);
1590 CHARS (3);
1592 else
1594 /* Output a complex integer type as a structure,
1595 pending some other way to do it. */
1596 putc ('s', asmfile);
1597 CHARS (1);
1598 print_wide_int (int_size_in_bytes (type));
1599 fprintf (asmfile, "real:");
1600 CHARS (5);
1602 dbxout_type (TREE_TYPE (type), 0);
1603 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1604 CHARS (7);
1605 fprintf (asmfile, "imag:");
1606 CHARS (5);
1607 dbxout_type (TREE_TYPE (type), 0);
1608 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1609 TYPE_PRECISION (TREE_TYPE (type)));
1610 CHARS (10);
1612 break;
1614 case SET_TYPE:
1615 if (use_gnu_debug_info_extensions)
1617 have_used_extensions = 1;
1618 fputs ("@s", asmfile);
1619 CHARS (2);
1620 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1621 putc (';', asmfile);
1622 CHARS (1);
1624 /* Check if a bitstring type, which in Chill is
1625 different from a [power]set. */
1626 if (TYPE_STRING_FLAG (type))
1628 fprintf (asmfile, "@S;");
1629 CHARS (3);
1632 putc ('S', asmfile);
1633 CHARS (1);
1634 dbxout_type (TYPE_DOMAIN (type), 0);
1635 break;
1637 case ARRAY_TYPE:
1638 /* Make arrays of packed bits look like bitstrings for chill. */
1639 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1641 have_used_extensions = 1;
1642 fputs ("@s", asmfile);
1643 CHARS (2);
1644 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1645 fprintf (asmfile, ";@S;S");
1646 CHARS (5);
1647 dbxout_type (TYPE_DOMAIN (type), 0);
1648 break;
1651 /* Output "a" followed by a range type definition
1652 for the index type of the array
1653 followed by a reference to the target-type.
1654 ar1;0;N;M for a C array of type M and size N+1. */
1655 /* Check if a character string type, which in Chill is
1656 different from an array of characters. */
1657 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1659 have_used_extensions = 1;
1660 fprintf (asmfile, "@S;");
1661 CHARS (3);
1663 tem = TYPE_DOMAIN (type);
1664 if (tem == NULL)
1666 fprintf (asmfile, "ar");
1667 CHARS (2);
1668 dbxout_type_index (integer_type_node);
1669 fprintf (asmfile, ";0;-1;");
1670 CHARS (6);
1672 else
1674 fprintf (asmfile, "a");
1675 CHARS (1);
1676 dbxout_range_type (tem);
1679 dbxout_type (TREE_TYPE (type), 0);
1680 break;
1682 case RECORD_TYPE:
1683 case UNION_TYPE:
1684 case QUAL_UNION_TYPE:
1686 tree binfo = TYPE_BINFO (type);
1688 /* Output a structure type. We must use the same test here as we
1689 use in the DBX_NO_XREFS case above. */
1690 if ((TYPE_NAME (type) != 0
1691 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1692 && DECL_IGNORED_P (TYPE_NAME (type)))
1693 && !full)
1694 || !COMPLETE_TYPE_P (type)
1695 /* No way in DBX fmt to describe a variable size. */
1696 || ! host_integerp (TYPE_SIZE (type), 1))
1698 /* If the type is just a cross reference, output one
1699 and mark the type as partially described.
1700 If it later becomes defined, we will output
1701 its real definition.
1702 If the type has a name, don't nest its definition within
1703 another type's definition; instead, output an xref
1704 and let the definition come when the name is defined. */
1705 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1706 CHARS (2);
1707 #if 0 /* This assertion is legitimately false in C++. */
1708 /* We shouldn't be outputting a reference to a type before its
1709 definition unless the type has a tag name.
1710 A typedef name without a tag name should be impossible. */
1711 gcc_assert (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE);
1712 #endif
1713 if (TYPE_NAME (type) != 0)
1714 dbxout_type_name (type);
1715 else
1717 fprintf (asmfile, "$$%d", anonymous_type_number++);
1718 CHARS (5);
1721 fprintf (asmfile, ":");
1722 CHARS (1);
1723 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1724 break;
1727 /* Identify record or union, and print its size. */
1728 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1729 CHARS (1);
1730 print_wide_int (int_size_in_bytes (type));
1732 if (binfo)
1734 int i;
1735 tree child;
1736 VEC (tree) *accesses = BINFO_BASE_ACCESSES (binfo);
1738 if (use_gnu_debug_info_extensions)
1740 if (BINFO_N_BASE_BINFOS (binfo))
1742 have_used_extensions = 1;
1743 fprintf (asmfile, "!%u,", BINFO_N_BASE_BINFOS (binfo));
1744 CHARS (8);
1747 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
1749 tree access = (accesses ? VEC_index (tree, accesses, i)
1750 : access_public_node);
1752 if (use_gnu_debug_info_extensions)
1754 have_used_extensions = 1;
1755 putc (BINFO_VIRTUAL_P (child) ? '1' : '0', asmfile);
1756 putc (access == access_public_node ? '2' :
1757 (access == access_protected_node ? '1' :'0'),
1758 asmfile);
1759 CHARS (2);
1760 if (BINFO_VIRTUAL_P (child)
1761 && strcmp (lang_hooks.name, "GNU C++") == 0)
1762 /* For a virtual base, print the (negative)
1763 offset within the vtable where we must look
1764 to find the necessary adjustment. */
1765 print_wide_int
1766 (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1767 * BITS_PER_UNIT);
1768 else
1769 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1770 * BITS_PER_UNIT);
1771 putc (',', asmfile);
1772 CHARS (1);
1773 dbxout_type (BINFO_TYPE (child), 0);
1774 putc (';', asmfile);
1775 CHARS (1);
1777 else
1779 /* Print out the base class information with
1780 fields which have the same names at the types
1781 they hold. */
1782 dbxout_type_name (BINFO_TYPE (child));
1783 putc (':', asmfile);
1784 CHARS (1);
1785 dbxout_type (BINFO_TYPE (child), full);
1786 putc (',', asmfile);
1787 CHARS (1);
1788 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1789 * BITS_PER_UNIT);
1790 putc (',', asmfile);
1791 CHARS (1);
1792 print_wide_int
1793 (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
1794 * BITS_PER_UNIT);
1795 putc (';', asmfile);
1796 CHARS (1);
1802 /* Write out the field declarations. */
1803 dbxout_type_fields (type);
1804 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1806 have_used_extensions = 1;
1807 dbxout_type_methods (type);
1810 putc (';', asmfile);
1811 CHARS (1);
1813 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1814 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1815 && TYPE_VFIELD (type))
1817 have_used_extensions = 1;
1819 /* Tell GDB+ that it may keep reading. */
1820 putc ('~', asmfile);
1821 CHARS (1);
1823 /* We need to write out info about what field this class
1824 uses as its "main" vtable pointer field, because if this
1825 field is inherited from a base class, GDB cannot necessarily
1826 figure out which field it's using in time. */
1827 if (TYPE_VFIELD (type))
1829 putc ('%', asmfile);
1830 CHARS (1);
1831 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1834 putc (';', asmfile);
1835 CHARS (1);
1837 break;
1839 case ENUMERAL_TYPE:
1840 /* We must use the same test here as we use in the DBX_NO_XREFS case
1841 above. We simplify it a bit since an enum will never have a variable
1842 size. */
1843 if ((TYPE_NAME (type) != 0
1844 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1845 && DECL_IGNORED_P (TYPE_NAME (type)))
1846 && !full)
1847 || !COMPLETE_TYPE_P (type))
1849 fprintf (asmfile, "xe");
1850 CHARS (2);
1851 dbxout_type_name (type);
1852 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1853 putc (':', asmfile);
1854 CHARS (1);
1855 return;
1857 if (use_gnu_debug_info_extensions
1858 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1860 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1861 CHARS (5);
1864 putc ('e', asmfile);
1865 CHARS (1);
1866 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1868 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1869 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1870 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1871 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1872 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1873 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1874 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1875 else
1876 print_int_cst_octal (TREE_VALUE (tem));
1878 putc (',', asmfile);
1879 CHARS (1);
1880 if (TREE_CHAIN (tem) != 0)
1881 CONTIN;
1884 putc (';', asmfile);
1885 CHARS (1);
1886 break;
1888 case POINTER_TYPE:
1889 putc ('*', asmfile);
1890 CHARS (1);
1891 dbxout_type (TREE_TYPE (type), 0);
1892 break;
1894 case METHOD_TYPE:
1895 if (use_gnu_debug_info_extensions)
1897 have_used_extensions = 1;
1898 putc ('#', asmfile);
1899 CHARS (1);
1901 /* Write the argument types out longhand. */
1902 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1903 putc (',', asmfile);
1904 CHARS (1);
1905 dbxout_type (TREE_TYPE (type), 0);
1906 dbxout_args (TYPE_ARG_TYPES (type));
1907 putc (';', asmfile);
1908 CHARS (1);
1910 else
1911 /* Treat it as a function type. */
1912 dbxout_type (TREE_TYPE (type), 0);
1913 break;
1915 case OFFSET_TYPE:
1916 if (use_gnu_debug_info_extensions)
1918 have_used_extensions = 1;
1919 putc ('@', asmfile);
1920 CHARS (1);
1921 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1922 putc (',', asmfile);
1923 CHARS (1);
1924 dbxout_type (TREE_TYPE (type), 0);
1926 else
1927 /* Should print as an int, because it is really just an offset. */
1928 dbxout_type (integer_type_node, 0);
1929 break;
1931 case REFERENCE_TYPE:
1932 if (use_gnu_debug_info_extensions)
1933 have_used_extensions = 1;
1934 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1935 CHARS (1);
1936 dbxout_type (TREE_TYPE (type), 0);
1937 break;
1939 case FUNCTION_TYPE:
1940 putc ('f', asmfile);
1941 CHARS (1);
1942 dbxout_type (TREE_TYPE (type), 0);
1943 break;
1945 default:
1946 gcc_unreachable ();
1950 /* Return nonzero if the given type represents an integer whose bounds
1951 should be printed in octal format. */
1953 static bool
1954 print_int_cst_bounds_in_octal_p (tree type)
1956 /* If we can use GDB extensions and the size is wider than a long
1957 (the size used by GDB to read them) or we may have trouble writing
1958 the bounds the usual way, write them in octal. Note the test is for
1959 the *target's* size of "long", not that of the host. The host test
1960 is just to make sure we can write it out in case the host wide int
1961 is narrower than the target "long".
1963 For unsigned types, we use octal if they are the same size or larger.
1964 This is because we print the bounds as signed decimal, and hence they
1965 can't span same size unsigned types. */
1967 if (use_gnu_debug_info_extensions
1968 && TYPE_MIN_VALUE (type) != 0
1969 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1970 && TYPE_MAX_VALUE (type) != 0
1971 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1972 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1973 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1974 && TYPE_UNSIGNED (type))
1975 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1976 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1977 && TYPE_UNSIGNED (type))))
1978 return TRUE;
1979 else
1980 return FALSE;
1983 /* Print the value of integer constant C, in octal,
1984 handling double precision. */
1986 static void
1987 print_int_cst_octal (tree c)
1989 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1990 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1991 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1992 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1994 /* GDB wants constants with no extra leading "1" bits, so
1995 we need to remove any sign-extension that might be
1996 present. */
1997 if (width == HOST_BITS_PER_WIDE_INT * 2)
1999 else if (width > HOST_BITS_PER_WIDE_INT)
2000 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
2001 else if (width == HOST_BITS_PER_WIDE_INT)
2002 high = 0;
2003 else
2004 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
2006 fprintf (asmfile, "0");
2007 CHARS (1);
2009 if (excess == 3)
2011 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
2012 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
2014 else
2016 unsigned HOST_WIDE_INT beg = high >> excess;
2017 unsigned HOST_WIDE_INT middle
2018 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
2019 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
2020 unsigned HOST_WIDE_INT end
2021 = low & (((unsigned HOST_WIDE_INT) 1
2022 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
2023 - 1);
2025 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
2026 CHARS (2);
2027 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
2031 static void
2032 print_octal (unsigned HOST_WIDE_INT value, int digits)
2034 int i;
2036 for (i = digits - 1; i >= 0; i--)
2037 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
2039 CHARS (digits);
2042 /* Output C in decimal while adjusting the number of digits written. */
2044 static void
2045 print_wide_int (HOST_WIDE_INT c)
2047 int digs = 0;
2049 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
2051 if (c < 0)
2052 digs++, c = -c;
2054 while (c > 0)
2055 c /= 10; digs++;
2057 CHARS (digs);
2060 /* Output the name of type TYPE, with no punctuation.
2061 Such names can be set up either by typedef declarations
2062 or by struct, enum and union tags. */
2064 static void
2065 dbxout_type_name (tree type)
2067 tree t = TYPE_NAME (type);
2069 gcc_assert (t);
2070 switch (TREE_CODE (t))
2072 case IDENTIFIER_NODE:
2073 break;
2074 case TYPE_DECL:
2075 t = DECL_NAME (t);
2076 break;
2077 default:
2078 gcc_unreachable ();
2081 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
2082 CHARS (IDENTIFIER_LENGTH (t));
2085 /* Output leading leading struct or class names needed for qualifying
2086 type whose scope is limited to a struct or class. */
2088 static void
2089 dbxout_class_name_qualifiers (tree decl)
2091 tree context = decl_type_context (decl);
2093 if (context != NULL_TREE
2094 && TREE_CODE(context) == RECORD_TYPE
2095 && TYPE_NAME (context) != 0
2096 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2097 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2099 tree name = TYPE_NAME (context);
2101 emit_pending_bincls_if_required ();
2103 if (TREE_CODE (name) == TYPE_DECL)
2105 dbxout_class_name_qualifiers (name);
2106 name = DECL_NAME (name);
2108 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
2109 CHARS (IDENTIFIER_LENGTH (name) + 2);
2113 /* Output a .stabs for the symbol defined by DECL,
2114 which must be a ..._DECL node in the normal namespace.
2115 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2116 LOCAL is nonzero if the scope is less than the entire file.
2117 Return 1 if a stabs might have been emitted. */
2120 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2122 tree type = TREE_TYPE (decl);
2123 tree context = NULL_TREE;
2124 int result = 0;
2126 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2127 ++debug_nesting;
2129 /* Ignore nameless syms, but don't ignore type tags. */
2131 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2132 || DECL_IGNORED_P (decl))
2133 DBXOUT_DECR_NESTING_AND_RETURN (0);
2135 /* If we are to generate only the symbols actually used then such
2136 symbol nodees are flagged with TREE_USED. Ignore any that
2137 aren't flaged as TREE_USED. */
2139 if (flag_debug_only_used_symbols
2140 && (!TREE_USED (decl)
2141 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2142 DBXOUT_DECR_NESTING_AND_RETURN (0);
2144 /* If dbxout_init has not yet run, queue this symbol for later. */
2145 if (!typevec)
2147 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2148 DBXOUT_DECR_NESTING_AND_RETURN (0);
2151 if (flag_debug_only_used_symbols)
2153 tree t;
2155 /* We now have a used symbol. We need to generate the info for
2156 the symbol's type in addition to the symbol itself. These
2157 type symbols are queued to be generated after were done with
2158 the symbol itself (done because the symbol's info is generated
2159 with fprintf's, etc. as it determines what's needed).
2161 Note, because the TREE_TYPE(type) might be something like a
2162 pointer to a named type we need to look for the first name
2163 we see following the TREE_TYPE chain. */
2165 t = type;
2166 while (POINTER_TYPE_P (t))
2167 t = TREE_TYPE (t);
2169 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2170 need special treatment. The TYPE_STUB_DECL field in these
2171 types generally represents the tag name type we want to
2172 output. In addition there could be a typedef type with
2173 a different name. In that case we also want to output
2174 that. */
2176 if ((TREE_CODE (t) == RECORD_TYPE
2177 || TREE_CODE (t) == UNION_TYPE
2178 || TREE_CODE (t) == QUAL_UNION_TYPE
2179 || TREE_CODE (t) == ENUMERAL_TYPE)
2180 && TYPE_STUB_DECL (t)
2181 && TYPE_STUB_DECL (t) != decl
2182 && DECL_P (TYPE_STUB_DECL (t))
2183 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2185 debug_queue_symbol (TYPE_STUB_DECL (t));
2186 if (TYPE_NAME (t)
2187 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2188 && TYPE_NAME (t) != decl
2189 && DECL_P (TYPE_NAME (t)))
2190 debug_queue_symbol (TYPE_NAME (t));
2192 else if (TYPE_NAME (t)
2193 && TYPE_NAME (t) != decl
2194 && DECL_P (TYPE_NAME (t)))
2195 debug_queue_symbol (TYPE_NAME (t));
2198 emit_pending_bincls_if_required ();
2200 dbxout_prepare_symbol (decl);
2202 /* The output will always start with the symbol name,
2203 so always count that in the length-output-so-far. */
2205 if (DECL_NAME (decl) != 0)
2206 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2208 switch (TREE_CODE (decl))
2210 case CONST_DECL:
2211 /* Enum values are defined by defining the enum type. */
2212 break;
2214 case FUNCTION_DECL:
2215 if (DECL_RTL (decl) == 0)
2216 DBXOUT_DECR_NESTING_AND_RETURN (0);
2217 if (DECL_EXTERNAL (decl))
2218 break;
2219 /* Don't mention a nested function under its parent. */
2220 context = decl_function_context (decl);
2221 if (context == current_function_decl)
2222 break;
2223 if (!MEM_P (DECL_RTL (decl))
2224 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2225 break;
2226 FORCE_TEXT;
2228 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2229 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2230 TREE_PUBLIC (decl) ? 'F' : 'f');
2231 result = 1;
2233 current_sym_code = N_FUN;
2234 current_sym_addr = XEXP (DECL_RTL (decl), 0);
2236 if (TREE_TYPE (type))
2237 dbxout_type (TREE_TYPE (type), 0);
2238 else
2239 dbxout_type (void_type_node, 0);
2241 /* For a nested function, when that function is compiled,
2242 mention the containing function name
2243 as well as (since dbx wants it) our own assembler-name. */
2244 if (context != 0)
2245 fprintf (asmfile, ",%s,%s",
2246 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2247 IDENTIFIER_POINTER (DECL_NAME (context)));
2249 dbxout_finish_symbol (decl);
2250 break;
2252 case TYPE_DECL:
2253 /* Don't output the same typedef twice.
2254 And don't output what language-specific stuff doesn't want output. */
2255 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2256 DBXOUT_DECR_NESTING_AND_RETURN (0);
2258 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2259 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2261 int fundamental_type_number =
2262 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2264 if (fundamental_type_number != 0)
2266 TREE_ASM_WRITTEN (decl) = 1;
2267 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2268 DBXOUT_DECR_NESTING_AND_RETURN (0);
2271 #endif
2272 FORCE_TEXT;
2273 result = 1;
2275 int tag_needed = 1;
2276 int did_output = 0;
2278 if (DECL_NAME (decl))
2280 /* Nonzero means we must output a tag as well as a typedef. */
2281 tag_needed = 0;
2283 /* Handle the case of a C++ structure or union
2284 where the TYPE_NAME is a TYPE_DECL
2285 which gives both a typedef name and a tag. */
2286 /* dbx requires the tag first and the typedef second. */
2287 if ((TREE_CODE (type) == RECORD_TYPE
2288 || TREE_CODE (type) == UNION_TYPE
2289 || TREE_CODE (type) == QUAL_UNION_TYPE)
2290 && TYPE_NAME (type) == decl
2291 && !(use_gnu_debug_info_extensions && have_used_extensions)
2292 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2293 /* Distinguish the implicit typedefs of C++
2294 from explicit ones that might be found in C. */
2295 && DECL_ARTIFICIAL (decl)
2296 /* Do not generate a tag for incomplete records. */
2297 && COMPLETE_TYPE_P (type)
2298 /* Do not generate a tag for records of variable size,
2299 since this type can not be properly described in the
2300 DBX format, and it confuses some tools such as objdump. */
2301 && host_integerp (TYPE_SIZE (type), 1))
2303 tree name = TYPE_NAME (type);
2304 if (TREE_CODE (name) == TYPE_DECL)
2305 name = DECL_NAME (name);
2307 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2308 current_sym_value = 0;
2309 current_sym_addr = 0;
2310 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2312 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2313 IDENTIFIER_POINTER (name));
2314 dbxout_type (type, 1);
2315 dbxout_finish_symbol (NULL_TREE);
2318 /* Output .stabs (or whatever) and leading double quote. */
2319 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2321 if (use_gnu_debug_info_extensions)
2323 /* Output leading class/struct qualifiers. */
2324 dbxout_class_name_qualifiers (decl);
2327 /* Output typedef name. */
2328 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2330 /* Short cut way to output a tag also. */
2331 if ((TREE_CODE (type) == RECORD_TYPE
2332 || TREE_CODE (type) == UNION_TYPE
2333 || TREE_CODE (type) == QUAL_UNION_TYPE)
2334 && TYPE_NAME (type) == decl
2335 /* Distinguish the implicit typedefs of C++
2336 from explicit ones that might be found in C. */
2337 && DECL_ARTIFICIAL (decl))
2339 if (use_gnu_debug_info_extensions && have_used_extensions)
2341 putc ('T', asmfile);
2342 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2344 #if 0 /* Now we generate the tag for this case up above. */
2345 else
2346 tag_needed = 1;
2347 #endif
2350 putc ('t', asmfile);
2351 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2353 dbxout_type (type, 1);
2354 dbxout_finish_symbol (decl);
2355 did_output = 1;
2358 /* Don't output a tag if this is an incomplete type. This prevents
2359 the sun4 Sun OS 4.x dbx from crashing. */
2361 if (tag_needed && TYPE_NAME (type) != 0
2362 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2363 || (DECL_NAME (TYPE_NAME (type)) != 0))
2364 && COMPLETE_TYPE_P (type)
2365 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2367 /* For a TYPE_DECL with no name, but the type has a name,
2368 output a tag.
2369 This is what represents `struct foo' with no typedef. */
2370 /* In C++, the name of a type is the corresponding typedef.
2371 In C, it is an IDENTIFIER_NODE. */
2372 tree name = TYPE_NAME (type);
2373 if (TREE_CODE (name) == TYPE_DECL)
2374 name = DECL_NAME (name);
2376 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2377 current_sym_value = 0;
2378 current_sym_addr = 0;
2379 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2381 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2382 IDENTIFIER_POINTER (name));
2383 dbxout_type (type, 1);
2384 dbxout_finish_symbol (NULL_TREE);
2385 did_output = 1;
2388 /* If an enum type has no name, it cannot be referred to,
2389 but we must output it anyway, since the enumeration constants
2390 can be referred to. */
2391 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2393 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2394 current_sym_value = 0;
2395 current_sym_addr = 0;
2396 current_sym_nchars = 2;
2398 /* Some debuggers fail when given NULL names, so give this a
2399 harmless name of ` '. */
2400 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2401 dbxout_type (type, 1);
2402 dbxout_finish_symbol (NULL_TREE);
2405 /* Prevent duplicate output of a typedef. */
2406 TREE_ASM_WRITTEN (decl) = 1;
2407 break;
2410 case PARM_DECL:
2411 /* Parm decls go in their own separate chains
2412 and are output by dbxout_reg_parms and dbxout_parms. */
2413 gcc_unreachable ();
2415 case RESULT_DECL:
2416 /* Named return value, treat like a VAR_DECL. */
2417 case VAR_DECL:
2418 if (! DECL_RTL_SET_P (decl))
2419 DBXOUT_DECR_NESTING_AND_RETURN (0);
2420 /* Don't mention a variable that is external.
2421 Let the file that defines it describe it. */
2422 if (DECL_EXTERNAL (decl))
2423 break;
2425 /* If the variable is really a constant
2426 and not written in memory, inform the debugger. */
2427 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2428 && DECL_INITIAL (decl) != 0
2429 && host_integerp (DECL_INITIAL (decl), 0)
2430 && ! TREE_ASM_WRITTEN (decl)
2431 && (DECL_CONTEXT (decl) == NULL_TREE
2432 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2434 if (TREE_PUBLIC (decl) == 0)
2436 /* The sun4 assembler does not grok this. */
2437 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2439 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2440 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2442 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2443 fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2444 "\",0x%x,0,0,0\n",
2445 ASM_STABS_OP, name, ival, N_LSYM);
2446 DBXOUT_DECR_NESTING;
2447 return 1;
2449 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2451 /* Don't know how to do this yet. */
2453 break;
2455 /* else it is something we handle like a normal variable. */
2458 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2459 #ifdef LEAF_REG_REMAP
2460 if (current_function_uses_only_leaf_regs)
2461 leaf_renumber_regs_insn (DECL_RTL (decl));
2462 #endif
2464 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2465 break;
2467 default:
2468 break;
2470 DBXOUT_DECR_NESTING;
2471 return result;
2474 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2475 Add SUFFIX to its name, if SUFFIX is not 0.
2476 Describe the variable as residing in HOME
2477 (usually HOME is DECL_RTL (DECL), but not always).
2478 Returns 1 if the stab was really emitted. */
2480 static int
2481 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2483 int letter = 0;
2484 int regno = -1;
2486 emit_pending_bincls_if_required ();
2488 /* Don't mention a variable at all
2489 if it was completely optimized into nothingness.
2491 If the decl was from an inline function, then its rtl
2492 is not identically the rtl that was used in this
2493 particular compilation. */
2494 if (GET_CODE (home) == SUBREG)
2496 rtx value = home;
2498 while (GET_CODE (value) == SUBREG)
2499 value = SUBREG_REG (value);
2500 if (REG_P (value))
2502 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2503 return 0;
2505 home = alter_subreg (&home);
2507 if (REG_P (home))
2509 regno = REGNO (home);
2510 if (regno >= FIRST_PSEUDO_REGISTER)
2511 return 0;
2514 /* The kind-of-variable letter depends on where
2515 the variable is and on the scope of its name:
2516 G and N_GSYM for static storage and global scope,
2517 S for static storage and file scope,
2518 V for static storage and local scope,
2519 for those two, use N_LCSYM if data is in bss segment,
2520 N_STSYM if in data segment, N_FUN otherwise.
2521 (We used N_FUN originally, then changed to N_STSYM
2522 to please GDB. However, it seems that confused ld.
2523 Now GDB has been fixed to like N_FUN, says Kingdon.)
2524 no letter at all, and N_LSYM, for auto variable,
2525 r and N_RSYM for register variable. */
2527 if (MEM_P (home)
2528 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2530 if (TREE_PUBLIC (decl))
2532 letter = 'G';
2533 current_sym_code = N_GSYM;
2535 else
2537 current_sym_addr = XEXP (home, 0);
2539 letter = decl_function_context (decl) ? 'V' : 'S';
2541 /* This should be the same condition as in assemble_variable, but
2542 we don't have access to dont_output_data here. So, instead,
2543 we rely on the fact that error_mark_node initializers always
2544 end up in bss for C++ and never end up in bss for C. */
2545 if (DECL_INITIAL (decl) == 0
2546 || (!strcmp (lang_hooks.name, "GNU C++")
2547 && DECL_INITIAL (decl) == error_mark_node))
2548 current_sym_code = N_LCSYM;
2549 else if (DECL_IN_TEXT_SECTION (decl))
2550 /* This is not quite right, but it's the closest
2551 of all the codes that Unix defines. */
2552 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2553 else
2555 /* Some ports can transform a symbol ref into a label ref,
2556 because the symbol ref is too far away and has to be
2557 dumped into a constant pool. Alternatively, the symbol
2558 in the constant pool might be referenced by a different
2559 symbol. */
2560 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2561 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2563 bool marked;
2564 rtx tmp = get_pool_constant_mark (current_sym_addr, &marked);
2566 if (GET_CODE (tmp) == SYMBOL_REF)
2568 current_sym_addr = tmp;
2569 if (CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2570 get_pool_constant_mark (current_sym_addr, &marked);
2571 else
2572 marked = true;
2574 else if (GET_CODE (tmp) == LABEL_REF)
2576 current_sym_addr = tmp;
2577 marked = true;
2580 /* If all references to the constant pool were optimized
2581 out, we just ignore the symbol. */
2582 if (!marked)
2583 return 0;
2586 /* Ultrix `as' seems to need this. */
2587 #ifdef DBX_STATIC_STAB_DATA_SECTION
2588 data_section ();
2589 #endif
2590 current_sym_code = N_STSYM;
2594 else if (regno >= 0)
2596 letter = 'r';
2597 current_sym_code = N_RSYM;
2598 current_sym_value = DBX_REGISTER_NUMBER (regno);
2600 else if (MEM_P (home)
2601 && (MEM_P (XEXP (home, 0))
2602 || (REG_P (XEXP (home, 0))
2603 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2604 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2605 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2606 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2607 #endif
2609 /* If the value is indirect by memory or by a register
2610 that isn't the frame pointer
2611 then it means the object is variable-sized and address through
2612 that register or stack slot. DBX has no way to represent this
2613 so all we can do is output the variable as a pointer.
2614 If it's not a parameter, ignore it. */
2616 if (REG_P (XEXP (home, 0)))
2618 letter = 'r';
2619 current_sym_code = N_RSYM;
2620 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2621 return 0;
2622 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2624 else
2626 current_sym_code = N_LSYM;
2627 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2628 We want the value of that CONST_INT. */
2629 current_sym_value
2630 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2633 /* Effectively do build_pointer_type, but don't cache this type,
2634 since it might be temporary whereas the type it points to
2635 might have been saved for inlining. */
2636 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2637 type = make_node (POINTER_TYPE);
2638 TREE_TYPE (type) = TREE_TYPE (decl);
2640 else if (MEM_P (home)
2641 && REG_P (XEXP (home, 0)))
2643 current_sym_code = N_LSYM;
2644 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2646 else if (MEM_P (home)
2647 && GET_CODE (XEXP (home, 0)) == PLUS
2648 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2650 current_sym_code = N_LSYM;
2651 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2652 We want the value of that CONST_INT. */
2653 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2655 else if (MEM_P (home)
2656 && GET_CODE (XEXP (home, 0)) == CONST)
2658 /* Handle an obscure case which can arise when optimizing and
2659 when there are few available registers. (This is *always*
2660 the case for i386/i486 targets). The RTL looks like
2661 (MEM (CONST ...)) even though this variable is a local `auto'
2662 or a local `register' variable. In effect, what has happened
2663 is that the reload pass has seen that all assignments and
2664 references for one such a local variable can be replaced by
2665 equivalent assignments and references to some static storage
2666 variable, thereby avoiding the need for a register. In such
2667 cases we're forced to lie to debuggers and tell them that
2668 this variable was itself `static'. */
2669 current_sym_code = N_LCSYM;
2670 letter = 'V';
2671 current_sym_addr = XEXP (XEXP (home, 0), 0);
2673 else if (GET_CODE (home) == CONCAT)
2675 tree subtype;
2677 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2678 for example), then there is no easy way to figure out
2679 what SUBTYPE should be. So, we give up. */
2680 if (TREE_CODE (type) != COMPLEX_TYPE)
2681 return 0;
2683 subtype = TREE_TYPE (type);
2685 /* If the variable's storage is in two parts,
2686 output each as a separate stab with a modified name. */
2687 if (WORDS_BIG_ENDIAN)
2688 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2689 else
2690 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2692 dbxout_prepare_symbol (decl);
2694 if (WORDS_BIG_ENDIAN)
2695 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2696 else
2697 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2698 return 1;
2700 else
2701 /* Address might be a MEM, when DECL is a variable-sized object.
2702 Or it might be const0_rtx, meaning previous passes
2703 want us to ignore this variable. */
2704 return 0;
2706 /* Ok, start a symtab entry and output the variable name. */
2707 FORCE_TEXT;
2709 #ifdef DBX_STATIC_BLOCK_START
2710 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2711 #endif
2713 dbxout_symbol_name (decl, suffix, letter);
2714 dbxout_type (type, 0);
2715 dbxout_finish_symbol (decl);
2717 #ifdef DBX_STATIC_BLOCK_END
2718 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2719 #endif
2720 return 1;
2723 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2724 Then output LETTER to indicate the kind of location the symbol has. */
2726 static void
2727 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2729 const char *name;
2731 if (DECL_CONTEXT (decl)
2732 && (TYPE_P (DECL_CONTEXT (decl))
2733 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
2734 /* One slight hitch: if this is a VAR_DECL which is a class member
2735 or a namespace member, we must put out the mangled name instead of the
2736 DECL_NAME. Note also that static member (variable) names DO NOT begin
2737 with underscores in .stabs directives. */
2738 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2739 else
2740 /* ...but if we're function-local, we don't want to include the junk
2741 added by ASM_FORMAT_PRIVATE_NAME. */
2742 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2744 if (name == 0)
2745 name = "(anon)";
2746 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2747 (suffix ? suffix : ""));
2749 if (letter)
2750 putc (letter, asmfile);
2753 static void
2754 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)
2756 #ifdef WINNING_GDB
2757 const char *filename = DECL_SOURCE_FILE (decl);
2759 dbxout_source_file (asmfile, filename);
2760 #endif
2762 /* Initialize variables used to communicate each symbol's debug
2763 information to dbxout_finish_symbol with zeroes. */
2765 /* Cast avoids warning in old compilers. */
2766 current_sym_code = (STAB_CODE_TYPE) 0;
2767 current_sym_value = 0;
2768 current_sym_addr = 0;
2771 static void
2772 dbxout_finish_symbol (tree sym)
2774 #ifdef DBX_FINISH_SYMBOL
2775 DBX_FINISH_SYMBOL (sym);
2776 #else
2777 int line = 0;
2778 if (use_gnu_debug_info_extensions && sym != 0)
2779 line = DECL_SOURCE_LINE (sym);
2781 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2782 if (current_sym_addr)
2783 output_addr_const (asmfile, current_sym_addr);
2784 else
2785 fprintf (asmfile, "%d", current_sym_value);
2786 putc ('\n', asmfile);
2787 #endif
2790 /* Output definitions of all the decls in a chain. Return nonzero if
2791 anything was output */
2794 dbxout_syms (tree syms)
2796 int result = 0;
2797 while (syms)
2799 result += dbxout_symbol (syms, 1);
2800 syms = TREE_CHAIN (syms);
2802 return result;
2805 /* The following two functions output definitions of function parameters.
2806 Each parameter gets a definition locating it in the parameter list.
2807 Each parameter that is a register variable gets a second definition
2808 locating it in the register.
2810 Printing or argument lists in gdb uses the definitions that
2811 locate in the parameter list. But reference to the variable in
2812 expressions uses preferentially the definition as a register. */
2814 /* Output definitions, referring to storage in the parmlist,
2815 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2817 void
2818 dbxout_parms (tree parms)
2820 ++debug_nesting;
2822 emit_pending_bincls_if_required ();
2824 for (; parms; parms = TREE_CHAIN (parms))
2825 if (DECL_NAME (parms)
2826 && TREE_TYPE (parms) != error_mark_node
2827 && DECL_RTL_SET_P (parms)
2828 && DECL_INCOMING_RTL (parms))
2830 dbxout_prepare_symbol (parms);
2832 /* Perform any necessary register eliminations on the parameter's rtl,
2833 so that the debugging output will be accurate. */
2834 DECL_INCOMING_RTL (parms)
2835 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2836 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2837 #ifdef LEAF_REG_REMAP
2838 if (current_function_uses_only_leaf_regs)
2840 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2841 leaf_renumber_regs_insn (DECL_RTL (parms));
2843 #endif
2845 if (PARM_PASSED_IN_MEMORY (parms))
2847 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2849 /* ??? Here we assume that the parm address is indexed
2850 off the frame pointer or arg pointer.
2851 If that is not true, we produce meaningless results,
2852 but do not crash. */
2853 if (GET_CODE (addr) == PLUS
2854 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2855 current_sym_value = INTVAL (XEXP (addr, 1));
2856 else
2857 current_sym_value = 0;
2859 current_sym_code = N_PSYM;
2860 current_sym_addr = 0;
2862 FORCE_TEXT;
2863 if (DECL_NAME (parms))
2865 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2867 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2868 IDENTIFIER_POINTER (DECL_NAME (parms)),
2869 DBX_MEMPARM_STABS_LETTER);
2871 else
2873 current_sym_nchars = 8;
2874 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2875 DBX_MEMPARM_STABS_LETTER);
2878 /* It is quite tempting to use:
2880 dbxout_type (TREE_TYPE (parms), 0);
2882 as the next statement, rather than using DECL_ARG_TYPE(), so
2883 that gcc reports the actual type of the parameter, rather
2884 than the promoted type. This certainly makes GDB's life
2885 easier, at least for some ports. The change is a bad idea
2886 however, since GDB expects to be able access the type without
2887 performing any conversions. So for example, if we were
2888 passing a float to an unprototyped function, gcc will store a
2889 double on the stack, but if we emit a stab saying the type is a
2890 float, then gdb will only read in a single value, and this will
2891 produce an erroneous value. */
2892 dbxout_type (DECL_ARG_TYPE (parms), 0);
2893 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2894 dbxout_finish_symbol (parms);
2896 else if (REG_P (DECL_RTL (parms)))
2898 rtx best_rtl;
2899 char regparm_letter;
2900 tree parm_type;
2901 /* Parm passed in registers and lives in registers or nowhere. */
2903 current_sym_code = DBX_REGPARM_STABS_CODE;
2904 regparm_letter = DBX_REGPARM_STABS_LETTER;
2905 current_sym_addr = 0;
2907 /* If parm lives in a register, use that register;
2908 pretend the parm was passed there. It would be more consistent
2909 to describe the register where the parm was passed,
2910 but in practice that register usually holds something else.
2912 If we use DECL_RTL, then we must use the declared type of
2913 the variable, not the type that it arrived in. */
2914 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2916 best_rtl = DECL_RTL (parms);
2917 parm_type = TREE_TYPE (parms);
2919 /* If the parm lives nowhere, use the register where it was
2920 passed. It is also better to use the declared type here. */
2921 else
2923 best_rtl = DECL_INCOMING_RTL (parms);
2924 parm_type = TREE_TYPE (parms);
2926 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2928 FORCE_TEXT;
2929 if (DECL_NAME (parms))
2931 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2932 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2933 IDENTIFIER_POINTER (DECL_NAME (parms)),
2934 regparm_letter);
2936 else
2938 current_sym_nchars = 8;
2939 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2940 regparm_letter);
2943 dbxout_type (parm_type, 0);
2944 dbxout_finish_symbol (parms);
2946 else if (MEM_P (DECL_RTL (parms))
2947 && REG_P (XEXP (DECL_RTL (parms), 0))
2948 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2949 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2950 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2951 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2952 #endif
2955 /* Parm was passed via invisible reference.
2956 That is, its address was passed in a register.
2957 Output it as if it lived in that register.
2958 The debugger will know from the type
2959 that it was actually passed by invisible reference. */
2961 char regparm_letter;
2962 /* Parm passed in registers and lives in registers or nowhere. */
2964 current_sym_code = DBX_REGPARM_STABS_CODE;
2965 if (use_gnu_debug_info_extensions)
2966 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2967 else
2968 regparm_letter = DBX_REGPARM_STABS_LETTER;
2970 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2971 If it is an unallocated pseudo-reg, then use the register where
2972 it was passed instead. */
2973 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2974 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2975 else
2976 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2978 current_sym_addr = 0;
2980 FORCE_TEXT;
2981 if (DECL_NAME (parms))
2983 current_sym_nchars
2984 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2986 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2987 IDENTIFIER_POINTER (DECL_NAME (parms)),
2988 regparm_letter);
2990 else
2992 current_sym_nchars = 8;
2993 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2994 regparm_letter);
2997 dbxout_type (TREE_TYPE (parms), 0);
2998 dbxout_finish_symbol (parms);
3000 else if (MEM_P (DECL_RTL (parms))
3001 && MEM_P (XEXP (DECL_RTL (parms), 0)))
3003 /* Parm was passed via invisible reference, with the reference
3004 living on the stack. DECL_RTL looks like
3005 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3006 could look like (MEM (MEM (REG))). */
3007 const char *const decl_name = (DECL_NAME (parms)
3008 ? IDENTIFIER_POINTER (DECL_NAME (parms))
3009 : "(anon)");
3010 if (REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3011 current_sym_value = 0;
3012 else
3013 current_sym_value
3014 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3015 current_sym_addr = 0;
3016 current_sym_code = N_PSYM;
3018 FORCE_TEXT;
3019 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
3021 current_sym_value
3022 = DEBUGGER_ARG_OFFSET (current_sym_value,
3023 XEXP (XEXP (DECL_RTL (parms), 0), 0));
3024 dbxout_type (TREE_TYPE (parms), 0);
3025 dbxout_finish_symbol (parms);
3027 else if (MEM_P (DECL_RTL (parms))
3028 && XEXP (DECL_RTL (parms), 0) != const0_rtx
3029 /* ??? A constant address for a parm can happen
3030 when the reg it lives in is equiv to a constant in memory.
3031 Should make this not happen, after 2.4. */
3032 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3034 /* Parm was passed in registers but lives on the stack. */
3036 current_sym_code = N_PSYM;
3037 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3038 in which case we want the value of that CONST_INT,
3039 or (MEM (REG ...)),
3040 in which case we use a value of zero. */
3041 if (REG_P (XEXP (DECL_RTL (parms), 0)))
3042 current_sym_value = 0;
3043 else
3044 current_sym_value
3045 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3047 current_sym_addr = 0;
3049 /* Make a big endian correction if the mode of the type of the
3050 parameter is not the same as the mode of the rtl. */
3051 if (BYTES_BIG_ENDIAN
3052 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3053 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3055 current_sym_value +=
3056 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3057 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
3060 FORCE_TEXT;
3061 if (DECL_NAME (parms))
3063 current_sym_nchars
3064 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
3066 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
3067 IDENTIFIER_POINTER (DECL_NAME (parms)),
3068 DBX_MEMPARM_STABS_LETTER);
3070 else
3072 current_sym_nchars = 8;
3073 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
3074 DBX_MEMPARM_STABS_LETTER);
3077 current_sym_value
3078 = DEBUGGER_ARG_OFFSET (current_sym_value,
3079 XEXP (DECL_RTL (parms), 0));
3080 dbxout_type (TREE_TYPE (parms), 0);
3081 dbxout_finish_symbol (parms);
3084 DBXOUT_DECR_NESTING;
3087 /* Output definitions for the places where parms live during the function,
3088 when different from where they were passed, when the parms were passed
3089 in memory.
3091 It is not useful to do this for parms passed in registers
3092 that live during the function in different registers, because it is
3093 impossible to look in the passed register for the passed value,
3094 so we use the within-the-function register to begin with.
3096 PARMS is a chain of PARM_DECL nodes. */
3098 void
3099 dbxout_reg_parms (tree parms)
3101 ++debug_nesting;
3103 for (; parms; parms = TREE_CHAIN (parms))
3104 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3106 dbxout_prepare_symbol (parms);
3108 /* Report parms that live in registers during the function
3109 but were passed in memory. */
3110 if (REG_P (DECL_RTL (parms))
3111 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3112 dbxout_symbol_location (parms, TREE_TYPE (parms),
3113 0, DECL_RTL (parms));
3114 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3115 dbxout_symbol_location (parms, TREE_TYPE (parms),
3116 0, DECL_RTL (parms));
3117 /* Report parms that live in memory but not where they were passed. */
3118 else if (MEM_P (DECL_RTL (parms))
3119 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3120 dbxout_symbol_location (parms, TREE_TYPE (parms),
3121 0, DECL_RTL (parms));
3123 DBXOUT_DECR_NESTING;
3126 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3127 output definitions of those names, in raw form */
3129 static void
3130 dbxout_args (tree args)
3132 while (args)
3134 putc (',', asmfile);
3135 dbxout_type (TREE_VALUE (args), 0);
3136 CHARS (1);
3137 args = TREE_CHAIN (args);
3141 /* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL.
3142 BEGIN_LABEL is the name of the beginning of the function, which may
3143 be required. */
3144 static void
3145 dbx_output_lbrac (const char *label,
3146 const char *begin_label ATTRIBUTE_UNUSED)
3148 #ifdef DBX_OUTPUT_LBRAC
3149 DBX_OUTPUT_LBRAC (asmfile, label);
3150 #else
3151 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
3152 assemble_name (asmfile, label);
3153 #if DBX_BLOCKS_FUNCTION_RELATIVE
3154 putc ('-', asmfile);
3155 assemble_name (asmfile, begin_label);
3156 #endif
3157 fprintf (asmfile, "\n");
3158 #endif
3161 /* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL.
3162 BEGIN_LABEL is the name of the beginning of the function, which may
3163 be required. */
3164 static void
3165 dbx_output_rbrac (const char *label,
3166 const char *begin_label ATTRIBUTE_UNUSED)
3168 #ifdef DBX_OUTPUT_RBRAC
3169 DBX_OUTPUT_RBRAC (asmfile, label);
3170 #else
3171 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3172 assemble_name (asmfile, label);
3173 #if DBX_BLOCKS_FUNCTION_RELATIVE
3174 putc ('-', asmfile);
3175 assemble_name (asmfile, begin_label);
3176 #endif
3177 fprintf (asmfile, "\n");
3178 #endif
3181 /* Output everything about a symbol block (a BLOCK node
3182 that represents a scope level),
3183 including recursive output of contained blocks.
3185 BLOCK is the BLOCK node.
3186 DEPTH is its depth within containing symbol blocks.
3187 ARGS is usually zero; but for the outermost block of the
3188 body of a function, it is a chain of PARM_DECLs for the function parameters.
3189 We output definitions of all the register parms
3190 as if they were local variables of that block.
3192 If -g1 was used, we count blocks just the same, but output nothing
3193 except for the outermost block.
3195 Actually, BLOCK may be several blocks chained together.
3196 We handle them all in sequence. */
3198 static void
3199 dbxout_block (tree block, int depth, tree args)
3201 const char *begin_label;
3202 if (current_function_func_begin_label != NULL)
3203 begin_label = current_function_func_begin_label;
3204 else
3205 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3207 while (block)
3209 /* Ignore blocks never expanded or otherwise marked as real. */
3210 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3212 int did_output;
3213 int blocknum = BLOCK_NUMBER (block);
3215 /* In dbx format, the syms of a block come before the N_LBRAC.
3216 If nothing is output, we don't need the N_LBRAC, either. */
3217 did_output = 0;
3218 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3219 did_output = dbxout_syms (BLOCK_VARS (block));
3220 if (args)
3221 dbxout_reg_parms (args);
3223 /* Now output an N_LBRAC symbol to represent the beginning of
3224 the block. Use the block's tree-walk order to generate
3225 the assembler symbols LBBn and LBEn
3226 that final will define around the code in this block. */
3227 if (did_output)
3229 char buf[20];
3230 const char *scope_start;
3232 if (depth == 0)
3233 /* The outermost block doesn't get LBB labels; use
3234 the function symbol. */
3235 scope_start = begin_label;
3236 else
3238 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3239 scope_start = buf;
3242 if (BLOCK_HANDLER_BLOCK (block))
3244 /* A catch block. Must precede N_LBRAC. */
3245 tree decl = BLOCK_VARS (block);
3246 while (decl)
3248 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
3249 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
3250 assemble_name (asmfile, scope_start);
3251 fprintf (asmfile, "\n");
3252 decl = TREE_CHAIN (decl);
3255 dbx_output_lbrac (scope_start, begin_label);
3258 /* Output the subblocks. */
3259 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3261 /* Refer to the marker for the end of the block. */
3262 if (did_output)
3264 char buf[100];
3265 if (depth == 0)
3266 /* The outermost block doesn't get LBE labels;
3267 use the "scope" label which will be emitted
3268 by dbxout_function_end. */
3269 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3270 else
3271 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3273 dbx_output_rbrac (buf, begin_label);
3276 block = BLOCK_CHAIN (block);
3280 /* Output the information about a function and its arguments and result.
3281 Usually this follows the function's code,
3282 but on some systems, it comes before. */
3284 #if defined (DBX_DEBUGGING_INFO)
3285 static void
3286 dbxout_begin_function (tree decl)
3288 int saved_tree_used1 = TREE_USED (decl);
3289 TREE_USED (decl) = 1;
3290 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3292 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3293 TREE_USED (DECL_RESULT (decl)) = 1;
3294 dbxout_symbol (decl, 0);
3295 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3297 else
3298 dbxout_symbol (decl, 0);
3299 TREE_USED (decl) = saved_tree_used1;
3301 dbxout_parms (DECL_ARGUMENTS (decl));
3302 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3303 dbxout_symbol (DECL_RESULT (decl), 1);
3305 #endif /* DBX_DEBUGGING_INFO */
3307 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3309 #include "gt-dbxout.h"