OSDN Git Service

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