OSDN Git Service

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