* gcc.dg/arm-asm.c: Enable for StrongARM and XScale targets.
[official-gcc.git] / gcc / dbxout.c
blob683745fc56b54c899a350254f4a5a2c7ea7959d8
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 #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 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
142 /* Structure recording information about a C data type.
143 The status element says whether we have yet output
144 the definition of the type. TYPE_XREF says we have
145 output it as a cross-reference only.
146 The file_number and type_number elements are used if DBX_USE_BINCL
147 is defined. */
149 struct typeinfo GTY(())
151 enum typestatus status;
152 int file_number;
153 int type_number;
156 /* Vector recording information about C data types.
157 When we first notice a data type (a tree node),
158 we assign it a number using next_type_number.
159 That is its index in this vector. */
161 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
163 /* Number of elements of space allocated in `typevec'. */
165 static GTY(()) int typevec_len;
167 /* In dbx output, each type gets a unique number.
168 This is the number for the next type output.
169 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
171 static GTY(()) int next_type_number;
173 /* When using N_BINCL in dbx output, each type number is actually a
174 pair of the file number and the type number within the file.
175 This is a stack of input files. */
177 struct dbx_file GTY(())
179 struct dbx_file *next;
180 int file_number;
181 int next_type_number;
184 /* This is the top of the stack. */
186 static GTY(()) struct dbx_file *current_file;
188 /* This is the next file number to use. */
190 static GTY(()) int next_file_number;
192 /* Typical USG systems don't have stab.h, and they also have
193 no use for DBX-format debugging info. */
195 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
197 /* Last source file name mentioned in a NOTE insn. */
199 static const char *lastfile;
201 /* Current working directory. */
203 static const char *cwd;
205 /* Nonzero if we have actually used any of the GDB extensions
206 to the debugging format. The idea is that we use them for the
207 first time only if there's a strong reason, but once we have done that,
208 we use them whenever convenient. */
210 static int have_used_extensions = 0;
212 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
213 for the N_SO filename stabs label. */
215 #if defined (DBX_DEBUGGING_INFO) && !defined (DBX_OUTPUT_SOURCE_FILENAME)
216 static int source_label_number = 1;
217 #endif
219 #ifdef DEBUG_SYMS_TEXT
220 #define FORCE_TEXT function_section (current_function_decl);
221 #else
222 #define FORCE_TEXT
223 #endif
225 #include "gstab.h"
227 #define STAB_CODE_TYPE enum __stab_debug_code
229 /* 1 if PARM is passed to this function in memory. */
231 #define PARM_PASSED_IN_MEMORY(PARM) \
232 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
234 /* A C expression for the integer offset value of an automatic variable
235 (N_LSYM) having address X (an RTX). */
236 #ifndef DEBUGGER_AUTO_OFFSET
237 #define DEBUGGER_AUTO_OFFSET(X) \
238 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
239 #endif
241 /* A C expression for the integer offset value of an argument (N_PSYM)
242 having address X (an RTX). The nominal offset is OFFSET. */
243 #ifndef DEBUGGER_ARG_OFFSET
244 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
245 #endif
247 /* Stream for writing to assembler file. */
249 static FILE *asmfile;
251 /* These variables are for dbxout_symbol to communicate to
252 dbxout_finish_symbol.
253 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
254 current_sym_value and current_sym_addr are two ways to address the
255 value to store in the symtab entry.
256 current_sym_addr if nonzero represents the value as an rtx.
257 If that is zero, current_sym_value is used. This is used
258 when the value is an offset (such as for auto variables,
259 register variables and parms). */
261 static STAB_CODE_TYPE current_sym_code;
262 static int current_sym_value;
263 static rtx current_sym_addr;
265 /* Number of chars of symbol-description generated so far for the
266 current symbol. Used by CHARS and CONTIN. */
268 static int current_sym_nchars;
270 /* Report having output N chars of the current symbol-description. */
272 #define CHARS(N) (current_sym_nchars += (N))
274 /* Break the current symbol-description, generating a continuation,
275 if it has become long. */
277 #ifndef DBX_CONTIN_LENGTH
278 #define DBX_CONTIN_LENGTH 80
279 #endif
281 #if DBX_CONTIN_LENGTH > 0
282 #define CONTIN \
283 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
284 #else
285 #define CONTIN do { } while (0)
286 #endif
288 static void dbxout_init PARAMS ((const char *));
289 static void dbxout_finish PARAMS ((const char *));
290 static void dbxout_start_source_file PARAMS ((unsigned, const char *));
291 static void dbxout_end_source_file PARAMS ((unsigned));
292 static void dbxout_typedefs PARAMS ((tree));
293 static void dbxout_fptype_value PARAMS ((tree));
294 static void dbxout_type_index PARAMS ((tree));
295 #if DBX_CONTIN_LENGTH > 0
296 static void dbxout_continue PARAMS ((void));
297 #endif
298 static void dbxout_args PARAMS ((tree));
299 static void dbxout_type_fields PARAMS ((tree));
300 static void dbxout_type_method_1 PARAMS ((tree, const char *));
301 static void dbxout_type_methods PARAMS ((tree));
302 static void dbxout_range_type PARAMS ((tree));
303 static void dbxout_type PARAMS ((tree, int));
304 static void print_int_cst_octal PARAMS ((tree));
305 static void print_octal PARAMS ((unsigned HOST_WIDE_INT, int));
306 static void print_wide_int PARAMS ((HOST_WIDE_INT));
307 static void dbxout_type_name PARAMS ((tree));
308 static void dbxout_class_name_qualifiers PARAMS ((tree));
309 static int dbxout_symbol_location PARAMS ((tree, tree, const char *, rtx));
310 static void dbxout_symbol_name PARAMS ((tree, const char *, int));
311 static void dbxout_prepare_symbol PARAMS ((tree));
312 static void dbxout_finish_symbol PARAMS ((tree));
313 static void dbxout_block PARAMS ((tree, int, tree));
314 static void dbxout_global_decl PARAMS ((tree));
316 /* The debug hooks structure. */
317 #if defined (DBX_DEBUGGING_INFO)
319 static void dbxout_source_line PARAMS ((unsigned int, const char *));
320 static void dbxout_source_file PARAMS ((FILE *, const char *));
321 static void dbxout_function_end PARAMS ((void));
322 static void dbxout_begin_function PARAMS ((tree));
323 static void dbxout_begin_block PARAMS ((unsigned, unsigned));
324 static void dbxout_end_block PARAMS ((unsigned, unsigned));
325 static void dbxout_function_decl PARAMS ((tree));
327 const struct gcc_debug_hooks dbx_debug_hooks =
329 dbxout_init,
330 dbxout_finish,
331 debug_nothing_int_charstar,
332 debug_nothing_int_charstar,
333 dbxout_start_source_file,
334 dbxout_end_source_file,
335 dbxout_begin_block,
336 dbxout_end_block,
337 debug_true_tree, /* ignore_block */
338 dbxout_source_line, /* source_line */
339 dbxout_source_line, /* begin_prologue: just output line info */
340 debug_nothing_int_charstar, /* end_prologue */
341 debug_nothing_int_charstar, /* end_epilogue */
342 #ifdef DBX_FUNCTION_FIRST
343 dbxout_begin_function,
344 #else
345 debug_nothing_tree, /* begin_function */
346 #endif
347 debug_nothing_int, /* end_function */
348 dbxout_function_decl,
349 dbxout_global_decl, /* global_decl */
350 debug_nothing_tree, /* deferred_inline_function */
351 debug_nothing_tree, /* outlining_inline_function */
352 debug_nothing_rtx /* label */
354 #endif /* DBX_DEBUGGING_INFO */
356 #if defined (XCOFF_DEBUGGING_INFO)
357 const struct gcc_debug_hooks xcoff_debug_hooks =
359 dbxout_init,
360 dbxout_finish,
361 debug_nothing_int_charstar,
362 debug_nothing_int_charstar,
363 dbxout_start_source_file,
364 dbxout_end_source_file,
365 xcoffout_begin_block,
366 xcoffout_end_block,
367 debug_true_tree, /* ignore_block */
368 xcoffout_source_line,
369 xcoffout_begin_prologue, /* begin_prologue */
370 debug_nothing_int_charstar, /* end_prologue */
371 xcoffout_end_epilogue,
372 debug_nothing_tree, /* begin_function */
373 xcoffout_end_function,
374 debug_nothing_tree, /* function_decl */
375 dbxout_global_decl, /* global_decl */
376 debug_nothing_tree, /* deferred_inline_function */
377 debug_nothing_tree, /* outlining_inline_function */
378 debug_nothing_rtx /* label */
380 #endif /* XCOFF_DEBUGGING_INFO */
382 #if defined (DBX_DEBUGGING_INFO)
383 static void
384 dbxout_function_end ()
386 static int scope_labelno = 0;
387 char lscope_label_name[100];
388 /* Convert Ltext into the appropriate format for local labels in case
389 the system doesn't insert underscores in front of user generated
390 labels. */
391 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
392 (*targetm.asm_out.internal_label) (asmfile, "Lscope", scope_labelno);
393 scope_labelno++;
395 /* By convention, GCC will mark the end of a function with an N_FUN
396 symbol and an empty string. */
397 #ifdef DBX_OUTPUT_NFUN
398 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
399 #else
400 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
401 assemble_name (asmfile, lscope_label_name);
402 putc ('-', asmfile);
403 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
404 fprintf (asmfile, "\n");
405 #endif
407 #endif /* DBX_DEBUGGING_INFO */
409 /* At the beginning of compilation, start writing the symbol table.
410 Initialize `typevec' and output the standard data types of C. */
412 static void
413 dbxout_init (input_file_name)
414 const char *input_file_name;
416 char ltext_label_name[100];
417 tree syms = (*lang_hooks.decls.getdecls) ();
419 asmfile = asm_out_file;
421 typevec_len = 100;
422 typevec = (struct typeinfo *) ggc_calloc (typevec_len, sizeof typevec[0]);
424 /* Convert Ltext into the appropriate format for local labels in case
425 the system doesn't insert underscores in front of user generated
426 labels. */
427 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
429 /* Put the current working directory in an N_SO symbol. */
430 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
431 but GDB always does. */
432 if (use_gnu_debug_info_extensions)
433 #endif
435 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
436 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
437 if (cwd)
439 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
440 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
441 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
442 fprintf (asmfile, "%s", ASM_STABS_OP);
443 output_quoted_string (asmfile, cwd);
444 fprintf (asmfile, ",%d,0,0,", N_SO);
445 assemble_name (asmfile, ltext_label_name);
446 fputc ('\n', asmfile);
447 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
451 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
452 /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
453 would give us an N_SOL, and we want an N_SO. */
454 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
455 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
456 /* We include outputting `Ltext:' here,
457 because that gives you a way to override it. */
458 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
459 fprintf (asmfile, "%s", ASM_STABS_OP);
460 output_quoted_string (asmfile, input_file_name);
461 fprintf (asmfile, ",%d,0,0,", N_SO);
462 assemble_name (asmfile, ltext_label_name);
463 fputc ('\n', asmfile);
464 text_section ();
465 (*targetm.asm_out.internal_label) (asmfile, "Ltext", 0);
466 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
468 #ifdef DBX_OUTPUT_GCC_MARKER
469 DBX_OUTPUT_GCC_MARKER (asmfile);
470 #else
471 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
472 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
473 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
474 #endif
476 lastfile = input_file_name;
478 next_type_number = 1;
480 #ifdef DBX_USE_BINCL
481 current_file = (struct dbx_file *) ggc_alloc (sizeof *current_file);
482 current_file->next = NULL;
483 current_file->file_number = 0;
484 current_file->next_type_number = 1;
485 next_file_number = 1;
486 #endif
488 /* Make sure that types `int' and `char' have numbers 1 and 2.
489 Definitions of other integer types will refer to those numbers.
490 (Actually it should no longer matter what their numbers are.
491 Also, if any types with tags have been defined, dbxout_symbol
492 will output them first, so the numbers won't be 1 and 2. That
493 happens in C++. So it's a good thing it should no longer matter). */
495 #ifdef DBX_OUTPUT_STANDARD_TYPES
496 DBX_OUTPUT_STANDARD_TYPES (syms);
497 #else
498 dbxout_symbol (TYPE_NAME (integer_type_node), 0);
499 dbxout_symbol (TYPE_NAME (char_type_node), 0);
500 #endif
502 /* Get all permanent types that have typedef names,
503 and output them all, except for those already output. */
505 dbxout_typedefs (syms);
508 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
509 in the reverse order from that which is found in SYMS. */
511 static void
512 dbxout_typedefs (syms)
513 tree syms;
515 if (syms)
517 dbxout_typedefs (TREE_CHAIN (syms));
518 if (TREE_CODE (syms) == TYPE_DECL)
520 tree type = TREE_TYPE (syms);
521 if (TYPE_NAME (type)
522 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
523 && COMPLETE_TYPE_P (type)
524 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
525 dbxout_symbol (TYPE_NAME (type), 0);
530 /* Change to reading from a new source file. Generate a N_BINCL stab. */
532 static void
533 dbxout_start_source_file (line, filename)
534 unsigned int line ATTRIBUTE_UNUSED;
535 const char *filename ATTRIBUTE_UNUSED;
537 #ifdef DBX_USE_BINCL
538 struct dbx_file *n = (struct dbx_file *) ggc_alloc (sizeof *n);
540 n->next = current_file;
541 n->file_number = next_file_number++;
542 n->next_type_number = 1;
543 current_file = n;
544 fprintf (asmfile, "%s", ASM_STABS_OP);
545 output_quoted_string (asmfile, filename);
546 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
547 #endif
550 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
552 static void
553 dbxout_end_source_file (line)
554 unsigned int line ATTRIBUTE_UNUSED;
556 #ifdef DBX_USE_BINCL
557 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
558 current_file = current_file->next;
559 #endif
562 #if defined (DBX_DEBUGGING_INFO)
563 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
565 static void
566 dbxout_source_file (file, filename)
567 FILE *file;
568 const char *filename;
570 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
572 #ifdef DBX_OUTPUT_SOURCE_FILENAME
573 DBX_OUTPUT_SOURCE_FILENAME (file, filename);
574 #else
575 char ltext_label_name[100];
577 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
578 source_label_number);
579 fprintf (file, "%s", ASM_STABS_OP);
580 output_quoted_string (file, filename);
581 fprintf (asmfile, ",%d,0,0,", N_SOL);
582 assemble_name (asmfile, ltext_label_name);
583 fputc ('\n', asmfile);
584 if (current_function_decl != NULL_TREE
585 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
586 ; /* Don't change section amid function. */
587 else
588 text_section ();
589 (*targetm.asm_out.internal_label) (file, "Ltext", source_label_number);
590 source_label_number++;
591 #endif
592 lastfile = filename;
596 /* Output a line number symbol entry for source file FILENAME and line
597 number LINENO. */
599 static void
600 dbxout_source_line (lineno, filename)
601 unsigned int lineno;
602 const char *filename;
604 dbxout_source_file (asmfile, filename);
606 #ifdef ASM_OUTPUT_SOURCE_LINE
607 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno);
608 #else
609 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
610 #endif
613 /* Describe the beginning of an internal block within a function. */
615 static void
616 dbxout_begin_block (line, n)
617 unsigned int line ATTRIBUTE_UNUSED;
618 unsigned int n;
620 (*targetm.asm_out.internal_label) (asmfile, "LBB", n);
623 /* Describe the end line-number of an internal block within a function. */
625 static void
626 dbxout_end_block (line, n)
627 unsigned int line ATTRIBUTE_UNUSED;
628 unsigned int n;
630 (*targetm.asm_out.internal_label) (asmfile, "LBE", n);
633 /* Output dbx data for a function definition.
634 This includes a definition of the function name itself (a symbol),
635 definitions of the parameters (locating them in the parameter list)
636 and then output the block that makes up the function's body
637 (including all the auto variables of the function). */
639 static void
640 dbxout_function_decl (decl)
641 tree decl;
643 #ifndef DBX_FUNCTION_FIRST
644 dbxout_begin_function (decl);
645 #endif
646 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
647 #ifdef DBX_OUTPUT_FUNCTION_END
648 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
649 #endif
650 if (use_gnu_debug_info_extensions
651 #if defined(NO_DBX_FUNCTION_END)
652 && ! NO_DBX_FUNCTION_END
653 #endif
654 && targetm.have_named_sections)
655 dbxout_function_end ();
658 #endif /* DBX_DEBUGGING_INFO */
660 /* Debug information for a global DECL. Called from toplev.c after
661 compilation proper has finished. */
662 static void
663 dbxout_global_decl (decl)
664 tree decl;
666 if (TREE_CODE (decl) == VAR_DECL
667 && ! DECL_EXTERNAL (decl)
668 && DECL_RTL_SET_P (decl)) /* Not necessary? */
669 dbxout_symbol (decl, 0);
672 /* At the end of compilation, finish writing the symbol table.
673 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
674 to do nothing. */
676 static void
677 dbxout_finish (filename)
678 const char *filename ATTRIBUTE_UNUSED;
680 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
681 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
682 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
685 /* Output floating point type values used by the 'R' stab letter.
686 These numbers come from include/aout/stab_gnu.h in binutils/gdb.
688 There are only 3 real/complex types defined, and we need 7/6.
689 We use NF_SINGLE as a generic float type, and NF_COMPLEX as a generic
690 complex type. Since we have the type size anyways, we don't really need
691 to distinguish between different FP types, we only need to distinguish
692 between float and complex. This works fine with gdb.
694 We only use this for complex types, to avoid breaking backwards
695 compatibility for real types. complex types aren't in ISO C90, so it is
696 OK if old debuggers don't understand the debug info we emit for them. */
698 /* ??? These are supposed to be IEEE types, but we don't check for that.
699 We could perhaps add additional numbers for non-IEEE types if we need
700 them. */
702 static void
703 dbxout_fptype_value (type)
704 tree type;
706 char value = '0';
707 enum machine_mode mode = TYPE_MODE (type);
709 if (TREE_CODE (type) == REAL_TYPE)
711 if (mode == SFmode)
712 value = '1';
713 else if (mode == DFmode)
714 value = '2';
715 else if (mode == TFmode || mode == XFmode)
716 value = '6';
717 else
718 /* Use NF_SINGLE as a generic real type for other sizes. */
719 value = '1';
721 else if (TREE_CODE (type) == COMPLEX_TYPE)
723 if (mode == SCmode)
724 value = '3';
725 else if (mode == DCmode)
726 value = '4';
727 else if (mode == TCmode || mode == XCmode)
728 value = '5';
729 else
730 /* Use NF_COMPLEX as a generic complex type for other sizes. */
731 value = '3';
733 else
734 abort ();
736 putc (value, asmfile);
737 CHARS (1);
740 /* Output the index of a type. */
742 static void
743 dbxout_type_index (type)
744 tree type;
746 #ifndef DBX_USE_BINCL
747 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
748 CHARS (3);
749 #else
750 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
751 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
752 CHARS (9);
753 #endif
756 #if DBX_CONTIN_LENGTH > 0
757 /* Continue a symbol-description that gets too big.
758 End one symbol table entry with a double-backslash
759 and start a new one, eventually producing something like
760 .stabs "start......\\",code,0,value
761 .stabs "...rest",code,0,value */
763 static void
764 dbxout_continue ()
766 #ifdef DBX_CONTIN_CHAR
767 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
768 #else
769 fprintf (asmfile, "\\\\");
770 #endif
771 dbxout_finish_symbol (NULL_TREE);
772 fprintf (asmfile, "%s\"", ASM_STABS_OP);
773 current_sym_nchars = 0;
775 #endif /* DBX_CONTIN_LENGTH > 0 */
777 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
778 This must be a separate function because anonymous unions require
779 recursive calls. */
781 static void
782 dbxout_type_fields (type)
783 tree type;
785 tree tem;
787 /* Output the name, type, position (in bits), size (in bits) of each
788 field that we can support. */
789 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
791 /* Omit here local type decls until we know how to support them. */
792 if (TREE_CODE (tem) == TYPE_DECL
793 /* Omit fields whose position or size are variable or too large to
794 represent. */
795 || (TREE_CODE (tem) == FIELD_DECL
796 && (! host_integerp (bit_position (tem), 0)
797 || ! DECL_SIZE (tem)
798 || ! host_integerp (DECL_SIZE (tem), 1)))
799 /* Omit here the nameless fields that are used to skip bits. */
800 || DECL_IGNORED_P (tem))
801 continue;
803 else if (TREE_CODE (tem) != CONST_DECL)
805 /* Continue the line if necessary,
806 but not before the first field. */
807 if (tem != TYPE_FIELDS (type))
808 CONTIN;
810 if (DECL_NAME (tem))
812 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
813 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
815 else
817 fprintf (asmfile, ":");
818 CHARS (1);
821 if (use_gnu_debug_info_extensions
822 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
823 || TREE_CODE (tem) != FIELD_DECL))
825 have_used_extensions = 1;
826 putc ('/', asmfile);
827 putc ((TREE_PRIVATE (tem) ? '0'
828 : TREE_PROTECTED (tem) ? '1' : '2'),
829 asmfile);
830 CHARS (2);
833 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
834 && DECL_BIT_FIELD_TYPE (tem))
835 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
837 if (TREE_CODE (tem) == VAR_DECL)
839 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
841 tree name = DECL_ASSEMBLER_NAME (tem);
843 have_used_extensions = 1;
844 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
845 CHARS (IDENTIFIER_LENGTH (name) + 2);
847 else
849 /* If TEM is non-static, GDB won't understand it. */
850 fprintf (asmfile, ",0,0;");
851 CHARS (5);
854 else
856 putc (',', asmfile);
857 print_wide_int (int_bit_position (tem));
858 putc (',', asmfile);
859 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
860 putc (';', asmfile);
861 CHARS (3);
867 /* Subroutine of `dbxout_type_methods'. Output debug info about the
868 method described DECL. DEBUG_NAME is an encoding of the method's
869 type signature. ??? We may be able to do without DEBUG_NAME altogether
870 now. */
872 static void
873 dbxout_type_method_1 (decl, debug_name)
874 tree decl;
875 const char *debug_name;
877 char c1 = 'A', c2;
879 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
880 c2 = '?';
881 else /* it's a METHOD_TYPE. */
883 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
884 /* A for normal functions.
885 B for `const' member functions.
886 C for `volatile' member functions.
887 D for `const volatile' member functions. */
888 if (TYPE_READONLY (TREE_TYPE (firstarg)))
889 c1 += 1;
890 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
891 c1 += 2;
893 if (DECL_VINDEX (decl))
894 c2 = '*';
895 else
896 c2 = '.';
899 fprintf (asmfile, ":%s;%c%c%c", debug_name,
900 TREE_PRIVATE (decl) ? '0'
901 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
902 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
903 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
905 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
907 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
908 putc (';', asmfile);
909 CHARS (1);
910 dbxout_type (DECL_CONTEXT (decl), 0);
911 fprintf (asmfile, ";");
912 CHARS (1);
916 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
917 in TYPE. */
919 static void
920 dbxout_type_methods (type)
921 tree type;
923 /* C++: put out the method names and their parameter lists */
924 tree methods = TYPE_METHODS (type);
925 tree type_encoding;
926 tree fndecl;
927 tree last;
928 char formatted_type_identifier_length[16];
929 int type_identifier_length;
931 if (methods == NULL_TREE)
932 return;
934 type_encoding = DECL_NAME (TYPE_NAME (type));
936 #if 0
937 /* C++: Template classes break some assumptions made by this code about
938 the class names, constructor names, and encodings for assembler
939 label names. For now, disable output of dbx info for them. */
941 const char *ptr = IDENTIFIER_POINTER (type_encoding);
942 /* This should use index. (mrs) */
943 while (*ptr && *ptr != '<') ptr++;
944 if (*ptr != 0)
946 static int warned;
947 if (!warned)
948 warned = 1;
949 return;
952 #endif
954 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
956 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
958 if (TREE_CODE (methods) != TREE_VEC)
959 fndecl = methods;
960 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
961 fndecl = TREE_VEC_ELT (methods, 0);
962 else
963 fndecl = TREE_VEC_ELT (methods, 1);
965 while (fndecl)
967 int need_prefix = 1;
969 /* Group together all the methods for the same operation.
970 These differ in the types of the arguments. */
971 for (last = NULL_TREE;
972 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
973 fndecl = TREE_CHAIN (fndecl))
974 /* Output the name of the field (after overloading), as
975 well as the name of the field before overloading, along
976 with its parameter list */
978 /* This is the "mangled" name of the method.
979 It encodes the argument types. */
980 const char *debug_name;
982 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
983 include TEMPLATE_DECLs.) The debugger doesn't know what
984 to do with such entities anyhow. */
985 if (TREE_CODE (fndecl) != FUNCTION_DECL)
986 continue;
988 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
990 CONTIN;
992 last = fndecl;
994 /* Also ignore abstract methods; those are only interesting to
995 the DWARF backends. */
996 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
997 continue;
999 /* Redundantly output the plain name, since that's what gdb
1000 expects. */
1001 if (need_prefix)
1003 tree name = DECL_NAME (fndecl);
1004 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1005 CHARS (IDENTIFIER_LENGTH (name) + 2);
1006 need_prefix = 0;
1009 dbxout_type (TREE_TYPE (fndecl), 0);
1011 dbxout_type_method_1 (fndecl, debug_name);
1013 if (!need_prefix)
1015 putc (';', asmfile);
1016 CHARS (1);
1021 /* Emit a "range" type specification, which has the form:
1022 "r<index type>;<lower bound>;<upper bound>;".
1023 TYPE is an INTEGER_TYPE. */
1025 static void
1026 dbxout_range_type (type)
1027 tree type;
1029 fprintf (asmfile, "r");
1030 if (TREE_TYPE (type))
1031 dbxout_type (TREE_TYPE (type), 0);
1032 else if (TREE_CODE (type) != INTEGER_TYPE)
1033 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1034 else
1036 /* Traditionally, we made sure 'int' was type 1, and builtin types
1037 were defined to be sub-ranges of int. Unfortunately, this
1038 does not allow us to distinguish true sub-ranges from integer
1039 types. So, instead we define integer (non-sub-range) types as
1040 sub-ranges of themselves. This matters for Chill. If this isn't
1041 a subrange type, then we want to define it in terms of itself.
1042 However, in C, this may be an anonymous integer type, and we don't
1043 want to emit debug info referring to it. Just calling
1044 dbxout_type_index won't work anyways, because the type hasn't been
1045 defined yet. We make this work for both cases by checked to see
1046 whether this is a defined type, referring to it if it is, and using
1047 'int' otherwise. */
1048 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1049 dbxout_type_index (type);
1050 else
1051 dbxout_type_index (integer_type_node);
1054 if (TYPE_MIN_VALUE (type) != 0
1055 && host_integerp (TYPE_MIN_VALUE (type), 0))
1057 putc (';', asmfile);
1058 CHARS (1);
1059 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1061 else
1063 fprintf (asmfile, ";0");
1064 CHARS (2);
1067 if (TYPE_MAX_VALUE (type) != 0
1068 && host_integerp (TYPE_MAX_VALUE (type), 0))
1070 putc (';', asmfile);
1071 CHARS (1);
1072 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1073 putc (';', asmfile);
1074 CHARS (1);
1076 else
1078 fprintf (asmfile, ";-1;");
1079 CHARS (4);
1083 /* Output a reference to a type. If the type has not yet been
1084 described in the dbx output, output its definition now.
1085 For a type already defined, just refer to its definition
1086 using the type number.
1088 If FULL is nonzero, and the type has been described only with
1089 a forward-reference, output the definition now.
1090 If FULL is zero in this case, just refer to the forward-reference
1091 using the number previously allocated. */
1093 static void
1094 dbxout_type (type, full)
1095 tree type;
1096 int full;
1098 tree tem;
1099 tree main_variant;
1100 static int anonymous_type_number = 0;
1102 if (TREE_CODE (type) == VECTOR_TYPE)
1103 /* The frontend feeds us a representation for the vector as a struct
1104 containing an array. Pull out the array type. */
1105 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1107 /* If there was an input error and we don't really have a type,
1108 avoid crashing and write something that is at least valid
1109 by assuming `int'. */
1110 if (type == error_mark_node)
1111 type = integer_type_node;
1112 else
1114 if (TYPE_NAME (type)
1115 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1116 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1117 full = 0;
1120 /* Try to find the "main variant" with the same name. */
1121 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1122 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1123 main_variant = TREE_TYPE (TYPE_NAME (type));
1124 else
1125 main_variant = TYPE_MAIN_VARIANT (type);
1127 /* If we are not using extensions, stabs does not distinguish const and
1128 volatile, so there is no need to make them separate types. */
1129 if (!use_gnu_debug_info_extensions)
1130 type = main_variant;
1132 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1134 /* Type has no dbx number assigned. Assign next available number. */
1135 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1137 /* Make sure type vector is long enough to record about this type. */
1139 if (next_type_number == typevec_len)
1141 typevec
1142 = (struct typeinfo *) ggc_realloc (typevec,
1143 (typevec_len * 2
1144 * sizeof typevec[0]));
1145 memset ((char *) (typevec + typevec_len), 0,
1146 typevec_len * sizeof typevec[0]);
1147 typevec_len *= 2;
1150 #ifdef DBX_USE_BINCL
1151 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1152 = current_file->file_number;
1153 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1154 = current_file->next_type_number++;
1155 #endif
1158 /* Output the number of this type, to refer to it. */
1159 dbxout_type_index (type);
1161 #ifdef DBX_TYPE_DEFINED
1162 if (DBX_TYPE_DEFINED (type))
1163 return;
1164 #endif
1166 /* If this type's definition has been output or is now being output,
1167 that is all. */
1169 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1171 case TYPE_UNSEEN:
1172 break;
1173 case TYPE_XREF:
1174 /* If we have already had a cross reference,
1175 and either that's all we want or that's the best we could do,
1176 don't repeat the cross reference.
1177 Sun dbx crashes if we do. */
1178 if (! full || !COMPLETE_TYPE_P (type)
1179 /* No way in DBX fmt to describe a variable size. */
1180 || ! host_integerp (TYPE_SIZE (type), 1))
1181 return;
1182 break;
1183 case TYPE_DEFINED:
1184 return;
1187 #ifdef DBX_NO_XREFS
1188 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1189 leave the type-number completely undefined rather than output
1190 a cross-reference. If we have already used GNU debug info extensions,
1191 then it is OK to output a cross reference. This is necessary to get
1192 proper C++ debug output. */
1193 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1194 || TREE_CODE (type) == QUAL_UNION_TYPE
1195 || TREE_CODE (type) == ENUMERAL_TYPE)
1196 && ! use_gnu_debug_info_extensions)
1197 /* We must use the same test here as we use twice below when deciding
1198 whether to emit a cross-reference. */
1199 if ((TYPE_NAME (type) != 0
1200 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1201 && DECL_IGNORED_P (TYPE_NAME (type)))
1202 && !full)
1203 || !COMPLETE_TYPE_P (type)
1204 /* No way in DBX fmt to describe a variable size. */
1205 || ! host_integerp (TYPE_SIZE (type), 1))
1207 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1208 return;
1210 #endif
1212 /* Output a definition now. */
1214 fprintf (asmfile, "=");
1215 CHARS (1);
1217 /* Mark it as defined, so that if it is self-referent
1218 we will not get into an infinite recursion of definitions. */
1220 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1222 /* If this type is a variant of some other, hand off. Types with
1223 different names are usefully distinguished. We only distinguish
1224 cv-qualified types if we're using extensions. */
1225 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1227 putc ('k', asmfile);
1228 CHARS (1);
1229 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1230 return;
1232 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1234 putc ('B', asmfile);
1235 CHARS (1);
1236 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1237 return;
1239 else if (main_variant != TYPE_MAIN_VARIANT (type))
1241 /* 'type' is a typedef; output the type it refers to. */
1242 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1243 return;
1245 /* else continue. */
1247 switch (TREE_CODE (type))
1249 case VOID_TYPE:
1250 case LANG_TYPE:
1251 /* For a void type, just define it as itself; ie, "5=5".
1252 This makes us consider it defined
1253 without saying what it is. The debugger will make it
1254 a void type when the reference is seen, and nothing will
1255 ever override that default. */
1256 dbxout_type_index (type);
1257 break;
1259 case INTEGER_TYPE:
1260 if (type == char_type_node && ! TREE_UNSIGNED (type))
1262 /* Output the type `char' as a subrange of itself!
1263 I don't understand this definition, just copied it
1264 from the output of pcc.
1265 This used to use `r2' explicitly and we used to
1266 take care to make sure that `char' was type number 2. */
1267 fprintf (asmfile, "r");
1268 CHARS (1);
1269 dbxout_type_index (type);
1270 fprintf (asmfile, ";0;127;");
1271 CHARS (7);
1274 /* If this is a subtype of another integer type, always prefer to
1275 write it as a subtype. */
1276 else if (TREE_TYPE (type) != 0
1277 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1279 /* If the size is non-standard, say what it is if we can use
1280 GDB extensions. */
1282 if (use_gnu_debug_info_extensions
1283 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1285 have_used_extensions = 1;
1286 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1287 CHARS (5);
1290 dbxout_range_type (type);
1293 else
1295 /* If the size is non-standard, say what it is if we can use
1296 GDB extensions. */
1298 if (use_gnu_debug_info_extensions
1299 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1301 have_used_extensions = 1;
1302 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1303 CHARS (5);
1306 /* If we can use GDB extensions and the size is wider than a
1307 long (the size used by GDB to read them) or we may have
1308 trouble writing the bounds the usual way, write them in
1309 octal. Note the test is for the *target's* size of "long",
1310 not that of the host. The host test is just to make sure we
1311 can write it out in case the host wide int is narrower than the
1312 target "long". */
1314 /* For unsigned types, we use octal if they are the same size or
1315 larger. This is because we print the bounds as signed decimal,
1316 and hence they can't span same size unsigned types. */
1318 if (use_gnu_debug_info_extensions
1319 && TYPE_MIN_VALUE (type) != 0
1320 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1321 && TYPE_MAX_VALUE (type) != 0
1322 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1323 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1324 || ((TYPE_PRECISION (type)
1325 == TYPE_PRECISION (integer_type_node))
1326 && TREE_UNSIGNED (type))
1327 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1328 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1329 && TREE_UNSIGNED (type))))
1331 fprintf (asmfile, "r");
1332 CHARS (1);
1333 dbxout_type_index (type);
1334 fprintf (asmfile, ";");
1335 CHARS (1);
1336 print_int_cst_octal (TYPE_MIN_VALUE (type));
1337 fprintf (asmfile, ";");
1338 CHARS (1);
1339 print_int_cst_octal (TYPE_MAX_VALUE (type));
1340 fprintf (asmfile, ";");
1341 CHARS (1);
1344 else
1345 /* Output other integer types as subranges of `int'. */
1346 dbxout_range_type (type);
1349 break;
1351 case REAL_TYPE:
1352 /* This used to say `r1' and we used to take care
1353 to make sure that `int' was type number 1. */
1354 fprintf (asmfile, "r");
1355 CHARS (1);
1356 dbxout_type_index (integer_type_node);
1357 putc (';', asmfile);
1358 CHARS (1);
1359 print_wide_int (int_size_in_bytes (type));
1360 fputs (";0;", asmfile);
1361 CHARS (3);
1362 break;
1364 case CHAR_TYPE:
1365 if (use_gnu_debug_info_extensions)
1367 have_used_extensions = 1;
1368 fputs ("@s", asmfile);
1369 CHARS (2);
1370 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1371 fputs (";-20;", asmfile);
1372 CHARS (4);
1374 else
1376 /* Output the type `char' as a subrange of itself.
1377 That is what pcc seems to do. */
1378 fprintf (asmfile, "r");
1379 CHARS (1);
1380 dbxout_type_index (char_type_node);
1381 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1382 CHARS (7);
1384 break;
1386 case BOOLEAN_TYPE:
1387 if (use_gnu_debug_info_extensions)
1389 have_used_extensions = 1;
1390 fputs ("@s", asmfile);
1391 CHARS (2);
1392 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1393 fputs (";-16;", asmfile);
1394 CHARS (4);
1396 else /* Define as enumeral type (False, True) */
1398 fprintf (asmfile, "eFalse:0,True:1,;");
1399 CHARS (17);
1401 break;
1403 case FILE_TYPE:
1404 putc ('d', asmfile);
1405 CHARS (1);
1406 dbxout_type (TREE_TYPE (type), 0);
1407 break;
1409 case COMPLEX_TYPE:
1410 /* Differs from the REAL_TYPE by its new data type number */
1412 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1414 putc ('R', asmfile);
1415 CHARS (1);
1416 dbxout_fptype_value (type);
1417 putc (';', asmfile);
1418 CHARS (1);
1419 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1420 fputs (";0;", asmfile);
1421 CHARS (3);
1423 else
1425 /* Output a complex integer type as a structure,
1426 pending some other way to do it. */
1427 putc ('s', asmfile);
1428 CHARS (1);
1429 print_wide_int (int_size_in_bytes (type));
1430 fprintf (asmfile, "real:");
1431 CHARS (5);
1433 dbxout_type (TREE_TYPE (type), 0);
1434 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1435 CHARS (7);
1436 fprintf (asmfile, "imag:");
1437 CHARS (5);
1438 dbxout_type (TREE_TYPE (type), 0);
1439 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1440 TYPE_PRECISION (TREE_TYPE (type)));
1441 CHARS (10);
1443 break;
1445 case SET_TYPE:
1446 if (use_gnu_debug_info_extensions)
1448 have_used_extensions = 1;
1449 fputs ("@s", asmfile);
1450 CHARS (2);
1451 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1452 putc (';', asmfile);
1453 CHARS (1);
1455 /* Check if a bitstring type, which in Chill is
1456 different from a [power]set. */
1457 if (TYPE_STRING_FLAG (type))
1459 fprintf (asmfile, "@S;");
1460 CHARS (3);
1463 putc ('S', asmfile);
1464 CHARS (1);
1465 dbxout_type (TYPE_DOMAIN (type), 0);
1466 break;
1468 case ARRAY_TYPE:
1469 /* Make arrays of packed bits look like bitstrings for chill. */
1470 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1472 have_used_extensions = 1;
1473 fputs ("@s", asmfile);
1474 CHARS (2);
1475 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1476 fprintf (asmfile, ";@S;S");
1477 CHARS (5);
1478 dbxout_type (TYPE_DOMAIN (type), 0);
1479 break;
1482 /* Output "a" followed by a range type definition
1483 for the index type of the array
1484 followed by a reference to the target-type.
1485 ar1;0;N;M for a C array of type M and size N+1. */
1486 /* Check if a character string type, which in Chill is
1487 different from an array of characters. */
1488 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1490 have_used_extensions = 1;
1491 fprintf (asmfile, "@S;");
1492 CHARS (3);
1494 tem = TYPE_DOMAIN (type);
1495 if (tem == NULL)
1497 fprintf (asmfile, "ar");
1498 CHARS (2);
1499 dbxout_type_index (integer_type_node);
1500 fprintf (asmfile, ";0;-1;");
1501 CHARS (6);
1503 else
1505 fprintf (asmfile, "a");
1506 CHARS (1);
1507 dbxout_range_type (tem);
1510 dbxout_type (TREE_TYPE (type), 0);
1511 break;
1513 case RECORD_TYPE:
1514 case UNION_TYPE:
1515 case QUAL_UNION_TYPE:
1517 int i, n_baseclasses = 0;
1519 if (TYPE_BINFO (type) != 0
1520 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1521 && TYPE_BINFO_BASETYPES (type) != 0)
1522 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1524 /* Output a structure type. We must use the same test here as we
1525 use in the DBX_NO_XREFS case above. */
1526 if ((TYPE_NAME (type) != 0
1527 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1528 && DECL_IGNORED_P (TYPE_NAME (type)))
1529 && !full)
1530 || !COMPLETE_TYPE_P (type)
1531 /* No way in DBX fmt to describe a variable size. */
1532 || ! host_integerp (TYPE_SIZE (type), 1))
1534 /* If the type is just a cross reference, output one
1535 and mark the type as partially described.
1536 If it later becomes defined, we will output
1537 its real definition.
1538 If the type has a name, don't nest its definition within
1539 another type's definition; instead, output an xref
1540 and let the definition come when the name is defined. */
1541 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1542 CHARS (2);
1543 #if 0 /* This assertion is legitimately false in C++. */
1544 /* We shouldn't be outputting a reference to a type before its
1545 definition unless the type has a tag name.
1546 A typedef name without a tag name should be impossible. */
1547 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1548 abort ();
1549 #endif
1550 if (TYPE_NAME (type) != 0)
1551 dbxout_type_name (type);
1552 else
1554 fprintf (asmfile, "$$%d", anonymous_type_number++);
1555 CHARS (5);
1558 fprintf (asmfile, ":");
1559 CHARS (1);
1560 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1561 break;
1564 /* Identify record or union, and print its size. */
1565 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1566 CHARS (1);
1567 print_wide_int (int_size_in_bytes (type));
1569 if (use_gnu_debug_info_extensions)
1571 if (n_baseclasses)
1573 have_used_extensions = 1;
1574 fprintf (asmfile, "!%d,", n_baseclasses);
1575 CHARS (8);
1578 for (i = 0; i < n_baseclasses; i++)
1580 tree binfo = TYPE_BINFO (type);
1581 tree child = BINFO_BASETYPE (binfo, i);
1582 tree access = (BINFO_BASEACCESSES (binfo)
1583 ? BINFO_BASEACCESS (binfo, i) : access_public_node);
1585 if (use_gnu_debug_info_extensions)
1587 have_used_extensions = 1;
1588 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1589 putc (access == access_public_node ? '2' : '0', asmfile);
1590 CHARS (2);
1591 if (TREE_VIA_VIRTUAL (child)
1592 && strcmp (lang_hooks.name, "GNU C++") == 0)
1593 /* For a virtual base, print the (negative) offset within
1594 the vtable where we must look to find the necessary
1595 adjustment. */
1596 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1597 * BITS_PER_UNIT);
1598 else
1599 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1600 * BITS_PER_UNIT);
1601 putc (',', asmfile);
1602 CHARS (1);
1603 dbxout_type (BINFO_TYPE (child), 0);
1604 putc (';', asmfile);
1605 CHARS (1);
1607 else
1609 /* Print out the base class information with fields
1610 which have the same names at the types they hold. */
1611 dbxout_type_name (BINFO_TYPE (child));
1612 putc (':', asmfile);
1613 CHARS (1);
1614 dbxout_type (BINFO_TYPE (child), full);
1615 putc (',', asmfile);
1616 CHARS (1);
1617 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1618 * BITS_PER_UNIT);
1619 putc (',', asmfile);
1620 CHARS (1);
1621 print_wide_int (tree_low_cst (DECL_SIZE
1622 (TYPE_NAME
1623 (BINFO_TYPE (child))),
1625 * BITS_PER_UNIT);
1626 putc (';', asmfile);
1627 CHARS (1);
1632 /* Write out the field declarations. */
1633 dbxout_type_fields (type);
1634 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1636 have_used_extensions = 1;
1637 dbxout_type_methods (type);
1640 putc (';', asmfile);
1641 CHARS (1);
1643 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1644 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1645 && TYPE_VFIELD (type))
1647 have_used_extensions = 1;
1649 /* Tell GDB+ that it may keep reading. */
1650 putc ('~', asmfile);
1651 CHARS (1);
1653 /* We need to write out info about what field this class
1654 uses as its "main" vtable pointer field, because if this
1655 field is inherited from a base class, GDB cannot necessarily
1656 figure out which field it's using in time. */
1657 if (TYPE_VFIELD (type))
1659 putc ('%', asmfile);
1660 CHARS (1);
1661 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1664 putc (';', asmfile);
1665 CHARS (1);
1667 break;
1669 case ENUMERAL_TYPE:
1670 /* We must use the same test here as we use in the DBX_NO_XREFS case
1671 above. We simplify it a bit since an enum will never have a variable
1672 size. */
1673 if ((TYPE_NAME (type) != 0
1674 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1675 && DECL_IGNORED_P (TYPE_NAME (type)))
1676 && !full)
1677 || !COMPLETE_TYPE_P (type))
1679 fprintf (asmfile, "xe");
1680 CHARS (2);
1681 dbxout_type_name (type);
1682 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1683 putc (':', asmfile);
1684 CHARS (1);
1685 return;
1687 #ifdef DBX_OUTPUT_ENUM
1688 DBX_OUTPUT_ENUM (asmfile, type);
1689 #else
1690 if (use_gnu_debug_info_extensions
1691 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1693 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1694 CHARS (5);
1697 putc ('e', asmfile);
1698 CHARS (1);
1699 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1701 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1702 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1703 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1704 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1705 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1706 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1707 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1708 else
1709 print_int_cst_octal (TREE_VALUE (tem));
1711 putc (',', asmfile);
1712 CHARS (1);
1713 if (TREE_CHAIN (tem) != 0)
1714 CONTIN;
1717 putc (';', asmfile);
1718 CHARS (1);
1719 #endif
1720 break;
1722 case POINTER_TYPE:
1723 putc ('*', asmfile);
1724 CHARS (1);
1725 dbxout_type (TREE_TYPE (type), 0);
1726 break;
1728 case METHOD_TYPE:
1729 if (use_gnu_debug_info_extensions)
1731 have_used_extensions = 1;
1732 putc ('#', asmfile);
1733 CHARS (1);
1735 /* Write the argument types out longhand. */
1736 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1737 putc (',', asmfile);
1738 CHARS (1);
1739 dbxout_type (TREE_TYPE (type), 0);
1740 dbxout_args (TYPE_ARG_TYPES (type));
1741 putc (';', asmfile);
1742 CHARS (1);
1744 else
1745 /* Treat it as a function type. */
1746 dbxout_type (TREE_TYPE (type), 0);
1747 break;
1749 case OFFSET_TYPE:
1750 if (use_gnu_debug_info_extensions)
1752 have_used_extensions = 1;
1753 putc ('@', asmfile);
1754 CHARS (1);
1755 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1756 putc (',', asmfile);
1757 CHARS (1);
1758 dbxout_type (TREE_TYPE (type), 0);
1760 else
1761 /* Should print as an int, because it is really just an offset. */
1762 dbxout_type (integer_type_node, 0);
1763 break;
1765 case REFERENCE_TYPE:
1766 if (use_gnu_debug_info_extensions)
1767 have_used_extensions = 1;
1768 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1769 CHARS (1);
1770 dbxout_type (TREE_TYPE (type), 0);
1771 break;
1773 case FUNCTION_TYPE:
1774 putc ('f', asmfile);
1775 CHARS (1);
1776 dbxout_type (TREE_TYPE (type), 0);
1777 break;
1779 default:
1780 abort ();
1784 /* Print the value of integer constant C, in octal,
1785 handling double precision. */
1787 static void
1788 print_int_cst_octal (c)
1789 tree c;
1791 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1792 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1793 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1794 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1796 /* GDB wants constants with no extra leading "1" bits, so
1797 we need to remove any sign-extension that might be
1798 present. */
1799 if (width == HOST_BITS_PER_WIDE_INT * 2)
1801 else if (width > HOST_BITS_PER_WIDE_INT)
1802 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1803 else if (width == HOST_BITS_PER_WIDE_INT)
1804 high = 0;
1805 else
1806 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1808 fprintf (asmfile, "0");
1809 CHARS (1);
1811 if (excess == 3)
1813 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1814 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1816 else
1818 unsigned HOST_WIDE_INT beg = high >> excess;
1819 unsigned HOST_WIDE_INT middle
1820 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1821 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1822 unsigned HOST_WIDE_INT end
1823 = low & (((unsigned HOST_WIDE_INT) 1
1824 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1825 - 1);
1827 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1828 CHARS (2);
1829 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1833 static void
1834 print_octal (value, digits)
1835 unsigned HOST_WIDE_INT value;
1836 int digits;
1838 int i;
1840 for (i = digits - 1; i >= 0; i--)
1841 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1843 CHARS (digits);
1846 /* Output C in decimal while adjusting the number of digits written. */
1848 static void
1849 print_wide_int (c)
1850 HOST_WIDE_INT c;
1852 int digs = 0;
1854 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1856 if (c < 0)
1857 digs++, c = -c;
1859 while (c > 0)
1860 c /= 10; digs++;
1862 CHARS (digs);
1865 /* Output the name of type TYPE, with no punctuation.
1866 Such names can be set up either by typedef declarations
1867 or by struct, enum and union tags. */
1869 static void
1870 dbxout_type_name (type)
1871 tree type;
1873 tree t;
1874 if (TYPE_NAME (type) == 0)
1875 abort ();
1876 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1878 t = TYPE_NAME (type);
1880 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1882 t = DECL_NAME (TYPE_NAME (type));
1884 else
1885 abort ();
1887 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1888 CHARS (IDENTIFIER_LENGTH (t));
1891 /* Output leading leading struct or class names needed for qualifying
1892 type whose scope is limited to a struct or class. */
1894 static void
1895 dbxout_class_name_qualifiers (decl)
1896 tree decl;
1898 tree context = decl_type_context (decl);
1900 if (context != NULL_TREE
1901 && TREE_CODE(context) == RECORD_TYPE
1902 && TYPE_NAME (context) != 0
1903 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
1904 || (DECL_NAME (TYPE_NAME (context)) != 0)))
1906 tree name = TYPE_NAME (context);
1908 if (TREE_CODE (name) == TYPE_DECL)
1910 dbxout_class_name_qualifiers (name);
1911 name = DECL_NAME (name);
1913 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1914 CHARS (IDENTIFIER_LENGTH (name) + 2);
1918 /* Output a .stabs for the symbol defined by DECL,
1919 which must be a ..._DECL node in the normal namespace.
1920 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1921 LOCAL is nonzero if the scope is less than the entire file.
1922 Return 1 if a stabs might have been emitted. */
1925 dbxout_symbol (decl, local)
1926 tree decl;
1927 int local ATTRIBUTE_UNUSED;
1929 tree type = TREE_TYPE (decl);
1930 tree context = NULL_TREE;
1931 int result = 0;
1933 /* Cast avoids warning in old compilers. */
1934 current_sym_code = (STAB_CODE_TYPE) 0;
1935 current_sym_value = 0;
1936 current_sym_addr = 0;
1938 /* Ignore nameless syms, but don't ignore type tags. */
1940 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1941 || DECL_IGNORED_P (decl))
1942 return 0;
1944 dbxout_prepare_symbol (decl);
1946 /* The output will always start with the symbol name,
1947 so always count that in the length-output-so-far. */
1949 if (DECL_NAME (decl) != 0)
1950 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1952 switch (TREE_CODE (decl))
1954 case CONST_DECL:
1955 /* Enum values are defined by defining the enum type. */
1956 break;
1958 case FUNCTION_DECL:
1959 if (DECL_RTL (decl) == 0)
1960 return 0;
1961 if (DECL_EXTERNAL (decl))
1962 break;
1963 /* Don't mention a nested function under its parent. */
1964 context = decl_function_context (decl);
1965 if (context == current_function_decl)
1966 break;
1967 if (GET_CODE (DECL_RTL (decl)) != MEM
1968 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1969 break;
1970 FORCE_TEXT;
1972 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1973 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1974 TREE_PUBLIC (decl) ? 'F' : 'f');
1975 result = 1;
1977 current_sym_code = N_FUN;
1978 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1980 if (TREE_TYPE (type))
1981 dbxout_type (TREE_TYPE (type), 0);
1982 else
1983 dbxout_type (void_type_node, 0);
1985 /* For a nested function, when that function is compiled,
1986 mention the containing function name
1987 as well as (since dbx wants it) our own assembler-name. */
1988 if (context != 0)
1989 fprintf (asmfile, ",%s,%s",
1990 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1991 IDENTIFIER_POINTER (DECL_NAME (context)));
1993 dbxout_finish_symbol (decl);
1994 break;
1996 case TYPE_DECL:
1997 #if 0
1998 /* This seems all wrong. Outputting most kinds of types gives no name
1999 at all. A true definition gives no name; a cross-ref for a
2000 structure can give the tag name, but not a type name.
2001 It seems that no typedef name is defined by outputting a type. */
2003 /* If this typedef name was defined by outputting the type,
2004 don't duplicate it. */
2005 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
2006 && TYPE_NAME (TREE_TYPE (decl)) == decl)
2007 return 0;
2008 #endif
2009 /* Don't output the same typedef twice.
2010 And don't output what language-specific stuff doesn't want output. */
2011 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2012 return 0;
2014 FORCE_TEXT;
2015 result = 1;
2017 int tag_needed = 1;
2018 int did_output = 0;
2020 if (DECL_NAME (decl))
2022 /* Nonzero means we must output a tag as well as a typedef. */
2023 tag_needed = 0;
2025 /* Handle the case of a C++ structure or union
2026 where the TYPE_NAME is a TYPE_DECL
2027 which gives both a typedef name and a tag. */
2028 /* dbx requires the tag first and the typedef second. */
2029 if ((TREE_CODE (type) == RECORD_TYPE
2030 || TREE_CODE (type) == UNION_TYPE
2031 || TREE_CODE (type) == QUAL_UNION_TYPE)
2032 && TYPE_NAME (type) == decl
2033 && !(use_gnu_debug_info_extensions && have_used_extensions)
2034 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2035 /* Distinguish the implicit typedefs of C++
2036 from explicit ones that might be found in C. */
2037 && DECL_ARTIFICIAL (decl)
2038 /* Do not generate a tag for records of variable size,
2039 since this type can not be properly described in the
2040 DBX format, and it confuses some tools such as objdump. */
2041 && host_integerp (TYPE_SIZE (type), 1))
2043 tree name = TYPE_NAME (type);
2044 if (TREE_CODE (name) == TYPE_DECL)
2045 name = DECL_NAME (name);
2047 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2048 current_sym_value = 0;
2049 current_sym_addr = 0;
2050 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2052 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2053 IDENTIFIER_POINTER (name));
2054 dbxout_type (type, 1);
2055 dbxout_finish_symbol (NULL_TREE);
2058 /* Output .stabs (or whatever) and leading double quote. */
2059 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2061 if (use_gnu_debug_info_extensions)
2063 /* Output leading class/struct qualifiers. */
2064 dbxout_class_name_qualifiers (decl);
2067 /* Output typedef name. */
2068 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2070 /* Short cut way to output a tag also. */
2071 if ((TREE_CODE (type) == RECORD_TYPE
2072 || TREE_CODE (type) == UNION_TYPE
2073 || TREE_CODE (type) == QUAL_UNION_TYPE)
2074 && TYPE_NAME (type) == decl
2075 /* Distinguish the implicit typedefs of C++
2076 from explicit ones that might be found in C. */
2077 && DECL_ARTIFICIAL (decl))
2079 if (use_gnu_debug_info_extensions && have_used_extensions)
2081 putc ('T', asmfile);
2082 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2084 #if 0 /* Now we generate the tag for this case up above. */
2085 else
2086 tag_needed = 1;
2087 #endif
2090 putc ('t', asmfile);
2091 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2093 dbxout_type (type, 1);
2094 dbxout_finish_symbol (decl);
2095 did_output = 1;
2098 /* Don't output a tag if this is an incomplete type. This prevents
2099 the sun4 Sun OS 4.x dbx from crashing. */
2101 if (tag_needed && TYPE_NAME (type) != 0
2102 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2103 || (DECL_NAME (TYPE_NAME (type)) != 0))
2104 && COMPLETE_TYPE_P (type)
2105 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2107 /* For a TYPE_DECL with no name, but the type has a name,
2108 output a tag.
2109 This is what represents `struct foo' with no typedef. */
2110 /* In C++, the name of a type is the corresponding typedef.
2111 In C, it is an IDENTIFIER_NODE. */
2112 tree name = TYPE_NAME (type);
2113 if (TREE_CODE (name) == TYPE_DECL)
2114 name = DECL_NAME (name);
2116 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2117 current_sym_value = 0;
2118 current_sym_addr = 0;
2119 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2121 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2122 IDENTIFIER_POINTER (name));
2123 dbxout_type (type, 1);
2124 dbxout_finish_symbol (NULL_TREE);
2125 did_output = 1;
2128 /* If an enum type has no name, it cannot be referred to,
2129 but we must output it anyway, since the enumeration constants
2130 can be referred to. */
2131 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2133 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2134 current_sym_value = 0;
2135 current_sym_addr = 0;
2136 current_sym_nchars = 2;
2138 /* Some debuggers fail when given NULL names, so give this a
2139 harmless name of ` '. */
2140 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2141 dbxout_type (type, 1);
2142 dbxout_finish_symbol (NULL_TREE);
2145 /* Prevent duplicate output of a typedef. */
2146 TREE_ASM_WRITTEN (decl) = 1;
2147 break;
2150 case PARM_DECL:
2151 /* Parm decls go in their own separate chains
2152 and are output by dbxout_reg_parms and dbxout_parms. */
2153 abort ();
2155 case RESULT_DECL:
2156 /* Named return value, treat like a VAR_DECL. */
2157 case VAR_DECL:
2158 if (! DECL_RTL_SET_P (decl))
2159 return 0;
2160 /* Don't mention a variable that is external.
2161 Let the file that defines it describe it. */
2162 if (DECL_EXTERNAL (decl))
2163 break;
2165 /* If the variable is really a constant
2166 and not written in memory, inform the debugger. */
2167 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2168 && DECL_INITIAL (decl) != 0
2169 && host_integerp (DECL_INITIAL (decl), 0)
2170 && ! TREE_ASM_WRITTEN (decl)
2171 && (DECL_CONTEXT (decl) == NULL_TREE
2172 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2174 if (TREE_PUBLIC (decl) == 0)
2176 /* The sun4 assembler does not grok this. */
2177 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2179 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2180 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2182 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2183 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
2184 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
2185 #else
2186 fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
2188 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
2189 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
2190 #endif
2191 return 1;
2193 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2195 /* don't know how to do this yet. */
2197 break;
2199 /* else it is something we handle like a normal variable. */
2202 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2203 #ifdef LEAF_REG_REMAP
2204 if (current_function_uses_only_leaf_regs)
2205 leaf_renumber_regs_insn (DECL_RTL (decl));
2206 #endif
2208 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2209 break;
2211 default:
2212 break;
2214 return result;
2217 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2218 Add SUFFIX to its name, if SUFFIX is not 0.
2219 Describe the variable as residing in HOME
2220 (usually HOME is DECL_RTL (DECL), but not always).
2221 Returns 1 if the stab was really emitted. */
2223 static int
2224 dbxout_symbol_location (decl, type, suffix, home)
2225 tree decl, type;
2226 const char *suffix;
2227 rtx home;
2229 int letter = 0;
2230 int regno = -1;
2232 /* Don't mention a variable at all
2233 if it was completely optimized into nothingness.
2235 If the decl was from an inline function, then its rtl
2236 is not identically the rtl that was used in this
2237 particular compilation. */
2238 if (GET_CODE (home) == SUBREG)
2240 rtx value = home;
2242 while (GET_CODE (value) == SUBREG)
2243 value = SUBREG_REG (value);
2244 if (GET_CODE (value) == REG)
2246 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2247 return 0;
2249 home = alter_subreg (&home);
2251 if (GET_CODE (home) == REG)
2253 regno = REGNO (home);
2254 if (regno >= FIRST_PSEUDO_REGISTER)
2255 return 0;
2258 /* The kind-of-variable letter depends on where
2259 the variable is and on the scope of its name:
2260 G and N_GSYM for static storage and global scope,
2261 S for static storage and file scope,
2262 V for static storage and local scope,
2263 for those two, use N_LCSYM if data is in bss segment,
2264 N_STSYM if in data segment, N_FUN otherwise.
2265 (We used N_FUN originally, then changed to N_STSYM
2266 to please GDB. However, it seems that confused ld.
2267 Now GDB has been fixed to like N_FUN, says Kingdon.)
2268 no letter at all, and N_LSYM, for auto variable,
2269 r and N_RSYM for register variable. */
2271 if (GET_CODE (home) == MEM
2272 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2274 if (TREE_PUBLIC (decl))
2276 letter = 'G';
2277 current_sym_code = N_GSYM;
2279 else
2281 current_sym_addr = XEXP (home, 0);
2283 letter = decl_function_context (decl) ? 'V' : 'S';
2285 /* This should be the same condition as in assemble_variable, but
2286 we don't have access to dont_output_data here. So, instead,
2287 we rely on the fact that error_mark_node initializers always
2288 end up in bss for C++ and never end up in bss for C. */
2289 if (DECL_INITIAL (decl) == 0
2290 || (!strcmp (lang_hooks.name, "GNU C++")
2291 && DECL_INITIAL (decl) == error_mark_node))
2292 current_sym_code = N_LCSYM;
2293 else if (DECL_IN_TEXT_SECTION (decl))
2294 /* This is not quite right, but it's the closest
2295 of all the codes that Unix defines. */
2296 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2297 else
2299 /* Some ports can transform a symbol ref into a label ref,
2300 because the symbol ref is too far away and has to be
2301 dumped into a constant pool. Alternatively, the symbol
2302 in the constant pool might be referenced by a different
2303 symbol. */
2304 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2305 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2307 rtx tmp = get_pool_constant (current_sym_addr);
2309 if (GET_CODE (tmp) == SYMBOL_REF
2310 || GET_CODE (tmp) == LABEL_REF)
2311 current_sym_addr = tmp;
2314 /* Ultrix `as' seems to need this. */
2315 #ifdef DBX_STATIC_STAB_DATA_SECTION
2316 data_section ();
2317 #endif
2318 current_sym_code = N_STSYM;
2322 else if (regno >= 0)
2324 letter = 'r';
2325 current_sym_code = N_RSYM;
2326 current_sym_value = DBX_REGISTER_NUMBER (regno);
2328 else if (GET_CODE (home) == MEM
2329 && (GET_CODE (XEXP (home, 0)) == MEM
2330 || (GET_CODE (XEXP (home, 0)) == REG
2331 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2332 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2333 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2334 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2335 #endif
2337 /* If the value is indirect by memory or by a register
2338 that isn't the frame pointer
2339 then it means the object is variable-sized and address through
2340 that register or stack slot. DBX has no way to represent this
2341 so all we can do is output the variable as a pointer.
2342 If it's not a parameter, ignore it.
2343 (VAR_DECLs like this can be made by integrate.c.) */
2345 if (GET_CODE (XEXP (home, 0)) == REG)
2347 letter = 'r';
2348 current_sym_code = N_RSYM;
2349 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2350 return 0;
2351 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2353 else
2355 current_sym_code = N_LSYM;
2356 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2357 We want the value of that CONST_INT. */
2358 current_sym_value
2359 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2362 /* Effectively do build_pointer_type, but don't cache this type,
2363 since it might be temporary whereas the type it points to
2364 might have been saved for inlining. */
2365 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2366 type = make_node (POINTER_TYPE);
2367 TREE_TYPE (type) = TREE_TYPE (decl);
2369 else if (GET_CODE (home) == MEM
2370 && GET_CODE (XEXP (home, 0)) == REG)
2372 current_sym_code = N_LSYM;
2373 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2375 else if (GET_CODE (home) == MEM
2376 && GET_CODE (XEXP (home, 0)) == PLUS
2377 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2379 current_sym_code = N_LSYM;
2380 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2381 We want the value of that CONST_INT. */
2382 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2384 else if (GET_CODE (home) == MEM
2385 && GET_CODE (XEXP (home, 0)) == CONST)
2387 /* Handle an obscure case which can arise when optimizing and
2388 when there are few available registers. (This is *always*
2389 the case for i386/i486 targets). The RTL looks like
2390 (MEM (CONST ...)) even though this variable is a local `auto'
2391 or a local `register' variable. In effect, what has happened
2392 is that the reload pass has seen that all assignments and
2393 references for one such a local variable can be replaced by
2394 equivalent assignments and references to some static storage
2395 variable, thereby avoiding the need for a register. In such
2396 cases we're forced to lie to debuggers and tell them that
2397 this variable was itself `static'. */
2398 current_sym_code = N_LCSYM;
2399 letter = 'V';
2400 current_sym_addr = XEXP (XEXP (home, 0), 0);
2402 else if (GET_CODE (home) == CONCAT)
2404 tree subtype;
2406 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2407 for example), then there is no easy way to figure out
2408 what SUBTYPE should be. So, we give up. */
2409 if (TREE_CODE (type) != COMPLEX_TYPE)
2410 return 0;
2412 subtype = TREE_TYPE (type);
2414 /* If the variable's storage is in two parts,
2415 output each as a separate stab with a modified name. */
2416 if (WORDS_BIG_ENDIAN)
2417 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2418 else
2419 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2421 /* Cast avoids warning in old compilers. */
2422 current_sym_code = (STAB_CODE_TYPE) 0;
2423 current_sym_value = 0;
2424 current_sym_addr = 0;
2425 dbxout_prepare_symbol (decl);
2427 if (WORDS_BIG_ENDIAN)
2428 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2429 else
2430 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2431 return 1;
2433 else
2434 /* Address might be a MEM, when DECL is a variable-sized object.
2435 Or it might be const0_rtx, meaning previous passes
2436 want us to ignore this variable. */
2437 return 0;
2439 /* Ok, start a symtab entry and output the variable name. */
2440 FORCE_TEXT;
2442 #ifdef DBX_STATIC_BLOCK_START
2443 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2444 #endif
2446 dbxout_symbol_name (decl, suffix, letter);
2447 dbxout_type (type, 0);
2448 dbxout_finish_symbol (decl);
2450 #ifdef DBX_STATIC_BLOCK_END
2451 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2452 #endif
2453 return 1;
2456 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2457 Then output LETTER to indicate the kind of location the symbol has. */
2459 static void
2460 dbxout_symbol_name (decl, suffix, letter)
2461 tree decl;
2462 const char *suffix;
2463 int letter;
2465 const char *name;
2467 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2468 /* One slight hitch: if this is a VAR_DECL which is a static
2469 class member, we must put out the mangled name instead of the
2470 DECL_NAME. Note also that static member (variable) names DO NOT begin
2471 with underscores in .stabs directives. */
2472 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2473 else
2474 /* ...but if we're function-local, we don't want to include the junk
2475 added by ASM_FORMAT_PRIVATE_NAME. */
2476 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2478 if (name == 0)
2479 name = "(anon)";
2480 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2481 (suffix ? suffix : ""));
2483 if (letter)
2484 putc (letter, asmfile);
2487 static void
2488 dbxout_prepare_symbol (decl)
2489 tree decl ATTRIBUTE_UNUSED;
2491 #ifdef WINNING_GDB
2492 const char *filename = DECL_SOURCE_FILE (decl);
2494 dbxout_source_file (asmfile, filename);
2495 #endif
2498 static void
2499 dbxout_finish_symbol (sym)
2500 tree sym;
2502 #ifdef DBX_FINISH_SYMBOL
2503 DBX_FINISH_SYMBOL (sym);
2504 #else
2505 int line = 0;
2506 if (use_gnu_debug_info_extensions && sym != 0)
2507 line = DECL_SOURCE_LINE (sym);
2509 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2510 if (current_sym_addr)
2511 output_addr_const (asmfile, current_sym_addr);
2512 else
2513 fprintf (asmfile, "%d", current_sym_value);
2514 putc ('\n', asmfile);
2515 #endif
2518 /* Output definitions of all the decls in a chain. Return nonzero if
2519 anything was output */
2522 dbxout_syms (syms)
2523 tree syms;
2525 int result = 0;
2526 while (syms)
2528 result += dbxout_symbol (syms, 1);
2529 syms = TREE_CHAIN (syms);
2531 return result;
2534 /* The following two functions output definitions of function parameters.
2535 Each parameter gets a definition locating it in the parameter list.
2536 Each parameter that is a register variable gets a second definition
2537 locating it in the register.
2539 Printing or argument lists in gdb uses the definitions that
2540 locate in the parameter list. But reference to the variable in
2541 expressions uses preferentially the definition as a register. */
2543 /* Output definitions, referring to storage in the parmlist,
2544 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2546 void
2547 dbxout_parms (parms)
2548 tree parms;
2550 for (; parms; parms = TREE_CHAIN (parms))
2551 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2553 dbxout_prepare_symbol (parms);
2555 /* Perform any necessary register eliminations on the parameter's rtl,
2556 so that the debugging output will be accurate. */
2557 DECL_INCOMING_RTL (parms)
2558 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2559 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2560 #ifdef LEAF_REG_REMAP
2561 if (current_function_uses_only_leaf_regs)
2563 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2564 leaf_renumber_regs_insn (DECL_RTL (parms));
2566 #endif
2568 if (PARM_PASSED_IN_MEMORY (parms))
2570 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2572 /* ??? Here we assume that the parm address is indexed
2573 off the frame pointer or arg pointer.
2574 If that is not true, we produce meaningless results,
2575 but do not crash. */
2576 if (GET_CODE (addr) == PLUS
2577 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2578 current_sym_value = INTVAL (XEXP (addr, 1));
2579 else
2580 current_sym_value = 0;
2582 current_sym_code = N_PSYM;
2583 current_sym_addr = 0;
2585 FORCE_TEXT;
2586 if (DECL_NAME (parms))
2588 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2590 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2591 IDENTIFIER_POINTER (DECL_NAME (parms)),
2592 DBX_MEMPARM_STABS_LETTER);
2594 else
2596 current_sym_nchars = 8;
2597 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2598 DBX_MEMPARM_STABS_LETTER);
2601 /* It is quite tempting to use:
2603 dbxout_type (TREE_TYPE (parms), 0);
2605 as the next statement, rather than using DECL_ARG_TYPE(), so
2606 that gcc reports the actual type of the parameter, rather
2607 than the promoted type. This certainly makes GDB's life
2608 easier, at least for some ports. The change is a bad idea
2609 however, since GDB expects to be able access the type without
2610 performing any conversions. So for example, if we were
2611 passing a float to an unprototyped function, gcc will store a
2612 double on the stack, but if we emit a stab saying the type is a
2613 float, then gdb will only read in a single value, and this will
2614 produce an erroneous value. */
2615 dbxout_type (DECL_ARG_TYPE (parms), 0);
2616 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2617 dbxout_finish_symbol (parms);
2619 else if (GET_CODE (DECL_RTL (parms)) == REG)
2621 rtx best_rtl;
2622 char regparm_letter;
2623 tree parm_type;
2624 /* Parm passed in registers and lives in registers or nowhere. */
2626 current_sym_code = DBX_REGPARM_STABS_CODE;
2627 regparm_letter = DBX_REGPARM_STABS_LETTER;
2628 current_sym_addr = 0;
2630 /* If parm lives in a register, use that register;
2631 pretend the parm was passed there. It would be more consistent
2632 to describe the register where the parm was passed,
2633 but in practice that register usually holds something else.
2635 If we use DECL_RTL, then we must use the declared type of
2636 the variable, not the type that it arrived in. */
2637 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2639 best_rtl = DECL_RTL (parms);
2640 parm_type = TREE_TYPE (parms);
2642 /* If the parm lives nowhere, use the register where it was
2643 passed. It is also better to use the declared type here. */
2644 else
2646 best_rtl = DECL_INCOMING_RTL (parms);
2647 parm_type = TREE_TYPE (parms);
2649 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2651 FORCE_TEXT;
2652 if (DECL_NAME (parms))
2654 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2655 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2656 IDENTIFIER_POINTER (DECL_NAME (parms)),
2657 regparm_letter);
2659 else
2661 current_sym_nchars = 8;
2662 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2663 regparm_letter);
2666 dbxout_type (parm_type, 0);
2667 dbxout_finish_symbol (parms);
2669 else if (GET_CODE (DECL_RTL (parms)) == MEM
2670 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2671 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2672 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2673 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2674 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2675 #endif
2678 /* Parm was passed via invisible reference.
2679 That is, its address was passed in a register.
2680 Output it as if it lived in that register.
2681 The debugger will know from the type
2682 that it was actually passed by invisible reference. */
2684 char regparm_letter;
2685 /* Parm passed in registers and lives in registers or nowhere. */
2687 current_sym_code = DBX_REGPARM_STABS_CODE;
2688 if (use_gnu_debug_info_extensions)
2689 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2690 else
2691 regparm_letter = DBX_REGPARM_STABS_LETTER;
2693 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2694 If it is an unallocated pseudo-reg, then use the register where
2695 it was passed instead. */
2696 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2697 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2698 else
2699 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2701 current_sym_addr = 0;
2703 FORCE_TEXT;
2704 if (DECL_NAME (parms))
2706 current_sym_nchars
2707 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2709 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2710 IDENTIFIER_POINTER (DECL_NAME (parms)),
2711 regparm_letter);
2713 else
2715 current_sym_nchars = 8;
2716 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2717 regparm_letter);
2720 dbxout_type (TREE_TYPE (parms), 0);
2721 dbxout_finish_symbol (parms);
2723 else if (GET_CODE (DECL_RTL (parms)) == MEM
2724 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2726 /* Parm was passed via invisible reference, with the reference
2727 living on the stack. DECL_RTL looks like
2728 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2729 could look like (MEM (MEM (REG))). */
2730 const char *const decl_name = (DECL_NAME (parms)
2731 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2732 : "(anon)");
2733 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2734 current_sym_value = 0;
2735 else
2736 current_sym_value
2737 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2738 current_sym_addr = 0;
2739 current_sym_code = N_PSYM;
2741 FORCE_TEXT;
2742 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2744 current_sym_value
2745 = DEBUGGER_ARG_OFFSET (current_sym_value,
2746 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2747 dbxout_type (TREE_TYPE (parms), 0);
2748 dbxout_finish_symbol (parms);
2750 else if (GET_CODE (DECL_RTL (parms)) == MEM
2751 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2752 /* ??? A constant address for a parm can happen
2753 when the reg it lives in is equiv to a constant in memory.
2754 Should make this not happen, after 2.4. */
2755 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2757 /* Parm was passed in registers but lives on the stack. */
2759 current_sym_code = N_PSYM;
2760 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2761 in which case we want the value of that CONST_INT,
2762 or (MEM (REG ...)),
2763 in which case we use a value of zero. */
2764 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2765 current_sym_value = 0;
2766 else
2767 current_sym_value
2768 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2770 current_sym_addr = 0;
2772 /* Make a big endian correction if the mode of the type of the
2773 parameter is not the same as the mode of the rtl. */
2774 if (BYTES_BIG_ENDIAN
2775 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2776 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2778 current_sym_value +=
2779 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2780 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2783 FORCE_TEXT;
2784 if (DECL_NAME (parms))
2786 current_sym_nchars
2787 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2789 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2790 IDENTIFIER_POINTER (DECL_NAME (parms)),
2791 DBX_MEMPARM_STABS_LETTER);
2793 else
2795 current_sym_nchars = 8;
2796 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2797 DBX_MEMPARM_STABS_LETTER);
2800 current_sym_value
2801 = DEBUGGER_ARG_OFFSET (current_sym_value,
2802 XEXP (DECL_RTL (parms), 0));
2803 dbxout_type (TREE_TYPE (parms), 0);
2804 dbxout_finish_symbol (parms);
2809 /* Output definitions for the places where parms live during the function,
2810 when different from where they were passed, when the parms were passed
2811 in memory.
2813 It is not useful to do this for parms passed in registers
2814 that live during the function in different registers, because it is
2815 impossible to look in the passed register for the passed value,
2816 so we use the within-the-function register to begin with.
2818 PARMS is a chain of PARM_DECL nodes. */
2820 void
2821 dbxout_reg_parms (parms)
2822 tree parms;
2824 for (; parms; parms = TREE_CHAIN (parms))
2825 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2827 dbxout_prepare_symbol (parms);
2829 /* Report parms that live in registers during the function
2830 but were passed in memory. */
2831 if (GET_CODE (DECL_RTL (parms)) == REG
2832 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2833 dbxout_symbol_location (parms, TREE_TYPE (parms),
2834 0, DECL_RTL (parms));
2835 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2836 dbxout_symbol_location (parms, TREE_TYPE (parms),
2837 0, DECL_RTL (parms));
2838 /* Report parms that live in memory but not where they were passed. */
2839 else if (GET_CODE (DECL_RTL (parms)) == MEM
2840 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2841 dbxout_symbol_location (parms, TREE_TYPE (parms),
2842 0, DECL_RTL (parms));
2846 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2847 output definitions of those names, in raw form */
2849 static void
2850 dbxout_args (args)
2851 tree args;
2853 while (args)
2855 putc (',', asmfile);
2856 dbxout_type (TREE_VALUE (args), 0);
2857 CHARS (1);
2858 args = TREE_CHAIN (args);
2862 /* Output everything about a symbol block (a BLOCK node
2863 that represents a scope level),
2864 including recursive output of contained blocks.
2866 BLOCK is the BLOCK node.
2867 DEPTH is its depth within containing symbol blocks.
2868 ARGS is usually zero; but for the outermost block of the
2869 body of a function, it is a chain of PARM_DECLs for the function parameters.
2870 We output definitions of all the register parms
2871 as if they were local variables of that block.
2873 If -g1 was used, we count blocks just the same, but output nothing
2874 except for the outermost block.
2876 Actually, BLOCK may be several blocks chained together.
2877 We handle them all in sequence. */
2879 static void
2880 dbxout_block (block, depth, args)
2881 tree block;
2882 int depth;
2883 tree args;
2885 int blocknum = -1;
2887 #if DBX_BLOCKS_FUNCTION_RELATIVE
2888 const char *begin_label;
2889 if (current_function_func_begin_label != NULL_TREE)
2890 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2891 else
2892 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2893 #endif
2895 while (block)
2897 /* Ignore blocks never expanded or otherwise marked as real. */
2898 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2900 int did_output;
2902 #ifdef DBX_LBRAC_FIRST
2903 did_output = 1;
2904 #else
2905 /* In dbx format, the syms of a block come before the N_LBRAC.
2906 If nothing is output, we don't need the N_LBRAC, either. */
2907 did_output = 0;
2908 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2909 did_output = dbxout_syms (BLOCK_VARS (block));
2910 if (args)
2911 dbxout_reg_parms (args);
2912 #endif
2914 /* Now output an N_LBRAC symbol to represent the beginning of
2915 the block. Use the block's tree-walk order to generate
2916 the assembler symbols LBBn and LBEn
2917 that final will define around the code in this block. */
2918 if (depth > 0 && did_output)
2920 char buf[20];
2921 blocknum = BLOCK_NUMBER (block);
2922 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2924 if (BLOCK_HANDLER_BLOCK (block))
2926 /* A catch block. Must precede N_LBRAC. */
2927 tree decl = BLOCK_VARS (block);
2928 while (decl)
2930 #ifdef DBX_OUTPUT_CATCH
2931 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2932 #else
2933 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2934 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2935 assemble_name (asmfile, buf);
2936 fprintf (asmfile, "\n");
2937 #endif
2938 decl = TREE_CHAIN (decl);
2942 #ifdef DBX_OUTPUT_LBRAC
2943 DBX_OUTPUT_LBRAC (asmfile, buf);
2944 #else
2945 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2946 assemble_name (asmfile, buf);
2947 #if DBX_BLOCKS_FUNCTION_RELATIVE
2948 putc ('-', asmfile);
2949 assemble_name (asmfile, begin_label);
2950 #endif
2951 fprintf (asmfile, "\n");
2952 #endif
2955 #ifdef DBX_LBRAC_FIRST
2956 /* On some weird machines, the syms of a block
2957 come after the N_LBRAC. */
2958 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2959 dbxout_syms (BLOCK_VARS (block));
2960 if (args)
2961 dbxout_reg_parms (args);
2962 #endif
2964 /* Output the subblocks. */
2965 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2967 /* Refer to the marker for the end of the block. */
2968 if (depth > 0 && did_output)
2970 char buf[20];
2971 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2972 #ifdef DBX_OUTPUT_RBRAC
2973 DBX_OUTPUT_RBRAC (asmfile, buf);
2974 #else
2975 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2976 assemble_name (asmfile, buf);
2977 #if DBX_BLOCKS_FUNCTION_RELATIVE
2978 putc ('-', asmfile);
2979 assemble_name (asmfile, begin_label);
2980 #endif
2981 fprintf (asmfile, "\n");
2982 #endif
2985 block = BLOCK_CHAIN (block);
2989 /* Output the information about a function and its arguments and result.
2990 Usually this follows the function's code,
2991 but on some systems, it comes before. */
2993 #if defined (DBX_DEBUGGING_INFO)
2994 static void
2995 dbxout_begin_function (decl)
2996 tree decl;
2998 dbxout_symbol (decl, 0);
2999 dbxout_parms (DECL_ARGUMENTS (decl));
3000 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3001 dbxout_symbol (DECL_RESULT (decl), 1);
3003 #endif /* DBX_DEBUGGING_INFO */
3005 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3007 #include "gt-dbxout.h"