* doc/install.texi (Prerequisites): New section documenting
[official-gcc.git] / gcc / dbxout.c
blob7b13e3b84339d2ebfb858162a98f502a9fc1c394
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 /* A counter for dbxout_function_end. */
194 static GTY(()) int scope_labelno;
196 /* Nonzero if we have actually used any of the GDB extensions
197 to the debugging format. The idea is that we use them for the
198 first time only if there's a strong reason, but once we have done that,
199 we use them whenever convenient. */
201 static GTY(()) int have_used_extensions = 0;
203 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
204 for the N_SO filename stabs label. */
206 static GTY(()) int source_label_number = 1;
208 /* Last source file name mentioned in a NOTE insn. */
210 static GTY(()) const char *lastfile;
212 /* Used by PCH machinery to detect if 'lastfile' should be reset to
213 base_input_file. */
214 static GTY(()) int lastfile_is_base;
216 /* Typical USG systems don't have stab.h, and they also have
217 no use for DBX-format debugging info. */
219 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
221 /* The original input file name. */
222 static const char *base_input_file;
224 /* Current working directory. */
226 static const char *cwd;
228 #ifdef DEBUG_SYMS_TEXT
229 #define FORCE_TEXT function_section (current_function_decl);
230 #else
231 #define FORCE_TEXT
232 #endif
234 #include "gstab.h"
236 #define STAB_CODE_TYPE enum __stab_debug_code
238 /* 1 if PARM is passed to this function in memory. */
240 #define PARM_PASSED_IN_MEMORY(PARM) \
241 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
243 /* A C expression for the integer offset value of an automatic variable
244 (N_LSYM) having address X (an RTX). */
245 #ifndef DEBUGGER_AUTO_OFFSET
246 #define DEBUGGER_AUTO_OFFSET(X) \
247 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
248 #endif
250 /* A C expression for the integer offset value of an argument (N_PSYM)
251 having address X (an RTX). The nominal offset is OFFSET. */
252 #ifndef DEBUGGER_ARG_OFFSET
253 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
254 #endif
256 /* Stream for writing to assembler file. */
258 static FILE *asmfile;
260 /* These variables are for dbxout_symbol to communicate to
261 dbxout_finish_symbol.
262 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
263 current_sym_value and current_sym_addr are two ways to address the
264 value to store in the symtab entry.
265 current_sym_addr if nonzero represents the value as an rtx.
266 If that is zero, current_sym_value is used. This is used
267 when the value is an offset (such as for auto variables,
268 register variables and parms). */
270 static STAB_CODE_TYPE current_sym_code;
271 static int current_sym_value;
272 static rtx current_sym_addr;
274 /* Number of chars of symbol-description generated so far for the
275 current symbol. Used by CHARS and CONTIN. */
277 static int current_sym_nchars;
279 /* Report having output N chars of the current symbol-description. */
281 #define CHARS(N) (current_sym_nchars += (N))
283 /* Break the current symbol-description, generating a continuation,
284 if it has become long. */
286 #ifndef DBX_CONTIN_LENGTH
287 #define DBX_CONTIN_LENGTH 80
288 #endif
290 #if DBX_CONTIN_LENGTH > 0
291 #define CONTIN \
292 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
293 #else
294 #define CONTIN do { } while (0)
295 #endif
297 static void dbxout_init PARAMS ((const char *));
298 static void dbxout_finish PARAMS ((const char *));
299 static void dbxout_start_source_file PARAMS ((unsigned, const char *));
300 static void dbxout_end_source_file PARAMS ((unsigned));
301 static void dbxout_typedefs PARAMS ((tree));
302 static void dbxout_fptype_value PARAMS ((tree));
303 static void dbxout_type_index PARAMS ((tree));
304 #if DBX_CONTIN_LENGTH > 0
305 static void dbxout_continue PARAMS ((void));
306 #endif
307 static void dbxout_args PARAMS ((tree));
308 static void dbxout_type_fields PARAMS ((tree));
309 static void dbxout_type_method_1 PARAMS ((tree, const char *));
310 static void dbxout_type_methods PARAMS ((tree));
311 static void dbxout_range_type PARAMS ((tree));
312 static void dbxout_type PARAMS ((tree, int));
313 static bool print_int_cst_bounds_in_octal_p PARAMS ((tree));
314 static void print_int_cst_octal PARAMS ((tree));
315 static void print_octal PARAMS ((unsigned HOST_WIDE_INT, int));
316 static void print_wide_int PARAMS ((HOST_WIDE_INT));
317 static void dbxout_type_name PARAMS ((tree));
318 static void dbxout_class_name_qualifiers PARAMS ((tree));
319 static int dbxout_symbol_location PARAMS ((tree, tree, const char *, rtx));
320 static void dbxout_symbol_name PARAMS ((tree, const char *, int));
321 static void dbxout_prepare_symbol PARAMS ((tree));
322 static void dbxout_finish_symbol PARAMS ((tree));
323 static void dbxout_block PARAMS ((tree, int, tree));
324 static void dbxout_global_decl PARAMS ((tree));
325 static void dbxout_handle_pch PARAMS ((unsigned));
327 /* The debug hooks structure. */
328 #if defined (DBX_DEBUGGING_INFO)
330 static void dbxout_source_line PARAMS ((unsigned int, const char *));
331 static void dbxout_source_file PARAMS ((FILE *, const char *));
332 static void dbxout_function_end PARAMS ((void));
333 static void dbxout_begin_function PARAMS ((tree));
334 static void dbxout_begin_block PARAMS ((unsigned, unsigned));
335 static void dbxout_end_block PARAMS ((unsigned, unsigned));
336 static void dbxout_function_decl PARAMS ((tree));
338 const struct gcc_debug_hooks dbx_debug_hooks =
340 dbxout_init,
341 dbxout_finish,
342 debug_nothing_int_charstar,
343 debug_nothing_int_charstar,
344 dbxout_start_source_file,
345 dbxout_end_source_file,
346 dbxout_begin_block,
347 dbxout_end_block,
348 debug_true_tree, /* ignore_block */
349 dbxout_source_line, /* source_line */
350 dbxout_source_line, /* begin_prologue: just output line info */
351 debug_nothing_int_charstar, /* end_prologue */
352 debug_nothing_int_charstar, /* end_epilogue */
353 #ifdef DBX_FUNCTION_FIRST
354 dbxout_begin_function,
355 #else
356 debug_nothing_tree, /* begin_function */
357 #endif
358 debug_nothing_int, /* end_function */
359 dbxout_function_decl,
360 dbxout_global_decl, /* global_decl */
361 debug_nothing_tree, /* deferred_inline_function */
362 debug_nothing_tree, /* outlining_inline_function */
363 debug_nothing_rtx, /* label */
364 dbxout_handle_pch /* handle_pch */
366 #endif /* DBX_DEBUGGING_INFO */
368 #if defined (XCOFF_DEBUGGING_INFO)
369 const struct gcc_debug_hooks xcoff_debug_hooks =
371 dbxout_init,
372 dbxout_finish,
373 debug_nothing_int_charstar,
374 debug_nothing_int_charstar,
375 dbxout_start_source_file,
376 dbxout_end_source_file,
377 xcoffout_begin_block,
378 xcoffout_end_block,
379 debug_true_tree, /* ignore_block */
380 xcoffout_source_line,
381 xcoffout_begin_prologue, /* begin_prologue */
382 debug_nothing_int_charstar, /* end_prologue */
383 xcoffout_end_epilogue,
384 debug_nothing_tree, /* begin_function */
385 xcoffout_end_function,
386 debug_nothing_tree, /* function_decl */
387 dbxout_global_decl, /* global_decl */
388 debug_nothing_tree, /* deferred_inline_function */
389 debug_nothing_tree, /* outlining_inline_function */
390 debug_nothing_rtx, /* label */
391 dbxout_handle_pch /* handle_pch */
393 #endif /* XCOFF_DEBUGGING_INFO */
395 #if defined (DBX_DEBUGGING_INFO)
396 static void
397 dbxout_function_end ()
399 char lscope_label_name[100];
400 /* Convert Ltext into the appropriate format for local labels in case
401 the system doesn't insert underscores in front of user generated
402 labels. */
403 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
404 (*targetm.asm_out.internal_label) (asmfile, "Lscope", scope_labelno);
405 scope_labelno++;
407 /* By convention, GCC will mark the end of a function with an N_FUN
408 symbol and an empty string. */
409 #ifdef DBX_OUTPUT_NFUN
410 DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
411 #else
412 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
413 assemble_name (asmfile, lscope_label_name);
414 putc ('-', asmfile);
415 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
416 fprintf (asmfile, "\n");
417 #endif
419 #endif /* DBX_DEBUGGING_INFO */
421 /* At the beginning of compilation, start writing the symbol table.
422 Initialize `typevec' and output the standard data types of C. */
424 static void
425 dbxout_init (input_file_name)
426 const char *input_file_name;
428 char ltext_label_name[100];
429 tree syms = (*lang_hooks.decls.getdecls) ();
431 asmfile = asm_out_file;
433 typevec_len = 100;
434 typevec = (struct typeinfo *) ggc_calloc (typevec_len, sizeof typevec[0]);
436 /* Convert Ltext into the appropriate format for local labels in case
437 the system doesn't insert underscores in front of user generated
438 labels. */
439 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
441 /* Put the current working directory in an N_SO symbol. */
442 if (use_gnu_debug_info_extensions)
444 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
445 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
446 if (cwd)
448 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
449 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
450 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
451 fprintf (asmfile, "%s", ASM_STABS_OP);
452 output_quoted_string (asmfile, cwd);
453 fprintf (asmfile, ",%d,0,0,", N_SO);
454 assemble_name (asmfile, ltext_label_name);
455 fputc ('\n', asmfile);
456 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
460 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
461 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
462 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
463 /* We include outputting `Ltext:' here,
464 because that gives you a way to override it. */
465 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
466 fprintf (asmfile, "%s", ASM_STABS_OP);
467 output_quoted_string (asmfile, input_file_name);
468 fprintf (asmfile, ",%d,0,0,", N_SO);
469 assemble_name (asmfile, ltext_label_name);
470 fputc ('\n', asmfile);
471 text_section ();
472 (*targetm.asm_out.internal_label) (asmfile, "Ltext", 0);
473 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
475 #ifdef DBX_OUTPUT_GCC_MARKER
476 DBX_OUTPUT_GCC_MARKER (asmfile);
477 #else
478 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
479 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
480 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
481 #endif
483 base_input_file = lastfile = input_file_name;
485 next_type_number = 1;
487 #ifdef DBX_USE_BINCL
488 current_file = (struct dbx_file *) ggc_alloc (sizeof *current_file);
489 current_file->next = NULL;
490 current_file->file_number = 0;
491 current_file->next_type_number = 1;
492 next_file_number = 1;
493 #endif
495 /* Make sure that types `int' and `char' have numbers 1 and 2.
496 Definitions of other integer types will refer to those numbers.
497 (Actually it should no longer matter what their numbers are.
498 Also, if any types with tags have been defined, dbxout_symbol
499 will output them first, so the numbers won't be 1 and 2. That
500 happens in C++. So it's a good thing it should no longer matter). */
502 #ifdef DBX_OUTPUT_STANDARD_TYPES
503 DBX_OUTPUT_STANDARD_TYPES (syms);
504 #else
505 dbxout_symbol (TYPE_NAME (integer_type_node), 0);
506 dbxout_symbol (TYPE_NAME (char_type_node), 0);
507 #endif
509 /* Get all permanent types that have typedef names,
510 and output them all, except for those already output. */
512 dbxout_typedefs (syms);
515 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
516 in the reverse order from that which is found in SYMS. */
518 static void
519 dbxout_typedefs (syms)
520 tree syms;
522 if (syms)
524 dbxout_typedefs (TREE_CHAIN (syms));
525 if (TREE_CODE (syms) == TYPE_DECL)
527 tree type = TREE_TYPE (syms);
528 if (TYPE_NAME (type)
529 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
530 && COMPLETE_TYPE_P (type)
531 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
532 dbxout_symbol (TYPE_NAME (type), 0);
537 /* Change to reading from a new source file. Generate a N_BINCL stab. */
539 static void
540 dbxout_start_source_file (line, filename)
541 unsigned int line ATTRIBUTE_UNUSED;
542 const char *filename ATTRIBUTE_UNUSED;
544 #ifdef DBX_USE_BINCL
545 struct dbx_file *n = (struct dbx_file *) ggc_alloc (sizeof *n);
547 n->next = current_file;
548 n->file_number = next_file_number++;
549 n->next_type_number = 1;
550 current_file = n;
551 fprintf (asmfile, "%s", ASM_STABS_OP);
552 output_quoted_string (asmfile, filename);
553 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
554 #endif
557 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
559 static void
560 dbxout_end_source_file (line)
561 unsigned int line ATTRIBUTE_UNUSED;
563 #ifdef DBX_USE_BINCL
564 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
565 current_file = current_file->next;
566 #endif
569 /* Handle a few odd cases that occur when trying to make PCH files work. */
571 static void
572 dbxout_handle_pch (unsigned at_end)
574 if (! at_end)
576 /* When using the PCH, this file will be included, so we need to output
577 a BINCL. */
578 dbxout_start_source_file (0, lastfile);
580 /* The base file when using the PCH won't be the same as
581 the base file when it's being generated. */
582 lastfile = NULL;
584 else
586 /* ... and an EINCL. */
587 dbxout_end_source_file (0);
589 /* Deal with cases where 'lastfile' was never actually changed. */
590 lastfile_is_base = lastfile == NULL;
594 #if defined (DBX_DEBUGGING_INFO)
595 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
597 static void
598 dbxout_source_file (file, filename)
599 FILE *file;
600 const char *filename;
602 if (lastfile == 0 && lastfile_is_base)
604 lastfile = base_input_file;
605 lastfile_is_base = 0;
608 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
610 char ltext_label_name[100];
612 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
613 source_label_number);
614 fprintf (file, "%s", ASM_STABS_OP);
615 output_quoted_string (file, filename);
616 fprintf (asmfile, ",%d,0,0,", N_SOL);
617 assemble_name (asmfile, ltext_label_name);
618 fputc ('\n', asmfile);
619 if (current_function_decl != NULL_TREE
620 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
621 ; /* Don't change section amid function. */
622 else
623 text_section ();
624 (*targetm.asm_out.internal_label) (file, "Ltext", source_label_number);
625 source_label_number++;
626 lastfile = filename;
630 /* Output a line number symbol entry for source file FILENAME and line
631 number LINENO. */
633 static void
634 dbxout_source_line (lineno, filename)
635 unsigned int lineno;
636 const char *filename;
638 dbxout_source_file (asmfile, filename);
640 #ifdef ASM_OUTPUT_SOURCE_LINE
641 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno);
642 #else
643 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
644 #endif
647 /* Describe the beginning of an internal block within a function. */
649 static void
650 dbxout_begin_block (line, n)
651 unsigned int line ATTRIBUTE_UNUSED;
652 unsigned int n;
654 (*targetm.asm_out.internal_label) (asmfile, "LBB", n);
657 /* Describe the end line-number of an internal block within a function. */
659 static void
660 dbxout_end_block (line, n)
661 unsigned int line ATTRIBUTE_UNUSED;
662 unsigned int n;
664 (*targetm.asm_out.internal_label) (asmfile, "LBE", n);
667 /* Output dbx data for a function definition.
668 This includes a definition of the function name itself (a symbol),
669 definitions of the parameters (locating them in the parameter list)
670 and then output the block that makes up the function's body
671 (including all the auto variables of the function). */
673 static void
674 dbxout_function_decl (decl)
675 tree decl;
677 #ifndef DBX_FUNCTION_FIRST
678 dbxout_begin_function (decl);
679 #endif
680 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
681 #ifdef DBX_OUTPUT_FUNCTION_END
682 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
683 #endif
684 if (use_gnu_debug_info_extensions
685 #if defined(NO_DBX_FUNCTION_END)
686 && ! NO_DBX_FUNCTION_END
687 #endif
688 && targetm.have_named_sections)
689 dbxout_function_end ();
692 #endif /* DBX_DEBUGGING_INFO */
694 /* Debug information for a global DECL. Called from toplev.c after
695 compilation proper has finished. */
696 static void
697 dbxout_global_decl (decl)
698 tree decl;
700 if (TREE_CODE (decl) == VAR_DECL
701 && ! DECL_EXTERNAL (decl)
702 && DECL_RTL_SET_P (decl)) /* Not necessary? */
703 dbxout_symbol (decl, 0);
706 /* At the end of compilation, finish writing the symbol table.
707 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
708 to do nothing. */
710 static void
711 dbxout_finish (filename)
712 const char *filename ATTRIBUTE_UNUSED;
714 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
715 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
716 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
719 /* Output floating point type values used by the 'R' stab letter.
720 These numbers come from include/aout/stab_gnu.h in binutils/gdb.
722 There are only 3 real/complex types defined, and we need 7/6.
723 We use NF_SINGLE as a generic float type, and NF_COMPLEX as a generic
724 complex type. Since we have the type size anyways, we don't really need
725 to distinguish between different FP types, we only need to distinguish
726 between float and complex. This works fine with gdb.
728 We only use this for complex types, to avoid breaking backwards
729 compatibility for real types. complex types aren't in ISO C90, so it is
730 OK if old debuggers don't understand the debug info we emit for them. */
732 /* ??? These are supposed to be IEEE types, but we don't check for that.
733 We could perhaps add additional numbers for non-IEEE types if we need
734 them. */
736 static void
737 dbxout_fptype_value (type)
738 tree type;
740 char value = '0';
741 enum machine_mode mode = TYPE_MODE (type);
743 if (TREE_CODE (type) == REAL_TYPE)
745 if (mode == SFmode)
746 value = '1';
747 else if (mode == DFmode)
748 value = '2';
749 else if (mode == TFmode || mode == XFmode)
750 value = '6';
751 else
752 /* Use NF_SINGLE as a generic real type for other sizes. */
753 value = '1';
755 else if (TREE_CODE (type) == COMPLEX_TYPE)
757 if (mode == SCmode)
758 value = '3';
759 else if (mode == DCmode)
760 value = '4';
761 else if (mode == TCmode || mode == XCmode)
762 value = '5';
763 else
764 /* Use NF_COMPLEX as a generic complex type for other sizes. */
765 value = '3';
767 else
768 abort ();
770 putc (value, asmfile);
771 CHARS (1);
774 /* Output the index of a type. */
776 static void
777 dbxout_type_index (type)
778 tree type;
780 #ifndef DBX_USE_BINCL
781 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
782 CHARS (3);
783 #else
784 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
785 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
786 CHARS (9);
787 #endif
790 #if DBX_CONTIN_LENGTH > 0
791 /* Continue a symbol-description that gets too big.
792 End one symbol table entry with a double-backslash
793 and start a new one, eventually producing something like
794 .stabs "start......\\",code,0,value
795 .stabs "...rest",code,0,value */
797 static void
798 dbxout_continue ()
800 #ifdef DBX_CONTIN_CHAR
801 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
802 #else
803 fprintf (asmfile, "\\\\");
804 #endif
805 dbxout_finish_symbol (NULL_TREE);
806 fprintf (asmfile, "%s\"", ASM_STABS_OP);
807 current_sym_nchars = 0;
809 #endif /* DBX_CONTIN_LENGTH > 0 */
811 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
812 This must be a separate function because anonymous unions require
813 recursive calls. */
815 static void
816 dbxout_type_fields (type)
817 tree type;
819 tree tem;
821 /* Output the name, type, position (in bits), size (in bits) of each
822 field that we can support. */
823 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
825 /* Omit here local type decls until we know how to support them. */
826 if (TREE_CODE (tem) == TYPE_DECL
827 /* Omit fields whose position or size are variable or too large to
828 represent. */
829 || (TREE_CODE (tem) == FIELD_DECL
830 && (! host_integerp (bit_position (tem), 0)
831 || ! DECL_SIZE (tem)
832 || ! host_integerp (DECL_SIZE (tem), 1)))
833 /* Omit here the nameless fields that are used to skip bits. */
834 || DECL_IGNORED_P (tem))
835 continue;
837 else if (TREE_CODE (tem) != CONST_DECL)
839 /* Continue the line if necessary,
840 but not before the first field. */
841 if (tem != TYPE_FIELDS (type))
842 CONTIN;
844 if (DECL_NAME (tem))
846 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
847 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
849 else
851 fprintf (asmfile, ":");
852 CHARS (1);
855 if (use_gnu_debug_info_extensions
856 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
857 || TREE_CODE (tem) != FIELD_DECL))
859 have_used_extensions = 1;
860 putc ('/', asmfile);
861 putc ((TREE_PRIVATE (tem) ? '0'
862 : TREE_PROTECTED (tem) ? '1' : '2'),
863 asmfile);
864 CHARS (2);
867 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
868 && DECL_BIT_FIELD_TYPE (tem))
869 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
871 if (TREE_CODE (tem) == VAR_DECL)
873 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
875 tree name = DECL_ASSEMBLER_NAME (tem);
877 have_used_extensions = 1;
878 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
879 CHARS (IDENTIFIER_LENGTH (name) + 2);
881 else
883 /* If TEM is non-static, GDB won't understand it. */
884 fprintf (asmfile, ",0,0;");
885 CHARS (5);
888 else
890 putc (',', asmfile);
891 print_wide_int (int_bit_position (tem));
892 putc (',', asmfile);
893 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
894 putc (';', asmfile);
895 CHARS (3);
901 /* Subroutine of `dbxout_type_methods'. Output debug info about the
902 method described DECL. DEBUG_NAME is an encoding of the method's
903 type signature. ??? We may be able to do without DEBUG_NAME altogether
904 now. */
906 static void
907 dbxout_type_method_1 (decl, debug_name)
908 tree decl;
909 const char *debug_name;
911 char c1 = 'A', c2;
913 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
914 c2 = '?';
915 else /* it's a METHOD_TYPE. */
917 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
918 /* A for normal functions.
919 B for `const' member functions.
920 C for `volatile' member functions.
921 D for `const volatile' member functions. */
922 if (TYPE_READONLY (TREE_TYPE (firstarg)))
923 c1 += 1;
924 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
925 c1 += 2;
927 if (DECL_VINDEX (decl))
928 c2 = '*';
929 else
930 c2 = '.';
933 fprintf (asmfile, ":%s;%c%c%c", debug_name,
934 TREE_PRIVATE (decl) ? '0'
935 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
936 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
937 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
939 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
941 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
942 putc (';', asmfile);
943 CHARS (1);
944 dbxout_type (DECL_CONTEXT (decl), 0);
945 fprintf (asmfile, ";");
946 CHARS (1);
950 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
951 in TYPE. */
953 static void
954 dbxout_type_methods (type)
955 tree type;
957 /* C++: put out the method names and their parameter lists */
958 tree methods = TYPE_METHODS (type);
959 tree type_encoding;
960 tree fndecl;
961 tree last;
962 char formatted_type_identifier_length[16];
963 int type_identifier_length;
965 if (methods == NULL_TREE)
966 return;
968 type_encoding = DECL_NAME (TYPE_NAME (type));
970 #if 0
971 /* C++: Template classes break some assumptions made by this code about
972 the class names, constructor names, and encodings for assembler
973 label names. For now, disable output of dbx info for them. */
975 const char *ptr = IDENTIFIER_POINTER (type_encoding);
976 /* This should use index. (mrs) */
977 while (*ptr && *ptr != '<') ptr++;
978 if (*ptr != 0)
980 static int warned;
981 if (!warned)
982 warned = 1;
983 return;
986 #endif
988 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
990 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
992 if (TREE_CODE (methods) != TREE_VEC)
993 fndecl = methods;
994 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
995 fndecl = TREE_VEC_ELT (methods, 0);
996 else
997 fndecl = TREE_VEC_ELT (methods, 1);
999 while (fndecl)
1001 int need_prefix = 1;
1003 /* Group together all the methods for the same operation.
1004 These differ in the types of the arguments. */
1005 for (last = NULL_TREE;
1006 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1007 fndecl = TREE_CHAIN (fndecl))
1008 /* Output the name of the field (after overloading), as
1009 well as the name of the field before overloading, along
1010 with its parameter list */
1012 /* This is the "mangled" name of the method.
1013 It encodes the argument types. */
1014 const char *debug_name;
1016 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
1017 include TEMPLATE_DECLs.) The debugger doesn't know what
1018 to do with such entities anyhow. */
1019 if (TREE_CODE (fndecl) != FUNCTION_DECL)
1020 continue;
1022 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1024 CONTIN;
1026 last = fndecl;
1028 /* Also ignore abstract methods; those are only interesting to
1029 the DWARF backends. */
1030 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1031 continue;
1033 /* Redundantly output the plain name, since that's what gdb
1034 expects. */
1035 if (need_prefix)
1037 tree name = DECL_NAME (fndecl);
1038 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1039 CHARS (IDENTIFIER_LENGTH (name) + 2);
1040 need_prefix = 0;
1043 dbxout_type (TREE_TYPE (fndecl), 0);
1045 dbxout_type_method_1 (fndecl, debug_name);
1047 if (!need_prefix)
1049 putc (';', asmfile);
1050 CHARS (1);
1055 /* Emit a "range" type specification, which has the form:
1056 "r<index type>;<lower bound>;<upper bound>;".
1057 TYPE is an INTEGER_TYPE. */
1059 static void
1060 dbxout_range_type (type)
1061 tree type;
1063 fprintf (asmfile, "r");
1064 if (TREE_TYPE (type))
1065 dbxout_type (TREE_TYPE (type), 0);
1066 else if (TREE_CODE (type) != INTEGER_TYPE)
1067 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1068 else
1070 /* Traditionally, we made sure 'int' was type 1, and builtin types
1071 were defined to be sub-ranges of int. Unfortunately, this
1072 does not allow us to distinguish true sub-ranges from integer
1073 types. So, instead we define integer (non-sub-range) types as
1074 sub-ranges of themselves. This matters for Chill. If this isn't
1075 a subrange type, then we want to define it in terms of itself.
1076 However, in C, this may be an anonymous integer type, and we don't
1077 want to emit debug info referring to it. Just calling
1078 dbxout_type_index won't work anyways, because the type hasn't been
1079 defined yet. We make this work for both cases by checked to see
1080 whether this is a defined type, referring to it if it is, and using
1081 'int' otherwise. */
1082 if (TYPE_SYMTAB_ADDRESS (type) != 0)
1083 dbxout_type_index (type);
1084 else
1085 dbxout_type_index (integer_type_node);
1088 if (TYPE_MIN_VALUE (type) != 0
1089 && host_integerp (TYPE_MIN_VALUE (type), 0))
1091 putc (';', asmfile);
1092 CHARS (1);
1093 if (print_int_cst_bounds_in_octal_p (type))
1094 print_int_cst_octal (TYPE_MIN_VALUE (type));
1095 else
1096 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1098 else
1100 fprintf (asmfile, ";0");
1101 CHARS (2);
1104 if (TYPE_MAX_VALUE (type) != 0
1105 && host_integerp (TYPE_MAX_VALUE (type), 0))
1107 putc (';', asmfile);
1108 CHARS (1);
1109 if (print_int_cst_bounds_in_octal_p (type))
1110 print_int_cst_octal (TYPE_MAX_VALUE (type));
1111 else
1112 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1113 putc (';', asmfile);
1114 CHARS (1);
1116 else
1118 fprintf (asmfile, ";-1;");
1119 CHARS (4);
1123 /* Output a reference to a type. If the type has not yet been
1124 described in the dbx output, output its definition now.
1125 For a type already defined, just refer to its definition
1126 using the type number.
1128 If FULL is nonzero, and the type has been described only with
1129 a forward-reference, output the definition now.
1130 If FULL is zero in this case, just refer to the forward-reference
1131 using the number previously allocated. */
1133 static void
1134 dbxout_type (type, full)
1135 tree type;
1136 int full;
1138 tree tem;
1139 tree main_variant;
1140 static int anonymous_type_number = 0;
1142 if (TREE_CODE (type) == VECTOR_TYPE)
1143 /* The frontend feeds us a representation for the vector as a struct
1144 containing an array. Pull out the array type. */
1145 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1147 /* If there was an input error and we don't really have a type,
1148 avoid crashing and write something that is at least valid
1149 by assuming `int'. */
1150 if (type == error_mark_node)
1151 type = integer_type_node;
1152 else
1154 if (TYPE_NAME (type)
1155 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1156 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1157 full = 0;
1160 /* Try to find the "main variant" with the same name. */
1161 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1162 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1163 main_variant = TREE_TYPE (TYPE_NAME (type));
1164 else
1165 main_variant = TYPE_MAIN_VARIANT (type);
1167 /* If we are not using extensions, stabs does not distinguish const and
1168 volatile, so there is no need to make them separate types. */
1169 if (!use_gnu_debug_info_extensions)
1170 type = main_variant;
1172 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1174 /* Type has no dbx number assigned. Assign next available number. */
1175 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1177 /* Make sure type vector is long enough to record about this type. */
1179 if (next_type_number == typevec_len)
1181 typevec
1182 = (struct typeinfo *) ggc_realloc (typevec,
1183 (typevec_len * 2
1184 * sizeof typevec[0]));
1185 memset ((char *) (typevec + typevec_len), 0,
1186 typevec_len * sizeof typevec[0]);
1187 typevec_len *= 2;
1190 #ifdef DBX_USE_BINCL
1191 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1192 = current_file->file_number;
1193 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1194 = current_file->next_type_number++;
1195 #endif
1198 /* Output the number of this type, to refer to it. */
1199 dbxout_type_index (type);
1201 #ifdef DBX_TYPE_DEFINED
1202 if (DBX_TYPE_DEFINED (type))
1203 return;
1204 #endif
1206 /* If this type's definition has been output or is now being output,
1207 that is all. */
1209 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1211 case TYPE_UNSEEN:
1212 break;
1213 case TYPE_XREF:
1214 /* If we have already had a cross reference,
1215 and either that's all we want or that's the best we could do,
1216 don't repeat the cross reference.
1217 Sun dbx crashes if we do. */
1218 if (! full || !COMPLETE_TYPE_P (type)
1219 /* No way in DBX fmt to describe a variable size. */
1220 || ! host_integerp (TYPE_SIZE (type), 1))
1221 return;
1222 break;
1223 case TYPE_DEFINED:
1224 return;
1227 #ifdef DBX_NO_XREFS
1228 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1229 leave the type-number completely undefined rather than output
1230 a cross-reference. If we have already used GNU debug info extensions,
1231 then it is OK to output a cross reference. This is necessary to get
1232 proper C++ debug output. */
1233 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1234 || TREE_CODE (type) == QUAL_UNION_TYPE
1235 || TREE_CODE (type) == ENUMERAL_TYPE)
1236 && ! use_gnu_debug_info_extensions)
1237 /* We must use the same test here as we use twice below when deciding
1238 whether to emit a cross-reference. */
1239 if ((TYPE_NAME (type) != 0
1240 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1241 && DECL_IGNORED_P (TYPE_NAME (type)))
1242 && !full)
1243 || !COMPLETE_TYPE_P (type)
1244 /* No way in DBX fmt to describe a variable size. */
1245 || ! host_integerp (TYPE_SIZE (type), 1))
1247 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1248 return;
1250 #endif
1252 /* Output a definition now. */
1254 fprintf (asmfile, "=");
1255 CHARS (1);
1257 /* Mark it as defined, so that if it is self-referent
1258 we will not get into an infinite recursion of definitions. */
1260 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1262 /* If this type is a variant of some other, hand off. Types with
1263 different names are usefully distinguished. We only distinguish
1264 cv-qualified types if we're using extensions. */
1265 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1267 putc ('k', asmfile);
1268 CHARS (1);
1269 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1270 return;
1272 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1274 putc ('B', asmfile);
1275 CHARS (1);
1276 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1277 return;
1279 else if (main_variant != TYPE_MAIN_VARIANT (type))
1281 /* 'type' is a typedef; output the type it refers to. */
1282 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1283 return;
1285 /* else continue. */
1287 switch (TREE_CODE (type))
1289 case VOID_TYPE:
1290 case LANG_TYPE:
1291 /* For a void type, just define it as itself; ie, "5=5".
1292 This makes us consider it defined
1293 without saying what it is. The debugger will make it
1294 a void type when the reference is seen, and nothing will
1295 ever override that default. */
1296 dbxout_type_index (type);
1297 break;
1299 case INTEGER_TYPE:
1300 if (type == char_type_node && ! TREE_UNSIGNED (type))
1302 /* Output the type `char' as a subrange of itself!
1303 I don't understand this definition, just copied it
1304 from the output of pcc.
1305 This used to use `r2' explicitly and we used to
1306 take care to make sure that `char' was type number 2. */
1307 fprintf (asmfile, "r");
1308 CHARS (1);
1309 dbxout_type_index (type);
1310 fprintf (asmfile, ";0;127;");
1311 CHARS (7);
1314 /* If this is a subtype of another integer type, always prefer to
1315 write it as a subtype. */
1316 else if (TREE_TYPE (type) != 0
1317 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1319 /* If the size is non-standard, say what it is if we can use
1320 GDB extensions. */
1322 if (use_gnu_debug_info_extensions
1323 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1325 have_used_extensions = 1;
1326 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1327 CHARS (5);
1330 dbxout_range_type (type);
1333 else
1335 /* If the size is non-standard, say what it is if we can use
1336 GDB extensions. */
1338 if (use_gnu_debug_info_extensions
1339 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1341 have_used_extensions = 1;
1342 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1343 CHARS (5);
1346 if (print_int_cst_bounds_in_octal_p (type))
1348 fprintf (asmfile, "r");
1349 CHARS (1);
1351 /* If this type derives from another type, output type index of
1352 parent type. This is particularly important when parent type
1353 is an enumerated type, because not generating the parent type
1354 index would transform the definition of this enumerated type
1355 into a plain unsigned type. */
1356 if (TREE_TYPE (type) != 0)
1357 dbxout_type_index (TREE_TYPE (type));
1358 else
1359 dbxout_type_index (type);
1361 fprintf (asmfile, ";");
1362 CHARS (1);
1363 print_int_cst_octal (TYPE_MIN_VALUE (type));
1364 fprintf (asmfile, ";");
1365 CHARS (1);
1366 print_int_cst_octal (TYPE_MAX_VALUE (type));
1367 fprintf (asmfile, ";");
1368 CHARS (1);
1371 else
1372 /* Output other integer types as subranges of `int'. */
1373 dbxout_range_type (type);
1376 break;
1378 case REAL_TYPE:
1379 /* This used to say `r1' and we used to take care
1380 to make sure that `int' was type number 1. */
1381 fprintf (asmfile, "r");
1382 CHARS (1);
1383 dbxout_type_index (integer_type_node);
1384 putc (';', asmfile);
1385 CHARS (1);
1386 print_wide_int (int_size_in_bytes (type));
1387 fputs (";0;", asmfile);
1388 CHARS (3);
1389 break;
1391 case CHAR_TYPE:
1392 if (use_gnu_debug_info_extensions)
1394 have_used_extensions = 1;
1395 fputs ("@s", asmfile);
1396 CHARS (2);
1397 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1398 fputs (";-20;", asmfile);
1399 CHARS (4);
1401 else
1403 /* Output the type `char' as a subrange of itself.
1404 That is what pcc seems to do. */
1405 fprintf (asmfile, "r");
1406 CHARS (1);
1407 dbxout_type_index (char_type_node);
1408 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1409 CHARS (7);
1411 break;
1413 case BOOLEAN_TYPE:
1414 if (use_gnu_debug_info_extensions)
1416 have_used_extensions = 1;
1417 fputs ("@s", asmfile);
1418 CHARS (2);
1419 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1420 fputs (";-16;", asmfile);
1421 CHARS (4);
1423 else /* Define as enumeral type (False, True) */
1425 fprintf (asmfile, "eFalse:0,True:1,;");
1426 CHARS (17);
1428 break;
1430 case FILE_TYPE:
1431 putc ('d', asmfile);
1432 CHARS (1);
1433 dbxout_type (TREE_TYPE (type), 0);
1434 break;
1436 case COMPLEX_TYPE:
1437 /* Differs from the REAL_TYPE by its new data type number */
1439 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1441 putc ('R', asmfile);
1442 CHARS (1);
1443 dbxout_fptype_value (type);
1444 putc (';', asmfile);
1445 CHARS (1);
1446 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1447 fputs (";0;", asmfile);
1448 CHARS (3);
1450 else
1452 /* Output a complex integer type as a structure,
1453 pending some other way to do it. */
1454 putc ('s', asmfile);
1455 CHARS (1);
1456 print_wide_int (int_size_in_bytes (type));
1457 fprintf (asmfile, "real:");
1458 CHARS (5);
1460 dbxout_type (TREE_TYPE (type), 0);
1461 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1462 CHARS (7);
1463 fprintf (asmfile, "imag:");
1464 CHARS (5);
1465 dbxout_type (TREE_TYPE (type), 0);
1466 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1467 TYPE_PRECISION (TREE_TYPE (type)));
1468 CHARS (10);
1470 break;
1472 case SET_TYPE:
1473 if (use_gnu_debug_info_extensions)
1475 have_used_extensions = 1;
1476 fputs ("@s", asmfile);
1477 CHARS (2);
1478 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1479 putc (';', asmfile);
1480 CHARS (1);
1482 /* Check if a bitstring type, which in Chill is
1483 different from a [power]set. */
1484 if (TYPE_STRING_FLAG (type))
1486 fprintf (asmfile, "@S;");
1487 CHARS (3);
1490 putc ('S', asmfile);
1491 CHARS (1);
1492 dbxout_type (TYPE_DOMAIN (type), 0);
1493 break;
1495 case ARRAY_TYPE:
1496 /* Make arrays of packed bits look like bitstrings for chill. */
1497 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1499 have_used_extensions = 1;
1500 fputs ("@s", asmfile);
1501 CHARS (2);
1502 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1503 fprintf (asmfile, ";@S;S");
1504 CHARS (5);
1505 dbxout_type (TYPE_DOMAIN (type), 0);
1506 break;
1509 /* Output "a" followed by a range type definition
1510 for the index type of the array
1511 followed by a reference to the target-type.
1512 ar1;0;N;M for a C array of type M and size N+1. */
1513 /* Check if a character string type, which in Chill is
1514 different from an array of characters. */
1515 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1517 have_used_extensions = 1;
1518 fprintf (asmfile, "@S;");
1519 CHARS (3);
1521 tem = TYPE_DOMAIN (type);
1522 if (tem == NULL)
1524 fprintf (asmfile, "ar");
1525 CHARS (2);
1526 dbxout_type_index (integer_type_node);
1527 fprintf (asmfile, ";0;-1;");
1528 CHARS (6);
1530 else
1532 fprintf (asmfile, "a");
1533 CHARS (1);
1534 dbxout_range_type (tem);
1537 dbxout_type (TREE_TYPE (type), 0);
1538 break;
1540 case RECORD_TYPE:
1541 case UNION_TYPE:
1542 case QUAL_UNION_TYPE:
1544 int i, n_baseclasses = 0;
1546 if (TYPE_BINFO (type) != 0
1547 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1548 && TYPE_BINFO_BASETYPES (type) != 0)
1549 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1551 /* Output a structure type. We must use the same test here as we
1552 use in the DBX_NO_XREFS case above. */
1553 if ((TYPE_NAME (type) != 0
1554 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1555 && DECL_IGNORED_P (TYPE_NAME (type)))
1556 && !full)
1557 || !COMPLETE_TYPE_P (type)
1558 /* No way in DBX fmt to describe a variable size. */
1559 || ! host_integerp (TYPE_SIZE (type), 1))
1561 /* If the type is just a cross reference, output one
1562 and mark the type as partially described.
1563 If it later becomes defined, we will output
1564 its real definition.
1565 If the type has a name, don't nest its definition within
1566 another type's definition; instead, output an xref
1567 and let the definition come when the name is defined. */
1568 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1569 CHARS (2);
1570 #if 0 /* This assertion is legitimately false in C++. */
1571 /* We shouldn't be outputting a reference to a type before its
1572 definition unless the type has a tag name.
1573 A typedef name without a tag name should be impossible. */
1574 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1575 abort ();
1576 #endif
1577 if (TYPE_NAME (type) != 0)
1578 dbxout_type_name (type);
1579 else
1581 fprintf (asmfile, "$$%d", anonymous_type_number++);
1582 CHARS (5);
1585 fprintf (asmfile, ":");
1586 CHARS (1);
1587 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1588 break;
1591 /* Identify record or union, and print its size. */
1592 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1593 CHARS (1);
1594 print_wide_int (int_size_in_bytes (type));
1596 if (use_gnu_debug_info_extensions)
1598 if (n_baseclasses)
1600 have_used_extensions = 1;
1601 fprintf (asmfile, "!%d,", n_baseclasses);
1602 CHARS (8);
1605 for (i = 0; i < n_baseclasses; i++)
1607 tree binfo = TYPE_BINFO (type);
1608 tree child = BINFO_BASETYPE (binfo, i);
1609 tree access = (BINFO_BASEACCESSES (binfo)
1610 ? BINFO_BASEACCESS (binfo, i) : access_public_node);
1612 if (use_gnu_debug_info_extensions)
1614 have_used_extensions = 1;
1615 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1616 putc (access == access_public_node ? '2' : '0', asmfile);
1617 CHARS (2);
1618 if (TREE_VIA_VIRTUAL (child)
1619 && strcmp (lang_hooks.name, "GNU C++") == 0)
1620 /* For a virtual base, print the (negative) offset within
1621 the vtable where we must look to find the necessary
1622 adjustment. */
1623 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1624 * BITS_PER_UNIT);
1625 else
1626 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1627 * BITS_PER_UNIT);
1628 putc (',', asmfile);
1629 CHARS (1);
1630 dbxout_type (BINFO_TYPE (child), 0);
1631 putc (';', asmfile);
1632 CHARS (1);
1634 else
1636 /* Print out the base class information with fields
1637 which have the same names at the types they hold. */
1638 dbxout_type_name (BINFO_TYPE (child));
1639 putc (':', asmfile);
1640 CHARS (1);
1641 dbxout_type (BINFO_TYPE (child), full);
1642 putc (',', asmfile);
1643 CHARS (1);
1644 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1645 * BITS_PER_UNIT);
1646 putc (',', asmfile);
1647 CHARS (1);
1648 print_wide_int (tree_low_cst (DECL_SIZE
1649 (TYPE_NAME
1650 (BINFO_TYPE (child))),
1652 * BITS_PER_UNIT);
1653 putc (';', asmfile);
1654 CHARS (1);
1659 /* Write out the field declarations. */
1660 dbxout_type_fields (type);
1661 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1663 have_used_extensions = 1;
1664 dbxout_type_methods (type);
1667 putc (';', asmfile);
1668 CHARS (1);
1670 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1671 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1672 && TYPE_VFIELD (type))
1674 have_used_extensions = 1;
1676 /* Tell GDB+ that it may keep reading. */
1677 putc ('~', asmfile);
1678 CHARS (1);
1680 /* We need to write out info about what field this class
1681 uses as its "main" vtable pointer field, because if this
1682 field is inherited from a base class, GDB cannot necessarily
1683 figure out which field it's using in time. */
1684 if (TYPE_VFIELD (type))
1686 putc ('%', asmfile);
1687 CHARS (1);
1688 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1691 putc (';', asmfile);
1692 CHARS (1);
1694 break;
1696 case ENUMERAL_TYPE:
1697 /* We must use the same test here as we use in the DBX_NO_XREFS case
1698 above. We simplify it a bit since an enum will never have a variable
1699 size. */
1700 if ((TYPE_NAME (type) != 0
1701 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1702 && DECL_IGNORED_P (TYPE_NAME (type)))
1703 && !full)
1704 || !COMPLETE_TYPE_P (type))
1706 fprintf (asmfile, "xe");
1707 CHARS (2);
1708 dbxout_type_name (type);
1709 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1710 putc (':', asmfile);
1711 CHARS (1);
1712 return;
1714 if (use_gnu_debug_info_extensions
1715 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1717 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1718 CHARS (5);
1721 putc ('e', asmfile);
1722 CHARS (1);
1723 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1725 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1726 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1727 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1728 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1729 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1730 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1731 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1732 else
1733 print_int_cst_octal (TREE_VALUE (tem));
1735 putc (',', asmfile);
1736 CHARS (1);
1737 if (TREE_CHAIN (tem) != 0)
1738 CONTIN;
1741 putc (';', asmfile);
1742 CHARS (1);
1743 break;
1745 case POINTER_TYPE:
1746 putc ('*', asmfile);
1747 CHARS (1);
1748 dbxout_type (TREE_TYPE (type), 0);
1749 break;
1751 case METHOD_TYPE:
1752 if (use_gnu_debug_info_extensions)
1754 have_used_extensions = 1;
1755 putc ('#', asmfile);
1756 CHARS (1);
1758 /* Write the argument types out longhand. */
1759 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1760 putc (',', asmfile);
1761 CHARS (1);
1762 dbxout_type (TREE_TYPE (type), 0);
1763 dbxout_args (TYPE_ARG_TYPES (type));
1764 putc (';', asmfile);
1765 CHARS (1);
1767 else
1768 /* Treat it as a function type. */
1769 dbxout_type (TREE_TYPE (type), 0);
1770 break;
1772 case OFFSET_TYPE:
1773 if (use_gnu_debug_info_extensions)
1775 have_used_extensions = 1;
1776 putc ('@', asmfile);
1777 CHARS (1);
1778 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1779 putc (',', asmfile);
1780 CHARS (1);
1781 dbxout_type (TREE_TYPE (type), 0);
1783 else
1784 /* Should print as an int, because it is really just an offset. */
1785 dbxout_type (integer_type_node, 0);
1786 break;
1788 case REFERENCE_TYPE:
1789 if (use_gnu_debug_info_extensions)
1790 have_used_extensions = 1;
1791 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1792 CHARS (1);
1793 dbxout_type (TREE_TYPE (type), 0);
1794 break;
1796 case FUNCTION_TYPE:
1797 putc ('f', asmfile);
1798 CHARS (1);
1799 dbxout_type (TREE_TYPE (type), 0);
1800 break;
1802 default:
1803 abort ();
1807 /* Return non-zero if the given type represents an integer whose bounds
1808 should be printed in octal format. */
1810 static bool
1811 print_int_cst_bounds_in_octal_p (type)
1812 tree type;
1814 /* If we can use GDB extensions and the size is wider than a long
1815 (the size used by GDB to read them) or we may have trouble writing
1816 the bounds the usual way, write them in octal. Note the test is for
1817 the *target's* size of "long", not that of the host. The host test
1818 is just to make sure we can write it out in case the host wide int
1819 is narrower than the target "long".
1821 For unsigned types, we use octal if they are the same size or larger.
1822 This is because we print the bounds as signed decimal, and hence they
1823 can't span same size unsigned types. */
1825 if (use_gnu_debug_info_extensions
1826 && TYPE_MIN_VALUE (type) != 0
1827 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1828 && TYPE_MAX_VALUE (type) != 0
1829 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1830 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1831 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1832 && TREE_UNSIGNED (type))
1833 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1834 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1835 && TREE_UNSIGNED (type))))
1836 return TRUE;
1837 else
1838 return FALSE;
1841 /* Print the value of integer constant C, in octal,
1842 handling double precision. */
1844 static void
1845 print_int_cst_octal (c)
1846 tree c;
1848 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1849 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1850 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1851 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1853 /* GDB wants constants with no extra leading "1" bits, so
1854 we need to remove any sign-extension that might be
1855 present. */
1856 if (width == HOST_BITS_PER_WIDE_INT * 2)
1858 else if (width > HOST_BITS_PER_WIDE_INT)
1859 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1860 else if (width == HOST_BITS_PER_WIDE_INT)
1861 high = 0;
1862 else
1863 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1865 fprintf (asmfile, "0");
1866 CHARS (1);
1868 if (excess == 3)
1870 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1871 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1873 else
1875 unsigned HOST_WIDE_INT beg = high >> excess;
1876 unsigned HOST_WIDE_INT middle
1877 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1878 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1879 unsigned HOST_WIDE_INT end
1880 = low & (((unsigned HOST_WIDE_INT) 1
1881 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1882 - 1);
1884 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1885 CHARS (2);
1886 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1890 static void
1891 print_octal (value, digits)
1892 unsigned HOST_WIDE_INT value;
1893 int digits;
1895 int i;
1897 for (i = digits - 1; i >= 0; i--)
1898 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1900 CHARS (digits);
1903 /* Output C in decimal while adjusting the number of digits written. */
1905 static void
1906 print_wide_int (c)
1907 HOST_WIDE_INT c;
1909 int digs = 0;
1911 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1913 if (c < 0)
1914 digs++, c = -c;
1916 while (c > 0)
1917 c /= 10; digs++;
1919 CHARS (digs);
1922 /* Output the name of type TYPE, with no punctuation.
1923 Such names can be set up either by typedef declarations
1924 or by struct, enum and union tags. */
1926 static void
1927 dbxout_type_name (type)
1928 tree type;
1930 tree t;
1931 if (TYPE_NAME (type) == 0)
1932 abort ();
1933 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1935 t = TYPE_NAME (type);
1937 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1939 t = DECL_NAME (TYPE_NAME (type));
1941 else
1942 abort ();
1944 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1945 CHARS (IDENTIFIER_LENGTH (t));
1948 /* Output leading leading struct or class names needed for qualifying
1949 type whose scope is limited to a struct or class. */
1951 static void
1952 dbxout_class_name_qualifiers (decl)
1953 tree decl;
1955 tree context = decl_type_context (decl);
1957 if (context != NULL_TREE
1958 && TREE_CODE(context) == RECORD_TYPE
1959 && TYPE_NAME (context) != 0
1960 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
1961 || (DECL_NAME (TYPE_NAME (context)) != 0)))
1963 tree name = TYPE_NAME (context);
1965 if (TREE_CODE (name) == TYPE_DECL)
1967 dbxout_class_name_qualifiers (name);
1968 name = DECL_NAME (name);
1970 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1971 CHARS (IDENTIFIER_LENGTH (name) + 2);
1975 /* Output a .stabs for the symbol defined by DECL,
1976 which must be a ..._DECL node in the normal namespace.
1977 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1978 LOCAL is nonzero if the scope is less than the entire file.
1979 Return 1 if a stabs might have been emitted. */
1982 dbxout_symbol (decl, local)
1983 tree decl;
1984 int local ATTRIBUTE_UNUSED;
1986 tree type = TREE_TYPE (decl);
1987 tree context = NULL_TREE;
1988 int result = 0;
1990 /* Cast avoids warning in old compilers. */
1991 current_sym_code = (STAB_CODE_TYPE) 0;
1992 current_sym_value = 0;
1993 current_sym_addr = 0;
1995 /* Ignore nameless syms, but don't ignore type tags. */
1997 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1998 || DECL_IGNORED_P (decl))
1999 return 0;
2001 dbxout_prepare_symbol (decl);
2003 /* The output will always start with the symbol name,
2004 so always count that in the length-output-so-far. */
2006 if (DECL_NAME (decl) != 0)
2007 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2009 switch (TREE_CODE (decl))
2011 case CONST_DECL:
2012 /* Enum values are defined by defining the enum type. */
2013 break;
2015 case FUNCTION_DECL:
2016 if (DECL_RTL (decl) == 0)
2017 return 0;
2018 if (DECL_EXTERNAL (decl))
2019 break;
2020 /* Don't mention a nested function under its parent. */
2021 context = decl_function_context (decl);
2022 if (context == current_function_decl)
2023 break;
2024 if (GET_CODE (DECL_RTL (decl)) != MEM
2025 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2026 break;
2027 FORCE_TEXT;
2029 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2030 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2031 TREE_PUBLIC (decl) ? 'F' : 'f');
2032 result = 1;
2034 current_sym_code = N_FUN;
2035 current_sym_addr = XEXP (DECL_RTL (decl), 0);
2037 if (TREE_TYPE (type))
2038 dbxout_type (TREE_TYPE (type), 0);
2039 else
2040 dbxout_type (void_type_node, 0);
2042 /* For a nested function, when that function is compiled,
2043 mention the containing function name
2044 as well as (since dbx wants it) our own assembler-name. */
2045 if (context != 0)
2046 fprintf (asmfile, ",%s,%s",
2047 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2048 IDENTIFIER_POINTER (DECL_NAME (context)));
2050 dbxout_finish_symbol (decl);
2051 break;
2053 case TYPE_DECL:
2054 #if 0
2055 /* This seems all wrong. Outputting most kinds of types gives no name
2056 at all. A true definition gives no name; a cross-ref for a
2057 structure can give the tag name, but not a type name.
2058 It seems that no typedef name is defined by outputting a type. */
2060 /* If this typedef name was defined by outputting the type,
2061 don't duplicate it. */
2062 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
2063 && TYPE_NAME (TREE_TYPE (decl)) == decl)
2064 return 0;
2065 #endif
2066 /* Don't output the same typedef twice.
2067 And don't output what language-specific stuff doesn't want output. */
2068 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2069 return 0;
2071 FORCE_TEXT;
2072 result = 1;
2074 int tag_needed = 1;
2075 int did_output = 0;
2077 if (DECL_NAME (decl))
2079 /* Nonzero means we must output a tag as well as a typedef. */
2080 tag_needed = 0;
2082 /* Handle the case of a C++ structure or union
2083 where the TYPE_NAME is a TYPE_DECL
2084 which gives both a typedef name and a tag. */
2085 /* dbx requires the tag first and the typedef second. */
2086 if ((TREE_CODE (type) == RECORD_TYPE
2087 || TREE_CODE (type) == UNION_TYPE
2088 || TREE_CODE (type) == QUAL_UNION_TYPE)
2089 && TYPE_NAME (type) == decl
2090 && !(use_gnu_debug_info_extensions && have_used_extensions)
2091 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2092 /* Distinguish the implicit typedefs of C++
2093 from explicit ones that might be found in C. */
2094 && DECL_ARTIFICIAL (decl)
2095 /* Do not generate a tag for records of variable size,
2096 since this type can not be properly described in the
2097 DBX format, and it confuses some tools such as objdump. */
2098 && host_integerp (TYPE_SIZE (type), 1))
2100 tree name = TYPE_NAME (type);
2101 if (TREE_CODE (name) == TYPE_DECL)
2102 name = DECL_NAME (name);
2104 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2105 current_sym_value = 0;
2106 current_sym_addr = 0;
2107 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2109 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2110 IDENTIFIER_POINTER (name));
2111 dbxout_type (type, 1);
2112 dbxout_finish_symbol (NULL_TREE);
2115 /* Output .stabs (or whatever) and leading double quote. */
2116 fprintf (asmfile, "%s\"", ASM_STABS_OP);
2118 if (use_gnu_debug_info_extensions)
2120 /* Output leading class/struct qualifiers. */
2121 dbxout_class_name_qualifiers (decl);
2124 /* Output typedef name. */
2125 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2127 /* Short cut way to output a tag also. */
2128 if ((TREE_CODE (type) == RECORD_TYPE
2129 || TREE_CODE (type) == UNION_TYPE
2130 || TREE_CODE (type) == QUAL_UNION_TYPE)
2131 && TYPE_NAME (type) == decl
2132 /* Distinguish the implicit typedefs of C++
2133 from explicit ones that might be found in C. */
2134 && DECL_ARTIFICIAL (decl))
2136 if (use_gnu_debug_info_extensions && have_used_extensions)
2138 putc ('T', asmfile);
2139 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2141 #if 0 /* Now we generate the tag for this case up above. */
2142 else
2143 tag_needed = 1;
2144 #endif
2147 putc ('t', asmfile);
2148 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2150 dbxout_type (type, 1);
2151 dbxout_finish_symbol (decl);
2152 did_output = 1;
2155 /* Don't output a tag if this is an incomplete type. This prevents
2156 the sun4 Sun OS 4.x dbx from crashing. */
2158 if (tag_needed && TYPE_NAME (type) != 0
2159 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2160 || (DECL_NAME (TYPE_NAME (type)) != 0))
2161 && COMPLETE_TYPE_P (type)
2162 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2164 /* For a TYPE_DECL with no name, but the type has a name,
2165 output a tag.
2166 This is what represents `struct foo' with no typedef. */
2167 /* In C++, the name of a type is the corresponding typedef.
2168 In C, it is an IDENTIFIER_NODE. */
2169 tree name = TYPE_NAME (type);
2170 if (TREE_CODE (name) == TYPE_DECL)
2171 name = DECL_NAME (name);
2173 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2174 current_sym_value = 0;
2175 current_sym_addr = 0;
2176 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2178 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2179 IDENTIFIER_POINTER (name));
2180 dbxout_type (type, 1);
2181 dbxout_finish_symbol (NULL_TREE);
2182 did_output = 1;
2185 /* If an enum type has no name, it cannot be referred to,
2186 but we must output it anyway, since the enumeration constants
2187 can be referred to. */
2188 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2190 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2191 current_sym_value = 0;
2192 current_sym_addr = 0;
2193 current_sym_nchars = 2;
2195 /* Some debuggers fail when given NULL names, so give this a
2196 harmless name of ` '. */
2197 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2198 dbxout_type (type, 1);
2199 dbxout_finish_symbol (NULL_TREE);
2202 /* Prevent duplicate output of a typedef. */
2203 TREE_ASM_WRITTEN (decl) = 1;
2204 break;
2207 case PARM_DECL:
2208 /* Parm decls go in their own separate chains
2209 and are output by dbxout_reg_parms and dbxout_parms. */
2210 abort ();
2212 case RESULT_DECL:
2213 /* Named return value, treat like a VAR_DECL. */
2214 case VAR_DECL:
2215 if (! DECL_RTL_SET_P (decl))
2216 return 0;
2217 /* Don't mention a variable that is external.
2218 Let the file that defines it describe it. */
2219 if (DECL_EXTERNAL (decl))
2220 break;
2222 /* If the variable is really a constant
2223 and not written in memory, inform the debugger. */
2224 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2225 && DECL_INITIAL (decl) != 0
2226 && host_integerp (DECL_INITIAL (decl), 0)
2227 && ! TREE_ASM_WRITTEN (decl)
2228 && (DECL_CONTEXT (decl) == NULL_TREE
2229 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2231 if (TREE_PUBLIC (decl) == 0)
2233 /* The sun4 assembler does not grok this. */
2234 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2236 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2237 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2239 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2240 fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2241 "\",0x%x,0,0,0\n",
2242 ASM_STABS_OP, name, ival, N_LSYM);
2243 return 1;
2245 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2247 /* don't know how to do this yet. */
2249 break;
2251 /* else it is something we handle like a normal variable. */
2254 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2255 #ifdef LEAF_REG_REMAP
2256 if (current_function_uses_only_leaf_regs)
2257 leaf_renumber_regs_insn (DECL_RTL (decl));
2258 #endif
2260 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2261 break;
2263 default:
2264 break;
2266 return result;
2269 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2270 Add SUFFIX to its name, if SUFFIX is not 0.
2271 Describe the variable as residing in HOME
2272 (usually HOME is DECL_RTL (DECL), but not always).
2273 Returns 1 if the stab was really emitted. */
2275 static int
2276 dbxout_symbol_location (decl, type, suffix, home)
2277 tree decl, type;
2278 const char *suffix;
2279 rtx home;
2281 int letter = 0;
2282 int regno = -1;
2284 /* Don't mention a variable at all
2285 if it was completely optimized into nothingness.
2287 If the decl was from an inline function, then its rtl
2288 is not identically the rtl that was used in this
2289 particular compilation. */
2290 if (GET_CODE (home) == SUBREG)
2292 rtx value = home;
2294 while (GET_CODE (value) == SUBREG)
2295 value = SUBREG_REG (value);
2296 if (GET_CODE (value) == REG)
2298 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2299 return 0;
2301 home = alter_subreg (&home);
2303 if (GET_CODE (home) == REG)
2305 regno = REGNO (home);
2306 if (regno >= FIRST_PSEUDO_REGISTER)
2307 return 0;
2310 /* The kind-of-variable letter depends on where
2311 the variable is and on the scope of its name:
2312 G and N_GSYM for static storage and global scope,
2313 S for static storage and file scope,
2314 V for static storage and local scope,
2315 for those two, use N_LCSYM if data is in bss segment,
2316 N_STSYM if in data segment, N_FUN otherwise.
2317 (We used N_FUN originally, then changed to N_STSYM
2318 to please GDB. However, it seems that confused ld.
2319 Now GDB has been fixed to like N_FUN, says Kingdon.)
2320 no letter at all, and N_LSYM, for auto variable,
2321 r and N_RSYM for register variable. */
2323 if (GET_CODE (home) == MEM
2324 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2326 if (TREE_PUBLIC (decl))
2328 letter = 'G';
2329 current_sym_code = N_GSYM;
2331 else
2333 current_sym_addr = XEXP (home, 0);
2335 letter = decl_function_context (decl) ? 'V' : 'S';
2337 /* This should be the same condition as in assemble_variable, but
2338 we don't have access to dont_output_data here. So, instead,
2339 we rely on the fact that error_mark_node initializers always
2340 end up in bss for C++ and never end up in bss for C. */
2341 if (DECL_INITIAL (decl) == 0
2342 || (!strcmp (lang_hooks.name, "GNU C++")
2343 && DECL_INITIAL (decl) == error_mark_node))
2344 current_sym_code = N_LCSYM;
2345 else if (DECL_IN_TEXT_SECTION (decl))
2346 /* This is not quite right, but it's the closest
2347 of all the codes that Unix defines. */
2348 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2349 else
2351 /* Some ports can transform a symbol ref into a label ref,
2352 because the symbol ref is too far away and has to be
2353 dumped into a constant pool. Alternatively, the symbol
2354 in the constant pool might be referenced by a different
2355 symbol. */
2356 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2357 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2359 rtx tmp = get_pool_constant (current_sym_addr);
2361 if (GET_CODE (tmp) == SYMBOL_REF
2362 || GET_CODE (tmp) == LABEL_REF)
2363 current_sym_addr = tmp;
2366 /* Ultrix `as' seems to need this. */
2367 #ifdef DBX_STATIC_STAB_DATA_SECTION
2368 data_section ();
2369 #endif
2370 current_sym_code = N_STSYM;
2374 else if (regno >= 0)
2376 letter = 'r';
2377 current_sym_code = N_RSYM;
2378 current_sym_value = DBX_REGISTER_NUMBER (regno);
2380 else if (GET_CODE (home) == MEM
2381 && (GET_CODE (XEXP (home, 0)) == MEM
2382 || (GET_CODE (XEXP (home, 0)) == REG
2383 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2384 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2385 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2386 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2387 #endif
2389 /* If the value is indirect by memory or by a register
2390 that isn't the frame pointer
2391 then it means the object is variable-sized and address through
2392 that register or stack slot. DBX has no way to represent this
2393 so all we can do is output the variable as a pointer.
2394 If it's not a parameter, ignore it.
2395 (VAR_DECLs like this can be made by integrate.c.) */
2397 if (GET_CODE (XEXP (home, 0)) == REG)
2399 letter = 'r';
2400 current_sym_code = N_RSYM;
2401 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2402 return 0;
2403 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2405 else
2407 current_sym_code = N_LSYM;
2408 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2409 We want the value of that CONST_INT. */
2410 current_sym_value
2411 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2414 /* Effectively do build_pointer_type, but don't cache this type,
2415 since it might be temporary whereas the type it points to
2416 might have been saved for inlining. */
2417 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2418 type = make_node (POINTER_TYPE);
2419 TREE_TYPE (type) = TREE_TYPE (decl);
2421 else if (GET_CODE (home) == MEM
2422 && GET_CODE (XEXP (home, 0)) == REG)
2424 current_sym_code = N_LSYM;
2425 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2427 else if (GET_CODE (home) == MEM
2428 && GET_CODE (XEXP (home, 0)) == PLUS
2429 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2431 current_sym_code = N_LSYM;
2432 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2433 We want the value of that CONST_INT. */
2434 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2436 else if (GET_CODE (home) == MEM
2437 && GET_CODE (XEXP (home, 0)) == CONST)
2439 /* Handle an obscure case which can arise when optimizing and
2440 when there are few available registers. (This is *always*
2441 the case for i386/i486 targets). The RTL looks like
2442 (MEM (CONST ...)) even though this variable is a local `auto'
2443 or a local `register' variable. In effect, what has happened
2444 is that the reload pass has seen that all assignments and
2445 references for one such a local variable can be replaced by
2446 equivalent assignments and references to some static storage
2447 variable, thereby avoiding the need for a register. In such
2448 cases we're forced to lie to debuggers and tell them that
2449 this variable was itself `static'. */
2450 current_sym_code = N_LCSYM;
2451 letter = 'V';
2452 current_sym_addr = XEXP (XEXP (home, 0), 0);
2454 else if (GET_CODE (home) == CONCAT)
2456 tree subtype;
2458 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2459 for example), then there is no easy way to figure out
2460 what SUBTYPE should be. So, we give up. */
2461 if (TREE_CODE (type) != COMPLEX_TYPE)
2462 return 0;
2464 subtype = TREE_TYPE (type);
2466 /* If the variable's storage is in two parts,
2467 output each as a separate stab with a modified name. */
2468 if (WORDS_BIG_ENDIAN)
2469 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2470 else
2471 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2473 /* Cast avoids warning in old compilers. */
2474 current_sym_code = (STAB_CODE_TYPE) 0;
2475 current_sym_value = 0;
2476 current_sym_addr = 0;
2477 dbxout_prepare_symbol (decl);
2479 if (WORDS_BIG_ENDIAN)
2480 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2481 else
2482 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2483 return 1;
2485 else
2486 /* Address might be a MEM, when DECL is a variable-sized object.
2487 Or it might be const0_rtx, meaning previous passes
2488 want us to ignore this variable. */
2489 return 0;
2491 /* Ok, start a symtab entry and output the variable name. */
2492 FORCE_TEXT;
2494 #ifdef DBX_STATIC_BLOCK_START
2495 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2496 #endif
2498 dbxout_symbol_name (decl, suffix, letter);
2499 dbxout_type (type, 0);
2500 dbxout_finish_symbol (decl);
2502 #ifdef DBX_STATIC_BLOCK_END
2503 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2504 #endif
2505 return 1;
2508 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2509 Then output LETTER to indicate the kind of location the symbol has. */
2511 static void
2512 dbxout_symbol_name (decl, suffix, letter)
2513 tree decl;
2514 const char *suffix;
2515 int letter;
2517 const char *name;
2519 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2520 /* One slight hitch: if this is a VAR_DECL which is a static
2521 class member, we must put out the mangled name instead of the
2522 DECL_NAME. Note also that static member (variable) names DO NOT begin
2523 with underscores in .stabs directives. */
2524 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2525 else
2526 /* ...but if we're function-local, we don't want to include the junk
2527 added by ASM_FORMAT_PRIVATE_NAME. */
2528 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2530 if (name == 0)
2531 name = "(anon)";
2532 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2533 (suffix ? suffix : ""));
2535 if (letter)
2536 putc (letter, asmfile);
2539 static void
2540 dbxout_prepare_symbol (decl)
2541 tree decl ATTRIBUTE_UNUSED;
2543 #ifdef WINNING_GDB
2544 const char *filename = DECL_SOURCE_FILE (decl);
2546 dbxout_source_file (asmfile, filename);
2547 #endif
2550 static void
2551 dbxout_finish_symbol (sym)
2552 tree sym;
2554 #ifdef DBX_FINISH_SYMBOL
2555 DBX_FINISH_SYMBOL (sym);
2556 #else
2557 int line = 0;
2558 if (use_gnu_debug_info_extensions && sym != 0)
2559 line = DECL_SOURCE_LINE (sym);
2561 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2562 if (current_sym_addr)
2563 output_addr_const (asmfile, current_sym_addr);
2564 else
2565 fprintf (asmfile, "%d", current_sym_value);
2566 putc ('\n', asmfile);
2567 #endif
2570 /* Output definitions of all the decls in a chain. Return nonzero if
2571 anything was output */
2574 dbxout_syms (syms)
2575 tree syms;
2577 int result = 0;
2578 while (syms)
2580 result += dbxout_symbol (syms, 1);
2581 syms = TREE_CHAIN (syms);
2583 return result;
2586 /* The following two functions output definitions of function parameters.
2587 Each parameter gets a definition locating it in the parameter list.
2588 Each parameter that is a register variable gets a second definition
2589 locating it in the register.
2591 Printing or argument lists in gdb uses the definitions that
2592 locate in the parameter list. But reference to the variable in
2593 expressions uses preferentially the definition as a register. */
2595 /* Output definitions, referring to storage in the parmlist,
2596 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2598 void
2599 dbxout_parms (parms)
2600 tree parms;
2602 for (; parms; parms = TREE_CHAIN (parms))
2603 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2605 dbxout_prepare_symbol (parms);
2607 /* Perform any necessary register eliminations on the parameter's rtl,
2608 so that the debugging output will be accurate. */
2609 DECL_INCOMING_RTL (parms)
2610 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2611 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2612 #ifdef LEAF_REG_REMAP
2613 if (current_function_uses_only_leaf_regs)
2615 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2616 leaf_renumber_regs_insn (DECL_RTL (parms));
2618 #endif
2620 if (PARM_PASSED_IN_MEMORY (parms))
2622 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2624 /* ??? Here we assume that the parm address is indexed
2625 off the frame pointer or arg pointer.
2626 If that is not true, we produce meaningless results,
2627 but do not crash. */
2628 if (GET_CODE (addr) == PLUS
2629 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2630 current_sym_value = INTVAL (XEXP (addr, 1));
2631 else
2632 current_sym_value = 0;
2634 current_sym_code = N_PSYM;
2635 current_sym_addr = 0;
2637 FORCE_TEXT;
2638 if (DECL_NAME (parms))
2640 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2642 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2643 IDENTIFIER_POINTER (DECL_NAME (parms)),
2644 DBX_MEMPARM_STABS_LETTER);
2646 else
2648 current_sym_nchars = 8;
2649 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2650 DBX_MEMPARM_STABS_LETTER);
2653 /* It is quite tempting to use:
2655 dbxout_type (TREE_TYPE (parms), 0);
2657 as the next statement, rather than using DECL_ARG_TYPE(), so
2658 that gcc reports the actual type of the parameter, rather
2659 than the promoted type. This certainly makes GDB's life
2660 easier, at least for some ports. The change is a bad idea
2661 however, since GDB expects to be able access the type without
2662 performing any conversions. So for example, if we were
2663 passing a float to an unprototyped function, gcc will store a
2664 double on the stack, but if we emit a stab saying the type is a
2665 float, then gdb will only read in a single value, and this will
2666 produce an erroneous value. */
2667 dbxout_type (DECL_ARG_TYPE (parms), 0);
2668 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2669 dbxout_finish_symbol (parms);
2671 else if (GET_CODE (DECL_RTL (parms)) == REG)
2673 rtx best_rtl;
2674 char regparm_letter;
2675 tree parm_type;
2676 /* Parm passed in registers and lives in registers or nowhere. */
2678 current_sym_code = DBX_REGPARM_STABS_CODE;
2679 regparm_letter = DBX_REGPARM_STABS_LETTER;
2680 current_sym_addr = 0;
2682 /* If parm lives in a register, use that register;
2683 pretend the parm was passed there. It would be more consistent
2684 to describe the register where the parm was passed,
2685 but in practice that register usually holds something else.
2687 If we use DECL_RTL, then we must use the declared type of
2688 the variable, not the type that it arrived in. */
2689 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2691 best_rtl = DECL_RTL (parms);
2692 parm_type = TREE_TYPE (parms);
2694 /* If the parm lives nowhere, use the register where it was
2695 passed. It is also better to use the declared type here. */
2696 else
2698 best_rtl = DECL_INCOMING_RTL (parms);
2699 parm_type = TREE_TYPE (parms);
2701 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2703 FORCE_TEXT;
2704 if (DECL_NAME (parms))
2706 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2707 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2708 IDENTIFIER_POINTER (DECL_NAME (parms)),
2709 regparm_letter);
2711 else
2713 current_sym_nchars = 8;
2714 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2715 regparm_letter);
2718 dbxout_type (parm_type, 0);
2719 dbxout_finish_symbol (parms);
2721 else if (GET_CODE (DECL_RTL (parms)) == MEM
2722 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2723 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2724 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2725 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2726 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2727 #endif
2730 /* Parm was passed via invisible reference.
2731 That is, its address was passed in a register.
2732 Output it as if it lived in that register.
2733 The debugger will know from the type
2734 that it was actually passed by invisible reference. */
2736 char regparm_letter;
2737 /* Parm passed in registers and lives in registers or nowhere. */
2739 current_sym_code = DBX_REGPARM_STABS_CODE;
2740 if (use_gnu_debug_info_extensions)
2741 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2742 else
2743 regparm_letter = DBX_REGPARM_STABS_LETTER;
2745 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2746 If it is an unallocated pseudo-reg, then use the register where
2747 it was passed instead. */
2748 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2749 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2750 else
2751 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2753 current_sym_addr = 0;
2755 FORCE_TEXT;
2756 if (DECL_NAME (parms))
2758 current_sym_nchars
2759 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2761 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2762 IDENTIFIER_POINTER (DECL_NAME (parms)),
2763 regparm_letter);
2765 else
2767 current_sym_nchars = 8;
2768 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2769 regparm_letter);
2772 dbxout_type (TREE_TYPE (parms), 0);
2773 dbxout_finish_symbol (parms);
2775 else if (GET_CODE (DECL_RTL (parms)) == MEM
2776 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2778 /* Parm was passed via invisible reference, with the reference
2779 living on the stack. DECL_RTL looks like
2780 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2781 could look like (MEM (MEM (REG))). */
2782 const char *const decl_name = (DECL_NAME (parms)
2783 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2784 : "(anon)");
2785 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2786 current_sym_value = 0;
2787 else
2788 current_sym_value
2789 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2790 current_sym_addr = 0;
2791 current_sym_code = N_PSYM;
2793 FORCE_TEXT;
2794 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2796 current_sym_value
2797 = DEBUGGER_ARG_OFFSET (current_sym_value,
2798 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2799 dbxout_type (TREE_TYPE (parms), 0);
2800 dbxout_finish_symbol (parms);
2802 else if (GET_CODE (DECL_RTL (parms)) == MEM
2803 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2804 /* ??? A constant address for a parm can happen
2805 when the reg it lives in is equiv to a constant in memory.
2806 Should make this not happen, after 2.4. */
2807 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2809 /* Parm was passed in registers but lives on the stack. */
2811 current_sym_code = N_PSYM;
2812 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2813 in which case we want the value of that CONST_INT,
2814 or (MEM (REG ...)),
2815 in which case we use a value of zero. */
2816 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2817 current_sym_value = 0;
2818 else
2819 current_sym_value
2820 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2822 current_sym_addr = 0;
2824 /* Make a big endian correction if the mode of the type of the
2825 parameter is not the same as the mode of the rtl. */
2826 if (BYTES_BIG_ENDIAN
2827 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2828 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2830 current_sym_value +=
2831 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2832 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2835 FORCE_TEXT;
2836 if (DECL_NAME (parms))
2838 current_sym_nchars
2839 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2841 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2842 IDENTIFIER_POINTER (DECL_NAME (parms)),
2843 DBX_MEMPARM_STABS_LETTER);
2845 else
2847 current_sym_nchars = 8;
2848 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2849 DBX_MEMPARM_STABS_LETTER);
2852 current_sym_value
2853 = DEBUGGER_ARG_OFFSET (current_sym_value,
2854 XEXP (DECL_RTL (parms), 0));
2855 dbxout_type (TREE_TYPE (parms), 0);
2856 dbxout_finish_symbol (parms);
2861 /* Output definitions for the places where parms live during the function,
2862 when different from where they were passed, when the parms were passed
2863 in memory.
2865 It is not useful to do this for parms passed in registers
2866 that live during the function in different registers, because it is
2867 impossible to look in the passed register for the passed value,
2868 so we use the within-the-function register to begin with.
2870 PARMS is a chain of PARM_DECL nodes. */
2872 void
2873 dbxout_reg_parms (parms)
2874 tree parms;
2876 for (; parms; parms = TREE_CHAIN (parms))
2877 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2879 dbxout_prepare_symbol (parms);
2881 /* Report parms that live in registers during the function
2882 but were passed in memory. */
2883 if (GET_CODE (DECL_RTL (parms)) == REG
2884 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2885 dbxout_symbol_location (parms, TREE_TYPE (parms),
2886 0, DECL_RTL (parms));
2887 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2888 dbxout_symbol_location (parms, TREE_TYPE (parms),
2889 0, DECL_RTL (parms));
2890 /* Report parms that live in memory but not where they were passed. */
2891 else if (GET_CODE (DECL_RTL (parms)) == MEM
2892 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2893 dbxout_symbol_location (parms, TREE_TYPE (parms),
2894 0, DECL_RTL (parms));
2898 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2899 output definitions of those names, in raw form */
2901 static void
2902 dbxout_args (args)
2903 tree args;
2905 while (args)
2907 putc (',', asmfile);
2908 dbxout_type (TREE_VALUE (args), 0);
2909 CHARS (1);
2910 args = TREE_CHAIN (args);
2914 /* Output everything about a symbol block (a BLOCK node
2915 that represents a scope level),
2916 including recursive output of contained blocks.
2918 BLOCK is the BLOCK node.
2919 DEPTH is its depth within containing symbol blocks.
2920 ARGS is usually zero; but for the outermost block of the
2921 body of a function, it is a chain of PARM_DECLs for the function parameters.
2922 We output definitions of all the register parms
2923 as if they were local variables of that block.
2925 If -g1 was used, we count blocks just the same, but output nothing
2926 except for the outermost block.
2928 Actually, BLOCK may be several blocks chained together.
2929 We handle them all in sequence. */
2931 static void
2932 dbxout_block (block, depth, args)
2933 tree block;
2934 int depth;
2935 tree args;
2937 int blocknum = -1;
2939 #if DBX_BLOCKS_FUNCTION_RELATIVE
2940 const char *begin_label;
2941 if (current_function_func_begin_label != NULL_TREE)
2942 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2943 else
2944 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2945 #endif
2947 while (block)
2949 /* Ignore blocks never expanded or otherwise marked as real. */
2950 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2952 int did_output;
2954 /* In dbx format, the syms of a block come before the N_LBRAC.
2955 If nothing is output, we don't need the N_LBRAC, either. */
2956 did_output = 0;
2957 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2958 did_output = dbxout_syms (BLOCK_VARS (block));
2959 if (args)
2960 dbxout_reg_parms (args);
2962 /* Now output an N_LBRAC symbol to represent the beginning of
2963 the block. Use the block's tree-walk order to generate
2964 the assembler symbols LBBn and LBEn
2965 that final will define around the code in this block. */
2966 if (depth > 0 && did_output)
2968 char buf[20];
2969 blocknum = BLOCK_NUMBER (block);
2970 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2972 if (BLOCK_HANDLER_BLOCK (block))
2974 /* A catch block. Must precede N_LBRAC. */
2975 tree decl = BLOCK_VARS (block);
2976 while (decl)
2978 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2979 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2980 assemble_name (asmfile, buf);
2981 fprintf (asmfile, "\n");
2982 decl = TREE_CHAIN (decl);
2986 #ifdef DBX_OUTPUT_LBRAC
2987 DBX_OUTPUT_LBRAC (asmfile, buf);
2988 #else
2989 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2990 assemble_name (asmfile, buf);
2991 #if DBX_BLOCKS_FUNCTION_RELATIVE
2992 putc ('-', asmfile);
2993 assemble_name (asmfile, begin_label);
2994 #endif
2995 fprintf (asmfile, "\n");
2996 #endif
2999 /* Output the subblocks. */
3000 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3002 /* Refer to the marker for the end of the block. */
3003 if (depth > 0 && did_output)
3005 char buf[20];
3006 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3007 #ifdef DBX_OUTPUT_RBRAC
3008 DBX_OUTPUT_RBRAC (asmfile, buf);
3009 #else
3010 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3011 assemble_name (asmfile, buf);
3012 #if DBX_BLOCKS_FUNCTION_RELATIVE
3013 putc ('-', asmfile);
3014 assemble_name (asmfile, begin_label);
3015 #endif
3016 fprintf (asmfile, "\n");
3017 #endif
3020 block = BLOCK_CHAIN (block);
3024 /* Output the information about a function and its arguments and result.
3025 Usually this follows the function's code,
3026 but on some systems, it comes before. */
3028 #if defined (DBX_DEBUGGING_INFO)
3029 static void
3030 dbxout_begin_function (decl)
3031 tree decl;
3033 dbxout_symbol (decl, 0);
3034 dbxout_parms (DECL_ARGUMENTS (decl));
3035 if (DECL_NAME (DECL_RESULT (decl)) != 0)
3036 dbxout_symbol (DECL_RESULT (decl), 1);
3038 #endif /* DBX_DEBUGGING_INFO */
3040 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3042 #include "gt-dbxout.h"