OSDN Git Service

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