* tm.texi (REGISTER_MOVE_COST): Add a mode argument.
[official-gcc.git] / gcc / dbxout.c
blobc3838dfe9566855fdec954b6a234d6d3c3e47a9b
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 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 "defaults.h"
81 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions. */
82 #include "dbxout.h"
83 #include "toplev.h"
84 #include "tm_p.h"
85 #include "ggc.h"
87 #ifdef XCOFF_DEBUGGING_INFO
88 #include "xcoffout.h"
89 #endif
91 #ifndef ASM_STABS_OP
92 #define ASM_STABS_OP "\t.stabs\t"
93 #endif
95 #ifndef ASM_STABN_OP
96 #define ASM_STABN_OP "\t.stabn\t"
97 #endif
99 #ifndef DBX_TYPE_DECL_STABS_CODE
100 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
101 #endif
103 #ifndef DBX_STATIC_CONST_VAR_CODE
104 #define DBX_STATIC_CONST_VAR_CODE N_FUN
105 #endif
107 #ifndef DBX_REGPARM_STABS_CODE
108 #define DBX_REGPARM_STABS_CODE N_RSYM
109 #endif
111 #ifndef DBX_REGPARM_STABS_LETTER
112 #define DBX_REGPARM_STABS_LETTER 'P'
113 #endif
115 /* This is used for parameters passed by invisible reference in a register. */
116 #ifndef GDB_INV_REF_REGPARM_STABS_LETTER
117 #define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
118 #endif
120 #ifndef DBX_MEMPARM_STABS_LETTER
121 #define DBX_MEMPARM_STABS_LETTER 'p'
122 #endif
124 #ifndef FILE_NAME_JOINER
125 #define FILE_NAME_JOINER "/"
126 #endif
128 /* Nonzero means if the type has methods, only output debugging
129 information if methods are actually written to the asm file. This
130 optimization only works if the debugger can detect the special C++
131 marker. */
133 #define MINIMAL_DEBUG 1
135 #ifdef NO_DOLLAR_IN_LABEL
136 #ifdef NO_DOT_IN_LABEL
137 #undef MINIMAL_DEBUG
138 #define MINIMAL_DEBUG 0
139 #endif
140 #endif
142 /* Typical USG systems don't have stab.h, and they also have
143 no use for DBX-format debugging info. */
145 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
147 static int flag_minimal_debug = MINIMAL_DEBUG;
149 /* Nonzero if we have actually used any of the GDB extensions
150 to the debugging format. The idea is that we use them for the
151 first time only if there's a strong reason, but once we have done that,
152 we use them whenever convenient. */
154 static int have_used_extensions = 0;
156 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
157 for the N_SO filename stabs label. */
159 static int source_label_number = 1;
161 #ifdef DEBUG_SYMS_TEXT
162 #define FORCE_TEXT text_section ();
163 #else
164 #define FORCE_TEXT
165 #endif
167 /* If there is a system stab.h, use it. Otherwise, use our own. */
168 /* ??? This is supposed to describe the target's stab format, so using
169 the host HAVE_STAB_H appears to be wrong. For now, we use our own file
170 when cross compiling. */
171 #if defined (USG) || !defined (HAVE_STAB_H) || defined (CROSS_COMPILE)
172 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
173 #else
174 #include <stab.h>
176 /* This is a GNU extension we need to reference in this file. */
177 #ifndef N_CATCH
178 #define N_CATCH 0x54
179 #endif
180 #endif
182 #ifdef __GNU_STAB__
183 #define STAB_CODE_TYPE enum __stab_debug_code
184 #else
185 #define STAB_CODE_TYPE int
186 #endif
188 /* 1 if PARM is passed to this function in memory. */
190 #define PARM_PASSED_IN_MEMORY(PARM) \
191 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
193 /* A C expression for the integer offset value of an automatic variable
194 (N_LSYM) having address X (an RTX). */
195 #ifndef DEBUGGER_AUTO_OFFSET
196 #define DEBUGGER_AUTO_OFFSET(X) \
197 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
198 #endif
200 /* A C expression for the integer offset value of an argument (N_PSYM)
201 having address X (an RTX). The nominal offset is OFFSET. */
202 #ifndef DEBUGGER_ARG_OFFSET
203 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
204 #endif
206 /* Stream for writing to assembler file. */
208 static FILE *asmfile;
210 /* Last source file name mentioned in a NOTE insn. */
212 static const char *lastfile;
214 /* Current working directory. */
216 static const char *cwd;
218 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
220 /* Structure recording information about a C data type.
221 The status element says whether we have yet output
222 the definition of the type. TYPE_XREF says we have
223 output it as a cross-reference only.
224 The file_number and type_number elements are used if DBX_USE_BINCL
225 is defined. */
227 struct typeinfo
229 enum typestatus status;
230 #ifdef DBX_USE_BINCL
231 int file_number;
232 int type_number;
233 #endif
236 /* Vector recording information about C data types.
237 When we first notice a data type (a tree node),
238 we assign it a number using next_type_number.
239 That is its index in this vector. */
241 struct typeinfo *typevec;
243 /* Number of elements of space allocated in `typevec'. */
245 static int typevec_len;
247 /* In dbx output, each type gets a unique number.
248 This is the number for the next type output.
249 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
251 static int next_type_number;
253 #ifdef DBX_USE_BINCL
255 /* When using N_BINCL in dbx output, each type number is actually a
256 pair of the file number and the type number within the file.
257 This is a stack of input files. */
259 struct dbx_file
261 struct dbx_file *next;
262 int file_number;
263 int next_type_number;
266 /* This is the top of the stack. */
268 static struct dbx_file *current_file;
270 /* This is the next file number to use. */
272 static int next_file_number;
274 #endif /* DBX_USE_BINCL */
276 /* These variables are for dbxout_symbol to communicate to
277 dbxout_finish_symbol.
278 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
279 current_sym_value and current_sym_addr are two ways to address the
280 value to store in the symtab entry.
281 current_sym_addr if nonzero represents the value as an rtx.
282 If that is zero, current_sym_value is used. This is used
283 when the value is an offset (such as for auto variables,
284 register variables and parms). */
286 static STAB_CODE_TYPE current_sym_code;
287 static int current_sym_value;
288 static rtx current_sym_addr;
290 /* Number of chars of symbol-description generated so far for the
291 current symbol. Used by CHARS and CONTIN. */
293 static int current_sym_nchars;
295 /* Report having output N chars of the current symbol-description. */
297 #define CHARS(N) (current_sym_nchars += (N))
299 /* Break the current symbol-description, generating a continuation,
300 if it has become long. */
302 #ifndef DBX_CONTIN_LENGTH
303 #define DBX_CONTIN_LENGTH 80
304 #endif
306 #if DBX_CONTIN_LENGTH > 0
307 #define CONTIN \
308 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
309 #else
310 #define CONTIN do { } while (0)
311 #endif
313 #if defined(ASM_OUTPUT_SECTION_NAME)
314 static void dbxout_function_end PARAMS ((void));
315 #endif
316 static void dbxout_typedefs PARAMS ((tree));
317 static void dbxout_type_index PARAMS ((tree));
318 #if DBX_CONTIN_LENGTH > 0
319 static void dbxout_continue PARAMS ((void));
320 #endif
321 static void dbxout_type_fields PARAMS ((tree));
322 static void dbxout_type_method_1 PARAMS ((tree, const char *));
323 static void dbxout_type_methods PARAMS ((tree));
324 static void dbxout_range_type PARAMS ((tree));
325 static void dbxout_type PARAMS ((tree, int, int));
326 static void print_int_cst_octal PARAMS ((tree));
327 static void print_octal PARAMS ((unsigned HOST_WIDE_INT, int));
328 static void dbxout_type_name PARAMS ((tree));
329 static int dbxout_symbol_location PARAMS ((tree, tree, const char *, rtx));
330 static void dbxout_symbol_name PARAMS ((tree, const char *, int));
331 static void dbxout_prepare_symbol PARAMS ((tree));
332 static void dbxout_finish_symbol PARAMS ((tree));
333 static void dbxout_block PARAMS ((tree, int, tree));
334 static void dbxout_really_begin_function PARAMS ((tree));
336 #if defined(ASM_OUTPUT_SECTION_NAME)
337 static void
338 dbxout_function_end ()
340 static int scope_labelno = 0;
341 char lscope_label_name[100];
342 /* Convert Ltext into the appropriate format for local labels in case
343 the system doesn't insert underscores in front of user generated
344 labels. */
345 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
346 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Lscope", scope_labelno);
347 scope_labelno++;
349 /* By convention, GCC will mark the end of a function with an N_FUN
350 symbol and an empty string. */
351 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
352 assemble_name (asmfile, lscope_label_name);
353 fputc ('-', asmfile);
354 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
355 fprintf (asmfile, "\n");
357 #endif /* ! NO_DBX_FUNCTION_END */
359 /* At the beginning of compilation, start writing the symbol table.
360 Initialize `typevec' and output the standard data types of C. */
362 void
363 dbxout_init (asm_file, input_file_name, syms)
364 FILE *asm_file;
365 const char *input_file_name;
366 tree syms;
368 char ltext_label_name[100];
370 asmfile = asm_file;
372 typevec_len = 100;
373 typevec = (struct typeinfo *) xcalloc (typevec_len, sizeof typevec[0]);
375 /* Convert Ltext into the appropriate format for local labels in case
376 the system doesn't insert underscores in front of user generated
377 labels. */
378 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
380 /* Put the current working directory in an N_SO symbol. */
381 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
382 but GDB always does. */
383 if (use_gnu_debug_info_extensions)
384 #endif
386 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
388 char *wdslash = xmalloc (strlen (cwd) + sizeof (FILE_NAME_JOINER));
389 sprintf (wdslash, "%s%s", cwd, FILE_NAME_JOINER);
390 cwd = wdslash;
392 if (cwd)
394 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
395 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
396 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
397 fprintf (asmfile, "%s", ASM_STABS_OP);
398 output_quoted_string (asmfile, cwd);
399 fprintf (asmfile, ",%d,0,0,%s\n", N_SO, &ltext_label_name[1]);
400 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
404 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
405 /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
406 would give us an N_SOL, and we want an N_SO. */
407 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
408 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
409 /* We include outputting `Ltext:' here,
410 because that gives you a way to override it. */
411 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
412 fprintf (asmfile, "%s", ASM_STABS_OP);
413 output_quoted_string (asmfile, input_file_name);
414 fprintf (asmfile, ",%d,0,0,%s\n",
415 N_SO, &ltext_label_name[1]);
416 text_section ();
417 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0);
418 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
420 /* Possibly output something to inform GDB that this compilation was by
421 GCC. It's easier for GDB to parse it when after the N_SO's. This
422 is used in Solaris 2. */
423 #ifdef ASM_IDENTIFY_GCC_AFTER_SOURCE
424 ASM_IDENTIFY_GCC_AFTER_SOURCE (asmfile);
425 #endif
427 lastfile = input_file_name;
429 next_type_number = 1;
431 #ifdef DBX_USE_BINCL
432 current_file = (struct dbx_file *) xmalloc (sizeof *current_file);
433 current_file->next = NULL;
434 current_file->file_number = 0;
435 current_file->next_type_number = 1;
436 next_file_number = 1;
437 #endif
439 /* Make sure that types `int' and `char' have numbers 1 and 2.
440 Definitions of other integer types will refer to those numbers.
441 (Actually it should no longer matter what their numbers are.
442 Also, if any types with tags have been defined, dbxout_symbol
443 will output them first, so the numbers won't be 1 and 2. That
444 happens in C++. So it's a good thing it should no longer matter). */
446 #ifdef DBX_OUTPUT_STANDARD_TYPES
447 DBX_OUTPUT_STANDARD_TYPES (syms);
448 #else
449 dbxout_symbol (TYPE_NAME (integer_type_node), 0);
450 dbxout_symbol (TYPE_NAME (char_type_node), 0);
451 #endif
453 /* Get all permanent types that have typedef names,
454 and output them all, except for those already output. */
456 dbxout_typedefs (syms);
459 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
460 in the reverse order from that which is found in SYMS. */
462 static void
463 dbxout_typedefs (syms)
464 tree syms;
466 if (syms)
468 dbxout_typedefs (TREE_CHAIN (syms));
469 if (TREE_CODE (syms) == TYPE_DECL)
471 tree type = TREE_TYPE (syms);
472 if (TYPE_NAME (type)
473 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
474 && COMPLETE_TYPE_P (type)
475 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
476 dbxout_symbol (TYPE_NAME (type), 0);
481 /* Change to reading from a new source file. Generate a N_BINCL stab. */
483 void
484 dbxout_start_new_source_file (filename)
485 const char *filename ATTRIBUTE_UNUSED;
487 #ifdef DBX_USE_BINCL
488 struct dbx_file *n = (struct dbx_file *) xmalloc (sizeof *n);
490 n->next = current_file;
491 n->file_number = next_file_number++;
492 n->next_type_number = 1;
493 current_file = n;
494 fprintf (asmfile, "%s", ASM_STABS_OP);
495 output_quoted_string (asmfile, filename);
496 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
497 #endif
500 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
502 void
503 dbxout_resume_previous_source_file ()
505 #ifdef DBX_USE_BINCL
506 struct dbx_file *next;
508 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
509 next = current_file->next;
510 free (current_file);
511 current_file = next;
512 #endif
515 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
517 void
518 dbxout_source_file (file, filename)
519 FILE *file;
520 const char *filename;
522 char ltext_label_name[100];
524 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
526 #ifdef DBX_OUTPUT_SOURCE_FILENAME
527 DBX_OUTPUT_SOURCE_FILENAME (file, filename);
528 #else
529 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
530 source_label_number);
531 fprintf (file, "%s", ASM_STABS_OP);
532 output_quoted_string (file, filename);
533 fprintf (file, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
534 if (current_function_decl != NULL_TREE
535 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
536 ; /* Don't change section amid function. */
537 else
538 text_section ();
539 ASM_OUTPUT_INTERNAL_LABEL (file, "Ltext", source_label_number);
540 source_label_number++;
541 #endif
542 lastfile = filename;
546 /* Output a line number symbol entry into output stream FILE,
547 for source file FILENAME and line number LINENO. */
549 void
550 dbxout_source_line (file, filename, lineno)
551 FILE *file;
552 const char *filename;
553 int lineno;
555 dbxout_source_file (file, filename);
557 #ifdef ASM_OUTPUT_SOURCE_LINE
558 ASM_OUTPUT_SOURCE_LINE (file, lineno);
559 #else
560 fprintf (file, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
561 #endif
564 /* At the end of compilation, finish writing the symbol table.
565 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
566 to do nothing. */
568 void
569 dbxout_finish (file, filename)
570 FILE *file ATTRIBUTE_UNUSED;
571 const char *filename ATTRIBUTE_UNUSED;
573 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
574 DBX_OUTPUT_MAIN_SOURCE_FILE_END (file, filename);
575 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
578 /* Output the index of a type. */
580 static void
581 dbxout_type_index (type)
582 tree type;
584 #ifndef DBX_USE_BINCL
585 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
586 CHARS (3);
587 #else
588 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
589 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
590 CHARS (7);
591 #endif
594 #if DBX_CONTIN_LENGTH > 0
595 /* Continue a symbol-description that gets too big.
596 End one symbol table entry with a double-backslash
597 and start a new one, eventually producing something like
598 .stabs "start......\\",code,0,value
599 .stabs "...rest",code,0,value */
601 static void
602 dbxout_continue ()
604 #ifdef DBX_CONTIN_CHAR
605 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
606 #else
607 fprintf (asmfile, "\\\\");
608 #endif
609 dbxout_finish_symbol (NULL_TREE);
610 fprintf (asmfile, "%s\"", ASM_STABS_OP);
611 current_sym_nchars = 0;
613 #endif /* DBX_CONTIN_LENGTH > 0 */
615 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
616 This must be a separate function because anonymous unions require
617 recursive calls. */
619 static void
620 dbxout_type_fields (type)
621 tree type;
623 tree tem;
625 /* Output the name, type, position (in bits), size (in bits) of each
626 field that we can support. */
627 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
629 /* Omit here local type decls until we know how to support them. */
630 if (TREE_CODE (tem) == TYPE_DECL
631 /* Omit fields whose position or size are variable or too large to
632 represent. */
633 || (TREE_CODE (tem) == FIELD_DECL
634 && (! host_integerp (bit_position (tem), 0)
635 || ! DECL_SIZE (tem)
636 || ! host_integerp (DECL_SIZE (tem), 1)))
637 /* Omit here the nameless fields that are used to skip bits. */
638 || DECL_IGNORED_P (tem))
639 continue;
641 else if (TREE_CODE (tem) != CONST_DECL)
643 /* Continue the line if necessary,
644 but not before the first field. */
645 if (tem != TYPE_FIELDS (type))
646 CONTIN;
648 if (use_gnu_debug_info_extensions
649 && flag_minimal_debug
650 && TREE_CODE (tem) == FIELD_DECL
651 && DECL_VIRTUAL_P (tem)
652 && DECL_ASSEMBLER_NAME (tem))
654 have_used_extensions = 1;
655 CHARS (3 + IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (tem)));
656 fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem)), asmfile);
657 dbxout_type (DECL_FCONTEXT (tem), 0, 0);
658 fprintf (asmfile, ":");
659 dbxout_type (TREE_TYPE (tem), 0, 0);
660 fputc (',', asmfile);
661 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
662 int_bit_position (tem));
663 fputc (';', asmfile);
664 continue;
667 if (DECL_NAME (tem))
669 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
670 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
672 else
674 fprintf (asmfile, ":");
675 CHARS (2);
678 if (use_gnu_debug_info_extensions
679 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
680 || TREE_CODE (tem) != FIELD_DECL))
682 have_used_extensions = 1;
683 putc ('/', asmfile);
684 putc ((TREE_PRIVATE (tem) ? '0'
685 : TREE_PROTECTED (tem) ? '1' : '2'),
686 asmfile);
687 CHARS (2);
690 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
691 && DECL_BIT_FIELD_TYPE (tem))
692 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0, 0);
694 if (TREE_CODE (tem) == VAR_DECL)
696 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
698 const char *name =
699 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
700 have_used_extensions = 1;
701 fprintf (asmfile, ":%s;", name);
702 CHARS (strlen (name));
704 else
705 /* If TEM is non-static, GDB won't understand it. */
706 fprintf (asmfile, ",0,0;");
708 else
710 fputc (',', asmfile);
711 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
712 int_bit_position (tem));
713 fputc (',', asmfile);
714 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
715 tree_low_cst (DECL_SIZE (tem), 1));
716 fputc (';', asmfile);
717 CHARS (23);
723 /* Subroutine of `dbxout_type_methods'. Output debug info about the
724 method described DECL. DEBUG_NAME is an encoding of the method's
725 type signature. ??? We may be able to do without DEBUG_NAME altogether
726 now. */
728 static void
729 dbxout_type_method_1 (decl, debug_name)
730 tree decl;
731 const char *debug_name;
733 char c1 = 'A', c2;
735 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
736 c2 = '?';
737 else /* it's a METHOD_TYPE. */
739 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
740 /* A for normal functions.
741 B for `const' member functions.
742 C for `volatile' member functions.
743 D for `const volatile' member functions. */
744 if (TYPE_READONLY (TREE_TYPE (firstarg)))
745 c1 += 1;
746 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
747 c1 += 2;
749 if (DECL_VINDEX (decl))
750 c2 = '*';
751 else
752 c2 = '.';
755 fprintf (asmfile, ":%s;%c%c%c", debug_name,
756 TREE_PRIVATE (decl) ? '0'
757 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
758 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
759 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
761 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
763 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
764 tree_low_cst (DECL_VINDEX (decl), 0));
765 fputc (';', asmfile);
766 dbxout_type (DECL_CONTEXT (decl), 0, 0);
767 fprintf (asmfile, ";");
768 CHARS (8);
772 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
773 in TYPE. */
775 static void
776 dbxout_type_methods (type)
777 register tree type;
779 /* C++: put out the method names and their parameter lists */
780 tree methods = TYPE_METHODS (type);
781 tree type_encoding;
782 register tree fndecl;
783 register tree last;
784 char formatted_type_identifier_length[16];
785 register int type_identifier_length;
787 if (methods == NULL_TREE)
788 return;
790 type_encoding = DECL_NAME (TYPE_NAME (type));
792 #if 0
793 /* C++: Template classes break some assumptions made by this code about
794 the class names, constructor names, and encodings for assembler
795 label names. For now, disable output of dbx info for them. */
797 const char *ptr = IDENTIFIER_POINTER (type_encoding);
798 /* This should use index. (mrs) */
799 while (*ptr && *ptr != '<') ptr++;
800 if (*ptr != 0)
802 static int warned;
803 if (!warned)
804 warned = 1;
805 return;
808 #endif
810 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
812 sprintf(formatted_type_identifier_length, "%d", type_identifier_length);
814 if (TREE_CODE (methods) != TREE_VEC)
815 fndecl = methods;
816 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
817 fndecl = TREE_VEC_ELT (methods, 0);
818 else
819 fndecl = TREE_VEC_ELT (methods, 1);
821 while (fndecl)
823 tree name = DECL_NAME (fndecl);
824 int need_prefix = 1;
826 /* Group together all the methods for the same operation.
827 These differ in the types of the arguments. */
828 for (last = NULL_TREE;
829 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
830 fndecl = TREE_CHAIN (fndecl))
831 /* Output the name of the field (after overloading), as
832 well as the name of the field before overloading, along
833 with its parameter list */
835 /* This is the "mangled" name of the method.
836 It encodes the argument types. */
837 const char *debug_name =
838 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
839 int show_arg_types = 0;
841 CONTIN;
843 last = fndecl;
845 if (DECL_IGNORED_P (fndecl))
846 continue;
848 if (flag_minimal_debug)
850 char marker;
852 /* We can't optimize a method which uses an anonymous
853 class, because the debugger will not be able to
854 associate the arbitrary class name with the actual
855 class. */
856 #ifndef NO_DOLLAR_IN_LABEL
857 marker = '$';
858 #else
859 marker = '.';
860 #endif
861 if (strchr (debug_name, marker))
862 show_arg_types = 1;
863 /* Detect ordinary methods because their mangled names
864 start with the operation name. */
865 else if (!strncmp (IDENTIFIER_POINTER (name), debug_name,
866 IDENTIFIER_LENGTH (name)))
868 debug_name += IDENTIFIER_LENGTH (name);
869 if (debug_name[0] == '_' && debug_name[1] == '_')
871 const char *method_name = debug_name + 2;
872 const char *length_ptr =
873 formatted_type_identifier_length;
874 /* Get past const and volatile qualifiers. */
875 while (*method_name == 'C' || *method_name == 'V')
876 method_name++;
877 /* Skip digits for length of type_encoding. */
878 while (*method_name == *length_ptr && *length_ptr)
879 length_ptr++, method_name++;
880 if (! strncmp (method_name,
881 IDENTIFIER_POINTER (type_encoding),
882 type_identifier_length))
883 method_name += type_identifier_length;
884 debug_name = method_name;
887 /* Detect constructors by their style of name mangling. */
888 else if (debug_name[0] == '_' && debug_name[1] == '_')
890 const char *ctor_name = debug_name + 2;
891 const char *length_ptr = formatted_type_identifier_length;
892 while (*ctor_name == 'C' || *ctor_name == 'V')
893 ctor_name++;
894 /* Skip digits for length of type_encoding. */
895 while (*ctor_name == *length_ptr && *length_ptr)
896 length_ptr++, ctor_name++;
897 if (!strncmp (IDENTIFIER_POINTER (type_encoding), ctor_name,
898 type_identifier_length))
899 debug_name = ctor_name + type_identifier_length;
901 /* The other alternative is a destructor. */
902 else
903 show_arg_types = 1;
905 /* Output the operation name just once, for the first method
906 that we output. */
907 if (need_prefix)
909 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
910 CHARS (IDENTIFIER_LENGTH (name) + 2);
911 need_prefix = 0;
915 dbxout_type (TREE_TYPE (fndecl), 0, show_arg_types);
917 dbxout_type_method_1 (fndecl, debug_name);
919 if (!need_prefix)
921 putc (';', asmfile);
922 CHARS (1);
927 /* Emit a "range" type specification, which has the form:
928 "r<index type>;<lower bound>;<upper bound>;".
929 TYPE is an INTEGER_TYPE. */
931 static void
932 dbxout_range_type (type)
933 tree type;
935 fprintf (asmfile, "r");
936 if (TREE_TYPE (type))
937 dbxout_type (TREE_TYPE (type), 0, 0);
938 else if (TREE_CODE (type) != INTEGER_TYPE)
939 dbxout_type (type, 0, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
940 else
942 /* Traditionally, we made sure 'int' was type 1, and builtin types
943 were defined to be sub-ranges of int. Unfortunately, this
944 does not allow us to distinguish true sub-ranges from integer
945 types. So, instead we define integer (non-sub-range) types as
946 sub-ranges of themselves. This matters for Chill. If this isn't
947 a subrange type, then we want to define it in terms of itself.
948 However, in C, this may be an anonymous integer type, and we don't
949 want to emit debug info referring to it. Just calling
950 dbxout_type_index won't work anyways, because the type hasn't been
951 defined yet. We make this work for both cases by checked to see
952 whether this is a defined type, referring to it if it is, and using
953 'int' otherwise. */
954 if (TYPE_SYMTAB_ADDRESS (type) != 0)
955 dbxout_type_index (type);
956 else
957 dbxout_type_index (integer_type_node);
960 if (TYPE_MIN_VALUE (type) != 0
961 && host_integerp (TYPE_MIN_VALUE (type), 0))
963 fputc (';', asmfile);
964 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
965 tree_low_cst (TYPE_MIN_VALUE (type), 0));
967 else
968 fprintf (asmfile, ";0");
970 if (TYPE_MAX_VALUE (type) != 0
971 && host_integerp (TYPE_MAX_VALUE (type), 0))
973 fputc (';', asmfile);
974 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
975 tree_low_cst (TYPE_MAX_VALUE (type), 0));
976 fputc (';', asmfile);
978 else
979 fprintf (asmfile, ";-1;");
982 /* Output a reference to a type. If the type has not yet been
983 described in the dbx output, output its definition now.
984 For a type already defined, just refer to its definition
985 using the type number.
987 If FULL is nonzero, and the type has been described only with
988 a forward-reference, output the definition now.
989 If FULL is zero in this case, just refer to the forward-reference
990 using the number previously allocated.
992 If SHOW_ARG_TYPES is nonzero, we output a description of the argument
993 types for a METHOD_TYPE. */
995 static void
996 dbxout_type (type, full, show_arg_types)
997 tree type;
998 int full;
999 int show_arg_types;
1001 register tree tem;
1002 static int anonymous_type_number = 0;
1004 if (TREE_CODE (type) == VECTOR_TYPE)
1005 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
1007 /* If there was an input error and we don't really have a type,
1008 avoid crashing and write something that is at least valid
1009 by assuming `int'. */
1010 if (type == error_mark_node)
1011 type = integer_type_node;
1012 else
1014 /* Try to find the "main variant" with the same name but not const
1015 or volatile. (Since stabs does not distinguish const and volatile,
1016 there is no need to make them separate types. But types with
1017 different names are usefully distinguished.) */
1019 for (tem = TYPE_MAIN_VARIANT (type); tem; tem = TYPE_NEXT_VARIANT (tem))
1020 if (!TYPE_READONLY (tem) && !TYPE_VOLATILE (tem)
1021 && TYPE_NAME (tem) == TYPE_NAME (type))
1023 type = tem;
1024 break;
1026 if (TYPE_NAME (type)
1027 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1028 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1029 full = 0;
1032 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1034 /* Type has no dbx number assigned. Assign next available number. */
1035 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1037 /* Make sure type vector is long enough to record about this type. */
1039 if (next_type_number == typevec_len)
1041 typevec
1042 = (struct typeinfo *) xrealloc (typevec,
1043 typevec_len * 2 * sizeof typevec[0]);
1044 memset ((char *) (typevec + typevec_len), 0,
1045 typevec_len * sizeof typevec[0]);
1046 typevec_len *= 2;
1049 #ifdef DBX_USE_BINCL
1050 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1051 = current_file->file_number;
1052 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1053 = current_file->next_type_number++;
1054 #endif
1057 /* Output the number of this type, to refer to it. */
1058 dbxout_type_index (type);
1060 #ifdef DBX_TYPE_DEFINED
1061 if (DBX_TYPE_DEFINED (type))
1062 return;
1063 #endif
1065 /* If this type's definition has been output or is now being output,
1066 that is all. */
1068 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1070 case TYPE_UNSEEN:
1071 break;
1072 case TYPE_XREF:
1073 /* If we have already had a cross reference,
1074 and either that's all we want or that's the best we could do,
1075 don't repeat the cross reference.
1076 Sun dbx crashes if we do. */
1077 if (! full || !COMPLETE_TYPE_P (type)
1078 /* No way in DBX fmt to describe a variable size. */
1079 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1080 return;
1081 break;
1082 case TYPE_DEFINED:
1083 return;
1086 #ifdef DBX_NO_XREFS
1087 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1088 leave the type-number completely undefined rather than output
1089 a cross-reference. If we have already used GNU debug info extensions,
1090 then it is OK to output a cross reference. This is necessary to get
1091 proper C++ debug output. */
1092 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1093 || TREE_CODE (type) == QUAL_UNION_TYPE
1094 || TREE_CODE (type) == ENUMERAL_TYPE)
1095 && ! use_gnu_debug_info_extensions)
1096 /* We must use the same test here as we use twice below when deciding
1097 whether to emit a cross-reference. */
1098 if ((TYPE_NAME (type) != 0
1099 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1100 && DECL_IGNORED_P (TYPE_NAME (type)))
1101 && !full)
1102 || !COMPLETE_TYPE_P (type)
1103 /* No way in DBX fmt to describe a variable size. */
1104 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1106 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1107 return;
1109 #endif
1111 /* Output a definition now. */
1113 fprintf (asmfile, "=");
1114 CHARS (1);
1116 /* Mark it as defined, so that if it is self-referent
1117 we will not get into an infinite recursion of definitions. */
1119 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1121 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1122 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1124 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0, 0);
1125 return;
1128 switch (TREE_CODE (type))
1130 case VOID_TYPE:
1131 case LANG_TYPE:
1132 /* For a void type, just define it as itself; ie, "5=5".
1133 This makes us consider it defined
1134 without saying what it is. The debugger will make it
1135 a void type when the reference is seen, and nothing will
1136 ever override that default. */
1137 dbxout_type_index (type);
1138 break;
1140 case INTEGER_TYPE:
1141 if (type == char_type_node && ! TREE_UNSIGNED (type))
1143 /* Output the type `char' as a subrange of itself!
1144 I don't understand this definition, just copied it
1145 from the output of pcc.
1146 This used to use `r2' explicitly and we used to
1147 take care to make sure that `char' was type number 2. */
1148 fprintf (asmfile, "r");
1149 dbxout_type_index (type);
1150 fprintf (asmfile, ";0;127;");
1153 /* If this is a subtype of another integer type, always prefer to
1154 write it as a subtype. */
1155 else if (TREE_TYPE (type) != 0
1156 && TREE_CODE (TREE_TYPE (type)) == INTEGER_CST)
1157 dbxout_range_type (type);
1159 else
1161 /* If the size is non-standard, say what it is if we can use
1162 GDB extensions. */
1164 if (use_gnu_debug_info_extensions
1165 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1166 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1168 /* If we can use GDB extensions and the size is wider than a
1169 long (the size used by GDB to read them) or we may have
1170 trouble writing the bounds the usual way, write them in
1171 octal. Note the test is for the *target's* size of "long",
1172 not that of the host. The host test is just to make sure we
1173 can write it out in case the host wide int is narrower than the
1174 target "long". */
1176 /* For unsigned types, we use octal if they are the same size or
1177 larger. This is because we print the bounds as signed decimal,
1178 and hence they can't span same size unsigned types. */
1180 if (use_gnu_debug_info_extensions
1181 && TYPE_MIN_VALUE (type) != 0
1182 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1183 && TYPE_MAX_VALUE (type) != 0
1184 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1185 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1186 || (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)
1187 && TREE_UNSIGNED (type))
1188 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1189 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1190 && TREE_UNSIGNED (type))))
1192 fprintf (asmfile, "r");
1193 dbxout_type_index (type);
1194 fprintf (asmfile, ";");
1195 print_int_cst_octal (TYPE_MIN_VALUE (type));
1196 fprintf (asmfile, ";");
1197 print_int_cst_octal (TYPE_MAX_VALUE (type));
1198 fprintf (asmfile, ";");
1201 else
1202 /* Output other integer types as subranges of `int'. */
1203 dbxout_range_type (type);
1206 CHARS (22);
1207 break;
1209 case REAL_TYPE:
1210 /* This used to say `r1' and we used to take care
1211 to make sure that `int' was type number 1. */
1212 fprintf (asmfile, "r");
1213 dbxout_type_index (integer_type_node);
1214 fputc (';', asmfile);
1215 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, int_size_in_bytes (type));
1216 fputs (";0;", asmfile);
1217 CHARS (13);
1218 break;
1220 case CHAR_TYPE:
1221 if (use_gnu_debug_info_extensions)
1223 fputs ("@s", asmfile);
1224 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1225 BITS_PER_UNIT * int_size_in_bytes (type));
1226 fputs (";-20;", asmfile);
1228 else
1230 /* Output the type `char' as a subrange of itself.
1231 That is what pcc seems to do. */
1232 fprintf (asmfile, "r");
1233 dbxout_type_index (char_type_node);
1234 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1236 CHARS (9);
1237 break;
1239 case BOOLEAN_TYPE:
1240 if (use_gnu_debug_info_extensions)
1242 fputs ("@s", asmfile);
1243 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1244 BITS_PER_UNIT * int_size_in_bytes (type));
1245 fputs (";-16;", asmfile);
1247 else /* Define as enumeral type (False, True) */
1248 fprintf (asmfile, "eFalse:0,True:1,;");
1249 CHARS (17);
1250 break;
1252 case FILE_TYPE:
1253 putc ('d', asmfile);
1254 CHARS (1);
1255 dbxout_type (TREE_TYPE (type), 0, 0);
1256 break;
1258 case COMPLEX_TYPE:
1259 /* Differs from the REAL_TYPE by its new data type number */
1261 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1263 fprintf (asmfile, "r");
1264 dbxout_type_index (type);
1265 fputc (';', asmfile);
1266 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1267 2 * int_size_in_bytes (TREE_TYPE (type)));
1268 fputs (";0;", asmfile);
1269 CHARS (12); /* The number is probably incorrect here. */
1271 else
1273 /* Output a complex integer type as a structure,
1274 pending some other way to do it. */
1275 fputc ('s', asmfile);
1276 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, int_size_in_bytes (type));
1278 fprintf (asmfile, "real:");
1279 CHARS (10);
1280 dbxout_type (TREE_TYPE (type), 0, 0);
1281 fprintf (asmfile, ",%d,%d;",
1282 0, TYPE_PRECISION (TREE_TYPE (type)));
1283 CHARS (8);
1284 fprintf (asmfile, "imag:");
1285 CHARS (5);
1286 dbxout_type (TREE_TYPE (type), 0, 0);
1287 fprintf (asmfile, ",%d,%d;;",
1288 TYPE_PRECISION (TREE_TYPE (type)),
1289 TYPE_PRECISION (TREE_TYPE (type)));
1290 CHARS (9);
1292 break;
1294 case SET_TYPE:
1295 if (use_gnu_debug_info_extensions)
1297 have_used_extensions = 1;
1298 fputs ("@s", asmfile);
1299 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1300 BITS_PER_UNIT * int_size_in_bytes (type));
1301 fputc (';', asmfile);
1302 /* Check if a bitstring type, which in Chill is
1303 different from a [power]set. */
1304 if (TYPE_STRING_FLAG (type))
1305 fprintf (asmfile, "@S;");
1307 putc ('S', asmfile);
1308 CHARS (1);
1309 dbxout_type (TYPE_DOMAIN (type), 0, 0);
1310 break;
1312 case ARRAY_TYPE:
1313 /* Make arrays of packed bits look like bitstrings for chill. */
1314 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1316 have_used_extensions = 1;
1317 fputs ("@s", asmfile);
1318 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1319 BITS_PER_UNIT * int_size_in_bytes (type));
1320 fputc (';', asmfile);
1321 fprintf (asmfile, "@S;");
1322 putc ('S', asmfile);
1323 CHARS (1);
1324 dbxout_type (TYPE_DOMAIN (type), 0, 0);
1325 break;
1327 /* Output "a" followed by a range type definition
1328 for the index type of the array
1329 followed by a reference to the target-type.
1330 ar1;0;N;M for a C array of type M and size N+1. */
1331 /* Check if a character string type, which in Chill is
1332 different from an array of characters. */
1333 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1335 have_used_extensions = 1;
1336 fprintf (asmfile, "@S;");
1338 tem = TYPE_DOMAIN (type);
1339 if (tem == NULL)
1341 fprintf (asmfile, "ar");
1342 dbxout_type_index (integer_type_node);
1343 fprintf (asmfile, ";0;-1;");
1345 else
1347 fprintf (asmfile, "a");
1348 dbxout_range_type (tem);
1350 CHARS (14);
1351 dbxout_type (TREE_TYPE (type), 0, 0);
1352 break;
1354 case RECORD_TYPE:
1355 case UNION_TYPE:
1356 case QUAL_UNION_TYPE:
1358 int i, n_baseclasses = 0;
1360 if (TYPE_BINFO (type) != 0
1361 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1362 && TYPE_BINFO_BASETYPES (type) != 0)
1363 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1365 /* Output a structure type. We must use the same test here as we
1366 use in the DBX_NO_XREFS case above. */
1367 if ((TYPE_NAME (type) != 0
1368 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1369 && DECL_IGNORED_P (TYPE_NAME (type)))
1370 && !full)
1371 || !COMPLETE_TYPE_P (type)
1372 /* No way in DBX fmt to describe a variable size. */
1373 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1375 /* If the type is just a cross reference, output one
1376 and mark the type as partially described.
1377 If it later becomes defined, we will output
1378 its real definition.
1379 If the type has a name, don't nest its definition within
1380 another type's definition; instead, output an xref
1381 and let the definition come when the name is defined. */
1382 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1383 CHARS (3);
1384 #if 0 /* This assertion is legitimately false in C++. */
1385 /* We shouldn't be outputting a reference to a type before its
1386 definition unless the type has a tag name.
1387 A typedef name without a tag name should be impossible. */
1388 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1389 abort ();
1390 #endif
1391 if (TYPE_NAME (type) != 0)
1392 dbxout_type_name (type);
1393 else
1394 fprintf (asmfile, "$$%d", anonymous_type_number++);
1395 fprintf (asmfile, ":");
1396 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1397 break;
1400 /* Identify record or union, and print its size. */
1401 fputc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1402 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1403 int_size_in_bytes (type));
1405 if (use_gnu_debug_info_extensions)
1407 if (n_baseclasses)
1409 have_used_extensions = 1;
1410 fprintf (asmfile, "!%d,", n_baseclasses);
1411 CHARS (8);
1414 for (i = 0; i < n_baseclasses; i++)
1416 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1418 if (use_gnu_debug_info_extensions)
1420 have_used_extensions = 1;
1421 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1422 putc (TREE_VIA_PUBLIC (child) ? '2' : '0', asmfile);
1423 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1424 (tree_low_cst (BINFO_OFFSET (child), 0)
1425 * BITS_PER_UNIT));
1426 fputc (',', asmfile);
1427 CHARS (15);
1428 dbxout_type (BINFO_TYPE (child), 0, 0);
1429 putc (';', asmfile);
1431 else
1433 /* Print out the base class information with fields
1434 which have the same names at the types they hold. */
1435 dbxout_type_name (BINFO_TYPE (child));
1436 putc (':', asmfile);
1437 dbxout_type (BINFO_TYPE (child), full, 0);
1438 fputc (',', asmfile);
1439 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1440 tree_low_cst (BINFO_OFFSET (child), 0)
1441 * BITS_PER_UNIT);
1442 fputc (',', asmfile);
1443 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1444 (tree_low_cst (DECL_SIZE (TYPE_NAME
1445 (BINFO_TYPE (child))), 0)
1446 * BITS_PER_UNIT));
1447 fputc (';', asmfile);
1448 CHARS (20);
1453 CHARS (11);
1455 /* Write out the field declarations. */
1456 dbxout_type_fields (type);
1457 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1459 have_used_extensions = 1;
1460 dbxout_type_methods (type);
1463 putc (';', asmfile);
1465 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1466 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1467 && TYPE_VFIELD (type))
1469 have_used_extensions = 1;
1471 /* Tell GDB+ that it may keep reading. */
1472 putc ('~', asmfile);
1474 /* We need to write out info about what field this class
1475 uses as its "main" vtable pointer field, because if this
1476 field is inherited from a base class, GDB cannot necessarily
1477 figure out which field it's using in time. */
1478 if (TYPE_VFIELD (type))
1480 putc ('%', asmfile);
1481 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0, 0);
1483 putc (';', asmfile);
1484 CHARS (3);
1486 break;
1488 case ENUMERAL_TYPE:
1489 /* We must use the same test here as we use in the DBX_NO_XREFS case
1490 above. We simplify it a bit since an enum will never have a variable
1491 size. */
1492 if ((TYPE_NAME (type) != 0
1493 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1494 && DECL_IGNORED_P (TYPE_NAME (type)))
1495 && !full)
1496 || !COMPLETE_TYPE_P (type))
1498 fprintf (asmfile, "xe");
1499 CHARS (3);
1500 dbxout_type_name (type);
1501 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1502 fprintf (asmfile, ":");
1503 return;
1505 #ifdef DBX_OUTPUT_ENUM
1506 DBX_OUTPUT_ENUM (asmfile, type);
1507 #else
1508 if (use_gnu_debug_info_extensions
1509 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1510 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1511 putc ('e', asmfile);
1512 CHARS (1);
1513 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1515 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1516 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1517 fprintf (asmfile, HOST_WIDE_INT_PRINT_UNSIGNED,
1518 TREE_INT_CST_LOW (TREE_VALUE (tem)));
1519 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1520 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1521 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC,
1522 TREE_INT_CST_LOW (TREE_VALUE (tem)));
1523 else
1524 print_int_cst_octal (TREE_VALUE (tem));
1525 fprintf (asmfile, ",");
1526 CHARS (20 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
1527 if (TREE_CHAIN (tem) != 0)
1529 CONTIN;
1532 putc (';', asmfile);
1533 CHARS (1);
1534 #endif
1535 break;
1537 case POINTER_TYPE:
1538 putc ('*', asmfile);
1539 CHARS (1);
1540 dbxout_type (TREE_TYPE (type), 0, 0);
1541 break;
1543 case METHOD_TYPE:
1544 if (use_gnu_debug_info_extensions)
1546 have_used_extensions = 1;
1547 putc ('#', asmfile);
1548 CHARS (1);
1549 if (flag_minimal_debug && !show_arg_types)
1551 /* Normally, just output the return type.
1552 The argument types are encoded in the method name. */
1553 putc ('#', asmfile);
1554 CHARS (1);
1555 dbxout_type (TREE_TYPE (type), 0, 0);
1556 putc (';', asmfile);
1557 CHARS (1);
1559 else
1561 /* When outputting destructors, we need to write
1562 the argument types out longhand. */
1563 dbxout_type (TYPE_METHOD_BASETYPE (type), 0, 0);
1564 putc (',', asmfile);
1565 CHARS (1);
1566 dbxout_type (TREE_TYPE (type), 0, 0);
1567 dbxout_args (TYPE_ARG_TYPES (type));
1568 putc (';', asmfile);
1569 CHARS (1);
1572 else
1574 /* Treat it as a function type. */
1575 dbxout_type (TREE_TYPE (type), 0, 0);
1577 break;
1579 case OFFSET_TYPE:
1580 if (use_gnu_debug_info_extensions)
1582 have_used_extensions = 1;
1583 putc ('@', asmfile);
1584 CHARS (1);
1585 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0, 0);
1586 putc (',', asmfile);
1587 CHARS (1);
1588 dbxout_type (TREE_TYPE (type), 0, 0);
1590 else
1592 /* Should print as an int, because it is really
1593 just an offset. */
1594 dbxout_type (integer_type_node, 0, 0);
1596 break;
1598 case REFERENCE_TYPE:
1599 if (use_gnu_debug_info_extensions)
1600 have_used_extensions = 1;
1601 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1602 CHARS (1);
1603 dbxout_type (TREE_TYPE (type), 0, 0);
1604 break;
1606 case FUNCTION_TYPE:
1607 putc ('f', asmfile);
1608 CHARS (1);
1609 dbxout_type (TREE_TYPE (type), 0, 0);
1610 break;
1612 default:
1613 abort ();
1617 /* Print the value of integer constant C, in octal,
1618 handling double precision. */
1620 static void
1621 print_int_cst_octal (c)
1622 tree c;
1624 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1625 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1626 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1627 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1629 /* GDB wants constants with no extra leading "1" bits, so
1630 we need to remove any sign-extension that might be
1631 present. */
1632 if (width == HOST_BITS_PER_WIDE_INT * 2)
1634 else if (width > HOST_BITS_PER_WIDE_INT)
1635 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1636 else if (width == HOST_BITS_PER_WIDE_INT)
1637 high = 0;
1638 else
1639 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1641 fprintf (asmfile, "0");
1643 if (excess == 3)
1645 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1646 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1648 else
1650 unsigned HOST_WIDE_INT beg = high >> excess;
1651 unsigned HOST_WIDE_INT middle
1652 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1653 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1654 unsigned HOST_WIDE_INT end
1655 = low & (((unsigned HOST_WIDE_INT) 1
1656 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1657 - 1);
1659 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1660 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1664 static void
1665 print_octal (value, digits)
1666 unsigned HOST_WIDE_INT value;
1667 int digits;
1669 int i;
1671 for (i = digits - 1; i >= 0; i--)
1672 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1675 /* Output the name of type TYPE, with no punctuation.
1676 Such names can be set up either by typedef declarations
1677 or by struct, enum and union tags. */
1679 static void
1680 dbxout_type_name (type)
1681 register tree type;
1683 tree t;
1684 if (TYPE_NAME (type) == 0)
1685 abort ();
1686 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1688 t = TYPE_NAME (type);
1690 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1692 t = DECL_NAME (TYPE_NAME (type));
1694 else
1695 abort ();
1697 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1698 CHARS (IDENTIFIER_LENGTH (t));
1701 /* Output a .stabs for the symbol defined by DECL,
1702 which must be a ..._DECL node in the normal namespace.
1703 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1704 LOCAL is nonzero if the scope is less than the entire file.
1705 Return 1 if a stabs might have been emitted. */
1708 dbxout_symbol (decl, local)
1709 tree decl;
1710 int local ATTRIBUTE_UNUSED;
1712 tree type = TREE_TYPE (decl);
1713 tree context = NULL_TREE;
1714 int result = 0;
1716 /* Cast avoids warning in old compilers. */
1717 current_sym_code = (STAB_CODE_TYPE) 0;
1718 current_sym_value = 0;
1719 current_sym_addr = 0;
1721 /* Ignore nameless syms, but don't ignore type tags. */
1723 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1724 || DECL_IGNORED_P (decl))
1725 return 0;
1727 dbxout_prepare_symbol (decl);
1729 /* The output will always start with the symbol name,
1730 so always count that in the length-output-so-far. */
1732 if (DECL_NAME (decl) != 0)
1733 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1735 switch (TREE_CODE (decl))
1737 case CONST_DECL:
1738 /* Enum values are defined by defining the enum type. */
1739 break;
1741 case FUNCTION_DECL:
1742 if (DECL_RTL (decl) == 0)
1743 return 0;
1744 if (DECL_EXTERNAL (decl))
1745 break;
1746 /* Don't mention a nested function under its parent. */
1747 context = decl_function_context (decl);
1748 if (context == current_function_decl)
1749 break;
1750 if (GET_CODE (DECL_RTL (decl)) != MEM
1751 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1752 break;
1753 FORCE_TEXT;
1755 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1756 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1757 TREE_PUBLIC (decl) ? 'F' : 'f');
1758 result = 1;
1760 current_sym_code = N_FUN;
1761 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1763 if (TREE_TYPE (type))
1764 dbxout_type (TREE_TYPE (type), 0, 0);
1765 else
1766 dbxout_type (void_type_node, 0, 0);
1768 /* For a nested function, when that function is compiled,
1769 mention the containing function name
1770 as well as (since dbx wants it) our own assembler-name. */
1771 if (context != 0)
1772 fprintf (asmfile, ",%s,%s",
1773 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1774 IDENTIFIER_POINTER (DECL_NAME (context)));
1776 dbxout_finish_symbol (decl);
1777 break;
1779 case TYPE_DECL:
1780 #if 0
1781 /* This seems all wrong. Outputting most kinds of types gives no name
1782 at all. A true definition gives no name; a cross-ref for a
1783 structure can give the tag name, but not a type name.
1784 It seems that no typedef name is defined by outputting a type. */
1786 /* If this typedef name was defined by outputting the type,
1787 don't duplicate it. */
1788 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
1789 && TYPE_NAME (TREE_TYPE (decl)) == decl)
1790 return 0;
1791 #endif
1792 /* Don't output the same typedef twice.
1793 And don't output what language-specific stuff doesn't want output. */
1794 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
1795 return 0;
1797 FORCE_TEXT;
1798 result = 1;
1800 int tag_needed = 1;
1801 int did_output = 0;
1803 if (DECL_NAME (decl))
1805 /* Nonzero means we must output a tag as well as a typedef. */
1806 tag_needed = 0;
1808 /* Handle the case of a C++ structure or union
1809 where the TYPE_NAME is a TYPE_DECL
1810 which gives both a typedef name and a tag. */
1811 /* dbx requires the tag first and the typedef second. */
1812 if ((TREE_CODE (type) == RECORD_TYPE
1813 || TREE_CODE (type) == UNION_TYPE
1814 || TREE_CODE (type) == QUAL_UNION_TYPE)
1815 && TYPE_NAME (type) == decl
1816 && !(use_gnu_debug_info_extensions && have_used_extensions)
1817 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
1818 /* Distinguish the implicit typedefs of C++
1819 from explicit ones that might be found in C. */
1820 && DECL_ARTIFICIAL (decl))
1822 tree name = TYPE_NAME (type);
1823 if (TREE_CODE (name) == TYPE_DECL)
1824 name = DECL_NAME (name);
1826 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1827 current_sym_value = 0;
1828 current_sym_addr = 0;
1829 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1831 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
1832 IDENTIFIER_POINTER (name));
1833 dbxout_type (type, 1, 0);
1834 dbxout_finish_symbol (NULL_TREE);
1837 /* Output typedef name. */
1838 fprintf (asmfile, "%s\"%s:", ASM_STABS_OP,
1839 IDENTIFIER_POINTER (DECL_NAME (decl)));
1841 /* Short cut way to output a tag also. */
1842 if ((TREE_CODE (type) == RECORD_TYPE
1843 || TREE_CODE (type) == UNION_TYPE
1844 || TREE_CODE (type) == QUAL_UNION_TYPE)
1845 && TYPE_NAME (type) == decl
1846 /* Distinguish the implicit typedefs of C++
1847 from explicit ones that might be found in C. */
1848 && DECL_ARTIFICIAL (decl))
1850 if (use_gnu_debug_info_extensions && have_used_extensions)
1852 putc ('T', asmfile);
1853 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1855 #if 0 /* Now we generate the tag for this case up above. */
1856 else
1857 tag_needed = 1;
1858 #endif
1861 putc ('t', asmfile);
1862 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1864 dbxout_type (type, 1, 0);
1865 dbxout_finish_symbol (decl);
1866 did_output = 1;
1869 /* Don't output a tag if this is an incomplete type (TYPE_SIZE is
1870 zero). This prevents the sun4 Sun OS 4.x dbx from crashing. */
1872 if (tag_needed && TYPE_NAME (type) != 0
1873 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
1874 || (DECL_NAME (TYPE_NAME (type)) != 0))
1875 && COMPLETE_TYPE_P (type)
1876 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
1878 /* For a TYPE_DECL with no name, but the type has a name,
1879 output a tag.
1880 This is what represents `struct foo' with no typedef. */
1881 /* In C++, the name of a type is the corresponding typedef.
1882 In C, it is an IDENTIFIER_NODE. */
1883 tree name = TYPE_NAME (type);
1884 if (TREE_CODE (name) == TYPE_DECL)
1885 name = DECL_NAME (name);
1887 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1888 current_sym_value = 0;
1889 current_sym_addr = 0;
1890 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1892 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
1893 IDENTIFIER_POINTER (name));
1894 dbxout_type (type, 1, 0);
1895 dbxout_finish_symbol (NULL_TREE);
1896 did_output = 1;
1899 /* If an enum type has no name, it cannot be referred to,
1900 but we must output it anyway, since the enumeration constants
1901 can be referred to. */
1902 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
1904 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1905 current_sym_value = 0;
1906 current_sym_addr = 0;
1907 current_sym_nchars = 2;
1909 /* Some debuggers fail when given NULL names, so give this a
1910 harmless name of ` '. */
1911 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
1912 dbxout_type (type, 1, 0);
1913 dbxout_finish_symbol (NULL_TREE);
1916 /* Prevent duplicate output of a typedef. */
1917 TREE_ASM_WRITTEN (decl) = 1;
1918 break;
1921 case PARM_DECL:
1922 /* Parm decls go in their own separate chains
1923 and are output by dbxout_reg_parms and dbxout_parms. */
1924 abort ();
1926 case RESULT_DECL:
1927 /* Named return value, treat like a VAR_DECL. */
1928 case VAR_DECL:
1929 if (DECL_RTL (decl) == 0)
1930 return 0;
1931 /* Don't mention a variable that is external.
1932 Let the file that defines it describe it. */
1933 if (DECL_EXTERNAL (decl))
1934 break;
1936 /* If the variable is really a constant
1937 and not written in memory, inform the debugger. */
1938 if (TREE_STATIC (decl) && TREE_READONLY (decl)
1939 && DECL_INITIAL (decl) != 0
1940 && host_integerp (DECL_INITIAL (decl), 0)
1941 && ! TREE_ASM_WRITTEN (decl)
1942 && (DECL_CONTEXT (decl) == NULL_TREE
1943 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
1945 if (TREE_PUBLIC (decl) == 0)
1947 /* The sun4 assembler does not grok this. */
1948 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1950 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
1951 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
1953 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
1954 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
1955 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
1956 #else
1957 fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
1959 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
1960 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
1961 #endif
1962 return 1;
1964 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
1966 /* don't know how to do this yet. */
1968 break;
1970 /* else it is something we handle like a normal variable. */
1973 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
1974 #ifdef LEAF_REG_REMAP
1975 if (current_function_uses_only_leaf_regs)
1976 leaf_renumber_regs_insn (DECL_RTL (decl));
1977 #endif
1979 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
1980 break;
1982 default:
1983 break;
1985 return result;
1988 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
1989 Add SUFFIX to its name, if SUFFIX is not 0.
1990 Describe the variable as residing in HOME
1991 (usually HOME is DECL_RTL (DECL), but not always).
1992 Returns 1 if the stab was really emitted. */
1994 static int
1995 dbxout_symbol_location (decl, type, suffix, home)
1996 tree decl, type;
1997 const char *suffix;
1998 rtx home;
2000 int letter = 0;
2001 int regno = -1;
2003 /* Don't mention a variable at all
2004 if it was completely optimized into nothingness.
2006 If the decl was from an inline function, then its rtl
2007 is not identically the rtl that was used in this
2008 particular compilation. */
2009 if (GET_CODE (home) == REG)
2011 regno = REGNO (home);
2012 if (regno >= FIRST_PSEUDO_REGISTER)
2013 return 0;
2015 else if (GET_CODE (home) == SUBREG)
2017 rtx value = home;
2018 int offset = 0;
2019 while (GET_CODE (value) == SUBREG)
2021 offset += SUBREG_WORD (value);
2022 value = SUBREG_REG (value);
2024 if (GET_CODE (value) == REG)
2026 regno = REGNO (value);
2027 if (regno >= FIRST_PSEUDO_REGISTER)
2028 return 0;
2029 regno += offset;
2031 alter_subreg (home);
2034 /* The kind-of-variable letter depends on where
2035 the variable is and on the scope of its name:
2036 G and N_GSYM for static storage and global scope,
2037 S for static storage and file scope,
2038 V for static storage and local scope,
2039 for those two, use N_LCSYM if data is in bss segment,
2040 N_STSYM if in data segment, N_FUN otherwise.
2041 (We used N_FUN originally, then changed to N_STSYM
2042 to please GDB. However, it seems that confused ld.
2043 Now GDB has been fixed to like N_FUN, says Kingdon.)
2044 no letter at all, and N_LSYM, for auto variable,
2045 r and N_RSYM for register variable. */
2047 if (GET_CODE (home) == MEM
2048 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2050 if (TREE_PUBLIC (decl))
2052 letter = 'G';
2053 current_sym_code = N_GSYM;
2055 else
2057 current_sym_addr = XEXP (home, 0);
2059 letter = decl_function_context (decl) ? 'V' : 'S';
2061 /* This should be the same condition as in assemble_variable, but
2062 we don't have access to dont_output_data here. So, instead,
2063 we rely on the fact that error_mark_node initializers always
2064 end up in bss for C++ and never end up in bss for C. */
2065 if (DECL_INITIAL (decl) == 0
2066 || (!strcmp (lang_identify (), "cplusplus")
2067 && DECL_INITIAL (decl) == error_mark_node))
2068 current_sym_code = N_LCSYM;
2069 else if (DECL_IN_TEXT_SECTION (decl))
2070 /* This is not quite right, but it's the closest
2071 of all the codes that Unix defines. */
2072 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2073 else
2075 /* Ultrix `as' seems to need this. */
2076 #ifdef DBX_STATIC_STAB_DATA_SECTION
2077 data_section ();
2078 #endif
2079 current_sym_code = N_STSYM;
2083 else if (regno >= 0)
2085 letter = 'r';
2086 current_sym_code = N_RSYM;
2087 current_sym_value = DBX_REGISTER_NUMBER (regno);
2089 else if (GET_CODE (home) == MEM
2090 && (GET_CODE (XEXP (home, 0)) == MEM
2091 || (GET_CODE (XEXP (home, 0)) == REG
2092 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2093 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2094 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2095 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2096 #endif
2098 /* If the value is indirect by memory or by a register
2099 that isn't the frame pointer
2100 then it means the object is variable-sized and address through
2101 that register or stack slot. DBX has no way to represent this
2102 so all we can do is output the variable as a pointer.
2103 If it's not a parameter, ignore it.
2104 (VAR_DECLs like this can be made by integrate.c.) */
2106 if (GET_CODE (XEXP (home, 0)) == REG)
2108 letter = 'r';
2109 current_sym_code = N_RSYM;
2110 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2112 else
2114 current_sym_code = N_LSYM;
2115 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2116 We want the value of that CONST_INT. */
2117 current_sym_value
2118 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2121 /* Effectively do build_pointer_type, but don't cache this type,
2122 since it might be temporary whereas the type it points to
2123 might have been saved for inlining. */
2124 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2125 type = make_node (POINTER_TYPE);
2126 TREE_TYPE (type) = TREE_TYPE (decl);
2128 else if (GET_CODE (home) == MEM
2129 && GET_CODE (XEXP (home, 0)) == REG)
2131 current_sym_code = N_LSYM;
2132 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2134 else if (GET_CODE (home) == MEM
2135 && GET_CODE (XEXP (home, 0)) == PLUS
2136 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2138 current_sym_code = N_LSYM;
2139 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2140 We want the value of that CONST_INT. */
2141 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2143 else if (GET_CODE (home) == MEM
2144 && GET_CODE (XEXP (home, 0)) == CONST)
2146 /* Handle an obscure case which can arise when optimizing and
2147 when there are few available registers. (This is *always*
2148 the case for i386/i486 targets). The RTL looks like
2149 (MEM (CONST ...)) even though this variable is a local `auto'
2150 or a local `register' variable. In effect, what has happened
2151 is that the reload pass has seen that all assignments and
2152 references for one such a local variable can be replaced by
2153 equivalent assignments and references to some static storage
2154 variable, thereby avoiding the need for a register. In such
2155 cases we're forced to lie to debuggers and tell them that
2156 this variable was itself `static'. */
2157 current_sym_code = N_LCSYM;
2158 letter = 'V';
2159 current_sym_addr = XEXP (XEXP (home, 0), 0);
2161 else if (GET_CODE (home) == CONCAT)
2163 tree subtype = TREE_TYPE (type);
2165 /* If the variable's storage is in two parts,
2166 output each as a separate stab with a modified name. */
2167 if (WORDS_BIG_ENDIAN)
2168 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2169 else
2170 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2172 /* Cast avoids warning in old compilers. */
2173 current_sym_code = (STAB_CODE_TYPE) 0;
2174 current_sym_value = 0;
2175 current_sym_addr = 0;
2176 dbxout_prepare_symbol (decl);
2178 if (WORDS_BIG_ENDIAN)
2179 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2180 else
2181 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2182 return 1;
2184 else
2185 /* Address might be a MEM, when DECL is a variable-sized object.
2186 Or it might be const0_rtx, meaning previous passes
2187 want us to ignore this variable. */
2188 return 0;
2190 /* Ok, start a symtab entry and output the variable name. */
2191 FORCE_TEXT;
2193 #ifdef DBX_STATIC_BLOCK_START
2194 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2195 #endif
2197 dbxout_symbol_name (decl, suffix, letter);
2198 dbxout_type (type, 0, 0);
2199 dbxout_finish_symbol (decl);
2201 #ifdef DBX_STATIC_BLOCK_END
2202 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2203 #endif
2204 return 1;
2207 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2208 Then output LETTER to indicate the kind of location the symbol has. */
2210 static void
2211 dbxout_symbol_name (decl, suffix, letter)
2212 tree decl;
2213 const char *suffix;
2214 int letter;
2216 const char *name;
2218 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2219 /* One slight hitch: if this is a VAR_DECL which is a static
2220 class member, we must put out the mangled name instead of the
2221 DECL_NAME. Note also that static member (variable) names DO NOT begin
2222 with underscores in .stabs directives. */
2223 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2224 else
2225 /* ...but if we're function-local, we don't want to include the junk
2226 added by ASM_FORMAT_PRIVATE_NAME. */
2227 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2229 if (name == 0)
2230 name = "(anon)";
2231 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2232 (suffix ? suffix : ""));
2234 if (letter) putc (letter, asmfile);
2237 static void
2238 dbxout_prepare_symbol (decl)
2239 tree decl ATTRIBUTE_UNUSED;
2241 #ifdef WINNING_GDB
2242 const char *filename = DECL_SOURCE_FILE (decl);
2244 dbxout_source_file (asmfile, filename);
2245 #endif
2248 static void
2249 dbxout_finish_symbol (sym)
2250 tree sym;
2252 #ifdef DBX_FINISH_SYMBOL
2253 DBX_FINISH_SYMBOL (sym);
2254 #else
2255 int line = 0;
2256 if (use_gnu_debug_info_extensions && sym != 0)
2257 line = DECL_SOURCE_LINE (sym);
2259 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2260 if (current_sym_addr)
2261 output_addr_const (asmfile, current_sym_addr);
2262 else
2263 fprintf (asmfile, "%d", current_sym_value);
2264 putc ('\n', asmfile);
2265 #endif
2268 /* Output definitions of all the decls in a chain. Return non-zero if
2269 anything was output */
2272 dbxout_syms (syms)
2273 tree syms;
2275 int result = 0;
2276 while (syms)
2278 result += dbxout_symbol (syms, 1);
2279 syms = TREE_CHAIN (syms);
2281 return result;
2284 /* The following two functions output definitions of function parameters.
2285 Each parameter gets a definition locating it in the parameter list.
2286 Each parameter that is a register variable gets a second definition
2287 locating it in the register.
2289 Printing or argument lists in gdb uses the definitions that
2290 locate in the parameter list. But reference to the variable in
2291 expressions uses preferentially the definition as a register. */
2293 /* Output definitions, referring to storage in the parmlist,
2294 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2296 void
2297 dbxout_parms (parms)
2298 tree parms;
2300 for (; parms; parms = TREE_CHAIN (parms))
2301 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2303 dbxout_prepare_symbol (parms);
2305 /* Perform any necessary register eliminations on the parameter's rtl,
2306 so that the debugging output will be accurate. */
2307 DECL_INCOMING_RTL (parms)
2308 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2309 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
2310 #ifdef LEAF_REG_REMAP
2311 if (current_function_uses_only_leaf_regs)
2313 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2314 leaf_renumber_regs_insn (DECL_RTL (parms));
2316 #endif
2318 if (PARM_PASSED_IN_MEMORY (parms))
2320 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2322 /* ??? Here we assume that the parm address is indexed
2323 off the frame pointer or arg pointer.
2324 If that is not true, we produce meaningless results,
2325 but do not crash. */
2326 if (GET_CODE (addr) == PLUS
2327 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2328 current_sym_value = INTVAL (XEXP (addr, 1));
2329 else
2330 current_sym_value = 0;
2332 current_sym_code = N_PSYM;
2333 current_sym_addr = 0;
2335 FORCE_TEXT;
2336 if (DECL_NAME (parms))
2338 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2340 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2341 IDENTIFIER_POINTER (DECL_NAME (parms)),
2342 DBX_MEMPARM_STABS_LETTER);
2344 else
2346 current_sym_nchars = 8;
2347 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2348 DBX_MEMPARM_STABS_LETTER);
2351 /* It is quite tempting to use:
2353 dbxout_type (TREE_TYPE (parms), 0, 0);
2355 as the next statement, rather than using DECL_ARG_TYPE(), so
2356 that gcc reports the actual type of the parameter, rather
2357 than the promoted type. This certainly makes GDB's life
2358 easier, at least for some ports. The change is a bad idea
2359 however, since GDB expects to be able access the type without
2360 performing any conversions. So for example, if we were
2361 passing a float to an unprototyped function, gcc will store a
2362 double on the stack, but if we emit a stab saying the type is a
2363 float, then gdb will only read in a single value, and this will
2364 produce an erropneous value. */
2365 dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
2366 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2367 dbxout_finish_symbol (parms);
2369 else if (GET_CODE (DECL_RTL (parms)) == REG)
2371 rtx best_rtl;
2372 char regparm_letter;
2373 tree parm_type;
2374 /* Parm passed in registers and lives in registers or nowhere. */
2376 current_sym_code = DBX_REGPARM_STABS_CODE;
2377 regparm_letter = DBX_REGPARM_STABS_LETTER;
2378 current_sym_addr = 0;
2380 /* If parm lives in a register, use that register;
2381 pretend the parm was passed there. It would be more consistent
2382 to describe the register where the parm was passed,
2383 but in practice that register usually holds something else.
2385 If we use DECL_RTL, then we must use the declared type of
2386 the variable, not the type that it arrived in. */
2387 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2389 best_rtl = DECL_RTL (parms);
2390 parm_type = TREE_TYPE (parms);
2392 /* If the parm lives nowhere, use the register where it was
2393 passed. It is also better to use the declared type here. */
2394 else
2396 best_rtl = DECL_INCOMING_RTL (parms);
2397 parm_type = TREE_TYPE (parms);
2399 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2401 FORCE_TEXT;
2402 if (DECL_NAME (parms))
2404 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2405 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2406 IDENTIFIER_POINTER (DECL_NAME (parms)),
2407 regparm_letter);
2409 else
2411 current_sym_nchars = 8;
2412 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2413 regparm_letter);
2416 dbxout_type (parm_type, 0, 0);
2417 dbxout_finish_symbol (parms);
2419 else if (GET_CODE (DECL_RTL (parms)) == MEM
2420 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2421 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2422 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2423 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2424 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2425 #endif
2428 /* Parm was passed via invisible reference.
2429 That is, its address was passed in a register.
2430 Output it as if it lived in that register.
2431 The debugger will know from the type
2432 that it was actually passed by invisible reference. */
2434 char regparm_letter;
2435 /* Parm passed in registers and lives in registers or nowhere. */
2437 current_sym_code = DBX_REGPARM_STABS_CODE;
2438 if (use_gnu_debug_info_extensions)
2439 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2440 else
2441 regparm_letter = DBX_REGPARM_STABS_LETTER;
2443 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2444 If it is an unallocated pseudo-reg, then use the register where
2445 it was passed instead. */
2446 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2447 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2448 else
2449 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2451 current_sym_addr = 0;
2453 FORCE_TEXT;
2454 if (DECL_NAME (parms))
2456 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2458 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2459 IDENTIFIER_POINTER (DECL_NAME (parms)),
2460 regparm_letter);
2462 else
2464 current_sym_nchars = 8;
2465 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2466 regparm_letter);
2469 dbxout_type (TREE_TYPE (parms), 0, 0);
2470 dbxout_finish_symbol (parms);
2472 else if (GET_CODE (DECL_RTL (parms)) == MEM
2473 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2475 /* Parm was passed via invisible reference, with the reference
2476 living on the stack. DECL_RTL looks like
2477 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))). */
2478 const char *decl_name = (DECL_NAME (parms)
2479 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2480 : "(anon)");
2481 current_sym_value
2482 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2483 current_sym_addr = 0;
2485 FORCE_TEXT;
2486 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2487 dbxout_type (TREE_TYPE (parms), 0, 0);
2488 dbxout_finish_symbol (parms);
2490 else if (GET_CODE (DECL_RTL (parms)) == MEM
2491 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2492 /* ??? A constant address for a parm can happen
2493 when the reg it lives in is equiv to a constant in memory.
2494 Should make this not happen, after 2.4. */
2495 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2497 /* Parm was passed in registers but lives on the stack. */
2499 current_sym_code = N_PSYM;
2500 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2501 in which case we want the value of that CONST_INT,
2502 or (MEM (REG ...)),
2503 in which case we use a value of zero. */
2504 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2505 current_sym_value = 0;
2506 else
2507 current_sym_value
2508 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2510 current_sym_addr = 0;
2512 /* Make a big endian correction if the mode of the type of the
2513 parameter is not the same as the mode of the rtl. */
2514 if (BYTES_BIG_ENDIAN
2515 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2516 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2518 current_sym_value +=
2519 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2520 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2523 FORCE_TEXT;
2524 if (DECL_NAME (parms))
2526 current_sym_nchars
2527 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2529 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2530 IDENTIFIER_POINTER (DECL_NAME (parms)),
2531 DBX_MEMPARM_STABS_LETTER);
2533 else
2535 current_sym_nchars = 8;
2536 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2537 DBX_MEMPARM_STABS_LETTER);
2540 current_sym_value
2541 = DEBUGGER_ARG_OFFSET (current_sym_value,
2542 XEXP (DECL_RTL (parms), 0));
2543 dbxout_type (TREE_TYPE (parms), 0, 0);
2544 dbxout_finish_symbol (parms);
2549 /* Output definitions for the places where parms live during the function,
2550 when different from where they were passed, when the parms were passed
2551 in memory.
2553 It is not useful to do this for parms passed in registers
2554 that live during the function in different registers, because it is
2555 impossible to look in the passed register for the passed value,
2556 so we use the within-the-function register to begin with.
2558 PARMS is a chain of PARM_DECL nodes. */
2560 void
2561 dbxout_reg_parms (parms)
2562 tree parms;
2564 for (; parms; parms = TREE_CHAIN (parms))
2565 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2567 dbxout_prepare_symbol (parms);
2569 /* Report parms that live in registers during the function
2570 but were passed in memory. */
2571 if (GET_CODE (DECL_RTL (parms)) == REG
2572 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2573 dbxout_symbol_location (parms, TREE_TYPE (parms),
2574 0, DECL_RTL (parms));
2575 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2576 dbxout_symbol_location (parms, TREE_TYPE (parms),
2577 0, DECL_RTL (parms));
2578 /* Report parms that live in memory but not where they were passed. */
2579 else if (GET_CODE (DECL_RTL (parms)) == MEM
2580 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2581 dbxout_symbol_location (parms, TREE_TYPE (parms),
2582 0, DECL_RTL (parms));
2586 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2587 output definitions of those names, in raw form */
2589 void
2590 dbxout_args (args)
2591 tree args;
2593 while (args)
2595 putc (',', asmfile);
2596 dbxout_type (TREE_VALUE (args), 0, 0);
2597 CHARS (1);
2598 args = TREE_CHAIN (args);
2602 /* Given a chain of ..._TYPE nodes,
2603 find those which have typedef names and output those names.
2604 This is to ensure those types get output. */
2606 void
2607 dbxout_types (types)
2608 register tree types;
2610 while (types)
2612 if (TYPE_NAME (types)
2613 && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
2614 && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
2615 dbxout_symbol (TYPE_NAME (types), 1);
2616 types = TREE_CHAIN (types);
2620 /* Output everything about a symbol block (a BLOCK node
2621 that represents a scope level),
2622 including recursive output of contained blocks.
2624 BLOCK is the BLOCK node.
2625 DEPTH is its depth within containing symbol blocks.
2626 ARGS is usually zero; but for the outermost block of the
2627 body of a function, it is a chain of PARM_DECLs for the function parameters.
2628 We output definitions of all the register parms
2629 as if they were local variables of that block.
2631 If -g1 was used, we count blocks just the same, but output nothing
2632 except for the outermost block.
2634 Actually, BLOCK may be several blocks chained together.
2635 We handle them all in sequence. */
2637 static void
2638 dbxout_block (block, depth, args)
2639 register tree block;
2640 int depth;
2641 tree args;
2643 int blocknum = -1;
2645 #if DBX_BLOCKS_FUNCTION_RELATIVE
2646 const char *begin_label;
2647 if (current_function_func_begin_label != NULL_TREE)
2648 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2649 else
2650 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2651 #endif
2653 while (block)
2655 /* Ignore blocks never expanded or otherwise marked as real. */
2656 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2658 int did_output;
2660 #ifdef DBX_LBRAC_FIRST
2661 did_output = 1;
2662 #else
2663 /* In dbx format, the syms of a block come before the N_LBRAC.
2664 If nothing is output, we don't need the N_LBRAC, either. */
2665 did_output = 0;
2666 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2667 did_output = dbxout_syms (BLOCK_VARS (block));
2668 if (args)
2669 dbxout_reg_parms (args);
2670 #endif
2672 /* Now output an N_LBRAC symbol to represent the beginning of
2673 the block. Use the block's tree-walk order to generate
2674 the assembler symbols LBBn and LBEn
2675 that final will define around the code in this block. */
2676 if (depth > 0 && did_output)
2678 char buf[20];
2679 blocknum = BLOCK_NUMBER (block);
2680 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2682 if (BLOCK_HANDLER_BLOCK (block))
2684 /* A catch block. Must precede N_LBRAC. */
2685 tree decl = BLOCK_VARS (block);
2686 while (decl)
2688 #ifdef DBX_OUTPUT_CATCH
2689 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2690 #else
2691 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2692 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2693 assemble_name (asmfile, buf);
2694 fprintf (asmfile, "\n");
2695 #endif
2696 decl = TREE_CHAIN (decl);
2700 #ifdef DBX_OUTPUT_LBRAC
2701 DBX_OUTPUT_LBRAC (asmfile, buf);
2702 #else
2703 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2704 assemble_name (asmfile, buf);
2705 #if DBX_BLOCKS_FUNCTION_RELATIVE
2706 fputc ('-', asmfile);
2707 assemble_name (asmfile, begin_label);
2708 #endif
2709 fprintf (asmfile, "\n");
2710 #endif
2713 #ifdef DBX_LBRAC_FIRST
2714 /* On some weird machines, the syms of a block
2715 come after the N_LBRAC. */
2716 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2717 dbxout_syms (BLOCK_VARS (block));
2718 if (args)
2719 dbxout_reg_parms (args);
2720 #endif
2722 /* Output the subblocks. */
2723 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2725 /* Refer to the marker for the end of the block. */
2726 if (depth > 0 && did_output)
2728 char buf[20];
2729 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2730 #ifdef DBX_OUTPUT_RBRAC
2731 DBX_OUTPUT_RBRAC (asmfile, buf);
2732 #else
2733 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2734 assemble_name (asmfile, buf);
2735 #if DBX_BLOCKS_FUNCTION_RELATIVE
2736 fputc ('-', asmfile);
2737 assemble_name (asmfile, begin_label);
2738 #endif
2739 fprintf (asmfile, "\n");
2740 #endif
2743 block = BLOCK_CHAIN (block);
2747 /* Output the information about a function and its arguments and result.
2748 Usually this follows the function's code,
2749 but on some systems, it comes before. */
2751 static void
2752 dbxout_really_begin_function (decl)
2753 tree decl;
2755 dbxout_symbol (decl, 0);
2756 dbxout_parms (DECL_ARGUMENTS (decl));
2757 if (DECL_NAME (DECL_RESULT (decl)) != 0)
2758 dbxout_symbol (DECL_RESULT (decl), 1);
2761 /* Called at beginning of output of function definition. */
2763 void
2764 dbxout_begin_function (decl)
2765 tree decl ATTRIBUTE_UNUSED;
2767 #ifdef DBX_FUNCTION_FIRST
2768 dbxout_really_begin_function (decl);
2769 #endif
2772 /* Output dbx data for a function definition.
2773 This includes a definition of the function name itself (a symbol),
2774 definitions of the parameters (locating them in the parameter list)
2775 and then output the block that makes up the function's body
2776 (including all the auto variables of the function). */
2778 void
2779 dbxout_function (decl)
2780 tree decl;
2782 #ifndef DBX_FUNCTION_FIRST
2783 dbxout_really_begin_function (decl);
2784 #endif
2785 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
2786 #ifdef DBX_OUTPUT_FUNCTION_END
2787 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
2788 #endif
2789 #if defined(ASM_OUTPUT_SECTION_NAME)
2790 if (use_gnu_debug_info_extensions
2791 #if defined(NO_DBX_FUNCTION_END)
2792 && ! NO_DBX_FUNCTION_END
2793 #endif
2795 dbxout_function_end ();
2796 #endif
2798 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */