Define ASM_OUTPUT_MAX_SKIP_ALIGN if the assembler supports .p2align.
[official-gcc.git] / gcc / dbxout.c
blob1252e2b5cd15acd5420924adf456b2e3e20dbcca
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 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 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"
74 #include "tree.h"
75 #include "rtl.h"
76 #include "flags.h"
77 #include "regs.h"
78 #include "insn-config.h"
79 #include "reload.h"
80 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions. */
81 #include "dbxout.h"
82 #include "toplev.h"
83 #include "tm_p.h"
84 #include "ggc.h"
86 #ifdef XCOFF_DEBUGGING_INFO
87 #include "xcoffout.h"
88 #endif
90 #ifndef ASM_STABS_OP
91 #define ASM_STABS_OP "\t.stabs\t"
92 #endif
94 #ifndef ASM_STABN_OP
95 #define ASM_STABN_OP "\t.stabn\t"
96 #endif
98 #ifndef DBX_TYPE_DECL_STABS_CODE
99 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
100 #endif
102 #ifndef DBX_STATIC_CONST_VAR_CODE
103 #define DBX_STATIC_CONST_VAR_CODE N_FUN
104 #endif
106 #ifndef DBX_REGPARM_STABS_CODE
107 #define DBX_REGPARM_STABS_CODE N_RSYM
108 #endif
110 #ifndef DBX_REGPARM_STABS_LETTER
111 #define DBX_REGPARM_STABS_LETTER 'P'
112 #endif
114 /* This is used for parameters passed by invisible reference in a register. */
115 #ifndef GDB_INV_REF_REGPARM_STABS_LETTER
116 #define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
117 #endif
119 #ifndef DBX_MEMPARM_STABS_LETTER
120 #define DBX_MEMPARM_STABS_LETTER 'p'
121 #endif
123 #ifndef FILE_NAME_JOINER
124 #define FILE_NAME_JOINER "/"
125 #endif
127 /* GDB needs to know that the stabs were generated by GCC. We emit an
128 N_OPT stab at the beginning of the source file to indicate this.
129 The string is historical, and different on a very few targets. */
130 #ifndef STABS_GCC_MARKER
131 #define STABS_GCC_MARKER "gcc2_compiled."
132 #endif
134 /* Nonzero means if the type has methods, only output debugging
135 information if methods are actually written to the asm file. This
136 optimization only works if the debugger can detect the special C++
137 marker. */
139 #define MINIMAL_DEBUG 1
141 #ifdef NO_DOLLAR_IN_LABEL
142 #ifdef NO_DOT_IN_LABEL
143 #undef MINIMAL_DEBUG
144 #define MINIMAL_DEBUG 0
145 #endif
146 #endif
148 /* Typical USG systems don't have stab.h, and they also have
149 no use for DBX-format debugging info. */
151 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
153 static int flag_minimal_debug = MINIMAL_DEBUG;
155 /* Nonzero if we have actually used any of the GDB extensions
156 to the debugging format. The idea is that we use them for the
157 first time only if there's a strong reason, but once we have done that,
158 we use them whenever convenient. */
160 static int have_used_extensions = 0;
162 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
163 for the N_SO filename stabs label. */
165 static int source_label_number = 1;
167 #ifdef DEBUG_SYMS_TEXT
168 #define FORCE_TEXT text_section ();
169 #else
170 #define FORCE_TEXT
171 #endif
173 /* If there is a system stab.h, use it. Otherwise, use our own. */
174 /* ??? This is supposed to describe the target's stab format, so using
175 the host HAVE_STAB_H appears to be wrong. For now, we use our own file
176 when cross compiling. */
177 #if defined (USG) || !defined (HAVE_STAB_H) || defined (CROSS_COMPILE)
178 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
179 #else
180 #include <stab.h>
182 /* This is a GNU extension we need to reference in this file. */
183 #ifndef N_CATCH
184 #define N_CATCH 0x54
185 #endif
187 /* This is a Solaris extension we need to reference in this file. */
188 #ifndef N_OPT
189 #define N_OPT 0x3c
190 #endif
191 #endif
193 #ifdef __GNU_STAB__
194 #define STAB_CODE_TYPE enum __stab_debug_code
195 #else
196 #define STAB_CODE_TYPE int
197 #endif
199 /* 1 if PARM is passed to this function in memory. */
201 #define PARM_PASSED_IN_MEMORY(PARM) \
202 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
204 /* A C expression for the integer offset value of an automatic variable
205 (N_LSYM) having address X (an RTX). */
206 #ifndef DEBUGGER_AUTO_OFFSET
207 #define DEBUGGER_AUTO_OFFSET(X) \
208 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
209 #endif
211 /* A C expression for the integer offset value of an argument (N_PSYM)
212 having address X (an RTX). The nominal offset is OFFSET. */
213 #ifndef DEBUGGER_ARG_OFFSET
214 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
215 #endif
217 /* Stream for writing to assembler file. */
219 static FILE *asmfile;
221 /* Last source file name mentioned in a NOTE insn. */
223 static const char *lastfile;
225 /* Current working directory. */
227 static const char *cwd;
229 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
231 /* Structure recording information about a C data type.
232 The status element says whether we have yet output
233 the definition of the type. TYPE_XREF says we have
234 output it as a cross-reference only.
235 The file_number and type_number elements are used if DBX_USE_BINCL
236 is defined. */
238 struct typeinfo
240 enum typestatus status;
241 #ifdef DBX_USE_BINCL
242 int file_number;
243 int type_number;
244 #endif
247 /* Vector recording information about C data types.
248 When we first notice a data type (a tree node),
249 we assign it a number using next_type_number.
250 That is its index in this vector. */
252 struct typeinfo *typevec;
254 /* Number of elements of space allocated in `typevec'. */
256 static int typevec_len;
258 /* In dbx output, each type gets a unique number.
259 This is the number for the next type output.
260 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
262 static int next_type_number;
264 #ifdef DBX_USE_BINCL
266 /* When using N_BINCL in dbx output, each type number is actually a
267 pair of the file number and the type number within the file.
268 This is a stack of input files. */
270 struct dbx_file
272 struct dbx_file *next;
273 int file_number;
274 int next_type_number;
277 /* This is the top of the stack. */
279 static struct dbx_file *current_file;
281 /* This is the next file number to use. */
283 static int next_file_number;
285 #endif /* DBX_USE_BINCL */
287 /* These variables are for dbxout_symbol to communicate to
288 dbxout_finish_symbol.
289 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
290 current_sym_value and current_sym_addr are two ways to address the
291 value to store in the symtab entry.
292 current_sym_addr if nonzero represents the value as an rtx.
293 If that is zero, current_sym_value is used. This is used
294 when the value is an offset (such as for auto variables,
295 register variables and parms). */
297 static STAB_CODE_TYPE current_sym_code;
298 static int current_sym_value;
299 static rtx current_sym_addr;
301 /* Number of chars of symbol-description generated so far for the
302 current symbol. Used by CHARS and CONTIN. */
304 static int current_sym_nchars;
306 /* Report having output N chars of the current symbol-description. */
308 #define CHARS(N) (current_sym_nchars += (N))
310 /* Break the current symbol-description, generating a continuation,
311 if it has become long. */
313 #ifndef DBX_CONTIN_LENGTH
314 #define DBX_CONTIN_LENGTH 80
315 #endif
317 #if DBX_CONTIN_LENGTH > 0
318 #define CONTIN \
319 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
320 #else
321 #define CONTIN do { } while (0)
322 #endif
324 #if defined(ASM_OUTPUT_SECTION_NAME)
325 static void dbxout_function_end PARAMS ((void));
326 #endif
327 static void dbxout_typedefs PARAMS ((tree));
328 static void dbxout_type_index PARAMS ((tree));
329 #if DBX_CONTIN_LENGTH > 0
330 static void dbxout_continue PARAMS ((void));
331 #endif
332 static void dbxout_type_fields PARAMS ((tree));
333 static void dbxout_type_method_1 PARAMS ((tree, const char *));
334 static void dbxout_type_methods PARAMS ((tree));
335 static void dbxout_range_type PARAMS ((tree));
336 static void dbxout_type PARAMS ((tree, int, int));
337 static void print_int_cst_octal PARAMS ((tree));
338 static void print_octal PARAMS ((unsigned HOST_WIDE_INT, int));
339 static void dbxout_type_name PARAMS ((tree));
340 static int dbxout_symbol_location PARAMS ((tree, tree, const char *, rtx));
341 static void dbxout_symbol_name PARAMS ((tree, const char *, int));
342 static void dbxout_prepare_symbol PARAMS ((tree));
343 static void dbxout_finish_symbol PARAMS ((tree));
344 static void dbxout_block PARAMS ((tree, int, tree));
345 static void dbxout_really_begin_function PARAMS ((tree));
347 #if defined(ASM_OUTPUT_SECTION_NAME)
348 static void
349 dbxout_function_end ()
351 static int scope_labelno = 0;
352 char lscope_label_name[100];
353 /* Convert Ltext into the appropriate format for local labels in case
354 the system doesn't insert underscores in front of user generated
355 labels. */
356 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
357 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Lscope", scope_labelno);
358 scope_labelno++;
360 /* By convention, GCC will mark the end of a function with an N_FUN
361 symbol and an empty string. */
362 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
363 assemble_name (asmfile, lscope_label_name);
364 fputc ('-', asmfile);
365 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
366 fprintf (asmfile, "\n");
368 #endif /* ! NO_DBX_FUNCTION_END */
370 /* At the beginning of compilation, start writing the symbol table.
371 Initialize `typevec' and output the standard data types of C. */
373 void
374 dbxout_init (asm_file, input_file_name, syms)
375 FILE *asm_file;
376 const char *input_file_name;
377 tree syms;
379 char ltext_label_name[100];
381 asmfile = asm_file;
383 typevec_len = 100;
384 typevec = (struct typeinfo *) xcalloc (typevec_len, sizeof typevec[0]);
386 /* Convert Ltext into the appropriate format for local labels in case
387 the system doesn't insert underscores in front of user generated
388 labels. */
389 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
391 /* Put the current working directory in an N_SO symbol. */
392 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
393 but GDB always does. */
394 if (use_gnu_debug_info_extensions)
395 #endif
397 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
398 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
399 if (cwd)
401 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
402 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
403 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
404 fprintf (asmfile, "%s", ASM_STABS_OP);
405 output_quoted_string (asmfile, cwd);
406 fprintf (asmfile, ",%d,0,0,%s\n", N_SO, &ltext_label_name[1]);
407 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
411 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
412 /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
413 would give us an N_SOL, and we want an N_SO. */
414 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
415 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
416 /* We include outputting `Ltext:' here,
417 because that gives you a way to override it. */
418 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
419 fprintf (asmfile, "%s", ASM_STABS_OP);
420 output_quoted_string (asmfile, input_file_name);
421 fprintf (asmfile, ",%d,0,0,%s\n",
422 N_SO, &ltext_label_name[1]);
423 text_section ();
424 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0);
425 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
427 #ifdef DBX_OUTPUT_GCC_MARKER
428 DBX_OUTPUT_GCC_MARKER (asmfile);
429 #else
430 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
431 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
432 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
433 #endif
435 lastfile = input_file_name;
437 next_type_number = 1;
439 #ifdef DBX_USE_BINCL
440 current_file = (struct dbx_file *) xmalloc (sizeof *current_file);
441 current_file->next = NULL;
442 current_file->file_number = 0;
443 current_file->next_type_number = 1;
444 next_file_number = 1;
445 #endif
447 /* Make sure that types `int' and `char' have numbers 1 and 2.
448 Definitions of other integer types will refer to those numbers.
449 (Actually it should no longer matter what their numbers are.
450 Also, if any types with tags have been defined, dbxout_symbol
451 will output them first, so the numbers won't be 1 and 2. That
452 happens in C++. So it's a good thing it should no longer matter). */
454 #ifdef DBX_OUTPUT_STANDARD_TYPES
455 DBX_OUTPUT_STANDARD_TYPES (syms);
456 #else
457 dbxout_symbol (TYPE_NAME (integer_type_node), 0);
458 dbxout_symbol (TYPE_NAME (char_type_node), 0);
459 #endif
461 /* Get all permanent types that have typedef names,
462 and output them all, except for those already output. */
464 dbxout_typedefs (syms);
467 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
468 in the reverse order from that which is found in SYMS. */
470 static void
471 dbxout_typedefs (syms)
472 tree syms;
474 if (syms)
476 dbxout_typedefs (TREE_CHAIN (syms));
477 if (TREE_CODE (syms) == TYPE_DECL)
479 tree type = TREE_TYPE (syms);
480 if (TYPE_NAME (type)
481 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
482 && COMPLETE_TYPE_P (type)
483 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
484 dbxout_symbol (TYPE_NAME (type), 0);
489 /* Change to reading from a new source file. Generate a N_BINCL stab. */
491 void
492 dbxout_start_new_source_file (filename)
493 const char *filename ATTRIBUTE_UNUSED;
495 #ifdef DBX_USE_BINCL
496 struct dbx_file *n = (struct dbx_file *) xmalloc (sizeof *n);
498 n->next = current_file;
499 n->file_number = next_file_number++;
500 n->next_type_number = 1;
501 current_file = n;
502 fprintf (asmfile, "%s", ASM_STABS_OP);
503 output_quoted_string (asmfile, filename);
504 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
505 #endif
508 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
510 void
511 dbxout_resume_previous_source_file ()
513 #ifdef DBX_USE_BINCL
514 struct dbx_file *next;
516 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
517 next = current_file->next;
518 free (current_file);
519 current_file = next;
520 #endif
523 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
525 void
526 dbxout_source_file (file, filename)
527 FILE *file;
528 const char *filename;
530 char ltext_label_name[100];
532 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
534 #ifdef DBX_OUTPUT_SOURCE_FILENAME
535 DBX_OUTPUT_SOURCE_FILENAME (file, filename);
536 #else
537 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
538 source_label_number);
539 fprintf (file, "%s", ASM_STABS_OP);
540 output_quoted_string (file, filename);
541 fprintf (file, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
542 if (current_function_decl != NULL_TREE
543 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
544 ; /* Don't change section amid function. */
545 else
546 text_section ();
547 ASM_OUTPUT_INTERNAL_LABEL (file, "Ltext", source_label_number);
548 source_label_number++;
549 #endif
550 lastfile = filename;
554 /* Output a line number symbol entry into output stream FILE,
555 for source file FILENAME and line number LINENO. */
557 void
558 dbxout_source_line (file, filename, lineno)
559 FILE *file;
560 const char *filename;
561 int lineno;
563 dbxout_source_file (file, filename);
565 #ifdef ASM_OUTPUT_SOURCE_LINE
566 ASM_OUTPUT_SOURCE_LINE (file, lineno);
567 #else
568 fprintf (file, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
569 #endif
572 /* At the end of compilation, finish writing the symbol table.
573 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
574 to do nothing. */
576 void
577 dbxout_finish (file, filename)
578 FILE *file ATTRIBUTE_UNUSED;
579 const char *filename ATTRIBUTE_UNUSED;
581 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
582 DBX_OUTPUT_MAIN_SOURCE_FILE_END (file, filename);
583 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
586 /* Output the index of a type. */
588 static void
589 dbxout_type_index (type)
590 tree type;
592 #ifndef DBX_USE_BINCL
593 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
594 CHARS (3);
595 #else
596 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
597 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
598 CHARS (7);
599 #endif
602 #if DBX_CONTIN_LENGTH > 0
603 /* Continue a symbol-description that gets too big.
604 End one symbol table entry with a double-backslash
605 and start a new one, eventually producing something like
606 .stabs "start......\\",code,0,value
607 .stabs "...rest",code,0,value */
609 static void
610 dbxout_continue ()
612 #ifdef DBX_CONTIN_CHAR
613 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
614 #else
615 fprintf (asmfile, "\\\\");
616 #endif
617 dbxout_finish_symbol (NULL_TREE);
618 fprintf (asmfile, "%s\"", ASM_STABS_OP);
619 current_sym_nchars = 0;
621 #endif /* DBX_CONTIN_LENGTH > 0 */
623 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
624 This must be a separate function because anonymous unions require
625 recursive calls. */
627 static void
628 dbxout_type_fields (type)
629 tree type;
631 tree tem;
633 /* Output the name, type, position (in bits), size (in bits) of each
634 field that we can support. */
635 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
637 /* Omit here local type decls until we know how to support them. */
638 if (TREE_CODE (tem) == TYPE_DECL
639 /* Omit fields whose position or size are variable or too large to
640 represent. */
641 || (TREE_CODE (tem) == FIELD_DECL
642 && (! host_integerp (bit_position (tem), 0)
643 || ! DECL_SIZE (tem)
644 || ! host_integerp (DECL_SIZE (tem), 1)))
645 /* Omit here the nameless fields that are used to skip bits. */
646 || DECL_IGNORED_P (tem))
647 continue;
649 else if (TREE_CODE (tem) != CONST_DECL)
651 /* Continue the line if necessary,
652 but not before the first field. */
653 if (tem != TYPE_FIELDS (type))
654 CONTIN;
656 if (use_gnu_debug_info_extensions
657 && flag_minimal_debug
658 && TREE_CODE (tem) == FIELD_DECL
659 && DECL_VIRTUAL_P (tem)
660 && DECL_ASSEMBLER_NAME (tem))
662 have_used_extensions = 1;
663 CHARS (3 + IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (tem)));
664 fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem)), asmfile);
665 dbxout_type (DECL_FCONTEXT (tem), 0, 0);
666 fprintf (asmfile, ":");
667 dbxout_type (TREE_TYPE (tem), 0, 0);
668 fputc (',', asmfile);
669 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
670 int_bit_position (tem));
671 fputc (';', asmfile);
672 continue;
675 if (DECL_NAME (tem))
677 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
678 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
680 else
682 fprintf (asmfile, ":");
683 CHARS (2);
686 if (use_gnu_debug_info_extensions
687 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
688 || TREE_CODE (tem) != FIELD_DECL))
690 have_used_extensions = 1;
691 putc ('/', asmfile);
692 putc ((TREE_PRIVATE (tem) ? '0'
693 : TREE_PROTECTED (tem) ? '1' : '2'),
694 asmfile);
695 CHARS (2);
698 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
699 && DECL_BIT_FIELD_TYPE (tem))
700 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0, 0);
702 if (TREE_CODE (tem) == VAR_DECL)
704 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
706 const char *name =
707 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
708 have_used_extensions = 1;
709 fprintf (asmfile, ":%s;", name);
710 CHARS (strlen (name));
712 else
713 /* If TEM is non-static, GDB won't understand it. */
714 fprintf (asmfile, ",0,0;");
716 else
718 fputc (',', asmfile);
719 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
720 int_bit_position (tem));
721 fputc (',', asmfile);
722 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
723 tree_low_cst (DECL_SIZE (tem), 1));
724 fputc (';', asmfile);
725 CHARS (23);
731 /* Subroutine of `dbxout_type_methods'. Output debug info about the
732 method described DECL. DEBUG_NAME is an encoding of the method's
733 type signature. ??? We may be able to do without DEBUG_NAME altogether
734 now. */
736 static void
737 dbxout_type_method_1 (decl, debug_name)
738 tree decl;
739 const char *debug_name;
741 char c1 = 'A', c2;
743 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
744 c2 = '?';
745 else /* it's a METHOD_TYPE. */
747 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
748 /* A for normal functions.
749 B for `const' member functions.
750 C for `volatile' member functions.
751 D for `const volatile' member functions. */
752 if (TYPE_READONLY (TREE_TYPE (firstarg)))
753 c1 += 1;
754 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
755 c1 += 2;
757 if (DECL_VINDEX (decl))
758 c2 = '*';
759 else
760 c2 = '.';
763 fprintf (asmfile, ":%s;%c%c%c", debug_name,
764 TREE_PRIVATE (decl) ? '0'
765 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
766 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
767 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
769 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
771 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
772 tree_low_cst (DECL_VINDEX (decl), 0));
773 fputc (';', asmfile);
774 dbxout_type (DECL_CONTEXT (decl), 0, 0);
775 fprintf (asmfile, ";");
776 CHARS (8);
780 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
781 in TYPE. */
783 static void
784 dbxout_type_methods (type)
785 register tree type;
787 /* C++: put out the method names and their parameter lists */
788 tree methods = TYPE_METHODS (type);
789 tree type_encoding;
790 register tree fndecl;
791 register tree last;
792 char formatted_type_identifier_length[16];
793 register int type_identifier_length;
795 if (methods == NULL_TREE)
796 return;
798 type_encoding = DECL_NAME (TYPE_NAME (type));
800 #if 0
801 /* C++: Template classes break some assumptions made by this code about
802 the class names, constructor names, and encodings for assembler
803 label names. For now, disable output of dbx info for them. */
805 const char *ptr = IDENTIFIER_POINTER (type_encoding);
806 /* This should use index. (mrs) */
807 while (*ptr && *ptr != '<') ptr++;
808 if (*ptr != 0)
810 static int warned;
811 if (!warned)
812 warned = 1;
813 return;
816 #endif
818 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
820 sprintf(formatted_type_identifier_length, "%d", type_identifier_length);
822 if (TREE_CODE (methods) != TREE_VEC)
823 fndecl = methods;
824 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
825 fndecl = TREE_VEC_ELT (methods, 0);
826 else
827 fndecl = TREE_VEC_ELT (methods, 1);
829 while (fndecl)
831 tree name = DECL_NAME (fndecl);
832 int need_prefix = 1;
834 /* Group together all the methods for the same operation.
835 These differ in the types of the arguments. */
836 for (last = NULL_TREE;
837 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
838 fndecl = TREE_CHAIN (fndecl))
839 /* Output the name of the field (after overloading), as
840 well as the name of the field before overloading, along
841 with its parameter list */
843 /* This is the "mangled" name of the method.
844 It encodes the argument types. */
845 const char *debug_name;
846 int show_arg_types = 0;
848 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
849 include TEMPLATE_DECLs.) The debugger doesn't know what
850 to do with such entities anyhow. */
851 if (TREE_CODE (fndecl) != FUNCTION_DECL)
852 continue;
854 debug_name =
855 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
857 CONTIN;
859 last = fndecl;
861 /* Also ignore abstract methods; those are only interesting to
862 the DWARF backends. */
863 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
864 continue;
866 if (flag_minimal_debug)
868 char marker;
870 /* We can't optimize a method which uses an anonymous
871 class, because the debugger will not be able to
872 associate the arbitrary class name with the actual
873 class. */
874 #ifndef NO_DOLLAR_IN_LABEL
875 marker = '$';
876 #else
877 marker = '.';
878 #endif
879 if (strchr (debug_name, marker))
880 show_arg_types = 1;
881 /* Detect ordinary methods because their mangled names
882 start with the operation name. */
883 else if (!strncmp (IDENTIFIER_POINTER (name), debug_name,
884 IDENTIFIER_LENGTH (name)))
886 debug_name += IDENTIFIER_LENGTH (name);
887 if (debug_name[0] == '_' && debug_name[1] == '_')
889 const char *method_name = debug_name + 2;
890 const char *length_ptr =
891 formatted_type_identifier_length;
892 /* Get past const and volatile qualifiers. */
893 while (*method_name == 'C' || *method_name == 'V')
894 method_name++;
895 /* Skip digits for length of type_encoding. */
896 while (*method_name == *length_ptr && *length_ptr)
897 length_ptr++, method_name++;
898 if (! strncmp (method_name,
899 IDENTIFIER_POINTER (type_encoding),
900 type_identifier_length))
901 method_name += type_identifier_length;
902 debug_name = method_name;
905 /* Detect constructors by their style of name mangling. */
906 else if (debug_name[0] == '_' && debug_name[1] == '_')
908 const char *ctor_name = debug_name + 2;
909 const char *length_ptr = formatted_type_identifier_length;
910 while (*ctor_name == 'C' || *ctor_name == 'V')
911 ctor_name++;
912 /* Skip digits for length of type_encoding. */
913 while (*ctor_name == *length_ptr && *length_ptr)
914 length_ptr++, ctor_name++;
915 if (!strncmp (IDENTIFIER_POINTER (type_encoding), ctor_name,
916 type_identifier_length))
917 debug_name = ctor_name + type_identifier_length;
919 /* The other alternative is a destructor. */
920 else
921 show_arg_types = 1;
923 /* Output the operation name just once, for the first method
924 that we output. */
925 if (need_prefix)
927 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
928 CHARS (IDENTIFIER_LENGTH (name) + 2);
929 need_prefix = 0;
933 dbxout_type (TREE_TYPE (fndecl), 0, show_arg_types);
935 dbxout_type_method_1 (fndecl, debug_name);
937 if (!need_prefix)
939 putc (';', asmfile);
940 CHARS (1);
945 /* Emit a "range" type specification, which has the form:
946 "r<index type>;<lower bound>;<upper bound>;".
947 TYPE is an INTEGER_TYPE. */
949 static void
950 dbxout_range_type (type)
951 tree type;
953 fprintf (asmfile, "r");
954 if (TREE_TYPE (type))
955 dbxout_type (TREE_TYPE (type), 0, 0);
956 else if (TREE_CODE (type) != INTEGER_TYPE)
957 dbxout_type (type, 0, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
958 else
960 /* Traditionally, we made sure 'int' was type 1, and builtin types
961 were defined to be sub-ranges of int. Unfortunately, this
962 does not allow us to distinguish true sub-ranges from integer
963 types. So, instead we define integer (non-sub-range) types as
964 sub-ranges of themselves. This matters for Chill. If this isn't
965 a subrange type, then we want to define it in terms of itself.
966 However, in C, this may be an anonymous integer type, and we don't
967 want to emit debug info referring to it. Just calling
968 dbxout_type_index won't work anyways, because the type hasn't been
969 defined yet. We make this work for both cases by checked to see
970 whether this is a defined type, referring to it if it is, and using
971 'int' otherwise. */
972 if (TYPE_SYMTAB_ADDRESS (type) != 0)
973 dbxout_type_index (type);
974 else
975 dbxout_type_index (integer_type_node);
978 if (TYPE_MIN_VALUE (type) != 0
979 && host_integerp (TYPE_MIN_VALUE (type), 0))
981 fputc (';', asmfile);
982 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
983 tree_low_cst (TYPE_MIN_VALUE (type), 0));
985 else
986 fprintf (asmfile, ";0");
988 if (TYPE_MAX_VALUE (type) != 0
989 && host_integerp (TYPE_MAX_VALUE (type), 0))
991 fputc (';', asmfile);
992 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
993 tree_low_cst (TYPE_MAX_VALUE (type), 0));
994 fputc (';', asmfile);
996 else
997 fprintf (asmfile, ";-1;");
1000 /* Output a reference to a type. If the type has not yet been
1001 described in the dbx output, output its definition now.
1002 For a type already defined, just refer to its definition
1003 using the type number.
1005 If FULL is nonzero, and the type has been described only with
1006 a forward-reference, output the definition now.
1007 If FULL is zero in this case, just refer to the forward-reference
1008 using the number previously allocated.
1010 If SHOW_ARG_TYPES is nonzero, we output a description of the argument
1011 types for a METHOD_TYPE. */
1013 static void
1014 dbxout_type (type, full, show_arg_types)
1015 tree type;
1016 int full;
1017 int show_arg_types;
1019 register tree tem;
1020 static int anonymous_type_number = 0;
1022 if (TREE_CODE (type) == VECTOR_TYPE)
1023 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
1025 /* If there was an input error and we don't really have a type,
1026 avoid crashing and write something that is at least valid
1027 by assuming `int'. */
1028 if (type == error_mark_node)
1029 type = integer_type_node;
1030 else
1032 /* Try to find the "main variant" with the same name but not const
1033 or volatile. (Since stabs does not distinguish const and volatile,
1034 there is no need to make them separate types. But types with
1035 different names are usefully distinguished.) */
1037 for (tem = TYPE_MAIN_VARIANT (type); tem; tem = TYPE_NEXT_VARIANT (tem))
1038 if (!TYPE_READONLY (tem) && !TYPE_VOLATILE (tem)
1039 && TYPE_NAME (tem) == TYPE_NAME (type))
1041 type = tem;
1042 break;
1044 if (TYPE_NAME (type)
1045 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1046 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1047 full = 0;
1050 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1052 /* Type has no dbx number assigned. Assign next available number. */
1053 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1055 /* Make sure type vector is long enough to record about this type. */
1057 if (next_type_number == typevec_len)
1059 typevec
1060 = (struct typeinfo *) xrealloc (typevec,
1061 typevec_len * 2 * sizeof typevec[0]);
1062 memset ((char *) (typevec + typevec_len), 0,
1063 typevec_len * sizeof typevec[0]);
1064 typevec_len *= 2;
1067 #ifdef DBX_USE_BINCL
1068 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1069 = current_file->file_number;
1070 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1071 = current_file->next_type_number++;
1072 #endif
1075 /* Output the number of this type, to refer to it. */
1076 dbxout_type_index (type);
1078 #ifdef DBX_TYPE_DEFINED
1079 if (DBX_TYPE_DEFINED (type))
1080 return;
1081 #endif
1083 /* If this type's definition has been output or is now being output,
1084 that is all. */
1086 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1088 case TYPE_UNSEEN:
1089 break;
1090 case TYPE_XREF:
1091 /* If we have already had a cross reference,
1092 and either that's all we want or that's the best we could do,
1093 don't repeat the cross reference.
1094 Sun dbx crashes if we do. */
1095 if (! full || !COMPLETE_TYPE_P (type)
1096 /* No way in DBX fmt to describe a variable size. */
1097 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1098 return;
1099 break;
1100 case TYPE_DEFINED:
1101 return;
1104 #ifdef DBX_NO_XREFS
1105 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1106 leave the type-number completely undefined rather than output
1107 a cross-reference. If we have already used GNU debug info extensions,
1108 then it is OK to output a cross reference. This is necessary to get
1109 proper C++ debug output. */
1110 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1111 || TREE_CODE (type) == QUAL_UNION_TYPE
1112 || TREE_CODE (type) == ENUMERAL_TYPE)
1113 && ! use_gnu_debug_info_extensions)
1114 /* We must use the same test here as we use twice below when deciding
1115 whether to emit a cross-reference. */
1116 if ((TYPE_NAME (type) != 0
1117 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1118 && DECL_IGNORED_P (TYPE_NAME (type)))
1119 && !full)
1120 || !COMPLETE_TYPE_P (type)
1121 /* No way in DBX fmt to describe a variable size. */
1122 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1124 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1125 return;
1127 #endif
1129 /* Output a definition now. */
1131 fprintf (asmfile, "=");
1132 CHARS (1);
1134 /* Mark it as defined, so that if it is self-referent
1135 we will not get into an infinite recursion of definitions. */
1137 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1139 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1140 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1142 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0, 0);
1143 return;
1146 switch (TREE_CODE (type))
1148 case VOID_TYPE:
1149 case LANG_TYPE:
1150 /* For a void type, just define it as itself; ie, "5=5".
1151 This makes us consider it defined
1152 without saying what it is. The debugger will make it
1153 a void type when the reference is seen, and nothing will
1154 ever override that default. */
1155 dbxout_type_index (type);
1156 break;
1158 case INTEGER_TYPE:
1159 if (type == char_type_node && ! TREE_UNSIGNED (type))
1161 /* Output the type `char' as a subrange of itself!
1162 I don't understand this definition, just copied it
1163 from the output of pcc.
1164 This used to use `r2' explicitly and we used to
1165 take care to make sure that `char' was type number 2. */
1166 fprintf (asmfile, "r");
1167 dbxout_type_index (type);
1168 fprintf (asmfile, ";0;127;");
1171 /* If this is a subtype of another integer type, always prefer to
1172 write it as a subtype. */
1173 else if (TREE_TYPE (type) != 0
1174 && TREE_CODE (TREE_TYPE (type)) == INTEGER_CST)
1175 dbxout_range_type (type);
1177 else
1179 /* If the size is non-standard, say what it is if we can use
1180 GDB extensions. */
1182 if (use_gnu_debug_info_extensions
1183 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1184 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1186 /* If we can use GDB extensions and the size is wider than a
1187 long (the size used by GDB to read them) or we may have
1188 trouble writing the bounds the usual way, write them in
1189 octal. Note the test is for the *target's* size of "long",
1190 not that of the host. The host test is just to make sure we
1191 can write it out in case the host wide int is narrower than the
1192 target "long". */
1194 /* For unsigned types, we use octal if they are the same size or
1195 larger. This is because we print the bounds as signed decimal,
1196 and hence they can't span same size unsigned types. */
1198 if (use_gnu_debug_info_extensions
1199 && TYPE_MIN_VALUE (type) != 0
1200 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1201 && TYPE_MAX_VALUE (type) != 0
1202 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1203 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1204 || (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)
1205 && TREE_UNSIGNED (type))
1206 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1207 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1208 && TREE_UNSIGNED (type))))
1210 fprintf (asmfile, "r");
1211 dbxout_type_index (type);
1212 fprintf (asmfile, ";");
1213 print_int_cst_octal (TYPE_MIN_VALUE (type));
1214 fprintf (asmfile, ";");
1215 print_int_cst_octal (TYPE_MAX_VALUE (type));
1216 fprintf (asmfile, ";");
1219 else
1220 /* Output other integer types as subranges of `int'. */
1221 dbxout_range_type (type);
1224 CHARS (22);
1225 break;
1227 case REAL_TYPE:
1228 /* This used to say `r1' and we used to take care
1229 to make sure that `int' was type number 1. */
1230 fprintf (asmfile, "r");
1231 dbxout_type_index (integer_type_node);
1232 fputc (';', asmfile);
1233 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, int_size_in_bytes (type));
1234 fputs (";0;", asmfile);
1235 CHARS (13);
1236 break;
1238 case CHAR_TYPE:
1239 if (use_gnu_debug_info_extensions)
1241 fputs ("@s", asmfile);
1242 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1243 BITS_PER_UNIT * int_size_in_bytes (type));
1244 fputs (";-20;", asmfile);
1246 else
1248 /* Output the type `char' as a subrange of itself.
1249 That is what pcc seems to do. */
1250 fprintf (asmfile, "r");
1251 dbxout_type_index (char_type_node);
1252 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1254 CHARS (9);
1255 break;
1257 case BOOLEAN_TYPE:
1258 if (use_gnu_debug_info_extensions)
1260 fputs ("@s", asmfile);
1261 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1262 BITS_PER_UNIT * int_size_in_bytes (type));
1263 fputs (";-16;", asmfile);
1265 else /* Define as enumeral type (False, True) */
1266 fprintf (asmfile, "eFalse:0,True:1,;");
1267 CHARS (17);
1268 break;
1270 case FILE_TYPE:
1271 putc ('d', asmfile);
1272 CHARS (1);
1273 dbxout_type (TREE_TYPE (type), 0, 0);
1274 break;
1276 case COMPLEX_TYPE:
1277 /* Differs from the REAL_TYPE by its new data type number */
1279 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1281 fprintf (asmfile, "r");
1282 dbxout_type_index (type);
1283 fputc (';', asmfile);
1284 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1285 2 * int_size_in_bytes (TREE_TYPE (type)));
1286 fputs (";0;", asmfile);
1287 CHARS (12); /* The number is probably incorrect here. */
1289 else
1291 /* Output a complex integer type as a structure,
1292 pending some other way to do it. */
1293 fputc ('s', asmfile);
1294 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, int_size_in_bytes (type));
1296 fprintf (asmfile, "real:");
1297 CHARS (10);
1298 dbxout_type (TREE_TYPE (type), 0, 0);
1299 fprintf (asmfile, ",%d,%d;",
1300 0, TYPE_PRECISION (TREE_TYPE (type)));
1301 CHARS (8);
1302 fprintf (asmfile, "imag:");
1303 CHARS (5);
1304 dbxout_type (TREE_TYPE (type), 0, 0);
1305 fprintf (asmfile, ",%d,%d;;",
1306 TYPE_PRECISION (TREE_TYPE (type)),
1307 TYPE_PRECISION (TREE_TYPE (type)));
1308 CHARS (9);
1310 break;
1312 case SET_TYPE:
1313 if (use_gnu_debug_info_extensions)
1315 have_used_extensions = 1;
1316 fputs ("@s", asmfile);
1317 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1318 BITS_PER_UNIT * int_size_in_bytes (type));
1319 fputc (';', asmfile);
1320 /* Check if a bitstring type, which in Chill is
1321 different from a [power]set. */
1322 if (TYPE_STRING_FLAG (type))
1323 fprintf (asmfile, "@S;");
1325 putc ('S', asmfile);
1326 CHARS (1);
1327 dbxout_type (TYPE_DOMAIN (type), 0, 0);
1328 break;
1330 case ARRAY_TYPE:
1331 /* Make arrays of packed bits look like bitstrings for chill. */
1332 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1334 have_used_extensions = 1;
1335 fputs ("@s", asmfile);
1336 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1337 BITS_PER_UNIT * int_size_in_bytes (type));
1338 fputc (';', asmfile);
1339 fprintf (asmfile, "@S;");
1340 putc ('S', asmfile);
1341 CHARS (1);
1342 dbxout_type (TYPE_DOMAIN (type), 0, 0);
1343 break;
1345 /* Output "a" followed by a range type definition
1346 for the index type of the array
1347 followed by a reference to the target-type.
1348 ar1;0;N;M for a C array of type M and size N+1. */
1349 /* Check if a character string type, which in Chill is
1350 different from an array of characters. */
1351 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1353 have_used_extensions = 1;
1354 fprintf (asmfile, "@S;");
1356 tem = TYPE_DOMAIN (type);
1357 if (tem == NULL)
1359 fprintf (asmfile, "ar");
1360 dbxout_type_index (integer_type_node);
1361 fprintf (asmfile, ";0;-1;");
1363 else
1365 fprintf (asmfile, "a");
1366 dbxout_range_type (tem);
1368 CHARS (14);
1369 dbxout_type (TREE_TYPE (type), 0, 0);
1370 break;
1372 case RECORD_TYPE:
1373 case UNION_TYPE:
1374 case QUAL_UNION_TYPE:
1376 int i, n_baseclasses = 0;
1378 if (TYPE_BINFO (type) != 0
1379 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1380 && TYPE_BINFO_BASETYPES (type) != 0)
1381 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1383 /* Output a structure type. We must use the same test here as we
1384 use in the DBX_NO_XREFS case above. */
1385 if ((TYPE_NAME (type) != 0
1386 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1387 && DECL_IGNORED_P (TYPE_NAME (type)))
1388 && !full)
1389 || !COMPLETE_TYPE_P (type)
1390 /* No way in DBX fmt to describe a variable size. */
1391 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1393 /* If the type is just a cross reference, output one
1394 and mark the type as partially described.
1395 If it later becomes defined, we will output
1396 its real definition.
1397 If the type has a name, don't nest its definition within
1398 another type's definition; instead, output an xref
1399 and let the definition come when the name is defined. */
1400 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1401 CHARS (3);
1402 #if 0 /* This assertion is legitimately false in C++. */
1403 /* We shouldn't be outputting a reference to a type before its
1404 definition unless the type has a tag name.
1405 A typedef name without a tag name should be impossible. */
1406 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1407 abort ();
1408 #endif
1409 if (TYPE_NAME (type) != 0)
1410 dbxout_type_name (type);
1411 else
1412 fprintf (asmfile, "$$%d", anonymous_type_number++);
1413 fprintf (asmfile, ":");
1414 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1415 break;
1418 /* Identify record or union, and print its size. */
1419 fputc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1420 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1421 int_size_in_bytes (type));
1423 if (use_gnu_debug_info_extensions)
1425 if (n_baseclasses)
1427 have_used_extensions = 1;
1428 fprintf (asmfile, "!%d,", n_baseclasses);
1429 CHARS (8);
1432 for (i = 0; i < n_baseclasses; i++)
1434 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1436 if (use_gnu_debug_info_extensions)
1438 have_used_extensions = 1;
1439 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1440 putc (TREE_VIA_PUBLIC (child) ? '2' : '0', asmfile);
1441 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1442 (tree_low_cst (BINFO_OFFSET (child), 0)
1443 * BITS_PER_UNIT));
1444 fputc (',', asmfile);
1445 CHARS (15);
1446 dbxout_type (BINFO_TYPE (child), 0, 0);
1447 putc (';', asmfile);
1449 else
1451 /* Print out the base class information with fields
1452 which have the same names at the types they hold. */
1453 dbxout_type_name (BINFO_TYPE (child));
1454 putc (':', asmfile);
1455 dbxout_type (BINFO_TYPE (child), full, 0);
1456 fputc (',', asmfile);
1457 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1458 tree_low_cst (BINFO_OFFSET (child), 0)
1459 * BITS_PER_UNIT);
1460 fputc (',', asmfile);
1461 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1462 (tree_low_cst (DECL_SIZE (TYPE_NAME
1463 (BINFO_TYPE (child))), 0)
1464 * BITS_PER_UNIT));
1465 fputc (';', asmfile);
1466 CHARS (20);
1471 CHARS (11);
1473 /* Write out the field declarations. */
1474 dbxout_type_fields (type);
1475 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1477 have_used_extensions = 1;
1478 dbxout_type_methods (type);
1481 putc (';', asmfile);
1483 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1484 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1485 && TYPE_VFIELD (type))
1487 have_used_extensions = 1;
1489 /* Tell GDB+ that it may keep reading. */
1490 putc ('~', asmfile);
1492 /* We need to write out info about what field this class
1493 uses as its "main" vtable pointer field, because if this
1494 field is inherited from a base class, GDB cannot necessarily
1495 figure out which field it's using in time. */
1496 if (TYPE_VFIELD (type))
1498 putc ('%', asmfile);
1499 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0, 0);
1501 putc (';', asmfile);
1502 CHARS (3);
1504 break;
1506 case ENUMERAL_TYPE:
1507 /* We must use the same test here as we use in the DBX_NO_XREFS case
1508 above. We simplify it a bit since an enum will never have a variable
1509 size. */
1510 if ((TYPE_NAME (type) != 0
1511 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1512 && DECL_IGNORED_P (TYPE_NAME (type)))
1513 && !full)
1514 || !COMPLETE_TYPE_P (type))
1516 fprintf (asmfile, "xe");
1517 CHARS (3);
1518 dbxout_type_name (type);
1519 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1520 fprintf (asmfile, ":");
1521 return;
1523 #ifdef DBX_OUTPUT_ENUM
1524 DBX_OUTPUT_ENUM (asmfile, type);
1525 #else
1526 if (use_gnu_debug_info_extensions
1527 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1528 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1529 putc ('e', asmfile);
1530 CHARS (1);
1531 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1533 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1534 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1535 fprintf (asmfile, HOST_WIDE_INT_PRINT_UNSIGNED,
1536 TREE_INT_CST_LOW (TREE_VALUE (tem)));
1537 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1538 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1539 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1540 TREE_INT_CST_LOW (TREE_VALUE (tem)));
1541 else
1542 print_int_cst_octal (TREE_VALUE (tem));
1543 fprintf (asmfile, ",");
1544 CHARS (20 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
1545 if (TREE_CHAIN (tem) != 0)
1547 CONTIN;
1550 putc (';', asmfile);
1551 CHARS (1);
1552 #endif
1553 break;
1555 case POINTER_TYPE:
1556 putc ('*', asmfile);
1557 CHARS (1);
1558 dbxout_type (TREE_TYPE (type), 0, 0);
1559 break;
1561 case METHOD_TYPE:
1562 if (use_gnu_debug_info_extensions)
1564 have_used_extensions = 1;
1565 putc ('#', asmfile);
1566 CHARS (1);
1567 if (flag_minimal_debug && !show_arg_types)
1569 /* Normally, just output the return type.
1570 The argument types are encoded in the method name. */
1571 putc ('#', asmfile);
1572 CHARS (1);
1573 dbxout_type (TREE_TYPE (type), 0, 0);
1574 putc (';', asmfile);
1575 CHARS (1);
1577 else
1579 /* When outputting destructors, we need to write
1580 the argument types out longhand. */
1581 dbxout_type (TYPE_METHOD_BASETYPE (type), 0, 0);
1582 putc (',', asmfile);
1583 CHARS (1);
1584 dbxout_type (TREE_TYPE (type), 0, 0);
1585 dbxout_args (TYPE_ARG_TYPES (type));
1586 putc (';', asmfile);
1587 CHARS (1);
1590 else
1592 /* Treat it as a function type. */
1593 dbxout_type (TREE_TYPE (type), 0, 0);
1595 break;
1597 case OFFSET_TYPE:
1598 if (use_gnu_debug_info_extensions)
1600 have_used_extensions = 1;
1601 putc ('@', asmfile);
1602 CHARS (1);
1603 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0, 0);
1604 putc (',', asmfile);
1605 CHARS (1);
1606 dbxout_type (TREE_TYPE (type), 0, 0);
1608 else
1610 /* Should print as an int, because it is really
1611 just an offset. */
1612 dbxout_type (integer_type_node, 0, 0);
1614 break;
1616 case REFERENCE_TYPE:
1617 if (use_gnu_debug_info_extensions)
1618 have_used_extensions = 1;
1619 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1620 CHARS (1);
1621 dbxout_type (TREE_TYPE (type), 0, 0);
1622 break;
1624 case FUNCTION_TYPE:
1625 putc ('f', asmfile);
1626 CHARS (1);
1627 dbxout_type (TREE_TYPE (type), 0, 0);
1628 break;
1630 default:
1631 abort ();
1635 /* Print the value of integer constant C, in octal,
1636 handling double precision. */
1638 static void
1639 print_int_cst_octal (c)
1640 tree c;
1642 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1643 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1644 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1645 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1647 /* GDB wants constants with no extra leading "1" bits, so
1648 we need to remove any sign-extension that might be
1649 present. */
1650 if (width == HOST_BITS_PER_WIDE_INT * 2)
1652 else if (width > HOST_BITS_PER_WIDE_INT)
1653 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1654 else if (width == HOST_BITS_PER_WIDE_INT)
1655 high = 0;
1656 else
1657 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1659 fprintf (asmfile, "0");
1661 if (excess == 3)
1663 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1664 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1666 else
1668 unsigned HOST_WIDE_INT beg = high >> excess;
1669 unsigned HOST_WIDE_INT middle
1670 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1671 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1672 unsigned HOST_WIDE_INT end
1673 = low & (((unsigned HOST_WIDE_INT) 1
1674 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1675 - 1);
1677 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1678 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1682 static void
1683 print_octal (value, digits)
1684 unsigned HOST_WIDE_INT value;
1685 int digits;
1687 int i;
1689 for (i = digits - 1; i >= 0; i--)
1690 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1693 /* Output the name of type TYPE, with no punctuation.
1694 Such names can be set up either by typedef declarations
1695 or by struct, enum and union tags. */
1697 static void
1698 dbxout_type_name (type)
1699 register tree type;
1701 tree t;
1702 if (TYPE_NAME (type) == 0)
1703 abort ();
1704 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1706 t = TYPE_NAME (type);
1708 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1710 t = DECL_NAME (TYPE_NAME (type));
1712 else
1713 abort ();
1715 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1716 CHARS (IDENTIFIER_LENGTH (t));
1719 /* Output a .stabs for the symbol defined by DECL,
1720 which must be a ..._DECL node in the normal namespace.
1721 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1722 LOCAL is nonzero if the scope is less than the entire file.
1723 Return 1 if a stabs might have been emitted. */
1726 dbxout_symbol (decl, local)
1727 tree decl;
1728 int local ATTRIBUTE_UNUSED;
1730 tree type = TREE_TYPE (decl);
1731 tree context = NULL_TREE;
1732 int result = 0;
1734 /* Cast avoids warning in old compilers. */
1735 current_sym_code = (STAB_CODE_TYPE) 0;
1736 current_sym_value = 0;
1737 current_sym_addr = 0;
1739 /* Ignore nameless syms, but don't ignore type tags. */
1741 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1742 || DECL_IGNORED_P (decl))
1743 return 0;
1745 dbxout_prepare_symbol (decl);
1747 /* The output will always start with the symbol name,
1748 so always count that in the length-output-so-far. */
1750 if (DECL_NAME (decl) != 0)
1751 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1753 switch (TREE_CODE (decl))
1755 case CONST_DECL:
1756 /* Enum values are defined by defining the enum type. */
1757 break;
1759 case FUNCTION_DECL:
1760 if (DECL_RTL (decl) == 0)
1761 return 0;
1762 if (DECL_EXTERNAL (decl))
1763 break;
1764 /* Don't mention a nested function under its parent. */
1765 context = decl_function_context (decl);
1766 if (context == current_function_decl)
1767 break;
1768 if (GET_CODE (DECL_RTL (decl)) != MEM
1769 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1770 break;
1771 FORCE_TEXT;
1773 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1774 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1775 TREE_PUBLIC (decl) ? 'F' : 'f');
1776 result = 1;
1778 current_sym_code = N_FUN;
1779 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1781 if (TREE_TYPE (type))
1782 dbxout_type (TREE_TYPE (type), 0, 0);
1783 else
1784 dbxout_type (void_type_node, 0, 0);
1786 /* For a nested function, when that function is compiled,
1787 mention the containing function name
1788 as well as (since dbx wants it) our own assembler-name. */
1789 if (context != 0)
1790 fprintf (asmfile, ",%s,%s",
1791 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1792 IDENTIFIER_POINTER (DECL_NAME (context)));
1794 dbxout_finish_symbol (decl);
1795 break;
1797 case TYPE_DECL:
1798 #if 0
1799 /* This seems all wrong. Outputting most kinds of types gives no name
1800 at all. A true definition gives no name; a cross-ref for a
1801 structure can give the tag name, but not a type name.
1802 It seems that no typedef name is defined by outputting a type. */
1804 /* If this typedef name was defined by outputting the type,
1805 don't duplicate it. */
1806 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
1807 && TYPE_NAME (TREE_TYPE (decl)) == decl)
1808 return 0;
1809 #endif
1810 /* Don't output the same typedef twice.
1811 And don't output what language-specific stuff doesn't want output. */
1812 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
1813 return 0;
1815 FORCE_TEXT;
1816 result = 1;
1818 int tag_needed = 1;
1819 int did_output = 0;
1821 if (DECL_NAME (decl))
1823 /* Nonzero means we must output a tag as well as a typedef. */
1824 tag_needed = 0;
1826 /* Handle the case of a C++ structure or union
1827 where the TYPE_NAME is a TYPE_DECL
1828 which gives both a typedef name and a tag. */
1829 /* dbx requires the tag first and the typedef second. */
1830 if ((TREE_CODE (type) == RECORD_TYPE
1831 || TREE_CODE (type) == UNION_TYPE
1832 || TREE_CODE (type) == QUAL_UNION_TYPE)
1833 && TYPE_NAME (type) == decl
1834 && !(use_gnu_debug_info_extensions && have_used_extensions)
1835 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
1836 /* Distinguish the implicit typedefs of C++
1837 from explicit ones that might be found in C. */
1838 && DECL_ARTIFICIAL (decl))
1840 tree name = TYPE_NAME (type);
1841 if (TREE_CODE (name) == TYPE_DECL)
1842 name = DECL_NAME (name);
1844 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1845 current_sym_value = 0;
1846 current_sym_addr = 0;
1847 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1849 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
1850 IDENTIFIER_POINTER (name));
1851 dbxout_type (type, 1, 0);
1852 dbxout_finish_symbol (NULL_TREE);
1855 /* Output typedef name. */
1856 fprintf (asmfile, "%s\"%s:", ASM_STABS_OP,
1857 IDENTIFIER_POINTER (DECL_NAME (decl)));
1859 /* Short cut way to output a tag also. */
1860 if ((TREE_CODE (type) == RECORD_TYPE
1861 || TREE_CODE (type) == UNION_TYPE
1862 || TREE_CODE (type) == QUAL_UNION_TYPE)
1863 && TYPE_NAME (type) == decl
1864 /* Distinguish the implicit typedefs of C++
1865 from explicit ones that might be found in C. */
1866 && DECL_ARTIFICIAL (decl))
1868 if (use_gnu_debug_info_extensions && have_used_extensions)
1870 putc ('T', asmfile);
1871 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1873 #if 0 /* Now we generate the tag for this case up above. */
1874 else
1875 tag_needed = 1;
1876 #endif
1879 putc ('t', asmfile);
1880 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1882 dbxout_type (type, 1, 0);
1883 dbxout_finish_symbol (decl);
1884 did_output = 1;
1887 /* Don't output a tag if this is an incomplete type (TYPE_SIZE is
1888 zero). This prevents the sun4 Sun OS 4.x dbx from crashing. */
1890 if (tag_needed && TYPE_NAME (type) != 0
1891 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
1892 || (DECL_NAME (TYPE_NAME (type)) != 0))
1893 && COMPLETE_TYPE_P (type)
1894 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
1896 /* For a TYPE_DECL with no name, but the type has a name,
1897 output a tag.
1898 This is what represents `struct foo' with no typedef. */
1899 /* In C++, the name of a type is the corresponding typedef.
1900 In C, it is an IDENTIFIER_NODE. */
1901 tree name = TYPE_NAME (type);
1902 if (TREE_CODE (name) == TYPE_DECL)
1903 name = DECL_NAME (name);
1905 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1906 current_sym_value = 0;
1907 current_sym_addr = 0;
1908 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1910 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
1911 IDENTIFIER_POINTER (name));
1912 dbxout_type (type, 1, 0);
1913 dbxout_finish_symbol (NULL_TREE);
1914 did_output = 1;
1917 /* If an enum type has no name, it cannot be referred to,
1918 but we must output it anyway, since the enumeration constants
1919 can be referred to. */
1920 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
1922 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1923 current_sym_value = 0;
1924 current_sym_addr = 0;
1925 current_sym_nchars = 2;
1927 /* Some debuggers fail when given NULL names, so give this a
1928 harmless name of ` '. */
1929 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
1930 dbxout_type (type, 1, 0);
1931 dbxout_finish_symbol (NULL_TREE);
1934 /* Prevent duplicate output of a typedef. */
1935 TREE_ASM_WRITTEN (decl) = 1;
1936 break;
1939 case PARM_DECL:
1940 /* Parm decls go in their own separate chains
1941 and are output by dbxout_reg_parms and dbxout_parms. */
1942 abort ();
1944 case RESULT_DECL:
1945 /* Named return value, treat like a VAR_DECL. */
1946 case VAR_DECL:
1947 if (DECL_RTL (decl) == 0)
1948 return 0;
1949 /* Don't mention a variable that is external.
1950 Let the file that defines it describe it. */
1951 if (DECL_EXTERNAL (decl))
1952 break;
1954 /* If the variable is really a constant
1955 and not written in memory, inform the debugger. */
1956 if (TREE_STATIC (decl) && TREE_READONLY (decl)
1957 && DECL_INITIAL (decl) != 0
1958 && host_integerp (DECL_INITIAL (decl), 0)
1959 && ! TREE_ASM_WRITTEN (decl)
1960 && (DECL_CONTEXT (decl) == NULL_TREE
1961 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
1963 if (TREE_PUBLIC (decl) == 0)
1965 /* The sun4 assembler does not grok this. */
1966 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1968 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
1969 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
1971 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
1972 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
1973 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
1974 #else
1975 fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
1977 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
1978 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
1979 #endif
1980 return 1;
1982 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
1984 /* don't know how to do this yet. */
1986 break;
1988 /* else it is something we handle like a normal variable. */
1991 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
1992 #ifdef LEAF_REG_REMAP
1993 if (current_function_uses_only_leaf_regs)
1994 leaf_renumber_regs_insn (DECL_RTL (decl));
1995 #endif
1997 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
1998 break;
2000 default:
2001 break;
2003 return result;
2006 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2007 Add SUFFIX to its name, if SUFFIX is not 0.
2008 Describe the variable as residing in HOME
2009 (usually HOME is DECL_RTL (DECL), but not always).
2010 Returns 1 if the stab was really emitted. */
2012 static int
2013 dbxout_symbol_location (decl, type, suffix, home)
2014 tree decl, type;
2015 const char *suffix;
2016 rtx home;
2018 int letter = 0;
2019 int regno = -1;
2021 /* Don't mention a variable at all
2022 if it was completely optimized into nothingness.
2024 If the decl was from an inline function, then its rtl
2025 is not identically the rtl that was used in this
2026 particular compilation. */
2027 if (GET_CODE (home) == REG)
2029 regno = REGNO (home);
2030 if (regno >= FIRST_PSEUDO_REGISTER)
2031 return 0;
2033 else if (GET_CODE (home) == SUBREG)
2035 rtx value = home;
2037 while (GET_CODE (value) == SUBREG)
2038 value = SUBREG_REG (value);
2039 if (GET_CODE (value) == REG)
2041 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2042 return 0;
2044 regno = REGNO (alter_subreg (home));
2047 /* The kind-of-variable letter depends on where
2048 the variable is and on the scope of its name:
2049 G and N_GSYM for static storage and global scope,
2050 S for static storage and file scope,
2051 V for static storage and local scope,
2052 for those two, use N_LCSYM if data is in bss segment,
2053 N_STSYM if in data segment, N_FUN otherwise.
2054 (We used N_FUN originally, then changed to N_STSYM
2055 to please GDB. However, it seems that confused ld.
2056 Now GDB has been fixed to like N_FUN, says Kingdon.)
2057 no letter at all, and N_LSYM, for auto variable,
2058 r and N_RSYM for register variable. */
2060 if (GET_CODE (home) == MEM
2061 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2063 if (TREE_PUBLIC (decl))
2065 letter = 'G';
2066 current_sym_code = N_GSYM;
2068 else
2070 current_sym_addr = XEXP (home, 0);
2072 letter = decl_function_context (decl) ? 'V' : 'S';
2074 /* This should be the same condition as in assemble_variable, but
2075 we don't have access to dont_output_data here. So, instead,
2076 we rely on the fact that error_mark_node initializers always
2077 end up in bss for C++ and never end up in bss for C. */
2078 if (DECL_INITIAL (decl) == 0
2079 || (!strcmp (lang_identify (), "cplusplus")
2080 && DECL_INITIAL (decl) == error_mark_node))
2081 current_sym_code = N_LCSYM;
2082 else if (DECL_IN_TEXT_SECTION (decl))
2083 /* This is not quite right, but it's the closest
2084 of all the codes that Unix defines. */
2085 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2086 else
2088 /* Ultrix `as' seems to need this. */
2089 #ifdef DBX_STATIC_STAB_DATA_SECTION
2090 data_section ();
2091 #endif
2092 current_sym_code = N_STSYM;
2096 else if (regno >= 0)
2098 letter = 'r';
2099 current_sym_code = N_RSYM;
2100 current_sym_value = DBX_REGISTER_NUMBER (regno);
2102 else if (GET_CODE (home) == MEM
2103 && (GET_CODE (XEXP (home, 0)) == MEM
2104 || (GET_CODE (XEXP (home, 0)) == REG
2105 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2106 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2107 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2108 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2109 #endif
2111 /* If the value is indirect by memory or by a register
2112 that isn't the frame pointer
2113 then it means the object is variable-sized and address through
2114 that register or stack slot. DBX has no way to represent this
2115 so all we can do is output the variable as a pointer.
2116 If it's not a parameter, ignore it.
2117 (VAR_DECLs like this can be made by integrate.c.) */
2119 if (GET_CODE (XEXP (home, 0)) == REG)
2121 letter = 'r';
2122 current_sym_code = N_RSYM;
2123 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2125 else
2127 current_sym_code = N_LSYM;
2128 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2129 We want the value of that CONST_INT. */
2130 current_sym_value
2131 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2134 /* Effectively do build_pointer_type, but don't cache this type,
2135 since it might be temporary whereas the type it points to
2136 might have been saved for inlining. */
2137 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2138 type = make_node (POINTER_TYPE);
2139 TREE_TYPE (type) = TREE_TYPE (decl);
2141 else if (GET_CODE (home) == MEM
2142 && GET_CODE (XEXP (home, 0)) == REG)
2144 current_sym_code = N_LSYM;
2145 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2147 else if (GET_CODE (home) == MEM
2148 && GET_CODE (XEXP (home, 0)) == PLUS
2149 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2151 current_sym_code = N_LSYM;
2152 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2153 We want the value of that CONST_INT. */
2154 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2156 else if (GET_CODE (home) == MEM
2157 && GET_CODE (XEXP (home, 0)) == CONST)
2159 /* Handle an obscure case which can arise when optimizing and
2160 when there are few available registers. (This is *always*
2161 the case for i386/i486 targets). The RTL looks like
2162 (MEM (CONST ...)) even though this variable is a local `auto'
2163 or a local `register' variable. In effect, what has happened
2164 is that the reload pass has seen that all assignments and
2165 references for one such a local variable can be replaced by
2166 equivalent assignments and references to some static storage
2167 variable, thereby avoiding the need for a register. In such
2168 cases we're forced to lie to debuggers and tell them that
2169 this variable was itself `static'. */
2170 current_sym_code = N_LCSYM;
2171 letter = 'V';
2172 current_sym_addr = XEXP (XEXP (home, 0), 0);
2174 else if (GET_CODE (home) == CONCAT)
2176 tree subtype = TREE_TYPE (type);
2178 /* If the variable's storage is in two parts,
2179 output each as a separate stab with a modified name. */
2180 if (WORDS_BIG_ENDIAN)
2181 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2182 else
2183 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2185 /* Cast avoids warning in old compilers. */
2186 current_sym_code = (STAB_CODE_TYPE) 0;
2187 current_sym_value = 0;
2188 current_sym_addr = 0;
2189 dbxout_prepare_symbol (decl);
2191 if (WORDS_BIG_ENDIAN)
2192 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2193 else
2194 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2195 return 1;
2197 else
2198 /* Address might be a MEM, when DECL is a variable-sized object.
2199 Or it might be const0_rtx, meaning previous passes
2200 want us to ignore this variable. */
2201 return 0;
2203 /* Ok, start a symtab entry and output the variable name. */
2204 FORCE_TEXT;
2206 #ifdef DBX_STATIC_BLOCK_START
2207 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2208 #endif
2210 dbxout_symbol_name (decl, suffix, letter);
2211 dbxout_type (type, 0, 0);
2212 dbxout_finish_symbol (decl);
2214 #ifdef DBX_STATIC_BLOCK_END
2215 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2216 #endif
2217 return 1;
2220 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2221 Then output LETTER to indicate the kind of location the symbol has. */
2223 static void
2224 dbxout_symbol_name (decl, suffix, letter)
2225 tree decl;
2226 const char *suffix;
2227 int letter;
2229 const char *name;
2231 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2232 /* One slight hitch: if this is a VAR_DECL which is a static
2233 class member, we must put out the mangled name instead of the
2234 DECL_NAME. Note also that static member (variable) names DO NOT begin
2235 with underscores in .stabs directives. */
2236 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2237 else
2238 /* ...but if we're function-local, we don't want to include the junk
2239 added by ASM_FORMAT_PRIVATE_NAME. */
2240 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2242 if (name == 0)
2243 name = "(anon)";
2244 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2245 (suffix ? suffix : ""));
2247 if (letter) putc (letter, asmfile);
2250 static void
2251 dbxout_prepare_symbol (decl)
2252 tree decl ATTRIBUTE_UNUSED;
2254 #ifdef WINNING_GDB
2255 const char *filename = DECL_SOURCE_FILE (decl);
2257 dbxout_source_file (asmfile, filename);
2258 #endif
2261 static void
2262 dbxout_finish_symbol (sym)
2263 tree sym;
2265 #ifdef DBX_FINISH_SYMBOL
2266 DBX_FINISH_SYMBOL (sym);
2267 #else
2268 int line = 0;
2269 if (use_gnu_debug_info_extensions && sym != 0)
2270 line = DECL_SOURCE_LINE (sym);
2272 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2273 if (current_sym_addr)
2274 output_addr_const (asmfile, current_sym_addr);
2275 else
2276 fprintf (asmfile, "%d", current_sym_value);
2277 putc ('\n', asmfile);
2278 #endif
2281 /* Output definitions of all the decls in a chain. Return non-zero if
2282 anything was output */
2285 dbxout_syms (syms)
2286 tree syms;
2288 int result = 0;
2289 while (syms)
2291 result += dbxout_symbol (syms, 1);
2292 syms = TREE_CHAIN (syms);
2294 return result;
2297 /* The following two functions output definitions of function parameters.
2298 Each parameter gets a definition locating it in the parameter list.
2299 Each parameter that is a register variable gets a second definition
2300 locating it in the register.
2302 Printing or argument lists in gdb uses the definitions that
2303 locate in the parameter list. But reference to the variable in
2304 expressions uses preferentially the definition as a register. */
2306 /* Output definitions, referring to storage in the parmlist,
2307 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2309 void
2310 dbxout_parms (parms)
2311 tree parms;
2313 for (; parms; parms = TREE_CHAIN (parms))
2314 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2316 dbxout_prepare_symbol (parms);
2318 /* Perform any necessary register eliminations on the parameter's rtl,
2319 so that the debugging output will be accurate. */
2320 DECL_INCOMING_RTL (parms)
2321 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2322 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2323 #ifdef LEAF_REG_REMAP
2324 if (current_function_uses_only_leaf_regs)
2326 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2327 leaf_renumber_regs_insn (DECL_RTL (parms));
2329 #endif
2331 if (PARM_PASSED_IN_MEMORY (parms))
2333 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2335 /* ??? Here we assume that the parm address is indexed
2336 off the frame pointer or arg pointer.
2337 If that is not true, we produce meaningless results,
2338 but do not crash. */
2339 if (GET_CODE (addr) == PLUS
2340 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2341 current_sym_value = INTVAL (XEXP (addr, 1));
2342 else
2343 current_sym_value = 0;
2345 current_sym_code = N_PSYM;
2346 current_sym_addr = 0;
2348 FORCE_TEXT;
2349 if (DECL_NAME (parms))
2351 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2353 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2354 IDENTIFIER_POINTER (DECL_NAME (parms)),
2355 DBX_MEMPARM_STABS_LETTER);
2357 else
2359 current_sym_nchars = 8;
2360 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2361 DBX_MEMPARM_STABS_LETTER);
2364 /* It is quite tempting to use:
2366 dbxout_type (TREE_TYPE (parms), 0, 0);
2368 as the next statement, rather than using DECL_ARG_TYPE(), so
2369 that gcc reports the actual type of the parameter, rather
2370 than the promoted type. This certainly makes GDB's life
2371 easier, at least for some ports. The change is a bad idea
2372 however, since GDB expects to be able access the type without
2373 performing any conversions. So for example, if we were
2374 passing a float to an unprototyped function, gcc will store a
2375 double on the stack, but if we emit a stab saying the type is a
2376 float, then gdb will only read in a single value, and this will
2377 produce an erropneous value. */
2378 dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
2379 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2380 dbxout_finish_symbol (parms);
2382 else if (GET_CODE (DECL_RTL (parms)) == REG)
2384 rtx best_rtl;
2385 char regparm_letter;
2386 tree parm_type;
2387 /* Parm passed in registers and lives in registers or nowhere. */
2389 current_sym_code = DBX_REGPARM_STABS_CODE;
2390 regparm_letter = DBX_REGPARM_STABS_LETTER;
2391 current_sym_addr = 0;
2393 /* If parm lives in a register, use that register;
2394 pretend the parm was passed there. It would be more consistent
2395 to describe the register where the parm was passed,
2396 but in practice that register usually holds something else.
2398 If we use DECL_RTL, then we must use the declared type of
2399 the variable, not the type that it arrived in. */
2400 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2402 best_rtl = DECL_RTL (parms);
2403 parm_type = TREE_TYPE (parms);
2405 /* If the parm lives nowhere, use the register where it was
2406 passed. It is also better to use the declared type here. */
2407 else
2409 best_rtl = DECL_INCOMING_RTL (parms);
2410 parm_type = TREE_TYPE (parms);
2412 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2414 FORCE_TEXT;
2415 if (DECL_NAME (parms))
2417 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2418 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2419 IDENTIFIER_POINTER (DECL_NAME (parms)),
2420 regparm_letter);
2422 else
2424 current_sym_nchars = 8;
2425 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2426 regparm_letter);
2429 dbxout_type (parm_type, 0, 0);
2430 dbxout_finish_symbol (parms);
2432 else if (GET_CODE (DECL_RTL (parms)) == MEM
2433 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2434 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2435 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2436 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2437 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2438 #endif
2441 /* Parm was passed via invisible reference.
2442 That is, its address was passed in a register.
2443 Output it as if it lived in that register.
2444 The debugger will know from the type
2445 that it was actually passed by invisible reference. */
2447 char regparm_letter;
2448 /* Parm passed in registers and lives in registers or nowhere. */
2450 current_sym_code = DBX_REGPARM_STABS_CODE;
2451 if (use_gnu_debug_info_extensions)
2452 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2453 else
2454 regparm_letter = DBX_REGPARM_STABS_LETTER;
2456 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2457 If it is an unallocated pseudo-reg, then use the register where
2458 it was passed instead. */
2459 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2460 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2461 else
2462 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2464 current_sym_addr = 0;
2466 FORCE_TEXT;
2467 if (DECL_NAME (parms))
2469 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2471 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2472 IDENTIFIER_POINTER (DECL_NAME (parms)),
2473 regparm_letter);
2475 else
2477 current_sym_nchars = 8;
2478 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2479 regparm_letter);
2482 dbxout_type (TREE_TYPE (parms), 0, 0);
2483 dbxout_finish_symbol (parms);
2485 else if (GET_CODE (DECL_RTL (parms)) == MEM
2486 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2488 /* Parm was passed via invisible reference, with the reference
2489 living on the stack. DECL_RTL looks like
2490 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2491 could look like (MEM (MEM (REG))). */
2492 const char *decl_name = (DECL_NAME (parms)
2493 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2494 : "(anon)");
2495 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2496 current_sym_value = 0;
2497 else
2498 current_sym_value
2499 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2500 current_sym_addr = 0;
2502 FORCE_TEXT;
2503 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2504 dbxout_type (TREE_TYPE (parms), 0, 0);
2505 dbxout_finish_symbol (parms);
2507 else if (GET_CODE (DECL_RTL (parms)) == MEM
2508 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2509 /* ??? A constant address for a parm can happen
2510 when the reg it lives in is equiv to a constant in memory.
2511 Should make this not happen, after 2.4. */
2512 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2514 /* Parm was passed in registers but lives on the stack. */
2516 current_sym_code = N_PSYM;
2517 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2518 in which case we want the value of that CONST_INT,
2519 or (MEM (REG ...)),
2520 in which case we use a value of zero. */
2521 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2522 current_sym_value = 0;
2523 else
2524 current_sym_value
2525 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2527 current_sym_addr = 0;
2529 /* Make a big endian correction if the mode of the type of the
2530 parameter is not the same as the mode of the rtl. */
2531 if (BYTES_BIG_ENDIAN
2532 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2533 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2535 current_sym_value +=
2536 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2537 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2540 FORCE_TEXT;
2541 if (DECL_NAME (parms))
2543 current_sym_nchars
2544 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2546 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2547 IDENTIFIER_POINTER (DECL_NAME (parms)),
2548 DBX_MEMPARM_STABS_LETTER);
2550 else
2552 current_sym_nchars = 8;
2553 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2554 DBX_MEMPARM_STABS_LETTER);
2557 current_sym_value
2558 = DEBUGGER_ARG_OFFSET (current_sym_value,
2559 XEXP (DECL_RTL (parms), 0));
2560 dbxout_type (TREE_TYPE (parms), 0, 0);
2561 dbxout_finish_symbol (parms);
2566 /* Output definitions for the places where parms live during the function,
2567 when different from where they were passed, when the parms were passed
2568 in memory.
2570 It is not useful to do this for parms passed in registers
2571 that live during the function in different registers, because it is
2572 impossible to look in the passed register for the passed value,
2573 so we use the within-the-function register to begin with.
2575 PARMS is a chain of PARM_DECL nodes. */
2577 void
2578 dbxout_reg_parms (parms)
2579 tree parms;
2581 for (; parms; parms = TREE_CHAIN (parms))
2582 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2584 dbxout_prepare_symbol (parms);
2586 /* Report parms that live in registers during the function
2587 but were passed in memory. */
2588 if (GET_CODE (DECL_RTL (parms)) == REG
2589 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2590 dbxout_symbol_location (parms, TREE_TYPE (parms),
2591 0, DECL_RTL (parms));
2592 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2593 dbxout_symbol_location (parms, TREE_TYPE (parms),
2594 0, DECL_RTL (parms));
2595 /* Report parms that live in memory but not where they were passed. */
2596 else if (GET_CODE (DECL_RTL (parms)) == MEM
2597 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2598 dbxout_symbol_location (parms, TREE_TYPE (parms),
2599 0, DECL_RTL (parms));
2603 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2604 output definitions of those names, in raw form */
2606 void
2607 dbxout_args (args)
2608 tree args;
2610 while (args)
2612 putc (',', asmfile);
2613 dbxout_type (TREE_VALUE (args), 0, 0);
2614 CHARS (1);
2615 args = TREE_CHAIN (args);
2619 /* Given a chain of ..._TYPE nodes,
2620 find those which have typedef names and output those names.
2621 This is to ensure those types get output. */
2623 void
2624 dbxout_types (types)
2625 register tree types;
2627 while (types)
2629 if (TYPE_NAME (types)
2630 && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
2631 && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
2632 dbxout_symbol (TYPE_NAME (types), 1);
2633 types = TREE_CHAIN (types);
2637 /* Output everything about a symbol block (a BLOCK node
2638 that represents a scope level),
2639 including recursive output of contained blocks.
2641 BLOCK is the BLOCK node.
2642 DEPTH is its depth within containing symbol blocks.
2643 ARGS is usually zero; but for the outermost block of the
2644 body of a function, it is a chain of PARM_DECLs for the function parameters.
2645 We output definitions of all the register parms
2646 as if they were local variables of that block.
2648 If -g1 was used, we count blocks just the same, but output nothing
2649 except for the outermost block.
2651 Actually, BLOCK may be several blocks chained together.
2652 We handle them all in sequence. */
2654 static void
2655 dbxout_block (block, depth, args)
2656 register tree block;
2657 int depth;
2658 tree args;
2660 int blocknum = -1;
2662 #if DBX_BLOCKS_FUNCTION_RELATIVE
2663 const char *begin_label;
2664 if (current_function_func_begin_label != NULL_TREE)
2665 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2666 else
2667 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2668 #endif
2670 while (block)
2672 /* Ignore blocks never expanded or otherwise marked as real. */
2673 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2675 int did_output;
2677 #ifdef DBX_LBRAC_FIRST
2678 did_output = 1;
2679 #else
2680 /* In dbx format, the syms of a block come before the N_LBRAC.
2681 If nothing is output, we don't need the N_LBRAC, either. */
2682 did_output = 0;
2683 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2684 did_output = dbxout_syms (BLOCK_VARS (block));
2685 if (args)
2686 dbxout_reg_parms (args);
2687 #endif
2689 /* Now output an N_LBRAC symbol to represent the beginning of
2690 the block. Use the block's tree-walk order to generate
2691 the assembler symbols LBBn and LBEn
2692 that final will define around the code in this block. */
2693 if (depth > 0 && did_output)
2695 char buf[20];
2696 blocknum = BLOCK_NUMBER (block);
2697 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2699 if (BLOCK_HANDLER_BLOCK (block))
2701 /* A catch block. Must precede N_LBRAC. */
2702 tree decl = BLOCK_VARS (block);
2703 while (decl)
2705 #ifdef DBX_OUTPUT_CATCH
2706 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2707 #else
2708 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2709 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2710 assemble_name (asmfile, buf);
2711 fprintf (asmfile, "\n");
2712 #endif
2713 decl = TREE_CHAIN (decl);
2717 #ifdef DBX_OUTPUT_LBRAC
2718 DBX_OUTPUT_LBRAC (asmfile, buf);
2719 #else
2720 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2721 assemble_name (asmfile, buf);
2722 #if DBX_BLOCKS_FUNCTION_RELATIVE
2723 fputc ('-', asmfile);
2724 assemble_name (asmfile, begin_label);
2725 #endif
2726 fprintf (asmfile, "\n");
2727 #endif
2730 #ifdef DBX_LBRAC_FIRST
2731 /* On some weird machines, the syms of a block
2732 come after the N_LBRAC. */
2733 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2734 dbxout_syms (BLOCK_VARS (block));
2735 if (args)
2736 dbxout_reg_parms (args);
2737 #endif
2739 /* Output the subblocks. */
2740 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2742 /* Refer to the marker for the end of the block. */
2743 if (depth > 0 && did_output)
2745 char buf[20];
2746 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2747 #ifdef DBX_OUTPUT_RBRAC
2748 DBX_OUTPUT_RBRAC (asmfile, buf);
2749 #else
2750 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2751 assemble_name (asmfile, buf);
2752 #if DBX_BLOCKS_FUNCTION_RELATIVE
2753 fputc ('-', asmfile);
2754 assemble_name (asmfile, begin_label);
2755 #endif
2756 fprintf (asmfile, "\n");
2757 #endif
2760 block = BLOCK_CHAIN (block);
2764 /* Output the information about a function and its arguments and result.
2765 Usually this follows the function's code,
2766 but on some systems, it comes before. */
2768 static void
2769 dbxout_really_begin_function (decl)
2770 tree decl;
2772 dbxout_symbol (decl, 0);
2773 dbxout_parms (DECL_ARGUMENTS (decl));
2774 if (DECL_NAME (DECL_RESULT (decl)) != 0)
2775 dbxout_symbol (DECL_RESULT (decl), 1);
2778 /* Called at beginning of output of function definition. */
2780 void
2781 dbxout_begin_function (decl)
2782 tree decl ATTRIBUTE_UNUSED;
2784 #ifdef DBX_FUNCTION_FIRST
2785 dbxout_really_begin_function (decl);
2786 #endif
2789 /* Output dbx data for a function definition.
2790 This includes a definition of the function name itself (a symbol),
2791 definitions of the parameters (locating them in the parameter list)
2792 and then output the block that makes up the function's body
2793 (including all the auto variables of the function). */
2795 void
2796 dbxout_function (decl)
2797 tree decl;
2799 #ifndef DBX_FUNCTION_FIRST
2800 dbxout_really_begin_function (decl);
2801 #endif
2802 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
2803 #ifdef DBX_OUTPUT_FUNCTION_END
2804 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
2805 #endif
2806 #if defined(ASM_OUTPUT_SECTION_NAME)
2807 if (use_gnu_debug_info_extensions
2808 #if defined(NO_DBX_FUNCTION_END)
2809 && ! NO_DBX_FUNCTION_END
2810 #endif
2812 dbxout_function_end ();
2813 #endif
2815 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */