OSDN Git Service

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