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