OSDN Git Service

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