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