Missed one in last change.
[official-gcc.git] / gcc / dbxout.c
blobcd17805466004aade18314f72e7ff619eb335833
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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 /* Output dbx-format symbol table data.
24 This consists of many symbol table entries, each of them
25 a .stabs assembler pseudo-op with four operands:
26 a "name" which is really a description of one symbol and its type,
27 a "code", which is a symbol defined in stab.h whose name starts with N_,
28 an unused operand always 0,
29 and a "value" which is an address or an offset.
30 The name is enclosed in doublequote characters.
32 Each function, variable, typedef, and structure tag
33 has a symbol table entry to define it.
34 The beginning and end of each level of name scoping within
35 a function are also marked by special symbol table entries.
37 The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
38 and a data type number. The data type number may be followed by
39 "=" and a type definition; normally this will happen the first time
40 the type number is mentioned. The type definition may refer to
41 other types by number, and those type numbers may be followed
42 by "=" and nested definitions.
44 This can make the "name" quite long.
45 When a name is more than 80 characters, we split the .stabs pseudo-op
46 into two .stabs pseudo-ops, both sharing the same "code" and "value".
47 The first one is marked as continued with a double-backslash at the
48 end of its "name".
50 The kind-of-symbol letter distinguished function names from global
51 variables from file-scope variables from parameters from auto
52 variables in memory from typedef names from register variables.
53 See `dbxout_symbol'.
55 The "code" is mostly redundant with the kind-of-symbol letter
56 that goes in the "name", but not entirely: for symbols located
57 in static storage, the "code" says which segment the address is in,
58 which controls how it is relocated.
60 The "value" for a symbol in static storage
61 is the core address of the symbol (actually, the assembler
62 label for the symbol). For a symbol located in a stack slot
63 it is the stack offset; for one in a register, the register number.
64 For a typedef symbol, it is zero.
66 If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
67 output while in the text section.
69 For more on data type definitions, see `dbxout_type'. */
71 #include "config.h"
72 #include "system.h"
73 #include "coretypes.h"
74 #include "tm.h"
76 #include "tree.h"
77 #include "rtl.h"
78 #include "flags.h"
79 #include "regs.h"
80 #include "insn-config.h"
81 #include "reload.h"
82 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions. */
83 #include "dbxout.h"
84 #include "toplev.h"
85 #include "tm_p.h"
86 #include "ggc.h"
87 #include "debug.h"
88 #include "function.h"
89 #include "target.h"
90 #include "langhooks.h"
92 #ifdef XCOFF_DEBUGGING_INFO
93 #include "xcoffout.h"
94 #endif
96 #undef DBXOUT_DECR_NESTING
97 #define DBXOUT_DECR_NESTING \
98 if (--debug_nesting == 0 && symbol_queue_index > 0) \
99 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
101 #undef DBXOUT_DECR_NESTING_AND_RETURN
102 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
103 do {--debug_nesting; return (x);} while (0)
105 #ifndef ASM_STABS_OP
106 #define ASM_STABS_OP "\t.stabs\t"
107 #endif
109 #ifndef ASM_STABN_OP
110 #define ASM_STABN_OP "\t.stabn\t"
111 #endif
113 #ifndef DBX_TYPE_DECL_STABS_CODE
114 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
115 #endif
117 #ifndef DBX_STATIC_CONST_VAR_CODE
118 #define DBX_STATIC_CONST_VAR_CODE N_FUN
119 #endif
121 #ifndef DBX_REGPARM_STABS_CODE
122 #define DBX_REGPARM_STABS_CODE N_RSYM
123 #endif
125 #ifndef DBX_REGPARM_STABS_LETTER
126 #define DBX_REGPARM_STABS_LETTER 'P'
127 #endif
129 /* This is used for parameters passed by invisible reference in a register. */
130 #ifndef GDB_INV_REF_REGPARM_STABS_LETTER
131 #define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
132 #endif
134 #ifndef DBX_MEMPARM_STABS_LETTER
135 #define DBX_MEMPARM_STABS_LETTER 'p'
136 #endif
138 #ifndef FILE_NAME_JOINER
139 #define FILE_NAME_JOINER "/"
140 #endif
142 /* GDB needs to know that the stabs were generated by GCC. We emit an
143 N_OPT stab at the beginning of the source file to indicate this.
144 The string is historical, and different on a very few targets. */
145 #ifndef STABS_GCC_MARKER
146 #define STABS_GCC_MARKER "gcc2_compiled."
147 #endif
149 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
151 /* Structure recording information about a C data type.
152 The status element says whether we have yet output
153 the definition of the type. TYPE_XREF says we have
154 output it as a cross-reference only.
155 The file_number and type_number elements are used if DBX_USE_BINCL
156 is defined. */
158 struct typeinfo GTY(())
160 enum typestatus status;
161 int file_number;
162 int type_number;
165 /* Vector recording information about C data types.
166 When we first notice a data type (a tree node),
167 we assign it a number using next_type_number.
168 That is its index in this vector. */
170 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
172 /* Number of elements of space allocated in `typevec'. */
174 static GTY(()) int typevec_len;
176 /* In dbx output, each type gets a unique number.
177 This is the number for the next type output.
178 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
180 static GTY(()) int next_type_number;
182 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
184 /* When using N_BINCL in dbx output, each type number is actually a
185 pair of the file number and the type number within the file.
186 This is a stack of input files. */
188 struct dbx_file GTY(())
190 struct dbx_file *next;
191 int file_number;
192 int next_type_number;
193 enum binclstatus bincl_status; /* Keep track of lazy bincl. */
194 const char *pending_bincl_name; /* Name of bincl. */
195 struct dbx_file *prev; /* Chain to traverse all pending bincls. */
198 /* This is the top of the stack. */
200 static GTY(()) struct dbx_file *current_file;
202 /* This is the next file number to use. */
204 static GTY(()) int next_file_number;
206 /* A counter for dbxout_function_end. */
208 static GTY(()) int scope_labelno;
210 /* A counter for dbxout_source_line. */
212 static GTY(()) int dbxout_source_line_counter;
214 /* Nonzero if we have actually used any of the GDB extensions
215 to the debugging format. The idea is that we use them for the
216 first time only if there's a strong reason, but once we have done that,
217 we use them whenever convenient. */
219 static GTY(()) int have_used_extensions = 0;
221 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
222 for the N_SO filename stabs label. */
224 static GTY(()) int source_label_number = 1;
226 /* Last source file name mentioned in a NOTE insn. */
228 static GTY(()) const char *lastfile;
230 /* Used by PCH machinery to detect if 'lastfile' should be reset to
231 base_input_file. */
232 static GTY(()) int lastfile_is_base;
234 /* Typical USG systems don't have stab.h, and they also have
235 no use for DBX-format debugging info. */
237 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
239 #ifdef DBX_USE_BINCL
240 /* If zero then there is no pending BINCL. */
241 static int pending_bincls = 0;
242 #endif
244 /* The original input file name. */
245 static const char *base_input_file;
247 /* Current working directory. */
249 static const char *cwd;
251 #ifdef DEBUG_SYMS_TEXT
252 #define FORCE_TEXT function_section (current_function_decl);
253 #else
254 #define FORCE_TEXT
255 #endif
257 #include "gstab.h"
259 #define STAB_CODE_TYPE enum __stab_debug_code
261 /* 1 if PARM is passed to this function in memory. */
263 #define PARM_PASSED_IN_MEMORY(PARM) \
264 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
266 /* A C expression for the integer offset value of an automatic variable
267 (N_LSYM) having address X (an RTX). */
268 #ifndef DEBUGGER_AUTO_OFFSET
269 #define DEBUGGER_AUTO_OFFSET(X) \
270 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
271 #endif
273 /* A C expression for the integer offset value of an argument (N_PSYM)
274 having address X (an RTX). The nominal offset is OFFSET. */
275 #ifndef DEBUGGER_ARG_OFFSET
276 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
277 #endif
279 /* Stream for writing to assembler file. */
281 static FILE *asmfile;
283 /* These variables are for dbxout_symbol to communicate to
284 dbxout_finish_symbol.
285 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
286 current_sym_value and current_sym_addr are two ways to address the
287 value to store in the symtab entry.
288 current_sym_addr if nonzero represents the value as an rtx.
289 If that is zero, current_sym_value is used. This is used
290 when the value is an offset (such as for auto variables,
291 register variables and parms). */
293 static STAB_CODE_TYPE current_sym_code;
294 static int current_sym_value;
295 static rtx current_sym_addr;
297 /* Number of chars of symbol-description generated so far for the
298 current symbol. Used by CHARS and CONTIN. */
300 static int current_sym_nchars;
302 /* Report having output N chars of the current symbol-description. */
304 #define CHARS(N) (current_sym_nchars += (N))
306 /* Break the current symbol-description, generating a continuation,
307 if it has become long. */
309 #ifndef DBX_CONTIN_LENGTH
310 #define DBX_CONTIN_LENGTH 80
311 #endif
313 #if DBX_CONTIN_LENGTH > 0
314 #define CONTIN \
315 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
316 #else
317 #define CONTIN do { } while (0)
318 #endif
320 #ifdef DBX_USE_BINCL
321 static void emit_bincl_stab (const char *c);
322 static void emit_pending_bincls (void);
323 #endif
324 static inline void emit_pending_bincls_if_required (void);
326 static void dbxout_init (const char *);
327 static void dbxout_finish (const char *);
328 static void dbxout_start_source_file (unsigned, const char *);
329 static void dbxout_end_source_file (unsigned);
330 static void dbxout_typedefs (tree);
331 static void dbxout_fptype_value (tree);
332 static void dbxout_type_index (tree);
333 #if DBX_CONTIN_LENGTH > 0
334 static void dbxout_continue (void);
335 #endif
336 static void dbxout_args (tree);
337 static void dbxout_type_fields (tree);
338 static void dbxout_type_method_1 (tree, const char *);
339 static void dbxout_type_methods (tree);
340 static void dbxout_range_type (tree);
341 static void dbxout_type (tree, int);
342 static bool print_int_cst_bounds_in_octal_p (tree);
343 static void print_int_cst_octal (tree);
344 static void print_octal (unsigned HOST_WIDE_INT, int);
345 static void print_wide_int (HOST_WIDE_INT);
346 static void dbxout_type_name (tree);
347 static void dbxout_class_name_qualifiers (tree);
348 static int dbxout_symbol_location (tree, tree, const char *, rtx);
349 static void dbxout_symbol_name (tree, const char *, int);
350 static void dbxout_prepare_symbol (tree);
351 static void dbxout_finish_symbol (tree);
352 static void dbxout_block (tree, int, tree);
353 static void dbxout_global_decl (tree);
354 static void dbxout_handle_pch (unsigned);
356 /* The debug hooks structure. */
357 #if defined (DBX_DEBUGGING_INFO)
359 static void dbxout_source_line (unsigned int, const char *);
360 static void dbxout_source_file (FILE *, const char *);
361 static void dbxout_function_end (void);
362 static void dbxout_begin_function (tree);
363 static void dbxout_begin_block (unsigned, unsigned);
364 static void dbxout_end_block (unsigned, unsigned);
365 static void dbxout_function_decl (tree);
367 const struct gcc_debug_hooks dbx_debug_hooks =
369 dbxout_init,
370 dbxout_finish,
371 debug_nothing_int_charstar,
372 debug_nothing_int_charstar,
373 dbxout_start_source_file,
374 dbxout_end_source_file,
375 dbxout_begin_block,
376 dbxout_end_block,
377 debug_true_tree, /* ignore_block */
378 dbxout_source_line, /* source_line */
379 dbxout_source_line, /* begin_prologue: just output line info */
380 debug_nothing_int_charstar, /* end_prologue */
381 debug_nothing_int_charstar, /* end_epilogue */
382 #ifdef DBX_FUNCTION_FIRST
383 dbxout_begin_function,
384 #else
385 debug_nothing_tree, /* begin_function */
386 #endif
387 debug_nothing_int, /* end_function */
388 dbxout_function_decl,
389 dbxout_global_decl, /* global_decl */
390 debug_nothing_tree, /* deferred_inline_function */
391 debug_nothing_tree, /* outlining_inline_function */
392 debug_nothing_rtx, /* label */
393 dbxout_handle_pch /* handle_pch */
395 #endif /* DBX_DEBUGGING_INFO */
397 #if defined (XCOFF_DEBUGGING_INFO)
398 const struct gcc_debug_hooks xcoff_debug_hooks =
400 dbxout_init,
401 dbxout_finish,
402 debug_nothing_int_charstar,
403 debug_nothing_int_charstar,
404 dbxout_start_source_file,
405 dbxout_end_source_file,
406 xcoffout_begin_block,
407 xcoffout_end_block,
408 debug_true_tree, /* ignore_block */
409 xcoffout_source_line,
410 xcoffout_begin_prologue, /* begin_prologue */
411 debug_nothing_int_charstar, /* end_prologue */
412 xcoffout_end_epilogue,
413 debug_nothing_tree, /* begin_function */
414 xcoffout_end_function,
415 debug_nothing_tree, /* function_decl */
416 dbxout_global_decl, /* global_decl */
417 debug_nothing_tree, /* deferred_inline_function */
418 debug_nothing_tree, /* outlining_inline_function */
419 debug_nothing_rtx, /* label */
420 dbxout_handle_pch /* handle_pch */
422 #endif /* XCOFF_DEBUGGING_INFO */
424 #if defined (DBX_DEBUGGING_INFO)
425 static void
426 dbxout_function_end (void)
428 char lscope_label_name[100];
429 /* Convert Ltext into the appropriate format for local labels in case
430 the system doesn't insert underscores in front of user generated
431 labels. */
432 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
433 (*targetm.asm_out.internal_label) (asmfile, "Lscope", scope_labelno);
434 scope_labelno++;
436 /* By convention, GCC will mark the end of a function with an N_FUN
437 symbol and an empty string. */
438 #ifdef DBX_OUTPUT_NFUN
439 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
440 #else
441 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
442 assemble_name (asmfile, lscope_label_name);
443 putc ('-', asmfile);
444 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
445 fprintf (asmfile, "\n");
446 #endif
448 #endif /* DBX_DEBUGGING_INFO */
450 /* At the beginning of compilation, start writing the symbol table.
451 Initialize `typevec' and output the standard data types of C. */
453 static void
454 dbxout_init (const char *input_file_name)
456 char ltext_label_name[100];
457 tree syms = (*lang_hooks.decls.getdecls) ();
459 asmfile = asm_out_file;
461 typevec_len = 100;
462 typevec = (struct typeinfo *) ggc_calloc (typevec_len, sizeof typevec[0]);
464 /* Convert Ltext into the appropriate format for local labels in case
465 the system doesn't insert underscores in front of user generated
466 labels. */
467 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
469 /* Put the current working directory in an N_SO symbol. */
470 if (use_gnu_debug_info_extensions)
472 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
473 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
474 if (cwd)
476 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
477 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
478 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
479 fprintf (asmfile, "%s", ASM_STABS_OP);
480 output_quoted_string (asmfile, cwd);
481 fprintf (asmfile, ",%d,0,0,", N_SO);
482 assemble_name (asmfile, ltext_label_name);
483 fputc ('\n', asmfile);
484 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
488 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
489 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
490 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
491 /* We include outputting `Ltext:' here,
492 because that gives you a way to override it. */
493 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
494 fprintf (asmfile, "%s", ASM_STABS_OP);
495 output_quoted_string (asmfile, input_file_name);
496 fprintf (asmfile, ",%d,0,0,", N_SO);
497 assemble_name (asmfile, ltext_label_name);
498 fputc ('\n', asmfile);
499 text_section ();
500 (*targetm.asm_out.internal_label) (asmfile, "Ltext", 0);
501 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
503 #ifdef DBX_OUTPUT_GCC_MARKER
504 DBX_OUTPUT_GCC_MARKER (asmfile);
505 #else
506 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
507 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
508 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
509 #endif
511 base_input_file = lastfile = input_file_name;
513 next_type_number = 1;
515 #ifdef DBX_USE_BINCL
516 current_file = (struct dbx_file *) ggc_alloc (sizeof *current_file);
517 current_file->next = NULL;
518 current_file->file_number = 0;
519 current_file->next_type_number = 1;
520 next_file_number = 1;
521 current_file->prev = NULL;
522 current_file->bincl_status = BINCL_NOT_REQUIRED;
523 current_file->pending_bincl_name = NULL;
524 #endif
526 /* Make sure that types `int' and `char' have numbers 1 and 2.
527 Definitions of other integer types will refer to those numbers.
528 (Actually it should no longer matter what their numbers are.
529 Also, if any types with tags have been defined, dbxout_symbol
530 will output them first, so the numbers won't be 1 and 2. That
531 happens in C++. So it's a good thing it should no longer matter). */
533 #ifdef DBX_OUTPUT_STANDARD_TYPES
534 DBX_OUTPUT_STANDARD_TYPES (syms);
535 #endif
537 /* Get all permanent types that have typedef names,
538 and output them all, except for those already output. */
540 dbxout_typedefs (syms);
543 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
544 in the reverse order from that which is found in SYMS. */
546 static void
547 dbxout_typedefs (tree syms)
549 if (syms)
551 dbxout_typedefs (TREE_CHAIN (syms));
552 if (TREE_CODE (syms) == TYPE_DECL)
554 tree type = TREE_TYPE (syms);
555 if (TYPE_NAME (type)
556 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
557 && COMPLETE_TYPE_P (type)
558 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
559 dbxout_symbol (TYPE_NAME (type), 0);
564 #ifdef DBX_USE_BINCL
565 /* Emit BINCL stab using given name. */
566 static void
567 emit_bincl_stab (const char *name)
569 fprintf (asmfile, "%s", ASM_STABS_OP);
570 output_quoted_string (asmfile, name);
571 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
574 /* If there are pending bincls then it is time to emit all of them. */
576 static inline void
577 emit_pending_bincls_if_required ()
579 if (pending_bincls)
580 emit_pending_bincls ();
583 /* Emit all pending bincls. */
585 static void
586 emit_pending_bincls ()
588 struct dbx_file *f = current_file;
590 /* Find first pending bincl. */
591 while (f->bincl_status == BINCL_PENDING)
592 f = f->next;
594 /* Now emit all bincls. */
595 f = f->prev;
597 while (f)
599 if (f->bincl_status == BINCL_PENDING)
601 emit_bincl_stab (f->pending_bincl_name);
603 /* Update file number and status. */
604 f->file_number = next_file_number++;
605 f->bincl_status = BINCL_PROCESSED;
607 if (f == current_file)
608 break;
609 f = f->prev;
612 /* All pending bincls have been emitted. */
613 pending_bincls = 0;
616 #else
618 static inline void
619 emit_pending_bincls_if_required () {}
620 #endif
622 /* Change to reading from a new source file. Generate a N_BINCL stab. */
624 static void
625 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
626 const char *filename ATTRIBUTE_UNUSED)
628 #ifdef DBX_USE_BINCL
629 struct dbx_file *n = (struct dbx_file *) ggc_alloc (sizeof *n);
631 n->next = current_file;
632 n->next_type_number = 1;
633 /* Do not assign file number now.
634 Delay it until we actually emit BINCL. */
635 n->file_number = 0;
636 n->prev = NULL;
637 current_file->prev = n;
638 n->bincl_status = BINCL_PENDING;
639 n->pending_bincl_name = filename;
640 pending_bincls = 1;
641 current_file = n;
642 #endif
645 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
647 static void
648 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
650 #ifdef DBX_USE_BINCL
651 /* Emit EINCL stab only if BINCL is not pending. */
652 if (current_file->bincl_status == BINCL_PROCESSED)
653 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
654 current_file->bincl_status = BINCL_NOT_REQUIRED;
655 current_file = current_file->next;
656 #endif
659 /* Handle a few odd cases that occur when trying to make PCH files work. */
661 static void
662 dbxout_handle_pch (unsigned at_end)
664 if (! at_end)
666 /* When using the PCH, this file will be included, so we need to output
667 a BINCL. */
668 dbxout_start_source_file (0, lastfile);
670 /* The base file when using the PCH won't be the same as
671 the base file when it's being generated. */
672 lastfile = NULL;
674 else
676 /* ... and an EINCL. */
677 dbxout_end_source_file (0);
679 /* Deal with cases where 'lastfile' was never actually changed. */
680 lastfile_is_base = lastfile == NULL;
684 #if defined (DBX_DEBUGGING_INFO)
685 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
687 static void
688 dbxout_source_file (FILE *file, const char *filename)
690 if (lastfile == 0 && lastfile_is_base)
692 lastfile = base_input_file;
693 lastfile_is_base = 0;
696 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
698 char ltext_label_name[100];
700 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
701 source_label_number);
702 fprintf (file, "%s", ASM_STABS_OP);
703 output_quoted_string (file, filename);
704 fprintf (asmfile, ",%d,0,0,", N_SOL);
705 assemble_name (asmfile, ltext_label_name);
706 fputc ('\n', asmfile);
707 if (current_function_decl != NULL_TREE
708 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
709 ; /* Don't change section amid function. */
710 else
711 text_section ();
712 (*targetm.asm_out.internal_label) (file, "Ltext", source_label_number);
713 source_label_number++;
714 lastfile = filename;
718 /* Output a line number symbol entry for source file FILENAME and line
719 number LINENO. */
721 static void
722 dbxout_source_line (unsigned int lineno, const char *filename)
724 dbxout_source_file (asmfile, filename);
726 #ifdef ASM_OUTPUT_SOURCE_LINE
727 dbxout_source_line_counter += 1;
728 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno, dbxout_source_line_counter);
729 #else
730 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
731 #endif
734 /* Describe the beginning of an internal block within a function. */
736 static void
737 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
739 emit_pending_bincls_if_required ();
740 (*targetm.asm_out.internal_label) (asmfile, "LBB", n);
743 /* Describe the end line-number of an internal block within a function. */
745 static void
746 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
748 emit_pending_bincls_if_required ();
749 (*targetm.asm_out.internal_label) (asmfile, "LBE", n);
752 /* Output dbx data for a function definition.
753 This includes a definition of the function name itself (a symbol),
754 definitions of the parameters (locating them in the parameter list)
755 and then output the block that makes up the function's body
756 (including all the auto variables of the function). */
758 static void
759 dbxout_function_decl (tree decl)
761 emit_pending_bincls_if_required ();
762 #ifndef DBX_FUNCTION_FIRST
763 dbxout_begin_function (decl);
764 #endif
765 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
766 #ifdef DBX_OUTPUT_FUNCTION_END
767 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
768 #endif
769 if (use_gnu_debug_info_extensions
770 #if defined(NO_DBX_FUNCTION_END)
771 && ! NO_DBX_FUNCTION_END
772 #endif
773 && targetm.have_named_sections)
774 dbxout_function_end ();
777 #endif /* DBX_DEBUGGING_INFO */
779 /* Debug information for a global DECL. Called from toplev.c after
780 compilation proper has finished. */
781 static void
782 dbxout_global_decl (tree decl)
784 if (TREE_CODE (decl) == VAR_DECL
785 && ! DECL_EXTERNAL (decl)
786 && DECL_RTL_SET_P (decl)) /* Not necessary? */
788 int saved_tree_used = TREE_USED (decl);
789 TREE_USED (decl) = 1;
790 dbxout_symbol (decl, 0);
791 TREE_USED (decl) = saved_tree_used;
795 /* At the end of compilation, finish writing the symbol table.
796 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
797 to do nothing. */
799 static void
800 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
802 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
803 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
804 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
806 debug_free_queue ();
809 /* Output floating point type values used by the 'R' stab letter.
810 These numbers come from include/aout/stab_gnu.h in binutils/gdb.
812 There are only 3 real/complex types defined, and we need 7/6.
813 We use NF_SINGLE as a generic float type, and NF_COMPLEX as a generic
814 complex type. Since we have the type size anyways, we don't really need
815 to distinguish between different FP types, we only need to distinguish
816 between float and complex. This works fine with gdb.
818 We only use this for complex types, to avoid breaking backwards
819 compatibility for real types. complex types aren't in ISO C90, so it is
820 OK if old debuggers don't understand the debug info we emit for them. */
822 /* ??? These are supposed to be IEEE types, but we don't check for that.
823 We could perhaps add additional numbers for non-IEEE types if we need
824 them. */
826 static void
827 dbxout_fptype_value (tree type)
829 char value = '0';
830 enum machine_mode mode = TYPE_MODE (type);
832 if (TREE_CODE (type) == REAL_TYPE)
834 if (mode == SFmode)
835 value = '1';
836 else if (mode == DFmode)
837 value = '2';
838 else if (mode == TFmode || mode == XFmode)
839 value = '6';
840 else
841 /* Use NF_SINGLE as a generic real type for other sizes. */
842 value = '1';
844 else if (TREE_CODE (type) == COMPLEX_TYPE)
846 if (mode == SCmode)
847 value = '3';
848 else if (mode == DCmode)
849 value = '4';
850 else if (mode == TCmode || mode == XCmode)
851 value = '5';
852 else
853 /* Use NF_COMPLEX as a generic complex type for other sizes. */
854 value = '3';
856 else
857 abort ();
859 putc (value, asmfile);
860 CHARS (1);
863 /* Output the index of a type. */
865 static void
866 dbxout_type_index (tree type)
868 #ifndef DBX_USE_BINCL
869 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
870 CHARS (3);
871 #else
872 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
873 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
874 CHARS (9);
875 #endif
878 #if DBX_CONTIN_LENGTH > 0
879 /* Continue a symbol-description that gets too big.
880 End one symbol table entry with a double-backslash
881 and start a new one, eventually producing something like
882 .stabs "start......\\",code,0,value
883 .stabs "...rest",code,0,value */
885 static void
886 dbxout_continue (void)
888 emit_pending_bincls_if_required ();
889 #ifdef DBX_CONTIN_CHAR
890 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
891 #else
892 fprintf (asmfile, "\\\\");
893 #endif
894 dbxout_finish_symbol (NULL_TREE);
895 fprintf (asmfile, "%s\"", ASM_STABS_OP);
896 current_sym_nchars = 0;
898 #endif /* DBX_CONTIN_LENGTH > 0 */
900 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
901 This must be a separate function because anonymous unions require
902 recursive calls. */
904 static void
905 dbxout_type_fields (tree type)
907 tree tem;
909 /* Output the name, type, position (in bits), size (in bits) of each
910 field that we can support. */
911 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
913 /* Omit here local type decls until we know how to support them. */
914 if (TREE_CODE (tem) == TYPE_DECL
915 /* Omit fields whose position or size are variable or too large to
916 represent. */
917 || (TREE_CODE (tem) == FIELD_DECL
918 && (! host_integerp (bit_position (tem), 0)
919 || ! DECL_SIZE (tem)
920 || ! host_integerp (DECL_SIZE (tem), 1)))
921 /* Omit here the nameless fields that are used to skip bits. */
922 || DECL_IGNORED_P (tem))
923 continue;
925 else if (TREE_CODE (tem) != CONST_DECL)
927 /* Continue the line if necessary,
928 but not before the first field. */
929 if (tem != TYPE_FIELDS (type))
930 CONTIN;
932 if (DECL_NAME (tem))
934 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
935 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
937 else
939 fprintf (asmfile, ":");
940 CHARS (1);
943 if (use_gnu_debug_info_extensions
944 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
945 || TREE_CODE (tem) != FIELD_DECL))
947 have_used_extensions = 1;
948 putc ('/', asmfile);
949 putc ((TREE_PRIVATE (tem) ? '0'
950 : TREE_PROTECTED (tem) ? '1' : '2'),
951 asmfile);
952 CHARS (2);
955 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
956 && DECL_BIT_FIELD_TYPE (tem))
957 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
959 if (TREE_CODE (tem) == VAR_DECL)
961 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
963 tree name = DECL_ASSEMBLER_NAME (tem);
965 have_used_extensions = 1;
966 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
967 CHARS (IDENTIFIER_LENGTH (name) + 2);
969 else
971 /* If TEM is non-static, GDB won't understand it. */
972 fprintf (asmfile, ",0,0;");
973 CHARS (5);
976 else
978 putc (',', asmfile);
979 print_wide_int (int_bit_position (tem));
980 putc (',', asmfile);
981 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
982 putc (';', asmfile);
983 CHARS (3);
989 /* Subroutine of `dbxout_type_methods'. Output debug info about the
990 method described DECL. DEBUG_NAME is an encoding of the method's
991 type signature. ??? We may be able to do without DEBUG_NAME altogether
992 now. */
994 static void
995 dbxout_type_method_1 (tree decl, const char *debug_name)
997 char c1 = 'A', c2;
999 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1000 c2 = '?';
1001 else /* it's a METHOD_TYPE. */
1003 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1004 /* A for normal functions.
1005 B for `const' member functions.
1006 C for `volatile' member functions.
1007 D for `const volatile' member functions. */
1008 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1009 c1 += 1;
1010 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1011 c1 += 2;
1013 if (DECL_VINDEX (decl))
1014 c2 = '*';
1015 else
1016 c2 = '.';
1019 fprintf (asmfile, ":%s;%c%c%c", debug_name,
1020 TREE_PRIVATE (decl) ? '0'
1021 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
1022 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
1023 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1025 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1027 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
1028 putc (';', asmfile);
1029 CHARS (1);
1030 dbxout_type (DECL_CONTEXT (decl), 0);
1031 fprintf (asmfile, ";");
1032 CHARS (1);
1036 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1037 in TYPE. */
1039 static void
1040 dbxout_type_methods (tree type)
1042 /* C++: put out the method names and their parameter lists */
1043 tree methods = TYPE_METHODS (type);
1044 tree type_encoding;
1045 tree fndecl;
1046 tree last;
1047 char formatted_type_identifier_length[16];
1048 int type_identifier_length;
1050 if (methods == NULL_TREE)
1051 return;
1053 type_encoding = DECL_NAME (TYPE_NAME (type));
1055 #if 0
1056 /* C++: Template classes break some assumptions made by this code about
1057 the class names, constructor names, and encodings for assembler
1058 label names. For now, disable output of dbx info for them. */
1060 const char *ptr = IDENTIFIER_POINTER (type_encoding);
1061 /* This should use index. (mrs) */
1062 while (*ptr && *ptr != '<') ptr++;
1063 if (*ptr != 0)
1065 static int warned;
1066 if (!warned)
1067 warned = 1;
1068 return;
1071 #endif
1073 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
1075 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
1077 if (TREE_CODE (methods) != TREE_VEC)
1078 fndecl = methods;
1079 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1080 fndecl = TREE_VEC_ELT (methods, 0);
1081 else
1082 fndecl = TREE_VEC_ELT (methods, 1);
1084 while (fndecl)
1086 int need_prefix = 1;
1088 /* Group together all the methods for the same operation.
1089 These differ in the types of the arguments. */
1090 for (last = NULL_TREE;
1091 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1092 fndecl = TREE_CHAIN (fndecl))
1093 /* Output the name of the field (after overloading), as
1094 well as the name of the field before overloading, along
1095 with its parameter list */
1097 /* This is the "mangled" name of the method.
1098 It encodes the argument types. */
1099 const char *debug_name;
1101 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1102 include TEMPLATE_DECLs.) The debugger doesn't know what
1103 to do with such entities anyhow. */
1104 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1105 continue;
1107 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1109 CONTIN;
1111 last = fndecl;
1113 /* Also ignore abstract methods; those are only interesting to
1114 the DWARF backends. */
1115 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1116 continue;
1118 /* Redundantly output the plain name, since that's what gdb
1119 expects. */
1120 if (need_prefix)
1122 tree name = DECL_NAME (fndecl);
1123 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1124 CHARS (IDENTIFIER_LENGTH (name) + 2);
1125 need_prefix = 0;
1128 dbxout_type (TREE_TYPE (fndecl), 0);
1130 dbxout_type_method_1 (fndecl, debug_name);
1132 if (!need_prefix)
1134 putc (';', asmfile);
1135 CHARS (1);
1140 /* Emit a "range" type specification, which has the form:
1141 "r<index type>;<lower bound>;<upper bound>;".
1142 TYPE is an INTEGER_TYPE. */
1144 static void
1145 dbxout_range_type (tree type)
1147 fprintf (asmfile, "r");
1148 if (TREE_TYPE (type))
1149 dbxout_type (TREE_TYPE (type), 0);
1150 else if (TREE_CODE (type) != INTEGER_TYPE)
1151 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1152 else
1154 /* Traditionally, we made sure 'int' was type 1, and builtin types
1155 were defined to be sub-ranges of int. Unfortunately, this
1156 does not allow us to distinguish true sub-ranges from integer
1157 types. So, instead we define integer (non-sub-range) types as
1158 sub-ranges of themselves. This matters for Chill. If this isn't
1159 a subrange type, then we want to define it in terms of itself.
1160 However, in C, this may be an anonymous integer type, and we don't
1161 want to emit debug info referring to it. Just calling
1162 dbxout_type_index won't work anyways, because the type hasn't been
1163 defined yet. We make this work for both cases by checked to see
1164 whether this is a defined type, referring to it if it is, and using
1165 'int' otherwise. */
1166 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1167 dbxout_type_index (type);
1168 else
1169 dbxout_type_index (integer_type_node);
1172 if (TYPE_MIN_VALUE (type) != 0
1173 && host_integerp (TYPE_MIN_VALUE (type), 0))
1175 putc (';', asmfile);
1176 CHARS (1);
1177 if (print_int_cst_bounds_in_octal_p (type))
1178 print_int_cst_octal (TYPE_MIN_VALUE (type));
1179 else
1180 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1182 else
1184 fprintf (asmfile, ";0");
1185 CHARS (2);
1188 if (TYPE_MAX_VALUE (type) != 0
1189 && host_integerp (TYPE_MAX_VALUE (type), 0))
1191 putc (';', asmfile);
1192 CHARS (1);
1193 if (print_int_cst_bounds_in_octal_p (type))
1194 print_int_cst_octal (TYPE_MAX_VALUE (type));
1195 else
1196 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1197 putc (';', asmfile);
1198 CHARS (1);
1200 else
1202 fprintf (asmfile, ";-1;");
1203 CHARS (4);
1208 /* Output a reference to a type. If the type has not yet been
1209 described in the dbx output, output its definition now.
1210 For a type already defined, just refer to its definition
1211 using the type number.
1213 If FULL is nonzero, and the type has been described only with
1214 a forward-reference, output the definition now.
1215 If FULL is zero in this case, just refer to the forward-reference
1216 using the number previously allocated. */
1218 static void
1219 dbxout_type (tree type, int full)
1221 tree tem;
1222 tree main_variant;
1223 static int anonymous_type_number = 0;
1225 if (TREE_CODE (type) == VECTOR_TYPE)
1226 /* The frontend feeds us a representation for the vector as a struct
1227 containing an array. Pull out the array type. */
1228 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1230 /* If there was an input error and we don't really have a type,
1231 avoid crashing and write something that is at least valid
1232 by assuming `int'. */
1233 if (type == error_mark_node)
1234 type = integer_type_node;
1235 else
1237 if (TYPE_NAME (type)
1238 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1239 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1240 full = 0;
1243 /* Try to find the "main variant" with the same name. */
1244 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1245 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1246 main_variant = TREE_TYPE (TYPE_NAME (type));
1247 else
1248 main_variant = TYPE_MAIN_VARIANT (type);
1250 /* If we are not using extensions, stabs does not distinguish const and
1251 volatile, so there is no need to make them separate types. */
1252 if (!use_gnu_debug_info_extensions)
1253 type = main_variant;
1255 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1257 /* Type has no dbx number assigned. Assign next available number. */
1258 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1260 /* Make sure type vector is long enough to record about this type. */
1262 if (next_type_number == typevec_len)
1264 typevec
1265 = (struct typeinfo *) ggc_realloc (typevec,
1266 (typevec_len * 2
1267 * sizeof typevec[0]));
1268 memset ((char *) (typevec + typevec_len), 0,
1269 typevec_len * sizeof typevec[0]);
1270 typevec_len *= 2;
1273 #ifdef DBX_USE_BINCL
1274 emit_pending_bincls_if_required ();
1275 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1276 = current_file->file_number;
1277 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1278 = current_file->next_type_number++;
1279 #endif
1282 if (flag_debug_only_used_symbols)
1284 if ((TREE_CODE (type) == RECORD_TYPE
1285 || TREE_CODE (type) == UNION_TYPE
1286 || TREE_CODE (type) == QUAL_UNION_TYPE
1287 || TREE_CODE (type) == ENUMERAL_TYPE)
1288 && TYPE_STUB_DECL (type)
1289 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (type))) == 'd'
1290 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1291 debug_queue_symbol (TYPE_STUB_DECL (type));
1292 else if (TYPE_NAME (type)
1293 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1294 debug_queue_symbol (TYPE_NAME (type));
1297 /* Output the number of this type, to refer to it. */
1298 dbxout_type_index (type);
1300 #ifdef DBX_TYPE_DEFINED
1301 if (DBX_TYPE_DEFINED (type))
1302 return;
1303 #endif
1305 /* If this type's definition has been output or is now being output,
1306 that is all. */
1308 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1310 case TYPE_UNSEEN:
1311 break;
1312 case TYPE_XREF:
1313 /* If we have already had a cross reference,
1314 and either that's all we want or that's the best we could do,
1315 don't repeat the cross reference.
1316 Sun dbx crashes if we do. */
1317 if (! full || !COMPLETE_TYPE_P (type)
1318 /* No way in DBX fmt to describe a variable size. */
1319 || ! host_integerp (TYPE_SIZE (type), 1))
1320 return;
1321 break;
1322 case TYPE_DEFINED:
1323 return;
1326 #ifdef DBX_NO_XREFS
1327 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1328 leave the type-number completely undefined rather than output
1329 a cross-reference. If we have already used GNU debug info extensions,
1330 then it is OK to output a cross reference. This is necessary to get
1331 proper C++ debug output. */
1332 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1333 || TREE_CODE (type) == QUAL_UNION_TYPE
1334 || TREE_CODE (type) == ENUMERAL_TYPE)
1335 && ! use_gnu_debug_info_extensions)
1336 /* We must use the same test here as we use twice below when deciding
1337 whether to emit a cross-reference. */
1338 if ((TYPE_NAME (type) != 0
1339 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1340 && DECL_IGNORED_P (TYPE_NAME (type)))
1341 && !full)
1342 || !COMPLETE_TYPE_P (type)
1343 /* No way in DBX fmt to describe a variable size. */
1344 || ! host_integerp (TYPE_SIZE (type), 1))
1346 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1347 return;
1349 #endif
1351 /* Output a definition now. */
1353 fprintf (asmfile, "=");
1354 CHARS (1);
1356 /* Mark it as defined, so that if it is self-referent
1357 we will not get into an infinite recursion of definitions. */
1359 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1361 /* If this type is a variant of some other, hand off. Types with
1362 different names are usefully distinguished. We only distinguish
1363 cv-qualified types if we're using extensions. */
1364 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1366 putc ('k', asmfile);
1367 CHARS (1);
1368 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1369 return;
1371 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1373 putc ('B', asmfile);
1374 CHARS (1);
1375 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1376 return;
1378 else if (main_variant != TYPE_MAIN_VARIANT (type))
1380 if (flag_debug_only_used_symbols)
1382 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1384 if ((TREE_CODE (orig_type) == RECORD_TYPE
1385 || TREE_CODE (orig_type) == UNION_TYPE
1386 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1387 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1388 && TYPE_STUB_DECL (orig_type)
1389 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1390 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1392 /* 'type' is a typedef; output the type it refers to. */
1393 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1394 return;
1396 /* else continue. */
1398 switch (TREE_CODE (type))
1400 case VOID_TYPE:
1401 case LANG_TYPE:
1402 /* For a void type, just define it as itself; ie, "5=5".
1403 This makes us consider it defined
1404 without saying what it is. The debugger will make it
1405 a void type when the reference is seen, and nothing will
1406 ever override that default. */
1407 dbxout_type_index (type);
1408 break;
1410 case INTEGER_TYPE:
1411 if (type == char_type_node && ! TREE_UNSIGNED (type))
1413 /* Output the type `char' as a subrange of itself!
1414 I don't understand this definition, just copied it
1415 from the output of pcc.
1416 This used to use `r2' explicitly and we used to
1417 take care to make sure that `char' was type number 2. */
1418 fprintf (asmfile, "r");
1419 CHARS (1);
1420 dbxout_type_index (type);
1421 fprintf (asmfile, ";0;127;");
1422 CHARS (7);
1425 /* If this is a subtype of another integer type, always prefer to
1426 write it as a subtype. */
1427 else if (TREE_TYPE (type) != 0
1428 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1430 /* If the size is non-standard, say what it is if we can use
1431 GDB extensions. */
1433 if (use_gnu_debug_info_extensions
1434 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1436 have_used_extensions = 1;
1437 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1438 CHARS (5);
1441 dbxout_range_type (type);
1444 else
1446 /* If the size is non-standard, say what it is if we can use
1447 GDB extensions. */
1449 if (use_gnu_debug_info_extensions
1450 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1452 have_used_extensions = 1;
1453 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1454 CHARS (5);
1457 if (print_int_cst_bounds_in_octal_p (type))
1459 fprintf (asmfile, "r");
1460 CHARS (1);
1462 /* If this type derives from another type, output type index of
1463 parent type. This is particularly important when parent type
1464 is an enumerated type, because not generating the parent type
1465 index would transform the definition of this enumerated type
1466 into a plain unsigned type. */
1467 if (TREE_TYPE (type) != 0)
1468 dbxout_type_index (TREE_TYPE (type));
1469 else
1470 dbxout_type_index (type);
1472 fprintf (asmfile, ";");
1473 CHARS (1);
1474 print_int_cst_octal (TYPE_MIN_VALUE (type));
1475 fprintf (asmfile, ";");
1476 CHARS (1);
1477 print_int_cst_octal (TYPE_MAX_VALUE (type));
1478 fprintf (asmfile, ";");
1479 CHARS (1);
1482 else
1483 /* Output other integer types as subranges of `int'. */
1484 dbxout_range_type (type);
1487 break;
1489 case REAL_TYPE:
1490 /* This used to say `r1' and we used to take care
1491 to make sure that `int' was type number 1. */
1492 fprintf (asmfile, "r");
1493 CHARS (1);
1494 dbxout_type_index (integer_type_node);
1495 putc (';', asmfile);
1496 CHARS (1);
1497 print_wide_int (int_size_in_bytes (type));
1498 fputs (";0;", asmfile);
1499 CHARS (3);
1500 break;
1502 case CHAR_TYPE:
1503 if (use_gnu_debug_info_extensions)
1505 have_used_extensions = 1;
1506 fputs ("@s", asmfile);
1507 CHARS (2);
1508 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1509 fputs (";-20;", asmfile);
1510 CHARS (4);
1512 else
1514 /* Output the type `char' as a subrange of itself.
1515 That is what pcc seems to do. */
1516 fprintf (asmfile, "r");
1517 CHARS (1);
1518 dbxout_type_index (char_type_node);
1519 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1520 CHARS (7);
1522 break;
1524 case BOOLEAN_TYPE:
1525 if (use_gnu_debug_info_extensions)
1527 have_used_extensions = 1;
1528 fputs ("@s", asmfile);
1529 CHARS (2);
1530 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1531 fputs (";-16;", asmfile);
1532 CHARS (4);
1534 else /* Define as enumeral type (False, True) */
1536 fprintf (asmfile, "eFalse:0,True:1,;");
1537 CHARS (17);
1539 break;
1541 case FILE_TYPE:
1542 putc ('d', asmfile);
1543 CHARS (1);
1544 dbxout_type (TREE_TYPE (type), 0);
1545 break;
1547 case COMPLEX_TYPE:
1548 /* Differs from the REAL_TYPE by its new data type number */
1550 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1552 putc ('R', asmfile);
1553 CHARS (1);
1554 dbxout_fptype_value (type);
1555 putc (';', asmfile);
1556 CHARS (1);
1557 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1558 fputs (";0;", asmfile);
1559 CHARS (3);
1561 else
1563 /* Output a complex integer type as a structure,
1564 pending some other way to do it. */
1565 putc ('s', asmfile);
1566 CHARS (1);
1567 print_wide_int (int_size_in_bytes (type));
1568 fprintf (asmfile, "real:");
1569 CHARS (5);
1571 dbxout_type (TREE_TYPE (type), 0);
1572 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1573 CHARS (7);
1574 fprintf (asmfile, "imag:");
1575 CHARS (5);
1576 dbxout_type (TREE_TYPE (type), 0);
1577 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1578 TYPE_PRECISION (TREE_TYPE (type)));
1579 CHARS (10);
1581 break;
1583 case SET_TYPE:
1584 if (use_gnu_debug_info_extensions)
1586 have_used_extensions = 1;
1587 fputs ("@s", asmfile);
1588 CHARS (2);
1589 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1590 putc (';', asmfile);
1591 CHARS (1);
1593 /* Check if a bitstring type, which in Chill is
1594 different from a [power]set. */
1595 if (TYPE_STRING_FLAG (type))
1597 fprintf (asmfile, "@S;");
1598 CHARS (3);
1601 putc ('S', asmfile);
1602 CHARS (1);
1603 dbxout_type (TYPE_DOMAIN (type), 0);
1604 break;
1606 case ARRAY_TYPE:
1607 /* Make arrays of packed bits look like bitstrings for chill. */
1608 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1610 have_used_extensions = 1;
1611 fputs ("@s", asmfile);
1612 CHARS (2);
1613 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1614 fprintf (asmfile, ";@S;S");
1615 CHARS (5);
1616 dbxout_type (TYPE_DOMAIN (type), 0);
1617 break;
1620 /* Output "a" followed by a range type definition
1621 for the index type of the array
1622 followed by a reference to the target-type.
1623 ar1;0;N;M for a C array of type M and size N+1. */
1624 /* Check if a character string type, which in Chill is
1625 different from an array of characters. */
1626 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1628 have_used_extensions = 1;
1629 fprintf (asmfile, "@S;");
1630 CHARS (3);
1632 tem = TYPE_DOMAIN (type);
1633 if (tem == NULL)
1635 fprintf (asmfile, "ar");
1636 CHARS (2);
1637 dbxout_type_index (integer_type_node);
1638 fprintf (asmfile, ";0;-1;");
1639 CHARS (6);
1641 else
1643 fprintf (asmfile, "a");
1644 CHARS (1);
1645 dbxout_range_type (tem);
1648 dbxout_type (TREE_TYPE (type), 0);
1649 break;
1651 case RECORD_TYPE:
1652 case UNION_TYPE:
1653 case QUAL_UNION_TYPE:
1655 int i, n_baseclasses = 0;
1657 if (TYPE_BINFO (type) != 0
1658 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1659 && TYPE_BINFO_BASETYPES (type) != 0)
1660 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1662 /* Output a structure type. We must use the same test here as we
1663 use in the DBX_NO_XREFS case above. */
1664 if ((TYPE_NAME (type) != 0
1665 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1666 && DECL_IGNORED_P (TYPE_NAME (type)))
1667 && !full)
1668 || !COMPLETE_TYPE_P (type)
1669 /* No way in DBX fmt to describe a variable size. */
1670 || ! host_integerp (TYPE_SIZE (type), 1))
1672 /* If the type is just a cross reference, output one
1673 and mark the type as partially described.
1674 If it later becomes defined, we will output
1675 its real definition.
1676 If the type has a name, don't nest its definition within
1677 another type's definition; instead, output an xref
1678 and let the definition come when the name is defined. */
1679 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1680 CHARS (2);
1681 #if 0 /* This assertion is legitimately false in C++. */
1682 /* We shouldn't be outputting a reference to a type before its
1683 definition unless the type has a tag name.
1684 A typedef name without a tag name should be impossible. */
1685 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1686 abort ();
1687 #endif
1688 if (TYPE_NAME (type) != 0)
1689 dbxout_type_name (type);
1690 else
1692 fprintf (asmfile, "$$%d", anonymous_type_number++);
1693 CHARS (5);
1696 fprintf (asmfile, ":");
1697 CHARS (1);
1698 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1699 break;
1702 /* Identify record or union, and print its size. */
1703 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1704 CHARS (1);
1705 print_wide_int (int_size_in_bytes (type));
1707 if (use_gnu_debug_info_extensions)
1709 if (n_baseclasses)
1711 have_used_extensions = 1;
1712 fprintf (asmfile, "!%d,", n_baseclasses);
1713 CHARS (8);
1716 for (i = 0; i < n_baseclasses; i++)
1718 tree binfo = TYPE_BINFO (type);
1719 tree child = BINFO_BASETYPE (binfo, i);
1720 tree access = (BINFO_BASEACCESSES (binfo)
1721 ? BINFO_BASEACCESS (binfo, i) : access_public_node);
1723 if (use_gnu_debug_info_extensions)
1725 have_used_extensions = 1;
1726 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1727 putc (access == access_public_node ? '2' : '0', asmfile);
1728 CHARS (2);
1729 if (TREE_VIA_VIRTUAL (child)
1730 && strcmp (lang_hooks.name, "GNU C++") == 0)
1731 /* For a virtual base, print the (negative) offset within
1732 the vtable where we must look to find the necessary
1733 adjustment. */
1734 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1735 * BITS_PER_UNIT);
1736 else
1737 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1738 * BITS_PER_UNIT);
1739 putc (',', asmfile);
1740 CHARS (1);
1741 dbxout_type (BINFO_TYPE (child), 0);
1742 putc (';', asmfile);
1743 CHARS (1);
1745 else
1747 /* Print out the base class information with fields
1748 which have the same names at the types they hold. */
1749 dbxout_type_name (BINFO_TYPE (child));
1750 putc (':', asmfile);
1751 CHARS (1);
1752 dbxout_type (BINFO_TYPE (child), full);
1753 putc (',', asmfile);
1754 CHARS (1);
1755 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1756 * BITS_PER_UNIT);
1757 putc (',', asmfile);
1758 CHARS (1);
1759 print_wide_int (tree_low_cst (DECL_SIZE
1760 (TYPE_NAME
1761 (BINFO_TYPE (child))),
1763 * BITS_PER_UNIT);
1764 putc (';', asmfile);
1765 CHARS (1);
1770 /* Write out the field declarations. */
1771 dbxout_type_fields (type);
1772 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1774 have_used_extensions = 1;
1775 dbxout_type_methods (type);
1778 putc (';', asmfile);
1779 CHARS (1);
1781 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1782 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1783 && TYPE_VFIELD (type))
1785 have_used_extensions = 1;
1787 /* Tell GDB+ that it may keep reading. */
1788 putc ('~', asmfile);
1789 CHARS (1);
1791 /* We need to write out info about what field this class
1792 uses as its "main" vtable pointer field, because if this
1793 field is inherited from a base class, GDB cannot necessarily
1794 figure out which field it's using in time. */
1795 if (TYPE_VFIELD (type))
1797 putc ('%', asmfile);
1798 CHARS (1);
1799 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1802 putc (';', asmfile);
1803 CHARS (1);
1805 break;
1807 case ENUMERAL_TYPE:
1808 /* We must use the same test here as we use in the DBX_NO_XREFS case
1809 above. We simplify it a bit since an enum will never have a variable
1810 size. */
1811 if ((TYPE_NAME (type) != 0
1812 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1813 && DECL_IGNORED_P (TYPE_NAME (type)))
1814 && !full)
1815 || !COMPLETE_TYPE_P (type))
1817 fprintf (asmfile, "xe");
1818 CHARS (2);
1819 dbxout_type_name (type);
1820 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1821 putc (':', asmfile);
1822 CHARS (1);
1823 return;
1825 if (use_gnu_debug_info_extensions
1826 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1828 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1829 CHARS (5);
1832 putc ('e', asmfile);
1833 CHARS (1);
1834 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1836 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1837 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1838 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1839 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1840 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1841 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1842 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1843 else
1844 print_int_cst_octal (TREE_VALUE (tem));
1846 putc (',', asmfile);
1847 CHARS (1);
1848 if (TREE_CHAIN (tem) != 0)
1849 CONTIN;
1852 putc (';', asmfile);
1853 CHARS (1);
1854 break;
1856 case POINTER_TYPE:
1857 putc ('*', asmfile);
1858 CHARS (1);
1859 dbxout_type (TREE_TYPE (type), 0);
1860 break;
1862 case METHOD_TYPE:
1863 if (use_gnu_debug_info_extensions)
1865 have_used_extensions = 1;
1866 putc ('#', asmfile);
1867 CHARS (1);
1869 /* Write the argument types out longhand. */
1870 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1871 putc (',', asmfile);
1872 CHARS (1);
1873 dbxout_type (TREE_TYPE (type), 0);
1874 dbxout_args (TYPE_ARG_TYPES (type));
1875 putc (';', asmfile);
1876 CHARS (1);
1878 else
1879 /* Treat it as a function type. */
1880 dbxout_type (TREE_TYPE (type), 0);
1881 break;
1883 case OFFSET_TYPE:
1884 if (use_gnu_debug_info_extensions)
1886 have_used_extensions = 1;
1887 putc ('@', asmfile);
1888 CHARS (1);
1889 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1890 putc (',', asmfile);
1891 CHARS (1);
1892 dbxout_type (TREE_TYPE (type), 0);
1894 else
1895 /* Should print as an int, because it is really just an offset. */
1896 dbxout_type (integer_type_node, 0);
1897 break;
1899 case REFERENCE_TYPE:
1900 if (use_gnu_debug_info_extensions)
1901 have_used_extensions = 1;
1902 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1903 CHARS (1);
1904 dbxout_type (TREE_TYPE (type), 0);
1905 break;
1907 case FUNCTION_TYPE:
1908 putc ('f', asmfile);
1909 CHARS (1);
1910 dbxout_type (TREE_TYPE (type), 0);
1911 break;
1913 default:
1914 abort ();
1918 /* Return nonzero if the given type represents an integer whose bounds
1919 should be printed in octal format. */
1921 static bool
1922 print_int_cst_bounds_in_octal_p (tree type)
1924 /* If we can use GDB extensions and the size is wider than a long
1925 (the size used by GDB to read them) or we may have trouble writing
1926 the bounds the usual way, write them in octal. Note the test is for
1927 the *target's* size of "long", not that of the host. The host test
1928 is just to make sure we can write it out in case the host wide int
1929 is narrower than the target "long".
1931 For unsigned types, we use octal if they are the same size or larger.
1932 This is because we print the bounds as signed decimal, and hence they
1933 can't span same size unsigned types. */
1935 if (use_gnu_debug_info_extensions
1936 && TYPE_MIN_VALUE (type) != 0
1937 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1938 && TYPE_MAX_VALUE (type) != 0
1939 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1940 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1941 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1942 && TREE_UNSIGNED (type))
1943 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1944 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1945 && TREE_UNSIGNED (type))))
1946 return TRUE;
1947 else
1948 return FALSE;
1951 /* Print the value of integer constant C, in octal,
1952 handling double precision. */
1954 static void
1955 print_int_cst_octal (tree c)
1957 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1958 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1959 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1960 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1962 /* GDB wants constants with no extra leading "1" bits, so
1963 we need to remove any sign-extension that might be
1964 present. */
1965 if (width == HOST_BITS_PER_WIDE_INT * 2)
1967 else if (width > HOST_BITS_PER_WIDE_INT)
1968 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1969 else if (width == HOST_BITS_PER_WIDE_INT)
1970 high = 0;
1971 else
1972 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1974 fprintf (asmfile, "0");
1975 CHARS (1);
1977 if (excess == 3)
1979 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1980 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1982 else
1984 unsigned HOST_WIDE_INT beg = high >> excess;
1985 unsigned HOST_WIDE_INT middle
1986 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1987 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1988 unsigned HOST_WIDE_INT end
1989 = low & (((unsigned HOST_WIDE_INT) 1
1990 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1991 - 1);
1993 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1994 CHARS (2);
1995 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1999 static void
2000 print_octal (unsigned HOST_WIDE_INT value, int digits)
2002 int i;
2004 for (i = digits - 1; i >= 0; i--)
2005 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
2007 CHARS (digits);
2010 /* Output C in decimal while adjusting the number of digits written. */
2012 static void
2013 print_wide_int (HOST_WIDE_INT c)
2015 int digs = 0;
2017 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
2019 if (c < 0)
2020 digs++, c = -c;
2022 while (c > 0)
2023 c /= 10; digs++;
2025 CHARS (digs);
2028 /* Output the name of type TYPE, with no punctuation.
2029 Such names can be set up either by typedef declarations
2030 or by struct, enum and union tags. */
2032 static void
2033 dbxout_type_name (tree type)
2035 tree t;
2036 if (TYPE_NAME (type) == 0)
2037 abort ();
2038 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2040 t = TYPE_NAME (type);
2042 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2044 t = DECL_NAME (TYPE_NAME (type));
2046 else
2047 abort ();
2049 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
2050 CHARS (IDENTIFIER_LENGTH (t));
2053 /* Output leading leading struct or class names needed for qualifying
2054 type whose scope is limited to a struct or class. */
2056 static void
2057 dbxout_class_name_qualifiers (tree decl)
2059 tree context = decl_type_context (decl);
2061 if (context != NULL_TREE
2062 && TREE_CODE(context) == RECORD_TYPE
2063 && TYPE_NAME (context) != 0
2064 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2065 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2067 tree name = TYPE_NAME (context);
2069 emit_pending_bincls_if_required ();
2071 if (TREE_CODE (name) == TYPE_DECL)
2073 dbxout_class_name_qualifiers (name);
2074 name = DECL_NAME (name);
2076 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
2077 CHARS (IDENTIFIER_LENGTH (name) + 2);
2081 /* Output a .stabs for the symbol defined by DECL,
2082 which must be a ..._DECL node in the normal namespace.
2083 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2084 LOCAL is nonzero if the scope is less than the entire file.
2085 Return 1 if a stabs might have been emitted. */
2088 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2090 tree type = TREE_TYPE (decl);
2091 tree context = NULL_TREE;
2092 int result = 0;
2094 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2095 ++debug_nesting;
2097 /* Cast avoids warning in old compilers. */
2098 current_sym_code = (STAB_CODE_TYPE) 0;
2099 current_sym_value = 0;
2100 current_sym_addr = 0;
2102 /* Ignore nameless syms, but don't ignore type tags. */
2104 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2105 || DECL_IGNORED_P (decl))
2106 DBXOUT_DECR_NESTING_AND_RETURN (0);
2108 /* If we are to generate only the symbols actually used then such
2109 symbol nodees are flagged with TREE_USED. Ignore any that
2110 aren't flaged as TREE_USED. */
2112 if (flag_debug_only_used_symbols)
2114 tree t;
2116 if (!TREE_USED (decl)
2117 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl)))
2118 DBXOUT_DECR_NESTING_AND_RETURN (0);
2120 /* We now have a used symbol. We need to generate the info for
2121 the symbol's type in addition to the symbol itself. These
2122 type symbols are queued to be generated after were done with
2123 the symbol itself (done because the symbol's info is generated
2124 with fprintf's, etc. as it determines what's needed).
2126 Note, because the TREE_TYPE(type) might be something like a
2127 pointer to a named type we need to look for the first name
2128 we see following the TREE_TYPE chain. */
2130 t = type;
2131 while (POINTER_TYPE_P (t))
2132 t = TREE_TYPE (t);
2134 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2135 need special treatment. The TYPE_STUB_DECL field in these
2136 types generally represents the tag name type we want to
2137 output. In addition there could be a typedef type with
2138 a different name. In that case we also want to output
2139 that. */
2141 if ((TREE_CODE (t) == RECORD_TYPE
2142 || TREE_CODE (t) == UNION_TYPE
2143 || TREE_CODE (t) == QUAL_UNION_TYPE
2144 || TREE_CODE (t) == ENUMERAL_TYPE)
2145 && TYPE_STUB_DECL (t)
2146 && TYPE_STUB_DECL (t) != decl
2147 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (t))) == 'd'
2148 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2150 debug_queue_symbol (TYPE_STUB_DECL (t));
2151 if (TYPE_NAME (t)
2152 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2153 && TYPE_NAME (t) != decl
2154 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2155 debug_queue_symbol (TYPE_NAME (t));
2157 else if (TYPE_NAME (t)
2158 && TYPE_NAME (t) != decl
2159 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2160 debug_queue_symbol (TYPE_NAME (t));
2163 emit_pending_bincls_if_required ();
2165 dbxout_prepare_symbol (decl);
2167 /* The output will always start with the symbol name,
2168 so always count that in the length-output-so-far. */
2170 if (DECL_NAME (decl) != 0)
2171 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2173 switch (TREE_CODE (decl))
2175 case CONST_DECL:
2176 /* Enum values are defined by defining the enum type. */
2177 break;
2179 case FUNCTION_DECL:
2180 if (DECL_RTL (decl) == 0)
2181 DBXOUT_DECR_NESTING_AND_RETURN (0);
2182 if (DECL_EXTERNAL (decl))
2183 break;
2184 /* Don't mention a nested function under its parent. */
2185 context = decl_function_context (decl);
2186 if (context == current_function_decl)
2187 break;
2188 if (GET_CODE (DECL_RTL (decl)) != MEM
2189 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2190 break;
2191 FORCE_TEXT;
2193 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2194 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2195 TREE_PUBLIC (decl) ? 'F' : 'f');
2196 result = 1;
2198 current_sym_code = N_FUN;
2199 current_sym_addr = XEXP (DECL_RTL (decl), 0);
2201 if (TREE_TYPE (type))
2202 dbxout_type (TREE_TYPE (type), 0);
2203 else
2204 dbxout_type (void_type_node, 0);
2206 /* For a nested function, when that function is compiled,
2207 mention the containing function name
2208 as well as (since dbx wants it) our own assembler-name. */
2209 if (context != 0)
2210 fprintf (asmfile, ",%s,%s",
2211 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2212 IDENTIFIER_POINTER (DECL_NAME (context)));
2214 dbxout_finish_symbol (decl);
2215 break;
2217 case TYPE_DECL:
2218 /* Don't output the same typedef twice.
2219 And don't output what language-specific stuff doesn't want output. */
2220 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2221 DBXOUT_DECR_NESTING_AND_RETURN (0);
2223 FORCE_TEXT;
2224 result = 1;
2226 int tag_needed = 1;
2227 int did_output = 0;
2229 if (DECL_NAME (decl))
2231 /* Nonzero means we must output a tag as well as a typedef. */
2232 tag_needed = 0;
2234 /* Handle the case of a C++ structure or union
2235 where the TYPE_NAME is a TYPE_DECL
2236 which gives both a typedef name and a tag. */
2237 /* dbx requires the tag first and the typedef second. */
2238 if ((TREE_CODE (type) == RECORD_TYPE
2239 || TREE_CODE (type) == UNION_TYPE
2240 || TREE_CODE (type) == QUAL_UNION_TYPE)
2241 && TYPE_NAME (type) == decl
2242 && !(use_gnu_debug_info_extensions && have_used_extensions)
2243 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2244 /* Distinguish the implicit typedefs of C++
2245 from explicit ones that might be found in C. */
2246 && DECL_ARTIFICIAL (decl)
2247 /* Do not generate a tag for incomplete records. */
2248 && COMPLETE_TYPE_P (type)
2249 /* Do not generate a tag for records of variable size,
2250 since this type can not be properly described in the
2251 DBX format, and it confuses some tools such as objdump. */
2252 && host_integerp (TYPE_SIZE (type), 1))
2254 tree name = TYPE_NAME (type);
2255 if (TREE_CODE (name) == TYPE_DECL)
2256 name = DECL_NAME (name);
2258 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2259 current_sym_value = 0;
2260 current_sym_addr = 0;
2261 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2263 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2264 IDENTIFIER_POINTER (name));
2265 dbxout_type (type, 1);
2266 dbxout_finish_symbol (NULL_TREE);
2269 /* Output .stabs (or whatever) and leading double quote. */
2270 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2272 if (use_gnu_debug_info_extensions)
2274 /* Output leading class/struct qualifiers. */
2275 dbxout_class_name_qualifiers (decl);
2278 /* Output typedef name. */
2279 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2281 /* Short cut way to output a tag also. */
2282 if ((TREE_CODE (type) == RECORD_TYPE
2283 || TREE_CODE (type) == UNION_TYPE
2284 || TREE_CODE (type) == QUAL_UNION_TYPE)
2285 && TYPE_NAME (type) == decl
2286 /* Distinguish the implicit typedefs of C++
2287 from explicit ones that might be found in C. */
2288 && DECL_ARTIFICIAL (decl))
2290 if (use_gnu_debug_info_extensions && have_used_extensions)
2292 putc ('T', asmfile);
2293 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2295 #if 0 /* Now we generate the tag for this case up above. */
2296 else
2297 tag_needed = 1;
2298 #endif
2301 putc ('t', asmfile);
2302 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2304 dbxout_type (type, 1);
2305 dbxout_finish_symbol (decl);
2306 did_output = 1;
2309 /* Don't output a tag if this is an incomplete type. This prevents
2310 the sun4 Sun OS 4.x dbx from crashing. */
2312 if (tag_needed && TYPE_NAME (type) != 0
2313 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2314 || (DECL_NAME (TYPE_NAME (type)) != 0))
2315 && COMPLETE_TYPE_P (type)
2316 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2318 /* For a TYPE_DECL with no name, but the type has a name,
2319 output a tag.
2320 This is what represents `struct foo' with no typedef. */
2321 /* In C++, the name of a type is the corresponding typedef.
2322 In C, it is an IDENTIFIER_NODE. */
2323 tree name = TYPE_NAME (type);
2324 if (TREE_CODE (name) == TYPE_DECL)
2325 name = DECL_NAME (name);
2327 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2328 current_sym_value = 0;
2329 current_sym_addr = 0;
2330 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2332 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2333 IDENTIFIER_POINTER (name));
2334 dbxout_type (type, 1);
2335 dbxout_finish_symbol (NULL_TREE);
2336 did_output = 1;
2339 /* If an enum type has no name, it cannot be referred to,
2340 but we must output it anyway, since the enumeration constants
2341 can be referred to. */
2342 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2344 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2345 current_sym_value = 0;
2346 current_sym_addr = 0;
2347 current_sym_nchars = 2;
2349 /* Some debuggers fail when given NULL names, so give this a
2350 harmless name of ` '. */
2351 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2352 dbxout_type (type, 1);
2353 dbxout_finish_symbol (NULL_TREE);
2356 /* Prevent duplicate output of a typedef. */
2357 TREE_ASM_WRITTEN (decl) = 1;
2358 break;
2361 case PARM_DECL:
2362 /* Parm decls go in their own separate chains
2363 and are output by dbxout_reg_parms and dbxout_parms. */
2364 abort ();
2366 case RESULT_DECL:
2367 /* Named return value, treat like a VAR_DECL. */
2368 case VAR_DECL:
2369 if (! DECL_RTL_SET_P (decl))
2370 DBXOUT_DECR_NESTING_AND_RETURN (0);
2371 /* Don't mention a variable that is external.
2372 Let the file that defines it describe it. */
2373 if (DECL_EXTERNAL (decl))
2374 break;
2376 /* If the variable is really a constant
2377 and not written in memory, inform the debugger. */
2378 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2379 && DECL_INITIAL (decl) != 0
2380 && host_integerp (DECL_INITIAL (decl), 0)
2381 && ! TREE_ASM_WRITTEN (decl)
2382 && (DECL_CONTEXT (decl) == NULL_TREE
2383 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2385 if (TREE_PUBLIC (decl) == 0)
2387 /* The sun4 assembler does not grok this. */
2388 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2390 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2391 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2393 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2394 fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2395 "\",0x%x,0,0,0\n",
2396 ASM_STABS_OP, name, ival, N_LSYM);
2397 DBXOUT_DECR_NESTING;
2398 return 1;
2400 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2402 /* don't know how to do this yet. */
2404 break;
2406 /* else it is something we handle like a normal variable. */
2409 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2410 #ifdef LEAF_REG_REMAP
2411 if (current_function_uses_only_leaf_regs)
2412 leaf_renumber_regs_insn (DECL_RTL (decl));
2413 #endif
2415 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2416 break;
2418 default:
2419 break;
2421 DBXOUT_DECR_NESTING;
2422 return result;
2425 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2426 Add SUFFIX to its name, if SUFFIX is not 0.
2427 Describe the variable as residing in HOME
2428 (usually HOME is DECL_RTL (DECL), but not always).
2429 Returns 1 if the stab was really emitted. */
2431 static int
2432 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2434 int letter = 0;
2435 int regno = -1;
2437 emit_pending_bincls_if_required ();
2439 /* Don't mention a variable at all
2440 if it was completely optimized into nothingness.
2442 If the decl was from an inline function, then its rtl
2443 is not identically the rtl that was used in this
2444 particular compilation. */
2445 if (GET_CODE (home) == SUBREG)
2447 rtx value = home;
2449 while (GET_CODE (value) == SUBREG)
2450 value = SUBREG_REG (value);
2451 if (GET_CODE (value) == REG)
2453 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2454 return 0;
2456 home = alter_subreg (&home);
2458 if (GET_CODE (home) == REG)
2460 regno = REGNO (home);
2461 if (regno >= FIRST_PSEUDO_REGISTER)
2462 return 0;
2465 /* The kind-of-variable letter depends on where
2466 the variable is and on the scope of its name:
2467 G and N_GSYM for static storage and global scope,
2468 S for static storage and file scope,
2469 V for static storage and local scope,
2470 for those two, use N_LCSYM if data is in bss segment,
2471 N_STSYM if in data segment, N_FUN otherwise.
2472 (We used N_FUN originally, then changed to N_STSYM
2473 to please GDB. However, it seems that confused ld.
2474 Now GDB has been fixed to like N_FUN, says Kingdon.)
2475 no letter at all, and N_LSYM, for auto variable,
2476 r and N_RSYM for register variable. */
2478 if (GET_CODE (home) == MEM
2479 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2481 if (TREE_PUBLIC (decl))
2483 letter = 'G';
2484 current_sym_code = N_GSYM;
2486 else
2488 current_sym_addr = XEXP (home, 0);
2490 letter = decl_function_context (decl) ? 'V' : 'S';
2492 /* This should be the same condition as in assemble_variable, but
2493 we don't have access to dont_output_data here. So, instead,
2494 we rely on the fact that error_mark_node initializers always
2495 end up in bss for C++ and never end up in bss for C. */
2496 if (DECL_INITIAL (decl) == 0
2497 || (!strcmp (lang_hooks.name, "GNU C++")
2498 && DECL_INITIAL (decl) == error_mark_node))
2499 current_sym_code = N_LCSYM;
2500 else if (DECL_IN_TEXT_SECTION (decl))
2501 /* This is not quite right, but it's the closest
2502 of all the codes that Unix defines. */
2503 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2504 else
2506 /* Some ports can transform a symbol ref into a label ref,
2507 because the symbol ref is too far away and has to be
2508 dumped into a constant pool. Alternatively, the symbol
2509 in the constant pool might be referenced by a different
2510 symbol. */
2511 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2512 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2514 rtx tmp = get_pool_constant (current_sym_addr);
2516 if (GET_CODE (tmp) == SYMBOL_REF
2517 || GET_CODE (tmp) == LABEL_REF)
2518 current_sym_addr = tmp;
2521 /* Ultrix `as' seems to need this. */
2522 #ifdef DBX_STATIC_STAB_DATA_SECTION
2523 data_section ();
2524 #endif
2525 current_sym_code = N_STSYM;
2529 else if (regno >= 0)
2531 letter = 'r';
2532 current_sym_code = N_RSYM;
2533 current_sym_value = DBX_REGISTER_NUMBER (regno);
2535 else if (GET_CODE (home) == MEM
2536 && (GET_CODE (XEXP (home, 0)) == MEM
2537 || (GET_CODE (XEXP (home, 0)) == REG
2538 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2539 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2540 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2541 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2542 #endif
2544 /* If the value is indirect by memory or by a register
2545 that isn't the frame pointer
2546 then it means the object is variable-sized and address through
2547 that register or stack slot. DBX has no way to represent this
2548 so all we can do is output the variable as a pointer.
2549 If it's not a parameter, ignore it.
2550 (VAR_DECLs like this can be made by integrate.c.) */
2552 if (GET_CODE (XEXP (home, 0)) == REG)
2554 letter = 'r';
2555 current_sym_code = N_RSYM;
2556 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2557 return 0;
2558 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2560 else
2562 current_sym_code = N_LSYM;
2563 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2564 We want the value of that CONST_INT. */
2565 current_sym_value
2566 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2569 /* Effectively do build_pointer_type, but don't cache this type,
2570 since it might be temporary whereas the type it points to
2571 might have been saved for inlining. */
2572 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2573 type = make_node (POINTER_TYPE);
2574 TREE_TYPE (type) = TREE_TYPE (decl);
2576 else if (GET_CODE (home) == MEM
2577 && GET_CODE (XEXP (home, 0)) == REG)
2579 current_sym_code = N_LSYM;
2580 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2582 else if (GET_CODE (home) == MEM
2583 && GET_CODE (XEXP (home, 0)) == PLUS
2584 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2586 current_sym_code = N_LSYM;
2587 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2588 We want the value of that CONST_INT. */
2589 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2591 else if (GET_CODE (home) == MEM
2592 && GET_CODE (XEXP (home, 0)) == CONST)
2594 /* Handle an obscure case which can arise when optimizing and
2595 when there are few available registers. (This is *always*
2596 the case for i386/i486 targets). The RTL looks like
2597 (MEM (CONST ...)) even though this variable is a local `auto'
2598 or a local `register' variable. In effect, what has happened
2599 is that the reload pass has seen that all assignments and
2600 references for one such a local variable can be replaced by
2601 equivalent assignments and references to some static storage
2602 variable, thereby avoiding the need for a register. In such
2603 cases we're forced to lie to debuggers and tell them that
2604 this variable was itself `static'. */
2605 current_sym_code = N_LCSYM;
2606 letter = 'V';
2607 current_sym_addr = XEXP (XEXP (home, 0), 0);
2609 else if (GET_CODE (home) == CONCAT)
2611 tree subtype;
2613 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2614 for example), then there is no easy way to figure out
2615 what SUBTYPE should be. So, we give up. */
2616 if (TREE_CODE (type) != COMPLEX_TYPE)
2617 return 0;
2619 subtype = TREE_TYPE (type);
2621 /* If the variable's storage is in two parts,
2622 output each as a separate stab with a modified name. */
2623 if (WORDS_BIG_ENDIAN)
2624 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2625 else
2626 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2628 /* Cast avoids warning in old compilers. */
2629 current_sym_code = (STAB_CODE_TYPE) 0;
2630 current_sym_value = 0;
2631 current_sym_addr = 0;
2632 dbxout_prepare_symbol (decl);
2634 if (WORDS_BIG_ENDIAN)
2635 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2636 else
2637 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2638 return 1;
2640 else
2641 /* Address might be a MEM, when DECL is a variable-sized object.
2642 Or it might be const0_rtx, meaning previous passes
2643 want us to ignore this variable. */
2644 return 0;
2646 /* Ok, start a symtab entry and output the variable name. */
2647 FORCE_TEXT;
2649 #ifdef DBX_STATIC_BLOCK_START
2650 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2651 #endif
2653 dbxout_symbol_name (decl, suffix, letter);
2654 dbxout_type (type, 0);
2655 dbxout_finish_symbol (decl);
2657 #ifdef DBX_STATIC_BLOCK_END
2658 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2659 #endif
2660 return 1;
2663 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2664 Then output LETTER to indicate the kind of location the symbol has. */
2666 static void
2667 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2669 const char *name;
2671 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2672 /* One slight hitch: if this is a VAR_DECL which is a static
2673 class member, we must put out the mangled name instead of the
2674 DECL_NAME. Note also that static member (variable) names DO NOT begin
2675 with underscores in .stabs directives. */
2676 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2677 else
2678 /* ...but if we're function-local, we don't want to include the junk
2679 added by ASM_FORMAT_PRIVATE_NAME. */
2680 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2682 if (name == 0)
2683 name = "(anon)";
2684 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2685 (suffix ? suffix : ""));
2687 if (letter)
2688 putc (letter, asmfile);
2691 static void
2692 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)
2694 #ifdef WINNING_GDB
2695 const char *filename = DECL_SOURCE_FILE (decl);
2697 dbxout_source_file (asmfile, filename);
2698 #endif
2701 static void
2702 dbxout_finish_symbol (tree sym)
2704 #ifdef DBX_FINISH_SYMBOL
2705 DBX_FINISH_SYMBOL (sym);
2706 #else
2707 int line = 0;
2708 if (use_gnu_debug_info_extensions && sym != 0)
2709 line = DECL_SOURCE_LINE (sym);
2711 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2712 if (current_sym_addr)
2713 output_addr_const (asmfile, current_sym_addr);
2714 else
2715 fprintf (asmfile, "%d", current_sym_value);
2716 putc ('\n', asmfile);
2717 #endif
2720 /* Output definitions of all the decls in a chain. Return nonzero if
2721 anything was output */
2724 dbxout_syms (tree syms)
2726 int result = 0;
2727 while (syms)
2729 result += dbxout_symbol (syms, 1);
2730 syms = TREE_CHAIN (syms);
2732 return result;
2735 /* The following two functions output definitions of function parameters.
2736 Each parameter gets a definition locating it in the parameter list.
2737 Each parameter that is a register variable gets a second definition
2738 locating it in the register.
2740 Printing or argument lists in gdb uses the definitions that
2741 locate in the parameter list. But reference to the variable in
2742 expressions uses preferentially the definition as a register. */
2744 /* Output definitions, referring to storage in the parmlist,
2745 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2747 void
2748 dbxout_parms (tree parms)
2750 ++debug_nesting;
2752 emit_pending_bincls_if_required ();
2754 for (; parms; parms = TREE_CHAIN (parms))
2755 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2757 dbxout_prepare_symbol (parms);
2759 /* Perform any necessary register eliminations on the parameter's rtl,
2760 so that the debugging output will be accurate. */
2761 DECL_INCOMING_RTL (parms)
2762 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2763 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2764 #ifdef LEAF_REG_REMAP
2765 if (current_function_uses_only_leaf_regs)
2767 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2768 leaf_renumber_regs_insn (DECL_RTL (parms));
2770 #endif
2772 if (PARM_PASSED_IN_MEMORY (parms))
2774 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2776 /* ??? Here we assume that the parm address is indexed
2777 off the frame pointer or arg pointer.
2778 If that is not true, we produce meaningless results,
2779 but do not crash. */
2780 if (GET_CODE (addr) == PLUS
2781 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2782 current_sym_value = INTVAL (XEXP (addr, 1));
2783 else
2784 current_sym_value = 0;
2786 current_sym_code = N_PSYM;
2787 current_sym_addr = 0;
2789 FORCE_TEXT;
2790 if (DECL_NAME (parms))
2792 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2794 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2795 IDENTIFIER_POINTER (DECL_NAME (parms)),
2796 DBX_MEMPARM_STABS_LETTER);
2798 else
2800 current_sym_nchars = 8;
2801 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2802 DBX_MEMPARM_STABS_LETTER);
2805 /* It is quite tempting to use:
2807 dbxout_type (TREE_TYPE (parms), 0);
2809 as the next statement, rather than using DECL_ARG_TYPE(), so
2810 that gcc reports the actual type of the parameter, rather
2811 than the promoted type. This certainly makes GDB's life
2812 easier, at least for some ports. The change is a bad idea
2813 however, since GDB expects to be able access the type without
2814 performing any conversions. So for example, if we were
2815 passing a float to an unprototyped function, gcc will store a
2816 double on the stack, but if we emit a stab saying the type is a
2817 float, then gdb will only read in a single value, and this will
2818 produce an erroneous value. */
2819 dbxout_type (DECL_ARG_TYPE (parms), 0);
2820 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2821 dbxout_finish_symbol (parms);
2823 else if (GET_CODE (DECL_RTL (parms)) == REG)
2825 rtx best_rtl;
2826 char regparm_letter;
2827 tree parm_type;
2828 /* Parm passed in registers and lives in registers or nowhere. */
2830 current_sym_code = DBX_REGPARM_STABS_CODE;
2831 regparm_letter = DBX_REGPARM_STABS_LETTER;
2832 current_sym_addr = 0;
2834 /* If parm lives in a register, use that register;
2835 pretend the parm was passed there. It would be more consistent
2836 to describe the register where the parm was passed,
2837 but in practice that register usually holds something else.
2839 If we use DECL_RTL, then we must use the declared type of
2840 the variable, not the type that it arrived in. */
2841 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2843 best_rtl = DECL_RTL (parms);
2844 parm_type = TREE_TYPE (parms);
2846 /* If the parm lives nowhere, use the register where it was
2847 passed. It is also better to use the declared type here. */
2848 else
2850 best_rtl = DECL_INCOMING_RTL (parms);
2851 parm_type = TREE_TYPE (parms);
2853 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2855 FORCE_TEXT;
2856 if (DECL_NAME (parms))
2858 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2859 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2860 IDENTIFIER_POINTER (DECL_NAME (parms)),
2861 regparm_letter);
2863 else
2865 current_sym_nchars = 8;
2866 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2867 regparm_letter);
2870 dbxout_type (parm_type, 0);
2871 dbxout_finish_symbol (parms);
2873 else if (GET_CODE (DECL_RTL (parms)) == MEM
2874 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2875 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2876 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2877 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2878 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2879 #endif
2882 /* Parm was passed via invisible reference.
2883 That is, its address was passed in a register.
2884 Output it as if it lived in that register.
2885 The debugger will know from the type
2886 that it was actually passed by invisible reference. */
2888 char regparm_letter;
2889 /* Parm passed in registers and lives in registers or nowhere. */
2891 current_sym_code = DBX_REGPARM_STABS_CODE;
2892 if (use_gnu_debug_info_extensions)
2893 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2894 else
2895 regparm_letter = DBX_REGPARM_STABS_LETTER;
2897 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2898 If it is an unallocated pseudo-reg, then use the register where
2899 it was passed instead. */
2900 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2901 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2902 else
2903 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2905 current_sym_addr = 0;
2907 FORCE_TEXT;
2908 if (DECL_NAME (parms))
2910 current_sym_nchars
2911 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2913 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2914 IDENTIFIER_POINTER (DECL_NAME (parms)),
2915 regparm_letter);
2917 else
2919 current_sym_nchars = 8;
2920 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2921 regparm_letter);
2924 dbxout_type (TREE_TYPE (parms), 0);
2925 dbxout_finish_symbol (parms);
2927 else if (GET_CODE (DECL_RTL (parms)) == MEM
2928 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2930 /* Parm was passed via invisible reference, with the reference
2931 living on the stack. DECL_RTL looks like
2932 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2933 could look like (MEM (MEM (REG))). */
2934 const char *const decl_name = (DECL_NAME (parms)
2935 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2936 : "(anon)");
2937 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2938 current_sym_value = 0;
2939 else
2940 current_sym_value
2941 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2942 current_sym_addr = 0;
2943 current_sym_code = N_PSYM;
2945 FORCE_TEXT;
2946 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2948 current_sym_value
2949 = DEBUGGER_ARG_OFFSET (current_sym_value,
2950 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2951 dbxout_type (TREE_TYPE (parms), 0);
2952 dbxout_finish_symbol (parms);
2954 else if (GET_CODE (DECL_RTL (parms)) == MEM
2955 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2956 /* ??? A constant address for a parm can happen
2957 when the reg it lives in is equiv to a constant in memory.
2958 Should make this not happen, after 2.4. */
2959 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2961 /* Parm was passed in registers but lives on the stack. */
2963 current_sym_code = N_PSYM;
2964 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2965 in which case we want the value of that CONST_INT,
2966 or (MEM (REG ...)),
2967 in which case we use a value of zero. */
2968 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2969 current_sym_value = 0;
2970 else
2971 current_sym_value
2972 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2974 current_sym_addr = 0;
2976 /* Make a big endian correction if the mode of the type of the
2977 parameter is not the same as the mode of the rtl. */
2978 if (BYTES_BIG_ENDIAN
2979 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2980 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2982 current_sym_value +=
2983 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2984 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2987 FORCE_TEXT;
2988 if (DECL_NAME (parms))
2990 current_sym_nchars
2991 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2993 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2994 IDENTIFIER_POINTER (DECL_NAME (parms)),
2995 DBX_MEMPARM_STABS_LETTER);
2997 else
2999 current_sym_nchars = 8;
3000 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
3001 DBX_MEMPARM_STABS_LETTER);
3004 current_sym_value
3005 = DEBUGGER_ARG_OFFSET (current_sym_value,
3006 XEXP (DECL_RTL (parms), 0));
3007 dbxout_type (TREE_TYPE (parms), 0);
3008 dbxout_finish_symbol (parms);
3011 DBXOUT_DECR_NESTING;
3014 /* Output definitions for the places where parms live during the function,
3015 when different from where they were passed, when the parms were passed
3016 in memory.
3018 It is not useful to do this for parms passed in registers
3019 that live during the function in different registers, because it is
3020 impossible to look in the passed register for the passed value,
3021 so we use the within-the-function register to begin with.
3023 PARMS is a chain of PARM_DECL nodes. */
3025 void
3026 dbxout_reg_parms (tree parms)
3028 ++debug_nesting;
3030 for (; parms; parms = TREE_CHAIN (parms))
3031 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3033 dbxout_prepare_symbol (parms);
3035 /* Report parms that live in registers during the function
3036 but were passed in memory. */
3037 if (GET_CODE (DECL_RTL (parms)) == REG
3038 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3039 dbxout_symbol_location (parms, TREE_TYPE (parms),
3040 0, DECL_RTL (parms));
3041 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3042 dbxout_symbol_location (parms, TREE_TYPE (parms),
3043 0, DECL_RTL (parms));
3044 /* Report parms that live in memory but not where they were passed. */
3045 else if (GET_CODE (DECL_RTL (parms)) == MEM
3046 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3047 dbxout_symbol_location (parms, TREE_TYPE (parms),
3048 0, DECL_RTL (parms));
3050 DBXOUT_DECR_NESTING;
3053 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3054 output definitions of those names, in raw form */
3056 static void
3057 dbxout_args (tree args)
3059 while (args)
3061 putc (',', asmfile);
3062 dbxout_type (TREE_VALUE (args), 0);
3063 CHARS (1);
3064 args = TREE_CHAIN (args);
3068 /* Output everything about a symbol block (a BLOCK node
3069 that represents a scope level),
3070 including recursive output of contained blocks.
3072 BLOCK is the BLOCK node.
3073 DEPTH is its depth within containing symbol blocks.
3074 ARGS is usually zero; but for the outermost block of the
3075 body of a function, it is a chain of PARM_DECLs for the function parameters.
3076 We output definitions of all the register parms
3077 as if they were local variables of that block.
3079 If -g1 was used, we count blocks just the same, but output nothing
3080 except for the outermost block.
3082 Actually, BLOCK may be several blocks chained together.
3083 We handle them all in sequence. */
3085 static void
3086 dbxout_block (tree block, int depth, tree args)
3088 int blocknum = -1;
3090 #if DBX_BLOCKS_FUNCTION_RELATIVE
3091 const char *begin_label;
3092 if (current_function_func_begin_label != NULL_TREE)
3093 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
3094 else
3095 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3096 #endif
3098 while (block)
3100 /* Ignore blocks never expanded or otherwise marked as real. */
3101 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3103 int did_output;
3105 /* In dbx format, the syms of a block come before the N_LBRAC.
3106 If nothing is output, we don't need the N_LBRAC, either. */
3107 did_output = 0;
3108 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3109 did_output = dbxout_syms (BLOCK_VARS (block));
3110 if (args)
3111 dbxout_reg_parms (args);
3113 /* Now output an N_LBRAC symbol to represent the beginning of
3114 the block. Use the block's tree-walk order to generate
3115 the assembler symbols LBBn and LBEn
3116 that final will define around the code in this block. */
3117 if (depth > 0 && did_output)
3119 char buf[20];
3120 blocknum = BLOCK_NUMBER (block);
3121 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3123 if (BLOCK_HANDLER_BLOCK (block))
3125 /* A catch block. Must precede N_LBRAC. */
3126 tree decl = BLOCK_VARS (block);
3127 while (decl)
3129 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
3130 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
3131 assemble_name (asmfile, buf);
3132 fprintf (asmfile, "\n");
3133 decl = TREE_CHAIN (decl);
3137 #ifdef DBX_OUTPUT_LBRAC
3138 DBX_OUTPUT_LBRAC (asmfile, buf);
3139 #else
3140 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
3141 assemble_name (asmfile, buf);
3142 #if DBX_BLOCKS_FUNCTION_RELATIVE
3143 putc ('-', asmfile);
3144 assemble_name (asmfile, begin_label);
3145 #endif
3146 fprintf (asmfile, "\n");
3147 #endif
3150 /* Output the subblocks. */
3151 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3153 /* Refer to the marker for the end of the block. */
3154 if (depth > 0 && did_output)
3156 char buf[20];
3157 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3158 #ifdef DBX_OUTPUT_RBRAC
3159 DBX_OUTPUT_RBRAC (asmfile, buf);
3160 #else
3161 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3162 assemble_name (asmfile, buf);
3163 #if DBX_BLOCKS_FUNCTION_RELATIVE
3164 putc ('-', asmfile);
3165 assemble_name (asmfile, begin_label);
3166 #endif
3167 fprintf (asmfile, "\n");
3168 #endif
3171 block = BLOCK_CHAIN (block);
3175 /* Output the information about a function and its arguments and result.
3176 Usually this follows the function's code,
3177 but on some systems, it comes before. */
3179 #if defined (DBX_DEBUGGING_INFO)
3180 static void
3181 dbxout_begin_function (tree decl)
3183 int saved_tree_used1 = TREE_USED (decl);
3184 TREE_USED (decl) = 1;
3185 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3187 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3188 TREE_USED (DECL_RESULT (decl)) = 1;
3189 dbxout_symbol (decl, 0);
3190 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3192 else
3193 dbxout_symbol (decl, 0);
3194 TREE_USED (decl) = saved_tree_used1;
3196 dbxout_parms (DECL_ARGUMENTS (decl));
3197 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3198 dbxout_symbol (DECL_RESULT (decl), 1);
3200 #endif /* DBX_DEBUGGING_INFO */
3202 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3204 #include "gt-dbxout.h"