re PR target/8343 ([m68k] [3.2 regression] m68k-elf/rtems ICE at instantiate_virtual_...
[official-gcc.git] / gcc / dbxout.c
blob5fcd28d8fc13c021585eaad77265ef450e5256a8
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 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 #ifndef ASM_STABS_OP
97 #define ASM_STABS_OP "\t.stabs\t"
98 #endif
100 #ifndef ASM_STABN_OP
101 #define ASM_STABN_OP "\t.stabn\t"
102 #endif
104 #ifndef DBX_TYPE_DECL_STABS_CODE
105 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
106 #endif
108 #ifndef DBX_STATIC_CONST_VAR_CODE
109 #define DBX_STATIC_CONST_VAR_CODE N_FUN
110 #endif
112 #ifndef DBX_REGPARM_STABS_CODE
113 #define DBX_REGPARM_STABS_CODE N_RSYM
114 #endif
116 #ifndef DBX_REGPARM_STABS_LETTER
117 #define DBX_REGPARM_STABS_LETTER 'P'
118 #endif
120 /* This is used for parameters passed by invisible reference in a register. */
121 #ifndef GDB_INV_REF_REGPARM_STABS_LETTER
122 #define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
123 #endif
125 #ifndef DBX_MEMPARM_STABS_LETTER
126 #define DBX_MEMPARM_STABS_LETTER 'p'
127 #endif
129 #ifndef FILE_NAME_JOINER
130 #define FILE_NAME_JOINER "/"
131 #endif
133 /* GDB needs to know that the stabs were generated by GCC. We emit an
134 N_OPT stab at the beginning of the source file to indicate this.
135 The string is historical, and different on a very few targets. */
136 #ifndef STABS_GCC_MARKER
137 #define STABS_GCC_MARKER "gcc2_compiled."
138 #endif
140 /* Typical USG systems don't have stab.h, and they also have
141 no use for DBX-format debugging info. */
143 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
145 /* Nonzero if we have actually used any of the GDB extensions
146 to the debugging format. The idea is that we use them for the
147 first time only if there's a strong reason, but once we have done that,
148 we use them whenever convenient. */
150 static int have_used_extensions = 0;
152 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
153 for the N_SO filename stabs label. */
155 #if defined (DBX_DEBUGGING_INFO) && !defined (DBX_OUTPUT_SOURCE_FILENAME)
156 static int source_label_number = 1;
157 #endif
159 #ifdef DEBUG_SYMS_TEXT
160 #define FORCE_TEXT function_section (current_function_decl);
161 #else
162 #define FORCE_TEXT
163 #endif
165 #include "gstab.h"
167 #define STAB_CODE_TYPE enum __stab_debug_code
169 /* 1 if PARM is passed to this function in memory. */
171 #define PARM_PASSED_IN_MEMORY(PARM) \
172 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
174 /* A C expression for the integer offset value of an automatic variable
175 (N_LSYM) having address X (an RTX). */
176 #ifndef DEBUGGER_AUTO_OFFSET
177 #define DEBUGGER_AUTO_OFFSET(X) \
178 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
179 #endif
181 /* A C expression for the integer offset value of an argument (N_PSYM)
182 having address X (an RTX). The nominal offset is OFFSET. */
183 #ifndef DEBUGGER_ARG_OFFSET
184 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
185 #endif
187 /* Stream for writing to assembler file. */
189 static FILE *asmfile;
191 /* Last source file name mentioned in a NOTE insn. */
193 static const char *lastfile;
195 /* Current working directory. */
197 static const char *cwd;
199 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
201 /* Structure recording information about a C data type.
202 The status element says whether we have yet output
203 the definition of the type. TYPE_XREF says we have
204 output it as a cross-reference only.
205 The file_number and type_number elements are used if DBX_USE_BINCL
206 is defined. */
208 struct typeinfo
210 enum typestatus status;
211 #ifdef DBX_USE_BINCL
212 int file_number;
213 int type_number;
214 #endif
217 /* Vector recording information about C data types.
218 When we first notice a data type (a tree node),
219 we assign it a number using next_type_number.
220 That is its index in this vector. */
222 struct typeinfo *typevec;
224 /* Number of elements of space allocated in `typevec'. */
226 static int typevec_len;
228 /* In dbx output, each type gets a unique number.
229 This is the number for the next type output.
230 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
232 static int next_type_number;
234 #ifdef DBX_USE_BINCL
236 /* When using N_BINCL in dbx output, each type number is actually a
237 pair of the file number and the type number within the file.
238 This is a stack of input files. */
240 struct dbx_file
242 struct dbx_file *next;
243 int file_number;
244 int next_type_number;
247 /* This is the top of the stack. */
249 static struct dbx_file *current_file;
251 /* This is the next file number to use. */
253 static int next_file_number;
255 #endif /* DBX_USE_BINCL */
257 /* These variables are for dbxout_symbol to communicate to
258 dbxout_finish_symbol.
259 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
260 current_sym_value and current_sym_addr are two ways to address the
261 value to store in the symtab entry.
262 current_sym_addr if nonzero represents the value as an rtx.
263 If that is zero, current_sym_value is used. This is used
264 when the value is an offset (such as for auto variables,
265 register variables and parms). */
267 static STAB_CODE_TYPE current_sym_code;
268 static int current_sym_value;
269 static rtx current_sym_addr;
271 /* Number of chars of symbol-description generated so far for the
272 current symbol. Used by CHARS and CONTIN. */
274 static int current_sym_nchars;
276 /* Report having output N chars of the current symbol-description. */
278 #define CHARS(N) (current_sym_nchars += (N))
280 /* Break the current symbol-description, generating a continuation,
281 if it has become long. */
283 #ifndef DBX_CONTIN_LENGTH
284 #define DBX_CONTIN_LENGTH 80
285 #endif
287 #if DBX_CONTIN_LENGTH > 0
288 #define CONTIN \
289 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
290 #else
291 #define CONTIN do { } while (0)
292 #endif
294 static void dbxout_init PARAMS ((const char *));
295 static void dbxout_finish PARAMS ((const char *));
296 static void dbxout_start_source_file PARAMS ((unsigned, const char *));
297 static void dbxout_end_source_file PARAMS ((unsigned));
298 static void dbxout_typedefs PARAMS ((tree));
299 static void dbxout_fptype_value PARAMS ((tree));
300 static void dbxout_type_index PARAMS ((tree));
301 #if DBX_CONTIN_LENGTH > 0
302 static void dbxout_continue PARAMS ((void));
303 #endif
304 static void dbxout_args PARAMS ((tree));
305 static void dbxout_type_fields PARAMS ((tree));
306 static void dbxout_type_method_1 PARAMS ((tree, const char *));
307 static void dbxout_type_methods PARAMS ((tree));
308 static void dbxout_range_type PARAMS ((tree));
309 static void dbxout_type PARAMS ((tree, int));
310 static void print_int_cst_octal PARAMS ((tree));
311 static void print_octal PARAMS ((unsigned HOST_WIDE_INT, int));
312 static void print_wide_int PARAMS ((HOST_WIDE_INT));
313 static void dbxout_type_name PARAMS ((tree));
314 static void dbxout_class_name_qualifiers PARAMS ((tree));
315 static int dbxout_symbol_location PARAMS ((tree, tree, const char *, rtx));
316 static void dbxout_symbol_name PARAMS ((tree, const char *, int));
317 static void dbxout_prepare_symbol PARAMS ((tree));
318 static void dbxout_finish_symbol PARAMS ((tree));
319 static void dbxout_block PARAMS ((tree, int, tree));
320 static void dbxout_global_decl PARAMS ((tree));
322 /* The debug hooks structure. */
323 #if defined (DBX_DEBUGGING_INFO)
325 static void dbxout_source_line PARAMS ((unsigned int, const char *));
326 static void dbxout_source_file PARAMS ((FILE *, const char *));
327 static void dbxout_function_end PARAMS ((void));
328 static void dbxout_begin_function PARAMS ((tree));
329 static void dbxout_begin_block PARAMS ((unsigned, unsigned));
330 static void dbxout_end_block PARAMS ((unsigned, unsigned));
331 static void dbxout_function_decl PARAMS ((tree));
333 const struct gcc_debug_hooks dbx_debug_hooks =
335 dbxout_init,
336 dbxout_finish,
337 debug_nothing_int_charstar,
338 debug_nothing_int_charstar,
339 dbxout_start_source_file,
340 dbxout_end_source_file,
341 dbxout_begin_block,
342 dbxout_end_block,
343 debug_true_tree, /* ignore_block */
344 dbxout_source_line, /* source_line */
345 dbxout_source_line, /* begin_prologue: just output line info */
346 debug_nothing_int_charstar, /* end_prologue */
347 debug_nothing_int_charstar, /* end_epilogue */
348 #ifdef DBX_FUNCTION_FIRST
349 dbxout_begin_function,
350 #else
351 debug_nothing_tree, /* begin_function */
352 #endif
353 debug_nothing_int, /* end_function */
354 dbxout_function_decl,
355 dbxout_global_decl, /* global_decl */
356 debug_nothing_tree, /* deferred_inline_function */
357 debug_nothing_tree, /* outlining_inline_function */
358 debug_nothing_rtx /* label */
360 #endif /* DBX_DEBUGGING_INFO */
362 #if defined (XCOFF_DEBUGGING_INFO)
363 const struct gcc_debug_hooks xcoff_debug_hooks =
365 dbxout_init,
366 dbxout_finish,
367 debug_nothing_int_charstar,
368 debug_nothing_int_charstar,
369 dbxout_start_source_file,
370 dbxout_end_source_file,
371 xcoffout_begin_block,
372 xcoffout_end_block,
373 debug_true_tree, /* ignore_block */
374 xcoffout_source_line,
375 xcoffout_begin_prologue, /* begin_prologue */
376 debug_nothing_int_charstar, /* end_prologue */
377 xcoffout_end_epilogue,
378 debug_nothing_tree, /* begin_function */
379 xcoffout_end_function,
380 debug_nothing_tree, /* function_decl */
381 dbxout_global_decl, /* global_decl */
382 debug_nothing_tree, /* deferred_inline_function */
383 debug_nothing_tree, /* outlining_inline_function */
384 debug_nothing_rtx /* label */
386 #endif /* XCOFF_DEBUGGING_INFO */
388 #if defined (DBX_DEBUGGING_INFO)
389 static void
390 dbxout_function_end ()
392 static int scope_labelno = 0;
393 char lscope_label_name[100];
394 /* Convert Ltext into the appropriate format for local labels in case
395 the system doesn't insert underscores in front of user generated
396 labels. */
397 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
398 (*targetm.asm_out.internal_label) (asmfile, "Lscope", scope_labelno);
399 scope_labelno++;
401 /* By convention, GCC will mark the end of a function with an N_FUN
402 symbol and an empty string. */
403 #ifdef DBX_OUTPUT_NFUN
404 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
405 #else
406 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
407 assemble_name (asmfile, lscope_label_name);
408 putc ('-', asmfile);
409 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
410 fprintf (asmfile, "\n");
411 #endif
413 #endif /* DBX_DEBUGGING_INFO */
415 /* At the beginning of compilation, start writing the symbol table.
416 Initialize `typevec' and output the standard data types of C. */
418 static void
419 dbxout_init (input_file_name)
420 const char *input_file_name;
422 char ltext_label_name[100];
423 tree syms = (*lang_hooks.decls.getdecls) ();
425 asmfile = asm_out_file;
427 typevec_len = 100;
428 typevec = (struct typeinfo *) xcalloc (typevec_len, sizeof typevec[0]);
430 /* Convert Ltext into the appropriate format for local labels in case
431 the system doesn't insert underscores in front of user generated
432 labels. */
433 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
435 /* Put the current working directory in an N_SO symbol. */
436 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
437 but GDB always does. */
438 if (use_gnu_debug_info_extensions)
439 #endif
441 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
442 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
443 if (cwd)
445 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
446 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
447 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
448 fprintf (asmfile, "%s", ASM_STABS_OP);
449 output_quoted_string (asmfile, cwd);
450 fprintf (asmfile, ",%d,0,0,", N_SO);
451 assemble_name (asmfile, ltext_label_name);
452 fputc ('\n', asmfile);
453 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
457 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
458 /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
459 would give us an N_SOL, and we want an N_SO. */
460 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
461 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
462 /* We include outputting `Ltext:' here,
463 because that gives you a way to override it. */
464 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
465 fprintf (asmfile, "%s", ASM_STABS_OP);
466 output_quoted_string (asmfile, input_file_name);
467 fprintf (asmfile, ",%d,0,0,", N_SO);
468 assemble_name (asmfile, ltext_label_name);
469 fputc ('\n', asmfile);
470 text_section ();
471 (*targetm.asm_out.internal_label) (asmfile, "Ltext", 0);
472 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
474 #ifdef DBX_OUTPUT_GCC_MARKER
475 DBX_OUTPUT_GCC_MARKER (asmfile);
476 #else
477 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
478 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
479 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
480 #endif
482 lastfile = input_file_name;
484 next_type_number = 1;
486 #ifdef DBX_USE_BINCL
487 current_file = (struct dbx_file *) xmalloc (sizeof *current_file);
488 current_file->next = NULL;
489 current_file->file_number = 0;
490 current_file->next_type_number = 1;
491 next_file_number = 1;
492 #endif
494 /* Make sure that types `int' and `char' have numbers 1 and 2.
495 Definitions of other integer types will refer to those numbers.
496 (Actually it should no longer matter what their numbers are.
497 Also, if any types with tags have been defined, dbxout_symbol
498 will output them first, so the numbers won't be 1 and 2. That
499 happens in C++. So it's a good thing it should no longer matter). */
501 #ifdef DBX_OUTPUT_STANDARD_TYPES
502 DBX_OUTPUT_STANDARD_TYPES (syms);
503 #else
504 dbxout_symbol (TYPE_NAME (integer_type_node), 0);
505 dbxout_symbol (TYPE_NAME (char_type_node), 0);
506 #endif
508 /* Get all permanent types that have typedef names,
509 and output them all, except for those already output. */
511 dbxout_typedefs (syms);
514 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
515 in the reverse order from that which is found in SYMS. */
517 static void
518 dbxout_typedefs (syms)
519 tree syms;
521 if (syms)
523 dbxout_typedefs (TREE_CHAIN (syms));
524 if (TREE_CODE (syms) == TYPE_DECL)
526 tree type = TREE_TYPE (syms);
527 if (TYPE_NAME (type)
528 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
529 && COMPLETE_TYPE_P (type)
530 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
531 dbxout_symbol (TYPE_NAME (type), 0);
536 /* Change to reading from a new source file. Generate a N_BINCL stab. */
538 static void
539 dbxout_start_source_file (line, filename)
540 unsigned int line ATTRIBUTE_UNUSED;
541 const char *filename ATTRIBUTE_UNUSED;
543 #ifdef DBX_USE_BINCL
544 struct dbx_file *n = (struct dbx_file *) xmalloc (sizeof *n);
546 n->next = current_file;
547 n->file_number = next_file_number++;
548 n->next_type_number = 1;
549 current_file = n;
550 fprintf (asmfile, "%s", ASM_STABS_OP);
551 output_quoted_string (asmfile, filename);
552 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
553 #endif
556 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
558 static void
559 dbxout_end_source_file (line)
560 unsigned int line ATTRIBUTE_UNUSED;
562 #ifdef DBX_USE_BINCL
563 struct dbx_file *next;
565 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
566 next = current_file->next;
567 free (current_file);
568 current_file = next;
569 #endif
572 #if defined (DBX_DEBUGGING_INFO)
573 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
575 static void
576 dbxout_source_file (file, filename)
577 FILE *file;
578 const char *filename;
580 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
582 #ifdef DBX_OUTPUT_SOURCE_FILENAME
583 DBX_OUTPUT_SOURCE_FILENAME (file, filename);
584 #else
585 char ltext_label_name[100];
587 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
588 source_label_number);
589 fprintf (file, "%s", ASM_STABS_OP);
590 output_quoted_string (file, filename);
591 fprintf (asmfile, ",%d,0,0,", N_SOL);
592 assemble_name (asmfile, ltext_label_name);
593 fputc ('\n', asmfile);
594 if (current_function_decl != NULL_TREE
595 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
596 ; /* Don't change section amid function. */
597 else
598 text_section ();
599 (*targetm.asm_out.internal_label) (file, "Ltext", source_label_number);
600 source_label_number++;
601 #endif
602 lastfile = filename;
606 /* Output a line number symbol entry for source file FILENAME and line
607 number LINENO. */
609 static void
610 dbxout_source_line (lineno, filename)
611 unsigned int lineno;
612 const char *filename;
614 dbxout_source_file (asmfile, filename);
616 #ifdef ASM_OUTPUT_SOURCE_LINE
617 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno);
618 #else
619 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
620 #endif
623 /* Describe the beginning of an internal block within a function. */
625 static void
626 dbxout_begin_block (line, n)
627 unsigned int line ATTRIBUTE_UNUSED;
628 unsigned int n;
630 (*targetm.asm_out.internal_label) (asmfile, "LBB", n);
633 /* Describe the end line-number of an internal block within a function. */
635 static void
636 dbxout_end_block (line, n)
637 unsigned int line ATTRIBUTE_UNUSED;
638 unsigned int n;
640 (*targetm.asm_out.internal_label) (asmfile, "LBE", n);
643 /* Output dbx data for a function definition.
644 This includes a definition of the function name itself (a symbol),
645 definitions of the parameters (locating them in the parameter list)
646 and then output the block that makes up the function's body
647 (including all the auto variables of the function). */
649 static void
650 dbxout_function_decl (decl)
651 tree decl;
653 #ifndef DBX_FUNCTION_FIRST
654 dbxout_begin_function (decl);
655 #endif
656 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
657 #ifdef DBX_OUTPUT_FUNCTION_END
658 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
659 #endif
660 if (use_gnu_debug_info_extensions
661 #if defined(NO_DBX_FUNCTION_END)
662 && ! NO_DBX_FUNCTION_END
663 #endif
664 && targetm.have_named_sections)
665 dbxout_function_end ();
668 #endif /* DBX_DEBUGGING_INFO */
670 /* Debug information for a global DECL. Called from toplev.c after
671 compilation proper has finished. */
672 static void
673 dbxout_global_decl (decl)
674 tree decl;
676 if (TREE_CODE (decl) == VAR_DECL
677 && ! DECL_EXTERNAL (decl)
678 && DECL_RTL_SET_P (decl)) /* Not necessary? */
679 dbxout_symbol (decl, 0);
682 /* At the end of compilation, finish writing the symbol table.
683 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
684 to do nothing. */
686 static void
687 dbxout_finish (filename)
688 const char *filename ATTRIBUTE_UNUSED;
690 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
691 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
692 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
695 /* Output floating point type values used by the 'R' stab letter.
696 These numbers come from include/aout/stab_gnu.h in binutils/gdb.
698 There are only 3 real/complex types defined, and we need 7/6.
699 We use NF_SINGLE as a generic float type, and NF_COMPLEX as a generic
700 complex type. Since we have the type size anyways, we don't really need
701 to distinguish between different FP types, we only need to distinguish
702 between float and complex. This works fine with gdb.
704 We only use this for complex types, to avoid breaking backwards
705 compatibility for real types. complex types aren't in ISO C90, so it is
706 OK if old debuggers don't understand the debug info we emit for them. */
708 /* ??? These are supposed to be IEEE types, but we don't check for that.
709 We could perhaps add additional numbers for non-IEEE types if we need
710 them. */
712 static void
713 dbxout_fptype_value (type)
714 tree type;
716 char value = '0';
717 enum machine_mode mode = TYPE_MODE (type);
719 if (TREE_CODE (type) == REAL_TYPE)
721 if (mode == SFmode)
722 value = '1';
723 else if (mode == DFmode)
724 value = '2';
725 else if (mode == TFmode || mode == XFmode)
726 value = '6';
727 else
728 /* Use NF_SINGLE as a generic real type for other sizes. */
729 value = '1';
731 else if (TREE_CODE (type) == COMPLEX_TYPE)
733 if (mode == SCmode)
734 value = '3';
735 else if (mode == DCmode)
736 value = '4';
737 else if (mode == TCmode || mode == XCmode)
738 value = '5';
739 else
740 /* Use NF_COMPLEX as a generic complex type for other sizes. */
741 value = '3';
743 else
744 abort ();
746 putc (value, asmfile);
747 CHARS (1);
750 /* Output the index of a type. */
752 static void
753 dbxout_type_index (type)
754 tree type;
756 #ifndef DBX_USE_BINCL
757 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
758 CHARS (3);
759 #else
760 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
761 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
762 CHARS (9);
763 #endif
766 #if DBX_CONTIN_LENGTH > 0
767 /* Continue a symbol-description that gets too big.
768 End one symbol table entry with a double-backslash
769 and start a new one, eventually producing something like
770 .stabs "start......\\",code,0,value
771 .stabs "...rest",code,0,value */
773 static void
774 dbxout_continue ()
776 #ifdef DBX_CONTIN_CHAR
777 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
778 #else
779 fprintf (asmfile, "\\\\");
780 #endif
781 dbxout_finish_symbol (NULL_TREE);
782 fprintf (asmfile, "%s\"", ASM_STABS_OP);
783 current_sym_nchars = 0;
785 #endif /* DBX_CONTIN_LENGTH > 0 */
787 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
788 This must be a separate function because anonymous unions require
789 recursive calls. */
791 static void
792 dbxout_type_fields (type)
793 tree type;
795 tree tem;
797 /* Output the name, type, position (in bits), size (in bits) of each
798 field that we can support. */
799 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
801 /* Omit here local type decls until we know how to support them. */
802 if (TREE_CODE (tem) == TYPE_DECL
803 /* Omit fields whose position or size are variable or too large to
804 represent. */
805 || (TREE_CODE (tem) == FIELD_DECL
806 && (! host_integerp (bit_position (tem), 0)
807 || ! DECL_SIZE (tem)
808 || ! host_integerp (DECL_SIZE (tem), 1)))
809 /* Omit here the nameless fields that are used to skip bits. */
810 || DECL_IGNORED_P (tem))
811 continue;
813 else if (TREE_CODE (tem) != CONST_DECL)
815 /* Continue the line if necessary,
816 but not before the first field. */
817 if (tem != TYPE_FIELDS (type))
818 CONTIN;
820 if (DECL_NAME (tem))
822 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
823 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
825 else
827 fprintf (asmfile, ":");
828 CHARS (1);
831 if (use_gnu_debug_info_extensions
832 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
833 || TREE_CODE (tem) != FIELD_DECL))
835 have_used_extensions = 1;
836 putc ('/', asmfile);
837 putc ((TREE_PRIVATE (tem) ? '0'
838 : TREE_PROTECTED (tem) ? '1' : '2'),
839 asmfile);
840 CHARS (2);
843 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
844 && DECL_BIT_FIELD_TYPE (tem))
845 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
847 if (TREE_CODE (tem) == VAR_DECL)
849 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
851 tree name = DECL_ASSEMBLER_NAME (tem);
853 have_used_extensions = 1;
854 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
855 CHARS (IDENTIFIER_LENGTH (name) + 2);
857 else
859 /* If TEM is non-static, GDB won't understand it. */
860 fprintf (asmfile, ",0,0;");
861 CHARS (5);
864 else
866 putc (',', asmfile);
867 print_wide_int (int_bit_position (tem));
868 putc (',', asmfile);
869 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
870 putc (';', asmfile);
871 CHARS (3);
877 /* Subroutine of `dbxout_type_methods'. Output debug info about the
878 method described DECL. DEBUG_NAME is an encoding of the method's
879 type signature. ??? We may be able to do without DEBUG_NAME altogether
880 now. */
882 static void
883 dbxout_type_method_1 (decl, debug_name)
884 tree decl;
885 const char *debug_name;
887 char c1 = 'A', c2;
889 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
890 c2 = '?';
891 else /* it's a METHOD_TYPE. */
893 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
894 /* A for normal functions.
895 B for `const' member functions.
896 C for `volatile' member functions.
897 D for `const volatile' member functions. */
898 if (TYPE_READONLY (TREE_TYPE (firstarg)))
899 c1 += 1;
900 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
901 c1 += 2;
903 if (DECL_VINDEX (decl))
904 c2 = '*';
905 else
906 c2 = '.';
909 fprintf (asmfile, ":%s;%c%c%c", debug_name,
910 TREE_PRIVATE (decl) ? '0'
911 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
912 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
913 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
915 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
917 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
918 putc (';', asmfile);
919 CHARS (1);
920 dbxout_type (DECL_CONTEXT (decl), 0);
921 fprintf (asmfile, ";");
922 CHARS (1);
926 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
927 in TYPE. */
929 static void
930 dbxout_type_methods (type)
931 tree type;
933 /* C++: put out the method names and their parameter lists */
934 tree methods = TYPE_METHODS (type);
935 tree type_encoding;
936 tree fndecl;
937 tree last;
938 char formatted_type_identifier_length[16];
939 int type_identifier_length;
941 if (methods == NULL_TREE)
942 return;
944 type_encoding = DECL_NAME (TYPE_NAME (type));
946 #if 0
947 /* C++: Template classes break some assumptions made by this code about
948 the class names, constructor names, and encodings for assembler
949 label names. For now, disable output of dbx info for them. */
951 const char *ptr = IDENTIFIER_POINTER (type_encoding);
952 /* This should use index. (mrs) */
953 while (*ptr && *ptr != '<') ptr++;
954 if (*ptr != 0)
956 static int warned;
957 if (!warned)
958 warned = 1;
959 return;
962 #endif
964 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
966 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
968 if (TREE_CODE (methods) != TREE_VEC)
969 fndecl = methods;
970 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
971 fndecl = TREE_VEC_ELT (methods, 0);
972 else
973 fndecl = TREE_VEC_ELT (methods, 1);
975 while (fndecl)
977 int need_prefix = 1;
979 /* Group together all the methods for the same operation.
980 These differ in the types of the arguments. */
981 for (last = NULL_TREE;
982 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
983 fndecl = TREE_CHAIN (fndecl))
984 /* Output the name of the field (after overloading), as
985 well as the name of the field before overloading, along
986 with its parameter list */
988 /* This is the "mangled" name of the method.
989 It encodes the argument types. */
990 const char *debug_name;
992 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
993 include TEMPLATE_DECLs.) The debugger doesn't know what
994 to do with such entities anyhow. */
995 if (TREE_CODE (fndecl) != FUNCTION_DECL)
996 continue;
998 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1000 CONTIN;
1002 last = fndecl;
1004 /* Also ignore abstract methods; those are only interesting to
1005 the DWARF backends. */
1006 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1007 continue;
1009 /* Redundantly output the plain name, since that's what gdb
1010 expects. */
1011 if (need_prefix)
1013 tree name = DECL_NAME (fndecl);
1014 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1015 CHARS (IDENTIFIER_LENGTH (name) + 2);
1016 need_prefix = 0;
1019 dbxout_type (TREE_TYPE (fndecl), 0);
1021 dbxout_type_method_1 (fndecl, debug_name);
1023 if (!need_prefix)
1025 putc (';', asmfile);
1026 CHARS (1);
1031 /* Emit a "range" type specification, which has the form:
1032 "r<index type>;<lower bound>;<upper bound>;".
1033 TYPE is an INTEGER_TYPE. */
1035 static void
1036 dbxout_range_type (type)
1037 tree type;
1039 fprintf (asmfile, "r");
1040 if (TREE_TYPE (type))
1041 dbxout_type (TREE_TYPE (type), 0);
1042 else if (TREE_CODE (type) != INTEGER_TYPE)
1043 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1044 else
1046 /* Traditionally, we made sure 'int' was type 1, and builtin types
1047 were defined to be sub-ranges of int. Unfortunately, this
1048 does not allow us to distinguish true sub-ranges from integer
1049 types. So, instead we define integer (non-sub-range) types as
1050 sub-ranges of themselves. This matters for Chill. If this isn't
1051 a subrange type, then we want to define it in terms of itself.
1052 However, in C, this may be an anonymous integer type, and we don't
1053 want to emit debug info referring to it. Just calling
1054 dbxout_type_index won't work anyways, because the type hasn't been
1055 defined yet. We make this work for both cases by checked to see
1056 whether this is a defined type, referring to it if it is, and using
1057 'int' otherwise. */
1058 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1059 dbxout_type_index (type);
1060 else
1061 dbxout_type_index (integer_type_node);
1064 if (TYPE_MIN_VALUE (type) != 0
1065 && host_integerp (TYPE_MIN_VALUE (type), 0))
1067 putc (';', asmfile);
1068 CHARS (1);
1069 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1071 else
1073 fprintf (asmfile, ";0");
1074 CHARS (2);
1077 if (TYPE_MAX_VALUE (type) != 0
1078 && host_integerp (TYPE_MAX_VALUE (type), 0))
1080 putc (';', asmfile);
1081 CHARS (1);
1082 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1083 putc (';', asmfile);
1084 CHARS (1);
1086 else
1088 fprintf (asmfile, ";-1;");
1089 CHARS (4);
1093 /* Output a reference to a type. If the type has not yet been
1094 described in the dbx output, output its definition now.
1095 For a type already defined, just refer to its definition
1096 using the type number.
1098 If FULL is nonzero, and the type has been described only with
1099 a forward-reference, output the definition now.
1100 If FULL is zero in this case, just refer to the forward-reference
1101 using the number previously allocated. */
1103 static void
1104 dbxout_type (type, full)
1105 tree type;
1106 int full;
1108 tree tem;
1109 tree main_variant;
1110 static int anonymous_type_number = 0;
1112 if (TREE_CODE (type) == VECTOR_TYPE)
1113 /* The frontend feeds us a representation for the vector as a struct
1114 containing an array. Pull out the array type. */
1115 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1117 /* If there was an input error and we don't really have a type,
1118 avoid crashing and write something that is at least valid
1119 by assuming `int'. */
1120 if (type == error_mark_node)
1121 type = integer_type_node;
1122 else
1124 if (TYPE_NAME (type)
1125 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1126 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1127 full = 0;
1130 /* Try to find the "main variant" with the same name. */
1131 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1132 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1133 main_variant = TREE_TYPE (TYPE_NAME (type));
1134 else
1135 main_variant = TYPE_MAIN_VARIANT (type);
1137 /* If we are not using extensions, stabs does not distinguish const and
1138 volatile, so there is no need to make them separate types. */
1139 if (!use_gnu_debug_info_extensions)
1140 type = main_variant;
1142 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1144 /* Type has no dbx number assigned. Assign next available number. */
1145 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1147 /* Make sure type vector is long enough to record about this type. */
1149 if (next_type_number == typevec_len)
1151 typevec
1152 = (struct typeinfo *) xrealloc (typevec,
1153 typevec_len * 2 * sizeof typevec[0]);
1154 memset ((char *) (typevec + typevec_len), 0,
1155 typevec_len * sizeof typevec[0]);
1156 typevec_len *= 2;
1159 #ifdef DBX_USE_BINCL
1160 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1161 = current_file->file_number;
1162 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1163 = current_file->next_type_number++;
1164 #endif
1167 /* Output the number of this type, to refer to it. */
1168 dbxout_type_index (type);
1170 #ifdef DBX_TYPE_DEFINED
1171 if (DBX_TYPE_DEFINED (type))
1172 return;
1173 #endif
1175 /* If this type's definition has been output or is now being output,
1176 that is all. */
1178 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1180 case TYPE_UNSEEN:
1181 break;
1182 case TYPE_XREF:
1183 /* If we have already had a cross reference,
1184 and either that's all we want or that's the best we could do,
1185 don't repeat the cross reference.
1186 Sun dbx crashes if we do. */
1187 if (! full || !COMPLETE_TYPE_P (type)
1188 /* No way in DBX fmt to describe a variable size. */
1189 || ! host_integerp (TYPE_SIZE (type), 1))
1190 return;
1191 break;
1192 case TYPE_DEFINED:
1193 return;
1196 #ifdef DBX_NO_XREFS
1197 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1198 leave the type-number completely undefined rather than output
1199 a cross-reference. If we have already used GNU debug info extensions,
1200 then it is OK to output a cross reference. This is necessary to get
1201 proper C++ debug output. */
1202 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1203 || TREE_CODE (type) == QUAL_UNION_TYPE
1204 || TREE_CODE (type) == ENUMERAL_TYPE)
1205 && ! use_gnu_debug_info_extensions)
1206 /* We must use the same test here as we use twice below when deciding
1207 whether to emit a cross-reference. */
1208 if ((TYPE_NAME (type) != 0
1209 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1210 && DECL_IGNORED_P (TYPE_NAME (type)))
1211 && !full)
1212 || !COMPLETE_TYPE_P (type)
1213 /* No way in DBX fmt to describe a variable size. */
1214 || ! host_integerp (TYPE_SIZE (type), 1))
1216 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1217 return;
1219 #endif
1221 /* Output a definition now. */
1223 fprintf (asmfile, "=");
1224 CHARS (1);
1226 /* Mark it as defined, so that if it is self-referent
1227 we will not get into an infinite recursion of definitions. */
1229 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1231 /* If this type is a variant of some other, hand off. Types with
1232 different names are usefully distinguished. We only distinguish
1233 cv-qualified types if we're using extensions. */
1234 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1236 putc ('k', asmfile);
1237 CHARS (1);
1238 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1239 return;
1241 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1243 putc ('B', asmfile);
1244 CHARS (1);
1245 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1246 return;
1248 else if (main_variant != TYPE_MAIN_VARIANT (type))
1250 /* 'type' is a typedef; output the type it refers to. */
1251 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1252 return;
1254 /* else continue. */
1256 switch (TREE_CODE (type))
1258 case VOID_TYPE:
1259 case LANG_TYPE:
1260 /* For a void type, just define it as itself; ie, "5=5".
1261 This makes us consider it defined
1262 without saying what it is. The debugger will make it
1263 a void type when the reference is seen, and nothing will
1264 ever override that default. */
1265 dbxout_type_index (type);
1266 break;
1268 case INTEGER_TYPE:
1269 if (type == char_type_node && ! TREE_UNSIGNED (type))
1271 /* Output the type `char' as a subrange of itself!
1272 I don't understand this definition, just copied it
1273 from the output of pcc.
1274 This used to use `r2' explicitly and we used to
1275 take care to make sure that `char' was type number 2. */
1276 fprintf (asmfile, "r");
1277 CHARS (1);
1278 dbxout_type_index (type);
1279 fprintf (asmfile, ";0;127;");
1280 CHARS (7);
1283 /* If this is a subtype of another integer type, always prefer to
1284 write it as a subtype. */
1285 else if (TREE_TYPE (type) != 0
1286 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1288 /* If the size is non-standard, say what it is if we can use
1289 GDB extensions. */
1291 if (use_gnu_debug_info_extensions
1292 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1294 have_used_extensions = 1;
1295 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1296 CHARS (5);
1299 dbxout_range_type (type);
1302 else
1304 /* If the size is non-standard, say what it is if we can use
1305 GDB extensions. */
1307 if (use_gnu_debug_info_extensions
1308 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1310 have_used_extensions = 1;
1311 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1312 CHARS (5);
1315 /* If we can use GDB extensions and the size is wider than a
1316 long (the size used by GDB to read them) or we may have
1317 trouble writing the bounds the usual way, write them in
1318 octal. Note the test is for the *target's* size of "long",
1319 not that of the host. The host test is just to make sure we
1320 can write it out in case the host wide int is narrower than the
1321 target "long". */
1323 /* For unsigned types, we use octal if they are the same size or
1324 larger. This is because we print the bounds as signed decimal,
1325 and hence they can't span same size unsigned types. */
1327 if (use_gnu_debug_info_extensions
1328 && TYPE_MIN_VALUE (type) != 0
1329 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1330 && TYPE_MAX_VALUE (type) != 0
1331 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1332 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1333 || ((TYPE_PRECISION (type)
1334 == TYPE_PRECISION (integer_type_node))
1335 && TREE_UNSIGNED (type))
1336 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1337 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1338 && TREE_UNSIGNED (type))))
1340 fprintf (asmfile, "r");
1341 CHARS (1);
1342 dbxout_type_index (type);
1343 fprintf (asmfile, ";");
1344 CHARS (1);
1345 print_int_cst_octal (TYPE_MIN_VALUE (type));
1346 fprintf (asmfile, ";");
1347 CHARS (1);
1348 print_int_cst_octal (TYPE_MAX_VALUE (type));
1349 fprintf (asmfile, ";");
1350 CHARS (1);
1353 else
1354 /* Output other integer types as subranges of `int'. */
1355 dbxout_range_type (type);
1358 break;
1360 case REAL_TYPE:
1361 /* This used to say `r1' and we used to take care
1362 to make sure that `int' was type number 1. */
1363 fprintf (asmfile, "r");
1364 CHARS (1);
1365 dbxout_type_index (integer_type_node);
1366 putc (';', asmfile);
1367 CHARS (1);
1368 print_wide_int (int_size_in_bytes (type));
1369 fputs (";0;", asmfile);
1370 CHARS (3);
1371 break;
1373 case CHAR_TYPE:
1374 if (use_gnu_debug_info_extensions)
1376 have_used_extensions = 1;
1377 fputs ("@s", asmfile);
1378 CHARS (2);
1379 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1380 fputs (";-20;", asmfile);
1381 CHARS (4);
1383 else
1385 /* Output the type `char' as a subrange of itself.
1386 That is what pcc seems to do. */
1387 fprintf (asmfile, "r");
1388 CHARS (1);
1389 dbxout_type_index (char_type_node);
1390 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1391 CHARS (7);
1393 break;
1395 case BOOLEAN_TYPE:
1396 if (use_gnu_debug_info_extensions)
1398 have_used_extensions = 1;
1399 fputs ("@s", asmfile);
1400 CHARS (2);
1401 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1402 fputs (";-16;", asmfile);
1403 CHARS (4);
1405 else /* Define as enumeral type (False, True) */
1407 fprintf (asmfile, "eFalse:0,True:1,;");
1408 CHARS (17);
1410 break;
1412 case FILE_TYPE:
1413 putc ('d', asmfile);
1414 CHARS (1);
1415 dbxout_type (TREE_TYPE (type), 0);
1416 break;
1418 case COMPLEX_TYPE:
1419 /* Differs from the REAL_TYPE by its new data type number */
1421 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1423 putc ('R', asmfile);
1424 CHARS (1);
1425 dbxout_fptype_value (type);
1426 putc (';', asmfile);
1427 CHARS (1);
1428 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1429 fputs (";0;", asmfile);
1430 CHARS (3);
1432 else
1434 /* Output a complex integer type as a structure,
1435 pending some other way to do it. */
1436 putc ('s', asmfile);
1437 CHARS (1);
1438 print_wide_int (int_size_in_bytes (type));
1439 fprintf (asmfile, "real:");
1440 CHARS (5);
1442 dbxout_type (TREE_TYPE (type), 0);
1443 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1444 CHARS (7);
1445 fprintf (asmfile, "imag:");
1446 CHARS (5);
1447 dbxout_type (TREE_TYPE (type), 0);
1448 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1449 TYPE_PRECISION (TREE_TYPE (type)));
1450 CHARS (10);
1452 break;
1454 case SET_TYPE:
1455 if (use_gnu_debug_info_extensions)
1457 have_used_extensions = 1;
1458 fputs ("@s", asmfile);
1459 CHARS (2);
1460 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1461 putc (';', asmfile);
1462 CHARS (1);
1464 /* Check if a bitstring type, which in Chill is
1465 different from a [power]set. */
1466 if (TYPE_STRING_FLAG (type))
1468 fprintf (asmfile, "@S;");
1469 CHARS (3);
1472 putc ('S', asmfile);
1473 CHARS (1);
1474 dbxout_type (TYPE_DOMAIN (type), 0);
1475 break;
1477 case ARRAY_TYPE:
1478 /* Make arrays of packed bits look like bitstrings for chill. */
1479 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1481 have_used_extensions = 1;
1482 fputs ("@s", asmfile);
1483 CHARS (2);
1484 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1485 fprintf (asmfile, ";@S;S");
1486 CHARS (5);
1487 dbxout_type (TYPE_DOMAIN (type), 0);
1488 break;
1491 /* Output "a" followed by a range type definition
1492 for the index type of the array
1493 followed by a reference to the target-type.
1494 ar1;0;N;M for a C array of type M and size N+1. */
1495 /* Check if a character string type, which in Chill is
1496 different from an array of characters. */
1497 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1499 have_used_extensions = 1;
1500 fprintf (asmfile, "@S;");
1501 CHARS (3);
1503 tem = TYPE_DOMAIN (type);
1504 if (tem == NULL)
1506 fprintf (asmfile, "ar");
1507 CHARS (2);
1508 dbxout_type_index (integer_type_node);
1509 fprintf (asmfile, ";0;-1;");
1510 CHARS (6);
1512 else
1514 fprintf (asmfile, "a");
1515 CHARS (1);
1516 dbxout_range_type (tem);
1519 dbxout_type (TREE_TYPE (type), 0);
1520 break;
1522 case RECORD_TYPE:
1523 case UNION_TYPE:
1524 case QUAL_UNION_TYPE:
1526 int i, n_baseclasses = 0;
1528 if (TYPE_BINFO (type) != 0
1529 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1530 && TYPE_BINFO_BASETYPES (type) != 0)
1531 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1533 /* Output a structure type. We must use the same test here as we
1534 use in the DBX_NO_XREFS case above. */
1535 if ((TYPE_NAME (type) != 0
1536 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1537 && DECL_IGNORED_P (TYPE_NAME (type)))
1538 && !full)
1539 || !COMPLETE_TYPE_P (type)
1540 /* No way in DBX fmt to describe a variable size. */
1541 || ! host_integerp (TYPE_SIZE (type), 1))
1543 /* If the type is just a cross reference, output one
1544 and mark the type as partially described.
1545 If it later becomes defined, we will output
1546 its real definition.
1547 If the type has a name, don't nest its definition within
1548 another type's definition; instead, output an xref
1549 and let the definition come when the name is defined. */
1550 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1551 CHARS (2);
1552 #if 0 /* This assertion is legitimately false in C++. */
1553 /* We shouldn't be outputting a reference to a type before its
1554 definition unless the type has a tag name.
1555 A typedef name without a tag name should be impossible. */
1556 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1557 abort ();
1558 #endif
1559 if (TYPE_NAME (type) != 0)
1560 dbxout_type_name (type);
1561 else
1563 fprintf (asmfile, "$$%d", anonymous_type_number++);
1564 CHARS (5);
1567 fprintf (asmfile, ":");
1568 CHARS (1);
1569 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1570 break;
1573 /* Identify record or union, and print its size. */
1574 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1575 CHARS (1);
1576 print_wide_int (int_size_in_bytes (type));
1578 if (use_gnu_debug_info_extensions)
1580 if (n_baseclasses)
1582 have_used_extensions = 1;
1583 fprintf (asmfile, "!%d,", n_baseclasses);
1584 CHARS (8);
1587 for (i = 0; i < n_baseclasses; i++)
1589 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1591 if (use_gnu_debug_info_extensions)
1593 have_used_extensions = 1;
1594 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1595 putc (TREE_VIA_PUBLIC (child) ? '2' : '0', asmfile);
1596 CHARS (2);
1597 if (TREE_VIA_VIRTUAL (child) && strcmp (lang_hooks.name, "GNU C++") == 0)
1598 /* For a virtual base, print the (negative) offset within
1599 the vtable where we must look to find the necessary
1600 adjustment. */
1601 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1602 * BITS_PER_UNIT);
1603 else
1604 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1605 * BITS_PER_UNIT);
1606 putc (',', asmfile);
1607 CHARS (1);
1608 dbxout_type (BINFO_TYPE (child), 0);
1609 putc (';', asmfile);
1610 CHARS (1);
1612 else
1614 /* Print out the base class information with fields
1615 which have the same names at the types they hold. */
1616 dbxout_type_name (BINFO_TYPE (child));
1617 putc (':', asmfile);
1618 CHARS (1);
1619 dbxout_type (BINFO_TYPE (child), full);
1620 putc (',', asmfile);
1621 CHARS (1);
1622 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1623 * BITS_PER_UNIT);
1624 putc (',', asmfile);
1625 CHARS (1);
1626 print_wide_int (tree_low_cst (DECL_SIZE
1627 (TYPE_NAME
1628 (BINFO_TYPE (child))),
1630 * BITS_PER_UNIT);
1631 putc (';', asmfile);
1632 CHARS (1);
1637 /* Write out the field declarations. */
1638 dbxout_type_fields (type);
1639 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1641 have_used_extensions = 1;
1642 dbxout_type_methods (type);
1645 putc (';', asmfile);
1646 CHARS (1);
1648 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1649 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1650 && TYPE_VFIELD (type))
1652 have_used_extensions = 1;
1654 /* Tell GDB+ that it may keep reading. */
1655 putc ('~', asmfile);
1656 CHARS (1);
1658 /* We need to write out info about what field this class
1659 uses as its "main" vtable pointer field, because if this
1660 field is inherited from a base class, GDB cannot necessarily
1661 figure out which field it's using in time. */
1662 if (TYPE_VFIELD (type))
1664 putc ('%', asmfile);
1665 CHARS (1);
1666 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1669 putc (';', asmfile);
1670 CHARS (1);
1672 break;
1674 case ENUMERAL_TYPE:
1675 /* We must use the same test here as we use in the DBX_NO_XREFS case
1676 above. We simplify it a bit since an enum will never have a variable
1677 size. */
1678 if ((TYPE_NAME (type) != 0
1679 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1680 && DECL_IGNORED_P (TYPE_NAME (type)))
1681 && !full)
1682 || !COMPLETE_TYPE_P (type))
1684 fprintf (asmfile, "xe");
1685 CHARS (2);
1686 dbxout_type_name (type);
1687 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1688 putc (':', asmfile);
1689 CHARS (1);
1690 return;
1692 #ifdef DBX_OUTPUT_ENUM
1693 DBX_OUTPUT_ENUM (asmfile, type);
1694 #else
1695 if (use_gnu_debug_info_extensions
1696 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1698 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1699 CHARS (5);
1702 putc ('e', asmfile);
1703 CHARS (1);
1704 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1706 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1707 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1708 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1709 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1710 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1711 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1712 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1713 else
1714 print_int_cst_octal (TREE_VALUE (tem));
1716 putc (',', asmfile);
1717 CHARS (1);
1718 if (TREE_CHAIN (tem) != 0)
1719 CONTIN;
1722 putc (';', asmfile);
1723 CHARS (1);
1724 #endif
1725 break;
1727 case POINTER_TYPE:
1728 putc ('*', asmfile);
1729 CHARS (1);
1730 dbxout_type (TREE_TYPE (type), 0);
1731 break;
1733 case METHOD_TYPE:
1734 if (use_gnu_debug_info_extensions)
1736 have_used_extensions = 1;
1737 putc ('#', asmfile);
1738 CHARS (1);
1740 /* Write the argument types out longhand. */
1741 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1742 putc (',', asmfile);
1743 CHARS (1);
1744 dbxout_type (TREE_TYPE (type), 0);
1745 dbxout_args (TYPE_ARG_TYPES (type));
1746 putc (';', asmfile);
1747 CHARS (1);
1749 else
1750 /* Treat it as a function type. */
1751 dbxout_type (TREE_TYPE (type), 0);
1752 break;
1754 case OFFSET_TYPE:
1755 if (use_gnu_debug_info_extensions)
1757 have_used_extensions = 1;
1758 putc ('@', asmfile);
1759 CHARS (1);
1760 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1761 putc (',', asmfile);
1762 CHARS (1);
1763 dbxout_type (TREE_TYPE (type), 0);
1765 else
1766 /* Should print as an int, because it is really just an offset. */
1767 dbxout_type (integer_type_node, 0);
1768 break;
1770 case REFERENCE_TYPE:
1771 if (use_gnu_debug_info_extensions)
1772 have_used_extensions = 1;
1773 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1774 CHARS (1);
1775 dbxout_type (TREE_TYPE (type), 0);
1776 break;
1778 case FUNCTION_TYPE:
1779 putc ('f', asmfile);
1780 CHARS (1);
1781 dbxout_type (TREE_TYPE (type), 0);
1782 break;
1784 default:
1785 abort ();
1789 /* Print the value of integer constant C, in octal,
1790 handling double precision. */
1792 static void
1793 print_int_cst_octal (c)
1794 tree c;
1796 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1797 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1798 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1799 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1801 /* GDB wants constants with no extra leading "1" bits, so
1802 we need to remove any sign-extension that might be
1803 present. */
1804 if (width == HOST_BITS_PER_WIDE_INT * 2)
1806 else if (width > HOST_BITS_PER_WIDE_INT)
1807 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1808 else if (width == HOST_BITS_PER_WIDE_INT)
1809 high = 0;
1810 else
1811 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1813 fprintf (asmfile, "0");
1814 CHARS (1);
1816 if (excess == 3)
1818 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1819 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1821 else
1823 unsigned HOST_WIDE_INT beg = high >> excess;
1824 unsigned HOST_WIDE_INT middle
1825 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1826 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1827 unsigned HOST_WIDE_INT end
1828 = low & (((unsigned HOST_WIDE_INT) 1
1829 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1830 - 1);
1832 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1833 CHARS (2);
1834 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1838 static void
1839 print_octal (value, digits)
1840 unsigned HOST_WIDE_INT value;
1841 int digits;
1843 int i;
1845 for (i = digits - 1; i >= 0; i--)
1846 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1848 CHARS (digits);
1851 /* Output C in decimal while adjusting the number of digits written. */
1853 static void
1854 print_wide_int (c)
1855 HOST_WIDE_INT c;
1857 int digs = 0;
1859 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1861 if (c < 0)
1862 digs++, c = -c;
1864 while (c > 0)
1865 c /= 10; digs++;
1867 CHARS (digs);
1870 /* Output the name of type TYPE, with no punctuation.
1871 Such names can be set up either by typedef declarations
1872 or by struct, enum and union tags. */
1874 static void
1875 dbxout_type_name (type)
1876 tree type;
1878 tree t;
1879 if (TYPE_NAME (type) == 0)
1880 abort ();
1881 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1883 t = TYPE_NAME (type);
1885 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1887 t = DECL_NAME (TYPE_NAME (type));
1889 else
1890 abort ();
1892 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1893 CHARS (IDENTIFIER_LENGTH (t));
1896 /* Output leading leading struct or class names needed for qualifying
1897 type whose scope is limited to a struct or class. */
1899 static void
1900 dbxout_class_name_qualifiers (decl)
1901 tree decl;
1903 tree context = decl_type_context (decl);
1905 if (context != NULL_TREE
1906 && TREE_CODE(context) == RECORD_TYPE
1907 && TYPE_NAME (context) != 0
1908 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
1909 || (DECL_NAME (TYPE_NAME (context)) != 0)))
1911 tree name = TYPE_NAME (context);
1913 if (TREE_CODE (name) == TYPE_DECL)
1915 dbxout_class_name_qualifiers (name);
1916 name = DECL_NAME (name);
1918 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1919 CHARS (IDENTIFIER_LENGTH (name) + 2);
1923 /* Output a .stabs for the symbol defined by DECL,
1924 which must be a ..._DECL node in the normal namespace.
1925 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1926 LOCAL is nonzero if the scope is less than the entire file.
1927 Return 1 if a stabs might have been emitted. */
1930 dbxout_symbol (decl, local)
1931 tree decl;
1932 int local ATTRIBUTE_UNUSED;
1934 tree type = TREE_TYPE (decl);
1935 tree context = NULL_TREE;
1936 int result = 0;
1938 /* Cast avoids warning in old compilers. */
1939 current_sym_code = (STAB_CODE_TYPE) 0;
1940 current_sym_value = 0;
1941 current_sym_addr = 0;
1943 /* Ignore nameless syms, but don't ignore type tags. */
1945 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1946 || DECL_IGNORED_P (decl))
1947 return 0;
1949 dbxout_prepare_symbol (decl);
1951 /* The output will always start with the symbol name,
1952 so always count that in the length-output-so-far. */
1954 if (DECL_NAME (decl) != 0)
1955 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1957 switch (TREE_CODE (decl))
1959 case CONST_DECL:
1960 /* Enum values are defined by defining the enum type. */
1961 break;
1963 case FUNCTION_DECL:
1964 if (DECL_RTL (decl) == 0)
1965 return 0;
1966 if (DECL_EXTERNAL (decl))
1967 break;
1968 /* Don't mention a nested function under its parent. */
1969 context = decl_function_context (decl);
1970 if (context == current_function_decl)
1971 break;
1972 if (GET_CODE (DECL_RTL (decl)) != MEM
1973 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1974 break;
1975 FORCE_TEXT;
1977 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1978 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1979 TREE_PUBLIC (decl) ? 'F' : 'f');
1980 result = 1;
1982 current_sym_code = N_FUN;
1983 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1985 if (TREE_TYPE (type))
1986 dbxout_type (TREE_TYPE (type), 0);
1987 else
1988 dbxout_type (void_type_node, 0);
1990 /* For a nested function, when that function is compiled,
1991 mention the containing function name
1992 as well as (since dbx wants it) our own assembler-name. */
1993 if (context != 0)
1994 fprintf (asmfile, ",%s,%s",
1995 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1996 IDENTIFIER_POINTER (DECL_NAME (context)));
1998 dbxout_finish_symbol (decl);
1999 break;
2001 case TYPE_DECL:
2002 #if 0
2003 /* This seems all wrong. Outputting most kinds of types gives no name
2004 at all. A true definition gives no name; a cross-ref for a
2005 structure can give the tag name, but not a type name.
2006 It seems that no typedef name is defined by outputting a type. */
2008 /* If this typedef name was defined by outputting the type,
2009 don't duplicate it. */
2010 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
2011 && TYPE_NAME (TREE_TYPE (decl)) == decl)
2012 return 0;
2013 #endif
2014 /* Don't output the same typedef twice.
2015 And don't output what language-specific stuff doesn't want output. */
2016 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2017 return 0;
2019 FORCE_TEXT;
2020 result = 1;
2022 int tag_needed = 1;
2023 int did_output = 0;
2025 if (DECL_NAME (decl))
2027 /* Nonzero means we must output a tag as well as a typedef. */
2028 tag_needed = 0;
2030 /* Handle the case of a C++ structure or union
2031 where the TYPE_NAME is a TYPE_DECL
2032 which gives both a typedef name and a tag. */
2033 /* dbx requires the tag first and the typedef second. */
2034 if ((TREE_CODE (type) == RECORD_TYPE
2035 || TREE_CODE (type) == UNION_TYPE
2036 || TREE_CODE (type) == QUAL_UNION_TYPE)
2037 && TYPE_NAME (type) == decl
2038 && !(use_gnu_debug_info_extensions && have_used_extensions)
2039 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2040 /* Distinguish the implicit typedefs of C++
2041 from explicit ones that might be found in C. */
2042 && DECL_ARTIFICIAL (decl)
2043 /* Do not generate a tag for records of variable size,
2044 since this type can not be properly described in the
2045 DBX format, and it confuses some tools such as objdump. */
2046 && host_integerp (TYPE_SIZE (type), 1))
2048 tree name = TYPE_NAME (type);
2049 if (TREE_CODE (name) == TYPE_DECL)
2050 name = DECL_NAME (name);
2052 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2053 current_sym_value = 0;
2054 current_sym_addr = 0;
2055 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2057 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2058 IDENTIFIER_POINTER (name));
2059 dbxout_type (type, 1);
2060 dbxout_finish_symbol (NULL_TREE);
2063 /* Output .stabs (or whatever) and leading double quote. */
2064 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2066 if (use_gnu_debug_info_extensions)
2068 /* Output leading class/struct qualifiers. */
2069 dbxout_class_name_qualifiers (decl);
2072 /* Output typedef name. */
2073 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2075 /* Short cut way to output a tag also. */
2076 if ((TREE_CODE (type) == RECORD_TYPE
2077 || TREE_CODE (type) == UNION_TYPE
2078 || TREE_CODE (type) == QUAL_UNION_TYPE)
2079 && TYPE_NAME (type) == decl
2080 /* Distinguish the implicit typedefs of C++
2081 from explicit ones that might be found in C. */
2082 && DECL_ARTIFICIAL (decl))
2084 if (use_gnu_debug_info_extensions && have_used_extensions)
2086 putc ('T', asmfile);
2087 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2089 #if 0 /* Now we generate the tag for this case up above. */
2090 else
2091 tag_needed = 1;
2092 #endif
2095 putc ('t', asmfile);
2096 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2098 dbxout_type (type, 1);
2099 dbxout_finish_symbol (decl);
2100 did_output = 1;
2103 /* Don't output a tag if this is an incomplete type. This prevents
2104 the sun4 Sun OS 4.x dbx from crashing. */
2106 if (tag_needed && TYPE_NAME (type) != 0
2107 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2108 || (DECL_NAME (TYPE_NAME (type)) != 0))
2109 && COMPLETE_TYPE_P (type)
2110 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2112 /* For a TYPE_DECL with no name, but the type has a name,
2113 output a tag.
2114 This is what represents `struct foo' with no typedef. */
2115 /* In C++, the name of a type is the corresponding typedef.
2116 In C, it is an IDENTIFIER_NODE. */
2117 tree name = TYPE_NAME (type);
2118 if (TREE_CODE (name) == TYPE_DECL)
2119 name = DECL_NAME (name);
2121 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2122 current_sym_value = 0;
2123 current_sym_addr = 0;
2124 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2126 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2127 IDENTIFIER_POINTER (name));
2128 dbxout_type (type, 1);
2129 dbxout_finish_symbol (NULL_TREE);
2130 did_output = 1;
2133 /* If an enum type has no name, it cannot be referred to,
2134 but we must output it anyway, since the enumeration constants
2135 can be referred to. */
2136 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2138 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2139 current_sym_value = 0;
2140 current_sym_addr = 0;
2141 current_sym_nchars = 2;
2143 /* Some debuggers fail when given NULL names, so give this a
2144 harmless name of ` '. */
2145 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2146 dbxout_type (type, 1);
2147 dbxout_finish_symbol (NULL_TREE);
2150 /* Prevent duplicate output of a typedef. */
2151 TREE_ASM_WRITTEN (decl) = 1;
2152 break;
2155 case PARM_DECL:
2156 /* Parm decls go in their own separate chains
2157 and are output by dbxout_reg_parms and dbxout_parms. */
2158 abort ();
2160 case RESULT_DECL:
2161 /* Named return value, treat like a VAR_DECL. */
2162 case VAR_DECL:
2163 if (! DECL_RTL_SET_P (decl))
2164 return 0;
2165 /* Don't mention a variable that is external.
2166 Let the file that defines it describe it. */
2167 if (DECL_EXTERNAL (decl))
2168 break;
2170 /* If the variable is really a constant
2171 and not written in memory, inform the debugger. */
2172 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2173 && DECL_INITIAL (decl) != 0
2174 && host_integerp (DECL_INITIAL (decl), 0)
2175 && ! TREE_ASM_WRITTEN (decl)
2176 && (DECL_CONTEXT (decl) == NULL_TREE
2177 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2179 if (TREE_PUBLIC (decl) == 0)
2181 /* The sun4 assembler does not grok this. */
2182 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2184 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2185 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2187 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2188 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
2189 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
2190 #else
2191 fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
2193 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
2194 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
2195 #endif
2196 return 1;
2198 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2200 /* don't know how to do this yet. */
2202 break;
2204 /* else it is something we handle like a normal variable. */
2207 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2208 #ifdef LEAF_REG_REMAP
2209 if (current_function_uses_only_leaf_regs)
2210 leaf_renumber_regs_insn (DECL_RTL (decl));
2211 #endif
2213 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2214 break;
2216 default:
2217 break;
2219 return result;
2222 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2223 Add SUFFIX to its name, if SUFFIX is not 0.
2224 Describe the variable as residing in HOME
2225 (usually HOME is DECL_RTL (DECL), but not always).
2226 Returns 1 if the stab was really emitted. */
2228 static int
2229 dbxout_symbol_location (decl, type, suffix, home)
2230 tree decl, type;
2231 const char *suffix;
2232 rtx home;
2234 int letter = 0;
2235 int regno = -1;
2237 /* Don't mention a variable at all
2238 if it was completely optimized into nothingness.
2240 If the decl was from an inline function, then its rtl
2241 is not identically the rtl that was used in this
2242 particular compilation. */
2243 if (GET_CODE (home) == SUBREG)
2245 rtx value = home;
2247 while (GET_CODE (value) == SUBREG)
2248 value = SUBREG_REG (value);
2249 if (GET_CODE (value) == REG)
2251 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2252 return 0;
2254 home = alter_subreg (&home);
2256 if (GET_CODE (home) == REG)
2258 regno = REGNO (home);
2259 if (regno >= FIRST_PSEUDO_REGISTER)
2260 return 0;
2263 /* The kind-of-variable letter depends on where
2264 the variable is and on the scope of its name:
2265 G and N_GSYM for static storage and global scope,
2266 S for static storage and file scope,
2267 V for static storage and local scope,
2268 for those two, use N_LCSYM if data is in bss segment,
2269 N_STSYM if in data segment, N_FUN otherwise.
2270 (We used N_FUN originally, then changed to N_STSYM
2271 to please GDB. However, it seems that confused ld.
2272 Now GDB has been fixed to like N_FUN, says Kingdon.)
2273 no letter at all, and N_LSYM, for auto variable,
2274 r and N_RSYM for register variable. */
2276 if (GET_CODE (home) == MEM
2277 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2279 if (TREE_PUBLIC (decl))
2281 letter = 'G';
2282 current_sym_code = N_GSYM;
2284 else
2286 current_sym_addr = XEXP (home, 0);
2288 letter = decl_function_context (decl) ? 'V' : 'S';
2290 /* This should be the same condition as in assemble_variable, but
2291 we don't have access to dont_output_data here. So, instead,
2292 we rely on the fact that error_mark_node initializers always
2293 end up in bss for C++ and never end up in bss for C. */
2294 if (DECL_INITIAL (decl) == 0
2295 || (!strcmp (lang_hooks.name, "GNU C++")
2296 && DECL_INITIAL (decl) == error_mark_node))
2297 current_sym_code = N_LCSYM;
2298 else if (DECL_IN_TEXT_SECTION (decl))
2299 /* This is not quite right, but it's the closest
2300 of all the codes that Unix defines. */
2301 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2302 else
2304 /* Some ports can transform a symbol ref into a label ref,
2305 because the symbol ref is too far away and has to be
2306 dumped into a constant pool. Alternatively, the symbol
2307 in the constant pool might be referenced by a different
2308 symbol. */
2309 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2310 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2312 rtx tmp = get_pool_constant (current_sym_addr);
2314 if (GET_CODE (tmp) == SYMBOL_REF
2315 || GET_CODE (tmp) == LABEL_REF)
2316 current_sym_addr = tmp;
2319 /* Ultrix `as' seems to need this. */
2320 #ifdef DBX_STATIC_STAB_DATA_SECTION
2321 data_section ();
2322 #endif
2323 current_sym_code = N_STSYM;
2327 else if (regno >= 0)
2329 letter = 'r';
2330 current_sym_code = N_RSYM;
2331 current_sym_value = DBX_REGISTER_NUMBER (regno);
2333 else if (GET_CODE (home) == MEM
2334 && (GET_CODE (XEXP (home, 0)) == MEM
2335 || (GET_CODE (XEXP (home, 0)) == REG
2336 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2337 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2338 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2339 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2340 #endif
2342 /* If the value is indirect by memory or by a register
2343 that isn't the frame pointer
2344 then it means the object is variable-sized and address through
2345 that register or stack slot. DBX has no way to represent this
2346 so all we can do is output the variable as a pointer.
2347 If it's not a parameter, ignore it.
2348 (VAR_DECLs like this can be made by integrate.c.) */
2350 if (GET_CODE (XEXP (home, 0)) == REG)
2352 letter = 'r';
2353 current_sym_code = N_RSYM;
2354 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2355 return 0;
2356 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2358 else
2360 current_sym_code = N_LSYM;
2361 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2362 We want the value of that CONST_INT. */
2363 current_sym_value
2364 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2367 /* Effectively do build_pointer_type, but don't cache this type,
2368 since it might be temporary whereas the type it points to
2369 might have been saved for inlining. */
2370 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2371 type = make_node (POINTER_TYPE);
2372 TREE_TYPE (type) = TREE_TYPE (decl);
2374 else if (GET_CODE (home) == MEM
2375 && GET_CODE (XEXP (home, 0)) == REG)
2377 current_sym_code = N_LSYM;
2378 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2380 else if (GET_CODE (home) == MEM
2381 && GET_CODE (XEXP (home, 0)) == PLUS
2382 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2384 current_sym_code = N_LSYM;
2385 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2386 We want the value of that CONST_INT. */
2387 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2389 else if (GET_CODE (home) == MEM
2390 && GET_CODE (XEXP (home, 0)) == CONST)
2392 /* Handle an obscure case which can arise when optimizing and
2393 when there are few available registers. (This is *always*
2394 the case for i386/i486 targets). The RTL looks like
2395 (MEM (CONST ...)) even though this variable is a local `auto'
2396 or a local `register' variable. In effect, what has happened
2397 is that the reload pass has seen that all assignments and
2398 references for one such a local variable can be replaced by
2399 equivalent assignments and references to some static storage
2400 variable, thereby avoiding the need for a register. In such
2401 cases we're forced to lie to debuggers and tell them that
2402 this variable was itself `static'. */
2403 current_sym_code = N_LCSYM;
2404 letter = 'V';
2405 current_sym_addr = XEXP (XEXP (home, 0), 0);
2407 else if (GET_CODE (home) == CONCAT)
2409 tree subtype;
2411 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2412 for example), then there is no easy way to figure out
2413 what SUBTYPE should be. So, we give up. */
2414 if (TREE_CODE (type) != COMPLEX_TYPE)
2415 return 0;
2417 subtype = TREE_TYPE (type);
2419 /* If the variable's storage is in two parts,
2420 output each as a separate stab with a modified name. */
2421 if (WORDS_BIG_ENDIAN)
2422 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2423 else
2424 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2426 /* Cast avoids warning in old compilers. */
2427 current_sym_code = (STAB_CODE_TYPE) 0;
2428 current_sym_value = 0;
2429 current_sym_addr = 0;
2430 dbxout_prepare_symbol (decl);
2432 if (WORDS_BIG_ENDIAN)
2433 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2434 else
2435 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2436 return 1;
2438 else
2439 /* Address might be a MEM, when DECL is a variable-sized object.
2440 Or it might be const0_rtx, meaning previous passes
2441 want us to ignore this variable. */
2442 return 0;
2444 /* Ok, start a symtab entry and output the variable name. */
2445 FORCE_TEXT;
2447 #ifdef DBX_STATIC_BLOCK_START
2448 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2449 #endif
2451 dbxout_symbol_name (decl, suffix, letter);
2452 dbxout_type (type, 0);
2453 dbxout_finish_symbol (decl);
2455 #ifdef DBX_STATIC_BLOCK_END
2456 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2457 #endif
2458 return 1;
2461 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2462 Then output LETTER to indicate the kind of location the symbol has. */
2464 static void
2465 dbxout_symbol_name (decl, suffix, letter)
2466 tree decl;
2467 const char *suffix;
2468 int letter;
2470 const char *name;
2472 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2473 /* One slight hitch: if this is a VAR_DECL which is a static
2474 class member, we must put out the mangled name instead of the
2475 DECL_NAME. Note also that static member (variable) names DO NOT begin
2476 with underscores in .stabs directives. */
2477 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2478 else
2479 /* ...but if we're function-local, we don't want to include the junk
2480 added by ASM_FORMAT_PRIVATE_NAME. */
2481 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2483 if (name == 0)
2484 name = "(anon)";
2485 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2486 (suffix ? suffix : ""));
2488 if (letter)
2489 putc (letter, asmfile);
2492 static void
2493 dbxout_prepare_symbol (decl)
2494 tree decl ATTRIBUTE_UNUSED;
2496 #ifdef WINNING_GDB
2497 const char *filename = DECL_SOURCE_FILE (decl);
2499 dbxout_source_file (asmfile, filename);
2500 #endif
2503 static void
2504 dbxout_finish_symbol (sym)
2505 tree sym;
2507 #ifdef DBX_FINISH_SYMBOL
2508 DBX_FINISH_SYMBOL (sym);
2509 #else
2510 int line = 0;
2511 if (use_gnu_debug_info_extensions && sym != 0)
2512 line = DECL_SOURCE_LINE (sym);
2514 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2515 if (current_sym_addr)
2516 output_addr_const (asmfile, current_sym_addr);
2517 else
2518 fprintf (asmfile, "%d", current_sym_value);
2519 putc ('\n', asmfile);
2520 #endif
2523 /* Output definitions of all the decls in a chain. Return nonzero if
2524 anything was output */
2527 dbxout_syms (syms)
2528 tree syms;
2530 int result = 0;
2531 while (syms)
2533 result += dbxout_symbol (syms, 1);
2534 syms = TREE_CHAIN (syms);
2536 return result;
2539 /* The following two functions output definitions of function parameters.
2540 Each parameter gets a definition locating it in the parameter list.
2541 Each parameter that is a register variable gets a second definition
2542 locating it in the register.
2544 Printing or argument lists in gdb uses the definitions that
2545 locate in the parameter list. But reference to the variable in
2546 expressions uses preferentially the definition as a register. */
2548 /* Output definitions, referring to storage in the parmlist,
2549 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2551 void
2552 dbxout_parms (parms)
2553 tree parms;
2555 for (; parms; parms = TREE_CHAIN (parms))
2556 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2558 dbxout_prepare_symbol (parms);
2560 /* Perform any necessary register eliminations on the parameter's rtl,
2561 so that the debugging output will be accurate. */
2562 DECL_INCOMING_RTL (parms)
2563 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2564 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2565 #ifdef LEAF_REG_REMAP
2566 if (current_function_uses_only_leaf_regs)
2568 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2569 leaf_renumber_regs_insn (DECL_RTL (parms));
2571 #endif
2573 if (PARM_PASSED_IN_MEMORY (parms))
2575 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2577 /* ??? Here we assume that the parm address is indexed
2578 off the frame pointer or arg pointer.
2579 If that is not true, we produce meaningless results,
2580 but do not crash. */
2581 if (GET_CODE (addr) == PLUS
2582 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2583 current_sym_value = INTVAL (XEXP (addr, 1));
2584 else
2585 current_sym_value = 0;
2587 current_sym_code = N_PSYM;
2588 current_sym_addr = 0;
2590 FORCE_TEXT;
2591 if (DECL_NAME (parms))
2593 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2595 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2596 IDENTIFIER_POINTER (DECL_NAME (parms)),
2597 DBX_MEMPARM_STABS_LETTER);
2599 else
2601 current_sym_nchars = 8;
2602 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2603 DBX_MEMPARM_STABS_LETTER);
2606 /* It is quite tempting to use:
2608 dbxout_type (TREE_TYPE (parms), 0);
2610 as the next statement, rather than using DECL_ARG_TYPE(), so
2611 that gcc reports the actual type of the parameter, rather
2612 than the promoted type. This certainly makes GDB's life
2613 easier, at least for some ports. The change is a bad idea
2614 however, since GDB expects to be able access the type without
2615 performing any conversions. So for example, if we were
2616 passing a float to an unprototyped function, gcc will store a
2617 double on the stack, but if we emit a stab saying the type is a
2618 float, then gdb will only read in a single value, and this will
2619 produce an erroneous value. */
2620 dbxout_type (DECL_ARG_TYPE (parms), 0);
2621 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2622 dbxout_finish_symbol (parms);
2624 else if (GET_CODE (DECL_RTL (parms)) == REG)
2626 rtx best_rtl;
2627 char regparm_letter;
2628 tree parm_type;
2629 /* Parm passed in registers and lives in registers or nowhere. */
2631 current_sym_code = DBX_REGPARM_STABS_CODE;
2632 regparm_letter = DBX_REGPARM_STABS_LETTER;
2633 current_sym_addr = 0;
2635 /* If parm lives in a register, use that register;
2636 pretend the parm was passed there. It would be more consistent
2637 to describe the register where the parm was passed,
2638 but in practice that register usually holds something else.
2640 If we use DECL_RTL, then we must use the declared type of
2641 the variable, not the type that it arrived in. */
2642 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2644 best_rtl = DECL_RTL (parms);
2645 parm_type = TREE_TYPE (parms);
2647 /* If the parm lives nowhere, use the register where it was
2648 passed. It is also better to use the declared type here. */
2649 else
2651 best_rtl = DECL_INCOMING_RTL (parms);
2652 parm_type = TREE_TYPE (parms);
2654 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2656 FORCE_TEXT;
2657 if (DECL_NAME (parms))
2659 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2660 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2661 IDENTIFIER_POINTER (DECL_NAME (parms)),
2662 regparm_letter);
2664 else
2666 current_sym_nchars = 8;
2667 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2668 regparm_letter);
2671 dbxout_type (parm_type, 0);
2672 dbxout_finish_symbol (parms);
2674 else if (GET_CODE (DECL_RTL (parms)) == MEM
2675 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2676 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2677 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2678 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2679 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2680 #endif
2683 /* Parm was passed via invisible reference.
2684 That is, its address was passed in a register.
2685 Output it as if it lived in that register.
2686 The debugger will know from the type
2687 that it was actually passed by invisible reference. */
2689 char regparm_letter;
2690 /* Parm passed in registers and lives in registers or nowhere. */
2692 current_sym_code = DBX_REGPARM_STABS_CODE;
2693 if (use_gnu_debug_info_extensions)
2694 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2695 else
2696 regparm_letter = DBX_REGPARM_STABS_LETTER;
2698 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2699 If it is an unallocated pseudo-reg, then use the register where
2700 it was passed instead. */
2701 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2702 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2703 else
2704 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2706 current_sym_addr = 0;
2708 FORCE_TEXT;
2709 if (DECL_NAME (parms))
2711 current_sym_nchars
2712 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2714 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2715 IDENTIFIER_POINTER (DECL_NAME (parms)),
2716 regparm_letter);
2718 else
2720 current_sym_nchars = 8;
2721 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2722 regparm_letter);
2725 dbxout_type (TREE_TYPE (parms), 0);
2726 dbxout_finish_symbol (parms);
2728 else if (GET_CODE (DECL_RTL (parms)) == MEM
2729 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2731 /* Parm was passed via invisible reference, with the reference
2732 living on the stack. DECL_RTL looks like
2733 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2734 could look like (MEM (MEM (REG))). */
2735 const char *const decl_name = (DECL_NAME (parms)
2736 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2737 : "(anon)");
2738 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2739 current_sym_value = 0;
2740 else
2741 current_sym_value
2742 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2743 current_sym_addr = 0;
2744 current_sym_code = N_PSYM;
2746 FORCE_TEXT;
2747 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2749 current_sym_value
2750 = DEBUGGER_ARG_OFFSET (current_sym_value,
2751 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2752 dbxout_type (TREE_TYPE (parms), 0);
2753 dbxout_finish_symbol (parms);
2755 else if (GET_CODE (DECL_RTL (parms)) == MEM
2756 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2757 /* ??? A constant address for a parm can happen
2758 when the reg it lives in is equiv to a constant in memory.
2759 Should make this not happen, after 2.4. */
2760 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2762 /* Parm was passed in registers but lives on the stack. */
2764 current_sym_code = N_PSYM;
2765 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2766 in which case we want the value of that CONST_INT,
2767 or (MEM (REG ...)),
2768 in which case we use a value of zero. */
2769 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2770 current_sym_value = 0;
2771 else
2772 current_sym_value
2773 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2775 current_sym_addr = 0;
2777 /* Make a big endian correction if the mode of the type of the
2778 parameter is not the same as the mode of the rtl. */
2779 if (BYTES_BIG_ENDIAN
2780 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2781 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2783 current_sym_value +=
2784 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2785 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2788 FORCE_TEXT;
2789 if (DECL_NAME (parms))
2791 current_sym_nchars
2792 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2794 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2795 IDENTIFIER_POINTER (DECL_NAME (parms)),
2796 DBX_MEMPARM_STABS_LETTER);
2798 else
2800 current_sym_nchars = 8;
2801 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2802 DBX_MEMPARM_STABS_LETTER);
2805 current_sym_value
2806 = DEBUGGER_ARG_OFFSET (current_sym_value,
2807 XEXP (DECL_RTL (parms), 0));
2808 dbxout_type (TREE_TYPE (parms), 0);
2809 dbxout_finish_symbol (parms);
2814 /* Output definitions for the places where parms live during the function,
2815 when different from where they were passed, when the parms were passed
2816 in memory.
2818 It is not useful to do this for parms passed in registers
2819 that live during the function in different registers, because it is
2820 impossible to look in the passed register for the passed value,
2821 so we use the within-the-function register to begin with.
2823 PARMS is a chain of PARM_DECL nodes. */
2825 void
2826 dbxout_reg_parms (parms)
2827 tree parms;
2829 for (; parms; parms = TREE_CHAIN (parms))
2830 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2832 dbxout_prepare_symbol (parms);
2834 /* Report parms that live in registers during the function
2835 but were passed in memory. */
2836 if (GET_CODE (DECL_RTL (parms)) == REG
2837 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2838 dbxout_symbol_location (parms, TREE_TYPE (parms),
2839 0, DECL_RTL (parms));
2840 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2841 dbxout_symbol_location (parms, TREE_TYPE (parms),
2842 0, DECL_RTL (parms));
2843 /* Report parms that live in memory but not where they were passed. */
2844 else if (GET_CODE (DECL_RTL (parms)) == MEM
2845 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2846 dbxout_symbol_location (parms, TREE_TYPE (parms),
2847 0, DECL_RTL (parms));
2851 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2852 output definitions of those names, in raw form */
2854 static void
2855 dbxout_args (args)
2856 tree args;
2858 while (args)
2860 putc (',', asmfile);
2861 dbxout_type (TREE_VALUE (args), 0);
2862 CHARS (1);
2863 args = TREE_CHAIN (args);
2867 /* Output everything about a symbol block (a BLOCK node
2868 that represents a scope level),
2869 including recursive output of contained blocks.
2871 BLOCK is the BLOCK node.
2872 DEPTH is its depth within containing symbol blocks.
2873 ARGS is usually zero; but for the outermost block of the
2874 body of a function, it is a chain of PARM_DECLs for the function parameters.
2875 We output definitions of all the register parms
2876 as if they were local variables of that block.
2878 If -g1 was used, we count blocks just the same, but output nothing
2879 except for the outermost block.
2881 Actually, BLOCK may be several blocks chained together.
2882 We handle them all in sequence. */
2884 static void
2885 dbxout_block (block, depth, args)
2886 tree block;
2887 int depth;
2888 tree args;
2890 int blocknum = -1;
2892 #if DBX_BLOCKS_FUNCTION_RELATIVE
2893 const char *begin_label;
2894 if (current_function_func_begin_label != NULL_TREE)
2895 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2896 else
2897 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2898 #endif
2900 while (block)
2902 /* Ignore blocks never expanded or otherwise marked as real. */
2903 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2905 int did_output;
2907 #ifdef DBX_LBRAC_FIRST
2908 did_output = 1;
2909 #else
2910 /* In dbx format, the syms of a block come before the N_LBRAC.
2911 If nothing is output, we don't need the N_LBRAC, either. */
2912 did_output = 0;
2913 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2914 did_output = dbxout_syms (BLOCK_VARS (block));
2915 if (args)
2916 dbxout_reg_parms (args);
2917 #endif
2919 /* Now output an N_LBRAC symbol to represent the beginning of
2920 the block. Use the block's tree-walk order to generate
2921 the assembler symbols LBBn and LBEn
2922 that final will define around the code in this block. */
2923 if (depth > 0 && did_output)
2925 char buf[20];
2926 blocknum = BLOCK_NUMBER (block);
2927 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2929 if (BLOCK_HANDLER_BLOCK (block))
2931 /* A catch block. Must precede N_LBRAC. */
2932 tree decl = BLOCK_VARS (block);
2933 while (decl)
2935 #ifdef DBX_OUTPUT_CATCH
2936 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2937 #else
2938 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2939 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2940 assemble_name (asmfile, buf);
2941 fprintf (asmfile, "\n");
2942 #endif
2943 decl = TREE_CHAIN (decl);
2947 #ifdef DBX_OUTPUT_LBRAC
2948 DBX_OUTPUT_LBRAC (asmfile, buf);
2949 #else
2950 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2951 assemble_name (asmfile, buf);
2952 #if DBX_BLOCKS_FUNCTION_RELATIVE
2953 putc ('-', asmfile);
2954 assemble_name (asmfile, begin_label);
2955 #endif
2956 fprintf (asmfile, "\n");
2957 #endif
2960 #ifdef DBX_LBRAC_FIRST
2961 /* On some weird machines, the syms of a block
2962 come after the N_LBRAC. */
2963 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2964 dbxout_syms (BLOCK_VARS (block));
2965 if (args)
2966 dbxout_reg_parms (args);
2967 #endif
2969 /* Output the subblocks. */
2970 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2972 /* Refer to the marker for the end of the block. */
2973 if (depth > 0 && did_output)
2975 char buf[20];
2976 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2977 #ifdef DBX_OUTPUT_RBRAC
2978 DBX_OUTPUT_RBRAC (asmfile, buf);
2979 #else
2980 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2981 assemble_name (asmfile, buf);
2982 #if DBX_BLOCKS_FUNCTION_RELATIVE
2983 putc ('-', asmfile);
2984 assemble_name (asmfile, begin_label);
2985 #endif
2986 fprintf (asmfile, "\n");
2987 #endif
2990 block = BLOCK_CHAIN (block);
2994 /* Output the information about a function and its arguments and result.
2995 Usually this follows the function's code,
2996 but on some systems, it comes before. */
2998 #if defined (DBX_DEBUGGING_INFO)
2999 static void
3000 dbxout_begin_function (decl)
3001 tree decl;
3003 dbxout_symbol (decl, 0);
3004 dbxout_parms (DECL_ARGUMENTS (decl));
3005 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3006 dbxout_symbol (DECL_RESULT (decl), 1);
3008 #endif /* DBX_DEBUGGING_INFO */
3010 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */