OSDN Git Service

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