OSDN Git Service

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