OSDN Git Service

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