OSDN Git Service

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