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