OSDN Git Service

Yet more Objective-C++...
[pf3gnuchains/gcc-fork.git] / gcc / dbxout.c
1 /* Output dbx-format symbol table information from GNU compiler.
2    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22
23 /* Output dbx-format symbol table data.
24    This consists of many symbol table entries, each of them
25    a .stabs assembler pseudo-op with four operands:
26    a "name" which is really a description of one symbol and its type,
27    a "code", which is a symbol defined in stab.h whose name starts with N_,
28    an unused operand always 0,
29    and a "value" which is an address or an offset.
30    The name is enclosed in doublequote characters.
31
32    Each function, variable, typedef, and structure tag
33    has a symbol table entry to define it.
34    The beginning and end of each level of name scoping within
35    a function are also marked by special symbol table entries.
36
37    The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
38    and a data type number.  The data type number may be followed by
39    "=" and a type definition; normally this will happen the first time
40    the type number is mentioned.  The type definition may refer to
41    other types by number, and those type numbers may be followed
42    by "=" and nested definitions.
43
44    This can make the "name" quite long.
45    When a name is more than 80 characters, we split the .stabs pseudo-op
46    into two .stabs pseudo-ops, both sharing the same "code" and "value".
47    The first one is marked as continued with a double-backslash at the
48    end of its "name".
49
50    The kind-of-symbol letter distinguished function names from global
51    variables from file-scope variables from parameters from auto
52    variables in memory from typedef names from register variables.
53    See `dbxout_symbol'.
54
55    The "code" is mostly redundant with the kind-of-symbol letter
56    that goes in the "name", but not entirely: for symbols located
57    in static storage, the "code" says which segment the address is in,
58    which controls how it is relocated.
59
60    The "value" for a symbol in static storage
61    is the core address of the symbol (actually, the assembler
62    label for the symbol).  For a symbol located in a stack slot
63    it is the stack offset; for one in a register, the register number.
64    For a typedef symbol, it is zero.
65
66    If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
67    output while in the text section.
68
69    For more on data type definitions, see `dbxout_type'.  */
70
71 #include "config.h"
72 #include "system.h"
73 #include "coretypes.h"
74 #include "tm.h"
75
76 #include "tree.h"
77 #include "rtl.h"
78 #include "flags.h"
79 #include "regs.h"
80 #include "insn-config.h"
81 #include "reload.h"
82 #include "output.h"
83 #include "dbxout.h"
84 #include "toplev.h"
85 #include "tm_p.h"
86 #include "ggc.h"
87 #include "debug.h"
88 #include "function.h"
89 #include "target.h"
90 #include "langhooks.h"
91 #include "obstack.h"
92
93 #ifdef XCOFF_DEBUGGING_INFO
94 #include "xcoffout.h"
95 #endif
96
97 #define DBXOUT_DECR_NESTING \
98   if (--debug_nesting == 0 && symbol_queue_index > 0) \
99     { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
100
101 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
102   do {--debug_nesting; return (x);} while (0)
103
104 #ifndef ASM_STABS_OP
105 # ifdef XCOFF_DEBUGGING_INFO
106 #  define ASM_STABS_OP "\t.stabx\t"
107 # else
108 #  define ASM_STABS_OP "\t.stabs\t"
109 # endif
110 #endif
111
112 #ifndef ASM_STABN_OP
113 #define ASM_STABN_OP "\t.stabn\t"
114 #endif
115
116 #ifndef ASM_STABD_OP
117 #define ASM_STABD_OP "\t.stabd\t"
118 #endif
119
120 #ifndef DBX_TYPE_DECL_STABS_CODE
121 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
122 #endif
123
124 #ifndef DBX_STATIC_CONST_VAR_CODE
125 #define DBX_STATIC_CONST_VAR_CODE N_FUN
126 #endif
127
128 #ifndef DBX_REGPARM_STABS_CODE
129 #define DBX_REGPARM_STABS_CODE N_RSYM
130 #endif
131
132 #ifndef DBX_REGPARM_STABS_LETTER
133 #define DBX_REGPARM_STABS_LETTER 'P'
134 #endif
135
136 #ifndef NO_DBX_FUNCTION_END
137 #define NO_DBX_FUNCTION_END 0
138 #endif
139
140 #ifndef NO_DBX_BNSYM_ENSYM
141 #define NO_DBX_BNSYM_ENSYM 0
142 #endif
143
144 #ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
145 #define NO_DBX_MAIN_SOURCE_DIRECTORY 0
146 #endif
147
148 #ifndef DBX_BLOCKS_FUNCTION_RELATIVE
149 #define DBX_BLOCKS_FUNCTION_RELATIVE 0
150 #endif
151
152 #ifndef DBX_LINES_FUNCTION_RELATIVE
153 #define DBX_LINES_FUNCTION_RELATIVE 0
154 #endif
155
156 #ifndef DBX_CONTIN_LENGTH
157 #define DBX_CONTIN_LENGTH 80
158 #endif
159
160 #ifndef DBX_CONTIN_CHAR
161 #define DBX_CONTIN_CHAR '\\'
162 #endif
163
164 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
165
166 /* Structure recording information about a C data type.
167    The status element says whether we have yet output
168    the definition of the type.  TYPE_XREF says we have
169    output it as a cross-reference only.
170    The file_number and type_number elements are used if DBX_USE_BINCL
171    is defined.  */
172
173 struct typeinfo GTY(())
174 {
175   enum typestatus status;
176   int file_number;
177   int type_number;
178 };
179
180 /* Vector recording information about C data types.
181    When we first notice a data type (a tree node),
182    we assign it a number using next_type_number.
183    That is its index in this vector.  */
184
185 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
186
187 /* Number of elements of space allocated in `typevec'.  */
188
189 static GTY(()) int typevec_len;
190
191 /* In dbx output, each type gets a unique number.
192    This is the number for the next type output.
193    The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
194
195 static GTY(()) int next_type_number;
196
197 /* The C front end may call dbxout_symbol before dbxout_init runs.
198    We save all such decls in this list and output them when we get
199    to dbxout_init.  */
200
201 static GTY(()) tree preinit_symbols;
202
203 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
204
205 /* When using N_BINCL in dbx output, each type number is actually a
206    pair of the file number and the type number within the file.
207    This is a stack of input files.  */
208
209 struct dbx_file
210 {
211   struct dbx_file *next;
212   int file_number;
213   int next_type_number;
214   enum binclstatus bincl_status;  /* Keep track of lazy bincl.  */
215   const char *pending_bincl_name; /* Name of bincl.  */
216   struct dbx_file *prev;          /* Chain to traverse all pending bincls.  */
217 };
218
219 /* This is the top of the stack.  
220    
221    This is not saved for PCH, because restoring a PCH should not change it.
222    next_file_number does have to be saved, because the PCH may use some
223    file numbers; however, just before restoring a PCH, next_file_number
224    should always be 0 because we should not have needed any file numbers
225    yet.  */
226
227 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
228     && defined (DBX_USE_BINCL)
229 static struct dbx_file *current_file;
230 #endif
231
232 /* This is the next file number to use.  */
233
234 static GTY(()) int next_file_number;
235
236 /* A counter for dbxout_function_end.  */
237
238 static GTY(()) int scope_labelno;
239
240 /* A counter for dbxout_source_line.  */
241
242 static GTY(()) int dbxout_source_line_counter;
243
244 /* Number for the next N_SOL filename stabs label.  The number 0 is reserved
245    for the N_SO filename stabs label.  */
246
247 static GTY(()) int source_label_number = 1;
248
249 /* Last source file name mentioned in a NOTE insn.  */
250
251 static GTY(()) const char *lastfile;
252
253 /* Used by PCH machinery to detect if 'lastfile' should be reset to
254    base_input_file.  */
255 static GTY(()) int lastfile_is_base;
256
257 /* Typical USG systems don't have stab.h, and they also have
258    no use for DBX-format debugging info.  */
259
260 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
261
262 #ifdef DBX_USE_BINCL
263 /* If zero then there is no pending BINCL.  */
264 static int pending_bincls = 0;
265 #endif
266
267 /* The original input file name.  */
268 static const char *base_input_file;
269
270 #ifdef DEBUG_SYMS_TEXT
271 #define FORCE_TEXT current_function_section (current_function_decl);
272 #else
273 #define FORCE_TEXT
274 #endif
275
276 #include "gstab.h"
277
278 #define STAB_CODE_TYPE enum __stab_debug_code
279
280 /* 1 if PARM is passed to this function in memory.  */
281
282 #define PARM_PASSED_IN_MEMORY(PARM) \
283  (MEM_P (DECL_INCOMING_RTL (PARM)))
284
285 /* A C expression for the integer offset value of an automatic variable
286    (N_LSYM) having address X (an RTX).  */
287 #ifndef DEBUGGER_AUTO_OFFSET
288 #define DEBUGGER_AUTO_OFFSET(X) \
289   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
290 #endif
291
292 /* A C expression for the integer offset value of an argument (N_PSYM)
293    having address X (an RTX).  The nominal offset is OFFSET.  */
294 #ifndef DEBUGGER_ARG_OFFSET
295 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
296 #endif
297
298 /* This obstack holds the stab string currently being constructed.  We
299    build it up here, then write it out, so we can split long lines up
300    properly (see dbxout_finish_complex_stabs).  */
301 static struct obstack stabstr_ob;
302 static size_t stabstr_last_contin_point;
303
304 #ifdef DBX_USE_BINCL
305 static void emit_bincl_stab             (const char *c);
306 static void emit_pending_bincls         (void);
307 #endif
308 static inline void emit_pending_bincls_if_required (void);
309
310 static void dbxout_init (const char *);
311  
312 static void dbxout_finish (const char *);
313 static void dbxout_start_source_file (unsigned, const char *);
314 static void dbxout_end_source_file (unsigned);
315 static void dbxout_typedefs (tree);
316 static void dbxout_type_index (tree);
317 static void dbxout_args (tree);
318 static void dbxout_type_fields (tree);
319 static void dbxout_type_method_1 (tree);
320 static void dbxout_type_methods (tree);
321 static void dbxout_range_type (tree);
322 static void dbxout_type (tree, int);
323 static bool print_int_cst_bounds_in_octal_p (tree);
324 static void dbxout_type_name (tree);
325 static void dbxout_class_name_qualifiers (tree);
326 static int dbxout_symbol_location (tree, tree, const char *, rtx);
327 static void dbxout_symbol_name (tree, const char *, int);
328 static void dbxout_block (tree, int, tree);
329 static void dbxout_global_decl (tree);
330 static void dbxout_type_decl (tree, int);
331 static void dbxout_handle_pch (unsigned);
332 \f
333 /* The debug hooks structure.  */
334 #if defined (DBX_DEBUGGING_INFO)
335
336 static void dbxout_source_line (unsigned int, const char *);
337 static void dbxout_begin_prologue (unsigned int, const char *);
338 static void dbxout_source_file (const char *);
339 static void dbxout_function_end (tree);
340 static void dbxout_begin_function (tree);
341 static void dbxout_begin_block (unsigned, unsigned);
342 static void dbxout_end_block (unsigned, unsigned);
343 static void dbxout_function_decl (tree);
344
345 const struct gcc_debug_hooks dbx_debug_hooks =
346 {
347   dbxout_init,
348   dbxout_finish,
349   debug_nothing_int_charstar,
350   debug_nothing_int_charstar,
351   dbxout_start_source_file,
352   dbxout_end_source_file,
353   dbxout_begin_block,
354   dbxout_end_block,
355   debug_true_tree,                       /* ignore_block */
356   dbxout_source_line,                    /* source_line */
357   dbxout_begin_prologue,                 /* begin_prologue */
358   debug_nothing_int_charstar,            /* end_prologue */
359   debug_nothing_int_charstar,            /* end_epilogue */
360 #ifdef DBX_FUNCTION_FIRST
361   dbxout_begin_function,
362 #else
363   debug_nothing_tree,                    /* begin_function */
364 #endif
365   debug_nothing_int,                     /* end_function */
366   dbxout_function_decl,
367   dbxout_global_decl,                    /* global_decl */
368   dbxout_type_decl,                      /* type_decl */
369   debug_nothing_tree_tree,               /* imported_module_or_decl */
370   debug_nothing_tree,                    /* deferred_inline_function */
371   debug_nothing_tree,                    /* outlining_inline_function */
372   debug_nothing_rtx,                     /* label */
373   dbxout_handle_pch,                     /* handle_pch */
374   debug_nothing_rtx,                     /* var_location */
375   debug_nothing_void,                    /* switch_text_section */
376   0                                      /* start_end_main_source_file */
377 };
378 #endif /* DBX_DEBUGGING_INFO  */
379
380 #if defined (XCOFF_DEBUGGING_INFO)
381 const struct gcc_debug_hooks xcoff_debug_hooks =
382 {
383   dbxout_init,
384   dbxout_finish,
385   debug_nothing_int_charstar,
386   debug_nothing_int_charstar,
387   dbxout_start_source_file,
388   dbxout_end_source_file,
389   xcoffout_begin_block,
390   xcoffout_end_block,
391   debug_true_tree,                       /* ignore_block */
392   xcoffout_source_line,
393   xcoffout_begin_prologue,               /* begin_prologue */
394   debug_nothing_int_charstar,            /* end_prologue */
395   xcoffout_end_epilogue,
396   debug_nothing_tree,                    /* begin_function */
397   xcoffout_end_function,
398   debug_nothing_tree,                    /* function_decl */
399   dbxout_global_decl,                    /* global_decl */
400   dbxout_type_decl,                      /* type_decl */
401   debug_nothing_tree_tree,               /* imported_module_or_decl */
402   debug_nothing_tree,                    /* deferred_inline_function */
403   debug_nothing_tree,                    /* outlining_inline_function */
404   debug_nothing_rtx,                     /* label */
405   dbxout_handle_pch,                     /* handle_pch */
406   debug_nothing_rtx,                     /* var_location */
407   debug_nothing_void,                    /* switch_text_section */
408   0                                      /* start_end_main_source_file */
409 };
410 #endif /* XCOFF_DEBUGGING_INFO  */
411 \f
412 /* Numeric formatting helper macro.  Note that this does not handle
413    hexadecimal.  */
414 #define NUMBER_FMT_LOOP(P, NUM, BASE)           \
415   do                                            \
416     {                                           \
417       int digit = NUM % BASE;                   \
418       NUM /= BASE;                              \
419       *--P = digit + '0';                       \
420     }                                           \
421   while (NUM > 0)
422
423 /* Utility: write a decimal integer NUM to asm_out_file.  */
424 void
425 dbxout_int (int num)
426 {
427   char buf[64];
428   char *p = buf + sizeof buf;
429   unsigned int unum;
430
431   if (num == 0)
432     {
433       putc ('0', asm_out_file);
434       return;
435     }
436   if (num < 0)
437     {
438       putc ('-', asm_out_file);
439       unum = -num;
440     }
441   else
442     unum = num;
443
444   NUMBER_FMT_LOOP (p, unum, 10);
445
446   while (p < buf + sizeof buf)
447     {
448       putc (*p, asm_out_file);
449       p++;
450     }
451 }
452
453 \f
454 /* Primitives for emitting simple stabs directives.  All other stabs
455    routines should use these functions instead of directly emitting
456    stabs.  They are exported because machine-dependent code may need
457    to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
458    forwards to code in CPU.c.  */
459
460 /* The following functions should all be called immediately after one
461    of the dbxout_begin_stab* functions (below).  They write out
462    various things as the value of a stab.  */
463
464 /* Write out a literal zero as the value of a stab.  */
465 void
466 dbxout_stab_value_zero (void)
467 {
468   fputs ("0\n", asm_out_file);
469 }
470
471 /* Write out the label LABEL as the value of a stab.  */
472 void
473 dbxout_stab_value_label (const char *label)
474 {
475   assemble_name (asm_out_file, label);
476   putc ('\n', asm_out_file);
477 }
478
479 /* Write out the difference of two labels, LABEL - BASE, as the value
480    of a stab.  */
481 void
482 dbxout_stab_value_label_diff (const char *label, const char *base)
483 {
484   assemble_name (asm_out_file, label);
485   putc ('-', asm_out_file);
486   assemble_name (asm_out_file, base);
487   putc ('\n', asm_out_file);
488 }
489
490 /* Write out an internal label as the value of a stab, and immediately
491    emit that internal label.  This should be used only when
492    dbxout_stabd will not work.  STEM is the name stem of the label,
493    COUNTERP is a pointer to a counter variable which will be used to
494    guarantee label uniqueness.  */
495 void
496 dbxout_stab_value_internal_label (const char *stem, int *counterp)
497 {
498   char label[100];
499   int counter = counterp ? (*counterp)++ : 0;
500
501   ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
502   dbxout_stab_value_label (label);
503   targetm.asm_out.internal_label (asm_out_file, stem, counter);
504 }
505
506 /* Write out the difference between BASE and an internal label as the
507    value of a stab, and immediately emit that internal label.  STEM and
508    COUNTERP are as for dbxout_stab_value_internal_label.  */
509 void
510 dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
511                                        const char *base)
512 {
513   char label[100];
514   int counter = counterp ? (*counterp)++ : 0;
515
516   ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
517   dbxout_stab_value_label_diff (label, base);
518   targetm.asm_out.internal_label (asm_out_file, stem, counter);
519 }
520
521 /* The following functions produce specific kinds of stab directives.  */
522
523 /* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file.  */
524 void
525 dbxout_stabd (int stype, int sdesc)
526 {
527   fputs (ASM_STABD_OP, asm_out_file);
528   dbxout_int (stype);
529   fputs (",0,", asm_out_file);
530   dbxout_int (sdesc);
531   putc ('\n', asm_out_file);
532 }
533
534 /* Write a .stabn directive with type STYPE.  This function stops
535    short of emitting the value field, which is the responsibility of
536    the caller (normally it will be either a symbol or the difference
537    of two symbols).  */
538
539 void
540 dbxout_begin_stabn (int stype)
541 {
542   fputs (ASM_STABN_OP, asm_out_file);
543   dbxout_int (stype);
544   fputs (",0,0,", asm_out_file);
545 }
546
547 /* Write a .stabn directive with type N_SLINE and desc LINE.  As above,
548    the value field is the responsibility of the caller.  */
549 void
550 dbxout_begin_stabn_sline (int lineno)
551 {
552   fputs (ASM_STABN_OP, asm_out_file);
553   dbxout_int (N_SLINE);
554   fputs (",0,", asm_out_file);
555   dbxout_int (lineno);
556   putc (',', asm_out_file);
557 }
558
559 /* Begin a .stabs directive with string "", type STYPE, and desc and
560    other fields 0.  The value field is the responsibility of the
561    caller.  This function cannot be used for .stabx directives.  */
562 void
563 dbxout_begin_empty_stabs (int stype)
564 {
565   fputs (ASM_STABS_OP, asm_out_file);
566   fputs ("\"\",", asm_out_file);
567   dbxout_int (stype);
568   fputs (",0,0,", asm_out_file);
569 }
570
571 /* Begin a .stabs directive with string STR, type STYPE, and desc 0.
572    The value field is the responsibility of the caller.  */
573 void
574 dbxout_begin_simple_stabs (const char *str, int stype)
575 {
576   fputs (ASM_STABS_OP, asm_out_file);
577   output_quoted_string (asm_out_file, str);
578   putc (',', asm_out_file);
579   dbxout_int (stype);
580   fputs (",0,0,", asm_out_file);
581 }
582
583 /* As above but use SDESC for the desc field.  */
584 void
585 dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
586 {
587   fputs (ASM_STABS_OP, asm_out_file);
588   output_quoted_string (asm_out_file, str);
589   putc (',', asm_out_file);
590   dbxout_int (stype);
591   fputs (",0,", asm_out_file);
592   dbxout_int (sdesc);
593   putc (',', asm_out_file);
594 }
595
596 /* The next set of functions are entirely concerned with production of
597    "complex" .stabs directives: that is, .stabs directives whose
598    strings have to be constructed piecemeal.  dbxout_type,
599    dbxout_symbol, etc. use these routines heavily.  The string is queued
600    up in an obstack, then written out by dbxout_finish_complex_stabs, which
601    is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
602    (You might think it would be more efficient to go straight to stdio
603    when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
604    out not to be the case, and anyway this needs fewer #ifdefs.)  */
605
606 /* Begin a complex .stabs directive.  If we can, write the initial
607    ASM_STABS_OP to the asm_out_file.  */
608
609 static void
610 dbxout_begin_complex_stabs (void)
611 {
612   emit_pending_bincls_if_required ();
613   FORCE_TEXT;
614   fputs (ASM_STABS_OP, asm_out_file);
615   putc ('"', asm_out_file);
616   gcc_assert (stabstr_last_contin_point == 0);
617 }
618
619 /* As above, but do not force text or emit pending bincls.  This is
620    used by dbxout_symbol_location, which needs to do something else.  */
621 static void
622 dbxout_begin_complex_stabs_noforcetext (void)
623 {
624   fputs (ASM_STABS_OP, asm_out_file);
625   putc ('"', asm_out_file);
626   gcc_assert (stabstr_last_contin_point == 0);
627 }
628
629 /* Add CHR, a single character, to the string being built.  */
630 #define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
631
632 /* Add STR, a normal C string, to the string being built.  */
633 #define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen(str))
634
635 /* Add the text of ID, an IDENTIFIER_NODE, to the string being built.  */
636 #define stabstr_I(id) obstack_grow (&stabstr_ob, \
637                                     IDENTIFIER_POINTER (id), \
638                                     IDENTIFIER_LENGTH (id))
639
640 /* Add NUM, a signed decimal number, to the string being built.  */
641 static void
642 stabstr_D (HOST_WIDE_INT num)
643 {
644   char buf[64];
645   char *p = buf + sizeof buf;
646   unsigned int unum;
647
648   if (num == 0)
649     {
650       stabstr_C ('0');
651       return;
652     }
653   if (num < 0)
654     {
655       stabstr_C ('-');
656       unum = -num;
657     }
658   else
659     unum = num;
660
661   NUMBER_FMT_LOOP (p, unum, 10);
662
663   obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
664 }
665
666 /* Add NUM, an unsigned decimal number, to the string being built.  */
667 static void
668 stabstr_U (unsigned HOST_WIDE_INT num)
669 {
670   char buf[64];
671   char *p = buf + sizeof buf;
672   if (num == 0)
673     {
674       stabstr_C ('0');
675       return;
676     }
677   NUMBER_FMT_LOOP (p, num, 10);
678   obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
679 }
680
681 /* Add CST, an INTEGER_CST tree, to the string being built as an
682    unsigned octal number.  This routine handles values which are
683    larger than a single HOST_WIDE_INT.  */
684 static void
685 stabstr_O (tree cst)
686 {
687   unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (cst);
688   unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
689
690   char buf[128];
691   char *p = buf + sizeof buf;
692
693   /* GDB wants constants with no extra leading "1" bits, so
694      we need to remove any sign-extension that might be
695      present.  */
696   {
697     const unsigned int width = TYPE_PRECISION (TREE_TYPE (cst));
698     if (width == HOST_BITS_PER_WIDE_INT * 2)
699       ;
700     else if (width > HOST_BITS_PER_WIDE_INT)
701       high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
702     else if (width == HOST_BITS_PER_WIDE_INT)
703       high = 0;
704     else
705       high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
706   }
707
708   /* Leading zero for base indicator.  */
709   stabstr_C ('0');
710
711   /* If the value is zero, the base indicator will serve as the value
712      all by itself.  */
713   if (high == 0 && low == 0)
714     return;
715
716   /* If the high half is zero, we need only print the low half normally.  */
717   if (high == 0)
718     NUMBER_FMT_LOOP (p, low, 8);
719   else
720     {
721       /* When high != 0, we need to print enough zeroes from low to
722          give the digits from high their proper place-values.  Hence
723          NUMBER_FMT_LOOP cannot be used.  */
724       const int n_digits = HOST_BITS_PER_WIDE_INT / 3;
725       int i;
726
727       for (i = 1; i <= n_digits; i++)
728         {
729           unsigned int digit = low % 8;
730           low /= 8;
731           *--p = '0' + digit;
732         }
733
734       /* Octal digits carry exactly three bits of information.  The
735          width of a HOST_WIDE_INT is not normally a multiple of three.
736          Therefore, the next digit printed probably needs to carry
737          information from both low and high.  */
738       if (HOST_BITS_PER_WIDE_INT % 3 != 0)
739         {
740           const int n_leftover_bits = HOST_BITS_PER_WIDE_INT % 3;
741           const int n_bits_from_high = 3 - n_leftover_bits;
742
743           const unsigned HOST_WIDE_INT
744             low_mask = (((unsigned HOST_WIDE_INT)1) << n_leftover_bits) - 1;
745           const unsigned HOST_WIDE_INT
746             high_mask = (((unsigned HOST_WIDE_INT)1) << n_bits_from_high) - 1;
747
748           unsigned int digit;
749
750           /* At this point, only the bottom n_leftover_bits bits of low
751              should be set.  */
752           gcc_assert (!(low & ~low_mask));
753
754           digit = (low | ((high & high_mask) << n_leftover_bits));
755           high >>= n_bits_from_high;
756
757           *--p = '0' + digit;
758         }
759
760       /* Now we can format high in the normal manner.  However, if
761          the only bits of high that were set were handled by the
762          digit split between low and high, high will now be zero, and
763          we don't want to print extra digits in that case.  */
764       if (high)
765         NUMBER_FMT_LOOP (p, high, 8);
766     }
767
768   obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
769 }
770
771 /* Called whenever it is safe to break a stabs string into multiple
772    .stabs directives.  If the current string has exceeded the limit
773    set by DBX_CONTIN_LENGTH, mark the current position in the buffer
774    as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
775    it is a backslash) and a null character.  */
776 static inline void
777 stabstr_continue (void)
778 {
779   if (DBX_CONTIN_LENGTH > 0
780       && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
781          > DBX_CONTIN_LENGTH)
782     {
783       if (DBX_CONTIN_CHAR == '\\')
784         obstack_1grow (&stabstr_ob, '\\');
785       obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
786       obstack_1grow (&stabstr_ob, '\0');
787       stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
788     }
789 }
790 #define CONTIN stabstr_continue ()
791
792 /* Macro subroutine of dbxout_finish_complex_stabs, which emits
793    all of the arguments to the .stabs directive after the string.
794    Overridden by xcoffout.h.  CODE is the stabs code for this symbol;
795    LINE is the source line to write into the desc field (in extended
796    mode); SYM is the symbol itself.
797
798    ADDR, LABEL, and NUMBER are three different ways to represent the
799    stabs value field.  At most one of these should be nonzero.
800
801      ADDR is used most of the time; it represents the value as an
802      RTL address constant.
803
804      LABEL is used (currently) only for N_CATCH stabs; it represents
805      the value as a string suitable for assemble_name.
806
807      NUMBER is used when the value is an offset from an implicit base
808      pointer (e.g. for a stack variable), or an index (e.g. for a
809      register variable).  It represents the value as a decimal integer.  */
810
811 #ifndef DBX_FINISH_STABS
812 #define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER)  \
813 do {                                                            \
814   int line_ = use_gnu_debug_info_extensions ? LINE : 0;         \
815                                                                 \
816   dbxout_int (CODE);                                            \
817   fputs (",0,", asm_out_file);                                  \
818   dbxout_int (line_);                                           \
819   putc (',', asm_out_file);                                     \
820   if (ADDR)                                                     \
821     output_addr_const (asm_out_file, ADDR);                     \
822   else if (LABEL)                                               \
823     assemble_name (asm_out_file, LABEL);                        \
824   else                                                          \
825     dbxout_int (NUMBER);                                        \
826   putc ('\n', asm_out_file);                                    \
827 } while (0)
828 #endif
829
830 /* Finish the emission of a complex .stabs directive.  When DBX_CONTIN_LENGTH
831    is zero, this has only to emit the close quote and the remainder of
832    the arguments.  When it is nonzero, the string has been marshalled in
833    stabstr_ob, and this routine is responsible for breaking it up into
834    DBX_CONTIN_LENGTH-sized chunks.
835
836    SYM is the DECL of the symbol under consideration; it is used only
837    for its DECL_SOURCE_LINE.  The other arguments are all passed directly
838    to DBX_FINISH_STABS; see above for details.  */
839    
840 static void
841 dbxout_finish_complex_stabs (tree sym, STAB_CODE_TYPE code,
842                              rtx addr, const char *label, int number)
843 {
844   int line ATTRIBUTE_UNUSED;
845   char *str;
846   size_t len;
847
848   line = sym ? DECL_SOURCE_LINE (sym) : 0;
849   if (DBX_CONTIN_LENGTH > 0)
850     {
851       char *chunk;
852       size_t chunklen;
853
854       /* Nul-terminate the growing string, then get its size and
855          address.  */
856       obstack_1grow (&stabstr_ob, '\0');
857
858       len = obstack_object_size (&stabstr_ob);
859       chunk = str = obstack_finish (&stabstr_ob);
860
861       /* Within the buffer are a sequence of NUL-separated strings,
862          each of which is to be written out as a separate stab
863          directive.  */
864       for (;;)
865         {
866           chunklen = strlen (chunk);
867           fwrite (chunk, 1, chunklen, asm_out_file);
868           fputs ("\",", asm_out_file);
869
870           /* Must add an extra byte to account for the NUL separator.  */
871           chunk += chunklen + 1;
872           len   -= chunklen + 1;
873
874           /* Only put a line number on the last stab in the sequence.  */
875           DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
876                             addr, label, number);
877           if (len == 0)
878             break;
879
880           fputs (ASM_STABS_OP, asm_out_file);
881           putc ('"', asm_out_file);
882         }
883       stabstr_last_contin_point = 0;
884     }
885   else
886     {
887       /* No continuations - we can put the whole string out at once.
888          It is faster to augment the string with the close quote and
889          comma than to do a two-character fputs.  */
890       obstack_grow (&stabstr_ob, "\",", 2);
891       len = obstack_object_size (&stabstr_ob);
892       str = obstack_finish (&stabstr_ob);
893       
894       fwrite (str, 1, len, asm_out_file);
895       DBX_FINISH_STABS (sym, code, line, addr, label, number);
896     }
897   obstack_free (&stabstr_ob, str);
898 }
899
900 #if defined (DBX_DEBUGGING_INFO)
901
902 static void
903 dbxout_function_end (tree decl)
904 {
905   char lscope_label_name[100];
906
907   /* The Lscope label must be emitted even if we aren't doing anything
908      else; dbxout_block needs it.  */
909   function_section (current_function_decl);
910   
911   /* Convert Lscope into the appropriate format for local labels in case
912      the system doesn't insert underscores in front of user generated
913      labels.  */
914   ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
915   targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
916   scope_labelno++;
917
918   /* The N_FUN tag at the end of the function is a GNU extension,
919      which may be undesirable, and is unnecessary if we do not have
920      named sections.  */
921   if (!use_gnu_debug_info_extensions
922       || NO_DBX_FUNCTION_END
923       || !targetm.have_named_sections
924       || DECL_IGNORED_P (decl))
925     return;
926
927   /* By convention, GCC will mark the end of a function with an N_FUN
928      symbol and an empty string.  */
929 #ifdef DBX_OUTPUT_NFUN
930   DBX_OUTPUT_NFUN (asm_out_file, lscope_label_name, current_function_decl);
931 #else
932   if (flag_reorder_blocks_and_partition)
933     {
934       dbxout_begin_empty_stabs (N_FUN);
935       dbxout_stab_value_label_diff (cfun->hot_section_end_label, 
936                                     cfun->hot_section_label);
937       dbxout_begin_empty_stabs (N_FUN);
938       dbxout_stab_value_label_diff (cfun->cold_section_end_label, 
939                                     cfun->cold_section_label);
940     }
941   else
942     {
943       dbxout_begin_empty_stabs (N_FUN);
944       dbxout_stab_value_label_diff (lscope_label_name,
945                                     XSTR (XEXP (DECL_RTL (current_function_decl), 
946                                                 0), 0));
947     }
948                                 
949 #endif
950
951   if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
952     dbxout_stabd (N_ENSYM, 0);
953 }
954 #endif /* DBX_DEBUGGING_INFO */
955
956 /* Get lang description for N_SO stab.  */
957 static unsigned int ATTRIBUTE_UNUSED
958 get_lang_number (void)
959 {
960   const char *language_string = lang_hooks.name;
961
962   if (strcmp (language_string, "GNU C") == 0)
963     return N_SO_C;
964   else if (strcmp (language_string, "GNU C++") == 0)
965     return N_SO_CC;
966   else if (strcmp (language_string, "GNU F77") == 0)
967     return N_SO_FORTRAN;
968   else if (strcmp (language_string, "GNU F95") == 0)
969     return N_SO_FORTRAN90; /* CHECKME */
970   else if (strcmp (language_string, "GNU Pascal") == 0)
971     return N_SO_PASCAL;
972   else if (strcmp (language_string, "GNU Objective-C") == 0)
973     return N_SO_OBJC;
974   else 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                       /* For a virtual base, print the (negative)
2086                          offset within the vtable where we must look
2087                          to find the necessary adjustment.  */
2088                       stabstr_D
2089                         (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2090                          * BITS_PER_UNIT);
2091                     else
2092                       stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2093                                        * BITS_PER_UNIT);
2094                     stabstr_C (',');
2095                     dbxout_type (BINFO_TYPE (child), 0);
2096                     stabstr_C (';');
2097                   }
2098                 else
2099                   {
2100                     /* Print out the base class information with
2101                        fields which have the same names at the types
2102                        they hold.  */
2103                     dbxout_type_name (BINFO_TYPE (child));
2104                     stabstr_C (':');
2105                     dbxout_type (BINFO_TYPE (child), full);
2106                     stabstr_C (',');
2107                     stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2108                                      * BITS_PER_UNIT);
2109                     stabstr_C (',');
2110                     stabstr_D
2111                       (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2112                        * BITS_PER_UNIT);
2113                     stabstr_C (';');
2114                   }
2115               }
2116           }
2117       }
2118
2119       /* Write out the field declarations.  */
2120       dbxout_type_fields (type);
2121       if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2122         {
2123           dbxout_type_methods (type);
2124         }
2125
2126       stabstr_C (';');
2127
2128       if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2129           /* Avoid the ~ if we don't really need it--it confuses dbx.  */
2130           && TYPE_VFIELD (type))
2131         {
2132
2133           /* We need to write out info about what field this class
2134              uses as its "main" vtable pointer field, because if this
2135              field is inherited from a base class, GDB cannot necessarily
2136              figure out which field it's using in time.  */
2137           stabstr_S ("~%");
2138           dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2139           stabstr_C (';');
2140         }
2141       break;
2142
2143     case ENUMERAL_TYPE:
2144       /* We must use the same test here as we use in the DBX_NO_XREFS case
2145          above.  We simplify it a bit since an enum will never have a variable
2146          size.  */
2147       if ((TYPE_NAME (type) != 0
2148            && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2149                  && DECL_IGNORED_P (TYPE_NAME (type)))
2150            && !full)
2151           || !COMPLETE_TYPE_P (type))
2152         {
2153           stabstr_S ("xe");
2154           dbxout_type_name (type);
2155           typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2156           stabstr_C (':');
2157           return;
2158         }
2159       if (use_gnu_debug_info_extensions
2160           && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2161         {
2162           stabstr_S ("@s");
2163           stabstr_D (TYPE_PRECISION (type));
2164           stabstr_C (';');
2165         }
2166
2167       stabstr_C ('e');
2168       for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2169         {
2170           stabstr_I (TREE_PURPOSE (tem));
2171           stabstr_C (':');
2172
2173           if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
2174             stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2175           else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
2176                    && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
2177             stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2178           else
2179             stabstr_O (TREE_VALUE (tem));
2180
2181           stabstr_C (',');
2182           if (TREE_CHAIN (tem) != 0)
2183             CONTIN;
2184         }
2185
2186       stabstr_C (';');
2187       break;
2188
2189     case POINTER_TYPE:
2190       stabstr_C ('*');
2191       dbxout_type (TREE_TYPE (type), 0);
2192       break;
2193
2194     case METHOD_TYPE:
2195       if (use_gnu_debug_info_extensions)
2196         {
2197           stabstr_C ('#');
2198
2199           /* Write the argument types out longhand.  */
2200           dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2201           stabstr_C (',');
2202           dbxout_type (TREE_TYPE (type), 0);
2203           dbxout_args (TYPE_ARG_TYPES (type));
2204           stabstr_C (';');
2205         }
2206       else
2207         /* Treat it as a function type.  */
2208         dbxout_type (TREE_TYPE (type), 0);
2209       break;
2210
2211     case OFFSET_TYPE:
2212       if (use_gnu_debug_info_extensions)
2213         {
2214           stabstr_C ('@');
2215           dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2216           stabstr_C (',');
2217           dbxout_type (TREE_TYPE (type), 0);
2218         }
2219       else
2220         /* Should print as an int, because it is really just an offset.  */
2221         dbxout_type (integer_type_node, 0);
2222       break;
2223
2224     case REFERENCE_TYPE:
2225       if (use_gnu_debug_info_extensions)
2226         {
2227           stabstr_C ('&');
2228         }
2229       else
2230         stabstr_C ('*');
2231       dbxout_type (TREE_TYPE (type), 0);
2232       break;
2233
2234     case FUNCTION_TYPE:
2235       stabstr_C ('f');
2236       dbxout_type (TREE_TYPE (type), 0);
2237       break;
2238
2239     default:
2240       gcc_unreachable ();
2241     }
2242 }
2243
2244 /* Return nonzero if the given type represents an integer whose bounds
2245    should be printed in octal format.  */
2246
2247 static bool
2248 print_int_cst_bounds_in_octal_p (tree type)
2249 {
2250   /* If we can use GDB extensions and the size is wider than a long
2251      (the size used by GDB to read them) or we may have trouble writing
2252      the bounds the usual way, write them in octal.  Note the test is for
2253      the *target's* size of "long", not that of the host.  The host test
2254      is just to make sure we can write it out in case the host wide int
2255      is narrower than the target "long".
2256
2257      For unsigned types, we use octal if they are the same size or larger.
2258      This is because we print the bounds as signed decimal, and hence they
2259      can't span same size unsigned types.  */
2260
2261   if (use_gnu_debug_info_extensions
2262       && TYPE_MIN_VALUE (type) != 0
2263       && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
2264       && TYPE_MAX_VALUE (type) != 0
2265       && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
2266       && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2267           || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2268               && TYPE_UNSIGNED (type))
2269           || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2270           || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2271               && TYPE_UNSIGNED (type))))
2272     return TRUE;
2273   else
2274     return FALSE;
2275 }
2276
2277 /* Output the name of type TYPE, with no punctuation.
2278    Such names can be set up either by typedef declarations
2279    or by struct, enum and union tags.  */
2280
2281 static void
2282 dbxout_type_name (tree type)
2283 {
2284   tree t = TYPE_NAME (type);
2285   
2286   gcc_assert (t);
2287   switch (TREE_CODE (t))
2288     {
2289     case IDENTIFIER_NODE:
2290       break;
2291     case TYPE_DECL:
2292       t = DECL_NAME (t);
2293       break;
2294     default:
2295       gcc_unreachable ();
2296     }
2297
2298   stabstr_I (t);
2299 }
2300
2301 /* Output leading leading struct or class names needed for qualifying
2302    type whose scope is limited to a struct or class.  */
2303
2304 static void
2305 dbxout_class_name_qualifiers (tree decl)
2306 {
2307   tree context = decl_type_context (decl);
2308
2309   if (context != NULL_TREE
2310       && TREE_CODE(context) == RECORD_TYPE
2311       && TYPE_NAME (context) != 0
2312       && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2313           || (DECL_NAME (TYPE_NAME (context)) != 0)))
2314     {
2315       tree name = TYPE_NAME (context);
2316
2317       if (TREE_CODE (name) == TYPE_DECL)
2318         {
2319           dbxout_class_name_qualifiers (name);
2320           name = DECL_NAME (name);
2321         }
2322       stabstr_I (name);
2323       stabstr_S ("::");
2324     }
2325 }
2326 \f
2327 /* Output a .stabs for the symbol defined by DECL,
2328    which must be a ..._DECL node in the normal namespace.
2329    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2330    LOCAL is nonzero if the scope is less than the entire file.
2331    Return 1 if a stabs might have been emitted.  */
2332
2333 int
2334 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2335 {
2336   tree type = TREE_TYPE (decl);
2337   tree context = NULL_TREE;
2338   int result = 0;
2339
2340   /* "Intercept" dbxout_symbol() calls like we do all debug_hooks.  */
2341   ++debug_nesting;
2342
2343   /* Ignore nameless syms, but don't ignore type tags.  */
2344
2345   if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2346       || DECL_IGNORED_P (decl))
2347     DBXOUT_DECR_NESTING_AND_RETURN (0);
2348
2349   /* If we are to generate only the symbols actually used then such
2350      symbol nodes are flagged with TREE_USED.  Ignore any that
2351      aren't flaged as TREE_USED.  */
2352
2353   if (flag_debug_only_used_symbols
2354       && (!TREE_USED (decl)
2355           && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2356     DBXOUT_DECR_NESTING_AND_RETURN (0);
2357
2358   /* If dbxout_init has not yet run, queue this symbol for later.  */
2359   if (!typevec)
2360     {
2361       preinit_symbols = tree_cons (0, decl, preinit_symbols);
2362       DBXOUT_DECR_NESTING_AND_RETURN (0);
2363     }
2364
2365   if (flag_debug_only_used_symbols)
2366     {
2367       tree t;
2368
2369       /* We now have a used symbol.  We need to generate the info for
2370          the symbol's type in addition to the symbol itself.  These
2371          type symbols are queued to be generated after were done with
2372          the symbol itself (otherwise they would fight over the
2373          stabstr obstack).
2374
2375          Note, because the TREE_TYPE(type) might be something like a
2376          pointer to a named type we need to look for the first name
2377          we see following the TREE_TYPE chain.  */
2378
2379       t = type;
2380       while (POINTER_TYPE_P (t))
2381         t = TREE_TYPE (t);
2382
2383       /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2384          need special treatment.  The TYPE_STUB_DECL field in these
2385          types generally represents the tag name type we want to
2386          output.  In addition there  could be a typedef type with
2387          a different name.  In that case we also want to output
2388          that.  */
2389
2390       if (TREE_CODE (t) == RECORD_TYPE
2391            || TREE_CODE (t) == UNION_TYPE
2392            || TREE_CODE (t) == QUAL_UNION_TYPE
2393            || TREE_CODE (t) == ENUMERAL_TYPE)
2394         {
2395             if (TYPE_STUB_DECL (t)
2396                 && TYPE_STUB_DECL (t) != decl
2397                 && DECL_P (TYPE_STUB_DECL (t))
2398                 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2399             {
2400               debug_queue_symbol (TYPE_STUB_DECL (t));
2401               if (TYPE_NAME (t)
2402                   && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2403                   && TYPE_NAME (t) != decl
2404                   && DECL_P (TYPE_NAME (t)))
2405                 debug_queue_symbol (TYPE_NAME (t));
2406             }
2407         }
2408       else if (TYPE_NAME (t)
2409                && TYPE_NAME (t) != decl
2410                && DECL_P (TYPE_NAME (t)))
2411         debug_queue_symbol (TYPE_NAME (t));
2412     }
2413
2414   emit_pending_bincls_if_required ();
2415
2416   switch (TREE_CODE (decl))
2417     {
2418     case CONST_DECL:
2419       /* Enum values are defined by defining the enum type.  */
2420       break;
2421
2422     case FUNCTION_DECL:
2423       if (DECL_RTL (decl) == 0)
2424         DBXOUT_DECR_NESTING_AND_RETURN (0);
2425       if (DECL_EXTERNAL (decl))
2426         break;
2427       /* Don't mention a nested function under its parent.  */
2428       context = decl_function_context (decl);
2429       if (context == current_function_decl)
2430         break;
2431       /* Don't mention an inline instance of a nested function.  */
2432       if (context && DECL_FROM_INLINE (decl))
2433         break;
2434       if (!MEM_P (DECL_RTL (decl))
2435           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2436         break;
2437
2438       dbxout_begin_complex_stabs ();
2439       stabstr_I (DECL_ASSEMBLER_NAME (decl));
2440       stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2441       result = 1;
2442
2443       if (TREE_TYPE (type))
2444         dbxout_type (TREE_TYPE (type), 0);
2445       else
2446         dbxout_type (void_type_node, 0);
2447
2448       /* For a nested function, when that function is compiled,
2449          mention the containing function name
2450          as well as (since dbx wants it) our own assembler-name.  */
2451       if (context != 0)
2452         {
2453           stabstr_C (',');
2454           stabstr_I (DECL_ASSEMBLER_NAME (decl));
2455           stabstr_C (',');
2456           stabstr_I (DECL_NAME (context));
2457         }
2458
2459       dbxout_finish_complex_stabs (decl, N_FUN, XEXP (DECL_RTL (decl), 0),
2460                                    0, 0);
2461       break;
2462
2463     case TYPE_DECL:
2464       /* Don't output the same typedef twice.
2465          And don't output what language-specific stuff doesn't want output.  */
2466       if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2467         DBXOUT_DECR_NESTING_AND_RETURN (0);
2468
2469       /* Don't output typedefs for types with magic type numbers (XCOFF).  */
2470 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2471       {
2472         int fundamental_type_number =
2473           DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2474
2475         if (fundamental_type_number != 0)
2476           {
2477             TREE_ASM_WRITTEN (decl) = 1;
2478             TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2479             DBXOUT_DECR_NESTING_AND_RETURN (0);
2480           }
2481       }
2482 #endif
2483       FORCE_TEXT;
2484       result = 1;
2485       {
2486         int tag_needed = 1;
2487         int did_output = 0;
2488
2489         if (DECL_NAME (decl))
2490           {
2491             /* Nonzero means we must output a tag as well as a typedef.  */
2492             tag_needed = 0;
2493
2494             /* Handle the case of a C++ structure or union
2495                where the TYPE_NAME is a TYPE_DECL
2496                which gives both a typedef name and a tag.  */
2497             /* dbx requires the tag first and the typedef second.  */
2498             if ((TREE_CODE (type) == RECORD_TYPE
2499                  || TREE_CODE (type) == UNION_TYPE
2500                  || TREE_CODE (type) == QUAL_UNION_TYPE)
2501                 && TYPE_NAME (type) == decl
2502                 && !use_gnu_debug_info_extensions
2503                 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2504                 /* Distinguish the implicit typedefs of C++
2505                    from explicit ones that might be found in C.  */
2506                 && DECL_ARTIFICIAL (decl)
2507                 /* Do not generate a tag for incomplete records.  */
2508                 && COMPLETE_TYPE_P (type)
2509                 /* Do not generate a tag for records of variable size,
2510                    since this type can not be properly described in the
2511                    DBX format, and it confuses some tools such as objdump.  */
2512                 && host_integerp (TYPE_SIZE (type), 1))
2513               {
2514                 tree name = TYPE_NAME (type);
2515                 if (TREE_CODE (name) == TYPE_DECL)
2516                   name = DECL_NAME (name);
2517
2518                 dbxout_begin_complex_stabs ();
2519                 stabstr_I (name);
2520                 stabstr_S (":T");
2521                 dbxout_type (type, 1);
2522                 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2523                                              0, 0, 0);
2524               }
2525
2526             dbxout_begin_complex_stabs ();
2527
2528             /* Output leading class/struct qualifiers.  */
2529             if (use_gnu_debug_info_extensions)
2530               dbxout_class_name_qualifiers (decl);
2531
2532             /* Output typedef name.  */
2533             stabstr_I (DECL_NAME (decl));
2534             stabstr_C (':');
2535
2536             /* Short cut way to output a tag also.  */
2537             if ((TREE_CODE (type) == RECORD_TYPE
2538                  || TREE_CODE (type) == UNION_TYPE
2539                  || TREE_CODE (type) == QUAL_UNION_TYPE)
2540                 && TYPE_NAME (type) == decl
2541                 /* Distinguish the implicit typedefs of C++
2542                    from explicit ones that might be found in C.  */
2543                 && DECL_ARTIFICIAL (decl))
2544               {
2545                 if (use_gnu_debug_info_extensions)
2546                   {
2547                     stabstr_C ('T');
2548                     TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2549                   }
2550               }
2551
2552             stabstr_C ('t');
2553             dbxout_type (type, 1);
2554             dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2555                                          0, 0, 0);
2556             did_output = 1;
2557           }
2558
2559         /* Don't output a tag if this is an incomplete type.  This prevents
2560            the sun4 Sun OS 4.x dbx from crashing.  */
2561
2562         if (tag_needed && TYPE_NAME (type) != 0
2563             && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2564                 || (DECL_NAME (TYPE_NAME (type)) != 0))
2565             && COMPLETE_TYPE_P (type)
2566             && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2567           {
2568             /* For a TYPE_DECL with no name, but the type has a name,
2569                output a tag.
2570                This is what represents `struct foo' with no typedef.  */
2571             /* In C++, the name of a type is the corresponding typedef.
2572                In C, it is an IDENTIFIER_NODE.  */
2573             tree name = TYPE_NAME (type);
2574             if (TREE_CODE (name) == TYPE_DECL)
2575               name = DECL_NAME (name);
2576
2577             dbxout_begin_complex_stabs ();
2578             stabstr_I (name);
2579             stabstr_S (":T");
2580             dbxout_type (type, 1);
2581             dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2582             did_output = 1;
2583           }
2584
2585         /* If an enum type has no name, it cannot be referred to, but
2586            we must output it anyway, to record the enumeration
2587            constants.  */
2588
2589         if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2590           {
2591             dbxout_begin_complex_stabs ();
2592             /* Some debuggers fail when given NULL names, so give this a
2593                harmless name of " " (Why not "(anon)"?).  */
2594             stabstr_S (" :T");
2595             dbxout_type (type, 1);
2596             dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2597           }
2598
2599         /* Prevent duplicate output of a typedef.  */
2600         TREE_ASM_WRITTEN (decl) = 1;
2601         break;
2602       }
2603
2604     case PARM_DECL:
2605       /* Parm decls go in their own separate chains
2606          and are output by dbxout_reg_parms and dbxout_parms.  */
2607       gcc_unreachable ();
2608
2609     case RESULT_DECL:
2610       /* Named return value, treat like a VAR_DECL.  */
2611     case VAR_DECL:
2612       if (! DECL_RTL_SET_P (decl))
2613         DBXOUT_DECR_NESTING_AND_RETURN (0);
2614       /* Don't mention a variable that is external.
2615          Let the file that defines it describe it.  */
2616       if (DECL_EXTERNAL (decl))
2617         break;
2618
2619       /* If the variable is really a constant
2620          and not written in memory, inform the debugger.
2621
2622          ??? Why do we skip emitting the type and location in this case?  */
2623       if (TREE_STATIC (decl) && TREE_READONLY (decl)
2624           && DECL_INITIAL (decl) != 0
2625           && host_integerp (DECL_INITIAL (decl), 0)
2626           && ! TREE_ASM_WRITTEN (decl)
2627           && (DECL_CONTEXT (decl) == NULL_TREE
2628               || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK)
2629           && TREE_PUBLIC (decl) == 0)
2630         {
2631           /* The sun4 assembler does not grok this.  */
2632
2633           if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2634               || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2635             {
2636               HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
2637
2638               dbxout_begin_complex_stabs ();
2639               stabstr_I (DECL_NAME (decl));
2640               stabstr_S (":c=i");
2641               stabstr_D (ival);
2642               dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2643               DBXOUT_DECR_NESTING;
2644               return 1;
2645             }
2646           else
2647             break;
2648         }
2649       /* else it is something we handle like a normal variable.  */
2650
2651       SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2652 #ifdef LEAF_REG_REMAP
2653       if (current_function_uses_only_leaf_regs)
2654         leaf_renumber_regs_insn (DECL_RTL (decl));
2655 #endif
2656
2657       result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2658       break;
2659
2660     default:
2661       break;
2662     }
2663   DBXOUT_DECR_NESTING;
2664   return result;
2665 }
2666 \f
2667 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2668    Add SUFFIX to its name, if SUFFIX is not 0.
2669    Describe the variable as residing in HOME
2670    (usually HOME is DECL_RTL (DECL), but not always).
2671    Returns 1 if the stab was really emitted.  */
2672
2673 static int
2674 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2675 {
2676   int letter = 0;
2677   STAB_CODE_TYPE code;
2678   rtx addr = 0;
2679   int number = 0;
2680   int regno = -1;
2681
2682   /* Don't mention a variable at all
2683      if it was completely optimized into nothingness.
2684
2685      If the decl was from an inline function, then its rtl
2686      is not identically the rtl that was used in this
2687      particular compilation.  */
2688   if (GET_CODE (home) == SUBREG)
2689     {
2690       rtx value = home;
2691
2692       while (GET_CODE (value) == SUBREG)
2693         value = SUBREG_REG (value);
2694       if (REG_P (value))
2695         {
2696           if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2697             return 0;
2698         }
2699       home = alter_subreg (&home);
2700     }
2701   if (REG_P (home))
2702     {
2703       regno = REGNO (home);
2704       if (regno >= FIRST_PSEUDO_REGISTER)
2705         return 0;
2706     }
2707
2708   /* The kind-of-variable letter depends on where
2709      the variable is and on the scope of its name:
2710      G and N_GSYM for static storage and global scope,
2711      S for static storage and file scope,
2712      V for static storage and local scope,
2713      for those two, use N_LCSYM if data is in bss segment,
2714      N_STSYM if in data segment, N_FUN otherwise.
2715      (We used N_FUN originally, then changed to N_STSYM
2716      to please GDB.  However, it seems that confused ld.
2717      Now GDB has been fixed to like N_FUN, says Kingdon.)
2718      no letter at all, and N_LSYM, for auto variable,
2719      r and N_RSYM for register variable.  */
2720
2721   if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2722     {
2723       if (TREE_PUBLIC (decl))
2724         {
2725           letter = 'G';
2726           code = N_GSYM;
2727         }
2728       else
2729         {
2730           addr = XEXP (home, 0);
2731
2732           letter = decl_function_context (decl) ? 'V' : 'S';
2733
2734           /* Some ports can transform a symbol ref into a label ref,
2735              because the symbol ref is too far away and has to be
2736              dumped into a constant pool.  Alternatively, the symbol
2737              in the constant pool might be referenced by a different
2738              symbol.  */
2739           if (GET_CODE (addr) == SYMBOL_REF
2740               && CONSTANT_POOL_ADDRESS_P (addr))
2741             {
2742               bool marked;
2743               rtx tmp = get_pool_constant_mark (addr, &marked);
2744
2745               if (GET_CODE (tmp) == SYMBOL_REF)
2746                 {
2747                   addr = tmp;
2748                   if (CONSTANT_POOL_ADDRESS_P (addr))
2749                     get_pool_constant_mark (addr, &marked);
2750                   else
2751                     marked = true;
2752                 }
2753               else if (GET_CODE (tmp) == LABEL_REF)
2754                 {
2755                   addr = tmp;
2756                   marked = true;
2757                 }
2758
2759               /* If all references to the constant pool were optimized
2760                  out, we just ignore the symbol.  */
2761               if (!marked)
2762                 return 0;
2763             }
2764
2765           /* This should be the same condition as in assemble_variable, but
2766              we don't have access to dont_output_data here.  So, instead,
2767              we rely on the fact that error_mark_node initializers always
2768              end up in bss for C++ and never end up in bss for C.  */
2769           if (DECL_INITIAL (decl) == 0
2770               || (!strcmp (lang_hooks.name, "GNU C++")
2771                   && DECL_INITIAL (decl) == error_mark_node))
2772             code = N_LCSYM;
2773           else if (DECL_IN_TEXT_SECTION (decl))
2774             /* This is not quite right, but it's the closest
2775                of all the codes that Unix defines.  */
2776             code = DBX_STATIC_CONST_VAR_CODE;
2777           else
2778             {
2779               /* Ultrix `as' seems to need this.  */
2780 #ifdef DBX_STATIC_STAB_DATA_SECTION
2781               data_section ();
2782 #endif
2783               code = N_STSYM;
2784             }
2785         }
2786     }
2787   else if (regno >= 0)
2788     {
2789       letter = 'r';
2790       code = N_RSYM;
2791       number = DBX_REGISTER_NUMBER (regno);
2792     }
2793   else if (MEM_P (home)
2794            && (MEM_P (XEXP (home, 0))
2795                || (REG_P (XEXP (home, 0))
2796                    && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2797                    && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2798 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2799                    && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2800 #endif
2801                    )))
2802     /* If the value is indirect by memory or by a register
2803        that isn't the frame pointer
2804        then it means the object is variable-sized and address through
2805        that register or stack slot.  DBX has no way to represent this
2806        so all we can do is output the variable as a pointer.
2807        If it's not a parameter, ignore it.  */
2808     {
2809       if (REG_P (XEXP (home, 0)))
2810         {
2811           letter = 'r';
2812           code = N_RSYM;
2813           if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2814             return 0;
2815           number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2816         }
2817       else
2818         {
2819           code = N_LSYM;
2820           /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2821              We want the value of that CONST_INT.  */
2822           number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2823         }
2824
2825       /* Effectively do build_pointer_type, but don't cache this type,
2826          since it might be temporary whereas the type it points to
2827          might have been saved for inlining.  */
2828       /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
2829       type = make_node (POINTER_TYPE);
2830       TREE_TYPE (type) = TREE_TYPE (decl);
2831     }
2832   else if (MEM_P (home)
2833            && REG_P (XEXP (home, 0)))
2834     {
2835       code = N_LSYM;
2836       number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2837     }
2838   else if (MEM_P (home)
2839            && GET_CODE (XEXP (home, 0)) == PLUS
2840            && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2841     {
2842       code = N_LSYM;
2843       /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2844          We want the value of that CONST_INT.  */
2845       number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2846     }
2847   else if (MEM_P (home)
2848            && GET_CODE (XEXP (home, 0)) == CONST)
2849     {
2850       /* Handle an obscure case which can arise when optimizing and
2851          when there are few available registers.  (This is *always*
2852          the case for i386/i486 targets).  The RTL looks like
2853          (MEM (CONST ...)) even though this variable is a local `auto'
2854          or a local `register' variable.  In effect, what has happened
2855          is that the reload pass has seen that all assignments and
2856          references for one such a local variable can be replaced by
2857          equivalent assignments and references to some static storage
2858          variable, thereby avoiding the need for a register.  In such
2859          cases we're forced to lie to debuggers and tell them that
2860          this variable was itself `static'.  */
2861       code = N_LCSYM;
2862       letter = 'V';
2863       addr = XEXP (XEXP (home, 0), 0);
2864     }
2865   else if (GET_CODE (home) == CONCAT)
2866     {
2867       tree subtype;
2868
2869       /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2870          for example), then there is no easy way to figure out
2871          what SUBTYPE should be.  So, we give up.  */
2872       if (TREE_CODE (type) != COMPLEX_TYPE)
2873         return 0;
2874
2875       subtype = TREE_TYPE (type);
2876
2877       /* If the variable's storage is in two parts,
2878          output each as a separate stab with a modified name.  */
2879       if (WORDS_BIG_ENDIAN)
2880         dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2881       else
2882         dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2883
2884       if (WORDS_BIG_ENDIAN)
2885         dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2886       else
2887         dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2888       return 1;
2889     }
2890   else
2891     /* Address might be a MEM, when DECL is a variable-sized object.
2892        Or it might be const0_rtx, meaning previous passes
2893        want us to ignore this variable.  */
2894     return 0;
2895
2896   /* Ok, start a symtab entry and output the variable name.  */
2897   emit_pending_bincls_if_required ();
2898   FORCE_TEXT;
2899
2900 #ifdef DBX_STATIC_BLOCK_START
2901   DBX_STATIC_BLOCK_START (asm_out_file, code);
2902 #endif
2903
2904   dbxout_begin_complex_stabs_noforcetext ();
2905   dbxout_symbol_name (decl, suffix, letter);
2906   dbxout_type (type, 0);
2907   dbxout_finish_complex_stabs (decl, code, addr, 0, number);
2908
2909 #ifdef DBX_STATIC_BLOCK_END
2910   DBX_STATIC_BLOCK_END (asm_out_file, code);
2911 #endif
2912   return 1;
2913 }
2914 \f
2915 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2916    Then output LETTER to indicate the kind of location the symbol has.  */
2917
2918 static void
2919 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2920 {
2921   tree name;
2922
2923   if (DECL_CONTEXT (decl) 
2924       && (TYPE_P (DECL_CONTEXT (decl))
2925           || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
2926     /* One slight hitch: if this is a VAR_DECL which is a class member
2927        or a namespace member, we must put out the mangled name instead of the
2928        DECL_NAME.  Note also that static member (variable) names DO NOT begin
2929        with underscores in .stabs directives.  */
2930     name = DECL_ASSEMBLER_NAME (decl);
2931   else
2932     /* ...but if we're function-local, we don't want to include the junk
2933        added by ASM_FORMAT_PRIVATE_NAME.  */
2934     name = DECL_NAME (decl);
2935
2936   if (name)
2937     stabstr_I (name);
2938   else
2939     stabstr_S ("(anon)");
2940
2941   if (suffix)
2942     stabstr_S (suffix);
2943   stabstr_C (':');
2944   if (letter)
2945     stabstr_C (letter);
2946 }
2947
2948 /* Output definitions of all the decls in a chain. Return nonzero if
2949    anything was output */
2950
2951 int
2952 dbxout_syms (tree syms)
2953 {
2954   int result = 0;
2955   while (syms)
2956     {
2957       result += dbxout_symbol (syms, 1);
2958       syms = TREE_CHAIN (syms);
2959     }
2960   return result;
2961 }
2962 \f
2963 /* The following two functions output definitions of function parameters.
2964    Each parameter gets a definition locating it in the parameter list.
2965    Each parameter that is a register variable gets a second definition
2966    locating it in the register.
2967
2968    Printing or argument lists in gdb uses the definitions that
2969    locate in the parameter list.  But reference to the variable in
2970    expressions uses preferentially the definition as a register.  */
2971
2972 /* Output definitions, referring to storage in the parmlist,
2973    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
2974
2975 void
2976 dbxout_parms (tree parms)
2977 {
2978   ++debug_nesting;
2979   emit_pending_bincls_if_required ();
2980
2981   for (; parms; parms = TREE_CHAIN (parms))
2982     if (DECL_NAME (parms)
2983         && TREE_TYPE (parms) != error_mark_node
2984         && DECL_RTL_SET_P (parms)
2985         && DECL_INCOMING_RTL (parms))
2986       {
2987         tree eff_type;
2988         char letter;
2989         STAB_CODE_TYPE code;
2990         int number;
2991
2992         /* Perform any necessary register eliminations on the parameter's rtl,
2993            so that the debugging output will be accurate.  */
2994         DECL_INCOMING_RTL (parms)
2995           = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2996         SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2997 #ifdef LEAF_REG_REMAP
2998         if (current_function_uses_only_leaf_regs)
2999           {
3000             leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3001             leaf_renumber_regs_insn (DECL_RTL (parms));
3002           }
3003 #endif
3004
3005         if (PARM_PASSED_IN_MEMORY (parms))
3006           {
3007             rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3008
3009             /* ??? Here we assume that the parm address is indexed
3010                off the frame pointer or arg pointer.
3011                If that is not true, we produce meaningless results,
3012                but do not crash.  */
3013             if (GET_CODE (inrtl) == PLUS
3014                 && GET_CODE (XEXP (inrtl, 1)) == CONST_INT)
3015               number = INTVAL (XEXP (inrtl, 1));
3016             else
3017               number = 0;
3018
3019             code = N_PSYM;
3020             number = DEBUGGER_ARG_OFFSET (number, inrtl);
3021             letter = 'p';
3022
3023             /* It is quite tempting to use TREE_TYPE (parms) instead
3024                of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3025                reports the actual type of the parameter, rather than
3026                the promoted type.  This certainly makes GDB's life
3027                easier, at least for some ports.  The change is a bad
3028                idea however, since GDB expects to be able access the
3029                type without performing any conversions.  So for
3030                example, if we were passing a float to an unprototyped
3031                function, gcc will store a double on the stack, but if
3032                we emit a stab saying the type is a float, then gdb
3033                will only read in a single value, and this will produce
3034                an erroneous value.  */
3035             eff_type = DECL_ARG_TYPE (parms);
3036           }
3037         else if (REG_P (DECL_RTL (parms)))
3038           {
3039             rtx best_rtl;
3040
3041             /* Parm passed in registers and lives in registers or nowhere.  */
3042             code = DBX_REGPARM_STABS_CODE;
3043             letter = DBX_REGPARM_STABS_LETTER;
3044
3045             /* For parms passed in registers, it is better to use the
3046                declared type of the variable, not the type it arrived in.  */
3047             eff_type = TREE_TYPE (parms);
3048
3049             /* If parm lives in a register, use that register; pretend
3050                the parm was passed there.  It would be more consistent
3051                to describe the register where the parm was passed, but
3052                in practice that register usually holds something else.
3053                If the parm lives nowhere, use the register where it
3054                was passed.  */
3055             if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3056               best_rtl = DECL_RTL (parms);
3057             else
3058               best_rtl = DECL_INCOMING_RTL (parms);
3059
3060             number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3061           }
3062         else if (MEM_P (DECL_RTL (parms))
3063                  && REG_P (XEXP (DECL_RTL (parms), 0))
3064                  && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3065                  && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3066 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3067                  && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3068 #endif
3069                  )
3070           {
3071             /* Parm was passed via invisible reference.
3072                That is, its address was passed in a register.
3073                Output it as if it lived in that register.
3074                The debugger will know from the type
3075                that it was actually passed by invisible reference.  */
3076
3077             code = DBX_REGPARM_STABS_CODE;
3078  
3079             /* GDB likes this marked with a special letter.  */
3080             letter = (use_gnu_debug_info_extensions
3081                       ? 'a' : DBX_REGPARM_STABS_LETTER);
3082             eff_type = TREE_TYPE (parms);
3083
3084             /* DECL_RTL looks like (MEM (REG...).  Get the register number.
3085                If it is an unallocated pseudo-reg, then use the register where
3086                it was passed instead.
3087                ??? Why is DBX_REGISTER_NUMBER not used here?  */
3088
3089             if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3090               number = REGNO (XEXP (DECL_RTL (parms), 0));
3091             else
3092               number = REGNO (DECL_INCOMING_RTL (parms));
3093           }
3094         else if (MEM_P (DECL_RTL (parms))
3095                  && MEM_P (XEXP (DECL_RTL (parms), 0)))
3096           {
3097             /* Parm was passed via invisible reference, with the reference
3098                living on the stack.  DECL_RTL looks like
3099                (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3100                could look like (MEM (MEM (REG))).  */
3101
3102             code = N_PSYM;
3103             letter = 'v';
3104             eff_type = TREE_TYPE (parms);
3105
3106             if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3107               number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3108             else
3109               number = 0;
3110
3111             number = DEBUGGER_ARG_OFFSET (number,
3112                                           XEXP (XEXP (DECL_RTL (parms), 0), 0));
3113           }
3114         else if (MEM_P (DECL_RTL (parms))
3115                  && XEXP (DECL_RTL (parms), 0) != const0_rtx
3116                  /* ??? A constant address for a parm can happen
3117                     when the reg it lives in is equiv to a constant in memory.
3118                     Should make this not happen, after 2.4.  */
3119                  && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3120           {
3121             /* Parm was passed in registers but lives on the stack.  */
3122
3123             code = N_PSYM;
3124             letter = 'p';
3125             eff_type = TREE_TYPE (parms);
3126
3127             /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3128                in which case we want the value of that CONST_INT,
3129                or (MEM (REG ...)),
3130                in which case we use a value of zero.  */
3131             if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3132               number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3133             else
3134               number = 0;
3135
3136             /* Make a big endian correction if the mode of the type of the
3137                parameter is not the same as the mode of the rtl.  */
3138             if (BYTES_BIG_ENDIAN
3139                 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3140                 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3141               number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3142                          - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3143           }
3144         else
3145           /* ??? We don't know how to represent this argument.  */
3146           continue;
3147
3148         dbxout_begin_complex_stabs ();
3149             
3150         if (DECL_NAME (parms))
3151           {
3152             stabstr_I (DECL_NAME (parms));
3153             stabstr_C (':');
3154           }
3155         else
3156           stabstr_S ("(anon):");
3157         stabstr_C (letter);
3158         dbxout_type (eff_type, 0);
3159         dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3160       }
3161   DBXOUT_DECR_NESTING;
3162 }
3163
3164 /* Output definitions for the places where parms live during the function,
3165    when different from where they were passed, when the parms were passed
3166    in memory.
3167
3168    It is not useful to do this for parms passed in registers
3169    that live during the function in different registers, because it is
3170    impossible to look in the passed register for the passed value,
3171    so we use the within-the-function register to begin with.
3172
3173    PARMS is a chain of PARM_DECL nodes.  */
3174
3175 void
3176 dbxout_reg_parms (tree parms)
3177 {
3178   ++debug_nesting;
3179
3180   for (; parms; parms = TREE_CHAIN (parms))
3181     if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3182       {
3183         /* Report parms that live in registers during the function
3184            but were passed in memory.  */
3185         if (REG_P (DECL_RTL (parms))
3186             && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3187           dbxout_symbol_location (parms, TREE_TYPE (parms),
3188                                   0, DECL_RTL (parms));
3189         else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3190           dbxout_symbol_location (parms, TREE_TYPE (parms),
3191                                   0, DECL_RTL (parms));
3192         /* Report parms that live in memory but not where they were passed.  */
3193         else if (MEM_P (DECL_RTL (parms))
3194                  && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3195           dbxout_symbol_location (parms, TREE_TYPE (parms),
3196                                   0, DECL_RTL (parms));
3197       }
3198   DBXOUT_DECR_NESTING;
3199 }
3200 \f
3201 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3202    output definitions of those names, in raw form */
3203
3204 static void
3205 dbxout_args (tree args)
3206 {
3207   while (args)
3208     {
3209       stabstr_C (',');
3210       dbxout_type (TREE_VALUE (args), 0);
3211       args = TREE_CHAIN (args);
3212     }
3213 }
3214 \f
3215 /* Subroutine of dbxout_block.  Emit an N_LBRAC stab referencing LABEL.
3216    BEGIN_LABEL is the name of the beginning of the function, which may
3217    be required.  */
3218 static void
3219 dbx_output_lbrac (const char *label,
3220                   const char *begin_label ATTRIBUTE_UNUSED)
3221 {
3222 #ifdef DBX_OUTPUT_LBRAC
3223   DBX_OUTPUT_LBRAC (asm_out_file, label);
3224 #else
3225   dbxout_begin_stabn (N_LBRAC);
3226   if (DBX_BLOCKS_FUNCTION_RELATIVE)
3227     dbxout_stab_value_label_diff (label, begin_label);
3228   else
3229     dbxout_stab_value_label (label);
3230 #endif
3231 }
3232
3233 /* Subroutine of dbxout_block.  Emit an N_RBRAC stab referencing LABEL.
3234    BEGIN_LABEL is the name of the beginning of the function, which may
3235    be required.  */
3236 static void
3237 dbx_output_rbrac (const char *label,
3238                   const char *begin_label ATTRIBUTE_UNUSED)
3239 {
3240 #ifdef DBX_OUTPUT_RBRAC
3241   DBX_OUTPUT_RBRAC (asm_out_file, label);
3242 #else
3243   dbxout_begin_stabn (N_RBRAC);
3244   if (DBX_BLOCKS_FUNCTION_RELATIVE)
3245     dbxout_stab_value_label_diff (label, begin_label);
3246   else
3247     dbxout_stab_value_label (label);
3248 #endif
3249 }
3250
3251 /* Output everything about a symbol block (a BLOCK node
3252    that represents a scope level),
3253    including recursive output of contained blocks.
3254
3255    BLOCK is the BLOCK node.
3256    DEPTH is its depth within containing symbol blocks.
3257    ARGS is usually zero; but for the outermost block of the
3258    body of a function, it is a chain of PARM_DECLs for the function parameters.
3259    We output definitions of all the register parms
3260    as if they were local variables of that block.
3261
3262    If -g1 was used, we count blocks just the same, but output nothing
3263    except for the outermost block.
3264
3265    Actually, BLOCK may be several blocks chained together.
3266    We handle them all in sequence.  */
3267
3268 static void
3269 dbxout_block (tree block, int depth, tree args)
3270 {
3271   const char *begin_label
3272     = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3273
3274   while (block)
3275     {
3276       /* Ignore blocks never expanded or otherwise marked as real.  */
3277       if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3278         {
3279           int did_output;
3280           int blocknum = BLOCK_NUMBER (block);
3281
3282           /* In dbx format, the syms of a block come before the N_LBRAC.
3283              If nothing is output, we don't need the N_LBRAC, either.  */
3284           did_output = 0;
3285           if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3286             did_output = dbxout_syms (BLOCK_VARS (block));
3287           if (args)
3288             dbxout_reg_parms (args);
3289
3290           /* Now output an N_LBRAC symbol to represent the beginning of
3291              the block.  Use the block's tree-walk order to generate
3292              the assembler symbols LBBn and LBEn
3293              that final will define around the code in this block.  */
3294           if (did_output)
3295             {
3296               char buf[20];
3297               const char *scope_start;
3298
3299               if (depth == 0)
3300                 /* The outermost block doesn't get LBB labels; use
3301                    the function symbol.  */
3302                 scope_start = begin_label;
3303               else
3304                 {
3305                   ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3306                   scope_start = buf;
3307                 }
3308
3309               if (BLOCK_HANDLER_BLOCK (block))
3310                 {
3311                   /* A catch block.  Must precede N_LBRAC.  */
3312                   tree decl = BLOCK_VARS (block);
3313                   while (decl)
3314                     {
3315                       dbxout_begin_complex_stabs ();
3316                       stabstr_I (DECL_NAME (decl));
3317                       stabstr_S (":C1");
3318                       dbxout_finish_complex_stabs (0, N_CATCH, 0,
3319                                                    scope_start, 0);
3320                       decl = TREE_CHAIN (decl);
3321                     }
3322                 }
3323               dbx_output_lbrac (scope_start, begin_label);
3324             }
3325
3326           /* Output the subblocks.  */
3327           dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3328
3329           /* Refer to the marker for the end of the block.  */
3330           if (did_output)
3331             {
3332               char buf[100];
3333               if (depth == 0)
3334                 /* The outermost block doesn't get LBE labels;
3335                    use the "scope" label which will be emitted
3336                    by dbxout_function_end.  */
3337                 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3338               else
3339                 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3340
3341               dbx_output_rbrac (buf, begin_label);
3342             }
3343         }
3344       block = BLOCK_CHAIN (block);
3345     }
3346 }
3347
3348 /* Output the information about a function and its arguments and result.
3349    Usually this follows the function's code,
3350    but on some systems, it comes before.  */
3351
3352 #if defined (DBX_DEBUGGING_INFO)
3353 static void
3354 dbxout_begin_function (tree decl)
3355 {
3356   int saved_tree_used1;
3357
3358   if (DECL_IGNORED_P (decl))
3359     return;
3360
3361   saved_tree_used1 = TREE_USED (decl);
3362   TREE_USED (decl) = 1;
3363   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3364     {
3365       int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3366       TREE_USED (DECL_RESULT (decl)) = 1;
3367       dbxout_symbol (decl, 0);
3368       TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3369     }
3370   else
3371     dbxout_symbol (decl, 0);
3372   TREE_USED (decl) = saved_tree_used1;
3373
3374   dbxout_parms (DECL_ARGUMENTS (decl));
3375   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3376     dbxout_symbol (DECL_RESULT (decl), 1);
3377 }
3378 #endif /* DBX_DEBUGGING_INFO */
3379
3380 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3381
3382 #include "gt-dbxout.h"