OSDN Git Service

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