(thumb_jump): Reduce the backward branch range, and increase the forward branch
[official-gcc.git] / gcc / dbxout.c
blob99d2767d962270c5d6dcee536ecbdc94c4c73bed
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 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
151 /* Structure recording information about a C data type.
152 The status element says whether we have yet output
153 the definition of the type. TYPE_XREF says we have
154 output it as a cross-reference only.
155 The file_number and type_number elements are used if DBX_USE_BINCL
156 is defined. */
158 struct typeinfo GTY(())
160 enum typestatus status;
161 int file_number;
162 int type_number;
165 /* Vector recording information about C data types.
166 When we first notice a data type (a tree node),
167 we assign it a number using next_type_number.
168 That is its index in this vector. */
170 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
172 /* Number of elements of space allocated in `typevec'. */
174 static GTY(()) int typevec_len;
176 /* In dbx output, each type gets a unique number.
177 This is the number for the next type output.
178 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
180 static GTY(()) int next_type_number;
182 /* The C front end may call dbxout_symbol before dbxout_init runs.
183 We save all such decls in this list and output them when we get
184 to dbxout_init. */
186 static GTY(()) tree preinit_symbols;
188 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
190 /* When using N_BINCL in dbx output, each type number is actually a
191 pair of the file number and the type number within the file.
192 This is a stack of input files. */
194 struct dbx_file
196 struct dbx_file *next;
197 int file_number;
198 int next_type_number;
199 enum binclstatus bincl_status; /* Keep track of lazy bincl. */
200 const char *pending_bincl_name; /* Name of bincl. */
201 struct dbx_file *prev; /* Chain to traverse all pending bincls. */
204 /* This is the top of the stack.
206 This is not saved for PCH, because restoring a PCH should not change it.
207 next_file_number does have to be saved, because the PCH may use some
208 file numbers; however, just before restoring a PCH, next_file_number
209 should always be 0 because we should not have needed any file numbers
210 yet. */
212 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
213 && defined (DBX_USE_BINCL)
214 static struct dbx_file *current_file;
215 #endif
217 /* This is the next file number to use. */
219 static GTY(()) int next_file_number;
221 /* A counter for dbxout_function_end. */
223 static GTY(()) int scope_labelno;
225 /* A counter for dbxout_source_line. */
227 static GTY(()) int dbxout_source_line_counter;
229 /* Nonzero if we have actually used any of the GDB extensions
230 to the debugging format. The idea is that we use them for the
231 first time only if there's a strong reason, but once we have done that,
232 we use them whenever convenient. */
234 static GTY(()) int have_used_extensions = 0;
236 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
237 for the N_SO filename stabs label. */
239 static GTY(()) int source_label_number = 1;
241 /* Last source file name mentioned in a NOTE insn. */
243 static GTY(()) const char *lastfile;
245 /* Used by PCH machinery to detect if 'lastfile' should be reset to
246 base_input_file. */
247 static GTY(()) int lastfile_is_base;
249 /* Typical USG systems don't have stab.h, and they also have
250 no use for DBX-format debugging info. */
252 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
254 #ifdef DBX_USE_BINCL
255 /* If zero then there is no pending BINCL. */
256 static int pending_bincls = 0;
257 #endif
259 /* The original input file name. */
260 static const char *base_input_file;
262 /* Current working directory. */
264 static const char *cwd;
266 #ifdef DEBUG_SYMS_TEXT
267 #define FORCE_TEXT function_section (current_function_decl);
268 #else
269 #define FORCE_TEXT
270 #endif
272 #include "gstab.h"
274 #define STAB_CODE_TYPE enum __stab_debug_code
276 /* 1 if PARM is passed to this function in memory. */
278 #define PARM_PASSED_IN_MEMORY(PARM) \
279 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
281 /* A C expression for the integer offset value of an automatic variable
282 (N_LSYM) having address X (an RTX). */
283 #ifndef DEBUGGER_AUTO_OFFSET
284 #define DEBUGGER_AUTO_OFFSET(X) \
285 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
286 #endif
288 /* A C expression for the integer offset value of an argument (N_PSYM)
289 having address X (an RTX). The nominal offset is OFFSET. */
290 #ifndef DEBUGGER_ARG_OFFSET
291 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
292 #endif
294 /* Stream for writing to assembler file. */
296 static FILE *asmfile;
298 /* These variables are for dbxout_symbol to communicate to
299 dbxout_finish_symbol.
300 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
301 current_sym_value and current_sym_addr are two ways to address the
302 value to store in the symtab entry.
303 current_sym_addr if nonzero represents the value as an rtx.
304 If that is zero, current_sym_value is used. This is used
305 when the value is an offset (such as for auto variables,
306 register variables and parms). */
308 static STAB_CODE_TYPE current_sym_code;
309 static int current_sym_value;
310 static rtx current_sym_addr;
312 /* Number of chars of symbol-description generated so far for the
313 current symbol. Used by CHARS and CONTIN. */
315 static int current_sym_nchars;
317 /* Report having output N chars of the current symbol-description. */
319 #define CHARS(N) (current_sym_nchars += (N))
321 /* Break the current symbol-description, generating a continuation,
322 if it has become long. */
324 #ifndef DBX_CONTIN_LENGTH
325 #define DBX_CONTIN_LENGTH 80
326 #endif
328 #if DBX_CONTIN_LENGTH > 0
329 #define CONTIN \
330 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
331 #else
332 #define CONTIN do { } while (0)
333 #endif
335 #ifdef DBX_USE_BINCL
336 static void emit_bincl_stab (const char *c);
337 static void emit_pending_bincls (void);
338 #endif
339 static inline void emit_pending_bincls_if_required (void);
341 static void dbxout_init (const char *);
342 static void dbxout_finish (const char *);
343 static void dbxout_start_source_file (unsigned, const char *);
344 static void dbxout_end_source_file (unsigned);
345 static void dbxout_typedefs (tree);
346 static void dbxout_type_index (tree);
347 #if DBX_CONTIN_LENGTH > 0
348 static void dbxout_continue (void);
349 #endif
350 static void dbxout_args (tree);
351 static void dbxout_type_fields (tree);
352 static void dbxout_type_method_1 (tree, const char *);
353 static void dbxout_type_methods (tree);
354 static void dbxout_range_type (tree);
355 static void dbxout_type (tree, int);
356 static bool print_int_cst_bounds_in_octal_p (tree);
357 static void print_int_cst_octal (tree);
358 static void print_octal (unsigned HOST_WIDE_INT, int);
359 static void print_wide_int (HOST_WIDE_INT);
360 static void dbxout_type_name (tree);
361 static void dbxout_class_name_qualifiers (tree);
362 static int dbxout_symbol_location (tree, tree, const char *, rtx);
363 static void dbxout_symbol_name (tree, const char *, int);
364 static void dbxout_prepare_symbol (tree);
365 static void dbxout_finish_symbol (tree);
366 static void dbxout_block (tree, int, tree);
367 static void dbxout_global_decl (tree);
368 static void dbxout_type_decl (tree, int);
369 static void dbxout_handle_pch (unsigned);
371 /* The debug hooks structure. */
372 #if defined (DBX_DEBUGGING_INFO)
374 static void dbxout_source_line (unsigned int, const char *);
375 static void dbxout_source_file (FILE *, const char *);
376 static void dbxout_function_end (void);
377 static void dbxout_begin_function (tree);
378 static void dbxout_begin_block (unsigned, unsigned);
379 static void dbxout_end_block (unsigned, unsigned);
380 static void dbxout_function_decl (tree);
382 const struct gcc_debug_hooks dbx_debug_hooks =
384 dbxout_init,
385 dbxout_finish,
386 debug_nothing_int_charstar,
387 debug_nothing_int_charstar,
388 dbxout_start_source_file,
389 dbxout_end_source_file,
390 dbxout_begin_block,
391 dbxout_end_block,
392 debug_true_tree, /* ignore_block */
393 dbxout_source_line, /* source_line */
394 dbxout_source_line, /* begin_prologue: just output
395 line info */
396 debug_nothing_int_charstar, /* end_prologue */
397 debug_nothing_int_charstar, /* end_epilogue */
398 #ifdef DBX_FUNCTION_FIRST
399 dbxout_begin_function,
400 #else
401 debug_nothing_tree, /* begin_function */
402 #endif
403 debug_nothing_int, /* end_function */
404 dbxout_function_decl,
405 dbxout_global_decl, /* global_decl */
406 dbxout_type_decl, /* type_decl */
407 debug_nothing_tree_tree, /* imported_module_or_decl */
408 debug_nothing_tree, /* deferred_inline_function */
409 debug_nothing_tree, /* outlining_inline_function */
410 debug_nothing_rtx, /* label */
411 dbxout_handle_pch, /* handle_pch */
412 debug_nothing_rtx /* var_location */
414 #endif /* DBX_DEBUGGING_INFO */
416 #if defined (XCOFF_DEBUGGING_INFO)
417 const struct gcc_debug_hooks xcoff_debug_hooks =
419 dbxout_init,
420 dbxout_finish,
421 debug_nothing_int_charstar,
422 debug_nothing_int_charstar,
423 dbxout_start_source_file,
424 dbxout_end_source_file,
425 xcoffout_begin_block,
426 xcoffout_end_block,
427 debug_true_tree, /* ignore_block */
428 xcoffout_source_line,
429 xcoffout_begin_prologue, /* begin_prologue */
430 debug_nothing_int_charstar, /* end_prologue */
431 xcoffout_end_epilogue,
432 debug_nothing_tree, /* begin_function */
433 xcoffout_end_function,
434 debug_nothing_tree, /* function_decl */
435 dbxout_global_decl, /* global_decl */
436 dbxout_type_decl, /* type_decl */
437 debug_nothing_tree_tree, /* imported_module_or_decl */
438 debug_nothing_tree, /* deferred_inline_function */
439 debug_nothing_tree, /* outlining_inline_function */
440 debug_nothing_rtx, /* label */
441 dbxout_handle_pch, /* handle_pch */
442 debug_nothing_rtx /* var_location */
444 #endif /* XCOFF_DEBUGGING_INFO */
446 #if defined (DBX_DEBUGGING_INFO)
447 static void
448 dbxout_function_end (void)
450 char lscope_label_name[100];
451 /* Convert Ltext into the appropriate format for local labels in case
452 the system doesn't insert underscores in front of user generated
453 labels. */
454 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
455 targetm.asm_out.internal_label (asmfile, "Lscope", scope_labelno);
456 scope_labelno++;
458 /* By convention, GCC will mark the end of a function with an N_FUN
459 symbol and an empty string. */
460 #ifdef DBX_OUTPUT_NFUN
461 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
462 #else
463 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
464 assemble_name (asmfile, lscope_label_name);
465 putc ('-', asmfile);
466 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
467 fprintf (asmfile, "\n");
468 #endif
470 #endif /* DBX_DEBUGGING_INFO */
472 /* At the beginning of compilation, start writing the symbol table.
473 Initialize `typevec' and output the standard data types of C. */
475 static void
476 dbxout_init (const char *input_file_name)
478 char ltext_label_name[100];
479 tree syms = lang_hooks.decls.getdecls ();
481 asmfile = asm_out_file;
483 typevec_len = 100;
484 typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
486 /* Convert Ltext into the appropriate format for local labels in case
487 the system doesn't insert underscores in front of user generated
488 labels. */
489 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
491 /* Put the current working directory in an N_SO symbol. */
492 if (use_gnu_debug_info_extensions)
494 if (!cwd && (cwd = get_src_pwd ())
495 && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
496 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
497 if (cwd)
499 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
500 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
501 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
502 fprintf (asmfile, "%s", ASM_STABS_OP);
503 output_quoted_string (asmfile, cwd);
504 fprintf (asmfile, ",%d,0,0,", N_SO);
505 assemble_name (asmfile, ltext_label_name);
506 fputc ('\n', asmfile);
507 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
511 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
512 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
513 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
514 /* We include outputting `Ltext:' here,
515 because that gives you a way to override it. */
516 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
517 fprintf (asmfile, "%s", ASM_STABS_OP);
518 output_quoted_string (asmfile, input_file_name);
519 fprintf (asmfile, ",%d,0,0,", N_SO);
520 assemble_name (asmfile, ltext_label_name);
521 fputc ('\n', asmfile);
522 text_section ();
523 targetm.asm_out.internal_label (asmfile, "Ltext", 0);
524 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
526 #ifdef DBX_OUTPUT_GCC_MARKER
527 DBX_OUTPUT_GCC_MARKER (asmfile);
528 #else
529 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
530 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
531 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
532 #endif
534 base_input_file = lastfile = input_file_name;
536 next_type_number = 1;
538 #ifdef DBX_USE_BINCL
539 current_file = xmalloc (sizeof *current_file);
540 current_file->next = NULL;
541 current_file->file_number = 0;
542 current_file->next_type_number = 1;
543 next_file_number = 1;
544 current_file->prev = NULL;
545 current_file->bincl_status = BINCL_NOT_REQUIRED;
546 current_file->pending_bincl_name = NULL;
547 #endif
549 /* Get all permanent types that have typedef names, and output them
550 all, except for those already output. Some language front ends
551 put these declarations in the top-level scope; some do not;
552 the latter are responsible for calling debug_hooks->type_decl from
553 their record_builtin_type function. */
554 dbxout_typedefs (syms);
556 if (preinit_symbols)
558 tree t;
559 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
560 dbxout_symbol (TREE_VALUE (t), 0);
561 preinit_symbols = 0;
565 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
567 static void
568 dbxout_typedefs (tree syms)
570 for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
572 if (TREE_CODE (syms) == TYPE_DECL)
574 tree type = TREE_TYPE (syms);
575 if (TYPE_NAME (type)
576 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
577 && COMPLETE_OR_VOID_TYPE_P (type)
578 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
579 dbxout_symbol (TYPE_NAME (type), 0);
584 #ifdef DBX_USE_BINCL
585 /* Emit BINCL stab using given name. */
586 static void
587 emit_bincl_stab (const char *name)
589 fprintf (asmfile, "%s", ASM_STABS_OP);
590 output_quoted_string (asmfile, name);
591 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
594 /* If there are pending bincls then it is time to emit all of them. */
596 static inline void
597 emit_pending_bincls_if_required (void)
599 if (pending_bincls)
600 emit_pending_bincls ();
603 /* Emit all pending bincls. */
605 static void
606 emit_pending_bincls (void)
608 struct dbx_file *f = current_file;
610 /* Find first pending bincl. */
611 while (f->bincl_status == BINCL_PENDING)
612 f = f->next;
614 /* Now emit all bincls. */
615 f = f->prev;
617 while (f)
619 if (f->bincl_status == BINCL_PENDING)
621 emit_bincl_stab (f->pending_bincl_name);
623 /* Update file number and status. */
624 f->file_number = next_file_number++;
625 f->bincl_status = BINCL_PROCESSED;
627 if (f == current_file)
628 break;
629 f = f->prev;
632 /* All pending bincls have been emitted. */
633 pending_bincls = 0;
636 #else
638 static inline void
639 emit_pending_bincls_if_required (void) {}
640 #endif
642 /* Change to reading from a new source file. Generate a N_BINCL stab. */
644 static void
645 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
646 const char *filename ATTRIBUTE_UNUSED)
648 #ifdef DBX_USE_BINCL
649 struct dbx_file *n = xmalloc (sizeof *n);
651 n->next = current_file;
652 n->next_type_number = 1;
653 /* Do not assign file number now.
654 Delay it until we actually emit BINCL. */
655 n->file_number = 0;
656 n->prev = NULL;
657 current_file->prev = n;
658 n->bincl_status = BINCL_PENDING;
659 n->pending_bincl_name = filename;
660 pending_bincls = 1;
661 current_file = n;
662 #endif
665 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
667 static void
668 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
670 #ifdef DBX_USE_BINCL
671 /* Emit EINCL stab only if BINCL is not pending. */
672 if (current_file->bincl_status == BINCL_PROCESSED)
673 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
674 current_file->bincl_status = BINCL_NOT_REQUIRED;
675 current_file = current_file->next;
676 #endif
679 /* Handle a few odd cases that occur when trying to make PCH files work. */
681 static void
682 dbxout_handle_pch (unsigned at_end)
684 if (! at_end)
686 /* When using the PCH, this file will be included, so we need to output
687 a BINCL. */
688 dbxout_start_source_file (0, lastfile);
690 /* The base file when using the PCH won't be the same as
691 the base file when it's being generated. */
692 lastfile = NULL;
694 else
696 /* ... and an EINCL. */
697 dbxout_end_source_file (0);
699 /* Deal with cases where 'lastfile' was never actually changed. */
700 lastfile_is_base = lastfile == NULL;
704 #if defined (DBX_DEBUGGING_INFO)
705 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
707 static void
708 dbxout_source_file (FILE *file, const char *filename)
710 if (lastfile == 0 && lastfile_is_base)
712 lastfile = base_input_file;
713 lastfile_is_base = 0;
716 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
718 char ltext_label_name[100];
720 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
721 source_label_number);
722 fprintf (file, "%s", ASM_STABS_OP);
723 output_quoted_string (file, filename);
724 fprintf (asmfile, ",%d,0,0,", N_SOL);
725 assemble_name (asmfile, ltext_label_name);
726 fputc ('\n', asmfile);
727 if (current_function_decl != NULL_TREE
728 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
729 ; /* Don't change section amid function. */
730 else
731 text_section ();
732 targetm.asm_out.internal_label (file, "Ltext", source_label_number);
733 source_label_number++;
734 lastfile = filename;
738 /* Output a line number symbol entry for source file FILENAME and line
739 number LINENO. */
741 static void
742 dbxout_source_line (unsigned int lineno, const char *filename)
744 dbxout_source_file (asmfile, filename);
746 #ifdef ASM_OUTPUT_SOURCE_LINE
747 dbxout_source_line_counter += 1;
748 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno, dbxout_source_line_counter);
749 #else
750 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
751 #endif
754 /* Describe the beginning of an internal block within a function. */
756 static void
757 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
759 emit_pending_bincls_if_required ();
760 targetm.asm_out.internal_label (asmfile, "LBB", n);
763 /* Describe the end line-number of an internal block within a function. */
765 static void
766 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
768 emit_pending_bincls_if_required ();
769 targetm.asm_out.internal_label (asmfile, "LBE", n);
772 /* Output dbx data for a function definition.
773 This includes a definition of the function name itself (a symbol),
774 definitions of the parameters (locating them in the parameter list)
775 and then output the block that makes up the function's body
776 (including all the auto variables of the function). */
778 static void
779 dbxout_function_decl (tree decl)
781 emit_pending_bincls_if_required ();
782 #ifndef DBX_FUNCTION_FIRST
783 dbxout_begin_function (decl);
784 #endif
785 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
786 #ifdef DBX_OUTPUT_FUNCTION_END
787 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
788 #endif
789 if (use_gnu_debug_info_extensions
790 #if defined(NO_DBX_FUNCTION_END)
791 && ! NO_DBX_FUNCTION_END
792 #endif
793 && targetm.have_named_sections)
794 dbxout_function_end ();
797 #endif /* DBX_DEBUGGING_INFO */
799 /* Debug information for a global DECL. Called from toplev.c after
800 compilation proper has finished. */
801 static void
802 dbxout_global_decl (tree decl)
804 if (TREE_CODE (decl) == VAR_DECL
805 && ! DECL_EXTERNAL (decl)
806 && DECL_RTL_SET_P (decl)) /* Not necessary? */
808 int saved_tree_used = TREE_USED (decl);
809 TREE_USED (decl) = 1;
810 dbxout_symbol (decl, 0);
811 TREE_USED (decl) = saved_tree_used;
815 /* This is just a function-type adapter; dbxout_symbol does exactly
816 what we want but returns an int. */
817 static void
818 dbxout_type_decl (tree decl, int local)
820 dbxout_symbol (decl, local);
823 /* At the end of compilation, finish writing the symbol table.
824 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
825 to do nothing. */
827 static void
828 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
830 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
831 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
832 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
834 debug_free_queue ();
837 /* Output the index of a type. */
839 static void
840 dbxout_type_index (tree type)
842 #ifndef DBX_USE_BINCL
843 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
844 CHARS (3);
845 #else
846 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
847 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
848 CHARS (9);
849 #endif
852 #if DBX_CONTIN_LENGTH > 0
853 /* Continue a symbol-description that gets too big.
854 End one symbol table entry with a double-backslash
855 and start a new one, eventually producing something like
856 .stabs "start......\\",code,0,value
857 .stabs "...rest",code,0,value */
859 static void
860 dbxout_continue (void)
862 emit_pending_bincls_if_required ();
863 #ifdef DBX_CONTIN_CHAR
864 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
865 #else
866 fprintf (asmfile, "\\\\");
867 #endif
868 dbxout_finish_symbol (NULL_TREE);
869 fprintf (asmfile, "%s\"", ASM_STABS_OP);
870 current_sym_nchars = 0;
872 #endif /* DBX_CONTIN_LENGTH > 0 */
874 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
875 This must be a separate function because anonymous unions require
876 recursive calls. */
878 static void
879 dbxout_type_fields (tree type)
881 tree tem;
883 /* Output the name, type, position (in bits), size (in bits) of each
884 field that we can support. */
885 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
887 /* If one of the nodes is an error_mark or its type is then
888 return early. */
889 if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
890 return;
892 /* Omit here local type decls until we know how to support them. */
893 if (TREE_CODE (tem) == TYPE_DECL
894 /* Omit fields whose position or size are variable or too large to
895 represent. */
896 || (TREE_CODE (tem) == FIELD_DECL
897 && (! host_integerp (bit_position (tem), 0)
898 || ! DECL_SIZE (tem)
899 || ! host_integerp (DECL_SIZE (tem), 1)))
900 /* Omit here the nameless fields that are used to skip bits. */
901 || DECL_IGNORED_P (tem))
902 continue;
904 else if (TREE_CODE (tem) != CONST_DECL)
906 /* Continue the line if necessary,
907 but not before the first field. */
908 if (tem != TYPE_FIELDS (type))
909 CONTIN;
911 if (DECL_NAME (tem))
913 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
914 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
916 else
918 fprintf (asmfile, ":");
919 CHARS (1);
922 if (use_gnu_debug_info_extensions
923 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
924 || TREE_CODE (tem) != FIELD_DECL))
926 have_used_extensions = 1;
927 putc ('/', asmfile);
928 putc ((TREE_PRIVATE (tem) ? '0'
929 : TREE_PROTECTED (tem) ? '1' : '2'),
930 asmfile);
931 CHARS (2);
934 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
935 && DECL_BIT_FIELD_TYPE (tem))
936 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
938 if (TREE_CODE (tem) == VAR_DECL)
940 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
942 tree name = DECL_ASSEMBLER_NAME (tem);
944 have_used_extensions = 1;
945 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
946 CHARS (IDENTIFIER_LENGTH (name) + 2);
948 else
950 /* If TEM is non-static, GDB won't understand it. */
951 fprintf (asmfile, ",0,0;");
952 CHARS (5);
955 else
957 putc (',', asmfile);
958 print_wide_int (int_bit_position (tem));
959 putc (',', asmfile);
960 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
961 putc (';', asmfile);
962 CHARS (3);
968 /* Subroutine of `dbxout_type_methods'. Output debug info about the
969 method described DECL. DEBUG_NAME is an encoding of the method's
970 type signature. ??? We may be able to do without DEBUG_NAME altogether
971 now. */
973 static void
974 dbxout_type_method_1 (tree decl, const char *debug_name)
976 char c1 = 'A', c2;
978 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
979 c2 = '?';
980 else /* it's a METHOD_TYPE. */
982 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
983 /* A for normal functions.
984 B for `const' member functions.
985 C for `volatile' member functions.
986 D for `const volatile' member functions. */
987 if (TYPE_READONLY (TREE_TYPE (firstarg)))
988 c1 += 1;
989 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
990 c1 += 2;
992 if (DECL_VINDEX (decl))
993 c2 = '*';
994 else
995 c2 = '.';
998 fprintf (asmfile, ":%s;%c%c%c", debug_name,
999 TREE_PRIVATE (decl) ? '0'
1000 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
1001 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
1002 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1004 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1006 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
1007 putc (';', asmfile);
1008 CHARS (1);
1009 dbxout_type (DECL_CONTEXT (decl), 0);
1010 fprintf (asmfile, ";");
1011 CHARS (1);
1015 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1016 in TYPE. */
1018 static void
1019 dbxout_type_methods (tree type)
1021 /* C++: put out the method names and their parameter lists */
1022 tree methods = TYPE_METHODS (type);
1023 tree type_encoding;
1024 tree fndecl;
1025 tree last;
1026 char formatted_type_identifier_length[16];
1027 int type_identifier_length;
1029 if (methods == NULL_TREE)
1030 return;
1032 type_encoding = DECL_NAME (TYPE_NAME (type));
1034 #if 0
1035 /* C++: Template classes break some assumptions made by this code about
1036 the class names, constructor names, and encodings for assembler
1037 label names. For now, disable output of dbx info for them. */
1039 const char *ptr = IDENTIFIER_POINTER (type_encoding);
1040 /* This should use index. (mrs) */
1041 while (*ptr && *ptr != '<') ptr++;
1042 if (*ptr != 0)
1044 static int warned;
1045 if (!warned)
1046 warned = 1;
1047 return;
1050 #endif
1052 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
1054 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
1056 if (TREE_CODE (methods) != TREE_VEC)
1057 fndecl = methods;
1058 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1059 fndecl = TREE_VEC_ELT (methods, 0);
1060 else
1061 fndecl = TREE_VEC_ELT (methods, 1);
1063 while (fndecl)
1065 int need_prefix = 1;
1067 /* Group together all the methods for the same operation.
1068 These differ in the types of the arguments. */
1069 for (last = NULL_TREE;
1070 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1071 fndecl = TREE_CHAIN (fndecl))
1072 /* Output the name of the field (after overloading), as
1073 well as the name of the field before overloading, along
1074 with its parameter list */
1076 /* This is the "mangled" name of the method.
1077 It encodes the argument types. */
1078 const char *debug_name;
1080 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1081 include TEMPLATE_DECLs.) The debugger doesn't know what
1082 to do with such entities anyhow. */
1083 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1084 continue;
1086 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1088 CONTIN;
1090 last = fndecl;
1092 /* Also ignore abstract methods; those are only interesting to
1093 the DWARF backends. */
1094 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1095 continue;
1097 /* Redundantly output the plain name, since that's what gdb
1098 expects. */
1099 if (need_prefix)
1101 tree name = DECL_NAME (fndecl);
1102 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1103 CHARS (IDENTIFIER_LENGTH (name) + 2);
1104 need_prefix = 0;
1107 dbxout_type (TREE_TYPE (fndecl), 0);
1109 dbxout_type_method_1 (fndecl, debug_name);
1111 if (!need_prefix)
1113 putc (';', asmfile);
1114 CHARS (1);
1119 /* Emit a "range" type specification, which has the form:
1120 "r<index type>;<lower bound>;<upper bound>;".
1121 TYPE is an INTEGER_TYPE. */
1123 static void
1124 dbxout_range_type (tree type)
1126 fprintf (asmfile, "r");
1127 if (TREE_TYPE (type))
1128 dbxout_type (TREE_TYPE (type), 0);
1129 else if (TREE_CODE (type) != INTEGER_TYPE)
1130 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1131 else
1133 /* Traditionally, we made sure 'int' was type 1, and builtin types
1134 were defined to be sub-ranges of int. Unfortunately, this
1135 does not allow us to distinguish true sub-ranges from integer
1136 types. So, instead we define integer (non-sub-range) types as
1137 sub-ranges of themselves. This matters for Chill. If this isn't
1138 a subrange type, then we want to define it in terms of itself.
1139 However, in C, this may be an anonymous integer type, and we don't
1140 want to emit debug info referring to it. Just calling
1141 dbxout_type_index won't work anyways, because the type hasn't been
1142 defined yet. We make this work for both cases by checked to see
1143 whether this is a defined type, referring to it if it is, and using
1144 'int' otherwise. */
1145 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1146 dbxout_type_index (type);
1147 else
1148 dbxout_type_index (integer_type_node);
1151 if (TYPE_MIN_VALUE (type) != 0
1152 && host_integerp (TYPE_MIN_VALUE (type), 0))
1154 putc (';', asmfile);
1155 CHARS (1);
1156 if (print_int_cst_bounds_in_octal_p (type))
1157 print_int_cst_octal (TYPE_MIN_VALUE (type));
1158 else
1159 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1161 else
1163 fprintf (asmfile, ";0");
1164 CHARS (2);
1167 if (TYPE_MAX_VALUE (type) != 0
1168 && host_integerp (TYPE_MAX_VALUE (type), 0))
1170 putc (';', asmfile);
1171 CHARS (1);
1172 if (print_int_cst_bounds_in_octal_p (type))
1173 print_int_cst_octal (TYPE_MAX_VALUE (type));
1174 else
1175 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1176 putc (';', asmfile);
1177 CHARS (1);
1179 else
1181 fprintf (asmfile, ";-1;");
1182 CHARS (4);
1187 /* Output a reference to a type. If the type has not yet been
1188 described in the dbx output, output its definition now.
1189 For a type already defined, just refer to its definition
1190 using the type number.
1192 If FULL is nonzero, and the type has been described only with
1193 a forward-reference, output the definition now.
1194 If FULL is zero in this case, just refer to the forward-reference
1195 using the number previously allocated. */
1197 static void
1198 dbxout_type (tree type, int full)
1200 tree tem;
1201 tree main_variant;
1202 static int anonymous_type_number = 0;
1204 if (TREE_CODE (type) == VECTOR_TYPE)
1205 /* The frontend feeds us a representation for the vector as a struct
1206 containing an array. Pull out the array type. */
1207 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1209 /* If there was an input error and we don't really have a type,
1210 avoid crashing and write something that is at least valid
1211 by assuming `int'. */
1212 if (type == error_mark_node)
1213 type = integer_type_node;
1214 else
1216 if (TYPE_NAME (type)
1217 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1218 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1219 full = 0;
1222 /* Try to find the "main variant" with the same name. */
1223 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1224 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1225 main_variant = TREE_TYPE (TYPE_NAME (type));
1226 else
1227 main_variant = TYPE_MAIN_VARIANT (type);
1229 /* If we are not using extensions, stabs does not distinguish const and
1230 volatile, so there is no need to make them separate types. */
1231 if (!use_gnu_debug_info_extensions)
1232 type = main_variant;
1234 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1236 /* Type has no dbx number assigned. Assign next available number. */
1237 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1239 /* Make sure type vector is long enough to record about this type. */
1241 if (next_type_number == typevec_len)
1243 typevec
1244 = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1245 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1246 typevec_len *= 2;
1249 #ifdef DBX_USE_BINCL
1250 emit_pending_bincls_if_required ();
1251 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1252 = current_file->file_number;
1253 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1254 = current_file->next_type_number++;
1255 #endif
1258 if (flag_debug_only_used_symbols)
1260 if ((TREE_CODE (type) == RECORD_TYPE
1261 || TREE_CODE (type) == UNION_TYPE
1262 || TREE_CODE (type) == QUAL_UNION_TYPE
1263 || TREE_CODE (type) == ENUMERAL_TYPE)
1264 && TYPE_STUB_DECL (type)
1265 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (type))) == 'd'
1266 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1267 debug_queue_symbol (TYPE_STUB_DECL (type));
1268 else if (TYPE_NAME (type)
1269 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1270 debug_queue_symbol (TYPE_NAME (type));
1273 /* Output the number of this type, to refer to it. */
1274 dbxout_type_index (type);
1276 #ifdef DBX_TYPE_DEFINED
1277 if (DBX_TYPE_DEFINED (type))
1278 return;
1279 #endif
1281 /* If this type's definition has been output or is now being output,
1282 that is all. */
1284 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1286 case TYPE_UNSEEN:
1287 break;
1288 case TYPE_XREF:
1289 /* If we have already had a cross reference,
1290 and either that's all we want or that's the best we could do,
1291 don't repeat the cross reference.
1292 Sun dbx crashes if we do. */
1293 if (! full || !COMPLETE_TYPE_P (type)
1294 /* No way in DBX fmt to describe a variable size. */
1295 || ! host_integerp (TYPE_SIZE (type), 1))
1296 return;
1297 break;
1298 case TYPE_DEFINED:
1299 return;
1302 #ifdef DBX_NO_XREFS
1303 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1304 leave the type-number completely undefined rather than output
1305 a cross-reference. If we have already used GNU debug info extensions,
1306 then it is OK to output a cross reference. This is necessary to get
1307 proper C++ debug output. */
1308 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1309 || TREE_CODE (type) == QUAL_UNION_TYPE
1310 || TREE_CODE (type) == ENUMERAL_TYPE)
1311 && ! use_gnu_debug_info_extensions)
1312 /* We must use the same test here as we use twice below when deciding
1313 whether to emit a cross-reference. */
1314 if ((TYPE_NAME (type) != 0
1315 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1316 && DECL_IGNORED_P (TYPE_NAME (type)))
1317 && !full)
1318 || !COMPLETE_TYPE_P (type)
1319 /* No way in DBX fmt to describe a variable size. */
1320 || ! host_integerp (TYPE_SIZE (type), 1))
1322 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1323 return;
1325 #endif
1327 /* Output a definition now. */
1329 fprintf (asmfile, "=");
1330 CHARS (1);
1332 /* Mark it as defined, so that if it is self-referent
1333 we will not get into an infinite recursion of definitions. */
1335 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1337 /* If this type is a variant of some other, hand off. Types with
1338 different names are usefully distinguished. We only distinguish
1339 cv-qualified types if we're using extensions. */
1340 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1342 putc ('k', asmfile);
1343 CHARS (1);
1344 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1345 return;
1347 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1349 putc ('B', asmfile);
1350 CHARS (1);
1351 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1352 return;
1354 else if (main_variant != TYPE_MAIN_VARIANT (type))
1356 if (flag_debug_only_used_symbols)
1358 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1360 if ((TREE_CODE (orig_type) == RECORD_TYPE
1361 || TREE_CODE (orig_type) == UNION_TYPE
1362 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1363 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1364 && TYPE_STUB_DECL (orig_type)
1365 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1366 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1368 /* 'type' is a typedef; output the type it refers to. */
1369 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1370 return;
1372 /* else continue. */
1374 switch (TREE_CODE (type))
1376 case VOID_TYPE:
1377 case LANG_TYPE:
1378 /* For a void type, just define it as itself; ie, "5=5".
1379 This makes us consider it defined
1380 without saying what it is. The debugger will make it
1381 a void type when the reference is seen, and nothing will
1382 ever override that default. */
1383 dbxout_type_index (type);
1384 break;
1386 case INTEGER_TYPE:
1387 if (type == char_type_node && ! TREE_UNSIGNED (type))
1389 /* Output the type `char' as a subrange of itself!
1390 I don't understand this definition, just copied it
1391 from the output of pcc.
1392 This used to use `r2' explicitly and we used to
1393 take care to make sure that `char' was type number 2. */
1394 fprintf (asmfile, "r");
1395 CHARS (1);
1396 dbxout_type_index (type);
1397 fprintf (asmfile, ";0;127;");
1398 CHARS (7);
1401 /* If this is a subtype of another integer type, always prefer to
1402 write it as a subtype. */
1403 else if (TREE_TYPE (type) != 0
1404 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1406 /* If the size is non-standard, say what it is if we can use
1407 GDB extensions. */
1409 if (use_gnu_debug_info_extensions
1410 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1412 have_used_extensions = 1;
1413 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1414 CHARS (5);
1417 dbxout_range_type (type);
1420 else
1422 /* If the size is non-standard, say what it is if we can use
1423 GDB extensions. */
1425 if (use_gnu_debug_info_extensions
1426 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1428 have_used_extensions = 1;
1429 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1430 CHARS (5);
1433 if (print_int_cst_bounds_in_octal_p (type))
1435 fprintf (asmfile, "r");
1436 CHARS (1);
1438 /* If this type derives from another type, output type index of
1439 parent type. This is particularly important when parent type
1440 is an enumerated type, because not generating the parent type
1441 index would transform the definition of this enumerated type
1442 into a plain unsigned type. */
1443 if (TREE_TYPE (type) != 0)
1444 dbxout_type_index (TREE_TYPE (type));
1445 else
1446 dbxout_type_index (type);
1448 fprintf (asmfile, ";");
1449 CHARS (1);
1450 print_int_cst_octal (TYPE_MIN_VALUE (type));
1451 fprintf (asmfile, ";");
1452 CHARS (1);
1453 print_int_cst_octal (TYPE_MAX_VALUE (type));
1454 fprintf (asmfile, ";");
1455 CHARS (1);
1458 else
1459 /* Output other integer types as subranges of `int'. */
1460 dbxout_range_type (type);
1463 break;
1465 case REAL_TYPE:
1466 /* This used to say `r1' and we used to take care
1467 to make sure that `int' was type number 1. */
1468 fprintf (asmfile, "r");
1469 CHARS (1);
1470 dbxout_type_index (integer_type_node);
1471 putc (';', asmfile);
1472 CHARS (1);
1473 print_wide_int (int_size_in_bytes (type));
1474 fputs (";0;", asmfile);
1475 CHARS (3);
1476 break;
1478 case CHAR_TYPE:
1479 if (use_gnu_debug_info_extensions)
1481 have_used_extensions = 1;
1482 fputs ("@s", asmfile);
1483 CHARS (2);
1484 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1485 fputs (";-20;", asmfile);
1486 CHARS (4);
1488 else
1490 /* Output the type `char' as a subrange of itself.
1491 That is what pcc seems to do. */
1492 fprintf (asmfile, "r");
1493 CHARS (1);
1494 dbxout_type_index (char_type_node);
1495 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1496 CHARS (7);
1498 break;
1500 case BOOLEAN_TYPE:
1501 if (use_gnu_debug_info_extensions)
1503 have_used_extensions = 1;
1504 fputs ("@s", asmfile);
1505 CHARS (2);
1506 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1507 fputs (";-16;", asmfile);
1508 CHARS (4);
1510 else /* Define as enumeral type (False, True) */
1512 fprintf (asmfile, "eFalse:0,True:1,;");
1513 CHARS (17);
1515 break;
1517 case FILE_TYPE:
1518 putc ('d', asmfile);
1519 CHARS (1);
1520 dbxout_type (TREE_TYPE (type), 0);
1521 break;
1523 case COMPLEX_TYPE:
1524 /* Differs from the REAL_TYPE by its new data type number.
1525 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
1526 codes since gdb doesn't care anyway. */
1528 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1530 fputs ("R3;", asmfile);
1531 CHARS (3);
1532 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1533 fputs (";0;", asmfile);
1534 CHARS (3);
1536 else
1538 /* Output a complex integer type as a structure,
1539 pending some other way to do it. */
1540 putc ('s', asmfile);
1541 CHARS (1);
1542 print_wide_int (int_size_in_bytes (type));
1543 fprintf (asmfile, "real:");
1544 CHARS (5);
1546 dbxout_type (TREE_TYPE (type), 0);
1547 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1548 CHARS (7);
1549 fprintf (asmfile, "imag:");
1550 CHARS (5);
1551 dbxout_type (TREE_TYPE (type), 0);
1552 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1553 TYPE_PRECISION (TREE_TYPE (type)));
1554 CHARS (10);
1556 break;
1558 case SET_TYPE:
1559 if (use_gnu_debug_info_extensions)
1561 have_used_extensions = 1;
1562 fputs ("@s", asmfile);
1563 CHARS (2);
1564 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1565 putc (';', asmfile);
1566 CHARS (1);
1568 /* Check if a bitstring type, which in Chill is
1569 different from a [power]set. */
1570 if (TYPE_STRING_FLAG (type))
1572 fprintf (asmfile, "@S;");
1573 CHARS (3);
1576 putc ('S', asmfile);
1577 CHARS (1);
1578 dbxout_type (TYPE_DOMAIN (type), 0);
1579 break;
1581 case ARRAY_TYPE:
1582 /* Make arrays of packed bits look like bitstrings for chill. */
1583 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1585 have_used_extensions = 1;
1586 fputs ("@s", asmfile);
1587 CHARS (2);
1588 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1589 fprintf (asmfile, ";@S;S");
1590 CHARS (5);
1591 dbxout_type (TYPE_DOMAIN (type), 0);
1592 break;
1595 /* Output "a" followed by a range type definition
1596 for the index type of the array
1597 followed by a reference to the target-type.
1598 ar1;0;N;M for a C array of type M and size N+1. */
1599 /* Check if a character string type, which in Chill is
1600 different from an array of characters. */
1601 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1603 have_used_extensions = 1;
1604 fprintf (asmfile, "@S;");
1605 CHARS (3);
1607 tem = TYPE_DOMAIN (type);
1608 if (tem == NULL)
1610 fprintf (asmfile, "ar");
1611 CHARS (2);
1612 dbxout_type_index (integer_type_node);
1613 fprintf (asmfile, ";0;-1;");
1614 CHARS (6);
1616 else
1618 fprintf (asmfile, "a");
1619 CHARS (1);
1620 dbxout_range_type (tem);
1623 dbxout_type (TREE_TYPE (type), 0);
1624 break;
1626 case RECORD_TYPE:
1627 case UNION_TYPE:
1628 case QUAL_UNION_TYPE:
1630 int i, n_baseclasses = 0;
1632 if (TYPE_BINFO (type) != 0
1633 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1634 && TYPE_BINFO_BASETYPES (type) != 0)
1635 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1637 /* Output a structure type. We must use the same test here as we
1638 use in the DBX_NO_XREFS case above. */
1639 if ((TYPE_NAME (type) != 0
1640 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1641 && DECL_IGNORED_P (TYPE_NAME (type)))
1642 && !full)
1643 || !COMPLETE_TYPE_P (type)
1644 /* No way in DBX fmt to describe a variable size. */
1645 || ! host_integerp (TYPE_SIZE (type), 1))
1647 /* If the type is just a cross reference, output one
1648 and mark the type as partially described.
1649 If it later becomes defined, we will output
1650 its real definition.
1651 If the type has a name, don't nest its definition within
1652 another type's definition; instead, output an xref
1653 and let the definition come when the name is defined. */
1654 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1655 CHARS (2);
1656 #if 0 /* This assertion is legitimately false in C++. */
1657 /* We shouldn't be outputting a reference to a type before its
1658 definition unless the type has a tag name.
1659 A typedef name without a tag name should be impossible. */
1660 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1661 abort ();
1662 #endif
1663 if (TYPE_NAME (type) != 0)
1664 dbxout_type_name (type);
1665 else
1667 fprintf (asmfile, "$$%d", anonymous_type_number++);
1668 CHARS (5);
1671 fprintf (asmfile, ":");
1672 CHARS (1);
1673 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1674 break;
1677 /* Identify record or union, and print its size. */
1678 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1679 CHARS (1);
1680 print_wide_int (int_size_in_bytes (type));
1682 if (use_gnu_debug_info_extensions)
1684 if (n_baseclasses)
1686 have_used_extensions = 1;
1687 fprintf (asmfile, "!%d,", n_baseclasses);
1688 CHARS (8);
1691 for (i = 0; i < n_baseclasses; i++)
1693 tree binfo = TYPE_BINFO (type);
1694 tree child = BINFO_BASETYPE (binfo, i);
1695 tree access = (BINFO_BASEACCESSES (binfo)
1696 ? BINFO_BASEACCESS (binfo, i) : access_public_node);
1698 if (use_gnu_debug_info_extensions)
1700 have_used_extensions = 1;
1701 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1702 putc (access == access_public_node ? '2' :
1703 (access == access_protected_node ? '1' :'0'),
1704 asmfile);
1705 CHARS (2);
1706 if (TREE_VIA_VIRTUAL (child)
1707 && strcmp (lang_hooks.name, "GNU C++") == 0)
1708 /* For a virtual base, print the (negative) offset within
1709 the vtable where we must look to find the necessary
1710 adjustment. */
1711 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1712 * BITS_PER_UNIT);
1713 else
1714 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1715 * BITS_PER_UNIT);
1716 putc (',', asmfile);
1717 CHARS (1);
1718 dbxout_type (BINFO_TYPE (child), 0);
1719 putc (';', asmfile);
1720 CHARS (1);
1722 else
1724 /* Print out the base class information with fields
1725 which have the same names at the types they hold. */
1726 dbxout_type_name (BINFO_TYPE (child));
1727 putc (':', asmfile);
1728 CHARS (1);
1729 dbxout_type (BINFO_TYPE (child), full);
1730 putc (',', asmfile);
1731 CHARS (1);
1732 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1733 * BITS_PER_UNIT);
1734 putc (',', asmfile);
1735 CHARS (1);
1736 print_wide_int (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)),
1738 * BITS_PER_UNIT);
1739 putc (';', asmfile);
1740 CHARS (1);
1745 /* Write out the field declarations. */
1746 dbxout_type_fields (type);
1747 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1749 have_used_extensions = 1;
1750 dbxout_type_methods (type);
1753 putc (';', asmfile);
1754 CHARS (1);
1756 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1757 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1758 && TYPE_VFIELD (type))
1760 have_used_extensions = 1;
1762 /* Tell GDB+ that it may keep reading. */
1763 putc ('~', asmfile);
1764 CHARS (1);
1766 /* We need to write out info about what field this class
1767 uses as its "main" vtable pointer field, because if this
1768 field is inherited from a base class, GDB cannot necessarily
1769 figure out which field it's using in time. */
1770 if (TYPE_VFIELD (type))
1772 putc ('%', asmfile);
1773 CHARS (1);
1774 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1777 putc (';', asmfile);
1778 CHARS (1);
1780 break;
1782 case ENUMERAL_TYPE:
1783 /* We must use the same test here as we use in the DBX_NO_XREFS case
1784 above. We simplify it a bit since an enum will never have a variable
1785 size. */
1786 if ((TYPE_NAME (type) != 0
1787 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1788 && DECL_IGNORED_P (TYPE_NAME (type)))
1789 && !full)
1790 || !COMPLETE_TYPE_P (type))
1792 fprintf (asmfile, "xe");
1793 CHARS (2);
1794 dbxout_type_name (type);
1795 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1796 putc (':', asmfile);
1797 CHARS (1);
1798 return;
1800 if (use_gnu_debug_info_extensions
1801 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1803 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1804 CHARS (5);
1807 putc ('e', asmfile);
1808 CHARS (1);
1809 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1811 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1812 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1813 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1814 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1815 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1816 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1817 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1818 else
1819 print_int_cst_octal (TREE_VALUE (tem));
1821 putc (',', asmfile);
1822 CHARS (1);
1823 if (TREE_CHAIN (tem) != 0)
1824 CONTIN;
1827 putc (';', asmfile);
1828 CHARS (1);
1829 break;
1831 case POINTER_TYPE:
1832 putc ('*', asmfile);
1833 CHARS (1);
1834 dbxout_type (TREE_TYPE (type), 0);
1835 break;
1837 case METHOD_TYPE:
1838 if (use_gnu_debug_info_extensions)
1840 have_used_extensions = 1;
1841 putc ('#', asmfile);
1842 CHARS (1);
1844 /* Write the argument types out longhand. */
1845 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1846 putc (',', asmfile);
1847 CHARS (1);
1848 dbxout_type (TREE_TYPE (type), 0);
1849 dbxout_args (TYPE_ARG_TYPES (type));
1850 putc (';', asmfile);
1851 CHARS (1);
1853 else
1854 /* Treat it as a function type. */
1855 dbxout_type (TREE_TYPE (type), 0);
1856 break;
1858 case OFFSET_TYPE:
1859 if (use_gnu_debug_info_extensions)
1861 have_used_extensions = 1;
1862 putc ('@', asmfile);
1863 CHARS (1);
1864 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1865 putc (',', asmfile);
1866 CHARS (1);
1867 dbxout_type (TREE_TYPE (type), 0);
1869 else
1870 /* Should print as an int, because it is really just an offset. */
1871 dbxout_type (integer_type_node, 0);
1872 break;
1874 case REFERENCE_TYPE:
1875 if (use_gnu_debug_info_extensions)
1876 have_used_extensions = 1;
1877 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1878 CHARS (1);
1879 dbxout_type (TREE_TYPE (type), 0);
1880 break;
1882 case FUNCTION_TYPE:
1883 putc ('f', asmfile);
1884 CHARS (1);
1885 dbxout_type (TREE_TYPE (type), 0);
1886 break;
1888 default:
1889 abort ();
1893 /* Return nonzero if the given type represents an integer whose bounds
1894 should be printed in octal format. */
1896 static bool
1897 print_int_cst_bounds_in_octal_p (tree type)
1899 /* If we can use GDB extensions and the size is wider than a long
1900 (the size used by GDB to read them) or we may have trouble writing
1901 the bounds the usual way, write them in octal. Note the test is for
1902 the *target's* size of "long", not that of the host. The host test
1903 is just to make sure we can write it out in case the host wide int
1904 is narrower than the target "long".
1906 For unsigned types, we use octal if they are the same size or larger.
1907 This is because we print the bounds as signed decimal, and hence they
1908 can't span same size unsigned types. */
1910 if (use_gnu_debug_info_extensions
1911 && TYPE_MIN_VALUE (type) != 0
1912 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1913 && TYPE_MAX_VALUE (type) != 0
1914 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1915 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1916 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1917 && TREE_UNSIGNED (type))
1918 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1919 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1920 && TREE_UNSIGNED (type))))
1921 return TRUE;
1922 else
1923 return FALSE;
1926 /* Print the value of integer constant C, in octal,
1927 handling double precision. */
1929 static void
1930 print_int_cst_octal (tree c)
1932 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1933 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1934 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1935 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1937 /* GDB wants constants with no extra leading "1" bits, so
1938 we need to remove any sign-extension that might be
1939 present. */
1940 if (width == HOST_BITS_PER_WIDE_INT * 2)
1942 else if (width > HOST_BITS_PER_WIDE_INT)
1943 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1944 else if (width == HOST_BITS_PER_WIDE_INT)
1945 high = 0;
1946 else
1947 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1949 fprintf (asmfile, "0");
1950 CHARS (1);
1952 if (excess == 3)
1954 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1955 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1957 else
1959 unsigned HOST_WIDE_INT beg = high >> excess;
1960 unsigned HOST_WIDE_INT middle
1961 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1962 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1963 unsigned HOST_WIDE_INT end
1964 = low & (((unsigned HOST_WIDE_INT) 1
1965 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1966 - 1);
1968 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1969 CHARS (2);
1970 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1974 static void
1975 print_octal (unsigned HOST_WIDE_INT value, int digits)
1977 int i;
1979 for (i = digits - 1; i >= 0; i--)
1980 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1982 CHARS (digits);
1985 /* Output C in decimal while adjusting the number of digits written. */
1987 static void
1988 print_wide_int (HOST_WIDE_INT c)
1990 int digs = 0;
1992 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1994 if (c < 0)
1995 digs++, c = -c;
1997 while (c > 0)
1998 c /= 10; digs++;
2000 CHARS (digs);
2003 /* Output the name of type TYPE, with no punctuation.
2004 Such names can be set up either by typedef declarations
2005 or by struct, enum and union tags. */
2007 static void
2008 dbxout_type_name (tree type)
2010 tree t;
2011 if (TYPE_NAME (type) == 0)
2012 abort ();
2013 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2015 t = TYPE_NAME (type);
2017 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2019 t = DECL_NAME (TYPE_NAME (type));
2021 else
2022 abort ();
2024 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
2025 CHARS (IDENTIFIER_LENGTH (t));
2028 /* Output leading leading struct or class names needed for qualifying
2029 type whose scope is limited to a struct or class. */
2031 static void
2032 dbxout_class_name_qualifiers (tree decl)
2034 tree context = decl_type_context (decl);
2036 if (context != NULL_TREE
2037 && TREE_CODE(context) == RECORD_TYPE
2038 && TYPE_NAME (context) != 0
2039 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2040 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2042 tree name = TYPE_NAME (context);
2044 emit_pending_bincls_if_required ();
2046 if (TREE_CODE (name) == TYPE_DECL)
2048 dbxout_class_name_qualifiers (name);
2049 name = DECL_NAME (name);
2051 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
2052 CHARS (IDENTIFIER_LENGTH (name) + 2);
2056 /* Output a .stabs for the symbol defined by DECL,
2057 which must be a ..._DECL node in the normal namespace.
2058 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2059 LOCAL is nonzero if the scope is less than the entire file.
2060 Return 1 if a stabs might have been emitted. */
2063 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2065 tree type = TREE_TYPE (decl);
2066 tree context = NULL_TREE;
2067 int result = 0;
2069 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2070 ++debug_nesting;
2072 /* Ignore nameless syms, but don't ignore type tags. */
2074 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2075 || DECL_IGNORED_P (decl))
2076 DBXOUT_DECR_NESTING_AND_RETURN (0);
2078 /* If we are to generate only the symbols actually used then such
2079 symbol nodees are flagged with TREE_USED. Ignore any that
2080 aren't flaged as TREE_USED. */
2082 if (flag_debug_only_used_symbols
2083 && (!TREE_USED (decl)
2084 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2085 DBXOUT_DECR_NESTING_AND_RETURN (0);
2087 /* If dbxout_init has not yet run, queue this symbol for later. */
2088 if (!typevec)
2090 preinit_symbols = tree_cons (0, decl, preinit_symbols);
2091 DBXOUT_DECR_NESTING_AND_RETURN (0);
2094 if (flag_debug_only_used_symbols)
2096 tree t;
2098 /* We now have a used symbol. We need to generate the info for
2099 the symbol's type in addition to the symbol itself. These
2100 type symbols are queued to be generated after were done with
2101 the symbol itself (done because the symbol's info is generated
2102 with fprintf's, etc. as it determines what's needed).
2104 Note, because the TREE_TYPE(type) might be something like a
2105 pointer to a named type we need to look for the first name
2106 we see following the TREE_TYPE chain. */
2108 t = type;
2109 while (POINTER_TYPE_P (t))
2110 t = TREE_TYPE (t);
2112 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2113 need special treatment. The TYPE_STUB_DECL field in these
2114 types generally represents the tag name type we want to
2115 output. In addition there could be a typedef type with
2116 a different name. In that case we also want to output
2117 that. */
2119 if ((TREE_CODE (t) == RECORD_TYPE
2120 || TREE_CODE (t) == UNION_TYPE
2121 || TREE_CODE (t) == QUAL_UNION_TYPE
2122 || TREE_CODE (t) == ENUMERAL_TYPE)
2123 && TYPE_STUB_DECL (t)
2124 && TYPE_STUB_DECL (t) != decl
2125 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (t))) == 'd'
2126 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2128 debug_queue_symbol (TYPE_STUB_DECL (t));
2129 if (TYPE_NAME (t)
2130 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2131 && TYPE_NAME (t) != decl
2132 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2133 debug_queue_symbol (TYPE_NAME (t));
2135 else if (TYPE_NAME (t)
2136 && TYPE_NAME (t) != decl
2137 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2138 debug_queue_symbol (TYPE_NAME (t));
2141 emit_pending_bincls_if_required ();
2143 dbxout_prepare_symbol (decl);
2145 /* The output will always start with the symbol name,
2146 so always count that in the length-output-so-far. */
2148 if (DECL_NAME (decl) != 0)
2149 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2151 switch (TREE_CODE (decl))
2153 case CONST_DECL:
2154 /* Enum values are defined by defining the enum type. */
2155 break;
2157 case FUNCTION_DECL:
2158 if (DECL_RTL (decl) == 0)
2159 DBXOUT_DECR_NESTING_AND_RETURN (0);
2160 if (DECL_EXTERNAL (decl))
2161 break;
2162 /* Don't mention a nested function under its parent. */
2163 context = decl_function_context (decl);
2164 if (context == current_function_decl)
2165 break;
2166 if (GET_CODE (DECL_RTL (decl)) != MEM
2167 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2168 break;
2169 FORCE_TEXT;
2171 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2172 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2173 TREE_PUBLIC (decl) ? 'F' : 'f');
2174 result = 1;
2176 current_sym_code = N_FUN;
2177 current_sym_addr = XEXP (DECL_RTL (decl), 0);
2179 if (TREE_TYPE (type))
2180 dbxout_type (TREE_TYPE (type), 0);
2181 else
2182 dbxout_type (void_type_node, 0);
2184 /* For a nested function, when that function is compiled,
2185 mention the containing function name
2186 as well as (since dbx wants it) our own assembler-name. */
2187 if (context != 0)
2188 fprintf (asmfile, ",%s,%s",
2189 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2190 IDENTIFIER_POINTER (DECL_NAME (context)));
2192 dbxout_finish_symbol (decl);
2193 break;
2195 case TYPE_DECL:
2196 /* Don't output the same typedef twice.
2197 And don't output what language-specific stuff doesn't want output. */
2198 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2199 DBXOUT_DECR_NESTING_AND_RETURN (0);
2201 /* Don't output typedefs for types with magic type numbers (XCOFF). */
2202 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2204 int fundamental_type_number =
2205 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2207 if (fundamental_type_number != 0)
2209 TREE_ASM_WRITTEN (decl) = 1;
2210 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2211 DBXOUT_DECR_NESTING_AND_RETURN (0);
2214 #endif
2215 FORCE_TEXT;
2216 result = 1;
2218 int tag_needed = 1;
2219 int did_output = 0;
2221 if (DECL_NAME (decl))
2223 /* Nonzero means we must output a tag as well as a typedef. */
2224 tag_needed = 0;
2226 /* Handle the case of a C++ structure or union
2227 where the TYPE_NAME is a TYPE_DECL
2228 which gives both a typedef name and a tag. */
2229 /* dbx requires the tag first and the typedef second. */
2230 if ((TREE_CODE (type) == RECORD_TYPE
2231 || TREE_CODE (type) == UNION_TYPE
2232 || TREE_CODE (type) == QUAL_UNION_TYPE)
2233 && TYPE_NAME (type) == decl
2234 && !(use_gnu_debug_info_extensions && have_used_extensions)
2235 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2236 /* Distinguish the implicit typedefs of C++
2237 from explicit ones that might be found in C. */
2238 && DECL_ARTIFICIAL (decl)
2239 /* Do not generate a tag for incomplete records. */
2240 && COMPLETE_TYPE_P (type)
2241 /* Do not generate a tag for records of variable size,
2242 since this type can not be properly described in the
2243 DBX format, and it confuses some tools such as objdump. */
2244 && host_integerp (TYPE_SIZE (type), 1))
2246 tree name = TYPE_NAME (type);
2247 if (TREE_CODE (name) == TYPE_DECL)
2248 name = DECL_NAME (name);
2250 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2251 current_sym_value = 0;
2252 current_sym_addr = 0;
2253 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2255 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2256 IDENTIFIER_POINTER (name));
2257 dbxout_type (type, 1);
2258 dbxout_finish_symbol (NULL_TREE);
2261 /* Output .stabs (or whatever) and leading double quote. */
2262 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2264 if (use_gnu_debug_info_extensions)
2266 /* Output leading class/struct qualifiers. */
2267 dbxout_class_name_qualifiers (decl);
2270 /* Output typedef name. */
2271 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2273 /* Short cut way to output a tag also. */
2274 if ((TREE_CODE (type) == RECORD_TYPE
2275 || TREE_CODE (type) == UNION_TYPE
2276 || TREE_CODE (type) == QUAL_UNION_TYPE)
2277 && TYPE_NAME (type) == decl
2278 /* Distinguish the implicit typedefs of C++
2279 from explicit ones that might be found in C. */
2280 && DECL_ARTIFICIAL (decl))
2282 if (use_gnu_debug_info_extensions && have_used_extensions)
2284 putc ('T', asmfile);
2285 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2287 #if 0 /* Now we generate the tag for this case up above. */
2288 else
2289 tag_needed = 1;
2290 #endif
2293 putc ('t', asmfile);
2294 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2296 dbxout_type (type, 1);
2297 dbxout_finish_symbol (decl);
2298 did_output = 1;
2301 /* Don't output a tag if this is an incomplete type. This prevents
2302 the sun4 Sun OS 4.x dbx from crashing. */
2304 if (tag_needed && TYPE_NAME (type) != 0
2305 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2306 || (DECL_NAME (TYPE_NAME (type)) != 0))
2307 && COMPLETE_TYPE_P (type)
2308 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2310 /* For a TYPE_DECL with no name, but the type has a name,
2311 output a tag.
2312 This is what represents `struct foo' with no typedef. */
2313 /* In C++, the name of a type is the corresponding typedef.
2314 In C, it is an IDENTIFIER_NODE. */
2315 tree name = TYPE_NAME (type);
2316 if (TREE_CODE (name) == TYPE_DECL)
2317 name = DECL_NAME (name);
2319 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2320 current_sym_value = 0;
2321 current_sym_addr = 0;
2322 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2324 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2325 IDENTIFIER_POINTER (name));
2326 dbxout_type (type, 1);
2327 dbxout_finish_symbol (NULL_TREE);
2328 did_output = 1;
2331 /* If an enum type has no name, it cannot be referred to,
2332 but we must output it anyway, since the enumeration constants
2333 can be referred to. */
2334 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2336 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2337 current_sym_value = 0;
2338 current_sym_addr = 0;
2339 current_sym_nchars = 2;
2341 /* Some debuggers fail when given NULL names, so give this a
2342 harmless name of ` '. */
2343 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2344 dbxout_type (type, 1);
2345 dbxout_finish_symbol (NULL_TREE);
2348 /* Prevent duplicate output of a typedef. */
2349 TREE_ASM_WRITTEN (decl) = 1;
2350 break;
2353 case PARM_DECL:
2354 /* Parm decls go in their own separate chains
2355 and are output by dbxout_reg_parms and dbxout_parms. */
2356 abort ();
2358 case RESULT_DECL:
2359 /* Named return value, treat like a VAR_DECL. */
2360 case VAR_DECL:
2361 if (! DECL_RTL_SET_P (decl))
2362 DBXOUT_DECR_NESTING_AND_RETURN (0);
2363 /* Don't mention a variable that is external.
2364 Let the file that defines it describe it. */
2365 if (DECL_EXTERNAL (decl))
2366 break;
2368 /* If the variable is really a constant
2369 and not written in memory, inform the debugger. */
2370 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2371 && DECL_INITIAL (decl) != 0
2372 && host_integerp (DECL_INITIAL (decl), 0)
2373 && ! TREE_ASM_WRITTEN (decl)
2374 && (DECL_CONTEXT (decl) == NULL_TREE
2375 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2377 if (TREE_PUBLIC (decl) == 0)
2379 /* The sun4 assembler does not grok this. */
2380 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2382 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2383 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2385 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2386 fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2387 "\",0x%x,0,0,0\n",
2388 ASM_STABS_OP, name, ival, N_LSYM);
2389 DBXOUT_DECR_NESTING;
2390 return 1;
2392 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2394 /* Don't know how to do this yet. */
2396 break;
2398 /* else it is something we handle like a normal variable. */
2401 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2402 #ifdef LEAF_REG_REMAP
2403 if (current_function_uses_only_leaf_regs)
2404 leaf_renumber_regs_insn (DECL_RTL (decl));
2405 #endif
2407 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2408 break;
2410 default:
2411 break;
2413 DBXOUT_DECR_NESTING;
2414 return result;
2417 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2418 Add SUFFIX to its name, if SUFFIX is not 0.
2419 Describe the variable as residing in HOME
2420 (usually HOME is DECL_RTL (DECL), but not always).
2421 Returns 1 if the stab was really emitted. */
2423 static int
2424 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2426 int letter = 0;
2427 int regno = -1;
2429 emit_pending_bincls_if_required ();
2431 /* Don't mention a variable at all
2432 if it was completely optimized into nothingness.
2434 If the decl was from an inline function, then its rtl
2435 is not identically the rtl that was used in this
2436 particular compilation. */
2437 if (GET_CODE (home) == SUBREG)
2439 rtx value = home;
2441 while (GET_CODE (value) == SUBREG)
2442 value = SUBREG_REG (value);
2443 if (GET_CODE (value) == REG)
2445 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2446 return 0;
2448 home = alter_subreg (&home);
2450 if (GET_CODE (home) == REG)
2452 regno = REGNO (home);
2453 if (regno >= FIRST_PSEUDO_REGISTER)
2454 return 0;
2457 /* The kind-of-variable letter depends on where
2458 the variable is and on the scope of its name:
2459 G and N_GSYM for static storage and global scope,
2460 S for static storage and file scope,
2461 V for static storage and local scope,
2462 for those two, use N_LCSYM if data is in bss segment,
2463 N_STSYM if in data segment, N_FUN otherwise.
2464 (We used N_FUN originally, then changed to N_STSYM
2465 to please GDB. However, it seems that confused ld.
2466 Now GDB has been fixed to like N_FUN, says Kingdon.)
2467 no letter at all, and N_LSYM, for auto variable,
2468 r and N_RSYM for register variable. */
2470 if (GET_CODE (home) == MEM
2471 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2473 if (TREE_PUBLIC (decl))
2475 letter = 'G';
2476 current_sym_code = N_GSYM;
2478 else
2480 current_sym_addr = XEXP (home, 0);
2482 letter = decl_function_context (decl) ? 'V' : 'S';
2484 /* This should be the same condition as in assemble_variable, but
2485 we don't have access to dont_output_data here. So, instead,
2486 we rely on the fact that error_mark_node initializers always
2487 end up in bss for C++ and never end up in bss for C. */
2488 if (DECL_INITIAL (decl) == 0
2489 || (!strcmp (lang_hooks.name, "GNU C++")
2490 && DECL_INITIAL (decl) == error_mark_node))
2491 current_sym_code = N_LCSYM;
2492 else if (DECL_IN_TEXT_SECTION (decl))
2493 /* This is not quite right, but it's the closest
2494 of all the codes that Unix defines. */
2495 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2496 else
2498 /* Some ports can transform a symbol ref into a label ref,
2499 because the symbol ref is too far away and has to be
2500 dumped into a constant pool. Alternatively, the symbol
2501 in the constant pool might be referenced by a different
2502 symbol. */
2503 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2504 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2506 bool marked;
2507 rtx tmp = get_pool_constant_mark (current_sym_addr, &marked);
2509 if (GET_CODE (tmp) == SYMBOL_REF)
2511 current_sym_addr = tmp;
2512 if (CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2513 get_pool_constant_mark (current_sym_addr, &marked);
2514 else
2515 marked = true;
2517 else if (GET_CODE (tmp) == LABEL_REF)
2519 current_sym_addr = tmp;
2520 marked = true;
2523 /* If all references to the constant pool were optimized
2524 out, we just ignore the symbol. */
2525 if (!marked)
2526 return 0;
2529 /* Ultrix `as' seems to need this. */
2530 #ifdef DBX_STATIC_STAB_DATA_SECTION
2531 data_section ();
2532 #endif
2533 current_sym_code = N_STSYM;
2537 else if (regno >= 0)
2539 letter = 'r';
2540 current_sym_code = N_RSYM;
2541 current_sym_value = DBX_REGISTER_NUMBER (regno);
2543 else if (GET_CODE (home) == MEM
2544 && (GET_CODE (XEXP (home, 0)) == MEM
2545 || (GET_CODE (XEXP (home, 0)) == REG
2546 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2547 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2548 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2549 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2550 #endif
2552 /* If the value is indirect by memory or by a register
2553 that isn't the frame pointer
2554 then it means the object is variable-sized and address through
2555 that register or stack slot. DBX has no way to represent this
2556 so all we can do is output the variable as a pointer.
2557 If it's not a parameter, ignore it.
2558 (VAR_DECLs like this can be made by integrate.c.) */
2560 if (GET_CODE (XEXP (home, 0)) == REG)
2562 letter = 'r';
2563 current_sym_code = N_RSYM;
2564 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2565 return 0;
2566 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2568 else
2570 current_sym_code = N_LSYM;
2571 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2572 We want the value of that CONST_INT. */
2573 current_sym_value
2574 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2577 /* Effectively do build_pointer_type, but don't cache this type,
2578 since it might be temporary whereas the type it points to
2579 might have been saved for inlining. */
2580 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2581 type = make_node (POINTER_TYPE);
2582 TREE_TYPE (type) = TREE_TYPE (decl);
2584 else if (GET_CODE (home) == MEM
2585 && GET_CODE (XEXP (home, 0)) == REG)
2587 current_sym_code = N_LSYM;
2588 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2590 else if (GET_CODE (home) == MEM
2591 && GET_CODE (XEXP (home, 0)) == PLUS
2592 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2594 current_sym_code = N_LSYM;
2595 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2596 We want the value of that CONST_INT. */
2597 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2599 else if (GET_CODE (home) == MEM
2600 && GET_CODE (XEXP (home, 0)) == CONST)
2602 /* Handle an obscure case which can arise when optimizing and
2603 when there are few available registers. (This is *always*
2604 the case for i386/i486 targets). The RTL looks like
2605 (MEM (CONST ...)) even though this variable is a local `auto'
2606 or a local `register' variable. In effect, what has happened
2607 is that the reload pass has seen that all assignments and
2608 references for one such a local variable can be replaced by
2609 equivalent assignments and references to some static storage
2610 variable, thereby avoiding the need for a register. In such
2611 cases we're forced to lie to debuggers and tell them that
2612 this variable was itself `static'. */
2613 current_sym_code = N_LCSYM;
2614 letter = 'V';
2615 current_sym_addr = XEXP (XEXP (home, 0), 0);
2617 else if (GET_CODE (home) == CONCAT)
2619 tree subtype;
2621 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2622 for example), then there is no easy way to figure out
2623 what SUBTYPE should be. So, we give up. */
2624 if (TREE_CODE (type) != COMPLEX_TYPE)
2625 return 0;
2627 subtype = TREE_TYPE (type);
2629 /* If the variable's storage is in two parts,
2630 output each as a separate stab with a modified name. */
2631 if (WORDS_BIG_ENDIAN)
2632 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2633 else
2634 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2636 dbxout_prepare_symbol (decl);
2638 if (WORDS_BIG_ENDIAN)
2639 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2640 else
2641 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2642 return 1;
2644 else
2645 /* Address might be a MEM, when DECL is a variable-sized object.
2646 Or it might be const0_rtx, meaning previous passes
2647 want us to ignore this variable. */
2648 return 0;
2650 /* Ok, start a symtab entry and output the variable name. */
2651 FORCE_TEXT;
2653 #ifdef DBX_STATIC_BLOCK_START
2654 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2655 #endif
2657 dbxout_symbol_name (decl, suffix, letter);
2658 dbxout_type (type, 0);
2659 dbxout_finish_symbol (decl);
2661 #ifdef DBX_STATIC_BLOCK_END
2662 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2663 #endif
2664 return 1;
2667 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2668 Then output LETTER to indicate the kind of location the symbol has. */
2670 static void
2671 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2673 const char *name;
2675 if (DECL_CONTEXT (decl)
2676 && (TYPE_P (DECL_CONTEXT (decl))
2677 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
2678 /* One slight hitch: if this is a VAR_DECL which is a class member
2679 or a namespace member, we must put out the mangled name instead of the
2680 DECL_NAME. Note also that static member (variable) names DO NOT begin
2681 with underscores in .stabs directives. */
2682 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2683 else
2684 /* ...but if we're function-local, we don't want to include the junk
2685 added by ASM_FORMAT_PRIVATE_NAME. */
2686 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2688 if (name == 0)
2689 name = "(anon)";
2690 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2691 (suffix ? suffix : ""));
2693 if (letter)
2694 putc (letter, asmfile);
2697 static void
2698 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)
2700 #ifdef WINNING_GDB
2701 const char *filename = DECL_SOURCE_FILE (decl);
2703 dbxout_source_file (asmfile, filename);
2704 #endif
2706 /* Initialize variables used to communicate each symbol's debug
2707 information to dbxout_finish_symbol with zeroes. */
2709 /* Cast avoids warning in old compilers. */
2710 current_sym_code = (STAB_CODE_TYPE) 0;
2711 current_sym_value = 0;
2712 current_sym_addr = 0;
2715 static void
2716 dbxout_finish_symbol (tree sym)
2718 #ifdef DBX_FINISH_SYMBOL
2719 DBX_FINISH_SYMBOL (sym);
2720 #else
2721 int line = 0;
2722 if (use_gnu_debug_info_extensions && sym != 0)
2723 line = DECL_SOURCE_LINE (sym);
2725 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2726 if (current_sym_addr)
2727 output_addr_const (asmfile, current_sym_addr);
2728 else
2729 fprintf (asmfile, "%d", current_sym_value);
2730 putc ('\n', asmfile);
2731 #endif
2734 /* Output definitions of all the decls in a chain. Return nonzero if
2735 anything was output */
2738 dbxout_syms (tree syms)
2740 int result = 0;
2741 while (syms)
2743 result += dbxout_symbol (syms, 1);
2744 syms = TREE_CHAIN (syms);
2746 return result;
2749 /* The following two functions output definitions of function parameters.
2750 Each parameter gets a definition locating it in the parameter list.
2751 Each parameter that is a register variable gets a second definition
2752 locating it in the register.
2754 Printing or argument lists in gdb uses the definitions that
2755 locate in the parameter list. But reference to the variable in
2756 expressions uses preferentially the definition as a register. */
2758 /* Output definitions, referring to storage in the parmlist,
2759 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2761 void
2762 dbxout_parms (tree parms)
2764 ++debug_nesting;
2766 emit_pending_bincls_if_required ();
2768 for (; parms; parms = TREE_CHAIN (parms))
2769 if (DECL_NAME (parms)
2770 && TREE_TYPE (parms) != error_mark_node
2771 && DECL_RTL_SET_P (parms)
2772 && DECL_INCOMING_RTL (parms))
2774 dbxout_prepare_symbol (parms);
2776 /* Perform any necessary register eliminations on the parameter's rtl,
2777 so that the debugging output will be accurate. */
2778 DECL_INCOMING_RTL (parms)
2779 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2780 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2781 #ifdef LEAF_REG_REMAP
2782 if (current_function_uses_only_leaf_regs)
2784 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2785 leaf_renumber_regs_insn (DECL_RTL (parms));
2787 #endif
2789 if (PARM_PASSED_IN_MEMORY (parms))
2791 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2793 /* ??? Here we assume that the parm address is indexed
2794 off the frame pointer or arg pointer.
2795 If that is not true, we produce meaningless results,
2796 but do not crash. */
2797 if (GET_CODE (addr) == PLUS
2798 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2799 current_sym_value = INTVAL (XEXP (addr, 1));
2800 else
2801 current_sym_value = 0;
2803 current_sym_code = N_PSYM;
2804 current_sym_addr = 0;
2806 FORCE_TEXT;
2807 if (DECL_NAME (parms))
2809 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2811 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2812 IDENTIFIER_POINTER (DECL_NAME (parms)),
2813 DBX_MEMPARM_STABS_LETTER);
2815 else
2817 current_sym_nchars = 8;
2818 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2819 DBX_MEMPARM_STABS_LETTER);
2822 /* It is quite tempting to use:
2824 dbxout_type (TREE_TYPE (parms), 0);
2826 as the next statement, rather than using DECL_ARG_TYPE(), so
2827 that gcc reports the actual type of the parameter, rather
2828 than the promoted type. This certainly makes GDB's life
2829 easier, at least for some ports. The change is a bad idea
2830 however, since GDB expects to be able access the type without
2831 performing any conversions. So for example, if we were
2832 passing a float to an unprototyped function, gcc will store a
2833 double on the stack, but if we emit a stab saying the type is a
2834 float, then gdb will only read in a single value, and this will
2835 produce an erroneous value. */
2836 dbxout_type (DECL_ARG_TYPE (parms), 0);
2837 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2838 dbxout_finish_symbol (parms);
2840 else if (GET_CODE (DECL_RTL (parms)) == REG)
2842 rtx best_rtl;
2843 char regparm_letter;
2844 tree parm_type;
2845 /* Parm passed in registers and lives in registers or nowhere. */
2847 current_sym_code = DBX_REGPARM_STABS_CODE;
2848 regparm_letter = DBX_REGPARM_STABS_LETTER;
2849 current_sym_addr = 0;
2851 /* If parm lives in a register, use that register;
2852 pretend the parm was passed there. It would be more consistent
2853 to describe the register where the parm was passed,
2854 but in practice that register usually holds something else.
2856 If we use DECL_RTL, then we must use the declared type of
2857 the variable, not the type that it arrived in. */
2858 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2860 best_rtl = DECL_RTL (parms);
2861 parm_type = TREE_TYPE (parms);
2863 /* If the parm lives nowhere, use the register where it was
2864 passed. It is also better to use the declared type here. */
2865 else
2867 best_rtl = DECL_INCOMING_RTL (parms);
2868 parm_type = TREE_TYPE (parms);
2870 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2872 FORCE_TEXT;
2873 if (DECL_NAME (parms))
2875 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2876 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2877 IDENTIFIER_POINTER (DECL_NAME (parms)),
2878 regparm_letter);
2880 else
2882 current_sym_nchars = 8;
2883 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2884 regparm_letter);
2887 dbxout_type (parm_type, 0);
2888 dbxout_finish_symbol (parms);
2890 else if (GET_CODE (DECL_RTL (parms)) == MEM
2891 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2892 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2893 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2894 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2895 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2896 #endif
2899 /* Parm was passed via invisible reference.
2900 That is, its address was passed in a register.
2901 Output it as if it lived in that register.
2902 The debugger will know from the type
2903 that it was actually passed by invisible reference. */
2905 char regparm_letter;
2906 /* Parm passed in registers and lives in registers or nowhere. */
2908 current_sym_code = DBX_REGPARM_STABS_CODE;
2909 if (use_gnu_debug_info_extensions)
2910 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2911 else
2912 regparm_letter = DBX_REGPARM_STABS_LETTER;
2914 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2915 If it is an unallocated pseudo-reg, then use the register where
2916 it was passed instead. */
2917 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2918 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2919 else
2920 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2922 current_sym_addr = 0;
2924 FORCE_TEXT;
2925 if (DECL_NAME (parms))
2927 current_sym_nchars
2928 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2930 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2931 IDENTIFIER_POINTER (DECL_NAME (parms)),
2932 regparm_letter);
2934 else
2936 current_sym_nchars = 8;
2937 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2938 regparm_letter);
2941 dbxout_type (TREE_TYPE (parms), 0);
2942 dbxout_finish_symbol (parms);
2944 else if (GET_CODE (DECL_RTL (parms)) == MEM
2945 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2947 /* Parm was passed via invisible reference, with the reference
2948 living on the stack. DECL_RTL looks like
2949 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2950 could look like (MEM (MEM (REG))). */
2951 const char *const decl_name = (DECL_NAME (parms)
2952 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2953 : "(anon)");
2954 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2955 current_sym_value = 0;
2956 else
2957 current_sym_value
2958 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2959 current_sym_addr = 0;
2960 current_sym_code = N_PSYM;
2962 FORCE_TEXT;
2963 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2965 current_sym_value
2966 = DEBUGGER_ARG_OFFSET (current_sym_value,
2967 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2968 dbxout_type (TREE_TYPE (parms), 0);
2969 dbxout_finish_symbol (parms);
2971 else if (GET_CODE (DECL_RTL (parms)) == MEM
2972 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2973 /* ??? A constant address for a parm can happen
2974 when the reg it lives in is equiv to a constant in memory.
2975 Should make this not happen, after 2.4. */
2976 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2978 /* Parm was passed in registers but lives on the stack. */
2980 current_sym_code = N_PSYM;
2981 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2982 in which case we want the value of that CONST_INT,
2983 or (MEM (REG ...)),
2984 in which case we use a value of zero. */
2985 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2986 current_sym_value = 0;
2987 else
2988 current_sym_value
2989 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2991 current_sym_addr = 0;
2993 /* Make a big endian correction if the mode of the type of the
2994 parameter is not the same as the mode of the rtl. */
2995 if (BYTES_BIG_ENDIAN
2996 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2997 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2999 current_sym_value +=
3000 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3001 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
3004 FORCE_TEXT;
3005 if (DECL_NAME (parms))
3007 current_sym_nchars
3008 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
3010 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
3011 IDENTIFIER_POINTER (DECL_NAME (parms)),
3012 DBX_MEMPARM_STABS_LETTER);
3014 else
3016 current_sym_nchars = 8;
3017 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
3018 DBX_MEMPARM_STABS_LETTER);
3021 current_sym_value
3022 = DEBUGGER_ARG_OFFSET (current_sym_value,
3023 XEXP (DECL_RTL (parms), 0));
3024 dbxout_type (TREE_TYPE (parms), 0);
3025 dbxout_finish_symbol (parms);
3028 DBXOUT_DECR_NESTING;
3031 /* Output definitions for the places where parms live during the function,
3032 when different from where they were passed, when the parms were passed
3033 in memory.
3035 It is not useful to do this for parms passed in registers
3036 that live during the function in different registers, because it is
3037 impossible to look in the passed register for the passed value,
3038 so we use the within-the-function register to begin with.
3040 PARMS is a chain of PARM_DECL nodes. */
3042 void
3043 dbxout_reg_parms (tree parms)
3045 ++debug_nesting;
3047 for (; parms; parms = TREE_CHAIN (parms))
3048 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3050 dbxout_prepare_symbol (parms);
3052 /* Report parms that live in registers during the function
3053 but were passed in memory. */
3054 if (GET_CODE (DECL_RTL (parms)) == REG
3055 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3056 dbxout_symbol_location (parms, TREE_TYPE (parms),
3057 0, DECL_RTL (parms));
3058 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3059 dbxout_symbol_location (parms, TREE_TYPE (parms),
3060 0, DECL_RTL (parms));
3061 /* Report parms that live in memory but not where they were passed. */
3062 else if (GET_CODE (DECL_RTL (parms)) == MEM
3063 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3064 dbxout_symbol_location (parms, TREE_TYPE (parms),
3065 0, DECL_RTL (parms));
3067 DBXOUT_DECR_NESTING;
3070 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3071 output definitions of those names, in raw form */
3073 static void
3074 dbxout_args (tree args)
3076 while (args)
3078 putc (',', asmfile);
3079 dbxout_type (TREE_VALUE (args), 0);
3080 CHARS (1);
3081 args = TREE_CHAIN (args);
3085 /* Output everything about a symbol block (a BLOCK node
3086 that represents a scope level),
3087 including recursive output of contained blocks.
3089 BLOCK is the BLOCK node.
3090 DEPTH is its depth within containing symbol blocks.
3091 ARGS is usually zero; but for the outermost block of the
3092 body of a function, it is a chain of PARM_DECLs for the function parameters.
3093 We output definitions of all the register parms
3094 as if they were local variables of that block.
3096 If -g1 was used, we count blocks just the same, but output nothing
3097 except for the outermost block.
3099 Actually, BLOCK may be several blocks chained together.
3100 We handle them all in sequence. */
3102 static void
3103 dbxout_block (tree block, int depth, tree args)
3105 int blocknum = -1;
3107 #if DBX_BLOCKS_FUNCTION_RELATIVE
3108 const char *begin_label;
3109 if (current_function_func_begin_label != NULL_TREE)
3110 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
3111 else
3112 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3113 #endif
3115 while (block)
3117 /* Ignore blocks never expanded or otherwise marked as real. */
3118 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3120 int did_output;
3122 /* In dbx format, the syms of a block come before the N_LBRAC.
3123 If nothing is output, we don't need the N_LBRAC, either. */
3124 did_output = 0;
3125 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3126 did_output = dbxout_syms (BLOCK_VARS (block));
3127 if (args)
3128 dbxout_reg_parms (args);
3130 /* Now output an N_LBRAC symbol to represent the beginning of
3131 the block. Use the block's tree-walk order to generate
3132 the assembler symbols LBBn and LBEn
3133 that final will define around the code in this block. */
3134 if (depth > 0 && did_output)
3136 char buf[20];
3137 blocknum = BLOCK_NUMBER (block);
3138 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3140 if (BLOCK_HANDLER_BLOCK (block))
3142 /* A catch block. Must precede N_LBRAC. */
3143 tree decl = BLOCK_VARS (block);
3144 while (decl)
3146 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
3147 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
3148 assemble_name (asmfile, buf);
3149 fprintf (asmfile, "\n");
3150 decl = TREE_CHAIN (decl);
3154 #ifdef DBX_OUTPUT_LBRAC
3155 DBX_OUTPUT_LBRAC (asmfile, buf);
3156 #else
3157 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
3158 assemble_name (asmfile, buf);
3159 #if DBX_BLOCKS_FUNCTION_RELATIVE
3160 putc ('-', asmfile);
3161 assemble_name (asmfile, begin_label);
3162 #endif
3163 fprintf (asmfile, "\n");
3164 #endif
3167 /* Output the subblocks. */
3168 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3170 /* Refer to the marker for the end of the block. */
3171 if (depth > 0 && did_output)
3173 char buf[20];
3174 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3175 #ifdef DBX_OUTPUT_RBRAC
3176 DBX_OUTPUT_RBRAC (asmfile, buf);
3177 #else
3178 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3179 assemble_name (asmfile, buf);
3180 #if DBX_BLOCKS_FUNCTION_RELATIVE
3181 putc ('-', asmfile);
3182 assemble_name (asmfile, begin_label);
3183 #endif
3184 fprintf (asmfile, "\n");
3185 #endif
3188 block = BLOCK_CHAIN (block);
3192 /* Output the information about a function and its arguments and result.
3193 Usually this follows the function's code,
3194 but on some systems, it comes before. */
3196 #if defined (DBX_DEBUGGING_INFO)
3197 static void
3198 dbxout_begin_function (tree decl)
3200 int saved_tree_used1 = TREE_USED (decl);
3201 TREE_USED (decl) = 1;
3202 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3204 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3205 TREE_USED (DECL_RESULT (decl)) = 1;
3206 dbxout_symbol (decl, 0);
3207 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3209 else
3210 dbxout_symbol (decl, 0);
3211 TREE_USED (decl) = saved_tree_used1;
3213 dbxout_parms (DECL_ARGUMENTS (decl));
3214 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3215 dbxout_symbol (DECL_RESULT (decl), 1);
3217 #endif /* DBX_DEBUGGING_INFO */
3219 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3221 #include "gt-dbxout.h"