OSDN Git Service

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