OSDN Git Service

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