OSDN Git Service

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