1 /* Output dbx-format symbol table information from GNU compiler.
2 Copyright (C) 1987, 88, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* $FreeBSD: src/contrib/gcc/dbxout.c,v 1.4.2.1 2003/05/07 16:47:53 obrien Exp $ */
24 /* Output dbx-format symbol table data.
25 This consists of many symbol table entries, each of them
26 a .stabs assembler pseudo-op with four operands:
27 a "name" which is really a description of one symbol and its type,
28 a "code", which is a symbol defined in stab.h whose name starts with N_,
29 an unused operand always 0,
30 and a "value" which is an address or an offset.
31 The name is enclosed in doublequote characters.
33 Each function, variable, typedef, and structure tag
34 has a symbol table entry to define it.
35 The beginning and end of each level of name scoping within
36 a function are also marked by special symbol table entries.
38 The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
39 and a data type number. The data type number may be followed by
40 "=" and a type definition; normally this will happen the first time
41 the type number is mentioned. The type definition may refer to
42 other types by number, and those type numbers may be followed
43 by "=" and nested definitions.
45 This can make the "name" quite long.
46 When a name is more than 80 characters, we split the .stabs pseudo-op
47 into two .stabs pseudo-ops, both sharing the same "code" and "value".
48 The first one is marked as continued with a double-backslash at the
51 The kind-of-symbol letter distinguished function names from global
52 variables from file-scope variables from parameters from auto
53 variables in memory from typedef names from register variables.
56 The "code" is mostly redundant with the kind-of-symbol letter
57 that goes in the "name", but not entirely: for symbols located
58 in static storage, the "code" says which segment the address is in,
59 which controls how it is relocated.
61 The "value" for a symbol in static storage
62 is the core address of the symbol (actually, the assembler
63 label for the symbol). For a symbol located in a stack slot
64 it is the stack offset; for one in a register, the register number.
65 For a typedef symbol, it is zero.
67 If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
68 output while in the text section.
70 For more on data type definitions, see `dbxout_type'. */
79 #include "insn-config.h"
82 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions. */
86 #ifdef XCOFF_DEBUGGING_INFO
91 #define ASM_STABS_OP ".stabs"
95 #define ASM_STABN_OP ".stabn"
98 #ifndef DBX_TYPE_DECL_STABS_CODE
99 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
102 #ifndef DBX_STATIC_CONST_VAR_CODE
103 #define DBX_STATIC_CONST_VAR_CODE N_FUN
106 #ifndef DBX_REGPARM_STABS_CODE
107 #define DBX_REGPARM_STABS_CODE N_RSYM
110 #ifndef DBX_REGPARM_STABS_LETTER
111 #define DBX_REGPARM_STABS_LETTER 'P'
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'
119 #ifndef DBX_MEMPARM_STABS_LETTER
120 #define DBX_MEMPARM_STABS_LETTER 'p'
123 #ifndef FILE_NAME_JOINER
124 #define FILE_NAME_JOINER "/"
127 /* Nonzero means if the type has methods, only output debugging
128 information if methods are actually written to the asm file. This
129 optimization only works if the debugger can detect the special C++
132 #define MINIMAL_DEBUG 1
134 #ifdef NO_DOLLAR_IN_LABEL
135 #ifdef NO_DOT_IN_LABEL
137 #define MINIMAL_DEBUG 0
143 /* Typical USG systems don't have stab.h, and they also have
144 no use for DBX-format debugging info. */
146 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
148 static int flag_minimal_debug = MINIMAL_DEBUG;
150 /* Nonzero if we have actually used any of the GDB extensions
151 to the debugging format. The idea is that we use them for the
152 first time only if there's a strong reason, but once we have done that,
153 we use them whenever convenient. */
155 static int have_used_extensions = 0;
157 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
158 for the N_SO filename stabs label. */
160 static int source_label_number = 1;
162 #ifdef DEBUG_SYMS_TEXT
163 #define FORCE_TEXT text_section ();
168 /* If there is a system stab.h, use it. Otherwise, use our own. */
169 /* ??? This is supposed to describe the target's stab format, so using
170 the host HAVE_STAB_H appears to be wrong. For now, we use our own file
171 when cross compiling. */
172 #if defined (USG) || !defined (HAVE_STAB_H) || defined (CROSS_COMPILE)
173 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
177 /* This is a GNU extension we need to reference in this file. */
184 #define STAB_CODE_TYPE enum __stab_debug_code
186 #define STAB_CODE_TYPE int
189 /* 1 if PARM is passed to this function in memory. */
191 #define PARM_PASSED_IN_MEMORY(PARM) \
192 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
194 /* A C expression for the integer offset value of an automatic variable
195 (N_LSYM) having address X (an RTX). */
196 #ifndef DEBUGGER_AUTO_OFFSET
197 #define DEBUGGER_AUTO_OFFSET(X) \
198 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
201 /* A C expression for the integer offset value of an argument (N_PSYM)
202 having address X (an RTX). The nominal offset is OFFSET. */
203 #ifndef DEBUGGER_ARG_OFFSET
204 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
207 /* Stream for writing to assembler file. */
209 static FILE *asmfile;
211 /* Last source file name mentioned in a NOTE insn. */
213 static char *lastfile;
215 /* Current working directory. */
219 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
221 /* Structure recording information about a C data type.
222 The status element says whether we have yet output
223 the definition of the type. TYPE_XREF says we have
224 output it as a cross-reference only.
225 The file_number and type_number elements are used if DBX_USE_BINCL
230 enum typestatus status;
237 /* Vector recording information about C data types.
238 When we first notice a data type (a tree node),
239 we assign it a number using next_type_number.
240 That is its index in this vector. */
242 struct typeinfo *typevec;
244 /* Number of elements of space allocated in `typevec'. */
246 static int typevec_len;
248 /* In dbx output, each type gets a unique number.
249 This is the number for the next type output.
250 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
252 static int next_type_number;
256 /* When using N_BINCL in dbx output, each type number is actually a
257 pair of the file number and the type number within the file.
258 This is a stack of input files. */
262 struct dbx_file *next;
264 int next_type_number;
267 /* This is the top of the stack. */
269 static struct dbx_file *current_file;
271 /* This is the next file number to use. */
273 static int next_file_number;
275 #endif /* DBX_USE_BINCL */
277 /* In dbx output, we must assign symbol-blocks id numbers
278 in the order in which their beginnings are encountered.
279 We output debugging info that refers to the beginning and
280 end of the ranges of code in each block
281 with assembler labels LBBn and LBEn, where n is the block number.
282 The labels are generated in final, which assigns numbers to the
283 blocks in the same way. */
285 static int next_block_number;
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
317 #if DBX_CONTIN_LENGTH > 0
319 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
324 void dbxout_types ();
326 void dbxout_symbol ();
328 #if defined(ASM_OUTPUT_SECTION_NAME)
329 static void dbxout_function_end PROTO((void));
331 static void dbxout_typedefs PROTO((tree));
332 static void dbxout_type_index PROTO((tree));
333 #if DBX_CONTIN_LENGTH > 0
334 static void dbxout_continue PROTO((void));
336 static void dbxout_type_fields PROTO((tree));
337 static void dbxout_type_method_1 PROTO((tree, char *));
338 static void dbxout_type_methods PROTO((tree));
339 static void dbxout_range_type PROTO((tree));
340 static void dbxout_type PROTO((tree, int, int));
341 static void print_int_cst_octal PROTO((tree));
342 static void print_octal PROTO((unsigned HOST_WIDE_INT, int));
343 static void dbxout_type_name PROTO((tree));
344 static void dbxout_symbol_location PROTO((tree, tree, char *, rtx));
345 static void dbxout_symbol_name PROTO((tree, char *, int));
346 static void dbxout_prepare_symbol PROTO((tree));
347 static void dbxout_finish_symbol PROTO((tree));
348 static void dbxout_block PROTO((tree, int, tree));
349 static void dbxout_really_begin_function PROTO((tree));
351 #if defined(ASM_OUTPUT_SECTION_NAME)
353 dbxout_function_end ()
355 static int scope_labelno = 0;
356 char lscope_label_name[100];
357 /* Convert Ltext into the appropriate format for local labels in case
358 the system doesn't insert underscores in front of user generated
360 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
361 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Lscope", scope_labelno);
364 /* By convention, GCC will mark the end of a function with an N_FUN
365 symbol and an empty string. */
366 fprintf (asmfile, "%s \"\",%d,0,0,", ASM_STABS_OP, N_FUN);
367 assemble_name (asmfile, lscope_label_name);
368 fputc ('-', asmfile);
369 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
370 fprintf (asmfile, "\n");
372 #endif /* ! NO_DBX_FUNCTION_END */
374 /* At the beginning of compilation, start writing the symbol table.
375 Initialize `typevec' and output the standard data types of C. */
378 dbxout_init (asm_file, input_file_name, syms)
380 char *input_file_name;
383 char ltext_label_name[100];
388 typevec = (struct typeinfo *) xmalloc (typevec_len * sizeof typevec[0]);
389 bzero ((char *) typevec, typevec_len * sizeof typevec[0]);
391 /* Convert Ltext into the appropriate format for local labels in case
392 the system doesn't insert underscores in front of user generated
394 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
396 /* Put the current working directory in an N_SO symbol. */
397 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
398 but GDB always does. */
399 if (use_gnu_debug_info_extensions)
402 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
404 char *wdslash = xmalloc (strlen (cwd) + sizeof (FILE_NAME_JOINER));
405 sprintf (wdslash, "%s%s", cwd, FILE_NAME_JOINER);
410 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
411 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
412 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
413 fprintf (asmfile, "%s ", ASM_STABS_OP);
414 output_quoted_string (asmfile, cwd);
415 fprintf (asmfile, ",%d,0,0,%s\n", N_SO, <ext_label_name[1]);
416 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
420 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
421 /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
422 would give us an N_SOL, and we want an N_SO. */
423 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
424 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
425 /* We include outputting `Ltext:' here,
426 because that gives you a way to override it. */
427 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
428 fprintf (asmfile, "%s ", ASM_STABS_OP);
429 output_quoted_string (asmfile, input_file_name);
430 fprintf (asmfile, ",%d,0,0,%s\n",
431 N_SO, <ext_label_name[1]);
433 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0);
434 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
436 /* Possibly output something to inform GDB that this compilation was by
437 GCC. It's easier for GDB to parse it when after the N_SO's. This
438 is used in Solaris 2. */
439 #ifdef ASM_IDENTIFY_GCC_AFTER_SOURCE
440 ASM_IDENTIFY_GCC_AFTER_SOURCE (asmfile);
443 lastfile = input_file_name;
445 next_type_number = 1;
446 next_block_number = 2;
449 current_file = (struct dbx_file *) xmalloc (sizeof *current_file);
450 current_file->next = NULL;
451 current_file->file_number = 0;
452 current_file->next_type_number = 1;
453 next_file_number = 1;
456 /* Make sure that types `int' and `char' have numbers 1 and 2.
457 Definitions of other integer types will refer to those numbers.
458 (Actually it should no longer matter what their numbers are.
459 Also, if any types with tags have been defined, dbxout_symbol
460 will output them first, so the numbers won't be 1 and 2. That
461 happens in C++. So it's a good thing it should no longer matter). */
463 #ifdef DBX_OUTPUT_STANDARD_TYPES
464 DBX_OUTPUT_STANDARD_TYPES (syms);
466 dbxout_symbol (TYPE_NAME (integer_type_node), 0);
467 dbxout_symbol (TYPE_NAME (char_type_node), 0);
470 /* Get all permanent types that have typedef names,
471 and output them all, except for those already output. */
473 dbxout_typedefs (syms);
476 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
477 in the reverse order from that which is found in SYMS. */
480 dbxout_typedefs (syms)
485 dbxout_typedefs (TREE_CHAIN (syms));
486 if (TREE_CODE (syms) == TYPE_DECL)
488 tree type = TREE_TYPE (syms);
490 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
491 && TYPE_SIZE (type) != NULL_TREE
492 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
493 dbxout_symbol (TYPE_NAME (type), 0);
498 /* Change to reading from a new source file. Generate a N_BINCL stab. */
501 dbxout_start_new_source_file (filename)
502 char *filename ATTRIBUTE_UNUSED;
505 struct dbx_file *n = (struct dbx_file *) xmalloc (sizeof *n);
507 n->next = current_file;
508 n->file_number = next_file_number++;
509 n->next_type_number = 1;
511 fprintf (asmfile, "%s ", ASM_STABS_OP);
512 output_quoted_string (asmfile, filename);
513 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
517 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
520 dbxout_resume_previous_source_file ()
523 struct dbx_file *next;
525 fprintf (asmfile, "%s %d,0,0,0\n", ASM_STABN_OP, N_EINCL);
526 next = current_file->next;
532 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
535 dbxout_source_file (file, filename)
539 char ltext_label_name[100];
541 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
543 #ifdef DBX_OUTPUT_SOURCE_FILENAME
544 DBX_OUTPUT_SOURCE_FILENAME (file, filename);
546 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
547 source_label_number);
548 fprintf (file, "%s ", ASM_STABS_OP);
549 output_quoted_string (file, filename);
550 fprintf (file, ",%d,0,0,%s\n", N_SOL, <ext_label_name[1]);
551 if (current_function_decl != NULL_TREE
552 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
553 ; /* Don't change section amid function. */
556 ASM_OUTPUT_INTERNAL_LABEL (file, "Ltext", source_label_number);
557 source_label_number++;
563 /* Output a line number symbol entry into output stream FILE,
564 for source file FILENAME and line number LINENO. */
567 dbxout_source_line (file, filename, lineno)
572 dbxout_source_file (file, filename);
574 #ifdef ASM_OUTPUT_SOURCE_LINE
575 ASM_OUTPUT_SOURCE_LINE (file, lineno);
577 fprintf (file, "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
581 /* At the end of compilation, finish writing the symbol table.
582 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
586 dbxout_finish (file, filename)
587 FILE *file ATTRIBUTE_UNUSED;
588 char *filename ATTRIBUTE_UNUSED;
590 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
591 DBX_OUTPUT_MAIN_SOURCE_FILE_END (file, filename);
592 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
595 /* Output the index of a type. */
598 dbxout_type_index (type)
601 #ifndef DBX_USE_BINCL
602 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
605 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
606 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
611 #if DBX_CONTIN_LENGTH > 0
612 /* Continue a symbol-description that gets too big.
613 End one symbol table entry with a double-backslash
614 and start a new one, eventually producing something like
615 .stabs "start......\\",code,0,value
616 .stabs "...rest",code,0,value */
621 #ifdef DBX_CONTIN_CHAR
622 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
624 fprintf (asmfile, "\\\\");
626 dbxout_finish_symbol (NULL_TREE);
627 fprintf (asmfile, "%s \"", ASM_STABS_OP);
628 current_sym_nchars = 0;
630 #endif /* DBX_CONTIN_LENGTH > 0 */
632 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
633 This must be a separate function because anonymous unions require
637 dbxout_type_fields (type)
641 /* Output the name, type, position (in bits), size (in bits) of each
643 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
645 /* Omit here local type decls until we know how to support them. */
646 if (TREE_CODE (tem) == TYPE_DECL)
648 /* Omit fields whose position or size are variable. */
649 else if (TREE_CODE (tem) == FIELD_DECL
650 && (TREE_CODE (DECL_FIELD_BITPOS (tem)) != INTEGER_CST
651 || TREE_CODE (DECL_SIZE (tem)) != INTEGER_CST))
653 /* Omit here the nameless fields that are used to skip bits. */
654 else if (DECL_IGNORED_P (tem))
656 else if (TREE_CODE (tem) != CONST_DECL)
658 /* Continue the line if necessary,
659 but not before the first field. */
660 if (tem != TYPE_FIELDS (type))
665 if (use_gnu_debug_info_extensions
666 && flag_minimal_debug
667 && TREE_CODE (tem) == FIELD_DECL
668 && DECL_VIRTUAL_P (tem)
669 && DECL_ASSEMBLER_NAME (tem))
671 have_used_extensions = 1;
672 CHARS (3 + IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (tem)));
673 fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem)), asmfile);
674 dbxout_type (DECL_FCONTEXT (tem), 0, 0);
675 fprintf (asmfile, ":");
676 dbxout_type (TREE_TYPE (tem), 0, 0);
677 fputc (',', asmfile);
678 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
679 TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
680 fputc (';', asmfile);
686 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
687 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
691 fprintf (asmfile, ":");
695 if (use_gnu_debug_info_extensions
696 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
697 || TREE_CODE (tem) != FIELD_DECL))
699 have_used_extensions = 1;
701 putc ((TREE_PRIVATE (tem) ? '0'
702 : TREE_PROTECTED (tem) ? '1' : '2'),
707 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
708 && DECL_BIT_FIELD_TYPE (tem))
709 ? DECL_BIT_FIELD_TYPE (tem)
710 : TREE_TYPE (tem), 0, 0);
712 if (TREE_CODE (tem) == VAR_DECL)
714 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
716 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
717 have_used_extensions = 1;
718 fprintf (asmfile, ":%s;", name);
719 CHARS (strlen (name));
723 /* If TEM is non-static, GDB won't understand it. */
724 fprintf (asmfile, ",0,0;");
727 else if (TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
729 fputc (',', asmfile);
730 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
731 TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
732 fputc (',', asmfile);
733 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
734 TREE_INT_CST_LOW (DECL_SIZE (tem)));
735 fputc (';', asmfile);
742 /* Subroutine of `dbxout_type_methods'. Output debug info about the
743 method described DECL. DEBUG_NAME is an encoding of the method's
744 type signature. ??? We may be able to do without DEBUG_NAME altogether
748 dbxout_type_method_1 (decl, debug_name)
754 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
756 else /* it's a METHOD_TYPE. */
758 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
759 /* A for normal functions.
760 B for `const' member functions.
761 C for `volatile' member functions.
762 D for `const volatile' member functions. */
763 if (TYPE_READONLY (TREE_TYPE (firstarg)))
765 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
768 if (DECL_VINDEX (decl))
774 fprintf (asmfile, ":%s;%c%c%c", debug_name,
775 TREE_PRIVATE (decl) ? '0' : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
776 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
777 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
778 if (DECL_VINDEX (decl))
780 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
781 TREE_INT_CST_LOW (DECL_VINDEX (decl)));
782 fputc (';', asmfile);
783 dbxout_type (DECL_CONTEXT (decl), 0, 0);
784 fprintf (asmfile, ";");
789 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
793 dbxout_type_methods (type)
796 /* C++: put out the method names and their parameter lists */
797 tree methods = TYPE_METHODS (type);
799 register tree fndecl;
801 char formatted_type_identifier_length[16];
802 register int type_identifier_length;
804 if (methods == NULL_TREE)
807 type_encoding = DECL_NAME (TYPE_NAME (type));
810 /* C++: Template classes break some assumptions made by this code about
811 the class names, constructor names, and encodings for assembler
812 label names. For now, disable output of dbx info for them. */
814 char *ptr = IDENTIFIER_POINTER (type_encoding);
815 /* This should use index. (mrs) */
816 while (*ptr && *ptr != '<') ptr++;
827 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
829 sprintf(formatted_type_identifier_length, "%d", type_identifier_length);
831 if (TREE_CODE (methods) != TREE_VEC)
833 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
834 fndecl = TREE_VEC_ELT (methods, 0);
836 fndecl = TREE_VEC_ELT (methods, 1);
840 tree name = DECL_NAME (fndecl);
843 /* Group together all the methods for the same operation.
844 These differ in the types of the arguments. */
845 for (last = NULL_TREE;
846 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
847 fndecl = TREE_CHAIN (fndecl))
848 /* Output the name of the field (after overloading), as
849 well as the name of the field before overloading, along
850 with its parameter list */
852 /* This is the "mangled" name of the method.
853 It encodes the argument types. */
854 char *debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
855 int show_arg_types = 0;
861 if (DECL_IGNORED_P (fndecl))
864 if (flag_minimal_debug)
868 /* We can't optimize a method which uses an anonymous
869 class, because the debugger will not be able to
870 associate the arbitrary class name with the actual
872 #ifndef NO_DOLLAR_IN_LABEL
877 if (strchr (debug_name, marker))
879 /* Detect ordinary methods because their mangled names
880 start with the operation name. */
881 else if (!strncmp (IDENTIFIER_POINTER (name), debug_name,
882 IDENTIFIER_LENGTH (name)))
884 debug_name += IDENTIFIER_LENGTH (name);
885 if (debug_name[0] == '_' && debug_name[1] == '_')
887 char *method_name = debug_name + 2;
888 char *length_ptr = formatted_type_identifier_length;
889 /* Get past const and volatile qualifiers. */
890 while (*method_name == 'C' || *method_name == 'V')
892 /* Skip digits for length of type_encoding. */
893 while (*method_name == *length_ptr && *length_ptr)
894 length_ptr++, method_name++;
895 if (! strncmp (method_name,
896 IDENTIFIER_POINTER (type_encoding),
897 type_identifier_length))
898 method_name += type_identifier_length;
899 debug_name = method_name;
902 /* Detect constructors by their style of name mangling. */
903 else if (debug_name[0] == '_' && debug_name[1] == '_')
905 char *ctor_name = debug_name + 2;
906 char *length_ptr = formatted_type_identifier_length;
907 while (*ctor_name == 'C' || *ctor_name == 'V')
909 /* Skip digits for length of type_encoding. */
910 while (*ctor_name == *length_ptr && *length_ptr)
911 length_ptr++, ctor_name++;
912 if (!strncmp (IDENTIFIER_POINTER (type_encoding), ctor_name,
913 type_identifier_length))
914 debug_name = ctor_name + type_identifier_length;
916 /* The other alternative is a destructor. */
920 /* Output the operation name just once, for the first method
924 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
925 CHARS (IDENTIFIER_LENGTH (name) + 2);
930 dbxout_type (TREE_TYPE (fndecl), 0, show_arg_types);
932 dbxout_type_method_1 (fndecl, debug_name);
942 /* Emit a "range" type specification, which has the form:
943 "r<index type>;<lower bound>;<upper bound>;".
944 TYPE is an INTEGER_TYPE. */
947 dbxout_range_type (type)
950 fprintf (asmfile, "r");
951 if (TREE_TYPE (type))
952 dbxout_type (TREE_TYPE (type), 0, 0);
953 else if (TREE_CODE (type) != INTEGER_TYPE)
954 dbxout_type (type, 0, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
957 /* Traditionally, we made sure 'int' was type 1, and builtin types
958 were defined to be sub-ranges of int. Unfortunately, this
959 does not allow us to distinguish true sub-ranges from integer
960 types. So, instead we define integer (non-sub-range) types as
961 sub-ranges of themselves. This matters for Chill. If this isn't
962 a subrange type, then we want to define it in terms of itself.
963 However, in C, this may be an anonymous integer type, and we don't
964 want to emit debug info referring to it. Just calling
965 dbxout_type_index won't work anyways, because the type hasn't been
966 defined yet. We make this work for both cases by checked to see
967 whether this is a defined type, referring to it if it is, and using
969 if (TYPE_SYMTAB_ADDRESS (type) != 0)
970 dbxout_type_index (type);
972 dbxout_type_index (integer_type_node);
974 if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
976 fputc (';', asmfile);
977 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
978 TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)));
981 fprintf (asmfile, ";0");
982 if (TYPE_MAX_VALUE (type)
983 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
985 fputc (';', asmfile);
986 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
987 TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
988 fputc (';', asmfile);
991 fprintf (asmfile, ";-1;");
994 /* Output a reference to a type. If the type has not yet been
995 described in the dbx output, output its definition now.
996 For a type already defined, just refer to its definition
997 using the type number.
999 If FULL is nonzero, and the type has been described only with
1000 a forward-reference, output the definition now.
1001 If FULL is zero in this case, just refer to the forward-reference
1002 using the number previously allocated.
1004 If SHOW_ARG_TYPES is nonzero, we output a description of the argument
1005 types for a METHOD_TYPE. */
1008 dbxout_type (type, full, show_arg_types)
1014 static int anonymous_type_number = 0;
1016 /* If there was an input error and we don't really have a type,
1017 avoid crashing and write something that is at least valid
1018 by assuming `int'. */
1019 if (type == error_mark_node)
1020 type = integer_type_node;
1023 /* Try to find the "main variant" with the same name but not const
1024 or volatile. (Since stabs does not distinguish const and volatile,
1025 there is no need to make them separate types. But types with
1026 different names are usefully distinguished.) */
1028 for (tem = TYPE_MAIN_VARIANT (type); tem; tem = TYPE_NEXT_VARIANT (tem))
1029 if (!TYPE_READONLY (tem) && !TYPE_VOLATILE (tem)
1030 && TYPE_NAME (tem) == TYPE_NAME (type))
1035 if (TYPE_NAME (type)
1036 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1037 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1041 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1043 /* Type has no dbx number assigned. Assign next available number. */
1044 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1046 /* Make sure type vector is long enough to record about this type. */
1048 if (next_type_number == typevec_len)
1051 = (struct typeinfo *) xrealloc (typevec,
1052 typevec_len * 2 * sizeof typevec[0]);
1053 bzero ((char *) (typevec + typevec_len),
1054 typevec_len * sizeof typevec[0]);
1058 #ifdef DBX_USE_BINCL
1059 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1060 = current_file->file_number;
1061 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1062 = current_file->next_type_number++;
1066 /* Output the number of this type, to refer to it. */
1067 dbxout_type_index (type);
1069 #ifdef DBX_TYPE_DEFINED
1070 if (DBX_TYPE_DEFINED (type))
1074 /* If this type's definition has been output or is now being output,
1077 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1082 /* If we have already had a cross reference,
1083 and either that's all we want or that's the best we could do,
1084 don't repeat the cross reference.
1085 Sun dbx crashes if we do. */
1086 if (! full || TYPE_SIZE (type) == 0
1087 /* No way in DBX fmt to describe a variable size. */
1088 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1096 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1097 leave the type-number completely undefined rather than output
1098 a cross-reference. If we have already used GNU debug info extensions,
1099 then it is OK to output a cross reference. This is necessary to get
1100 proper C++ debug output. */
1101 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1102 || TREE_CODE (type) == QUAL_UNION_TYPE
1103 || TREE_CODE (type) == ENUMERAL_TYPE)
1104 && ! use_gnu_debug_info_extensions)
1105 /* We must use the same test here as we use twice below when deciding
1106 whether to emit a cross-reference. */
1107 if ((TYPE_NAME (type) != 0
1108 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1109 && DECL_IGNORED_P (TYPE_NAME (type)))
1111 || TYPE_SIZE (type) == 0
1112 /* No way in DBX fmt to describe a variable size. */
1113 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1115 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1120 /* Output a definition now. */
1122 fprintf (asmfile, "=");
1125 /* Mark it as defined, so that if it is self-referent
1126 we will not get into an infinite recursion of definitions. */
1128 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1130 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1131 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1133 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0, 0);
1137 switch (TREE_CODE (type))
1141 /* For a void type, just define it as itself; ie, "5=5".
1142 This makes us consider it defined
1143 without saying what it is. The debugger will make it
1144 a void type when the reference is seen, and nothing will
1145 ever override that default. */
1146 dbxout_type_index (type);
1150 if (type == char_type_node && ! TREE_UNSIGNED (type))
1152 /* Output the type `char' as a subrange of itself!
1153 I don't understand this definition, just copied it
1154 from the output of pcc.
1155 This used to use `r2' explicitly and we used to
1156 take care to make sure that `char' was type number 2. */
1157 fprintf (asmfile, "r");
1158 dbxout_type_index (type);
1159 fprintf (asmfile, ";0;127;");
1161 /* This used to check if the type's precision was more than
1162 HOST_BITS_PER_WIDE_INT. That is wrong since gdb uses a
1163 long (it has no concept of HOST_BITS_PER_WIDE_INT). */
1164 else if (use_gnu_debug_info_extensions
1165 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1166 || TYPE_PRECISION (type) >= HOST_BITS_PER_LONG))
1168 /* This used to say `r1' and we used to take care
1169 to make sure that `int' was type number 1. */
1170 fprintf (asmfile, "r");
1171 dbxout_type_index (integer_type_node);
1172 fprintf (asmfile, ";");
1173 print_int_cst_octal (TYPE_MIN_VALUE (type));
1174 fprintf (asmfile, ";");
1175 print_int_cst_octal (TYPE_MAX_VALUE (type));
1176 fprintf (asmfile, ";");
1178 else /* Output other integer types as subranges of `int'. */
1179 dbxout_range_type (type);
1184 /* This used to say `r1' and we used to take care
1185 to make sure that `int' was type number 1. */
1186 fprintf (asmfile, "r");
1187 dbxout_type_index (integer_type_node);
1188 fputc (';', asmfile);
1189 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, int_size_in_bytes (type));
1190 fputs (";0;", asmfile);
1195 if (use_gnu_debug_info_extensions)
1197 fputs ("@s", asmfile);
1198 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1199 BITS_PER_UNIT * int_size_in_bytes (type));
1200 fputs (";-20;", asmfile);
1204 /* Output the type `char' as a subrange of itself.
1205 That is what pcc seems to do. */
1206 fprintf (asmfile, "r");
1207 dbxout_type_index (char_type_node);
1208 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1214 if (use_gnu_debug_info_extensions)
1216 fputs ("@s", asmfile);
1217 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1218 BITS_PER_UNIT * int_size_in_bytes (type));
1219 fputs (";-16;", asmfile);
1221 else /* Define as enumeral type (False, True) */
1222 fprintf (asmfile, "eFalse:0,True:1,;");
1227 putc ('d', asmfile);
1229 dbxout_type (TREE_TYPE (type), 0, 0);
1233 /* Differs from the REAL_TYPE by its new data type number */
1235 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1237 fprintf (asmfile, "r");
1238 dbxout_type_index (type);
1239 fputc (';', asmfile);
1240 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1241 int_size_in_bytes (TREE_TYPE (type)));
1242 fputs (";0;", asmfile);
1243 CHARS (12); /* The number is probably incorrect here. */
1247 /* Output a complex integer type as a structure,
1248 pending some other way to do it. */
1249 fputc ('s', asmfile);
1250 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, int_size_in_bytes (type));
1252 fprintf (asmfile, "real:");
1254 dbxout_type (TREE_TYPE (type), 0, 0);
1255 fprintf (asmfile, ",%d,%d;",
1256 0, TYPE_PRECISION (TREE_TYPE (type)));
1258 fprintf (asmfile, "imag:");
1260 dbxout_type (TREE_TYPE (type), 0, 0);
1261 fprintf (asmfile, ",%d,%d;;",
1262 TYPE_PRECISION (TREE_TYPE (type)),
1263 TYPE_PRECISION (TREE_TYPE (type)));
1269 if (use_gnu_debug_info_extensions)
1271 have_used_extensions = 1;
1272 fputs ("@s", asmfile);
1273 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1274 BITS_PER_UNIT * int_size_in_bytes (type));
1275 fputc (';', asmfile);
1276 /* Check if a bitstring type, which in Chill is
1277 different from a [power]set. */
1278 if (TYPE_STRING_FLAG (type))
1279 fprintf (asmfile, "@S;");
1281 putc ('S', asmfile);
1283 dbxout_type (TYPE_DOMAIN (type), 0, 0);
1287 /* Make arrays of packed bits look like bitstrings for chill. */
1288 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1290 have_used_extensions = 1;
1291 fputs ("@s", asmfile);
1292 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1293 BITS_PER_UNIT * int_size_in_bytes (type));
1294 fputc (';', asmfile);
1295 fprintf (asmfile, "@S;");
1296 putc ('S', asmfile);
1298 dbxout_type (TYPE_DOMAIN (type), 0, 0);
1301 /* Output "a" followed by a range type definition
1302 for the index type of the array
1303 followed by a reference to the target-type.
1304 ar1;0;N;M for a C array of type M and size N+1. */
1305 /* Check if a character string type, which in Chill is
1306 different from an array of characters. */
1307 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1309 have_used_extensions = 1;
1310 fprintf (asmfile, "@S;");
1312 tem = TYPE_DOMAIN (type);
1315 fprintf (asmfile, "ar");
1316 dbxout_type_index (integer_type_node);
1317 fprintf (asmfile, ";0;-1;");
1321 fprintf (asmfile, "a");
1322 dbxout_range_type (tem);
1325 dbxout_type (TREE_TYPE (type), 0, 0);
1330 case QUAL_UNION_TYPE:
1332 int i, n_baseclasses = 0;
1334 if (TYPE_BINFO (type) != 0
1335 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1336 && TYPE_BINFO_BASETYPES (type) != 0)
1337 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1339 /* Output a structure type. We must use the same test here as we
1340 use in the DBX_NO_XREFS case above. */
1341 if ((TYPE_NAME (type) != 0
1342 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1343 && DECL_IGNORED_P (TYPE_NAME (type)))
1345 || TYPE_SIZE (type) == 0
1346 /* No way in DBX fmt to describe a variable size. */
1347 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1349 /* If the type is just a cross reference, output one
1350 and mark the type as partially described.
1351 If it later becomes defined, we will output
1352 its real definition.
1353 If the type has a name, don't nest its definition within
1354 another type's definition; instead, output an xref
1355 and let the definition come when the name is defined. */
1356 fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
1358 #if 0 /* This assertion is legitimately false in C++. */
1359 /* We shouldn't be outputting a reference to a type before its
1360 definition unless the type has a tag name.
1361 A typedef name without a tag name should be impossible. */
1362 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1365 if (TYPE_NAME (type) != 0)
1366 dbxout_type_name (type);
1368 fprintf (asmfile, "$$%d", anonymous_type_number++);
1369 fprintf (asmfile, ":");
1370 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1374 /* Identify record or union, and print its size. */
1375 fputc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1376 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1377 int_size_in_bytes (type));
1379 if (use_gnu_debug_info_extensions)
1383 have_used_extensions = 1;
1384 fprintf (asmfile, "!%d,", n_baseclasses);
1388 for (i = 0; i < n_baseclasses; i++)
1390 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1391 if (use_gnu_debug_info_extensions)
1393 have_used_extensions = 1;
1394 putc (TREE_VIA_VIRTUAL (child) ? '1'
1397 putc (TREE_VIA_PUBLIC (child) ? '2'
1400 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1401 TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT);
1402 fputc (',', asmfile);
1404 dbxout_type (BINFO_TYPE (child), 0, 0);
1405 putc (';', asmfile);
1409 /* Print out the base class information with fields
1410 which have the same names at the types they hold. */
1411 dbxout_type_name (BINFO_TYPE (child));
1412 putc (':', asmfile);
1413 dbxout_type (BINFO_TYPE (child), full, 0);
1414 fputc (',', asmfile);
1415 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1416 TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT);
1417 fputc (',', asmfile);
1418 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1419 TREE_INT_CST_LOW (DECL_SIZE (TYPE_NAME (BINFO_TYPE (child)))) * BITS_PER_UNIT);
1420 fputc (';', asmfile);
1428 /* Write out the field declarations. */
1429 dbxout_type_fields (type);
1430 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1432 have_used_extensions = 1;
1433 dbxout_type_methods (type);
1435 putc (';', asmfile);
1437 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1438 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1439 && TYPE_VFIELD (type))
1441 have_used_extensions = 1;
1443 /* Tell GDB+ that it may keep reading. */
1444 putc ('~', asmfile);
1446 /* We need to write out info about what field this class
1447 uses as its "main" vtable pointer field, because if this
1448 field is inherited from a base class, GDB cannot necessarily
1449 figure out which field it's using in time. */
1450 if (TYPE_VFIELD (type))
1452 putc ('%', asmfile);
1453 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0, 0);
1455 putc (';', asmfile);
1461 /* We must use the same test here as we use in the DBX_NO_XREFS case
1462 above. We simplify it a bit since an enum will never have a variable
1464 if ((TYPE_NAME (type) != 0
1465 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1466 && DECL_IGNORED_P (TYPE_NAME (type)))
1468 || TYPE_SIZE (type) == 0)
1470 fprintf (asmfile, "xe");
1472 dbxout_type_name (type);
1473 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1474 fprintf (asmfile, ":");
1477 #ifdef DBX_OUTPUT_ENUM
1478 DBX_OUTPUT_ENUM (asmfile, type);
1480 if (use_gnu_debug_info_extensions
1481 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1482 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1483 putc ('e', asmfile);
1485 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1487 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1488 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1489 fprintf (asmfile, HOST_WIDE_INT_PRINT_UNSIGNED,
1490 TREE_INT_CST_LOW (TREE_VALUE (tem)));
1491 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1492 && TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1493 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1494 TREE_INT_CST_LOW (TREE_VALUE (tem)));
1496 print_int_cst_octal (TREE_VALUE (tem));
1497 fprintf (asmfile, ",");
1498 CHARS (20 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
1499 if (TREE_CHAIN (tem) != 0)
1504 putc (';', asmfile);
1510 putc ('*', asmfile);
1512 dbxout_type (TREE_TYPE (type), 0, 0);
1516 if (use_gnu_debug_info_extensions)
1518 have_used_extensions = 1;
1519 putc ('#', asmfile);
1521 if (flag_minimal_debug && !show_arg_types)
1523 /* Normally, just output the return type.
1524 The argument types are encoded in the method name. */
1525 putc ('#', asmfile);
1527 dbxout_type (TREE_TYPE (type), 0, 0);
1528 putc (';', asmfile);
1533 /* When outputting destructors, we need to write
1534 the argument types out longhand. */
1535 dbxout_type (TYPE_METHOD_BASETYPE (type), 0, 0);
1536 putc (',', asmfile);
1538 dbxout_type (TREE_TYPE (type), 0, 0);
1539 dbxout_args (TYPE_ARG_TYPES (type));
1540 putc (';', asmfile);
1546 /* Treat it as a function type. */
1547 dbxout_type (TREE_TYPE (type), 0, 0);
1552 if (use_gnu_debug_info_extensions)
1554 have_used_extensions = 1;
1555 putc ('@', asmfile);
1557 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0, 0);
1558 putc (',', asmfile);
1560 dbxout_type (TREE_TYPE (type), 0, 0);
1564 /* Should print as an int, because it is really
1566 dbxout_type (integer_type_node, 0, 0);
1570 case REFERENCE_TYPE:
1571 if (use_gnu_debug_info_extensions)
1572 have_used_extensions = 1;
1573 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1575 dbxout_type (TREE_TYPE (type), 0, 0);
1579 putc ('f', asmfile);
1581 dbxout_type (TREE_TYPE (type), 0, 0);
1589 /* Print the value of integer constant C, in octal,
1590 handling double precision. */
1593 print_int_cst_octal (c)
1596 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1597 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1598 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1599 int width = TYPE_PRECISION (TREE_TYPE (c));
1601 /* GDB wants constants with no extra leading "1" bits, so
1602 we need to remove any sign-extension that might be
1604 if (width == HOST_BITS_PER_WIDE_INT * 2)
1606 else if (width > HOST_BITS_PER_WIDE_INT)
1607 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1608 else if (width == HOST_BITS_PER_WIDE_INT)
1611 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1613 fprintf (asmfile, "0");
1617 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1618 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1622 unsigned HOST_WIDE_INT beg = high >> excess;
1623 unsigned HOST_WIDE_INT middle
1624 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1625 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1626 unsigned HOST_WIDE_INT end
1627 = low & (((unsigned HOST_WIDE_INT) 1
1628 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1631 fprintf (asmfile, "%o%01o", (int)beg, (int)middle);
1632 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1637 print_octal (value, digits)
1638 unsigned HOST_WIDE_INT value;
1643 for (i = digits - 1; i >= 0; i--)
1644 fprintf (asmfile, "%01o", (int)((value >> (3 * i)) & 7));
1647 /* Output the name of type TYPE, with no punctuation.
1648 Such names can be set up either by typedef declarations
1649 or by struct, enum and union tags. */
1652 dbxout_type_name (type)
1656 if (TYPE_NAME (type) == 0)
1658 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1660 t = TYPE_NAME (type);
1662 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1664 t = DECL_NAME (TYPE_NAME (type));
1669 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1670 CHARS (IDENTIFIER_LENGTH (t));
1673 /* Output a .stabs for the symbol defined by DECL,
1674 which must be a ..._DECL node in the normal namespace.
1675 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1676 LOCAL is nonzero if the scope is less than the entire file. */
1679 dbxout_symbol (decl, local)
1683 tree type = TREE_TYPE (decl);
1684 tree context = NULL_TREE;
1686 /* Cast avoids warning in old compilers. */
1687 current_sym_code = (STAB_CODE_TYPE) 0;
1688 current_sym_value = 0;
1689 current_sym_addr = 0;
1691 /* Ignore nameless syms, but don't ignore type tags. */
1693 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1694 || DECL_IGNORED_P (decl))
1697 dbxout_prepare_symbol (decl);
1699 /* The output will always start with the symbol name,
1700 so always count that in the length-output-so-far. */
1702 if (DECL_NAME (decl) != 0)
1703 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1705 switch (TREE_CODE (decl))
1708 /* Enum values are defined by defining the enum type. */
1712 if (DECL_RTL (decl) == 0)
1714 if (DECL_EXTERNAL (decl))
1716 /* Don't mention a nested function under its parent. */
1717 context = decl_function_context (decl);
1718 if (context == current_function_decl)
1720 if (GET_CODE (DECL_RTL (decl)) != MEM
1721 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1725 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1726 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1727 TREE_PUBLIC (decl) ? 'F' : 'f');
1729 current_sym_code = N_FUN;
1730 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1732 if (TREE_TYPE (type))
1733 dbxout_type (TREE_TYPE (type), 0, 0);
1735 dbxout_type (void_type_node, 0, 0);
1737 /* For a nested function, when that function is compiled,
1738 mention the containing function name
1739 as well as (since dbx wants it) our own assembler-name. */
1741 fprintf (asmfile, ",%s,%s",
1742 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1743 IDENTIFIER_POINTER (DECL_NAME (context)));
1745 dbxout_finish_symbol (decl);
1750 /* This seems all wrong. Outputting most kinds of types gives no name
1751 at all. A true definition gives no name; a cross-ref for a
1752 structure can give the tag name, but not a type name.
1753 It seems that no typedef name is defined by outputting a type. */
1755 /* If this typedef name was defined by outputting the type,
1756 don't duplicate it. */
1757 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
1758 && TYPE_NAME (TREE_TYPE (decl)) == decl)
1761 /* Don't output the same typedef twice.
1762 And don't output what language-specific stuff doesn't want output. */
1763 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
1772 if (DECL_NAME (decl))
1774 /* Nonzero means we must output a tag as well as a typedef. */
1777 /* Handle the case of a C++ structure or union
1778 where the TYPE_NAME is a TYPE_DECL
1779 which gives both a typedef name and a tag. */
1780 /* dbx requires the tag first and the typedef second. */
1781 if ((TREE_CODE (type) == RECORD_TYPE
1782 || TREE_CODE (type) == UNION_TYPE
1783 || TREE_CODE (type) == QUAL_UNION_TYPE)
1784 && TYPE_NAME (type) == decl
1785 && !(use_gnu_debug_info_extensions && have_used_extensions)
1786 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
1787 /* Distinguish the implicit typedefs of C++
1788 from explicit ones that might be found in C. */
1789 && DECL_ARTIFICIAL (decl))
1791 tree name = TYPE_NAME (type);
1792 if (TREE_CODE (name) == TYPE_DECL)
1793 name = DECL_NAME (name);
1795 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1796 current_sym_value = 0;
1797 current_sym_addr = 0;
1798 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1800 fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP,
1801 IDENTIFIER_POINTER (name));
1802 dbxout_type (type, 1, 0);
1803 dbxout_finish_symbol (NULL_TREE);
1806 /* Output typedef name. */
1807 fprintf (asmfile, "%s \"%s:", ASM_STABS_OP,
1808 IDENTIFIER_POINTER (DECL_NAME (decl)));
1810 /* Short cut way to output a tag also. */
1811 if ((TREE_CODE (type) == RECORD_TYPE
1812 || TREE_CODE (type) == UNION_TYPE
1813 || TREE_CODE (type) == QUAL_UNION_TYPE)
1814 && TYPE_NAME (type) == decl
1815 /* Distinguish the implicit typedefs of C++
1816 from explicit ones that might be found in C. */
1817 && DECL_ARTIFICIAL (decl))
1819 if (use_gnu_debug_info_extensions && have_used_extensions)
1821 putc ('T', asmfile);
1822 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1824 #if 0 /* Now we generate the tag for this case up above. */
1830 putc ('t', asmfile);
1831 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1833 dbxout_type (type, 1, 0);
1834 dbxout_finish_symbol (decl);
1838 /* Don't output a tag if this is an incomplete type (TYPE_SIZE is
1839 zero). This prevents the sun4 Sun OS 4.x dbx from crashing. */
1841 if (tag_needed && TYPE_NAME (type) != 0
1842 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
1843 || (DECL_NAME (TYPE_NAME (type)) != 0))
1844 && TYPE_SIZE (type) != 0
1845 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
1847 /* For a TYPE_DECL with no name, but the type has a name,
1849 This is what represents `struct foo' with no typedef. */
1850 /* In C++, the name of a type is the corresponding typedef.
1851 In C, it is an IDENTIFIER_NODE. */
1852 tree name = TYPE_NAME (type);
1853 if (TREE_CODE (name) == TYPE_DECL)
1854 name = DECL_NAME (name);
1856 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1857 current_sym_value = 0;
1858 current_sym_addr = 0;
1859 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1861 fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP,
1862 IDENTIFIER_POINTER (name));
1863 dbxout_type (type, 1, 0);
1864 dbxout_finish_symbol (NULL_TREE);
1868 /* If an enum type has no name, it cannot be referred to,
1869 but we must output it anyway, since the enumeration constants
1870 can be referred to. */
1871 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
1873 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1874 current_sym_value = 0;
1875 current_sym_addr = 0;
1876 current_sym_nchars = 2;
1878 /* Some debuggers fail when given NULL names, so give this a
1879 harmless name of ` '. */
1880 fprintf (asmfile, "%s \" :T", ASM_STABS_OP);
1881 dbxout_type (type, 1, 0);
1882 dbxout_finish_symbol (NULL_TREE);
1885 /* Prevent duplicate output of a typedef. */
1886 TREE_ASM_WRITTEN (decl) = 1;
1891 /* Parm decls go in their own separate chains
1892 and are output by dbxout_reg_parms and dbxout_parms. */
1896 /* Named return value, treat like a VAR_DECL. */
1898 if (DECL_RTL (decl) == 0)
1900 /* Don't mention a variable that is external.
1901 Let the file that defines it describe it. */
1902 if (DECL_EXTERNAL (decl))
1905 /* If the variable is really a constant
1906 and not written in memory, inform the debugger. */
1907 if (TREE_STATIC (decl) && TREE_READONLY (decl)
1908 && DECL_INITIAL (decl) != 0
1909 && ! TREE_ASM_WRITTEN (decl)
1910 && (DECL_FIELD_CONTEXT (decl) == NULL_TREE
1911 || TREE_CODE (DECL_FIELD_CONTEXT (decl)) == BLOCK))
1913 if (TREE_PUBLIC (decl) == 0)
1915 /* The sun4 assembler does not grok this. */
1916 char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1917 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
1918 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
1920 HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
1921 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
1922 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
1924 fprintf (asmfile, "%s \"%s:c=i", ASM_STABS_OP, name);
1926 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
1927 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
1931 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
1933 /* don't know how to do this yet. */
1937 /* else it is something we handle like a normal variable. */
1940 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
1941 #ifdef LEAF_REG_REMAP
1942 if (current_function_uses_only_leaf_regs)
1943 leaf_renumber_regs_insn (DECL_RTL (decl));
1946 dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
1954 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
1955 Add SUFFIX to its name, if SUFFIX is not 0.
1956 Describe the variable as residing in HOME
1957 (usually HOME is DECL_RTL (DECL), but not always). */
1960 dbxout_symbol_location (decl, type, suffix, home)
1968 /* Don't mention a variable at all
1969 if it was completely optimized into nothingness.
1971 If the decl was from an inline function, then its rtl
1972 is not identically the rtl that was used in this
1973 particular compilation. */
1974 if (GET_CODE (home) == REG)
1976 regno = REGNO (home);
1977 if (regno >= FIRST_PSEUDO_REGISTER)
1980 else if (GET_CODE (home) == SUBREG)
1984 while (GET_CODE (value) == SUBREG)
1986 offset += SUBREG_WORD (value);
1987 value = SUBREG_REG (value);
1989 if (GET_CODE (value) == REG)
1991 regno = REGNO (value);
1992 if (regno >= FIRST_PSEUDO_REGISTER)
1996 alter_subreg (home);
1999 /* The kind-of-variable letter depends on where
2000 the variable is and on the scope of its name:
2001 G and N_GSYM for static storage and global scope,
2002 S for static storage and file scope,
2003 V for static storage and local scope,
2004 for those two, use N_LCSYM if data is in bss segment,
2005 N_STSYM if in data segment, N_FUN otherwise.
2006 (We used N_FUN originally, then changed to N_STSYM
2007 to please GDB. However, it seems that confused ld.
2008 Now GDB has been fixed to like N_FUN, says Kingdon.)
2009 no letter at all, and N_LSYM, for auto variable,
2010 r and N_RSYM for register variable. */
2012 if (GET_CODE (home) == MEM
2013 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2015 if (TREE_PUBLIC (decl))
2018 current_sym_code = N_GSYM;
2022 current_sym_addr = XEXP (home, 0);
2024 letter = decl_function_context (decl) ? 'V' : 'S';
2026 /* This should be the same condition as in assemble_variable, but
2027 we don't have access to dont_output_data here. So, instead,
2028 we rely on the fact that error_mark_node initializers always
2029 end up in bss for C++ and never end up in bss for C. */
2030 if (DECL_INITIAL (decl) == 0
2031 || (!strcmp (lang_identify (), "cplusplus")
2032 && DECL_INITIAL (decl) == error_mark_node))
2033 current_sym_code = N_LCSYM;
2034 else if (DECL_IN_TEXT_SECTION (decl))
2035 /* This is not quite right, but it's the closest
2036 of all the codes that Unix defines. */
2037 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2040 /* Ultrix `as' seems to need this. */
2041 #ifdef DBX_STATIC_STAB_DATA_SECTION
2044 current_sym_code = N_STSYM;
2048 else if (regno >= 0)
2051 current_sym_code = N_RSYM;
2052 current_sym_value = DBX_REGISTER_NUMBER (regno);
2054 else if (GET_CODE (home) == MEM
2055 && (GET_CODE (XEXP (home, 0)) == MEM
2056 || (GET_CODE (XEXP (home, 0)) == REG
2057 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2058 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2059 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2060 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2063 /* If the value is indirect by memory or by a register
2064 that isn't the frame pointer
2065 then it means the object is variable-sized and address through
2066 that register or stack slot. DBX has no way to represent this
2067 so all we can do is output the variable as a pointer.
2068 If it's not a parameter, ignore it.
2069 (VAR_DECLs like this can be made by integrate.c.) */
2071 if (GET_CODE (XEXP (home, 0)) == REG)
2074 current_sym_code = N_RSYM;
2075 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2079 current_sym_code = N_LSYM;
2080 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2081 We want the value of that CONST_INT. */
2083 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2086 /* Effectively do build_pointer_type, but don't cache this type,
2087 since it might be temporary whereas the type it points to
2088 might have been saved for inlining. */
2089 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2090 type = make_node (POINTER_TYPE);
2091 TREE_TYPE (type) = TREE_TYPE (decl);
2093 else if (GET_CODE (home) == MEM
2094 && GET_CODE (XEXP (home, 0)) == REG)
2096 current_sym_code = N_LSYM;
2097 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2099 else if (GET_CODE (home) == MEM
2100 && GET_CODE (XEXP (home, 0)) == PLUS
2101 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2103 current_sym_code = N_LSYM;
2104 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2105 We want the value of that CONST_INT. */
2106 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2108 else if (GET_CODE (home) == MEM
2109 && GET_CODE (XEXP (home, 0)) == CONST)
2111 /* Handle an obscure case which can arise when optimizing and
2112 when there are few available registers. (This is *always*
2113 the case for i386/i486 targets). The RTL looks like
2114 (MEM (CONST ...)) even though this variable is a local `auto'
2115 or a local `register' variable. In effect, what has happened
2116 is that the reload pass has seen that all assignments and
2117 references for one such a local variable can be replaced by
2118 equivalent assignments and references to some static storage
2119 variable, thereby avoiding the need for a register. In such
2120 cases we're forced to lie to debuggers and tell them that
2121 this variable was itself `static'. */
2122 current_sym_code = N_LCSYM;
2124 current_sym_addr = XEXP (XEXP (home, 0), 0);
2126 else if (GET_CODE (home) == CONCAT)
2128 tree subtype = TREE_TYPE (type);
2130 /* If the variable's storage is in two parts,
2131 output each as a separate stab with a modified name. */
2132 if (WORDS_BIG_ENDIAN)
2133 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2135 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2137 /* Cast avoids warning in old compilers. */
2138 current_sym_code = (STAB_CODE_TYPE) 0;
2139 current_sym_value = 0;
2140 current_sym_addr = 0;
2141 dbxout_prepare_symbol (decl);
2143 if (WORDS_BIG_ENDIAN)
2144 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2146 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2150 /* Address might be a MEM, when DECL is a variable-sized object.
2151 Or it might be const0_rtx, meaning previous passes
2152 want us to ignore this variable. */
2155 /* Ok, start a symtab entry and output the variable name. */
2158 #ifdef DBX_STATIC_BLOCK_START
2159 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2162 dbxout_symbol_name (decl, suffix, letter);
2163 dbxout_type (type, 0, 0);
2164 dbxout_finish_symbol (decl);
2166 #ifdef DBX_STATIC_BLOCK_END
2167 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2171 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2172 Then output LETTER to indicate the kind of location the symbol has. */
2175 dbxout_symbol_name (decl, suffix, letter)
2180 /* One slight hitch: if this is a VAR_DECL which is a static
2181 class member, we must put out the mangled name instead of the
2182 DECL_NAME. Note also that static member (variable) names DO NOT begin
2183 with underscores in .stabs directives. */
2184 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2187 fprintf (asmfile, "%s \"%s%s:", ASM_STABS_OP, name,
2188 (suffix ? suffix : ""));
2190 if (letter) putc (letter, asmfile);
2194 dbxout_prepare_symbol (decl)
2195 tree decl ATTRIBUTE_UNUSED;
2198 char *filename = DECL_SOURCE_FILE (decl);
2200 dbxout_source_file (asmfile, filename);
2205 dbxout_finish_symbol (sym)
2208 #ifdef DBX_FINISH_SYMBOL
2209 DBX_FINISH_SYMBOL (sym);
2212 if (use_gnu_debug_info_extensions && sym != 0)
2213 line = DECL_SOURCE_LINE (sym);
2215 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2216 if (current_sym_addr)
2217 output_addr_const (asmfile, current_sym_addr);
2219 fprintf (asmfile, "%d", current_sym_value);
2220 putc ('\n', asmfile);
2224 /* Output definitions of all the decls in a chain. */
2232 dbxout_symbol (syms, 1);
2233 syms = TREE_CHAIN (syms);
2237 /* The following two functions output definitions of function parameters.
2238 Each parameter gets a definition locating it in the parameter list.
2239 Each parameter that is a register variable gets a second definition
2240 locating it in the register.
2242 Printing or argument lists in gdb uses the definitions that
2243 locate in the parameter list. But reference to the variable in
2244 expressions uses preferentially the definition as a register. */
2246 /* Output definitions, referring to storage in the parmlist,
2247 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2250 dbxout_parms (parms)
2253 for (; parms; parms = TREE_CHAIN (parms))
2254 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2256 dbxout_prepare_symbol (parms);
2258 /* Perform any necessary register eliminations on the parameter's rtl,
2259 so that the debugging output will be accurate. */
2260 DECL_INCOMING_RTL (parms)
2261 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2262 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
2263 #ifdef LEAF_REG_REMAP
2264 if (current_function_uses_only_leaf_regs)
2266 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2267 leaf_renumber_regs_insn (DECL_RTL (parms));
2271 if (PARM_PASSED_IN_MEMORY (parms))
2273 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2275 /* ??? Here we assume that the parm address is indexed
2276 off the frame pointer or arg pointer.
2277 If that is not true, we produce meaningless results,
2278 but do not crash. */
2279 if (GET_CODE (addr) == PLUS
2280 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2281 current_sym_value = INTVAL (XEXP (addr, 1));
2283 current_sym_value = 0;
2285 current_sym_code = N_PSYM;
2286 current_sym_addr = 0;
2289 if (DECL_NAME (parms))
2291 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2293 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
2294 IDENTIFIER_POINTER (DECL_NAME (parms)),
2295 DBX_MEMPARM_STABS_LETTER);
2299 current_sym_nchars = 8;
2300 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
2301 DBX_MEMPARM_STABS_LETTER);
2304 /* It is quite tempting to use:
2306 dbxout_type (TREE_TYPE (parms), 0, 0);
2308 as the next statement, rather than using DECL_ARG_TYPE(), so
2309 that gcc reports the actual type of the parameter, rather
2310 than the promoted type. This certainly makes GDB's life
2311 easier, at least for some ports. The change is a bad idea
2312 however, since GDB expects to be able access the type without
2313 performing any conversions. So for example, if we were
2314 passing a float to an unprototyped function, gcc will store a
2315 double on the stack, but if we emit a stab saying the type is a
2316 float, then gdb will only read in a single value, and this will
2317 produce an erropneous value. */
2318 dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
2319 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2320 dbxout_finish_symbol (parms);
2322 else if (GET_CODE (DECL_RTL (parms)) == REG)
2325 char regparm_letter;
2327 /* Parm passed in registers and lives in registers or nowhere. */
2329 current_sym_code = DBX_REGPARM_STABS_CODE;
2330 regparm_letter = DBX_REGPARM_STABS_LETTER;
2331 current_sym_addr = 0;
2333 /* If parm lives in a register, use that register;
2334 pretend the parm was passed there. It would be more consistent
2335 to describe the register where the parm was passed,
2336 but in practice that register usually holds something else.
2338 If we use DECL_RTL, then we must use the declared type of
2339 the variable, not the type that it arrived in. */
2340 if (REGNO (DECL_RTL (parms)) >= 0
2341 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2343 best_rtl = DECL_RTL (parms);
2344 parm_type = TREE_TYPE (parms);
2346 /* If the parm lives nowhere, use the register where it was
2347 passed. It is also better to use the declared type here. */
2350 best_rtl = DECL_INCOMING_RTL (parms);
2351 parm_type = TREE_TYPE (parms);
2353 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2356 if (DECL_NAME (parms))
2358 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2359 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
2360 IDENTIFIER_POINTER (DECL_NAME (parms)),
2365 current_sym_nchars = 8;
2366 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
2370 dbxout_type (parm_type, 0, 0);
2371 dbxout_finish_symbol (parms);
2373 else if (GET_CODE (DECL_RTL (parms)) == MEM
2374 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2375 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2376 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2377 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2378 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2382 /* Parm was passed via invisible reference.
2383 That is, its address was passed in a register.
2384 Output it as if it lived in that register.
2385 The debugger will know from the type
2386 that it was actually passed by invisible reference. */
2388 char regparm_letter;
2389 /* Parm passed in registers and lives in registers or nowhere. */
2391 current_sym_code = DBX_REGPARM_STABS_CODE;
2392 if (use_gnu_debug_info_extensions)
2393 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2395 regparm_letter = DBX_REGPARM_STABS_LETTER;
2397 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2398 If it is an unallocated pseudo-reg, then use the register where
2399 it was passed instead. */
2400 if (REGNO (XEXP (DECL_RTL (parms), 0)) >= 0
2401 && REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2402 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2404 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2406 current_sym_addr = 0;
2409 if (DECL_NAME (parms))
2411 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2413 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
2414 IDENTIFIER_POINTER (DECL_NAME (parms)),
2419 current_sym_nchars = 8;
2420 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
2424 dbxout_type (TREE_TYPE (parms), 0, 0);
2425 dbxout_finish_symbol (parms);
2427 else if (GET_CODE (DECL_RTL (parms)) == MEM
2428 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2429 /* ??? A constant address for a parm can happen
2430 when the reg it lives in is equiv to a constant in memory.
2431 Should make this not happen, after 2.4. */
2432 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2434 /* Parm was passed in registers but lives on the stack. */
2436 current_sym_code = N_PSYM;
2437 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2438 in which case we want the value of that CONST_INT,
2439 or (MEM (REG ...)) or (MEM (MEM ...)),
2440 in which case we use a value of zero. */
2441 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2442 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2443 current_sym_value = 0;
2445 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2446 current_sym_addr = 0;
2448 /* Make a big endian correction if the mode of the type of the
2449 parameter is not the same as the mode of the rtl. */
2450 if (BYTES_BIG_ENDIAN
2451 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2452 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2454 current_sym_value += UNITS_PER_WORD - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2458 if (DECL_NAME (parms))
2460 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2462 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
2463 IDENTIFIER_POINTER (DECL_NAME (parms)),
2464 DBX_MEMPARM_STABS_LETTER);
2468 current_sym_nchars = 8;
2469 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
2470 DBX_MEMPARM_STABS_LETTER);
2474 = DEBUGGER_ARG_OFFSET (current_sym_value,
2475 XEXP (DECL_RTL (parms), 0));
2476 dbxout_type (TREE_TYPE (parms), 0, 0);
2477 dbxout_finish_symbol (parms);
2482 /* Output definitions for the places where parms live during the function,
2483 when different from where they were passed, when the parms were passed
2486 It is not useful to do this for parms passed in registers
2487 that live during the function in different registers, because it is
2488 impossible to look in the passed register for the passed value,
2489 so we use the within-the-function register to begin with.
2491 PARMS is a chain of PARM_DECL nodes. */
2494 dbxout_reg_parms (parms)
2497 for (; parms; parms = TREE_CHAIN (parms))
2498 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2500 dbxout_prepare_symbol (parms);
2502 /* Report parms that live in registers during the function
2503 but were passed in memory. */
2504 if (GET_CODE (DECL_RTL (parms)) == REG
2505 && REGNO (DECL_RTL (parms)) >= 0
2506 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2507 dbxout_symbol_location (parms, TREE_TYPE (parms),
2508 0, DECL_RTL (parms));
2509 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2510 dbxout_symbol_location (parms, TREE_TYPE (parms),
2511 0, DECL_RTL (parms));
2512 /* Report parms that live in memory but not where they were passed. */
2513 else if (GET_CODE (DECL_RTL (parms)) == MEM
2514 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2515 dbxout_symbol_location (parms, TREE_TYPE (parms),
2516 0, DECL_RTL (parms));
2520 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2521 output definitions of those names, in raw form */
2529 putc (',', asmfile);
2530 dbxout_type (TREE_VALUE (args), 0, 0);
2532 args = TREE_CHAIN (args);
2536 /* Given a chain of ..._TYPE nodes,
2537 find those which have typedef names and output those names.
2538 This is to ensure those types get output. */
2541 dbxout_types (types)
2542 register tree types;
2546 if (TYPE_NAME (types)
2547 && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
2548 && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
2549 dbxout_symbol (TYPE_NAME (types), 1);
2550 types = TREE_CHAIN (types);
2554 /* Output everything about a symbol block (a BLOCK node
2555 that represents a scope level),
2556 including recursive output of contained blocks.
2558 BLOCK is the BLOCK node.
2559 DEPTH is its depth within containing symbol blocks.
2560 ARGS is usually zero; but for the outermost block of the
2561 body of a function, it is a chain of PARM_DECLs for the function parameters.
2562 We output definitions of all the register parms
2563 as if they were local variables of that block.
2565 If -g1 was used, we count blocks just the same, but output nothing
2566 except for the outermost block.
2568 Actually, BLOCK may be several blocks chained together.
2569 We handle them all in sequence. */
2572 dbxout_block (block, depth, args)
2573 register tree block;
2581 /* Ignore blocks never expanded or otherwise marked as real. */
2582 if (TREE_USED (block))
2584 #ifndef DBX_LBRAC_FIRST
2585 /* In dbx format, the syms of a block come before the N_LBRAC. */
2586 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2587 dbxout_syms (BLOCK_VARS (block));
2589 dbxout_reg_parms (args);
2592 /* Now output an N_LBRAC symbol to represent the beginning of
2593 the block. Use the block's tree-walk order to generate
2594 the assembler symbols LBBn and LBEn
2595 that final will define around the code in this block. */
2596 if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE)
2599 blocknum = next_block_number++;
2600 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2602 if (BLOCK_HANDLER_BLOCK (block))
2604 /* A catch block. Must precede N_LBRAC. */
2605 tree decl = BLOCK_VARS (block);
2608 #ifdef DBX_OUTPUT_CATCH
2609 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2611 fprintf (asmfile, "%s \"%s:C1\",%d,0,0,", ASM_STABS_OP,
2612 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2613 assemble_name (asmfile, buf);
2614 fprintf (asmfile, "\n");
2616 decl = TREE_CHAIN (decl);
2620 #ifdef DBX_OUTPUT_LBRAC
2621 DBX_OUTPUT_LBRAC (asmfile, buf);
2623 fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC);
2624 assemble_name (asmfile, buf);
2625 #if DBX_BLOCKS_FUNCTION_RELATIVE
2626 fputc ('-', asmfile);
2627 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
2629 fprintf (asmfile, "\n");
2633 /* Count blocks the same way regardless of debug_info_level. */
2634 next_block_number++;
2636 #ifdef DBX_LBRAC_FIRST
2637 /* On some weird machines, the syms of a block
2638 come after the N_LBRAC. */
2639 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2640 dbxout_syms (BLOCK_VARS (block));
2642 dbxout_reg_parms (args);
2645 /* Output the subblocks. */
2646 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2648 /* Refer to the marker for the end of the block. */
2649 if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE)
2652 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2653 #ifdef DBX_OUTPUT_RBRAC
2654 DBX_OUTPUT_RBRAC (asmfile, buf);
2656 fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC);
2657 assemble_name (asmfile, buf);
2658 #if DBX_BLOCKS_FUNCTION_RELATIVE
2659 fputc ('-', asmfile);
2660 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
2662 fprintf (asmfile, "\n");
2666 block = BLOCK_CHAIN (block);
2670 /* Output the information about a function and its arguments and result.
2671 Usually this follows the function's code,
2672 but on some systems, it comes before. */
2675 dbxout_really_begin_function (decl)
2678 dbxout_symbol (decl, 0);
2679 dbxout_parms (DECL_ARGUMENTS (decl));
2680 if (DECL_NAME (DECL_RESULT (decl)) != 0)
2681 dbxout_symbol (DECL_RESULT (decl), 1);
2684 /* Called at beginning of output of function definition. */
2687 dbxout_begin_function (decl)
2688 tree decl ATTRIBUTE_UNUSED;
2690 #ifdef DBX_FUNCTION_FIRST
2691 dbxout_really_begin_function (decl);
2693 #ifdef DBX_CHECK_FUNCTION_FIRST
2694 if (DBX_CHECK_FUNCTION_FIRST)
2695 dbxout_really_begin_function (decl);
2700 /* Output dbx data for a function definition.
2701 This includes a definition of the function name itself (a symbol),
2702 definitions of the parameters (locating them in the parameter list)
2703 and then output the block that makes up the function's body
2704 (including all the auto variables of the function). */
2707 dbxout_function (decl)
2710 #ifndef DBX_FUNCTION_FIRST
2711 #ifdef DBX_CHECK_FUNCTION_FIRST
2712 if (!(DBX_CHECK_FUNCTION_FIRST))
2713 dbxout_really_begin_function (decl);
2715 dbxout_really_begin_function (decl);
2718 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
2719 #ifdef DBX_OUTPUT_FUNCTION_END
2720 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
2722 #if defined(ASM_OUTPUT_SECTION_NAME)
2723 if (use_gnu_debug_info_extensions
2724 #if defined(NO_DBX_FUNCTION_END)
2725 && ! NO_DBX_FUNCTION_END
2728 dbxout_function_end ();
2731 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */