index.html: Correct link to libg++ information.
[official-gcc.git] / gcc / dbxout.c
blob468ee0969d386c01aacab024776c1be26e75c823
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 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 child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1582 if (use_gnu_debug_info_extensions)
1584 have_used_extensions = 1;
1585 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1586 putc (TREE_VIA_PUBLIC (child) ? '2' : '0', asmfile);
1587 CHARS (2);
1588 if (TREE_VIA_VIRTUAL (child) && strcmp (lang_hooks.name, "GNU C++") == 0)
1589 /* For a virtual base, print the (negative) offset within
1590 the vtable where we must look to find the necessary
1591 adjustment. */
1592 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1593 * BITS_PER_UNIT);
1594 else
1595 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1596 * BITS_PER_UNIT);
1597 putc (',', asmfile);
1598 CHARS (1);
1599 dbxout_type (BINFO_TYPE (child), 0);
1600 putc (';', asmfile);
1601 CHARS (1);
1603 else
1605 /* Print out the base class information with fields
1606 which have the same names at the types they hold. */
1607 dbxout_type_name (BINFO_TYPE (child));
1608 putc (':', asmfile);
1609 CHARS (1);
1610 dbxout_type (BINFO_TYPE (child), full);
1611 putc (',', asmfile);
1612 CHARS (1);
1613 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1614 * BITS_PER_UNIT);
1615 putc (',', asmfile);
1616 CHARS (1);
1617 print_wide_int (tree_low_cst (DECL_SIZE
1618 (TYPE_NAME
1619 (BINFO_TYPE (child))),
1621 * BITS_PER_UNIT);
1622 putc (';', asmfile);
1623 CHARS (1);
1628 /* Write out the field declarations. */
1629 dbxout_type_fields (type);
1630 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1632 have_used_extensions = 1;
1633 dbxout_type_methods (type);
1636 putc (';', asmfile);
1637 CHARS (1);
1639 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1640 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1641 && TYPE_VFIELD (type))
1643 have_used_extensions = 1;
1645 /* Tell GDB+ that it may keep reading. */
1646 putc ('~', asmfile);
1647 CHARS (1);
1649 /* We need to write out info about what field this class
1650 uses as its "main" vtable pointer field, because if this
1651 field is inherited from a base class, GDB cannot necessarily
1652 figure out which field it's using in time. */
1653 if (TYPE_VFIELD (type))
1655 putc ('%', asmfile);
1656 CHARS (1);
1657 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1660 putc (';', asmfile);
1661 CHARS (1);
1663 break;
1665 case ENUMERAL_TYPE:
1666 /* We must use the same test here as we use in the DBX_NO_XREFS case
1667 above. We simplify it a bit since an enum will never have a variable
1668 size. */
1669 if ((TYPE_NAME (type) != 0
1670 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1671 && DECL_IGNORED_P (TYPE_NAME (type)))
1672 && !full)
1673 || !COMPLETE_TYPE_P (type))
1675 fprintf (asmfile, "xe");
1676 CHARS (2);
1677 dbxout_type_name (type);
1678 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1679 putc (':', asmfile);
1680 CHARS (1);
1681 return;
1683 #ifdef DBX_OUTPUT_ENUM
1684 DBX_OUTPUT_ENUM (asmfile, type);
1685 #else
1686 if (use_gnu_debug_info_extensions
1687 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1689 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1690 CHARS (5);
1693 putc ('e', asmfile);
1694 CHARS (1);
1695 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1697 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1698 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1699 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1700 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1701 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1702 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1703 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1704 else
1705 print_int_cst_octal (TREE_VALUE (tem));
1707 putc (',', asmfile);
1708 CHARS (1);
1709 if (TREE_CHAIN (tem) != 0)
1710 CONTIN;
1713 putc (';', asmfile);
1714 CHARS (1);
1715 #endif
1716 break;
1718 case POINTER_TYPE:
1719 putc ('*', asmfile);
1720 CHARS (1);
1721 dbxout_type (TREE_TYPE (type), 0);
1722 break;
1724 case METHOD_TYPE:
1725 if (use_gnu_debug_info_extensions)
1727 have_used_extensions = 1;
1728 putc ('#', asmfile);
1729 CHARS (1);
1731 /* Write the argument types out longhand. */
1732 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1733 putc (',', asmfile);
1734 CHARS (1);
1735 dbxout_type (TREE_TYPE (type), 0);
1736 dbxout_args (TYPE_ARG_TYPES (type));
1737 putc (';', asmfile);
1738 CHARS (1);
1740 else
1741 /* Treat it as a function type. */
1742 dbxout_type (TREE_TYPE (type), 0);
1743 break;
1745 case OFFSET_TYPE:
1746 if (use_gnu_debug_info_extensions)
1748 have_used_extensions = 1;
1749 putc ('@', asmfile);
1750 CHARS (1);
1751 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1752 putc (',', asmfile);
1753 CHARS (1);
1754 dbxout_type (TREE_TYPE (type), 0);
1756 else
1757 /* Should print as an int, because it is really just an offset. */
1758 dbxout_type (integer_type_node, 0);
1759 break;
1761 case REFERENCE_TYPE:
1762 if (use_gnu_debug_info_extensions)
1763 have_used_extensions = 1;
1764 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1765 CHARS (1);
1766 dbxout_type (TREE_TYPE (type), 0);
1767 break;
1769 case FUNCTION_TYPE:
1770 putc ('f', asmfile);
1771 CHARS (1);
1772 dbxout_type (TREE_TYPE (type), 0);
1773 break;
1775 default:
1776 abort ();
1780 /* Print the value of integer constant C, in octal,
1781 handling double precision. */
1783 static void
1784 print_int_cst_octal (c)
1785 tree c;
1787 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1788 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1789 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1790 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1792 /* GDB wants constants with no extra leading "1" bits, so
1793 we need to remove any sign-extension that might be
1794 present. */
1795 if (width == HOST_BITS_PER_WIDE_INT * 2)
1797 else if (width > HOST_BITS_PER_WIDE_INT)
1798 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1799 else if (width == HOST_BITS_PER_WIDE_INT)
1800 high = 0;
1801 else
1802 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1804 fprintf (asmfile, "0");
1805 CHARS (1);
1807 if (excess == 3)
1809 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1810 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1812 else
1814 unsigned HOST_WIDE_INT beg = high >> excess;
1815 unsigned HOST_WIDE_INT middle
1816 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1817 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1818 unsigned HOST_WIDE_INT end
1819 = low & (((unsigned HOST_WIDE_INT) 1
1820 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1821 - 1);
1823 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1824 CHARS (2);
1825 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1829 static void
1830 print_octal (value, digits)
1831 unsigned HOST_WIDE_INT value;
1832 int digits;
1834 int i;
1836 for (i = digits - 1; i >= 0; i--)
1837 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1839 CHARS (digits);
1842 /* Output C in decimal while adjusting the number of digits written. */
1844 static void
1845 print_wide_int (c)
1846 HOST_WIDE_INT c;
1848 int digs = 0;
1850 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1852 if (c < 0)
1853 digs++, c = -c;
1855 while (c > 0)
1856 c /= 10; digs++;
1858 CHARS (digs);
1861 /* Output the name of type TYPE, with no punctuation.
1862 Such names can be set up either by typedef declarations
1863 or by struct, enum and union tags. */
1865 static void
1866 dbxout_type_name (type)
1867 tree type;
1869 tree t;
1870 if (TYPE_NAME (type) == 0)
1871 abort ();
1872 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1874 t = TYPE_NAME (type);
1876 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1878 t = DECL_NAME (TYPE_NAME (type));
1880 else
1881 abort ();
1883 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1884 CHARS (IDENTIFIER_LENGTH (t));
1887 /* Output leading leading struct or class names needed for qualifying
1888 type whose scope is limited to a struct or class. */
1890 static void
1891 dbxout_class_name_qualifiers (decl)
1892 tree decl;
1894 tree context = decl_type_context (decl);
1896 if (context != NULL_TREE
1897 && TREE_CODE(context) == RECORD_TYPE
1898 && TYPE_NAME (context) != 0
1899 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
1900 || (DECL_NAME (TYPE_NAME (context)) != 0)))
1902 tree name = TYPE_NAME (context);
1904 if (TREE_CODE (name) == TYPE_DECL)
1906 dbxout_class_name_qualifiers (name);
1907 name = DECL_NAME (name);
1909 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1910 CHARS (IDENTIFIER_LENGTH (name) + 2);
1914 /* Output a .stabs for the symbol defined by DECL,
1915 which must be a ..._DECL node in the normal namespace.
1916 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1917 LOCAL is nonzero if the scope is less than the entire file.
1918 Return 1 if a stabs might have been emitted. */
1921 dbxout_symbol (decl, local)
1922 tree decl;
1923 int local ATTRIBUTE_UNUSED;
1925 tree type = TREE_TYPE (decl);
1926 tree context = NULL_TREE;
1927 int result = 0;
1929 /* Cast avoids warning in old compilers. */
1930 current_sym_code = (STAB_CODE_TYPE) 0;
1931 current_sym_value = 0;
1932 current_sym_addr = 0;
1934 /* Ignore nameless syms, but don't ignore type tags. */
1936 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1937 || DECL_IGNORED_P (decl))
1938 return 0;
1940 dbxout_prepare_symbol (decl);
1942 /* The output will always start with the symbol name,
1943 so always count that in the length-output-so-far. */
1945 if (DECL_NAME (decl) != 0)
1946 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1948 switch (TREE_CODE (decl))
1950 case CONST_DECL:
1951 /* Enum values are defined by defining the enum type. */
1952 break;
1954 case FUNCTION_DECL:
1955 if (DECL_RTL (decl) == 0)
1956 return 0;
1957 if (DECL_EXTERNAL (decl))
1958 break;
1959 /* Don't mention a nested function under its parent. */
1960 context = decl_function_context (decl);
1961 if (context == current_function_decl)
1962 break;
1963 if (GET_CODE (DECL_RTL (decl)) != MEM
1964 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1965 break;
1966 FORCE_TEXT;
1968 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1969 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1970 TREE_PUBLIC (decl) ? 'F' : 'f');
1971 result = 1;
1973 current_sym_code = N_FUN;
1974 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1976 if (TREE_TYPE (type))
1977 dbxout_type (TREE_TYPE (type), 0);
1978 else
1979 dbxout_type (void_type_node, 0);
1981 /* For a nested function, when that function is compiled,
1982 mention the containing function name
1983 as well as (since dbx wants it) our own assembler-name. */
1984 if (context != 0)
1985 fprintf (asmfile, ",%s,%s",
1986 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1987 IDENTIFIER_POINTER (DECL_NAME (context)));
1989 dbxout_finish_symbol (decl);
1990 break;
1992 case TYPE_DECL:
1993 #if 0
1994 /* This seems all wrong. Outputting most kinds of types gives no name
1995 at all. A true definition gives no name; a cross-ref for a
1996 structure can give the tag name, but not a type name.
1997 It seems that no typedef name is defined by outputting a type. */
1999 /* If this typedef name was defined by outputting the type,
2000 don't duplicate it. */
2001 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
2002 && TYPE_NAME (TREE_TYPE (decl)) == decl)
2003 return 0;
2004 #endif
2005 /* Don't output the same typedef twice.
2006 And don't output what language-specific stuff doesn't want output. */
2007 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2008 return 0;
2010 FORCE_TEXT;
2011 result = 1;
2013 int tag_needed = 1;
2014 int did_output = 0;
2016 if (DECL_NAME (decl))
2018 /* Nonzero means we must output a tag as well as a typedef. */
2019 tag_needed = 0;
2021 /* Handle the case of a C++ structure or union
2022 where the TYPE_NAME is a TYPE_DECL
2023 which gives both a typedef name and a tag. */
2024 /* dbx requires the tag first and the typedef second. */
2025 if ((TREE_CODE (type) == RECORD_TYPE
2026 || TREE_CODE (type) == UNION_TYPE
2027 || TREE_CODE (type) == QUAL_UNION_TYPE)
2028 && TYPE_NAME (type) == decl
2029 && !(use_gnu_debug_info_extensions && have_used_extensions)
2030 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2031 /* Distinguish the implicit typedefs of C++
2032 from explicit ones that might be found in C. */
2033 && DECL_ARTIFICIAL (decl)
2034 /* Do not generate a tag for records of variable size,
2035 since this type can not be properly described in the
2036 DBX format, and it confuses some tools such as objdump. */
2037 && host_integerp (TYPE_SIZE (type), 1))
2039 tree name = TYPE_NAME (type);
2040 if (TREE_CODE (name) == TYPE_DECL)
2041 name = DECL_NAME (name);
2043 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2044 current_sym_value = 0;
2045 current_sym_addr = 0;
2046 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2048 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2049 IDENTIFIER_POINTER (name));
2050 dbxout_type (type, 1);
2051 dbxout_finish_symbol (NULL_TREE);
2054 /* Output .stabs (or whatever) and leading double quote. */
2055 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2057 if (use_gnu_debug_info_extensions)
2059 /* Output leading class/struct qualifiers. */
2060 dbxout_class_name_qualifiers (decl);
2063 /* Output typedef name. */
2064 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2066 /* Short cut way to output a tag also. */
2067 if ((TREE_CODE (type) == RECORD_TYPE
2068 || TREE_CODE (type) == UNION_TYPE
2069 || TREE_CODE (type) == QUAL_UNION_TYPE)
2070 && TYPE_NAME (type) == decl
2071 /* Distinguish the implicit typedefs of C++
2072 from explicit ones that might be found in C. */
2073 && DECL_ARTIFICIAL (decl))
2075 if (use_gnu_debug_info_extensions && have_used_extensions)
2077 putc ('T', asmfile);
2078 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2080 #if 0 /* Now we generate the tag for this case up above. */
2081 else
2082 tag_needed = 1;
2083 #endif
2086 putc ('t', asmfile);
2087 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2089 dbxout_type (type, 1);
2090 dbxout_finish_symbol (decl);
2091 did_output = 1;
2094 /* Don't output a tag if this is an incomplete type. This prevents
2095 the sun4 Sun OS 4.x dbx from crashing. */
2097 if (tag_needed && TYPE_NAME (type) != 0
2098 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2099 || (DECL_NAME (TYPE_NAME (type)) != 0))
2100 && COMPLETE_TYPE_P (type)
2101 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2103 /* For a TYPE_DECL with no name, but the type has a name,
2104 output a tag.
2105 This is what represents `struct foo' with no typedef. */
2106 /* In C++, the name of a type is the corresponding typedef.
2107 In C, it is an IDENTIFIER_NODE. */
2108 tree name = TYPE_NAME (type);
2109 if (TREE_CODE (name) == TYPE_DECL)
2110 name = DECL_NAME (name);
2112 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2113 current_sym_value = 0;
2114 current_sym_addr = 0;
2115 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2117 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2118 IDENTIFIER_POINTER (name));
2119 dbxout_type (type, 1);
2120 dbxout_finish_symbol (NULL_TREE);
2121 did_output = 1;
2124 /* If an enum type has no name, it cannot be referred to,
2125 but we must output it anyway, since the enumeration constants
2126 can be referred to. */
2127 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2129 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2130 current_sym_value = 0;
2131 current_sym_addr = 0;
2132 current_sym_nchars = 2;
2134 /* Some debuggers fail when given NULL names, so give this a
2135 harmless name of ` '. */
2136 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2137 dbxout_type (type, 1);
2138 dbxout_finish_symbol (NULL_TREE);
2141 /* Prevent duplicate output of a typedef. */
2142 TREE_ASM_WRITTEN (decl) = 1;
2143 break;
2146 case PARM_DECL:
2147 /* Parm decls go in their own separate chains
2148 and are output by dbxout_reg_parms and dbxout_parms. */
2149 abort ();
2151 case RESULT_DECL:
2152 /* Named return value, treat like a VAR_DECL. */
2153 case VAR_DECL:
2154 if (! DECL_RTL_SET_P (decl))
2155 return 0;
2156 /* Don't mention a variable that is external.
2157 Let the file that defines it describe it. */
2158 if (DECL_EXTERNAL (decl))
2159 break;
2161 /* If the variable is really a constant
2162 and not written in memory, inform the debugger. */
2163 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2164 && DECL_INITIAL (decl) != 0
2165 && host_integerp (DECL_INITIAL (decl), 0)
2166 && ! TREE_ASM_WRITTEN (decl)
2167 && (DECL_CONTEXT (decl) == NULL_TREE
2168 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2170 if (TREE_PUBLIC (decl) == 0)
2172 /* The sun4 assembler does not grok this. */
2173 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2175 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2176 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2178 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2179 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
2180 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
2181 #else
2182 fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
2184 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
2185 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
2186 #endif
2187 return 1;
2189 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2191 /* don't know how to do this yet. */
2193 break;
2195 /* else it is something we handle like a normal variable. */
2198 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2199 #ifdef LEAF_REG_REMAP
2200 if (current_function_uses_only_leaf_regs)
2201 leaf_renumber_regs_insn (DECL_RTL (decl));
2202 #endif
2204 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2205 break;
2207 default:
2208 break;
2210 return result;
2213 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2214 Add SUFFIX to its name, if SUFFIX is not 0.
2215 Describe the variable as residing in HOME
2216 (usually HOME is DECL_RTL (DECL), but not always).
2217 Returns 1 if the stab was really emitted. */
2219 static int
2220 dbxout_symbol_location (decl, type, suffix, home)
2221 tree decl, type;
2222 const char *suffix;
2223 rtx home;
2225 int letter = 0;
2226 int regno = -1;
2228 /* Don't mention a variable at all
2229 if it was completely optimized into nothingness.
2231 If the decl was from an inline function, then its rtl
2232 is not identically the rtl that was used in this
2233 particular compilation. */
2234 if (GET_CODE (home) == SUBREG)
2236 rtx value = home;
2238 while (GET_CODE (value) == SUBREG)
2239 value = SUBREG_REG (value);
2240 if (GET_CODE (value) == REG)
2242 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2243 return 0;
2245 home = alter_subreg (&home);
2247 if (GET_CODE (home) == REG)
2249 regno = REGNO (home);
2250 if (regno >= FIRST_PSEUDO_REGISTER)
2251 return 0;
2254 /* The kind-of-variable letter depends on where
2255 the variable is and on the scope of its name:
2256 G and N_GSYM for static storage and global scope,
2257 S for static storage and file scope,
2258 V for static storage and local scope,
2259 for those two, use N_LCSYM if data is in bss segment,
2260 N_STSYM if in data segment, N_FUN otherwise.
2261 (We used N_FUN originally, then changed to N_STSYM
2262 to please GDB. However, it seems that confused ld.
2263 Now GDB has been fixed to like N_FUN, says Kingdon.)
2264 no letter at all, and N_LSYM, for auto variable,
2265 r and N_RSYM for register variable. */
2267 if (GET_CODE (home) == MEM
2268 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2270 if (TREE_PUBLIC (decl))
2272 letter = 'G';
2273 current_sym_code = N_GSYM;
2275 else
2277 current_sym_addr = XEXP (home, 0);
2279 letter = decl_function_context (decl) ? 'V' : 'S';
2281 /* This should be the same condition as in assemble_variable, but
2282 we don't have access to dont_output_data here. So, instead,
2283 we rely on the fact that error_mark_node initializers always
2284 end up in bss for C++ and never end up in bss for C. */
2285 if (DECL_INITIAL (decl) == 0
2286 || (!strcmp (lang_hooks.name, "GNU C++")
2287 && DECL_INITIAL (decl) == error_mark_node))
2288 current_sym_code = N_LCSYM;
2289 else if (DECL_IN_TEXT_SECTION (decl))
2290 /* This is not quite right, but it's the closest
2291 of all the codes that Unix defines. */
2292 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2293 else
2295 /* Some ports can transform a symbol ref into a label ref,
2296 because the symbol ref is too far away and has to be
2297 dumped into a constant pool. Alternatively, the symbol
2298 in the constant pool might be referenced by a different
2299 symbol. */
2300 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2301 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2303 rtx tmp = get_pool_constant (current_sym_addr);
2305 if (GET_CODE (tmp) == SYMBOL_REF
2306 || GET_CODE (tmp) == LABEL_REF)
2307 current_sym_addr = tmp;
2310 /* Ultrix `as' seems to need this. */
2311 #ifdef DBX_STATIC_STAB_DATA_SECTION
2312 data_section ();
2313 #endif
2314 current_sym_code = N_STSYM;
2318 else if (regno >= 0)
2320 letter = 'r';
2321 current_sym_code = N_RSYM;
2322 current_sym_value = DBX_REGISTER_NUMBER (regno);
2324 else if (GET_CODE (home) == MEM
2325 && (GET_CODE (XEXP (home, 0)) == MEM
2326 || (GET_CODE (XEXP (home, 0)) == REG
2327 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2328 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2329 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2330 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2331 #endif
2333 /* If the value is indirect by memory or by a register
2334 that isn't the frame pointer
2335 then it means the object is variable-sized and address through
2336 that register or stack slot. DBX has no way to represent this
2337 so all we can do is output the variable as a pointer.
2338 If it's not a parameter, ignore it.
2339 (VAR_DECLs like this can be made by integrate.c.) */
2341 if (GET_CODE (XEXP (home, 0)) == REG)
2343 letter = 'r';
2344 current_sym_code = N_RSYM;
2345 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2346 return 0;
2347 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2349 else
2351 current_sym_code = N_LSYM;
2352 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2353 We want the value of that CONST_INT. */
2354 current_sym_value
2355 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2358 /* Effectively do build_pointer_type, but don't cache this type,
2359 since it might be temporary whereas the type it points to
2360 might have been saved for inlining. */
2361 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2362 type = make_node (POINTER_TYPE);
2363 TREE_TYPE (type) = TREE_TYPE (decl);
2365 else if (GET_CODE (home) == MEM
2366 && GET_CODE (XEXP (home, 0)) == REG)
2368 current_sym_code = N_LSYM;
2369 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2371 else if (GET_CODE (home) == MEM
2372 && GET_CODE (XEXP (home, 0)) == PLUS
2373 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2375 current_sym_code = N_LSYM;
2376 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2377 We want the value of that CONST_INT. */
2378 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2380 else if (GET_CODE (home) == MEM
2381 && GET_CODE (XEXP (home, 0)) == CONST)
2383 /* Handle an obscure case which can arise when optimizing and
2384 when there are few available registers. (This is *always*
2385 the case for i386/i486 targets). The RTL looks like
2386 (MEM (CONST ...)) even though this variable is a local `auto'
2387 or a local `register' variable. In effect, what has happened
2388 is that the reload pass has seen that all assignments and
2389 references for one such a local variable can be replaced by
2390 equivalent assignments and references to some static storage
2391 variable, thereby avoiding the need for a register. In such
2392 cases we're forced to lie to debuggers and tell them that
2393 this variable was itself `static'. */
2394 current_sym_code = N_LCSYM;
2395 letter = 'V';
2396 current_sym_addr = XEXP (XEXP (home, 0), 0);
2398 else if (GET_CODE (home) == CONCAT)
2400 tree subtype;
2402 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2403 for example), then there is no easy way to figure out
2404 what SUBTYPE should be. So, we give up. */
2405 if (TREE_CODE (type) != COMPLEX_TYPE)
2406 return 0;
2408 subtype = TREE_TYPE (type);
2410 /* If the variable's storage is in two parts,
2411 output each as a separate stab with a modified name. */
2412 if (WORDS_BIG_ENDIAN)
2413 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2414 else
2415 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2417 /* Cast avoids warning in old compilers. */
2418 current_sym_code = (STAB_CODE_TYPE) 0;
2419 current_sym_value = 0;
2420 current_sym_addr = 0;
2421 dbxout_prepare_symbol (decl);
2423 if (WORDS_BIG_ENDIAN)
2424 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2425 else
2426 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2427 return 1;
2429 else
2430 /* Address might be a MEM, when DECL is a variable-sized object.
2431 Or it might be const0_rtx, meaning previous passes
2432 want us to ignore this variable. */
2433 return 0;
2435 /* Ok, start a symtab entry and output the variable name. */
2436 FORCE_TEXT;
2438 #ifdef DBX_STATIC_BLOCK_START
2439 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2440 #endif
2442 dbxout_symbol_name (decl, suffix, letter);
2443 dbxout_type (type, 0);
2444 dbxout_finish_symbol (decl);
2446 #ifdef DBX_STATIC_BLOCK_END
2447 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2448 #endif
2449 return 1;
2452 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2453 Then output LETTER to indicate the kind of location the symbol has. */
2455 static void
2456 dbxout_symbol_name (decl, suffix, letter)
2457 tree decl;
2458 const char *suffix;
2459 int letter;
2461 const char *name;
2463 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2464 /* One slight hitch: if this is a VAR_DECL which is a static
2465 class member, we must put out the mangled name instead of the
2466 DECL_NAME. Note also that static member (variable) names DO NOT begin
2467 with underscores in .stabs directives. */
2468 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2469 else
2470 /* ...but if we're function-local, we don't want to include the junk
2471 added by ASM_FORMAT_PRIVATE_NAME. */
2472 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2474 if (name == 0)
2475 name = "(anon)";
2476 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2477 (suffix ? suffix : ""));
2479 if (letter)
2480 putc (letter, asmfile);
2483 static void
2484 dbxout_prepare_symbol (decl)
2485 tree decl ATTRIBUTE_UNUSED;
2487 #ifdef WINNING_GDB
2488 const char *filename = DECL_SOURCE_FILE (decl);
2490 dbxout_source_file (asmfile, filename);
2491 #endif
2494 static void
2495 dbxout_finish_symbol (sym)
2496 tree sym;
2498 #ifdef DBX_FINISH_SYMBOL
2499 DBX_FINISH_SYMBOL (sym);
2500 #else
2501 int line = 0;
2502 if (use_gnu_debug_info_extensions && sym != 0)
2503 line = DECL_SOURCE_LINE (sym);
2505 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2506 if (current_sym_addr)
2507 output_addr_const (asmfile, current_sym_addr);
2508 else
2509 fprintf (asmfile, "%d", current_sym_value);
2510 putc ('\n', asmfile);
2511 #endif
2514 /* Output definitions of all the decls in a chain. Return nonzero if
2515 anything was output */
2518 dbxout_syms (syms)
2519 tree syms;
2521 int result = 0;
2522 while (syms)
2524 result += dbxout_symbol (syms, 1);
2525 syms = TREE_CHAIN (syms);
2527 return result;
2530 /* The following two functions output definitions of function parameters.
2531 Each parameter gets a definition locating it in the parameter list.
2532 Each parameter that is a register variable gets a second definition
2533 locating it in the register.
2535 Printing or argument lists in gdb uses the definitions that
2536 locate in the parameter list. But reference to the variable in
2537 expressions uses preferentially the definition as a register. */
2539 /* Output definitions, referring to storage in the parmlist,
2540 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2542 void
2543 dbxout_parms (parms)
2544 tree parms;
2546 for (; parms; parms = TREE_CHAIN (parms))
2547 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2549 dbxout_prepare_symbol (parms);
2551 /* Perform any necessary register eliminations on the parameter's rtl,
2552 so that the debugging output will be accurate. */
2553 DECL_INCOMING_RTL (parms)
2554 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2555 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2556 #ifdef LEAF_REG_REMAP
2557 if (current_function_uses_only_leaf_regs)
2559 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2560 leaf_renumber_regs_insn (DECL_RTL (parms));
2562 #endif
2564 if (PARM_PASSED_IN_MEMORY (parms))
2566 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2568 /* ??? Here we assume that the parm address is indexed
2569 off the frame pointer or arg pointer.
2570 If that is not true, we produce meaningless results,
2571 but do not crash. */
2572 if (GET_CODE (addr) == PLUS
2573 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2574 current_sym_value = INTVAL (XEXP (addr, 1));
2575 else
2576 current_sym_value = 0;
2578 current_sym_code = N_PSYM;
2579 current_sym_addr = 0;
2581 FORCE_TEXT;
2582 if (DECL_NAME (parms))
2584 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2586 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2587 IDENTIFIER_POINTER (DECL_NAME (parms)),
2588 DBX_MEMPARM_STABS_LETTER);
2590 else
2592 current_sym_nchars = 8;
2593 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2594 DBX_MEMPARM_STABS_LETTER);
2597 /* It is quite tempting to use:
2599 dbxout_type (TREE_TYPE (parms), 0);
2601 as the next statement, rather than using DECL_ARG_TYPE(), so
2602 that gcc reports the actual type of the parameter, rather
2603 than the promoted type. This certainly makes GDB's life
2604 easier, at least for some ports. The change is a bad idea
2605 however, since GDB expects to be able access the type without
2606 performing any conversions. So for example, if we were
2607 passing a float to an unprototyped function, gcc will store a
2608 double on the stack, but if we emit a stab saying the type is a
2609 float, then gdb will only read in a single value, and this will
2610 produce an erroneous value. */
2611 dbxout_type (DECL_ARG_TYPE (parms), 0);
2612 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2613 dbxout_finish_symbol (parms);
2615 else if (GET_CODE (DECL_RTL (parms)) == REG)
2617 rtx best_rtl;
2618 char regparm_letter;
2619 tree parm_type;
2620 /* Parm passed in registers and lives in registers or nowhere. */
2622 current_sym_code = DBX_REGPARM_STABS_CODE;
2623 regparm_letter = DBX_REGPARM_STABS_LETTER;
2624 current_sym_addr = 0;
2626 /* If parm lives in a register, use that register;
2627 pretend the parm was passed there. It would be more consistent
2628 to describe the register where the parm was passed,
2629 but in practice that register usually holds something else.
2631 If we use DECL_RTL, then we must use the declared type of
2632 the variable, not the type that it arrived in. */
2633 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2635 best_rtl = DECL_RTL (parms);
2636 parm_type = TREE_TYPE (parms);
2638 /* If the parm lives nowhere, use the register where it was
2639 passed. It is also better to use the declared type here. */
2640 else
2642 best_rtl = DECL_INCOMING_RTL (parms);
2643 parm_type = TREE_TYPE (parms);
2645 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2647 FORCE_TEXT;
2648 if (DECL_NAME (parms))
2650 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2651 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2652 IDENTIFIER_POINTER (DECL_NAME (parms)),
2653 regparm_letter);
2655 else
2657 current_sym_nchars = 8;
2658 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2659 regparm_letter);
2662 dbxout_type (parm_type, 0);
2663 dbxout_finish_symbol (parms);
2665 else if (GET_CODE (DECL_RTL (parms)) == MEM
2666 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2667 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2668 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2669 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2670 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2671 #endif
2674 /* Parm was passed via invisible reference.
2675 That is, its address was passed in a register.
2676 Output it as if it lived in that register.
2677 The debugger will know from the type
2678 that it was actually passed by invisible reference. */
2680 char regparm_letter;
2681 /* Parm passed in registers and lives in registers or nowhere. */
2683 current_sym_code = DBX_REGPARM_STABS_CODE;
2684 if (use_gnu_debug_info_extensions)
2685 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2686 else
2687 regparm_letter = DBX_REGPARM_STABS_LETTER;
2689 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2690 If it is an unallocated pseudo-reg, then use the register where
2691 it was passed instead. */
2692 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2693 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2694 else
2695 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2697 current_sym_addr = 0;
2699 FORCE_TEXT;
2700 if (DECL_NAME (parms))
2702 current_sym_nchars
2703 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2705 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2706 IDENTIFIER_POINTER (DECL_NAME (parms)),
2707 regparm_letter);
2709 else
2711 current_sym_nchars = 8;
2712 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2713 regparm_letter);
2716 dbxout_type (TREE_TYPE (parms), 0);
2717 dbxout_finish_symbol (parms);
2719 else if (GET_CODE (DECL_RTL (parms)) == MEM
2720 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2722 /* Parm was passed via invisible reference, with the reference
2723 living on the stack. DECL_RTL looks like
2724 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2725 could look like (MEM (MEM (REG))). */
2726 const char *const decl_name = (DECL_NAME (parms)
2727 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2728 : "(anon)");
2729 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2730 current_sym_value = 0;
2731 else
2732 current_sym_value
2733 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2734 current_sym_addr = 0;
2735 current_sym_code = N_PSYM;
2737 FORCE_TEXT;
2738 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2740 current_sym_value
2741 = DEBUGGER_ARG_OFFSET (current_sym_value,
2742 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2743 dbxout_type (TREE_TYPE (parms), 0);
2744 dbxout_finish_symbol (parms);
2746 else if (GET_CODE (DECL_RTL (parms)) == MEM
2747 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2748 /* ??? A constant address for a parm can happen
2749 when the reg it lives in is equiv to a constant in memory.
2750 Should make this not happen, after 2.4. */
2751 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2753 /* Parm was passed in registers but lives on the stack. */
2755 current_sym_code = N_PSYM;
2756 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2757 in which case we want the value of that CONST_INT,
2758 or (MEM (REG ...)),
2759 in which case we use a value of zero. */
2760 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2761 current_sym_value = 0;
2762 else
2763 current_sym_value
2764 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2766 current_sym_addr = 0;
2768 /* Make a big endian correction if the mode of the type of the
2769 parameter is not the same as the mode of the rtl. */
2770 if (BYTES_BIG_ENDIAN
2771 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2772 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2774 current_sym_value +=
2775 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2776 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2779 FORCE_TEXT;
2780 if (DECL_NAME (parms))
2782 current_sym_nchars
2783 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2785 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2786 IDENTIFIER_POINTER (DECL_NAME (parms)),
2787 DBX_MEMPARM_STABS_LETTER);
2789 else
2791 current_sym_nchars = 8;
2792 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2793 DBX_MEMPARM_STABS_LETTER);
2796 current_sym_value
2797 = DEBUGGER_ARG_OFFSET (current_sym_value,
2798 XEXP (DECL_RTL (parms), 0));
2799 dbxout_type (TREE_TYPE (parms), 0);
2800 dbxout_finish_symbol (parms);
2805 /* Output definitions for the places where parms live during the function,
2806 when different from where they were passed, when the parms were passed
2807 in memory.
2809 It is not useful to do this for parms passed in registers
2810 that live during the function in different registers, because it is
2811 impossible to look in the passed register for the passed value,
2812 so we use the within-the-function register to begin with.
2814 PARMS is a chain of PARM_DECL nodes. */
2816 void
2817 dbxout_reg_parms (parms)
2818 tree parms;
2820 for (; parms; parms = TREE_CHAIN (parms))
2821 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2823 dbxout_prepare_symbol (parms);
2825 /* Report parms that live in registers during the function
2826 but were passed in memory. */
2827 if (GET_CODE (DECL_RTL (parms)) == REG
2828 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2829 dbxout_symbol_location (parms, TREE_TYPE (parms),
2830 0, DECL_RTL (parms));
2831 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2832 dbxout_symbol_location (parms, TREE_TYPE (parms),
2833 0, DECL_RTL (parms));
2834 /* Report parms that live in memory but not where they were passed. */
2835 else if (GET_CODE (DECL_RTL (parms)) == MEM
2836 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2837 dbxout_symbol_location (parms, TREE_TYPE (parms),
2838 0, DECL_RTL (parms));
2842 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2843 output definitions of those names, in raw form */
2845 static void
2846 dbxout_args (args)
2847 tree args;
2849 while (args)
2851 putc (',', asmfile);
2852 dbxout_type (TREE_VALUE (args), 0);
2853 CHARS (1);
2854 args = TREE_CHAIN (args);
2858 /* Output everything about a symbol block (a BLOCK node
2859 that represents a scope level),
2860 including recursive output of contained blocks.
2862 BLOCK is the BLOCK node.
2863 DEPTH is its depth within containing symbol blocks.
2864 ARGS is usually zero; but for the outermost block of the
2865 body of a function, it is a chain of PARM_DECLs for the function parameters.
2866 We output definitions of all the register parms
2867 as if they were local variables of that block.
2869 If -g1 was used, we count blocks just the same, but output nothing
2870 except for the outermost block.
2872 Actually, BLOCK may be several blocks chained together.
2873 We handle them all in sequence. */
2875 static void
2876 dbxout_block (block, depth, args)
2877 tree block;
2878 int depth;
2879 tree args;
2881 int blocknum = -1;
2883 #if DBX_BLOCKS_FUNCTION_RELATIVE
2884 const char *begin_label;
2885 if (current_function_func_begin_label != NULL_TREE)
2886 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2887 else
2888 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2889 #endif
2891 while (block)
2893 /* Ignore blocks never expanded or otherwise marked as real. */
2894 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2896 int did_output;
2898 #ifdef DBX_LBRAC_FIRST
2899 did_output = 1;
2900 #else
2901 /* In dbx format, the syms of a block come before the N_LBRAC.
2902 If nothing is output, we don't need the N_LBRAC, either. */
2903 did_output = 0;
2904 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2905 did_output = dbxout_syms (BLOCK_VARS (block));
2906 if (args)
2907 dbxout_reg_parms (args);
2908 #endif
2910 /* Now output an N_LBRAC symbol to represent the beginning of
2911 the block. Use the block's tree-walk order to generate
2912 the assembler symbols LBBn and LBEn
2913 that final will define around the code in this block. */
2914 if (depth > 0 && did_output)
2916 char buf[20];
2917 blocknum = BLOCK_NUMBER (block);
2918 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2920 if (BLOCK_HANDLER_BLOCK (block))
2922 /* A catch block. Must precede N_LBRAC. */
2923 tree decl = BLOCK_VARS (block);
2924 while (decl)
2926 #ifdef DBX_OUTPUT_CATCH
2927 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2928 #else
2929 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2930 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2931 assemble_name (asmfile, buf);
2932 fprintf (asmfile, "\n");
2933 #endif
2934 decl = TREE_CHAIN (decl);
2938 #ifdef DBX_OUTPUT_LBRAC
2939 DBX_OUTPUT_LBRAC (asmfile, buf);
2940 #else
2941 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2942 assemble_name (asmfile, buf);
2943 #if DBX_BLOCKS_FUNCTION_RELATIVE
2944 putc ('-', asmfile);
2945 assemble_name (asmfile, begin_label);
2946 #endif
2947 fprintf (asmfile, "\n");
2948 #endif
2951 #ifdef DBX_LBRAC_FIRST
2952 /* On some weird machines, the syms of a block
2953 come after the N_LBRAC. */
2954 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2955 dbxout_syms (BLOCK_VARS (block));
2956 if (args)
2957 dbxout_reg_parms (args);
2958 #endif
2960 /* Output the subblocks. */
2961 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2963 /* Refer to the marker for the end of the block. */
2964 if (depth > 0 && did_output)
2966 char buf[20];
2967 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2968 #ifdef DBX_OUTPUT_RBRAC
2969 DBX_OUTPUT_RBRAC (asmfile, buf);
2970 #else
2971 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2972 assemble_name (asmfile, buf);
2973 #if DBX_BLOCKS_FUNCTION_RELATIVE
2974 putc ('-', asmfile);
2975 assemble_name (asmfile, begin_label);
2976 #endif
2977 fprintf (asmfile, "\n");
2978 #endif
2981 block = BLOCK_CHAIN (block);
2985 /* Output the information about a function and its arguments and result.
2986 Usually this follows the function's code,
2987 but on some systems, it comes before. */
2989 #if defined (DBX_DEBUGGING_INFO)
2990 static void
2991 dbxout_begin_function (decl)
2992 tree decl;
2994 dbxout_symbol (decl, 0);
2995 dbxout_parms (DECL_ARGUMENTS (decl));
2996 if (DECL_NAME (DECL_RESULT (decl)) != 0)
2997 dbxout_symbol (DECL_RESULT (decl), 1);
2999 #endif /* DBX_DEBUGGING_INFO */
3001 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3003 #include "gt-dbxout.h"