PR target/12676
[official-gcc.git] / gcc / dbxout.c
blobef04c8311340d02922f2a67fb2c495cfbff935c0
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_type_index (tree);
332 #if DBX_CONTIN_LENGTH > 0
333 static void dbxout_continue (void);
334 #endif
335 static void dbxout_args (tree);
336 static void dbxout_type_fields (tree);
337 static void dbxout_type_method_1 (tree, const char *);
338 static void dbxout_type_methods (tree);
339 static void dbxout_range_type (tree);
340 static void dbxout_type (tree, int);
341 static bool print_int_cst_bounds_in_octal_p (tree);
342 static void print_int_cst_octal (tree);
343 static void print_octal (unsigned HOST_WIDE_INT, int);
344 static void print_wide_int (HOST_WIDE_INT);
345 static void dbxout_type_name (tree);
346 static void dbxout_class_name_qualifiers (tree);
347 static int dbxout_symbol_location (tree, tree, const char *, rtx);
348 static void dbxout_symbol_name (tree, const char *, int);
349 static void dbxout_prepare_symbol (tree);
350 static void dbxout_finish_symbol (tree);
351 static void dbxout_block (tree, int, tree);
352 static void dbxout_global_decl (tree);
353 static void dbxout_handle_pch (unsigned);
355 /* The debug hooks structure. */
356 #if defined (DBX_DEBUGGING_INFO)
358 static void dbxout_source_line (unsigned int, const char *);
359 static void dbxout_source_file (FILE *, const char *);
360 static void dbxout_function_end (void);
361 static void dbxout_begin_function (tree);
362 static void dbxout_begin_block (unsigned, unsigned);
363 static void dbxout_end_block (unsigned, unsigned);
364 static void dbxout_function_decl (tree);
366 const struct gcc_debug_hooks dbx_debug_hooks =
368 dbxout_init,
369 dbxout_finish,
370 debug_nothing_int_charstar,
371 debug_nothing_int_charstar,
372 dbxout_start_source_file,
373 dbxout_end_source_file,
374 dbxout_begin_block,
375 dbxout_end_block,
376 debug_true_tree, /* ignore_block */
377 dbxout_source_line, /* source_line */
378 dbxout_source_line, /* begin_prologue: just output line info */
379 debug_nothing_int_charstar, /* end_prologue */
380 debug_nothing_int_charstar, /* end_epilogue */
381 #ifdef DBX_FUNCTION_FIRST
382 dbxout_begin_function,
383 #else
384 debug_nothing_tree, /* begin_function */
385 #endif
386 debug_nothing_int, /* end_function */
387 dbxout_function_decl,
388 dbxout_global_decl, /* global_decl */
389 debug_nothing_tree, /* deferred_inline_function */
390 debug_nothing_tree, /* outlining_inline_function */
391 debug_nothing_rtx, /* label */
392 dbxout_handle_pch /* handle_pch */
394 #endif /* DBX_DEBUGGING_INFO */
396 #if defined (XCOFF_DEBUGGING_INFO)
397 const struct gcc_debug_hooks xcoff_debug_hooks =
399 dbxout_init,
400 dbxout_finish,
401 debug_nothing_int_charstar,
402 debug_nothing_int_charstar,
403 dbxout_start_source_file,
404 dbxout_end_source_file,
405 xcoffout_begin_block,
406 xcoffout_end_block,
407 debug_true_tree, /* ignore_block */
408 xcoffout_source_line,
409 xcoffout_begin_prologue, /* begin_prologue */
410 debug_nothing_int_charstar, /* end_prologue */
411 xcoffout_end_epilogue,
412 debug_nothing_tree, /* begin_function */
413 xcoffout_end_function,
414 debug_nothing_tree, /* function_decl */
415 dbxout_global_decl, /* global_decl */
416 debug_nothing_tree, /* deferred_inline_function */
417 debug_nothing_tree, /* outlining_inline_function */
418 debug_nothing_rtx, /* label */
419 dbxout_handle_pch /* handle_pch */
421 #endif /* XCOFF_DEBUGGING_INFO */
423 #if defined (DBX_DEBUGGING_INFO)
424 static void
425 dbxout_function_end (void)
427 char lscope_label_name[100];
428 /* Convert Ltext into the appropriate format for local labels in case
429 the system doesn't insert underscores in front of user generated
430 labels. */
431 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
432 (*targetm.asm_out.internal_label) (asmfile, "Lscope", scope_labelno);
433 scope_labelno++;
435 /* By convention, GCC will mark the end of a function with an N_FUN
436 symbol and an empty string. */
437 #ifdef DBX_OUTPUT_NFUN
438 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
439 #else
440 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
441 assemble_name (asmfile, lscope_label_name);
442 putc ('-', asmfile);
443 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
444 fprintf (asmfile, "\n");
445 #endif
447 #endif /* DBX_DEBUGGING_INFO */
449 /* At the beginning of compilation, start writing the symbol table.
450 Initialize `typevec' and output the standard data types of C. */
452 static void
453 dbxout_init (const char *input_file_name)
455 char ltext_label_name[100];
456 tree syms = (*lang_hooks.decls.getdecls) ();
458 asmfile = asm_out_file;
460 typevec_len = 100;
461 typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
463 /* Convert Ltext into the appropriate format for local labels in case
464 the system doesn't insert underscores in front of user generated
465 labels. */
466 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
468 /* Put the current working directory in an N_SO symbol. */
469 if (use_gnu_debug_info_extensions)
471 if (!cwd && (cwd = get_src_pwd ())
472 && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
473 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
474 if (cwd)
476 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
477 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
478 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
479 fprintf (asmfile, "%s", ASM_STABS_OP);
480 output_quoted_string (asmfile, cwd);
481 fprintf (asmfile, ",%d,0,0,", N_SO);
482 assemble_name (asmfile, ltext_label_name);
483 fputc ('\n', asmfile);
484 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
488 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
489 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
490 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
491 /* We include outputting `Ltext:' here,
492 because that gives you a way to override it. */
493 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
494 fprintf (asmfile, "%s", ASM_STABS_OP);
495 output_quoted_string (asmfile, input_file_name);
496 fprintf (asmfile, ",%d,0,0,", N_SO);
497 assemble_name (asmfile, ltext_label_name);
498 fputc ('\n', asmfile);
499 text_section ();
500 (*targetm.asm_out.internal_label) (asmfile, "Ltext", 0);
501 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
503 #ifdef DBX_OUTPUT_GCC_MARKER
504 DBX_OUTPUT_GCC_MARKER (asmfile);
505 #else
506 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
507 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
508 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
509 #endif
511 base_input_file = lastfile = input_file_name;
513 next_type_number = 1;
515 #ifdef DBX_USE_BINCL
516 current_file = ggc_alloc (sizeof *current_file);
517 current_file->next = NULL;
518 current_file->file_number = 0;
519 current_file->next_type_number = 1;
520 next_file_number = 1;
521 current_file->prev = NULL;
522 current_file->bincl_status = BINCL_NOT_REQUIRED;
523 current_file->pending_bincl_name = NULL;
524 #endif
526 /* Make sure that types `int' and `char' have numbers 1 and 2.
527 Definitions of other integer types will refer to those numbers.
528 (Actually it should no longer matter what their numbers are.
529 Also, if any types with tags have been defined, dbxout_symbol
530 will output them first, so the numbers won't be 1 and 2. That
531 happens in C++. So it's a good thing it should no longer matter). */
533 #ifdef DBX_OUTPUT_STANDARD_TYPES
534 DBX_OUTPUT_STANDARD_TYPES (syms);
535 #endif
537 /* Get all permanent types that have typedef names, and output them
538 all, except for those already output. Some language front ends
539 put these declarations in the top-level scope; some do not. */
540 dbxout_typedefs ((*lang_hooks.decls.builtin_type_decls) ());
541 dbxout_typedefs (syms);
544 /* Output any typedef names for types described by TYPE_DECLs in SYMS. */
546 static void
547 dbxout_typedefs (tree syms)
549 for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
551 if (TREE_CODE (syms) == TYPE_DECL)
553 tree type = TREE_TYPE (syms);
554 if (TYPE_NAME (type)
555 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
556 && COMPLETE_OR_VOID_TYPE_P (type)
557 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
558 dbxout_symbol (TYPE_NAME (type), 0);
563 #ifdef DBX_USE_BINCL
564 /* Emit BINCL stab using given name. */
565 static void
566 emit_bincl_stab (const char *name)
568 fprintf (asmfile, "%s", ASM_STABS_OP);
569 output_quoted_string (asmfile, name);
570 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
573 /* If there are pending bincls then it is time to emit all of them. */
575 static inline void
576 emit_pending_bincls_if_required (void)
578 if (pending_bincls)
579 emit_pending_bincls ();
582 /* Emit all pending bincls. */
584 static void
585 emit_pending_bincls (void)
587 struct dbx_file *f = current_file;
589 /* Find first pending bincl. */
590 while (f->bincl_status == BINCL_PENDING)
591 f = f->next;
593 /* Now emit all bincls. */
594 f = f->prev;
596 while (f)
598 if (f->bincl_status == BINCL_PENDING)
600 emit_bincl_stab (f->pending_bincl_name);
602 /* Update file number and status. */
603 f->file_number = next_file_number++;
604 f->bincl_status = BINCL_PROCESSED;
606 if (f == current_file)
607 break;
608 f = f->prev;
611 /* All pending bincls have been emitted. */
612 pending_bincls = 0;
615 #else
617 static inline void
618 emit_pending_bincls_if_required (void) {}
619 #endif
621 /* Change to reading from a new source file. Generate a N_BINCL stab. */
623 static void
624 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
625 const char *filename ATTRIBUTE_UNUSED)
627 #ifdef DBX_USE_BINCL
628 struct dbx_file *n = ggc_alloc (sizeof *n);
630 n->next = current_file;
631 n->next_type_number = 1;
632 /* Do not assign file number now.
633 Delay it until we actually emit BINCL. */
634 n->file_number = 0;
635 n->prev = NULL;
636 current_file->prev = n;
637 n->bincl_status = BINCL_PENDING;
638 n->pending_bincl_name = filename;
639 pending_bincls = 1;
640 current_file = n;
641 #endif
644 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
646 static void
647 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
649 #ifdef DBX_USE_BINCL
650 /* Emit EINCL stab only if BINCL is not pending. */
651 if (current_file->bincl_status == BINCL_PROCESSED)
652 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
653 current_file->bincl_status = BINCL_NOT_REQUIRED;
654 current_file = current_file->next;
655 #endif
658 /* Handle a few odd cases that occur when trying to make PCH files work. */
660 static void
661 dbxout_handle_pch (unsigned at_end)
663 if (! at_end)
665 /* When using the PCH, this file will be included, so we need to output
666 a BINCL. */
667 dbxout_start_source_file (0, lastfile);
669 /* The base file when using the PCH won't be the same as
670 the base file when it's being generated. */
671 lastfile = NULL;
673 else
675 /* ... and an EINCL. */
676 dbxout_end_source_file (0);
678 /* Deal with cases where 'lastfile' was never actually changed. */
679 lastfile_is_base = lastfile == NULL;
683 #if defined (DBX_DEBUGGING_INFO)
684 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
686 static void
687 dbxout_source_file (FILE *file, const char *filename)
689 if (lastfile == 0 && lastfile_is_base)
691 lastfile = base_input_file;
692 lastfile_is_base = 0;
695 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
697 char ltext_label_name[100];
699 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
700 source_label_number);
701 fprintf (file, "%s", ASM_STABS_OP);
702 output_quoted_string (file, filename);
703 fprintf (asmfile, ",%d,0,0,", N_SOL);
704 assemble_name (asmfile, ltext_label_name);
705 fputc ('\n', asmfile);
706 if (current_function_decl != NULL_TREE
707 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
708 ; /* Don't change section amid function. */
709 else
710 text_section ();
711 (*targetm.asm_out.internal_label) (file, "Ltext", source_label_number);
712 source_label_number++;
713 lastfile = filename;
717 /* Output a line number symbol entry for source file FILENAME and line
718 number LINENO. */
720 static void
721 dbxout_source_line (unsigned int lineno, const char *filename)
723 dbxout_source_file (asmfile, filename);
725 #ifdef ASM_OUTPUT_SOURCE_LINE
726 dbxout_source_line_counter += 1;
727 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno, dbxout_source_line_counter);
728 #else
729 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
730 #endif
733 /* Describe the beginning of an internal block within a function. */
735 static void
736 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
738 emit_pending_bincls_if_required ();
739 (*targetm.asm_out.internal_label) (asmfile, "LBB", n);
742 /* Describe the end line-number of an internal block within a function. */
744 static void
745 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
747 emit_pending_bincls_if_required ();
748 (*targetm.asm_out.internal_label) (asmfile, "LBE", n);
751 /* Output dbx data for a function definition.
752 This includes a definition of the function name itself (a symbol),
753 definitions of the parameters (locating them in the parameter list)
754 and then output the block that makes up the function's body
755 (including all the auto variables of the function). */
757 static void
758 dbxout_function_decl (tree decl)
760 emit_pending_bincls_if_required ();
761 #ifndef DBX_FUNCTION_FIRST
762 dbxout_begin_function (decl);
763 #endif
764 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
765 #ifdef DBX_OUTPUT_FUNCTION_END
766 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
767 #endif
768 if (use_gnu_debug_info_extensions
769 #if defined(NO_DBX_FUNCTION_END)
770 && ! NO_DBX_FUNCTION_END
771 #endif
772 && targetm.have_named_sections)
773 dbxout_function_end ();
776 #endif /* DBX_DEBUGGING_INFO */
778 /* Debug information for a global DECL. Called from toplev.c after
779 compilation proper has finished. */
780 static void
781 dbxout_global_decl (tree decl)
783 if (TREE_CODE (decl) == VAR_DECL
784 && ! DECL_EXTERNAL (decl)
785 && DECL_RTL_SET_P (decl)) /* Not necessary? */
787 int saved_tree_used = TREE_USED (decl);
788 TREE_USED (decl) = 1;
789 dbxout_symbol (decl, 0);
790 TREE_USED (decl) = saved_tree_used;
794 /* At the end of compilation, finish writing the symbol table.
795 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
796 to do nothing. */
798 static void
799 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
801 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
802 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
803 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
805 debug_free_queue ();
808 /* Output the index of a type. */
810 static void
811 dbxout_type_index (tree type)
813 #ifndef DBX_USE_BINCL
814 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
815 CHARS (3);
816 #else
817 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
818 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
819 CHARS (9);
820 #endif
823 #if DBX_CONTIN_LENGTH > 0
824 /* Continue a symbol-description that gets too big.
825 End one symbol table entry with a double-backslash
826 and start a new one, eventually producing something like
827 .stabs "start......\\",code,0,value
828 .stabs "...rest",code,0,value */
830 static void
831 dbxout_continue (void)
833 emit_pending_bincls_if_required ();
834 #ifdef DBX_CONTIN_CHAR
835 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
836 #else
837 fprintf (asmfile, "\\\\");
838 #endif
839 dbxout_finish_symbol (NULL_TREE);
840 fprintf (asmfile, "%s\"", ASM_STABS_OP);
841 current_sym_nchars = 0;
843 #endif /* DBX_CONTIN_LENGTH > 0 */
845 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
846 This must be a separate function because anonymous unions require
847 recursive calls. */
849 static void
850 dbxout_type_fields (tree type)
852 tree tem;
854 /* Output the name, type, position (in bits), size (in bits) of each
855 field that we can support. */
856 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
858 /* Omit here local type decls until we know how to support them. */
859 if (TREE_CODE (tem) == TYPE_DECL
860 /* Omit fields whose position or size are variable or too large to
861 represent. */
862 || (TREE_CODE (tem) == FIELD_DECL
863 && (! host_integerp (bit_position (tem), 0)
864 || ! DECL_SIZE (tem)
865 || ! host_integerp (DECL_SIZE (tem), 1)))
866 /* Omit here the nameless fields that are used to skip bits. */
867 || DECL_IGNORED_P (tem))
868 continue;
870 else if (TREE_CODE (tem) != CONST_DECL)
872 /* Continue the line if necessary,
873 but not before the first field. */
874 if (tem != TYPE_FIELDS (type))
875 CONTIN;
877 if (DECL_NAME (tem))
879 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
880 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
882 else
884 fprintf (asmfile, ":");
885 CHARS (1);
888 if (use_gnu_debug_info_extensions
889 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
890 || TREE_CODE (tem) != FIELD_DECL))
892 have_used_extensions = 1;
893 putc ('/', asmfile);
894 putc ((TREE_PRIVATE (tem) ? '0'
895 : TREE_PROTECTED (tem) ? '1' : '2'),
896 asmfile);
897 CHARS (2);
900 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
901 && DECL_BIT_FIELD_TYPE (tem))
902 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
904 if (TREE_CODE (tem) == VAR_DECL)
906 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
908 tree name = DECL_ASSEMBLER_NAME (tem);
910 have_used_extensions = 1;
911 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
912 CHARS (IDENTIFIER_LENGTH (name) + 2);
914 else
916 /* If TEM is non-static, GDB won't understand it. */
917 fprintf (asmfile, ",0,0;");
918 CHARS (5);
921 else
923 putc (',', asmfile);
924 print_wide_int (int_bit_position (tem));
925 putc (',', asmfile);
926 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
927 putc (';', asmfile);
928 CHARS (3);
934 /* Subroutine of `dbxout_type_methods'. Output debug info about the
935 method described DECL. DEBUG_NAME is an encoding of the method's
936 type signature. ??? We may be able to do without DEBUG_NAME altogether
937 now. */
939 static void
940 dbxout_type_method_1 (tree decl, const char *debug_name)
942 char c1 = 'A', c2;
944 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
945 c2 = '?';
946 else /* it's a METHOD_TYPE. */
948 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
949 /* A for normal functions.
950 B for `const' member functions.
951 C for `volatile' member functions.
952 D for `const volatile' member functions. */
953 if (TYPE_READONLY (TREE_TYPE (firstarg)))
954 c1 += 1;
955 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
956 c1 += 2;
958 if (DECL_VINDEX (decl))
959 c2 = '*';
960 else
961 c2 = '.';
964 fprintf (asmfile, ":%s;%c%c%c", debug_name,
965 TREE_PRIVATE (decl) ? '0'
966 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
967 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
968 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
970 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
972 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
973 putc (';', asmfile);
974 CHARS (1);
975 dbxout_type (DECL_CONTEXT (decl), 0);
976 fprintf (asmfile, ";");
977 CHARS (1);
981 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
982 in TYPE. */
984 static void
985 dbxout_type_methods (tree type)
987 /* C++: put out the method names and their parameter lists */
988 tree methods = TYPE_METHODS (type);
989 tree type_encoding;
990 tree fndecl;
991 tree last;
992 char formatted_type_identifier_length[16];
993 int type_identifier_length;
995 if (methods == NULL_TREE)
996 return;
998 type_encoding = DECL_NAME (TYPE_NAME (type));
1000 #if 0
1001 /* C++: Template classes break some assumptions made by this code about
1002 the class names, constructor names, and encodings for assembler
1003 label names. For now, disable output of dbx info for them. */
1005 const char *ptr = IDENTIFIER_POINTER (type_encoding);
1006 /* This should use index. (mrs) */
1007 while (*ptr && *ptr != '<') ptr++;
1008 if (*ptr != 0)
1010 static int warned;
1011 if (!warned)
1012 warned = 1;
1013 return;
1016 #endif
1018 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
1020 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
1022 if (TREE_CODE (methods) != TREE_VEC)
1023 fndecl = methods;
1024 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1025 fndecl = TREE_VEC_ELT (methods, 0);
1026 else
1027 fndecl = TREE_VEC_ELT (methods, 1);
1029 while (fndecl)
1031 int need_prefix = 1;
1033 /* Group together all the methods for the same operation.
1034 These differ in the types of the arguments. */
1035 for (last = NULL_TREE;
1036 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1037 fndecl = TREE_CHAIN (fndecl))
1038 /* Output the name of the field (after overloading), as
1039 well as the name of the field before overloading, along
1040 with its parameter list */
1042 /* This is the "mangled" name of the method.
1043 It encodes the argument types. */
1044 const char *debug_name;
1046 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1047 include TEMPLATE_DECLs.) The debugger doesn't know what
1048 to do with such entities anyhow. */
1049 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1050 continue;
1052 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1054 CONTIN;
1056 last = fndecl;
1058 /* Also ignore abstract methods; those are only interesting to
1059 the DWARF backends. */
1060 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1061 continue;
1063 /* Redundantly output the plain name, since that's what gdb
1064 expects. */
1065 if (need_prefix)
1067 tree name = DECL_NAME (fndecl);
1068 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1069 CHARS (IDENTIFIER_LENGTH (name) + 2);
1070 need_prefix = 0;
1073 dbxout_type (TREE_TYPE (fndecl), 0);
1075 dbxout_type_method_1 (fndecl, debug_name);
1077 if (!need_prefix)
1079 putc (';', asmfile);
1080 CHARS (1);
1085 /* Emit a "range" type specification, which has the form:
1086 "r<index type>;<lower bound>;<upper bound>;".
1087 TYPE is an INTEGER_TYPE. */
1089 static void
1090 dbxout_range_type (tree type)
1092 fprintf (asmfile, "r");
1093 if (TREE_TYPE (type))
1094 dbxout_type (TREE_TYPE (type), 0);
1095 else if (TREE_CODE (type) != INTEGER_TYPE)
1096 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1097 else
1099 /* Traditionally, we made sure 'int' was type 1, and builtin types
1100 were defined to be sub-ranges of int. Unfortunately, this
1101 does not allow us to distinguish true sub-ranges from integer
1102 types. So, instead we define integer (non-sub-range) types as
1103 sub-ranges of themselves. This matters for Chill. If this isn't
1104 a subrange type, then we want to define it in terms of itself.
1105 However, in C, this may be an anonymous integer type, and we don't
1106 want to emit debug info referring to it. Just calling
1107 dbxout_type_index won't work anyways, because the type hasn't been
1108 defined yet. We make this work for both cases by checked to see
1109 whether this is a defined type, referring to it if it is, and using
1110 'int' otherwise. */
1111 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1112 dbxout_type_index (type);
1113 else
1114 dbxout_type_index (integer_type_node);
1117 if (TYPE_MIN_VALUE (type) != 0
1118 && host_integerp (TYPE_MIN_VALUE (type), 0))
1120 putc (';', asmfile);
1121 CHARS (1);
1122 if (print_int_cst_bounds_in_octal_p (type))
1123 print_int_cst_octal (TYPE_MIN_VALUE (type));
1124 else
1125 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1127 else
1129 fprintf (asmfile, ";0");
1130 CHARS (2);
1133 if (TYPE_MAX_VALUE (type) != 0
1134 && host_integerp (TYPE_MAX_VALUE (type), 0))
1136 putc (';', asmfile);
1137 CHARS (1);
1138 if (print_int_cst_bounds_in_octal_p (type))
1139 print_int_cst_octal (TYPE_MAX_VALUE (type));
1140 else
1141 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1142 putc (';', asmfile);
1143 CHARS (1);
1145 else
1147 fprintf (asmfile, ";-1;");
1148 CHARS (4);
1153 /* Output a reference to a type. If the type has not yet been
1154 described in the dbx output, output its definition now.
1155 For a type already defined, just refer to its definition
1156 using the type number.
1158 If FULL is nonzero, and the type has been described only with
1159 a forward-reference, output the definition now.
1160 If FULL is zero in this case, just refer to the forward-reference
1161 using the number previously allocated. */
1163 static void
1164 dbxout_type (tree type, int full)
1166 tree tem;
1167 tree main_variant;
1168 static int anonymous_type_number = 0;
1170 if (TREE_CODE (type) == VECTOR_TYPE)
1171 /* The frontend feeds us a representation for the vector as a struct
1172 containing an array. Pull out the array type. */
1173 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1175 /* If there was an input error and we don't really have a type,
1176 avoid crashing and write something that is at least valid
1177 by assuming `int'. */
1178 if (type == error_mark_node)
1179 type = integer_type_node;
1180 else
1182 if (TYPE_NAME (type)
1183 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1184 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1185 full = 0;
1188 /* Try to find the "main variant" with the same name. */
1189 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1190 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1191 main_variant = TREE_TYPE (TYPE_NAME (type));
1192 else
1193 main_variant = TYPE_MAIN_VARIANT (type);
1195 /* If we are not using extensions, stabs does not distinguish const and
1196 volatile, so there is no need to make them separate types. */
1197 if (!use_gnu_debug_info_extensions)
1198 type = main_variant;
1200 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1202 /* Type has no dbx number assigned. Assign next available number. */
1203 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1205 /* Make sure type vector is long enough to record about this type. */
1207 if (next_type_number == typevec_len)
1209 typevec
1210 = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1211 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1212 typevec_len *= 2;
1215 #ifdef DBX_USE_BINCL
1216 emit_pending_bincls_if_required ();
1217 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1218 = current_file->file_number;
1219 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1220 = current_file->next_type_number++;
1221 #endif
1224 if (flag_debug_only_used_symbols)
1226 if ((TREE_CODE (type) == RECORD_TYPE
1227 || TREE_CODE (type) == UNION_TYPE
1228 || TREE_CODE (type) == QUAL_UNION_TYPE
1229 || TREE_CODE (type) == ENUMERAL_TYPE)
1230 && TYPE_STUB_DECL (type)
1231 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (type))) == 'd'
1232 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1233 debug_queue_symbol (TYPE_STUB_DECL (type));
1234 else if (TYPE_NAME (type)
1235 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1236 debug_queue_symbol (TYPE_NAME (type));
1239 /* Output the number of this type, to refer to it. */
1240 dbxout_type_index (type);
1242 #ifdef DBX_TYPE_DEFINED
1243 if (DBX_TYPE_DEFINED (type))
1244 return;
1245 #endif
1247 /* If this type's definition has been output or is now being output,
1248 that is all. */
1250 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1252 case TYPE_UNSEEN:
1253 break;
1254 case TYPE_XREF:
1255 /* If we have already had a cross reference,
1256 and either that's all we want or that's the best we could do,
1257 don't repeat the cross reference.
1258 Sun dbx crashes if we do. */
1259 if (! full || !COMPLETE_TYPE_P (type)
1260 /* No way in DBX fmt to describe a variable size. */
1261 || ! host_integerp (TYPE_SIZE (type), 1))
1262 return;
1263 break;
1264 case TYPE_DEFINED:
1265 return;
1268 #ifdef DBX_NO_XREFS
1269 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1270 leave the type-number completely undefined rather than output
1271 a cross-reference. If we have already used GNU debug info extensions,
1272 then it is OK to output a cross reference. This is necessary to get
1273 proper C++ debug output. */
1274 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1275 || TREE_CODE (type) == QUAL_UNION_TYPE
1276 || TREE_CODE (type) == ENUMERAL_TYPE)
1277 && ! use_gnu_debug_info_extensions)
1278 /* We must use the same test here as we use twice below when deciding
1279 whether to emit a cross-reference. */
1280 if ((TYPE_NAME (type) != 0
1281 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1282 && DECL_IGNORED_P (TYPE_NAME (type)))
1283 && !full)
1284 || !COMPLETE_TYPE_P (type)
1285 /* No way in DBX fmt to describe a variable size. */
1286 || ! host_integerp (TYPE_SIZE (type), 1))
1288 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1289 return;
1291 #endif
1293 /* Output a definition now. */
1295 fprintf (asmfile, "=");
1296 CHARS (1);
1298 /* Mark it as defined, so that if it is self-referent
1299 we will not get into an infinite recursion of definitions. */
1301 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1303 /* If this type is a variant of some other, hand off. Types with
1304 different names are usefully distinguished. We only distinguish
1305 cv-qualified types if we're using extensions. */
1306 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1308 putc ('k', asmfile);
1309 CHARS (1);
1310 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1311 return;
1313 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1315 putc ('B', asmfile);
1316 CHARS (1);
1317 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1318 return;
1320 else if (main_variant != TYPE_MAIN_VARIANT (type))
1322 if (flag_debug_only_used_symbols)
1324 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1326 if ((TREE_CODE (orig_type) == RECORD_TYPE
1327 || TREE_CODE (orig_type) == UNION_TYPE
1328 || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1329 || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1330 && TYPE_STUB_DECL (orig_type)
1331 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1332 debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1334 /* 'type' is a typedef; output the type it refers to. */
1335 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1336 return;
1338 /* else continue. */
1340 switch (TREE_CODE (type))
1342 case VOID_TYPE:
1343 case LANG_TYPE:
1344 /* For a void type, just define it as itself; ie, "5=5".
1345 This makes us consider it defined
1346 without saying what it is. The debugger will make it
1347 a void type when the reference is seen, and nothing will
1348 ever override that default. */
1349 dbxout_type_index (type);
1350 break;
1352 case INTEGER_TYPE:
1353 if (type == char_type_node && ! TREE_UNSIGNED (type))
1355 /* Output the type `char' as a subrange of itself!
1356 I don't understand this definition, just copied it
1357 from the output of pcc.
1358 This used to use `r2' explicitly and we used to
1359 take care to make sure that `char' was type number 2. */
1360 fprintf (asmfile, "r");
1361 CHARS (1);
1362 dbxout_type_index (type);
1363 fprintf (asmfile, ";0;127;");
1364 CHARS (7);
1367 /* If this is a subtype of another integer type, always prefer to
1368 write it as a subtype. */
1369 else if (TREE_TYPE (type) != 0
1370 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1372 /* If the size is non-standard, say what it is if we can use
1373 GDB extensions. */
1375 if (use_gnu_debug_info_extensions
1376 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1378 have_used_extensions = 1;
1379 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1380 CHARS (5);
1383 dbxout_range_type (type);
1386 else
1388 /* If the size is non-standard, say what it is if we can use
1389 GDB extensions. */
1391 if (use_gnu_debug_info_extensions
1392 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1394 have_used_extensions = 1;
1395 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1396 CHARS (5);
1399 if (print_int_cst_bounds_in_octal_p (type))
1401 fprintf (asmfile, "r");
1402 CHARS (1);
1404 /* If this type derives from another type, output type index of
1405 parent type. This is particularly important when parent type
1406 is an enumerated type, because not generating the parent type
1407 index would transform the definition of this enumerated type
1408 into a plain unsigned type. */
1409 if (TREE_TYPE (type) != 0)
1410 dbxout_type_index (TREE_TYPE (type));
1411 else
1412 dbxout_type_index (type);
1414 fprintf (asmfile, ";");
1415 CHARS (1);
1416 print_int_cst_octal (TYPE_MIN_VALUE (type));
1417 fprintf (asmfile, ";");
1418 CHARS (1);
1419 print_int_cst_octal (TYPE_MAX_VALUE (type));
1420 fprintf (asmfile, ";");
1421 CHARS (1);
1424 else
1425 /* Output other integer types as subranges of `int'. */
1426 dbxout_range_type (type);
1429 break;
1431 case REAL_TYPE:
1432 /* This used to say `r1' and we used to take care
1433 to make sure that `int' was type number 1. */
1434 fprintf (asmfile, "r");
1435 CHARS (1);
1436 dbxout_type_index (integer_type_node);
1437 putc (';', asmfile);
1438 CHARS (1);
1439 print_wide_int (int_size_in_bytes (type));
1440 fputs (";0;", asmfile);
1441 CHARS (3);
1442 break;
1444 case CHAR_TYPE:
1445 if (use_gnu_debug_info_extensions)
1447 have_used_extensions = 1;
1448 fputs ("@s", asmfile);
1449 CHARS (2);
1450 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1451 fputs (";-20;", asmfile);
1452 CHARS (4);
1454 else
1456 /* Output the type `char' as a subrange of itself.
1457 That is what pcc seems to do. */
1458 fprintf (asmfile, "r");
1459 CHARS (1);
1460 dbxout_type_index (char_type_node);
1461 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1462 CHARS (7);
1464 break;
1466 case BOOLEAN_TYPE:
1467 if (use_gnu_debug_info_extensions)
1469 have_used_extensions = 1;
1470 fputs ("@s", asmfile);
1471 CHARS (2);
1472 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1473 fputs (";-16;", asmfile);
1474 CHARS (4);
1476 else /* Define as enumeral type (False, True) */
1478 fprintf (asmfile, "eFalse:0,True:1,;");
1479 CHARS (17);
1481 break;
1483 case FILE_TYPE:
1484 putc ('d', asmfile);
1485 CHARS (1);
1486 dbxout_type (TREE_TYPE (type), 0);
1487 break;
1489 case COMPLEX_TYPE:
1490 /* Differs from the REAL_TYPE by its new data type number.
1491 R3 is NF_COMPLEX. We don't try to use any of the other NF_*
1492 codes since gdb doesn't care anyway. */
1494 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1496 fputs ("R3;", asmfile);
1497 CHARS (3);
1498 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1499 fputs (";0;", asmfile);
1500 CHARS (3);
1502 else
1504 /* Output a complex integer type as a structure,
1505 pending some other way to do it. */
1506 putc ('s', asmfile);
1507 CHARS (1);
1508 print_wide_int (int_size_in_bytes (type));
1509 fprintf (asmfile, "real:");
1510 CHARS (5);
1512 dbxout_type (TREE_TYPE (type), 0);
1513 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1514 CHARS (7);
1515 fprintf (asmfile, "imag:");
1516 CHARS (5);
1517 dbxout_type (TREE_TYPE (type), 0);
1518 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1519 TYPE_PRECISION (TREE_TYPE (type)));
1520 CHARS (10);
1522 break;
1524 case SET_TYPE:
1525 if (use_gnu_debug_info_extensions)
1527 have_used_extensions = 1;
1528 fputs ("@s", asmfile);
1529 CHARS (2);
1530 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1531 putc (';', asmfile);
1532 CHARS (1);
1534 /* Check if a bitstring type, which in Chill is
1535 different from a [power]set. */
1536 if (TYPE_STRING_FLAG (type))
1538 fprintf (asmfile, "@S;");
1539 CHARS (3);
1542 putc ('S', asmfile);
1543 CHARS (1);
1544 dbxout_type (TYPE_DOMAIN (type), 0);
1545 break;
1547 case ARRAY_TYPE:
1548 /* Make arrays of packed bits look like bitstrings for chill. */
1549 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1551 have_used_extensions = 1;
1552 fputs ("@s", asmfile);
1553 CHARS (2);
1554 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1555 fprintf (asmfile, ";@S;S");
1556 CHARS (5);
1557 dbxout_type (TYPE_DOMAIN (type), 0);
1558 break;
1561 /* Output "a" followed by a range type definition
1562 for the index type of the array
1563 followed by a reference to the target-type.
1564 ar1;0;N;M for a C array of type M and size N+1. */
1565 /* Check if a character string type, which in Chill is
1566 different from an array of characters. */
1567 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1569 have_used_extensions = 1;
1570 fprintf (asmfile, "@S;");
1571 CHARS (3);
1573 tem = TYPE_DOMAIN (type);
1574 if (tem == NULL)
1576 fprintf (asmfile, "ar");
1577 CHARS (2);
1578 dbxout_type_index (integer_type_node);
1579 fprintf (asmfile, ";0;-1;");
1580 CHARS (6);
1582 else
1584 fprintf (asmfile, "a");
1585 CHARS (1);
1586 dbxout_range_type (tem);
1589 dbxout_type (TREE_TYPE (type), 0);
1590 break;
1592 case RECORD_TYPE:
1593 case UNION_TYPE:
1594 case QUAL_UNION_TYPE:
1596 int i, n_baseclasses = 0;
1598 if (TYPE_BINFO (type) != 0
1599 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1600 && TYPE_BINFO_BASETYPES (type) != 0)
1601 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1603 /* Output a structure type. We must use the same test here as we
1604 use in the DBX_NO_XREFS case above. */
1605 if ((TYPE_NAME (type) != 0
1606 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1607 && DECL_IGNORED_P (TYPE_NAME (type)))
1608 && !full)
1609 || !COMPLETE_TYPE_P (type)
1610 /* No way in DBX fmt to describe a variable size. */
1611 || ! host_integerp (TYPE_SIZE (type), 1))
1613 /* If the type is just a cross reference, output one
1614 and mark the type as partially described.
1615 If it later becomes defined, we will output
1616 its real definition.
1617 If the type has a name, don't nest its definition within
1618 another type's definition; instead, output an xref
1619 and let the definition come when the name is defined. */
1620 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1621 CHARS (2);
1622 #if 0 /* This assertion is legitimately false in C++. */
1623 /* We shouldn't be outputting a reference to a type before its
1624 definition unless the type has a tag name.
1625 A typedef name without a tag name should be impossible. */
1626 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1627 abort ();
1628 #endif
1629 if (TYPE_NAME (type) != 0)
1630 dbxout_type_name (type);
1631 else
1633 fprintf (asmfile, "$$%d", anonymous_type_number++);
1634 CHARS (5);
1637 fprintf (asmfile, ":");
1638 CHARS (1);
1639 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1640 break;
1643 /* Identify record or union, and print its size. */
1644 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1645 CHARS (1);
1646 print_wide_int (int_size_in_bytes (type));
1648 if (use_gnu_debug_info_extensions)
1650 if (n_baseclasses)
1652 have_used_extensions = 1;
1653 fprintf (asmfile, "!%d,", n_baseclasses);
1654 CHARS (8);
1657 for (i = 0; i < n_baseclasses; i++)
1659 tree binfo = TYPE_BINFO (type);
1660 tree child = BINFO_BASETYPE (binfo, i);
1661 tree access = (BINFO_BASEACCESSES (binfo)
1662 ? BINFO_BASEACCESS (binfo, i) : access_public_node);
1664 if (use_gnu_debug_info_extensions)
1666 have_used_extensions = 1;
1667 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1668 putc (access == access_public_node ? '2' : '0', asmfile);
1669 CHARS (2);
1670 if (TREE_VIA_VIRTUAL (child)
1671 && strcmp (lang_hooks.name, "GNU C++") == 0)
1672 /* For a virtual base, print the (negative) offset within
1673 the vtable where we must look to find the necessary
1674 adjustment. */
1675 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1676 * BITS_PER_UNIT);
1677 else
1678 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1679 * BITS_PER_UNIT);
1680 putc (',', asmfile);
1681 CHARS (1);
1682 dbxout_type (BINFO_TYPE (child), 0);
1683 putc (';', asmfile);
1684 CHARS (1);
1686 else
1688 /* Print out the base class information with fields
1689 which have the same names at the types they hold. */
1690 dbxout_type_name (BINFO_TYPE (child));
1691 putc (':', asmfile);
1692 CHARS (1);
1693 dbxout_type (BINFO_TYPE (child), full);
1694 putc (',', asmfile);
1695 CHARS (1);
1696 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1697 * BITS_PER_UNIT);
1698 putc (',', asmfile);
1699 CHARS (1);
1700 print_wide_int (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)),
1702 * BITS_PER_UNIT);
1703 putc (';', asmfile);
1704 CHARS (1);
1709 /* Write out the field declarations. */
1710 dbxout_type_fields (type);
1711 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1713 have_used_extensions = 1;
1714 dbxout_type_methods (type);
1717 putc (';', asmfile);
1718 CHARS (1);
1720 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1721 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1722 && TYPE_VFIELD (type))
1724 have_used_extensions = 1;
1726 /* Tell GDB+ that it may keep reading. */
1727 putc ('~', asmfile);
1728 CHARS (1);
1730 /* We need to write out info about what field this class
1731 uses as its "main" vtable pointer field, because if this
1732 field is inherited from a base class, GDB cannot necessarily
1733 figure out which field it's using in time. */
1734 if (TYPE_VFIELD (type))
1736 putc ('%', asmfile);
1737 CHARS (1);
1738 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1741 putc (';', asmfile);
1742 CHARS (1);
1744 break;
1746 case ENUMERAL_TYPE:
1747 /* We must use the same test here as we use in the DBX_NO_XREFS case
1748 above. We simplify it a bit since an enum will never have a variable
1749 size. */
1750 if ((TYPE_NAME (type) != 0
1751 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1752 && DECL_IGNORED_P (TYPE_NAME (type)))
1753 && !full)
1754 || !COMPLETE_TYPE_P (type))
1756 fprintf (asmfile, "xe");
1757 CHARS (2);
1758 dbxout_type_name (type);
1759 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1760 putc (':', asmfile);
1761 CHARS (1);
1762 return;
1764 if (use_gnu_debug_info_extensions
1765 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1767 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1768 CHARS (5);
1771 putc ('e', asmfile);
1772 CHARS (1);
1773 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1775 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1776 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1777 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1778 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1779 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1780 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1781 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1782 else
1783 print_int_cst_octal (TREE_VALUE (tem));
1785 putc (',', asmfile);
1786 CHARS (1);
1787 if (TREE_CHAIN (tem) != 0)
1788 CONTIN;
1791 putc (';', asmfile);
1792 CHARS (1);
1793 break;
1795 case POINTER_TYPE:
1796 putc ('*', asmfile);
1797 CHARS (1);
1798 dbxout_type (TREE_TYPE (type), 0);
1799 break;
1801 case METHOD_TYPE:
1802 if (use_gnu_debug_info_extensions)
1804 have_used_extensions = 1;
1805 putc ('#', asmfile);
1806 CHARS (1);
1808 /* Write the argument types out longhand. */
1809 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1810 putc (',', asmfile);
1811 CHARS (1);
1812 dbxout_type (TREE_TYPE (type), 0);
1813 dbxout_args (TYPE_ARG_TYPES (type));
1814 putc (';', asmfile);
1815 CHARS (1);
1817 else
1818 /* Treat it as a function type. */
1819 dbxout_type (TREE_TYPE (type), 0);
1820 break;
1822 case OFFSET_TYPE:
1823 if (use_gnu_debug_info_extensions)
1825 have_used_extensions = 1;
1826 putc ('@', asmfile);
1827 CHARS (1);
1828 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1829 putc (',', asmfile);
1830 CHARS (1);
1831 dbxout_type (TREE_TYPE (type), 0);
1833 else
1834 /* Should print as an int, because it is really just an offset. */
1835 dbxout_type (integer_type_node, 0);
1836 break;
1838 case REFERENCE_TYPE:
1839 if (use_gnu_debug_info_extensions)
1840 have_used_extensions = 1;
1841 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1842 CHARS (1);
1843 dbxout_type (TREE_TYPE (type), 0);
1844 break;
1846 case FUNCTION_TYPE:
1847 putc ('f', asmfile);
1848 CHARS (1);
1849 dbxout_type (TREE_TYPE (type), 0);
1850 break;
1852 default:
1853 abort ();
1857 /* Return nonzero if the given type represents an integer whose bounds
1858 should be printed in octal format. */
1860 static bool
1861 print_int_cst_bounds_in_octal_p (tree type)
1863 /* If we can use GDB extensions and the size is wider than a long
1864 (the size used by GDB to read them) or we may have trouble writing
1865 the bounds the usual way, write them in octal. Note the test is for
1866 the *target's* size of "long", not that of the host. The host test
1867 is just to make sure we can write it out in case the host wide int
1868 is narrower than the target "long".
1870 For unsigned types, we use octal if they are the same size or larger.
1871 This is because we print the bounds as signed decimal, and hence they
1872 can't span same size unsigned types. */
1874 if (use_gnu_debug_info_extensions
1875 && TYPE_MIN_VALUE (type) != 0
1876 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1877 && TYPE_MAX_VALUE (type) != 0
1878 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1879 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1880 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1881 && TREE_UNSIGNED (type))
1882 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1883 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1884 && TREE_UNSIGNED (type))))
1885 return TRUE;
1886 else
1887 return FALSE;
1890 /* Print the value of integer constant C, in octal,
1891 handling double precision. */
1893 static void
1894 print_int_cst_octal (tree c)
1896 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1897 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1898 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1899 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1901 /* GDB wants constants with no extra leading "1" bits, so
1902 we need to remove any sign-extension that might be
1903 present. */
1904 if (width == HOST_BITS_PER_WIDE_INT * 2)
1906 else if (width > HOST_BITS_PER_WIDE_INT)
1907 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1908 else if (width == HOST_BITS_PER_WIDE_INT)
1909 high = 0;
1910 else
1911 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1913 fprintf (asmfile, "0");
1914 CHARS (1);
1916 if (excess == 3)
1918 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1919 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1921 else
1923 unsigned HOST_WIDE_INT beg = high >> excess;
1924 unsigned HOST_WIDE_INT middle
1925 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1926 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1927 unsigned HOST_WIDE_INT end
1928 = low & (((unsigned HOST_WIDE_INT) 1
1929 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1930 - 1);
1932 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1933 CHARS (2);
1934 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1938 static void
1939 print_octal (unsigned HOST_WIDE_INT value, int digits)
1941 int i;
1943 for (i = digits - 1; i >= 0; i--)
1944 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1946 CHARS (digits);
1949 /* Output C in decimal while adjusting the number of digits written. */
1951 static void
1952 print_wide_int (HOST_WIDE_INT c)
1954 int digs = 0;
1956 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1958 if (c < 0)
1959 digs++, c = -c;
1961 while (c > 0)
1962 c /= 10; digs++;
1964 CHARS (digs);
1967 /* Output the name of type TYPE, with no punctuation.
1968 Such names can be set up either by typedef declarations
1969 or by struct, enum and union tags. */
1971 static void
1972 dbxout_type_name (tree type)
1974 tree t;
1975 if (TYPE_NAME (type) == 0)
1976 abort ();
1977 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1979 t = TYPE_NAME (type);
1981 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1983 t = DECL_NAME (TYPE_NAME (type));
1985 else
1986 abort ();
1988 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1989 CHARS (IDENTIFIER_LENGTH (t));
1992 /* Output leading leading struct or class names needed for qualifying
1993 type whose scope is limited to a struct or class. */
1995 static void
1996 dbxout_class_name_qualifiers (tree decl)
1998 tree context = decl_type_context (decl);
2000 if (context != NULL_TREE
2001 && TREE_CODE(context) == RECORD_TYPE
2002 && TYPE_NAME (context) != 0
2003 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2004 || (DECL_NAME (TYPE_NAME (context)) != 0)))
2006 tree name = TYPE_NAME (context);
2008 emit_pending_bincls_if_required ();
2010 if (TREE_CODE (name) == TYPE_DECL)
2012 dbxout_class_name_qualifiers (name);
2013 name = DECL_NAME (name);
2015 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
2016 CHARS (IDENTIFIER_LENGTH (name) + 2);
2020 /* Output a .stabs for the symbol defined by DECL,
2021 which must be a ..._DECL node in the normal namespace.
2022 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2023 LOCAL is nonzero if the scope is less than the entire file.
2024 Return 1 if a stabs might have been emitted. */
2027 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2029 tree type = TREE_TYPE (decl);
2030 tree context = NULL_TREE;
2031 int result = 0;
2033 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */
2034 ++debug_nesting;
2036 /* Cast avoids warning in old compilers. */
2037 current_sym_code = (STAB_CODE_TYPE) 0;
2038 current_sym_value = 0;
2039 current_sym_addr = 0;
2041 /* Ignore nameless syms, but don't ignore type tags. */
2043 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2044 || DECL_IGNORED_P (decl))
2045 DBXOUT_DECR_NESTING_AND_RETURN (0);
2047 /* If we are to generate only the symbols actually used then such
2048 symbol nodees are flagged with TREE_USED. Ignore any that
2049 aren't flaged as TREE_USED. */
2051 if (flag_debug_only_used_symbols)
2053 tree t;
2055 if (!TREE_USED (decl)
2056 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl)))
2057 DBXOUT_DECR_NESTING_AND_RETURN (0);
2059 /* We now have a used symbol. We need to generate the info for
2060 the symbol's type in addition to the symbol itself. These
2061 type symbols are queued to be generated after were done with
2062 the symbol itself (done because the symbol's info is generated
2063 with fprintf's, etc. as it determines what's needed).
2065 Note, because the TREE_TYPE(type) might be something like a
2066 pointer to a named type we need to look for the first name
2067 we see following the TREE_TYPE chain. */
2069 t = type;
2070 while (POINTER_TYPE_P (t))
2071 t = TREE_TYPE (t);
2073 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2074 need special treatment. The TYPE_STUB_DECL field in these
2075 types generally represents the tag name type we want to
2076 output. In addition there could be a typedef type with
2077 a different name. In that case we also want to output
2078 that. */
2080 if ((TREE_CODE (t) == RECORD_TYPE
2081 || TREE_CODE (t) == UNION_TYPE
2082 || TREE_CODE (t) == QUAL_UNION_TYPE
2083 || TREE_CODE (t) == ENUMERAL_TYPE)
2084 && TYPE_STUB_DECL (t)
2085 && TYPE_STUB_DECL (t) != decl
2086 && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (t))) == 'd'
2087 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2089 debug_queue_symbol (TYPE_STUB_DECL (t));
2090 if (TYPE_NAME (t)
2091 && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2092 && TYPE_NAME (t) != decl
2093 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2094 debug_queue_symbol (TYPE_NAME (t));
2096 else if (TYPE_NAME (t)
2097 && TYPE_NAME (t) != decl
2098 && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2099 debug_queue_symbol (TYPE_NAME (t));
2102 emit_pending_bincls_if_required ();
2104 dbxout_prepare_symbol (decl);
2106 /* The output will always start with the symbol name,
2107 so always count that in the length-output-so-far. */
2109 if (DECL_NAME (decl) != 0)
2110 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2112 switch (TREE_CODE (decl))
2114 case CONST_DECL:
2115 /* Enum values are defined by defining the enum type. */
2116 break;
2118 case FUNCTION_DECL:
2119 if (DECL_RTL (decl) == 0)
2120 DBXOUT_DECR_NESTING_AND_RETURN (0);
2121 if (DECL_EXTERNAL (decl))
2122 break;
2123 /* Don't mention a nested function under its parent. */
2124 context = decl_function_context (decl);
2125 if (context == current_function_decl)
2126 break;
2127 if (GET_CODE (DECL_RTL (decl)) != MEM
2128 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2129 break;
2130 FORCE_TEXT;
2132 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2133 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2134 TREE_PUBLIC (decl) ? 'F' : 'f');
2135 result = 1;
2137 current_sym_code = N_FUN;
2138 current_sym_addr = XEXP (DECL_RTL (decl), 0);
2140 if (TREE_TYPE (type))
2141 dbxout_type (TREE_TYPE (type), 0);
2142 else
2143 dbxout_type (void_type_node, 0);
2145 /* For a nested function, when that function is compiled,
2146 mention the containing function name
2147 as well as (since dbx wants it) our own assembler-name. */
2148 if (context != 0)
2149 fprintf (asmfile, ",%s,%s",
2150 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2151 IDENTIFIER_POINTER (DECL_NAME (context)));
2153 dbxout_finish_symbol (decl);
2154 break;
2156 case TYPE_DECL:
2157 /* Don't output the same typedef twice.
2158 And don't output what language-specific stuff doesn't want output. */
2159 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2160 DBXOUT_DECR_NESTING_AND_RETURN (0);
2162 FORCE_TEXT;
2163 result = 1;
2165 int tag_needed = 1;
2166 int did_output = 0;
2168 if (DECL_NAME (decl))
2170 /* Nonzero means we must output a tag as well as a typedef. */
2171 tag_needed = 0;
2173 /* Handle the case of a C++ structure or union
2174 where the TYPE_NAME is a TYPE_DECL
2175 which gives both a typedef name and a tag. */
2176 /* dbx requires the tag first and the typedef second. */
2177 if ((TREE_CODE (type) == RECORD_TYPE
2178 || TREE_CODE (type) == UNION_TYPE
2179 || TREE_CODE (type) == QUAL_UNION_TYPE)
2180 && TYPE_NAME (type) == decl
2181 && !(use_gnu_debug_info_extensions && have_used_extensions)
2182 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2183 /* Distinguish the implicit typedefs of C++
2184 from explicit ones that might be found in C. */
2185 && DECL_ARTIFICIAL (decl)
2186 /* Do not generate a tag for incomplete records. */
2187 && COMPLETE_TYPE_P (type)
2188 /* Do not generate a tag for records of variable size,
2189 since this type can not be properly described in the
2190 DBX format, and it confuses some tools such as objdump. */
2191 && host_integerp (TYPE_SIZE (type), 1))
2193 tree name = TYPE_NAME (type);
2194 if (TREE_CODE (name) == TYPE_DECL)
2195 name = DECL_NAME (name);
2197 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2198 current_sym_value = 0;
2199 current_sym_addr = 0;
2200 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2202 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2203 IDENTIFIER_POINTER (name));
2204 dbxout_type (type, 1);
2205 dbxout_finish_symbol (NULL_TREE);
2208 /* Output .stabs (or whatever) and leading double quote. */
2209 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2211 if (use_gnu_debug_info_extensions)
2213 /* Output leading class/struct qualifiers. */
2214 dbxout_class_name_qualifiers (decl);
2217 /* Output typedef name. */
2218 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2220 /* Short cut way to output a tag also. */
2221 if ((TREE_CODE (type) == RECORD_TYPE
2222 || TREE_CODE (type) == UNION_TYPE
2223 || TREE_CODE (type) == QUAL_UNION_TYPE)
2224 && TYPE_NAME (type) == decl
2225 /* Distinguish the implicit typedefs of C++
2226 from explicit ones that might be found in C. */
2227 && DECL_ARTIFICIAL (decl))
2229 if (use_gnu_debug_info_extensions && have_used_extensions)
2231 putc ('T', asmfile);
2232 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2234 #if 0 /* Now we generate the tag for this case up above. */
2235 else
2236 tag_needed = 1;
2237 #endif
2240 putc ('t', asmfile);
2241 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2243 dbxout_type (type, 1);
2244 dbxout_finish_symbol (decl);
2245 did_output = 1;
2248 /* Don't output a tag if this is an incomplete type. This prevents
2249 the sun4 Sun OS 4.x dbx from crashing. */
2251 if (tag_needed && TYPE_NAME (type) != 0
2252 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2253 || (DECL_NAME (TYPE_NAME (type)) != 0))
2254 && COMPLETE_TYPE_P (type)
2255 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2257 /* For a TYPE_DECL with no name, but the type has a name,
2258 output a tag.
2259 This is what represents `struct foo' with no typedef. */
2260 /* In C++, the name of a type is the corresponding typedef.
2261 In C, it is an IDENTIFIER_NODE. */
2262 tree name = TYPE_NAME (type);
2263 if (TREE_CODE (name) == TYPE_DECL)
2264 name = DECL_NAME (name);
2266 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2267 current_sym_value = 0;
2268 current_sym_addr = 0;
2269 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2271 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2272 IDENTIFIER_POINTER (name));
2273 dbxout_type (type, 1);
2274 dbxout_finish_symbol (NULL_TREE);
2275 did_output = 1;
2278 /* If an enum type has no name, it cannot be referred to,
2279 but we must output it anyway, since the enumeration constants
2280 can be referred to. */
2281 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2283 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2284 current_sym_value = 0;
2285 current_sym_addr = 0;
2286 current_sym_nchars = 2;
2288 /* Some debuggers fail when given NULL names, so give this a
2289 harmless name of ` '. */
2290 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2291 dbxout_type (type, 1);
2292 dbxout_finish_symbol (NULL_TREE);
2295 /* Prevent duplicate output of a typedef. */
2296 TREE_ASM_WRITTEN (decl) = 1;
2297 break;
2300 case PARM_DECL:
2301 /* Parm decls go in their own separate chains
2302 and are output by dbxout_reg_parms and dbxout_parms. */
2303 abort ();
2305 case RESULT_DECL:
2306 /* Named return value, treat like a VAR_DECL. */
2307 case VAR_DECL:
2308 if (! DECL_RTL_SET_P (decl))
2309 DBXOUT_DECR_NESTING_AND_RETURN (0);
2310 /* Don't mention a variable that is external.
2311 Let the file that defines it describe it. */
2312 if (DECL_EXTERNAL (decl))
2313 break;
2315 /* If the variable is really a constant
2316 and not written in memory, inform the debugger. */
2317 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2318 && DECL_INITIAL (decl) != 0
2319 && host_integerp (DECL_INITIAL (decl), 0)
2320 && ! TREE_ASM_WRITTEN (decl)
2321 && (DECL_CONTEXT (decl) == NULL_TREE
2322 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2324 if (TREE_PUBLIC (decl) == 0)
2326 /* The sun4 assembler does not grok this. */
2327 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2329 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2330 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2332 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2333 fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2334 "\",0x%x,0,0,0\n",
2335 ASM_STABS_OP, name, ival, N_LSYM);
2336 DBXOUT_DECR_NESTING;
2337 return 1;
2339 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2341 /* don't know how to do this yet. */
2343 break;
2345 /* else it is something we handle like a normal variable. */
2348 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2349 #ifdef LEAF_REG_REMAP
2350 if (current_function_uses_only_leaf_regs)
2351 leaf_renumber_regs_insn (DECL_RTL (decl));
2352 #endif
2354 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2355 break;
2357 default:
2358 break;
2360 DBXOUT_DECR_NESTING;
2361 return result;
2364 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2365 Add SUFFIX to its name, if SUFFIX is not 0.
2366 Describe the variable as residing in HOME
2367 (usually HOME is DECL_RTL (DECL), but not always).
2368 Returns 1 if the stab was really emitted. */
2370 static int
2371 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2373 int letter = 0;
2374 int regno = -1;
2376 emit_pending_bincls_if_required ();
2378 /* Don't mention a variable at all
2379 if it was completely optimized into nothingness.
2381 If the decl was from an inline function, then its rtl
2382 is not identically the rtl that was used in this
2383 particular compilation. */
2384 if (GET_CODE (home) == SUBREG)
2386 rtx value = home;
2388 while (GET_CODE (value) == SUBREG)
2389 value = SUBREG_REG (value);
2390 if (GET_CODE (value) == REG)
2392 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2393 return 0;
2395 home = alter_subreg (&home);
2397 if (GET_CODE (home) == REG)
2399 regno = REGNO (home);
2400 if (regno >= FIRST_PSEUDO_REGISTER)
2401 return 0;
2404 /* The kind-of-variable letter depends on where
2405 the variable is and on the scope of its name:
2406 G and N_GSYM for static storage and global scope,
2407 S for static storage and file scope,
2408 V for static storage and local scope,
2409 for those two, use N_LCSYM if data is in bss segment,
2410 N_STSYM if in data segment, N_FUN otherwise.
2411 (We used N_FUN originally, then changed to N_STSYM
2412 to please GDB. However, it seems that confused ld.
2413 Now GDB has been fixed to like N_FUN, says Kingdon.)
2414 no letter at all, and N_LSYM, for auto variable,
2415 r and N_RSYM for register variable. */
2417 if (GET_CODE (home) == MEM
2418 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2420 if (TREE_PUBLIC (decl))
2422 letter = 'G';
2423 current_sym_code = N_GSYM;
2425 else
2427 current_sym_addr = XEXP (home, 0);
2429 letter = decl_function_context (decl) ? 'V' : 'S';
2431 /* This should be the same condition as in assemble_variable, but
2432 we don't have access to dont_output_data here. So, instead,
2433 we rely on the fact that error_mark_node initializers always
2434 end up in bss for C++ and never end up in bss for C. */
2435 if (DECL_INITIAL (decl) == 0
2436 || (!strcmp (lang_hooks.name, "GNU C++")
2437 && DECL_INITIAL (decl) == error_mark_node))
2438 current_sym_code = N_LCSYM;
2439 else if (DECL_IN_TEXT_SECTION (decl))
2440 /* This is not quite right, but it's the closest
2441 of all the codes that Unix defines. */
2442 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2443 else
2445 /* Some ports can transform a symbol ref into a label ref,
2446 because the symbol ref is too far away and has to be
2447 dumped into a constant pool. Alternatively, the symbol
2448 in the constant pool might be referenced by a different
2449 symbol. */
2450 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2451 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2453 rtx tmp = get_pool_constant (current_sym_addr);
2455 if (GET_CODE (tmp) == SYMBOL_REF
2456 || GET_CODE (tmp) == LABEL_REF)
2457 current_sym_addr = tmp;
2460 /* Ultrix `as' seems to need this. */
2461 #ifdef DBX_STATIC_STAB_DATA_SECTION
2462 data_section ();
2463 #endif
2464 current_sym_code = N_STSYM;
2468 else if (regno >= 0)
2470 letter = 'r';
2471 current_sym_code = N_RSYM;
2472 current_sym_value = DBX_REGISTER_NUMBER (regno);
2474 else if (GET_CODE (home) == MEM
2475 && (GET_CODE (XEXP (home, 0)) == MEM
2476 || (GET_CODE (XEXP (home, 0)) == REG
2477 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2478 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2479 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2480 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2481 #endif
2483 /* If the value is indirect by memory or by a register
2484 that isn't the frame pointer
2485 then it means the object is variable-sized and address through
2486 that register or stack slot. DBX has no way to represent this
2487 so all we can do is output the variable as a pointer.
2488 If it's not a parameter, ignore it.
2489 (VAR_DECLs like this can be made by integrate.c.) */
2491 if (GET_CODE (XEXP (home, 0)) == REG)
2493 letter = 'r';
2494 current_sym_code = N_RSYM;
2495 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2496 return 0;
2497 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2499 else
2501 current_sym_code = N_LSYM;
2502 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2503 We want the value of that CONST_INT. */
2504 current_sym_value
2505 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2508 /* Effectively do build_pointer_type, but don't cache this type,
2509 since it might be temporary whereas the type it points to
2510 might have been saved for inlining. */
2511 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2512 type = make_node (POINTER_TYPE);
2513 TREE_TYPE (type) = TREE_TYPE (decl);
2515 else if (GET_CODE (home) == MEM
2516 && GET_CODE (XEXP (home, 0)) == REG)
2518 current_sym_code = N_LSYM;
2519 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2521 else if (GET_CODE (home) == MEM
2522 && GET_CODE (XEXP (home, 0)) == PLUS
2523 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2525 current_sym_code = N_LSYM;
2526 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2527 We want the value of that CONST_INT. */
2528 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2530 else if (GET_CODE (home) == MEM
2531 && GET_CODE (XEXP (home, 0)) == CONST)
2533 /* Handle an obscure case which can arise when optimizing and
2534 when there are few available registers. (This is *always*
2535 the case for i386/i486 targets). The RTL looks like
2536 (MEM (CONST ...)) even though this variable is a local `auto'
2537 or a local `register' variable. In effect, what has happened
2538 is that the reload pass has seen that all assignments and
2539 references for one such a local variable can be replaced by
2540 equivalent assignments and references to some static storage
2541 variable, thereby avoiding the need for a register. In such
2542 cases we're forced to lie to debuggers and tell them that
2543 this variable was itself `static'. */
2544 current_sym_code = N_LCSYM;
2545 letter = 'V';
2546 current_sym_addr = XEXP (XEXP (home, 0), 0);
2548 else if (GET_CODE (home) == CONCAT)
2550 tree subtype;
2552 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2553 for example), then there is no easy way to figure out
2554 what SUBTYPE should be. So, we give up. */
2555 if (TREE_CODE (type) != COMPLEX_TYPE)
2556 return 0;
2558 subtype = TREE_TYPE (type);
2560 /* If the variable's storage is in two parts,
2561 output each as a separate stab with a modified name. */
2562 if (WORDS_BIG_ENDIAN)
2563 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2564 else
2565 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2567 /* Cast avoids warning in old compilers. */
2568 current_sym_code = (STAB_CODE_TYPE) 0;
2569 current_sym_value = 0;
2570 current_sym_addr = 0;
2571 dbxout_prepare_symbol (decl);
2573 if (WORDS_BIG_ENDIAN)
2574 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2575 else
2576 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2577 return 1;
2579 else
2580 /* Address might be a MEM, when DECL is a variable-sized object.
2581 Or it might be const0_rtx, meaning previous passes
2582 want us to ignore this variable. */
2583 return 0;
2585 /* Ok, start a symtab entry and output the variable name. */
2586 FORCE_TEXT;
2588 #ifdef DBX_STATIC_BLOCK_START
2589 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2590 #endif
2592 dbxout_symbol_name (decl, suffix, letter);
2593 dbxout_type (type, 0);
2594 dbxout_finish_symbol (decl);
2596 #ifdef DBX_STATIC_BLOCK_END
2597 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2598 #endif
2599 return 1;
2602 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2603 Then output LETTER to indicate the kind of location the symbol has. */
2605 static void
2606 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2608 const char *name;
2610 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2611 /* One slight hitch: if this is a VAR_DECL which is a static
2612 class member, we must put out the mangled name instead of the
2613 DECL_NAME. Note also that static member (variable) names DO NOT begin
2614 with underscores in .stabs directives. */
2615 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2616 else
2617 /* ...but if we're function-local, we don't want to include the junk
2618 added by ASM_FORMAT_PRIVATE_NAME. */
2619 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2621 if (name == 0)
2622 name = "(anon)";
2623 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2624 (suffix ? suffix : ""));
2626 if (letter)
2627 putc (letter, asmfile);
2630 static void
2631 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)
2633 #ifdef WINNING_GDB
2634 const char *filename = DECL_SOURCE_FILE (decl);
2636 dbxout_source_file (asmfile, filename);
2637 #endif
2640 static void
2641 dbxout_finish_symbol (tree sym)
2643 #ifdef DBX_FINISH_SYMBOL
2644 DBX_FINISH_SYMBOL (sym);
2645 #else
2646 int line = 0;
2647 if (use_gnu_debug_info_extensions && sym != 0)
2648 line = DECL_SOURCE_LINE (sym);
2650 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2651 if (current_sym_addr)
2652 output_addr_const (asmfile, current_sym_addr);
2653 else
2654 fprintf (asmfile, "%d", current_sym_value);
2655 putc ('\n', asmfile);
2656 #endif
2659 /* Output definitions of all the decls in a chain. Return nonzero if
2660 anything was output */
2663 dbxout_syms (tree syms)
2665 int result = 0;
2666 while (syms)
2668 result += dbxout_symbol (syms, 1);
2669 syms = TREE_CHAIN (syms);
2671 return result;
2674 /* The following two functions output definitions of function parameters.
2675 Each parameter gets a definition locating it in the parameter list.
2676 Each parameter that is a register variable gets a second definition
2677 locating it in the register.
2679 Printing or argument lists in gdb uses the definitions that
2680 locate in the parameter list. But reference to the variable in
2681 expressions uses preferentially the definition as a register. */
2683 /* Output definitions, referring to storage in the parmlist,
2684 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2686 void
2687 dbxout_parms (tree parms)
2689 ++debug_nesting;
2691 emit_pending_bincls_if_required ();
2693 for (; parms; parms = TREE_CHAIN (parms))
2694 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2696 dbxout_prepare_symbol (parms);
2698 /* Perform any necessary register eliminations on the parameter's rtl,
2699 so that the debugging output will be accurate. */
2700 DECL_INCOMING_RTL (parms)
2701 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2702 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2703 #ifdef LEAF_REG_REMAP
2704 if (current_function_uses_only_leaf_regs)
2706 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2707 leaf_renumber_regs_insn (DECL_RTL (parms));
2709 #endif
2711 if (PARM_PASSED_IN_MEMORY (parms))
2713 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2715 /* ??? Here we assume that the parm address is indexed
2716 off the frame pointer or arg pointer.
2717 If that is not true, we produce meaningless results,
2718 but do not crash. */
2719 if (GET_CODE (addr) == PLUS
2720 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2721 current_sym_value = INTVAL (XEXP (addr, 1));
2722 else
2723 current_sym_value = 0;
2725 current_sym_code = N_PSYM;
2726 current_sym_addr = 0;
2728 FORCE_TEXT;
2729 if (DECL_NAME (parms))
2731 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2733 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2734 IDENTIFIER_POINTER (DECL_NAME (parms)),
2735 DBX_MEMPARM_STABS_LETTER);
2737 else
2739 current_sym_nchars = 8;
2740 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2741 DBX_MEMPARM_STABS_LETTER);
2744 /* It is quite tempting to use:
2746 dbxout_type (TREE_TYPE (parms), 0);
2748 as the next statement, rather than using DECL_ARG_TYPE(), so
2749 that gcc reports the actual type of the parameter, rather
2750 than the promoted type. This certainly makes GDB's life
2751 easier, at least for some ports. The change is a bad idea
2752 however, since GDB expects to be able access the type without
2753 performing any conversions. So for example, if we were
2754 passing a float to an unprototyped function, gcc will store a
2755 double on the stack, but if we emit a stab saying the type is a
2756 float, then gdb will only read in a single value, and this will
2757 produce an erroneous value. */
2758 dbxout_type (DECL_ARG_TYPE (parms), 0);
2759 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2760 dbxout_finish_symbol (parms);
2762 else if (GET_CODE (DECL_RTL (parms)) == REG)
2764 rtx best_rtl;
2765 char regparm_letter;
2766 tree parm_type;
2767 /* Parm passed in registers and lives in registers or nowhere. */
2769 current_sym_code = DBX_REGPARM_STABS_CODE;
2770 regparm_letter = DBX_REGPARM_STABS_LETTER;
2771 current_sym_addr = 0;
2773 /* If parm lives in a register, use that register;
2774 pretend the parm was passed there. It would be more consistent
2775 to describe the register where the parm was passed,
2776 but in practice that register usually holds something else.
2778 If we use DECL_RTL, then we must use the declared type of
2779 the variable, not the type that it arrived in. */
2780 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2782 best_rtl = DECL_RTL (parms);
2783 parm_type = TREE_TYPE (parms);
2785 /* If the parm lives nowhere, use the register where it was
2786 passed. It is also better to use the declared type here. */
2787 else
2789 best_rtl = DECL_INCOMING_RTL (parms);
2790 parm_type = TREE_TYPE (parms);
2792 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2794 FORCE_TEXT;
2795 if (DECL_NAME (parms))
2797 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2798 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2799 IDENTIFIER_POINTER (DECL_NAME (parms)),
2800 regparm_letter);
2802 else
2804 current_sym_nchars = 8;
2805 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2806 regparm_letter);
2809 dbxout_type (parm_type, 0);
2810 dbxout_finish_symbol (parms);
2812 else if (GET_CODE (DECL_RTL (parms)) == MEM
2813 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2814 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2815 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2816 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2817 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2818 #endif
2821 /* Parm was passed via invisible reference.
2822 That is, its address was passed in a register.
2823 Output it as if it lived in that register.
2824 The debugger will know from the type
2825 that it was actually passed by invisible reference. */
2827 char regparm_letter;
2828 /* Parm passed in registers and lives in registers or nowhere. */
2830 current_sym_code = DBX_REGPARM_STABS_CODE;
2831 if (use_gnu_debug_info_extensions)
2832 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2833 else
2834 regparm_letter = DBX_REGPARM_STABS_LETTER;
2836 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2837 If it is an unallocated pseudo-reg, then use the register where
2838 it was passed instead. */
2839 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2840 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2841 else
2842 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2844 current_sym_addr = 0;
2846 FORCE_TEXT;
2847 if (DECL_NAME (parms))
2849 current_sym_nchars
2850 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2852 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2853 IDENTIFIER_POINTER (DECL_NAME (parms)),
2854 regparm_letter);
2856 else
2858 current_sym_nchars = 8;
2859 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2860 regparm_letter);
2863 dbxout_type (TREE_TYPE (parms), 0);
2864 dbxout_finish_symbol (parms);
2866 else if (GET_CODE (DECL_RTL (parms)) == MEM
2867 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2869 /* Parm was passed via invisible reference, with the reference
2870 living on the stack. DECL_RTL looks like
2871 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2872 could look like (MEM (MEM (REG))). */
2873 const char *const decl_name = (DECL_NAME (parms)
2874 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2875 : "(anon)");
2876 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2877 current_sym_value = 0;
2878 else
2879 current_sym_value
2880 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2881 current_sym_addr = 0;
2882 current_sym_code = N_PSYM;
2884 FORCE_TEXT;
2885 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2887 current_sym_value
2888 = DEBUGGER_ARG_OFFSET (current_sym_value,
2889 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2890 dbxout_type (TREE_TYPE (parms), 0);
2891 dbxout_finish_symbol (parms);
2893 else if (GET_CODE (DECL_RTL (parms)) == MEM
2894 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2895 /* ??? A constant address for a parm can happen
2896 when the reg it lives in is equiv to a constant in memory.
2897 Should make this not happen, after 2.4. */
2898 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2900 /* Parm was passed in registers but lives on the stack. */
2902 current_sym_code = N_PSYM;
2903 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2904 in which case we want the value of that CONST_INT,
2905 or (MEM (REG ...)),
2906 in which case we use a value of zero. */
2907 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2908 current_sym_value = 0;
2909 else
2910 current_sym_value
2911 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2913 current_sym_addr = 0;
2915 /* Make a big endian correction if the mode of the type of the
2916 parameter is not the same as the mode of the rtl. */
2917 if (BYTES_BIG_ENDIAN
2918 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2919 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2921 current_sym_value +=
2922 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2923 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2926 FORCE_TEXT;
2927 if (DECL_NAME (parms))
2929 current_sym_nchars
2930 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2932 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2933 IDENTIFIER_POINTER (DECL_NAME (parms)),
2934 DBX_MEMPARM_STABS_LETTER);
2936 else
2938 current_sym_nchars = 8;
2939 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2940 DBX_MEMPARM_STABS_LETTER);
2943 current_sym_value
2944 = DEBUGGER_ARG_OFFSET (current_sym_value,
2945 XEXP (DECL_RTL (parms), 0));
2946 dbxout_type (TREE_TYPE (parms), 0);
2947 dbxout_finish_symbol (parms);
2950 DBXOUT_DECR_NESTING;
2953 /* Output definitions for the places where parms live during the function,
2954 when different from where they were passed, when the parms were passed
2955 in memory.
2957 It is not useful to do this for parms passed in registers
2958 that live during the function in different registers, because it is
2959 impossible to look in the passed register for the passed value,
2960 so we use the within-the-function register to begin with.
2962 PARMS is a chain of PARM_DECL nodes. */
2964 void
2965 dbxout_reg_parms (tree parms)
2967 ++debug_nesting;
2969 for (; parms; parms = TREE_CHAIN (parms))
2970 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2972 dbxout_prepare_symbol (parms);
2974 /* Report parms that live in registers during the function
2975 but were passed in memory. */
2976 if (GET_CODE (DECL_RTL (parms)) == REG
2977 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2978 dbxout_symbol_location (parms, TREE_TYPE (parms),
2979 0, DECL_RTL (parms));
2980 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2981 dbxout_symbol_location (parms, TREE_TYPE (parms),
2982 0, DECL_RTL (parms));
2983 /* Report parms that live in memory but not where they were passed. */
2984 else if (GET_CODE (DECL_RTL (parms)) == MEM
2985 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2986 dbxout_symbol_location (parms, TREE_TYPE (parms),
2987 0, DECL_RTL (parms));
2989 DBXOUT_DECR_NESTING;
2992 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2993 output definitions of those names, in raw form */
2995 static void
2996 dbxout_args (tree args)
2998 while (args)
3000 putc (',', asmfile);
3001 dbxout_type (TREE_VALUE (args), 0);
3002 CHARS (1);
3003 args = TREE_CHAIN (args);
3007 /* Output everything about a symbol block (a BLOCK node
3008 that represents a scope level),
3009 including recursive output of contained blocks.
3011 BLOCK is the BLOCK node.
3012 DEPTH is its depth within containing symbol blocks.
3013 ARGS is usually zero; but for the outermost block of the
3014 body of a function, it is a chain of PARM_DECLs for the function parameters.
3015 We output definitions of all the register parms
3016 as if they were local variables of that block.
3018 If -g1 was used, we count blocks just the same, but output nothing
3019 except for the outermost block.
3021 Actually, BLOCK may be several blocks chained together.
3022 We handle them all in sequence. */
3024 static void
3025 dbxout_block (tree block, int depth, tree args)
3027 int blocknum = -1;
3029 #if DBX_BLOCKS_FUNCTION_RELATIVE
3030 const char *begin_label;
3031 if (current_function_func_begin_label != NULL_TREE)
3032 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
3033 else
3034 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3035 #endif
3037 while (block)
3039 /* Ignore blocks never expanded or otherwise marked as real. */
3040 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3042 int did_output;
3044 /* In dbx format, the syms of a block come before the N_LBRAC.
3045 If nothing is output, we don't need the N_LBRAC, either. */
3046 did_output = 0;
3047 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3048 did_output = dbxout_syms (BLOCK_VARS (block));
3049 if (args)
3050 dbxout_reg_parms (args);
3052 /* Now output an N_LBRAC symbol to represent the beginning of
3053 the block. Use the block's tree-walk order to generate
3054 the assembler symbols LBBn and LBEn
3055 that final will define around the code in this block. */
3056 if (depth > 0 && did_output)
3058 char buf[20];
3059 blocknum = BLOCK_NUMBER (block);
3060 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3062 if (BLOCK_HANDLER_BLOCK (block))
3064 /* A catch block. Must precede N_LBRAC. */
3065 tree decl = BLOCK_VARS (block);
3066 while (decl)
3068 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
3069 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
3070 assemble_name (asmfile, buf);
3071 fprintf (asmfile, "\n");
3072 decl = TREE_CHAIN (decl);
3076 #ifdef DBX_OUTPUT_LBRAC
3077 DBX_OUTPUT_LBRAC (asmfile, buf);
3078 #else
3079 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
3080 assemble_name (asmfile, buf);
3081 #if DBX_BLOCKS_FUNCTION_RELATIVE
3082 putc ('-', asmfile);
3083 assemble_name (asmfile, begin_label);
3084 #endif
3085 fprintf (asmfile, "\n");
3086 #endif
3089 /* Output the subblocks. */
3090 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3092 /* Refer to the marker for the end of the block. */
3093 if (depth > 0 && did_output)
3095 char buf[20];
3096 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3097 #ifdef DBX_OUTPUT_RBRAC
3098 DBX_OUTPUT_RBRAC (asmfile, buf);
3099 #else
3100 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3101 assemble_name (asmfile, buf);
3102 #if DBX_BLOCKS_FUNCTION_RELATIVE
3103 putc ('-', asmfile);
3104 assemble_name (asmfile, begin_label);
3105 #endif
3106 fprintf (asmfile, "\n");
3107 #endif
3110 block = BLOCK_CHAIN (block);
3114 /* Output the information about a function and its arguments and result.
3115 Usually this follows the function's code,
3116 but on some systems, it comes before. */
3118 #if defined (DBX_DEBUGGING_INFO)
3119 static void
3120 dbxout_begin_function (tree decl)
3122 int saved_tree_used1 = TREE_USED (decl);
3123 TREE_USED (decl) = 1;
3124 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3126 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3127 TREE_USED (DECL_RESULT (decl)) = 1;
3128 dbxout_symbol (decl, 0);
3129 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3131 else
3132 dbxout_symbol (decl, 0);
3133 TREE_USED (decl) = saved_tree_used1;
3135 dbxout_parms (DECL_ARGUMENTS (decl));
3136 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3137 dbxout_symbol (DECL_RESULT (decl), 1);
3139 #endif /* DBX_DEBUGGING_INFO */
3141 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3143 #include "gt-dbxout.h"