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