OSDN Git Service

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