configure.ac: GCC_NO_EXECUTABLES was supposed to be commented in the patch from 3...
[official-gcc.git] / gcc / dbxout.c
blobd257729d8f8ed2e9505e0c1e7aa5efd901797365
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 = 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 = get_src_pwd ())
473 && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
474 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
475 if (cwd)
477 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
478 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
479 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
480 fprintf (asmfile, "%s", ASM_STABS_OP);
481 output_quoted_string (asmfile, cwd);
482 fprintf (asmfile, ",%d,0,0,", N_SO);
483 assemble_name (asmfile, ltext_label_name);
484 fputc ('\n', asmfile);
485 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
489 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
490 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
491 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
492 /* We include outputting `Ltext:' here,
493 because that gives you a way to override it. */
494 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
495 fprintf (asmfile, "%s", ASM_STABS_OP);
496 output_quoted_string (asmfile, input_file_name);
497 fprintf (asmfile, ",%d,0,0,", N_SO);
498 assemble_name (asmfile, ltext_label_name);
499 fputc ('\n', asmfile);
500 text_section ();
501 (*targetm.asm_out.internal_label) (asmfile, "Ltext", 0);
502 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
504 #ifdef DBX_OUTPUT_GCC_MARKER
505 DBX_OUTPUT_GCC_MARKER (asmfile);
506 #else
507 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
508 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
509 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
510 #endif
512 base_input_file = lastfile = input_file_name;
514 next_type_number = 1;
516 #ifdef DBX_USE_BINCL
517 current_file = ggc_alloc (sizeof *current_file);
518 current_file->next = NULL;
519 current_file->file_number = 0;
520 current_file->next_type_number = 1;
521 next_file_number = 1;
522 current_file->prev = NULL;
523 current_file->bincl_status = BINCL_NOT_REQUIRED;
524 current_file->pending_bincl_name = NULL;
525 #endif
527 /* Make sure that types `int' and `char' have numbers 1 and 2.
528 Definitions of other integer types will refer to those numbers.
529 (Actually it should no longer matter what their numbers are.
530 Also, if any types with tags have been defined, dbxout_symbol
531 will output them first, so the numbers won't be 1 and 2. That
532 happens in C++. So it's a good thing it should no longer matter). */
534 #ifdef DBX_OUTPUT_STANDARD_TYPES
535 DBX_OUTPUT_STANDARD_TYPES (syms);
536 #endif
538 /* Get all permanent types that have typedef names,
539 and output them all, except for those already output. */
541 dbxout_typedefs (syms);
544 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
545 in the reverse order from that which is found in SYMS. */
547 static void
548 dbxout_typedefs (tree syms)
550 if (syms)
552 dbxout_typedefs (TREE_CHAIN (syms));
553 if (TREE_CODE (syms) == TYPE_DECL)
555 tree type = TREE_TYPE (syms);
556 if (TYPE_NAME (type)
557 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
558 && COMPLETE_TYPE_P (type)
559 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
560 dbxout_symbol (TYPE_NAME (type), 0);
565 #ifdef DBX_USE_BINCL
566 /* Emit BINCL stab using given name. */
567 static void
568 emit_bincl_stab (const char *name)
570 fprintf (asmfile, "%s", ASM_STABS_OP);
571 output_quoted_string (asmfile, name);
572 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
575 /* If there are pending bincls then it is time to emit all of them. */
577 static inline void
578 emit_pending_bincls_if_required (void)
580 if (pending_bincls)
581 emit_pending_bincls ();
584 /* Emit all pending bincls. */
586 static void
587 emit_pending_bincls (void)
589 struct dbx_file *f = current_file;
591 /* Find first pending bincl. */
592 while (f->bincl_status == BINCL_PENDING)
593 f = f->next;
595 /* Now emit all bincls. */
596 f = f->prev;
598 while (f)
600 if (f->bincl_status == BINCL_PENDING)
602 emit_bincl_stab (f->pending_bincl_name);
604 /* Update file number and status. */
605 f->file_number = next_file_number++;
606 f->bincl_status = BINCL_PROCESSED;
608 if (f == current_file)
609 break;
610 f = f->prev;
613 /* All pending bincls have been emitted. */
614 pending_bincls = 0;
617 #else
619 static inline void
620 emit_pending_bincls_if_required (void) {}
621 #endif
623 /* Change to reading from a new source file. Generate a N_BINCL stab. */
625 static void
626 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
627 const char *filename ATTRIBUTE_UNUSED)
629 #ifdef DBX_USE_BINCL
630 struct dbx_file *n = ggc_alloc (sizeof *n);
632 n->next = current_file;
633 n->next_type_number = 1;
634 /* Do not assign file number now.
635 Delay it until we actually emit BINCL. */
636 n->file_number = 0;
637 n->prev = NULL;
638 current_file->prev = n;
639 n->bincl_status = BINCL_PENDING;
640 n->pending_bincl_name = filename;
641 pending_bincls = 1;
642 current_file = n;
643 #endif
646 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
648 static void
649 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
651 #ifdef DBX_USE_BINCL
652 /* Emit EINCL stab only if BINCL is not pending. */
653 if (current_file->bincl_status == BINCL_PROCESSED)
654 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
655 current_file->bincl_status = BINCL_NOT_REQUIRED;
656 current_file = current_file->next;
657 #endif
660 /* Handle a few odd cases that occur when trying to make PCH files work. */
662 static void
663 dbxout_handle_pch (unsigned at_end)
665 if (! at_end)
667 /* When using the PCH, this file will be included, so we need to output
668 a BINCL. */
669 dbxout_start_source_file (0, lastfile);
671 /* The base file when using the PCH won't be the same as
672 the base file when it's being generated. */
673 lastfile = NULL;
675 else
677 /* ... and an EINCL. */
678 dbxout_end_source_file (0);
680 /* Deal with cases where 'lastfile' was never actually changed. */
681 lastfile_is_base = lastfile == NULL;
685 #if defined (DBX_DEBUGGING_INFO)
686 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
688 static void
689 dbxout_source_file (FILE *file, const char *filename)
691 if (lastfile == 0 && lastfile_is_base)
693 lastfile = base_input_file;
694 lastfile_is_base = 0;
697 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
699 char ltext_label_name[100];
701 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
702 source_label_number);
703 fprintf (file, "%s", ASM_STABS_OP);
704 output_quoted_string (file, filename);
705 fprintf (asmfile, ",%d,0,0,", N_SOL);
706 assemble_name (asmfile, ltext_label_name);
707 fputc ('\n', asmfile);
708 if (current_function_decl != NULL_TREE
709 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
710 ; /* Don't change section amid function. */
711 else
712 text_section ();
713 (*targetm.asm_out.internal_label) (file, "Ltext", source_label_number);
714 source_label_number++;
715 lastfile = filename;
719 /* Output a line number symbol entry for source file FILENAME and line
720 number LINENO. */
722 static void
723 dbxout_source_line (unsigned int lineno, const char *filename)
725 dbxout_source_file (asmfile, filename);
727 #ifdef ASM_OUTPUT_SOURCE_LINE
728 dbxout_source_line_counter += 1;
729 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno, dbxout_source_line_counter);
730 #else
731 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
732 #endif
735 /* Describe the beginning of an internal block within a function. */
737 static void
738 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
740 emit_pending_bincls_if_required ();
741 (*targetm.asm_out.internal_label) (asmfile, "LBB", n);
744 /* Describe the end line-number of an internal block within a function. */
746 static void
747 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
749 emit_pending_bincls_if_required ();
750 (*targetm.asm_out.internal_label) (asmfile, "LBE", n);
753 /* Output dbx data for a function definition.
754 This includes a definition of the function name itself (a symbol),
755 definitions of the parameters (locating them in the parameter list)
756 and then output the block that makes up the function's body
757 (including all the auto variables of the function). */
759 static void
760 dbxout_function_decl (tree decl)
762 emit_pending_bincls_if_required ();
763 #ifndef DBX_FUNCTION_FIRST
764 dbxout_begin_function (decl);
765 #endif
766 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
767 #ifdef DBX_OUTPUT_FUNCTION_END
768 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
769 #endif
770 if (use_gnu_debug_info_extensions
771 #if defined(NO_DBX_FUNCTION_END)
772 && ! NO_DBX_FUNCTION_END
773 #endif
774 && targetm.have_named_sections)
775 dbxout_function_end ();
778 #endif /* DBX_DEBUGGING_INFO */
780 /* Debug information for a global DECL. Called from toplev.c after
781 compilation proper has finished. */
782 static void
783 dbxout_global_decl (tree decl)
785 if (TREE_CODE (decl) == VAR_DECL
786 && ! DECL_EXTERNAL (decl)
787 && DECL_RTL_SET_P (decl)) /* Not necessary? */
789 int saved_tree_used = TREE_USED (decl);
790 TREE_USED (decl) = 1;
791 dbxout_symbol (decl, 0);
792 TREE_USED (decl) = saved_tree_used;
796 /* At the end of compilation, finish writing the symbol table.
797 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
798 to do nothing. */
800 static void
801 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
803 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
804 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
805 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
807 debug_free_queue ();
810 /* Output floating point type values used by the 'R' stab letter.
811 These numbers come from include/aout/stab_gnu.h in binutils/gdb.
813 There are only 3 real/complex types defined, and we need 7/6.
814 We use NF_SINGLE as a generic float type, and NF_COMPLEX as a generic
815 complex type. Since we have the type size anyways, we don't really need
816 to distinguish between different FP types, we only need to distinguish
817 between float and complex. This works fine with gdb.
819 We only use this for complex types, to avoid breaking backwards
820 compatibility for real types. complex types aren't in ISO C90, so it is
821 OK if old debuggers don't understand the debug info we emit for them. */
823 /* ??? These are supposed to be IEEE types, but we don't check for that.
824 We could perhaps add additional numbers for non-IEEE types if we need
825 them. */
827 static void
828 dbxout_fptype_value (tree type)
830 char value = '0';
831 enum machine_mode mode = TYPE_MODE (type);
833 if (TREE_CODE (type) == REAL_TYPE)
835 if (mode == SFmode)
836 value = '1';
837 else if (mode == DFmode)
838 value = '2';
839 else if (mode == TFmode || mode == XFmode)
840 value = '6';
841 else
842 /* Use NF_SINGLE as a generic real type for other sizes. */
843 value = '1';
845 else if (TREE_CODE (type) == COMPLEX_TYPE)
847 if (mode == SCmode)
848 value = '3';
849 else if (mode == DCmode)
850 value = '4';
851 else if (mode == TCmode || mode == XCmode)
852 value = '5';
853 else
854 /* Use NF_COMPLEX as a generic complex type for other sizes. */
855 value = '3';
857 else
858 abort ();
860 putc (value, asmfile);
861 CHARS (1);
864 /* Output the index of a type. */
866 static void
867 dbxout_type_index (tree type)
869 #ifndef DBX_USE_BINCL
870 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
871 CHARS (3);
872 #else
873 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
874 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
875 CHARS (9);
876 #endif
879 #if DBX_CONTIN_LENGTH > 0
880 /* Continue a symbol-description that gets too big.
881 End one symbol table entry with a double-backslash
882 and start a new one, eventually producing something like
883 .stabs "start......\\",code,0,value
884 .stabs "...rest",code,0,value */
886 static void
887 dbxout_continue (void)
889 emit_pending_bincls_if_required ();
890 #ifdef DBX_CONTIN_CHAR
891 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
892 #else
893 fprintf (asmfile, "\\\\");
894 #endif
895 dbxout_finish_symbol (NULL_TREE);
896 fprintf (asmfile, "%s\"", ASM_STABS_OP);
897 current_sym_nchars = 0;
899 #endif /* DBX_CONTIN_LENGTH > 0 */
901 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
902 This must be a separate function because anonymous unions require
903 recursive calls. */
905 static void
906 dbxout_type_fields (tree type)
908 tree tem;
910 /* Output the name, type, position (in bits), size (in bits) of each
911 field that we can support. */
912 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
914 /* Omit here local type decls until we know how to support them. */
915 if (TREE_CODE (tem) == TYPE_DECL
916 /* Omit fields whose position or size are variable or too large to
917 represent. */
918 || (TREE_CODE (tem) == FIELD_DECL
919 && (! host_integerp (bit_position (tem), 0)
920 || ! DECL_SIZE (tem)
921 || ! host_integerp (DECL_SIZE (tem), 1)))
922 /* Omit here the nameless fields that are used to skip bits. */
923 || DECL_IGNORED_P (tem))
924 continue;
926 else if (TREE_CODE (tem) != CONST_DECL)
928 /* Continue the line if necessary,
929 but not before the first field. */
930 if (tem != TYPE_FIELDS (type))
931 CONTIN;
933 if (DECL_NAME (tem))
935 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
936 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
938 else
940 fprintf (asmfile, ":");
941 CHARS (1);
944 if (use_gnu_debug_info_extensions
945 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
946 || TREE_CODE (tem) != FIELD_DECL))
948 have_used_extensions = 1;
949 putc ('/', asmfile);
950 putc ((TREE_PRIVATE (tem) ? '0'
951 : TREE_PROTECTED (tem) ? '1' : '2'),
952 asmfile);
953 CHARS (2);
956 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
957 && DECL_BIT_FIELD_TYPE (tem))
958 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
960 if (TREE_CODE (tem) == VAR_DECL)
962 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
964 tree name = DECL_ASSEMBLER_NAME (tem);
966 have_used_extensions = 1;
967 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
968 CHARS (IDENTIFIER_LENGTH (name) + 2);
970 else
972 /* If TEM is non-static, GDB won't understand it. */
973 fprintf (asmfile, ",0,0;");
974 CHARS (5);
977 else
979 putc (',', asmfile);
980 print_wide_int (int_bit_position (tem));
981 putc (',', asmfile);
982 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
983 putc (';', asmfile);
984 CHARS (3);
990 /* Subroutine of `dbxout_type_methods'. Output debug info about the
991 method described DECL. DEBUG_NAME is an encoding of the method's
992 type signature. ??? We may be able to do without DEBUG_NAME altogether
993 now. */
995 static void
996 dbxout_type_method_1 (tree decl, const char *debug_name)
998 char c1 = 'A', c2;
1000 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1001 c2 = '?';
1002 else /* it's a METHOD_TYPE. */
1004 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1005 /* A for normal functions.
1006 B for `const' member functions.
1007 C for `volatile' member functions.
1008 D for `const volatile' member functions. */
1009 if (TYPE_READONLY (TREE_TYPE (firstarg)))
1010 c1 += 1;
1011 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1012 c1 += 2;
1014 if (DECL_VINDEX (decl))
1015 c2 = '*';
1016 else
1017 c2 = '.';
1020 fprintf (asmfile, ":%s;%c%c%c", debug_name,
1021 TREE_PRIVATE (decl) ? '0'
1022 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
1023 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
1024 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1026 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1028 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
1029 putc (';', asmfile);
1030 CHARS (1);
1031 dbxout_type (DECL_CONTEXT (decl), 0);
1032 fprintf (asmfile, ";");
1033 CHARS (1);
1037 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
1038 in TYPE. */
1040 static void
1041 dbxout_type_methods (tree type)
1043 /* C++: put out the method names and their parameter lists */
1044 tree methods = TYPE_METHODS (type);
1045 tree type_encoding;
1046 tree fndecl;
1047 tree last;
1048 char formatted_type_identifier_length[16];
1049 int type_identifier_length;
1051 if (methods == NULL_TREE)
1052 return;
1054 type_encoding = DECL_NAME (TYPE_NAME (type));
1056 #if 0
1057 /* C++: Template classes break some assumptions made by this code about
1058 the class names, constructor names, and encodings for assembler
1059 label names. For now, disable output of dbx info for them. */
1061 const char *ptr = IDENTIFIER_POINTER (type_encoding);
1062 /* This should use index. (mrs) */
1063 while (*ptr && *ptr != '<') ptr++;
1064 if (*ptr != 0)
1066 static int warned;
1067 if (!warned)
1068 warned = 1;
1069 return;
1072 #endif
1074 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
1076 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
1078 if (TREE_CODE (methods) != TREE_VEC)
1079 fndecl = methods;
1080 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1081 fndecl = TREE_VEC_ELT (methods, 0);
1082 else
1083 fndecl = TREE_VEC_ELT (methods, 1);
1085 while (fndecl)
1087 int need_prefix = 1;
1089 /* Group together all the methods for the same operation.
1090 These differ in the types of the arguments. */
1091 for (last = NULL_TREE;
1092 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1093 fndecl = TREE_CHAIN (fndecl))
1094 /* Output the name of the field (after overloading), as
1095 well as the name of the field before overloading, along
1096 with its parameter list */
1098 /* This is the "mangled" name of the method.
1099 It encodes the argument types. */
1100 const char *debug_name;
1102 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1103 include TEMPLATE_DECLs.) The debugger doesn't know what
1104 to do with such entities anyhow. */
1105 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1106 continue;
1108 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1110 CONTIN;
1112 last = fndecl;
1114 /* Also ignore abstract methods; those are only interesting to
1115 the DWARF backends. */
1116 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1117 continue;
1119 /* Redundantly output the plain name, since that's what gdb
1120 expects. */
1121 if (need_prefix)
1123 tree name = DECL_NAME (fndecl);
1124 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1125 CHARS (IDENTIFIER_LENGTH (name) + 2);
1126 need_prefix = 0;
1129 dbxout_type (TREE_TYPE (fndecl), 0);
1131 dbxout_type_method_1 (fndecl, debug_name);
1133 if (!need_prefix)
1135 putc (';', asmfile);
1136 CHARS (1);
1141 /* Emit a "range" type specification, which has the form:
1142 "r<index type>;<lower bound>;<upper bound>;".
1143 TYPE is an INTEGER_TYPE. */
1145 static void
1146 dbxout_range_type (tree type)
1148 fprintf (asmfile, "r");
1149 if (TREE_TYPE (type))
1150 dbxout_type (TREE_TYPE (type), 0);
1151 else if (TREE_CODE (type) != INTEGER_TYPE)
1152 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1153 else
1155 /* Traditionally, we made sure 'int' was type 1, and builtin types
1156 were defined to be sub-ranges of int. Unfortunately, this
1157 does not allow us to distinguish true sub-ranges from integer
1158 types. So, instead we define integer (non-sub-range) types as
1159 sub-ranges of themselves. This matters for Chill. If this isn't
1160 a subrange type, then we want to define it in terms of itself.
1161 However, in C, this may be an anonymous integer type, and we don't
1162 want to emit debug info referring to it. Just calling
1163 dbxout_type_index won't work anyways, because the type hasn't been
1164 defined yet. We make this work for both cases by checked to see
1165 whether this is a defined type, referring to it if it is, and using
1166 'int' otherwise. */
1167 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1168 dbxout_type_index (type);
1169 else
1170 dbxout_type_index (integer_type_node);
1173 if (TYPE_MIN_VALUE (type) != 0
1174 && host_integerp (TYPE_MIN_VALUE (type), 0))
1176 putc (';', asmfile);
1177 CHARS (1);
1178 if (print_int_cst_bounds_in_octal_p (type))
1179 print_int_cst_octal (TYPE_MIN_VALUE (type));
1180 else
1181 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1183 else
1185 fprintf (asmfile, ";0");
1186 CHARS (2);
1189 if (TYPE_MAX_VALUE (type) != 0
1190 && host_integerp (TYPE_MAX_VALUE (type), 0))
1192 putc (';', asmfile);
1193 CHARS (1);
1194 if (print_int_cst_bounds_in_octal_p (type))
1195 print_int_cst_octal (TYPE_MAX_VALUE (type));
1196 else
1197 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1198 putc (';', asmfile);
1199 CHARS (1);
1201 else
1203 fprintf (asmfile, ";-1;");
1204 CHARS (4);
1209 /* Output a reference to a type. If the type has not yet been
1210 described in the dbx output, output its definition now.
1211 For a type already defined, just refer to its definition
1212 using the type number.
1214 If FULL is nonzero, and the type has been described only with
1215 a forward-reference, output the definition now.
1216 If FULL is zero in this case, just refer to the forward-reference
1217 using the number previously allocated. */
1219 static void
1220 dbxout_type (tree type, int full)
1222 tree tem;
1223 tree main_variant;
1224 static int anonymous_type_number = 0;
1226 if (TREE_CODE (type) == VECTOR_TYPE)
1227 /* The frontend feeds us a representation for the vector as a struct
1228 containing an array. Pull out the array type. */
1229 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1231 /* If there was an input error and we don't really have a type,
1232 avoid crashing and write something that is at least valid
1233 by assuming `int'. */
1234 if (type == error_mark_node)
1235 type = integer_type_node;
1236 else
1238 if (TYPE_NAME (type)
1239 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1240 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1241 full = 0;
1244 /* Try to find the "main variant" with the same name. */
1245 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1246 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1247 main_variant = TREE_TYPE (TYPE_NAME (type));
1248 else
1249 main_variant = TYPE_MAIN_VARIANT (type);
1251 /* If we are not using extensions, stabs does not distinguish const and
1252 volatile, so there is no need to make them separate types. */
1253 if (!use_gnu_debug_info_extensions)
1254 type = main_variant;
1256 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1258 /* Type has no dbx number assigned. Assign next available number. */
1259 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1261 /* Make sure type vector is long enough to record about this type. */
1263 if (next_type_number == typevec_len)
1265 typevec
1266 = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1267 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1268 typevec_len *= 2;
1271 #ifdef DBX_USE_BINCL
1272 emit_pending_bincls_if_required ();
1273 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1274 = current_file->file_number;
1275 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1276 = current_file->next_type_number++;
1277 #endif
1280 if (flag_debug_only_used_symbols)
1282 if ((TREE_CODE (type) == RECORD_TYPE
1283 || TREE_CODE (type) == UNION_TYPE
1284 || TREE_CODE (type) == QUAL_UNION_TYPE
1285 || TREE_CODE (type) == ENUMERAL_TYPE)
1286 && TYPE_STUB_DECL (type)
1287 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (type))) == 'd'
1288 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1289 debug_queue_symbol (TYPE_STUB_DECL (type));
1290 else if (TYPE_NAME (type)
1291 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1292 debug_queue_symbol (TYPE_NAME (type));
1295 /* Output the number of this type, to refer to it. */
1296 dbxout_type_index (type);
1298 #ifdef DBX_TYPE_DEFINED
1299 if (DBX_TYPE_DEFINED (type))
1300 return;
1301 #endif
1303 /* If this type's definition has been output or is now being output,
1304 that is all. */
1306 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1308 case TYPE_UNSEEN:
1309 break;
1310 case TYPE_XREF:
1311 /* If we have already had a cross reference,
1312 and either that's all we want or that's the best we could do,
1313 don't repeat the cross reference.
1314 Sun dbx crashes if we do. */
1315 if (! full || !COMPLETE_TYPE_P (type)
1316 /* No way in DBX fmt to describe a variable size. */
1317 || ! host_integerp (TYPE_SIZE (type), 1))
1318 return;
1319 break;
1320 case TYPE_DEFINED:
1321 return;
1324 #ifdef DBX_NO_XREFS
1325 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1326 leave the type-number completely undefined rather than output
1327 a cross-reference. If we have already used GNU debug info extensions,
1328 then it is OK to output a cross reference. This is necessary to get
1329 proper C++ debug output. */
1330 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1331 || TREE_CODE (type) == QUAL_UNION_TYPE
1332 || TREE_CODE (type) == ENUMERAL_TYPE)
1333 && ! use_gnu_debug_info_extensions)
1334 /* We must use the same test here as we use twice below when deciding
1335 whether to emit a cross-reference. */
1336 if ((TYPE_NAME (type) != 0
1337 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1338 && DECL_IGNORED_P (TYPE_NAME (type)))
1339 && !full)
1340 || !COMPLETE_TYPE_P (type)
1341 /* No way in DBX fmt to describe a variable size. */
1342 || ! host_integerp (TYPE_SIZE (type), 1))
1344 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1345 return;
1347 #endif
1349 /* Output a definition now. */
1351 fprintf (asmfile, "=");
1352 CHARS (1);
1354 /* Mark it as defined, so that if it is self-referent
1355 we will not get into an infinite recursion of definitions. */
1357 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1359 /* If this type is a variant of some other, hand off. Types with
1360 different names are usefully distinguished. We only distinguish
1361 cv-qualified types if we're using extensions. */
1362 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1364 putc ('k', asmfile);
1365 CHARS (1);
1366 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1367 return;
1369 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1371 putc ('B', asmfile);
1372 CHARS (1);
1373 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1374 return;
1376 else if (main_variant != TYPE_MAIN_VARIANT (type))
1378 if (flag_debug_only_used_symbols)
1380 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1382 if ((TREE_CODE (orig_type) == RECORD_TYPE
1383 || TREE_CODE (orig_type) == UNION_TYPE
1384 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1385 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1386 && TYPE_STUB_DECL (orig_type)
1387 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1388 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1390 /* 'type' is a typedef; output the type it refers to. */
1391 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1392 return;
1394 /* else continue. */
1396 switch (TREE_CODE (type))
1398 case VOID_TYPE:
1399 case LANG_TYPE:
1400 /* For a void type, just define it as itself; ie, "5=5".
1401 This makes us consider it defined
1402 without saying what it is. The debugger will make it
1403 a void type when the reference is seen, and nothing will
1404 ever override that default. */
1405 dbxout_type_index (type);
1406 break;
1408 case INTEGER_TYPE:
1409 if (type == char_type_node && ! TREE_UNSIGNED (type))
1411 /* Output the type `char' as a subrange of itself!
1412 I don't understand this definition, just copied it
1413 from the output of pcc.
1414 This used to use `r2' explicitly and we used to
1415 take care to make sure that `char' was type number 2. */
1416 fprintf (asmfile, "r");
1417 CHARS (1);
1418 dbxout_type_index (type);
1419 fprintf (asmfile, ";0;127;");
1420 CHARS (7);
1423 /* If this is a subtype of another integer type, always prefer to
1424 write it as a subtype. */
1425 else if (TREE_TYPE (type) != 0
1426 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1428 /* If the size is non-standard, say what it is if we can use
1429 GDB extensions. */
1431 if (use_gnu_debug_info_extensions
1432 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1434 have_used_extensions = 1;
1435 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1436 CHARS (5);
1439 dbxout_range_type (type);
1442 else
1444 /* If the size is non-standard, say what it is if we can use
1445 GDB extensions. */
1447 if (use_gnu_debug_info_extensions
1448 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1450 have_used_extensions = 1;
1451 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1452 CHARS (5);
1455 if (print_int_cst_bounds_in_octal_p (type))
1457 fprintf (asmfile, "r");
1458 CHARS (1);
1460 /* If this type derives from another type, output type index of
1461 parent type. This is particularly important when parent type
1462 is an enumerated type, because not generating the parent type
1463 index would transform the definition of this enumerated type
1464 into a plain unsigned type. */
1465 if (TREE_TYPE (type) != 0)
1466 dbxout_type_index (TREE_TYPE (type));
1467 else
1468 dbxout_type_index (type);
1470 fprintf (asmfile, ";");
1471 CHARS (1);
1472 print_int_cst_octal (TYPE_MIN_VALUE (type));
1473 fprintf (asmfile, ";");
1474 CHARS (1);
1475 print_int_cst_octal (TYPE_MAX_VALUE (type));
1476 fprintf (asmfile, ";");
1477 CHARS (1);
1480 else
1481 /* Output other integer types as subranges of `int'. */
1482 dbxout_range_type (type);
1485 break;
1487 case REAL_TYPE:
1488 /* This used to say `r1' and we used to take care
1489 to make sure that `int' was type number 1. */
1490 fprintf (asmfile, "r");
1491 CHARS (1);
1492 dbxout_type_index (integer_type_node);
1493 putc (';', asmfile);
1494 CHARS (1);
1495 print_wide_int (int_size_in_bytes (type));
1496 fputs (";0;", asmfile);
1497 CHARS (3);
1498 break;
1500 case CHAR_TYPE:
1501 if (use_gnu_debug_info_extensions)
1503 have_used_extensions = 1;
1504 fputs ("@s", asmfile);
1505 CHARS (2);
1506 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1507 fputs (";-20;", asmfile);
1508 CHARS (4);
1510 else
1512 /* Output the type `char' as a subrange of itself.
1513 That is what pcc seems to do. */
1514 fprintf (asmfile, "r");
1515 CHARS (1);
1516 dbxout_type_index (char_type_node);
1517 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1518 CHARS (7);
1520 break;
1522 case BOOLEAN_TYPE:
1523 if (use_gnu_debug_info_extensions)
1525 have_used_extensions = 1;
1526 fputs ("@s", asmfile);
1527 CHARS (2);
1528 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1529 fputs (";-16;", asmfile);
1530 CHARS (4);
1532 else /* Define as enumeral type (False, True) */
1534 fprintf (asmfile, "eFalse:0,True:1,;");
1535 CHARS (17);
1537 break;
1539 case FILE_TYPE:
1540 putc ('d', asmfile);
1541 CHARS (1);
1542 dbxout_type (TREE_TYPE (type), 0);
1543 break;
1545 case COMPLEX_TYPE:
1546 /* Differs from the REAL_TYPE by its new data type number */
1548 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1550 putc ('R', asmfile);
1551 CHARS (1);
1552 dbxout_fptype_value (type);
1553 putc (';', asmfile);
1554 CHARS (1);
1555 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1556 fputs (";0;", asmfile);
1557 CHARS (3);
1559 else
1561 /* Output a complex integer type as a structure,
1562 pending some other way to do it. */
1563 putc ('s', asmfile);
1564 CHARS (1);
1565 print_wide_int (int_size_in_bytes (type));
1566 fprintf (asmfile, "real:");
1567 CHARS (5);
1569 dbxout_type (TREE_TYPE (type), 0);
1570 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1571 CHARS (7);
1572 fprintf (asmfile, "imag:");
1573 CHARS (5);
1574 dbxout_type (TREE_TYPE (type), 0);
1575 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1576 TYPE_PRECISION (TREE_TYPE (type)));
1577 CHARS (10);
1579 break;
1581 case SET_TYPE:
1582 if (use_gnu_debug_info_extensions)
1584 have_used_extensions = 1;
1585 fputs ("@s", asmfile);
1586 CHARS (2);
1587 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1588 putc (';', asmfile);
1589 CHARS (1);
1591 /* Check if a bitstring type, which in Chill is
1592 different from a [power]set. */
1593 if (TYPE_STRING_FLAG (type))
1595 fprintf (asmfile, "@S;");
1596 CHARS (3);
1599 putc ('S', asmfile);
1600 CHARS (1);
1601 dbxout_type (TYPE_DOMAIN (type), 0);
1602 break;
1604 case ARRAY_TYPE:
1605 /* Make arrays of packed bits look like bitstrings for chill. */
1606 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1608 have_used_extensions = 1;
1609 fputs ("@s", asmfile);
1610 CHARS (2);
1611 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1612 fprintf (asmfile, ";@S;S");
1613 CHARS (5);
1614 dbxout_type (TYPE_DOMAIN (type), 0);
1615 break;
1618 /* Output "a" followed by a range type definition
1619 for the index type of the array
1620 followed by a reference to the target-type.
1621 ar1;0;N;M for a C array of type M and size N+1. */
1622 /* Check if a character string type, which in Chill is
1623 different from an array of characters. */
1624 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1626 have_used_extensions = 1;
1627 fprintf (asmfile, "@S;");
1628 CHARS (3);
1630 tem = TYPE_DOMAIN (type);
1631 if (tem == NULL)
1633 fprintf (asmfile, "ar");
1634 CHARS (2);
1635 dbxout_type_index (integer_type_node);
1636 fprintf (asmfile, ";0;-1;");
1637 CHARS (6);
1639 else
1641 fprintf (asmfile, "a");
1642 CHARS (1);
1643 dbxout_range_type (tem);
1646 dbxout_type (TREE_TYPE (type), 0);
1647 break;
1649 case RECORD_TYPE:
1650 case UNION_TYPE:
1651 case QUAL_UNION_TYPE:
1653 int i, n_baseclasses = 0;
1655 if (TYPE_BINFO (type) != 0
1656 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1657 && TYPE_BINFO_BASETYPES (type) != 0)
1658 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1660 /* Output a structure type. We must use the same test here as we
1661 use in the DBX_NO_XREFS case above. */
1662 if ((TYPE_NAME (type) != 0
1663 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1664 && DECL_IGNORED_P (TYPE_NAME (type)))
1665 && !full)
1666 || !COMPLETE_TYPE_P (type)
1667 /* No way in DBX fmt to describe a variable size. */
1668 || ! host_integerp (TYPE_SIZE (type), 1))
1670 /* If the type is just a cross reference, output one
1671 and mark the type as partially described.
1672 If it later becomes defined, we will output
1673 its real definition.
1674 If the type has a name, don't nest its definition within
1675 another type's definition; instead, output an xref
1676 and let the definition come when the name is defined. */
1677 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1678 CHARS (2);
1679 #if 0 /* This assertion is legitimately false in C++. */
1680 /* We shouldn't be outputting a reference to a type before its
1681 definition unless the type has a tag name.
1682 A typedef name without a tag name should be impossible. */
1683 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1684 abort ();
1685 #endif
1686 if (TYPE_NAME (type) != 0)
1687 dbxout_type_name (type);
1688 else
1690 fprintf (asmfile, "$$%d", anonymous_type_number++);
1691 CHARS (5);
1694 fprintf (asmfile, ":");
1695 CHARS (1);
1696 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1697 break;
1700 /* Identify record or union, and print its size. */
1701 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1702 CHARS (1);
1703 print_wide_int (int_size_in_bytes (type));
1705 if (use_gnu_debug_info_extensions)
1707 if (n_baseclasses)
1709 have_used_extensions = 1;
1710 fprintf (asmfile, "!%d,", n_baseclasses);
1711 CHARS (8);
1714 for (i = 0; i < n_baseclasses; i++)
1716 tree binfo = TYPE_BINFO (type);
1717 tree child = BINFO_BASETYPE (binfo, i);
1718 tree access = (BINFO_BASEACCESSES (binfo)
1719 ? BINFO_BASEACCESS (binfo, i) : access_public_node);
1721 if (use_gnu_debug_info_extensions)
1723 have_used_extensions = 1;
1724 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1725 putc (access == access_public_node ? '2' : '0', asmfile);
1726 CHARS (2);
1727 if (TREE_VIA_VIRTUAL (child)
1728 && strcmp (lang_hooks.name, "GNU C++") == 0)
1729 /* For a virtual base, print the (negative) offset within
1730 the vtable where we must look to find the necessary
1731 adjustment. */
1732 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1733 * BITS_PER_UNIT);
1734 else
1735 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1736 * BITS_PER_UNIT);
1737 putc (',', asmfile);
1738 CHARS (1);
1739 dbxout_type (BINFO_TYPE (child), 0);
1740 putc (';', asmfile);
1741 CHARS (1);
1743 else
1745 /* Print out the base class information with fields
1746 which have the same names at the types they hold. */
1747 dbxout_type_name (BINFO_TYPE (child));
1748 putc (':', asmfile);
1749 CHARS (1);
1750 dbxout_type (BINFO_TYPE (child), full);
1751 putc (',', asmfile);
1752 CHARS (1);
1753 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1754 * BITS_PER_UNIT);
1755 putc (',', asmfile);
1756 CHARS (1);
1757 print_wide_int (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)),
1759 * BITS_PER_UNIT);
1760 putc (';', asmfile);
1761 CHARS (1);
1766 /* Write out the field declarations. */
1767 dbxout_type_fields (type);
1768 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1770 have_used_extensions = 1;
1771 dbxout_type_methods (type);
1774 putc (';', asmfile);
1775 CHARS (1);
1777 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1778 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1779 && TYPE_VFIELD (type))
1781 have_used_extensions = 1;
1783 /* Tell GDB+ that it may keep reading. */
1784 putc ('~', asmfile);
1785 CHARS (1);
1787 /* We need to write out info about what field this class
1788 uses as its "main" vtable pointer field, because if this
1789 field is inherited from a base class, GDB cannot necessarily
1790 figure out which field it's using in time. */
1791 if (TYPE_VFIELD (type))
1793 putc ('%', asmfile);
1794 CHARS (1);
1795 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1798 putc (';', asmfile);
1799 CHARS (1);
1801 break;
1803 case ENUMERAL_TYPE:
1804 /* We must use the same test here as we use in the DBX_NO_XREFS case
1805 above. We simplify it a bit since an enum will never have a variable
1806 size. */
1807 if ((TYPE_NAME (type) != 0
1808 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1809 && DECL_IGNORED_P (TYPE_NAME (type)))
1810 && !full)
1811 || !COMPLETE_TYPE_P (type))
1813 fprintf (asmfile, "xe");
1814 CHARS (2);
1815 dbxout_type_name (type);
1816 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1817 putc (':', asmfile);
1818 CHARS (1);
1819 return;
1821 if (use_gnu_debug_info_extensions
1822 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1824 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1825 CHARS (5);
1828 putc ('e', asmfile);
1829 CHARS (1);
1830 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1832 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1833 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1834 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1835 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1836 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1837 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1838 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1839 else
1840 print_int_cst_octal (TREE_VALUE (tem));
1842 putc (',', asmfile);
1843 CHARS (1);
1844 if (TREE_CHAIN (tem) != 0)
1845 CONTIN;
1848 putc (';', asmfile);
1849 CHARS (1);
1850 break;
1852 case POINTER_TYPE:
1853 putc ('*', asmfile);
1854 CHARS (1);
1855 dbxout_type (TREE_TYPE (type), 0);
1856 break;
1858 case METHOD_TYPE:
1859 if (use_gnu_debug_info_extensions)
1861 have_used_extensions = 1;
1862 putc ('#', asmfile);
1863 CHARS (1);
1865 /* Write the argument types out longhand. */
1866 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1867 putc (',', asmfile);
1868 CHARS (1);
1869 dbxout_type (TREE_TYPE (type), 0);
1870 dbxout_args (TYPE_ARG_TYPES (type));
1871 putc (';', asmfile);
1872 CHARS (1);
1874 else
1875 /* Treat it as a function type. */
1876 dbxout_type (TREE_TYPE (type), 0);
1877 break;
1879 case OFFSET_TYPE:
1880 if (use_gnu_debug_info_extensions)
1882 have_used_extensions = 1;
1883 putc ('@', asmfile);
1884 CHARS (1);
1885 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1886 putc (',', asmfile);
1887 CHARS (1);
1888 dbxout_type (TREE_TYPE (type), 0);
1890 else
1891 /* Should print as an int, because it is really just an offset. */
1892 dbxout_type (integer_type_node, 0);
1893 break;
1895 case REFERENCE_TYPE:
1896 if (use_gnu_debug_info_extensions)
1897 have_used_extensions = 1;
1898 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1899 CHARS (1);
1900 dbxout_type (TREE_TYPE (type), 0);
1901 break;
1903 case FUNCTION_TYPE:
1904 putc ('f', asmfile);
1905 CHARS (1);
1906 dbxout_type (TREE_TYPE (type), 0);
1907 break;
1909 default:
1910 abort ();
1914 /* Return nonzero if the given type represents an integer whose bounds
1915 should be printed in octal format. */
1917 static bool
1918 print_int_cst_bounds_in_octal_p (tree type)
1920 /* If we can use GDB extensions and the size is wider than a long
1921 (the size used by GDB to read them) or we may have trouble writing
1922 the bounds the usual way, write them in octal. Note the test is for
1923 the *target's* size of "long", not that of the host. The host test
1924 is just to make sure we can write it out in case the host wide int
1925 is narrower than the target "long".
1927 For unsigned types, we use octal if they are the same size or larger.
1928 This is because we print the bounds as signed decimal, and hence they
1929 can't span same size unsigned types. */
1931 if (use_gnu_debug_info_extensions
1932 && TYPE_MIN_VALUE (type) != 0
1933 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1934 && TYPE_MAX_VALUE (type) != 0
1935 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1936 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1937 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1938 && TREE_UNSIGNED (type))
1939 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1940 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1941 && TREE_UNSIGNED (type))))
1942 return TRUE;
1943 else
1944 return FALSE;
1947 /* Print the value of integer constant C, in octal,
1948 handling double precision. */
1950 static void
1951 print_int_cst_octal (tree c)
1953 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1954 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1955 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1956 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1958 /* GDB wants constants with no extra leading "1" bits, so
1959 we need to remove any sign-extension that might be
1960 present. */
1961 if (width == HOST_BITS_PER_WIDE_INT * 2)
1963 else if (width > HOST_BITS_PER_WIDE_INT)
1964 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1965 else if (width == HOST_BITS_PER_WIDE_INT)
1966 high = 0;
1967 else
1968 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1970 fprintf (asmfile, "0");
1971 CHARS (1);
1973 if (excess == 3)
1975 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1976 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1978 else
1980 unsigned HOST_WIDE_INT beg = high >> excess;
1981 unsigned HOST_WIDE_INT middle
1982 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1983 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1984 unsigned HOST_WIDE_INT end
1985 = low & (((unsigned HOST_WIDE_INT) 1
1986 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1987 - 1);
1989 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1990 CHARS (2);
1991 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1995 static void
1996 print_octal (unsigned HOST_WIDE_INT value, int digits)
1998 int i;
2000 for (i = digits - 1; i >= 0; i--)
2001 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
2003 CHARS (digits);
2006 /* Output C in decimal while adjusting the number of digits written. */
2008 static void
2009 print_wide_int (HOST_WIDE_INT c)
2011 int digs = 0;
2013 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
2015 if (c < 0)
2016 digs++, c = -c;
2018 while (c > 0)
2019 c /= 10; digs++;
2021 CHARS (digs);
2024 /* Output the name of type TYPE, with no punctuation.
2025 Such names can be set up either by typedef declarations
2026 or by struct, enum and union tags. */
2028 static void
2029 dbxout_type_name (tree type)
2031 tree t;
2032 if (TYPE_NAME (type) == 0)
2033 abort ();
2034 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2036 t = TYPE_NAME (type);
2038 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2040 t = DECL_NAME (TYPE_NAME (type));
2042 else
2043 abort ();
2045 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
2046 CHARS (IDENTIFIER_LENGTH (t));
2049 /* Output leading leading struct or class names needed for qualifying
2050 type whose scope is limited to a struct or class. */
2052 static void
2053 dbxout_class_name_qualifiers (tree decl)
2055 tree context = decl_type_context (decl);
2057 if (context != NULL_TREE
2058 && TREE_CODE(context) == RECORD_TYPE
2059 && TYPE_NAME (context) != 0
2060 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2061 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2063 tree name = TYPE_NAME (context);
2065 emit_pending_bincls_if_required ();
2067 if (TREE_CODE (name) == TYPE_DECL)
2069 dbxout_class_name_qualifiers (name);
2070 name = DECL_NAME (name);
2072 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
2073 CHARS (IDENTIFIER_LENGTH (name) + 2);
2077 /* Output a .stabs for the symbol defined by DECL,
2078 which must be a ..._DECL node in the normal namespace.
2079 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2080 LOCAL is nonzero if the scope is less than the entire file.
2081 Return 1 if a stabs might have been emitted. */
2084 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2086 tree type = TREE_TYPE (decl);
2087 tree context = NULL_TREE;
2088 int result = 0;
2090 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2091 ++debug_nesting;
2093 /* Cast avoids warning in old compilers. */
2094 current_sym_code = (STAB_CODE_TYPE) 0;
2095 current_sym_value = 0;
2096 current_sym_addr = 0;
2098 /* Ignore nameless syms, but don't ignore type tags. */
2100 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2101 || DECL_IGNORED_P (decl))
2102 DBXOUT_DECR_NESTING_AND_RETURN (0);
2104 /* If we are to generate only the symbols actually used then such
2105 symbol nodees are flagged with TREE_USED. Ignore any that
2106 aren't flaged as TREE_USED. */
2108 if (flag_debug_only_used_symbols)
2110 tree t;
2112 if (!TREE_USED (decl)
2113 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl)))
2114 DBXOUT_DECR_NESTING_AND_RETURN (0);
2116 /* We now have a used symbol. We need to generate the info for
2117 the symbol's type in addition to the symbol itself. These
2118 type symbols are queued to be generated after were done with
2119 the symbol itself (done because the symbol's info is generated
2120 with fprintf's, etc. as it determines what's needed).
2122 Note, because the TREE_TYPE(type) might be something like a
2123 pointer to a named type we need to look for the first name
2124 we see following the TREE_TYPE chain. */
2126 t = type;
2127 while (POINTER_TYPE_P (t))
2128 t = TREE_TYPE (t);
2130 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2131 need special treatment. The TYPE_STUB_DECL field in these
2132 types generally represents the tag name type we want to
2133 output. In addition there could be a typedef type with
2134 a different name. In that case we also want to output
2135 that. */
2137 if ((TREE_CODE (t) == RECORD_TYPE
2138 || TREE_CODE (t) == UNION_TYPE
2139 || TREE_CODE (t) == QUAL_UNION_TYPE
2140 || TREE_CODE (t) == ENUMERAL_TYPE)
2141 && TYPE_STUB_DECL (t)
2142 && TYPE_STUB_DECL (t) != decl
2143 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (t))) == 'd'
2144 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2146 debug_queue_symbol (TYPE_STUB_DECL (t));
2147 if (TYPE_NAME (t)
2148 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2149 && TYPE_NAME (t) != decl
2150 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2151 debug_queue_symbol (TYPE_NAME (t));
2153 else if (TYPE_NAME (t)
2154 && TYPE_NAME (t) != decl
2155 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2156 debug_queue_symbol (TYPE_NAME (t));
2159 emit_pending_bincls_if_required ();
2161 dbxout_prepare_symbol (decl);
2163 /* The output will always start with the symbol name,
2164 so always count that in the length-output-so-far. */
2166 if (DECL_NAME (decl) != 0)
2167 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2169 switch (TREE_CODE (decl))
2171 case CONST_DECL:
2172 /* Enum values are defined by defining the enum type. */
2173 break;
2175 case FUNCTION_DECL:
2176 if (DECL_RTL (decl) == 0)
2177 DBXOUT_DECR_NESTING_AND_RETURN (0);
2178 if (DECL_EXTERNAL (decl))
2179 break;
2180 /* Don't mention a nested function under its parent. */
2181 context = decl_function_context (decl);
2182 if (context == current_function_decl)
2183 break;
2184 if (GET_CODE (DECL_RTL (decl)) != MEM
2185 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2186 break;
2187 FORCE_TEXT;
2189 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2190 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2191 TREE_PUBLIC (decl) ? 'F' : 'f');
2192 result = 1;
2194 current_sym_code = N_FUN;
2195 current_sym_addr = XEXP (DECL_RTL (decl), 0);
2197 if (TREE_TYPE (type))
2198 dbxout_type (TREE_TYPE (type), 0);
2199 else
2200 dbxout_type (void_type_node, 0);
2202 /* For a nested function, when that function is compiled,
2203 mention the containing function name
2204 as well as (since dbx wants it) our own assembler-name. */
2205 if (context != 0)
2206 fprintf (asmfile, ",%s,%s",
2207 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2208 IDENTIFIER_POINTER (DECL_NAME (context)));
2210 dbxout_finish_symbol (decl);
2211 break;
2213 case TYPE_DECL:
2214 /* Don't output the same typedef twice.
2215 And don't output what language-specific stuff doesn't want output. */
2216 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2217 DBXOUT_DECR_NESTING_AND_RETURN (0);
2219 FORCE_TEXT;
2220 result = 1;
2222 int tag_needed = 1;
2223 int did_output = 0;
2225 if (DECL_NAME (decl))
2227 /* Nonzero means we must output a tag as well as a typedef. */
2228 tag_needed = 0;
2230 /* Handle the case of a C++ structure or union
2231 where the TYPE_NAME is a TYPE_DECL
2232 which gives both a typedef name and a tag. */
2233 /* dbx requires the tag first and the typedef second. */
2234 if ((TREE_CODE (type) == RECORD_TYPE
2235 || TREE_CODE (type) == UNION_TYPE
2236 || TREE_CODE (type) == QUAL_UNION_TYPE)
2237 && TYPE_NAME (type) == decl
2238 && !(use_gnu_debug_info_extensions && have_used_extensions)
2239 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2240 /* Distinguish the implicit typedefs of C++
2241 from explicit ones that might be found in C. */
2242 && DECL_ARTIFICIAL (decl)
2243 /* Do not generate a tag for incomplete records. */
2244 && COMPLETE_TYPE_P (type)
2245 /* Do not generate a tag for records of variable size,
2246 since this type can not be properly described in the
2247 DBX format, and it confuses some tools such as objdump. */
2248 && host_integerp (TYPE_SIZE (type), 1))
2250 tree name = TYPE_NAME (type);
2251 if (TREE_CODE (name) == TYPE_DECL)
2252 name = DECL_NAME (name);
2254 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2255 current_sym_value = 0;
2256 current_sym_addr = 0;
2257 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2259 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2260 IDENTIFIER_POINTER (name));
2261 dbxout_type (type, 1);
2262 dbxout_finish_symbol (NULL_TREE);
2265 /* Output .stabs (or whatever) and leading double quote. */
2266 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2268 if (use_gnu_debug_info_extensions)
2270 /* Output leading class/struct qualifiers. */
2271 dbxout_class_name_qualifiers (decl);
2274 /* Output typedef name. */
2275 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2277 /* Short cut way to output a tag also. */
2278 if ((TREE_CODE (type) == RECORD_TYPE
2279 || TREE_CODE (type) == UNION_TYPE
2280 || TREE_CODE (type) == QUAL_UNION_TYPE)
2281 && TYPE_NAME (type) == decl
2282 /* Distinguish the implicit typedefs of C++
2283 from explicit ones that might be found in C. */
2284 && DECL_ARTIFICIAL (decl))
2286 if (use_gnu_debug_info_extensions && have_used_extensions)
2288 putc ('T', asmfile);
2289 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2291 #if 0 /* Now we generate the tag for this case up above. */
2292 else
2293 tag_needed = 1;
2294 #endif
2297 putc ('t', asmfile);
2298 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2300 dbxout_type (type, 1);
2301 dbxout_finish_symbol (decl);
2302 did_output = 1;
2305 /* Don't output a tag if this is an incomplete type. This prevents
2306 the sun4 Sun OS 4.x dbx from crashing. */
2308 if (tag_needed && TYPE_NAME (type) != 0
2309 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2310 || (DECL_NAME (TYPE_NAME (type)) != 0))
2311 && COMPLETE_TYPE_P (type)
2312 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2314 /* For a TYPE_DECL with no name, but the type has a name,
2315 output a tag.
2316 This is what represents `struct foo' with no typedef. */
2317 /* In C++, the name of a type is the corresponding typedef.
2318 In C, it is an IDENTIFIER_NODE. */
2319 tree name = TYPE_NAME (type);
2320 if (TREE_CODE (name) == TYPE_DECL)
2321 name = DECL_NAME (name);
2323 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2324 current_sym_value = 0;
2325 current_sym_addr = 0;
2326 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2328 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2329 IDENTIFIER_POINTER (name));
2330 dbxout_type (type, 1);
2331 dbxout_finish_symbol (NULL_TREE);
2332 did_output = 1;
2335 /* If an enum type has no name, it cannot be referred to,
2336 but we must output it anyway, since the enumeration constants
2337 can be referred to. */
2338 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2340 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2341 current_sym_value = 0;
2342 current_sym_addr = 0;
2343 current_sym_nchars = 2;
2345 /* Some debuggers fail when given NULL names, so give this a
2346 harmless name of ` '. */
2347 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2348 dbxout_type (type, 1);
2349 dbxout_finish_symbol (NULL_TREE);
2352 /* Prevent duplicate output of a typedef. */
2353 TREE_ASM_WRITTEN (decl) = 1;
2354 break;
2357 case PARM_DECL:
2358 /* Parm decls go in their own separate chains
2359 and are output by dbxout_reg_parms and dbxout_parms. */
2360 abort ();
2362 case RESULT_DECL:
2363 /* Named return value, treat like a VAR_DECL. */
2364 case VAR_DECL:
2365 if (! DECL_RTL_SET_P (decl))
2366 DBXOUT_DECR_NESTING_AND_RETURN (0);
2367 /* Don't mention a variable that is external.
2368 Let the file that defines it describe it. */
2369 if (DECL_EXTERNAL (decl))
2370 break;
2372 /* If the variable is really a constant
2373 and not written in memory, inform the debugger. */
2374 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2375 && DECL_INITIAL (decl) != 0
2376 && host_integerp (DECL_INITIAL (decl), 0)
2377 && ! TREE_ASM_WRITTEN (decl)
2378 && (DECL_CONTEXT (decl) == NULL_TREE
2379 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2381 if (TREE_PUBLIC (decl) == 0)
2383 /* The sun4 assembler does not grok this. */
2384 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2386 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2387 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2389 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2390 fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2391 "\",0x%x,0,0,0\n",
2392 ASM_STABS_OP, name, ival, N_LSYM);
2393 DBXOUT_DECR_NESTING;
2394 return 1;
2396 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2398 /* don't know how to do this yet. */
2400 break;
2402 /* else it is something we handle like a normal variable. */
2405 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2406 #ifdef LEAF_REG_REMAP
2407 if (current_function_uses_only_leaf_regs)
2408 leaf_renumber_regs_insn (DECL_RTL (decl));
2409 #endif
2411 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2412 break;
2414 default:
2415 break;
2417 DBXOUT_DECR_NESTING;
2418 return result;
2421 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2422 Add SUFFIX to its name, if SUFFIX is not 0.
2423 Describe the variable as residing in HOME
2424 (usually HOME is DECL_RTL (DECL), but not always).
2425 Returns 1 if the stab was really emitted. */
2427 static int
2428 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2430 int letter = 0;
2431 int regno = -1;
2433 emit_pending_bincls_if_required ();
2435 /* Don't mention a variable at all
2436 if it was completely optimized into nothingness.
2438 If the decl was from an inline function, then its rtl
2439 is not identically the rtl that was used in this
2440 particular compilation. */
2441 if (GET_CODE (home) == SUBREG)
2443 rtx value = home;
2445 while (GET_CODE (value) == SUBREG)
2446 value = SUBREG_REG (value);
2447 if (GET_CODE (value) == REG)
2449 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2450 return 0;
2452 home = alter_subreg (&home);
2454 if (GET_CODE (home) == REG)
2456 regno = REGNO (home);
2457 if (regno >= FIRST_PSEUDO_REGISTER)
2458 return 0;
2461 /* The kind-of-variable letter depends on where
2462 the variable is and on the scope of its name:
2463 G and N_GSYM for static storage and global scope,
2464 S for static storage and file scope,
2465 V for static storage and local scope,
2466 for those two, use N_LCSYM if data is in bss segment,
2467 N_STSYM if in data segment, N_FUN otherwise.
2468 (We used N_FUN originally, then changed to N_STSYM
2469 to please GDB. However, it seems that confused ld.
2470 Now GDB has been fixed to like N_FUN, says Kingdon.)
2471 no letter at all, and N_LSYM, for auto variable,
2472 r and N_RSYM for register variable. */
2474 if (GET_CODE (home) == MEM
2475 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2477 if (TREE_PUBLIC (decl))
2479 letter = 'G';
2480 current_sym_code = N_GSYM;
2482 else
2484 current_sym_addr = XEXP (home, 0);
2486 letter = decl_function_context (decl) ? 'V' : 'S';
2488 /* This should be the same condition as in assemble_variable, but
2489 we don't have access to dont_output_data here. So, instead,
2490 we rely on the fact that error_mark_node initializers always
2491 end up in bss for C++ and never end up in bss for C. */
2492 if (DECL_INITIAL (decl) == 0
2493 || (!strcmp (lang_hooks.name, "GNU C++")
2494 && DECL_INITIAL (decl) == error_mark_node))
2495 current_sym_code = N_LCSYM;
2496 else if (DECL_IN_TEXT_SECTION (decl))
2497 /* This is not quite right, but it's the closest
2498 of all the codes that Unix defines. */
2499 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2500 else
2502 /* Some ports can transform a symbol ref into a label ref,
2503 because the symbol ref is too far away and has to be
2504 dumped into a constant pool. Alternatively, the symbol
2505 in the constant pool might be referenced by a different
2506 symbol. */
2507 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2508 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2510 rtx tmp = get_pool_constant (current_sym_addr);
2512 if (GET_CODE (tmp) == SYMBOL_REF
2513 || GET_CODE (tmp) == LABEL_REF)
2514 current_sym_addr = tmp;
2517 /* Ultrix `as' seems to need this. */
2518 #ifdef DBX_STATIC_STAB_DATA_SECTION
2519 data_section ();
2520 #endif
2521 current_sym_code = N_STSYM;
2525 else if (regno >= 0)
2527 letter = 'r';
2528 current_sym_code = N_RSYM;
2529 current_sym_value = DBX_REGISTER_NUMBER (regno);
2531 else if (GET_CODE (home) == MEM
2532 && (GET_CODE (XEXP (home, 0)) == MEM
2533 || (GET_CODE (XEXP (home, 0)) == REG
2534 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2535 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2536 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2537 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2538 #endif
2540 /* If the value is indirect by memory or by a register
2541 that isn't the frame pointer
2542 then it means the object is variable-sized and address through
2543 that register or stack slot. DBX has no way to represent this
2544 so all we can do is output the variable as a pointer.
2545 If it's not a parameter, ignore it.
2546 (VAR_DECLs like this can be made by integrate.c.) */
2548 if (GET_CODE (XEXP (home, 0)) == REG)
2550 letter = 'r';
2551 current_sym_code = N_RSYM;
2552 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2553 return 0;
2554 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2556 else
2558 current_sym_code = N_LSYM;
2559 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2560 We want the value of that CONST_INT. */
2561 current_sym_value
2562 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2565 /* Effectively do build_pointer_type, but don't cache this type,
2566 since it might be temporary whereas the type it points to
2567 might have been saved for inlining. */
2568 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2569 type = make_node (POINTER_TYPE);
2570 TREE_TYPE (type) = TREE_TYPE (decl);
2572 else if (GET_CODE (home) == MEM
2573 && GET_CODE (XEXP (home, 0)) == REG)
2575 current_sym_code = N_LSYM;
2576 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2578 else if (GET_CODE (home) == MEM
2579 && GET_CODE (XEXP (home, 0)) == PLUS
2580 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2582 current_sym_code = N_LSYM;
2583 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2584 We want the value of that CONST_INT. */
2585 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2587 else if (GET_CODE (home) == MEM
2588 && GET_CODE (XEXP (home, 0)) == CONST)
2590 /* Handle an obscure case which can arise when optimizing and
2591 when there are few available registers. (This is *always*
2592 the case for i386/i486 targets). The RTL looks like
2593 (MEM (CONST ...)) even though this variable is a local `auto'
2594 or a local `register' variable. In effect, what has happened
2595 is that the reload pass has seen that all assignments and
2596 references for one such a local variable can be replaced by
2597 equivalent assignments and references to some static storage
2598 variable, thereby avoiding the need for a register. In such
2599 cases we're forced to lie to debuggers and tell them that
2600 this variable was itself `static'. */
2601 current_sym_code = N_LCSYM;
2602 letter = 'V';
2603 current_sym_addr = XEXP (XEXP (home, 0), 0);
2605 else if (GET_CODE (home) == CONCAT)
2607 tree subtype;
2609 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2610 for example), then there is no easy way to figure out
2611 what SUBTYPE should be. So, we give up. */
2612 if (TREE_CODE (type) != COMPLEX_TYPE)
2613 return 0;
2615 subtype = TREE_TYPE (type);
2617 /* If the variable's storage is in two parts,
2618 output each as a separate stab with a modified name. */
2619 if (WORDS_BIG_ENDIAN)
2620 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2621 else
2622 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2624 /* Cast avoids warning in old compilers. */
2625 current_sym_code = (STAB_CODE_TYPE) 0;
2626 current_sym_value = 0;
2627 current_sym_addr = 0;
2628 dbxout_prepare_symbol (decl);
2630 if (WORDS_BIG_ENDIAN)
2631 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2632 else
2633 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2634 return 1;
2636 else
2637 /* Address might be a MEM, when DECL is a variable-sized object.
2638 Or it might be const0_rtx, meaning previous passes
2639 want us to ignore this variable. */
2640 return 0;
2642 /* Ok, start a symtab entry and output the variable name. */
2643 FORCE_TEXT;
2645 #ifdef DBX_STATIC_BLOCK_START
2646 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2647 #endif
2649 dbxout_symbol_name (decl, suffix, letter);
2650 dbxout_type (type, 0);
2651 dbxout_finish_symbol (decl);
2653 #ifdef DBX_STATIC_BLOCK_END
2654 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2655 #endif
2656 return 1;
2659 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2660 Then output LETTER to indicate the kind of location the symbol has. */
2662 static void
2663 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2665 const char *name;
2667 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2668 /* One slight hitch: if this is a VAR_DECL which is a static
2669 class member, we must put out the mangled name instead of the
2670 DECL_NAME. Note also that static member (variable) names DO NOT begin
2671 with underscores in .stabs directives. */
2672 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2673 else
2674 /* ...but if we're function-local, we don't want to include the junk
2675 added by ASM_FORMAT_PRIVATE_NAME. */
2676 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2678 if (name == 0)
2679 name = "(anon)";
2680 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2681 (suffix ? suffix : ""));
2683 if (letter)
2684 putc (letter, asmfile);
2687 static void
2688 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)
2690 #ifdef WINNING_GDB
2691 const char *filename = DECL_SOURCE_FILE (decl);
2693 dbxout_source_file (asmfile, filename);
2694 #endif
2697 static void
2698 dbxout_finish_symbol (tree sym)
2700 #ifdef DBX_FINISH_SYMBOL
2701 DBX_FINISH_SYMBOL (sym);
2702 #else
2703 int line = 0;
2704 if (use_gnu_debug_info_extensions && sym != 0)
2705 line = DECL_SOURCE_LINE (sym);
2707 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2708 if (current_sym_addr)
2709 output_addr_const (asmfile, current_sym_addr);
2710 else
2711 fprintf (asmfile, "%d", current_sym_value);
2712 putc ('\n', asmfile);
2713 #endif
2716 /* Output definitions of all the decls in a chain. Return nonzero if
2717 anything was output */
2720 dbxout_syms (tree syms)
2722 int result = 0;
2723 while (syms)
2725 result += dbxout_symbol (syms, 1);
2726 syms = TREE_CHAIN (syms);
2728 return result;
2731 /* The following two functions output definitions of function parameters.
2732 Each parameter gets a definition locating it in the parameter list.
2733 Each parameter that is a register variable gets a second definition
2734 locating it in the register.
2736 Printing or argument lists in gdb uses the definitions that
2737 locate in the parameter list. But reference to the variable in
2738 expressions uses preferentially the definition as a register. */
2740 /* Output definitions, referring to storage in the parmlist,
2741 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2743 void
2744 dbxout_parms (tree parms)
2746 ++debug_nesting;
2748 emit_pending_bincls_if_required ();
2750 for (; parms; parms = TREE_CHAIN (parms))
2751 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2753 dbxout_prepare_symbol (parms);
2755 /* Perform any necessary register eliminations on the parameter's rtl,
2756 so that the debugging output will be accurate. */
2757 DECL_INCOMING_RTL (parms)
2758 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2759 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2760 #ifdef LEAF_REG_REMAP
2761 if (current_function_uses_only_leaf_regs)
2763 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2764 leaf_renumber_regs_insn (DECL_RTL (parms));
2766 #endif
2768 if (PARM_PASSED_IN_MEMORY (parms))
2770 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2772 /* ??? Here we assume that the parm address is indexed
2773 off the frame pointer or arg pointer.
2774 If that is not true, we produce meaningless results,
2775 but do not crash. */
2776 if (GET_CODE (addr) == PLUS
2777 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2778 current_sym_value = INTVAL (XEXP (addr, 1));
2779 else
2780 current_sym_value = 0;
2782 current_sym_code = N_PSYM;
2783 current_sym_addr = 0;
2785 FORCE_TEXT;
2786 if (DECL_NAME (parms))
2788 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2790 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2791 IDENTIFIER_POINTER (DECL_NAME (parms)),
2792 DBX_MEMPARM_STABS_LETTER);
2794 else
2796 current_sym_nchars = 8;
2797 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2798 DBX_MEMPARM_STABS_LETTER);
2801 /* It is quite tempting to use:
2803 dbxout_type (TREE_TYPE (parms), 0);
2805 as the next statement, rather than using DECL_ARG_TYPE(), so
2806 that gcc reports the actual type of the parameter, rather
2807 than the promoted type. This certainly makes GDB's life
2808 easier, at least for some ports. The change is a bad idea
2809 however, since GDB expects to be able access the type without
2810 performing any conversions. So for example, if we were
2811 passing a float to an unprototyped function, gcc will store a
2812 double on the stack, but if we emit a stab saying the type is a
2813 float, then gdb will only read in a single value, and this will
2814 produce an erroneous value. */
2815 dbxout_type (DECL_ARG_TYPE (parms), 0);
2816 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2817 dbxout_finish_symbol (parms);
2819 else if (GET_CODE (DECL_RTL (parms)) == REG)
2821 rtx best_rtl;
2822 char regparm_letter;
2823 tree parm_type;
2824 /* Parm passed in registers and lives in registers or nowhere. */
2826 current_sym_code = DBX_REGPARM_STABS_CODE;
2827 regparm_letter = DBX_REGPARM_STABS_LETTER;
2828 current_sym_addr = 0;
2830 /* If parm lives in a register, use that register;
2831 pretend the parm was passed there. It would be more consistent
2832 to describe the register where the parm was passed,
2833 but in practice that register usually holds something else.
2835 If we use DECL_RTL, then we must use the declared type of
2836 the variable, not the type that it arrived in. */
2837 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2839 best_rtl = DECL_RTL (parms);
2840 parm_type = TREE_TYPE (parms);
2842 /* If the parm lives nowhere, use the register where it was
2843 passed. It is also better to use the declared type here. */
2844 else
2846 best_rtl = DECL_INCOMING_RTL (parms);
2847 parm_type = TREE_TYPE (parms);
2849 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2851 FORCE_TEXT;
2852 if (DECL_NAME (parms))
2854 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2855 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2856 IDENTIFIER_POINTER (DECL_NAME (parms)),
2857 regparm_letter);
2859 else
2861 current_sym_nchars = 8;
2862 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2863 regparm_letter);
2866 dbxout_type (parm_type, 0);
2867 dbxout_finish_symbol (parms);
2869 else if (GET_CODE (DECL_RTL (parms)) == MEM
2870 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2871 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2872 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2873 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2874 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2875 #endif
2878 /* Parm was passed via invisible reference.
2879 That is, its address was passed in a register.
2880 Output it as if it lived in that register.
2881 The debugger will know from the type
2882 that it was actually passed by invisible reference. */
2884 char regparm_letter;
2885 /* Parm passed in registers and lives in registers or nowhere. */
2887 current_sym_code = DBX_REGPARM_STABS_CODE;
2888 if (use_gnu_debug_info_extensions)
2889 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2890 else
2891 regparm_letter = DBX_REGPARM_STABS_LETTER;
2893 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2894 If it is an unallocated pseudo-reg, then use the register where
2895 it was passed instead. */
2896 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2897 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2898 else
2899 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2901 current_sym_addr = 0;
2903 FORCE_TEXT;
2904 if (DECL_NAME (parms))
2906 current_sym_nchars
2907 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2909 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2910 IDENTIFIER_POINTER (DECL_NAME (parms)),
2911 regparm_letter);
2913 else
2915 current_sym_nchars = 8;
2916 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2917 regparm_letter);
2920 dbxout_type (TREE_TYPE (parms), 0);
2921 dbxout_finish_symbol (parms);
2923 else if (GET_CODE (DECL_RTL (parms)) == MEM
2924 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2926 /* Parm was passed via invisible reference, with the reference
2927 living on the stack. DECL_RTL looks like
2928 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2929 could look like (MEM (MEM (REG))). */
2930 const char *const decl_name = (DECL_NAME (parms)
2931 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2932 : "(anon)");
2933 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2934 current_sym_value = 0;
2935 else
2936 current_sym_value
2937 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2938 current_sym_addr = 0;
2939 current_sym_code = N_PSYM;
2941 FORCE_TEXT;
2942 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2944 current_sym_value
2945 = DEBUGGER_ARG_OFFSET (current_sym_value,
2946 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2947 dbxout_type (TREE_TYPE (parms), 0);
2948 dbxout_finish_symbol (parms);
2950 else if (GET_CODE (DECL_RTL (parms)) == MEM
2951 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2952 /* ??? A constant address for a parm can happen
2953 when the reg it lives in is equiv to a constant in memory.
2954 Should make this not happen, after 2.4. */
2955 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2957 /* Parm was passed in registers but lives on the stack. */
2959 current_sym_code = N_PSYM;
2960 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2961 in which case we want the value of that CONST_INT,
2962 or (MEM (REG ...)),
2963 in which case we use a value of zero. */
2964 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2965 current_sym_value = 0;
2966 else
2967 current_sym_value
2968 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2970 current_sym_addr = 0;
2972 /* Make a big endian correction if the mode of the type of the
2973 parameter is not the same as the mode of the rtl. */
2974 if (BYTES_BIG_ENDIAN
2975 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2976 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2978 current_sym_value +=
2979 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2980 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2983 FORCE_TEXT;
2984 if (DECL_NAME (parms))
2986 current_sym_nchars
2987 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2989 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2990 IDENTIFIER_POINTER (DECL_NAME (parms)),
2991 DBX_MEMPARM_STABS_LETTER);
2993 else
2995 current_sym_nchars = 8;
2996 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2997 DBX_MEMPARM_STABS_LETTER);
3000 current_sym_value
3001 = DEBUGGER_ARG_OFFSET (current_sym_value,
3002 XEXP (DECL_RTL (parms), 0));
3003 dbxout_type (TREE_TYPE (parms), 0);
3004 dbxout_finish_symbol (parms);
3007 DBXOUT_DECR_NESTING;
3010 /* Output definitions for the places where parms live during the function,
3011 when different from where they were passed, when the parms were passed
3012 in memory.
3014 It is not useful to do this for parms passed in registers
3015 that live during the function in different registers, because it is
3016 impossible to look in the passed register for the passed value,
3017 so we use the within-the-function register to begin with.
3019 PARMS is a chain of PARM_DECL nodes. */
3021 void
3022 dbxout_reg_parms (tree parms)
3024 ++debug_nesting;
3026 for (; parms; parms = TREE_CHAIN (parms))
3027 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3029 dbxout_prepare_symbol (parms);
3031 /* Report parms that live in registers during the function
3032 but were passed in memory. */
3033 if (GET_CODE (DECL_RTL (parms)) == REG
3034 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3035 dbxout_symbol_location (parms, TREE_TYPE (parms),
3036 0, DECL_RTL (parms));
3037 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3038 dbxout_symbol_location (parms, TREE_TYPE (parms),
3039 0, DECL_RTL (parms));
3040 /* Report parms that live in memory but not where they were passed. */
3041 else if (GET_CODE (DECL_RTL (parms)) == MEM
3042 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3043 dbxout_symbol_location (parms, TREE_TYPE (parms),
3044 0, DECL_RTL (parms));
3046 DBXOUT_DECR_NESTING;
3049 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3050 output definitions of those names, in raw form */
3052 static void
3053 dbxout_args (tree args)
3055 while (args)
3057 putc (',', asmfile);
3058 dbxout_type (TREE_VALUE (args), 0);
3059 CHARS (1);
3060 args = TREE_CHAIN (args);
3064 /* Output everything about a symbol block (a BLOCK node
3065 that represents a scope level),
3066 including recursive output of contained blocks.
3068 BLOCK is the BLOCK node.
3069 DEPTH is its depth within containing symbol blocks.
3070 ARGS is usually zero; but for the outermost block of the
3071 body of a function, it is a chain of PARM_DECLs for the function parameters.
3072 We output definitions of all the register parms
3073 as if they were local variables of that block.
3075 If -g1 was used, we count blocks just the same, but output nothing
3076 except for the outermost block.
3078 Actually, BLOCK may be several blocks chained together.
3079 We handle them all in sequence. */
3081 static void
3082 dbxout_block (tree block, int depth, tree args)
3084 int blocknum = -1;
3086 #if DBX_BLOCKS_FUNCTION_RELATIVE
3087 const char *begin_label;
3088 if (current_function_func_begin_label != NULL_TREE)
3089 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
3090 else
3091 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3092 #endif
3094 while (block)
3096 /* Ignore blocks never expanded or otherwise marked as real. */
3097 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3099 int did_output;
3101 /* In dbx format, the syms of a block come before the N_LBRAC.
3102 If nothing is output, we don't need the N_LBRAC, either. */
3103 did_output = 0;
3104 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3105 did_output = dbxout_syms (BLOCK_VARS (block));
3106 if (args)
3107 dbxout_reg_parms (args);
3109 /* Now output an N_LBRAC symbol to represent the beginning of
3110 the block. Use the block's tree-walk order to generate
3111 the assembler symbols LBBn and LBEn
3112 that final will define around the code in this block. */
3113 if (depth > 0 && did_output)
3115 char buf[20];
3116 blocknum = BLOCK_NUMBER (block);
3117 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3119 if (BLOCK_HANDLER_BLOCK (block))
3121 /* A catch block. Must precede N_LBRAC. */
3122 tree decl = BLOCK_VARS (block);
3123 while (decl)
3125 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
3126 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
3127 assemble_name (asmfile, buf);
3128 fprintf (asmfile, "\n");
3129 decl = TREE_CHAIN (decl);
3133 #ifdef DBX_OUTPUT_LBRAC
3134 DBX_OUTPUT_LBRAC (asmfile, buf);
3135 #else
3136 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
3137 assemble_name (asmfile, buf);
3138 #if DBX_BLOCKS_FUNCTION_RELATIVE
3139 putc ('-', asmfile);
3140 assemble_name (asmfile, begin_label);
3141 #endif
3142 fprintf (asmfile, "\n");
3143 #endif
3146 /* Output the subblocks. */
3147 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3149 /* Refer to the marker for the end of the block. */
3150 if (depth > 0 && did_output)
3152 char buf[20];
3153 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3154 #ifdef DBX_OUTPUT_RBRAC
3155 DBX_OUTPUT_RBRAC (asmfile, buf);
3156 #else
3157 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3158 assemble_name (asmfile, buf);
3159 #if DBX_BLOCKS_FUNCTION_RELATIVE
3160 putc ('-', asmfile);
3161 assemble_name (asmfile, begin_label);
3162 #endif
3163 fprintf (asmfile, "\n");
3164 #endif
3167 block = BLOCK_CHAIN (block);
3171 /* Output the information about a function and its arguments and result.
3172 Usually this follows the function's code,
3173 but on some systems, it comes before. */
3175 #if defined (DBX_DEBUGGING_INFO)
3176 static void
3177 dbxout_begin_function (tree decl)
3179 int saved_tree_used1 = TREE_USED (decl);
3180 TREE_USED (decl) = 1;
3181 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3183 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3184 TREE_USED (DECL_RESULT (decl)) = 1;
3185 dbxout_symbol (decl, 0);
3186 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3188 else
3189 dbxout_symbol (decl, 0);
3190 TREE_USED (decl) = saved_tree_used1;
3192 dbxout_parms (DECL_ARGUMENTS (decl));
3193 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3194 dbxout_symbol (DECL_RESULT (decl), 1);
3196 #endif /* DBX_DEBUGGING_INFO */
3198 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3200 #include "gt-dbxout.h"