OSDN Git Service

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