OSDN Git Service

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