OSDN Git Service

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