OSDN Git Service

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