OSDN Git Service

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