OSDN Git Service

Fix problems with labels with hot/cold partitioning.
[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       struct function *cfun = DECL_STRUCT_FUNCTION (decl);
942
943       dbxout_begin_empty_stabs (N_FUN);
944       dbxout_stab_value_label_diff (cfun->hot_section_end_label, 
945                                     cfun->hot_section_label);
946       dbxout_begin_empty_stabs (N_FUN);
947       dbxout_stab_value_label_diff (cfun->cold_section_end_label, 
948                                     cfun->cold_section_label);
949     }
950   else
951     {
952       dbxout_begin_empty_stabs (N_FUN);
953       dbxout_stab_value_label_diff (lscope_label_name,
954                                     XSTR (XEXP (DECL_RTL (current_function_decl), 
955                                                 0), 0));
956     }
957                                 
958 #endif
959
960   if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
961     dbxout_stabd (N_ENSYM, 0);
962 }
963 #endif /* DBX_DEBUGGING_INFO */
964
965 /* Get lang description for N_SO stab.  */
966 static unsigned int ATTRIBUTE_UNUSED
967 get_lang_number (void)
968 {
969   const char *language_string = lang_hooks.name;
970
971   if (strcmp (language_string, "GNU C") == 0)
972     return N_SO_C;
973   else if (strcmp (language_string, "GNU C++") == 0)
974     return N_SO_CC;
975   else if (strcmp (language_string, "GNU F77") == 0)
976     return N_SO_FORTRAN;
977   else if (strcmp (language_string, "GNU F95") == 0)
978     return N_SO_FORTRAN90; /* CHECKME */
979   else if (strcmp (language_string, "GNU Pascal") == 0)
980     return N_SO_PASCAL;
981   else if (strcmp (language_string, "GNU Objective-C") == 0)
982     return N_SO_OBJC;
983   else
984     return 0;
985
986 }
987
988 /* At the beginning of compilation, start writing the symbol table.
989    Initialize `typevec' and output the standard data types of C.  */
990
991 static void
992 dbxout_init (const char *input_file_name)
993 {
994   char ltext_label_name[100];
995   bool used_ltext_label_name = false;
996   tree syms = lang_hooks.decls.getdecls ();
997
998   typevec_len = 100;
999   typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
1000
1001   /* stabstr_ob contains one string, which will be just fine with
1002      1-byte alignment.  */
1003   obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free);
1004
1005   /* Convert Ltext into the appropriate format for local labels in case
1006      the system doesn't insert underscores in front of user generated
1007      labels.  */
1008   ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
1009
1010   /* Put the current working directory in an N_SO symbol.  */
1011   if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
1012     {
1013       static const char *cwd;
1014
1015       if (!cwd)
1016         {
1017           cwd = get_src_pwd ();
1018           if (cwd[0] == '\0')
1019             cwd = "/";
1020           else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1]))
1021             cwd = concat (cwd, "/", NULL);
1022         }
1023 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
1024       DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd);
1025 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1026       dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ());
1027       dbxout_stab_value_label (ltext_label_name);
1028       used_ltext_label_name = true;
1029 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
1030     }
1031
1032 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
1033   DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, input_file_name);
1034 #else
1035   dbxout_begin_simple_stabs_desc (input_file_name, N_SO, get_lang_number ());
1036   dbxout_stab_value_label (ltext_label_name);
1037   used_ltext_label_name = true;
1038 #endif
1039
1040   if (used_ltext_label_name)
1041     {
1042       text_section ();
1043       targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
1044     }
1045
1046   /* Emit an N_OPT stab to indicate that this file was compiled by GCC.
1047      The string used is historical.  */
1048 #ifndef NO_DBX_GCC_MARKER
1049   dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT);
1050   dbxout_stab_value_zero ();
1051 #endif
1052
1053   base_input_file = lastfile = input_file_name;
1054
1055   next_type_number = 1;
1056
1057 #ifdef DBX_USE_BINCL
1058   current_file = xmalloc (sizeof *current_file);
1059   current_file->next = NULL;
1060   current_file->file_number = 0;
1061   current_file->next_type_number = 1;
1062   next_file_number = 1;
1063   current_file->prev = NULL;
1064   current_file->bincl_status = BINCL_NOT_REQUIRED;
1065   current_file->pending_bincl_name = NULL;
1066 #endif
1067
1068   /* Get all permanent types that have typedef names, and output them
1069      all, except for those already output.  Some language front ends
1070      put these declarations in the top-level scope; some do not;
1071      the latter are responsible for calling debug_hooks->type_decl from
1072      their record_builtin_type function.  */
1073   dbxout_typedefs (syms);
1074
1075   if (preinit_symbols)
1076     {
1077       tree t;
1078       for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1079         dbxout_symbol (TREE_VALUE (t), 0);
1080       preinit_symbols = 0;
1081     }
1082 }
1083
1084 /* Output any typedef names for types described by TYPE_DECLs in SYMS.  */
1085
1086 static void
1087 dbxout_typedefs (tree syms)
1088 {
1089   for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
1090     {
1091       if (TREE_CODE (syms) == TYPE_DECL)
1092         {
1093           tree type = TREE_TYPE (syms);
1094           if (TYPE_NAME (type)
1095               && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1096               && COMPLETE_OR_VOID_TYPE_P (type)
1097               && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
1098             dbxout_symbol (TYPE_NAME (type), 0);
1099         }
1100     }
1101 }
1102
1103 #ifdef DBX_USE_BINCL
1104 /* Emit BINCL stab using given name.  */
1105 static void
1106 emit_bincl_stab (const char *name)
1107 {
1108   dbxout_begin_simple_stabs (name, N_BINCL);
1109   dbxout_stab_value_zero ();
1110 }
1111
1112 /* If there are pending bincls then it is time to emit all of them.  */
1113
1114 static inline void
1115 emit_pending_bincls_if_required (void)
1116 {
1117   if (pending_bincls)
1118     emit_pending_bincls ();
1119 }
1120
1121 /* Emit all pending bincls.  */
1122
1123 static void
1124 emit_pending_bincls (void)
1125 {
1126   struct dbx_file *f = current_file;
1127
1128   /* Find first pending bincl.  */
1129   while (f->bincl_status == BINCL_PENDING)
1130     f = f->next;
1131
1132   /* Now emit all bincls.  */
1133   f = f->prev;
1134
1135   while (f)
1136     {
1137       if (f->bincl_status == BINCL_PENDING)
1138         {
1139           emit_bincl_stab (f->pending_bincl_name);
1140
1141           /* Update file number and status.  */
1142           f->file_number = next_file_number++;
1143           f->bincl_status = BINCL_PROCESSED;
1144         }
1145       if (f == current_file)
1146         break;
1147       f = f->prev;
1148     }
1149
1150   /* All pending bincls have been emitted.  */
1151   pending_bincls = 0;
1152 }
1153
1154 #else
1155
1156 static inline void
1157 emit_pending_bincls_if_required (void) {}
1158 #endif
1159
1160 /* Change to reading from a new source file.  Generate a N_BINCL stab.  */
1161
1162 static void
1163 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1164                           const char *filename ATTRIBUTE_UNUSED)
1165 {
1166 #ifdef DBX_USE_BINCL
1167   struct dbx_file *n = xmalloc (sizeof *n);
1168
1169   n->next = current_file;
1170   n->next_type_number = 1;
1171   /* Do not assign file number now. 
1172      Delay it until we actually emit BINCL.  */
1173   n->file_number = 0;
1174   n->prev = NULL;
1175   current_file->prev = n;
1176   n->bincl_status = BINCL_PENDING;
1177   n->pending_bincl_name = filename;
1178   pending_bincls = 1;
1179   current_file = n;
1180 #endif
1181 }
1182
1183 /* Revert to reading a previous source file.  Generate a N_EINCL stab.  */
1184
1185 static void
1186 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1187 {
1188 #ifdef DBX_USE_BINCL
1189   /* Emit EINCL stab only if BINCL is not pending.  */
1190   if (current_file->bincl_status == BINCL_PROCESSED)
1191     {
1192       dbxout_begin_stabn (N_EINCL);
1193       dbxout_stab_value_zero ();
1194     }
1195   current_file->bincl_status = BINCL_NOT_REQUIRED;
1196   current_file = current_file->next;
1197 #endif
1198 }
1199
1200 /* Handle a few odd cases that occur when trying to make PCH files work.  */
1201
1202 static void
1203 dbxout_handle_pch (unsigned at_end)
1204 {
1205   if (! at_end)
1206     {
1207       /* When using the PCH, this file will be included, so we need to output
1208          a BINCL.  */
1209       dbxout_start_source_file (0, lastfile);
1210
1211       /* The base file when using the PCH won't be the same as
1212          the base file when it's being generated.  */
1213       lastfile = NULL;
1214     }
1215   else
1216     {
1217       /* ... and an EINCL.  */
1218       dbxout_end_source_file (0);
1219
1220       /* Deal with cases where 'lastfile' was never actually changed.  */
1221       lastfile_is_base = lastfile == NULL;
1222     }
1223 }
1224
1225 #if defined (DBX_DEBUGGING_INFO)
1226 /* Output debugging info to FILE to switch to sourcefile FILENAME.  */
1227
1228 static void
1229 dbxout_source_file (const char *filename)
1230 {
1231   if (lastfile == 0 && lastfile_is_base)
1232     {
1233       lastfile = base_input_file;
1234       lastfile_is_base = 0;
1235     }
1236
1237   if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
1238     {
1239       /* Don't change section amid function.  */
1240       if (current_function_decl == NULL_TREE)
1241         text_section ();
1242
1243       dbxout_begin_simple_stabs (filename, N_SOL);
1244       dbxout_stab_value_internal_label ("Ltext", &source_label_number);
1245       lastfile = filename;
1246     }
1247 }
1248
1249 /* Output N_BNSYM and line number symbol entry.  */
1250
1251 static void
1252 dbxout_begin_prologue (unsigned int lineno, const char *filename)
1253 {
1254   if (use_gnu_debug_info_extensions
1255       && !NO_DBX_FUNCTION_END
1256       && !NO_DBX_BNSYM_ENSYM
1257       && !flag_debug_only_used_symbols)
1258     dbxout_stabd (N_BNSYM, 0);
1259
1260   dbxout_source_line (lineno, filename);
1261 }
1262
1263 /* Output a line number symbol entry for source file FILENAME and line
1264    number LINENO.  */
1265
1266 static void
1267 dbxout_source_line (unsigned int lineno, const char *filename)
1268 {
1269   dbxout_source_file (filename);
1270
1271 #ifdef DBX_OUTPUT_SOURCE_LINE
1272   DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter);
1273 #else
1274   if (DBX_LINES_FUNCTION_RELATIVE)
1275     {
1276       rtx begin_label = XEXP (DECL_RTL (current_function_decl), 0);
1277       dbxout_begin_stabn_sline (lineno);
1278       dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
1279                                              XSTR (begin_label, 0));
1280
1281     }
1282   else
1283     dbxout_stabd (N_SLINE, lineno);
1284 #endif
1285 }
1286
1287 /* Describe the beginning of an internal block within a function.  */
1288
1289 static void
1290 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1291 {
1292   emit_pending_bincls_if_required ();
1293   targetm.asm_out.internal_label (asm_out_file, "LBB", n);
1294 }
1295
1296 /* Describe the end line-number of an internal block within a function.  */
1297
1298 static void
1299 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
1300 {
1301   emit_pending_bincls_if_required ();
1302   targetm.asm_out.internal_label (asm_out_file, "LBE", n);
1303 }
1304
1305 /* Output dbx data for a function definition.
1306    This includes a definition of the function name itself (a symbol),
1307    definitions of the parameters (locating them in the parameter list)
1308    and then output the block that makes up the function's body
1309    (including all the auto variables of the function).  */
1310
1311 static void
1312 dbxout_function_decl (tree decl)
1313 {
1314   emit_pending_bincls_if_required ();
1315 #ifndef DBX_FUNCTION_FIRST
1316   dbxout_begin_function (decl);
1317 #endif
1318   dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
1319   dbxout_function_end (decl);
1320 }
1321
1322 #endif /* DBX_DEBUGGING_INFO  */
1323
1324 /* Debug information for a global DECL.  Called from toplev.c after
1325    compilation proper has finished.  */
1326 static void
1327 dbxout_global_decl (tree decl)
1328 {
1329   if (TREE_CODE (decl) == VAR_DECL
1330       && ! DECL_EXTERNAL (decl)
1331       && DECL_RTL_SET_P (decl)) /* Not necessary?  */
1332     {
1333       int saved_tree_used = TREE_USED (decl);
1334       TREE_USED (decl) = 1;
1335       dbxout_symbol (decl, 0);
1336       TREE_USED (decl) = saved_tree_used;
1337     }
1338 }
1339
1340 /* This is just a function-type adapter; dbxout_symbol does exactly
1341    what we want but returns an int.  */
1342 static void
1343 dbxout_type_decl (tree decl, int local)
1344 {
1345   dbxout_symbol (decl, local);
1346 }
1347
1348 /* At the end of compilation, finish writing the symbol table.
1349    The default is to call debug_free_queue but do nothing else.  */
1350
1351 static void
1352 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
1353 {
1354 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
1355   DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
1356 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
1357  {
1358    text_section ();
1359    dbxout_begin_empty_stabs (N_SO);
1360    dbxout_stab_value_internal_label ("Letext", 0);
1361  }
1362 #endif
1363   debug_free_queue ();
1364 }
1365
1366 /* Output the index of a type.  */
1367
1368 static void
1369 dbxout_type_index (tree type)
1370 {
1371 #ifndef DBX_USE_BINCL
1372   stabstr_D (TYPE_SYMTAB_ADDRESS (type));
1373 #else
1374   struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
1375   stabstr_C ('(');
1376   stabstr_D (t->file_number);
1377   stabstr_C (',');
1378   stabstr_D (t->type_number);
1379   stabstr_C (')');
1380 #endif
1381 }
1382
1383 \f
1384
1385 /* Used in several places: evaluates to '0' for a private decl,
1386    '1' for a protected decl, '2' for a public decl.  */
1387 #define DECL_ACCESSIBILITY_CHAR(DECL) \
1388 (TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2')
1389
1390 /* Subroutine of `dbxout_type'.  Output the type fields of TYPE.
1391    This must be a separate function because anonymous unions require
1392    recursive calls.  */
1393
1394 static void
1395 dbxout_type_fields (tree type)
1396 {
1397   tree tem;
1398
1399   /* Output the name, type, position (in bits), size (in bits) of each
1400      field that we can support.  */
1401   for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1402     {
1403       /* If one of the nodes is an error_mark or its type is then
1404          return early.  */
1405       if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
1406         return;
1407
1408       /* Omit here local type decls until we know how to support them.  */
1409       if (TREE_CODE (tem) == TYPE_DECL
1410           /* Omit fields whose position or size are variable or too large to
1411              represent.  */
1412           || (TREE_CODE (tem) == FIELD_DECL
1413               && (! host_integerp (bit_position (tem), 0)
1414                   || ! DECL_SIZE (tem)
1415                   || ! host_integerp (DECL_SIZE (tem), 1)))
1416           /* Omit here the nameless fields that are used to skip bits.  */
1417            || DECL_IGNORED_P (tem))
1418         continue;
1419
1420       else if (TREE_CODE (tem) != CONST_DECL)
1421         {
1422           /* Continue the line if necessary,
1423              but not before the first field.  */
1424           if (tem != TYPE_FIELDS (type))
1425             CONTIN;
1426
1427           if (DECL_NAME (tem))
1428             stabstr_I (DECL_NAME (tem));
1429           stabstr_C (':');
1430
1431           if (use_gnu_debug_info_extensions
1432               && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
1433                   || TREE_CODE (tem) != FIELD_DECL))
1434             {
1435               have_used_extensions = 1;
1436               stabstr_C ('/');
1437               stabstr_C (DECL_ACCESSIBILITY_CHAR (tem));
1438             }
1439
1440           dbxout_type ((TREE_CODE (tem) == FIELD_DECL
1441                         && DECL_BIT_FIELD_TYPE (tem))
1442                        ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
1443
1444           if (TREE_CODE (tem) == VAR_DECL)
1445             {
1446               if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
1447                 {
1448                   tree name = DECL_ASSEMBLER_NAME (tem);
1449
1450                   have_used_extensions = 1;
1451                   stabstr_C (':');
1452                   stabstr_I (name);
1453                   stabstr_C (';');
1454                 }
1455               else
1456                 /* If TEM is non-static, GDB won't understand it.  */
1457                 stabstr_S (",0,0;");
1458             }
1459           else
1460             {
1461               stabstr_C (',');
1462               stabstr_D (int_bit_position (tem));
1463               stabstr_C (',');
1464               stabstr_D (tree_low_cst (DECL_SIZE (tem), 1));
1465               stabstr_C (';');
1466             }
1467         }
1468     }
1469 }
1470 \f
1471 /* Subroutine of `dbxout_type_methods'.  Output debug info about the
1472    method described DECL.  */
1473
1474 static void
1475 dbxout_type_method_1 (tree decl)
1476 {
1477   char c1 = 'A', c2;
1478
1479   if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
1480     c2 = '?';
1481   else /* it's a METHOD_TYPE.  */
1482     {
1483       tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
1484       /* A for normal functions.
1485          B for `const' member functions.
1486          C for `volatile' member functions.
1487          D for `const volatile' member functions.  */
1488       if (TYPE_READONLY (TREE_TYPE (firstarg)))
1489         c1 += 1;
1490       if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
1491         c1 += 2;
1492
1493       if (DECL_VINDEX (decl))
1494         c2 = '*';
1495       else
1496         c2 = '.';
1497     }
1498
1499   /* ??? Output the mangled name, which contains an encoding of the
1500      method's type signature.  May not be necessary anymore.  */
1501   stabstr_C (':');
1502   stabstr_I (DECL_ASSEMBLER_NAME (decl));
1503   stabstr_C (';');
1504   stabstr_C (DECL_ACCESSIBILITY_CHAR (decl));
1505   stabstr_C (c1);
1506   stabstr_C (c2);
1507
1508   if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1509     {
1510       stabstr_D (tree_low_cst (DECL_VINDEX (decl), 0));
1511       stabstr_C (';');
1512       dbxout_type (DECL_CONTEXT (decl), 0);
1513       stabstr_C (';');
1514     }
1515 }
1516 \f
1517 /* Subroutine of `dbxout_type'.  Output debug info about the methods defined
1518    in TYPE.  */
1519
1520 static void
1521 dbxout_type_methods (tree type)
1522 {
1523   /* C++: put out the method names and their parameter lists */
1524   tree methods = TYPE_METHODS (type);
1525   tree fndecl;
1526   tree last;
1527
1528   if (methods == NULL_TREE)
1529     return;
1530
1531   if (TREE_CODE (methods) != TREE_VEC)
1532     fndecl = methods;
1533   else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1534     fndecl = TREE_VEC_ELT (methods, 0);
1535   else
1536     fndecl = TREE_VEC_ELT (methods, 1);
1537
1538   while (fndecl)
1539     {
1540       int need_prefix = 1;
1541
1542       /* Group together all the methods for the same operation.
1543          These differ in the types of the arguments.  */
1544       for (last = NULL_TREE;
1545            fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1546            fndecl = TREE_CHAIN (fndecl))
1547         /* Output the name of the field (after overloading), as
1548            well as the name of the field before overloading, along
1549            with its parameter list */
1550         {
1551           /* Skip methods that aren't FUNCTION_DECLs.  (In C++, these
1552              include TEMPLATE_DECLs.)  The debugger doesn't know what
1553              to do with such entities anyhow.  */
1554           if (TREE_CODE (fndecl) != FUNCTION_DECL)
1555             continue;
1556
1557           CONTIN;
1558
1559           last = fndecl;
1560
1561           /* Also ignore abstract methods; those are only interesting to
1562              the DWARF backends.  */
1563           if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1564             continue;
1565
1566           /* Redundantly output the plain name, since that's what gdb
1567              expects.  */
1568           if (need_prefix)
1569             {
1570               stabstr_I (DECL_NAME (fndecl));
1571               stabstr_S ("::");
1572               need_prefix = 0;
1573             }
1574
1575           dbxout_type (TREE_TYPE (fndecl), 0);
1576           dbxout_type_method_1 (fndecl);
1577         }
1578       if (!need_prefix)
1579         stabstr_C (';');
1580     }
1581 }
1582
1583 /* Emit a "range" type specification, which has the form:
1584    "r<index type>;<lower bound>;<upper bound>;".
1585    TYPE is an INTEGER_TYPE.  */
1586
1587 static void
1588 dbxout_range_type (tree type)
1589 {
1590   stabstr_C ('r');
1591   if (TREE_TYPE (type))
1592     dbxout_type (TREE_TYPE (type), 0);
1593   else if (TREE_CODE (type) != INTEGER_TYPE)
1594     dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1595   else
1596     {
1597       /* Traditionally, we made sure 'int' was type 1, and builtin types
1598          were defined to be sub-ranges of int.  Unfortunately, this
1599          does not allow us to distinguish true sub-ranges from integer
1600          types.  So, instead we define integer (non-sub-range) types as
1601          sub-ranges of themselves.  This matters for Chill.  If this isn't
1602          a subrange type, then we want to define it in terms of itself.
1603          However, in C, this may be an anonymous integer type, and we don't
1604          want to emit debug info referring to it.  Just calling
1605          dbxout_type_index won't work anyways, because the type hasn't been
1606          defined yet.  We make this work for both cases by checked to see
1607          whether this is a defined type, referring to it if it is, and using
1608          'int' otherwise.  */
1609       if (TYPE_SYMTAB_ADDRESS (type) != 0)
1610         dbxout_type_index (type);
1611       else
1612         dbxout_type_index (integer_type_node);
1613     }
1614
1615   stabstr_C (';');
1616   if (TYPE_MIN_VALUE (type) != 0
1617       && host_integerp (TYPE_MIN_VALUE (type), 0))
1618     {
1619       if (print_int_cst_bounds_in_octal_p (type))
1620         stabstr_O (TYPE_MIN_VALUE (type));
1621       else
1622         stabstr_D (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1623     }
1624   else
1625     stabstr_C ('0');
1626
1627   stabstr_C (';');
1628   if (TYPE_MAX_VALUE (type) != 0
1629       && host_integerp (TYPE_MAX_VALUE (type), 0))
1630     {
1631       if (print_int_cst_bounds_in_octal_p (type))
1632         stabstr_O (TYPE_MAX_VALUE (type));
1633       else
1634         stabstr_D (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1635       stabstr_C (';');
1636     }
1637   else
1638     stabstr_S ("-1;");
1639 }
1640 \f
1641
1642 /* Output a reference to a type.  If the type has not yet been
1643    described in the dbx output, output its definition now.
1644    For a type already defined, just refer to its definition
1645    using the type number.
1646
1647    If FULL is nonzero, and the type has been described only with
1648    a forward-reference, output the definition now.
1649    If FULL is zero in this case, just refer to the forward-reference
1650    using the number previously allocated.  */
1651
1652 static void
1653 dbxout_type (tree type, int full)
1654 {
1655   tree tem;
1656   tree main_variant;
1657   static int anonymous_type_number = 0;
1658
1659   if (TREE_CODE (type) == VECTOR_TYPE)
1660     /* The frontend feeds us a representation for the vector as a struct
1661        containing an array.  Pull out the array type.  */
1662     type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1663
1664   /* If there was an input error and we don't really have a type,
1665      avoid crashing and write something that is at least valid
1666      by assuming `int'.  */
1667   if (type == error_mark_node)
1668     type = integer_type_node;
1669   else
1670     {
1671       if (TYPE_NAME (type)
1672           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1673           && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1674         full = 0;
1675     }
1676
1677   /* Try to find the "main variant" with the same name.  */
1678   if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1679       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1680     main_variant = TREE_TYPE (TYPE_NAME (type));
1681   else
1682     main_variant = TYPE_MAIN_VARIANT (type);
1683
1684   /* If we are not using extensions, stabs does not distinguish const and
1685      volatile, so there is no need to make them separate types.  */
1686   if (!use_gnu_debug_info_extensions)
1687     type = main_variant;
1688
1689   if (TYPE_SYMTAB_ADDRESS (type) == 0)
1690     {
1691       /* Type has no dbx number assigned.  Assign next available number.  */
1692       TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1693
1694       /* Make sure type vector is long enough to record about this type.  */
1695
1696       if (next_type_number == typevec_len)
1697         {
1698           typevec
1699             = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1700           memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1701           typevec_len *= 2;
1702         }
1703
1704 #ifdef DBX_USE_BINCL
1705       emit_pending_bincls_if_required ();
1706       typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1707         = current_file->file_number;
1708       typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1709         = current_file->next_type_number++;
1710 #endif
1711     }
1712
1713   if (flag_debug_only_used_symbols)
1714     {
1715       if ((TREE_CODE (type) == RECORD_TYPE
1716            || TREE_CODE (type) == UNION_TYPE
1717            || TREE_CODE (type) == QUAL_UNION_TYPE
1718            || TREE_CODE (type) == ENUMERAL_TYPE)
1719           && TYPE_STUB_DECL (type)
1720           && DECL_P (TYPE_STUB_DECL (type))
1721           && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1722         debug_queue_symbol (TYPE_STUB_DECL (type));
1723       else if (TYPE_NAME (type)
1724                && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1725         debug_queue_symbol (TYPE_NAME (type));
1726     }
1727
1728   /* Output the number of this type, to refer to it.  */
1729   dbxout_type_index (type);
1730
1731 #ifdef DBX_TYPE_DEFINED
1732   if (DBX_TYPE_DEFINED (type))
1733     return;
1734 #endif
1735
1736   /* If this type's definition has been output or is now being output,
1737      that is all.  */
1738
1739   switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1740     {
1741     case TYPE_UNSEEN:
1742       break;
1743     case TYPE_XREF:
1744       /* If we have already had a cross reference,
1745          and either that's all we want or that's the best we could do,
1746          don't repeat the cross reference.
1747          Sun dbx crashes if we do.  */
1748       if (! full || !COMPLETE_TYPE_P (type)
1749           /* No way in DBX fmt to describe a variable size.  */
1750           || ! host_integerp (TYPE_SIZE (type), 1))
1751         return;
1752       break;
1753     case TYPE_DEFINED:
1754       return;
1755     }
1756
1757 #ifdef DBX_NO_XREFS
1758   /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1759      leave the type-number completely undefined rather than output
1760      a cross-reference.  If we have already used GNU debug info extensions,
1761      then it is OK to output a cross reference.  This is necessary to get
1762      proper C++ debug output.  */
1763   if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1764        || TREE_CODE (type) == QUAL_UNION_TYPE
1765        || TREE_CODE (type) == ENUMERAL_TYPE)
1766       && ! use_gnu_debug_info_extensions)
1767     /* We must use the same test here as we use twice below when deciding
1768        whether to emit a cross-reference.  */
1769     if ((TYPE_NAME (type) != 0
1770          && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1771                && DECL_IGNORED_P (TYPE_NAME (type)))
1772          && !full)
1773         || !COMPLETE_TYPE_P (type)
1774         /* No way in DBX fmt to describe a variable size.  */
1775         || ! host_integerp (TYPE_SIZE (type), 1))
1776       {
1777         typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1778         return;
1779       }
1780 #endif
1781
1782   /* Output a definition now.  */
1783   stabstr_C ('=');
1784
1785   /* Mark it as defined, so that if it is self-referent
1786      we will not get into an infinite recursion of definitions.  */
1787
1788   typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1789
1790   /* If this type is a variant of some other, hand off.  Types with
1791      different names are usefully distinguished.  We only distinguish
1792      cv-qualified types if we're using extensions.  */
1793   if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1794     {
1795       stabstr_C ('k');
1796       dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1797       return;
1798     }
1799   else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1800     {
1801       stabstr_C ('B');
1802       dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1803       return;
1804     }
1805   else if (main_variant != TYPE_MAIN_VARIANT (type))
1806     {
1807       if (flag_debug_only_used_symbols)
1808         {
1809           tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1810
1811           if ((TREE_CODE (orig_type) == RECORD_TYPE
1812                || TREE_CODE (orig_type) == UNION_TYPE
1813                || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1814                || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1815               && TYPE_STUB_DECL (orig_type)
1816               && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1817             debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1818         }
1819       /* 'type' is a typedef; output the type it refers to.  */
1820       dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1821       return;
1822     }
1823   /* else continue.  */
1824
1825   switch (TREE_CODE (type))
1826     {
1827     case VOID_TYPE:
1828     case LANG_TYPE:
1829       /* For a void type, just define it as itself; i.e., "5=5".
1830          This makes us consider it defined
1831          without saying what it is.  The debugger will make it
1832          a void type when the reference is seen, and nothing will
1833          ever override that default.  */
1834       dbxout_type_index (type);
1835       break;
1836
1837     case INTEGER_TYPE:
1838       if (type == char_type_node && ! TYPE_UNSIGNED (type))
1839         {
1840           /* Output the type `char' as a subrange of itself!
1841              I don't understand this definition, just copied it
1842              from the output of pcc.
1843              This used to use `r2' explicitly and we used to
1844              take care to make sure that `char' was type number 2.  */
1845           stabstr_C ('r');
1846           dbxout_type_index (type);
1847           stabstr_S (";0;127;");
1848         }
1849
1850       /* If this is a subtype of another integer type, always prefer to
1851          write it as a subtype.  */
1852       else if (TREE_TYPE (type) != 0
1853                && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1854         {
1855           /* If the size is non-standard, say what it is if we can use
1856              GDB extensions.  */
1857
1858           if (use_gnu_debug_info_extensions
1859               && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1860             {
1861               have_used_extensions = 1;
1862               stabstr_S ("@s");
1863               stabstr_D (TYPE_PRECISION (type));
1864               stabstr_C (';');
1865             }
1866
1867           dbxout_range_type (type);
1868         }
1869
1870       else
1871         {
1872           /* If the size is non-standard, say what it is if we can use
1873              GDB extensions.  */
1874
1875           if (use_gnu_debug_info_extensions
1876               && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1877             {
1878               have_used_extensions = 1;
1879               stabstr_S ("@s");
1880               stabstr_D (TYPE_PRECISION (type));
1881               stabstr_C (';');
1882             }
1883
1884           if (print_int_cst_bounds_in_octal_p (type))
1885             {
1886               stabstr_C ('r');
1887
1888               /* If this type derives from another type, output type index of
1889                  parent type. This is particularly important when parent type
1890                  is an enumerated type, because not generating the parent type
1891                  index would transform the definition of this enumerated type
1892                  into a plain unsigned type.  */
1893               if (TREE_TYPE (type) != 0)
1894                 dbxout_type_index (TREE_TYPE (type));
1895               else
1896                 dbxout_type_index (type);
1897
1898               stabstr_C (';');
1899               stabstr_O (TYPE_MIN_VALUE (type));
1900               stabstr_C (';');
1901               stabstr_O (TYPE_MAX_VALUE (type));
1902               stabstr_C (';');
1903             }
1904
1905           else
1906             /* Output other integer types as subranges of `int'.  */
1907             dbxout_range_type (type);
1908         }
1909
1910       break;
1911
1912     case REAL_TYPE:
1913       /* This used to say `r1' and we used to take care
1914          to make sure that `int' was type number 1.  */
1915       stabstr_C ('r');
1916       dbxout_type_index (integer_type_node);
1917       stabstr_C (';');
1918       stabstr_D (int_size_in_bytes (type));
1919       stabstr_S (";0;");
1920       break;
1921
1922     case CHAR_TYPE:
1923       if (use_gnu_debug_info_extensions)
1924         {
1925           have_used_extensions = 1;
1926           stabstr_S ("@s");
1927           stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1928           stabstr_S (";-20;");
1929         }
1930       else
1931         {
1932           /* Output the type `char' as a subrange of itself.
1933              That is what pcc seems to do.  */
1934           stabstr_C ('r');
1935           dbxout_type_index (char_type_node);
1936           stabstr_S (TYPE_UNSIGNED (type) ? ";0;255;" : ";0;127;");
1937         }
1938       break;
1939
1940     case BOOLEAN_TYPE:
1941       if (use_gnu_debug_info_extensions)
1942         {
1943           have_used_extensions = 1;
1944           stabstr_S ("@s");
1945           stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1946           stabstr_S (";-16;");
1947         }
1948       else /* Define as enumeral type (False, True) */
1949         stabstr_S ("eFalse:0,True:1,;");
1950       break;
1951
1952     case COMPLEX_TYPE:
1953       /* Differs from the REAL_TYPE by its new data type number.
1954          R3 is NF_COMPLEX.  We don't try to use any of the other NF_*
1955          codes since gdb doesn't care anyway.  */
1956
1957       if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1958         {
1959           stabstr_S ("R3;");
1960           stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type)));
1961           stabstr_S (";0;");
1962         }
1963       else
1964         {
1965           /* Output a complex integer type as a structure,
1966              pending some other way to do it.  */
1967           stabstr_C ('s');
1968           stabstr_D (int_size_in_bytes (type));
1969
1970           stabstr_S ("real:");
1971           dbxout_type (TREE_TYPE (type), 0);
1972           stabstr_S (",0,");
1973           stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1974
1975           stabstr_S (";imag:");
1976           dbxout_type (TREE_TYPE (type), 0);
1977           stabstr_C (',');
1978           stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1979           stabstr_C (',');
1980           stabstr_D (TYPE_PRECISION (TREE_TYPE (type)));
1981           stabstr_S (";;");
1982         }
1983       break;
1984
1985     case ARRAY_TYPE:
1986       /* Make arrays of packed bits look like bitstrings for chill.  */
1987       if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1988         {
1989           have_used_extensions = 1;
1990           stabstr_S ("@s");
1991           stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type));
1992           stabstr_S (";@S;S");
1993           dbxout_type (TYPE_DOMAIN (type), 0);
1994           break;
1995         }
1996
1997       /* Output "a" followed by a range type definition
1998          for the index type of the array
1999          followed by a reference to the target-type.
2000          ar1;0;N;M for a C array of type M and size N+1.  */
2001       /* Check if a character string type, which in Chill is
2002          different from an array of characters.  */
2003       if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
2004         {
2005           have_used_extensions = 1;
2006           stabstr_S ("@S;");
2007         }
2008       tem = TYPE_DOMAIN (type);
2009       if (tem == NULL)
2010         {
2011           stabstr_S ("ar");
2012           dbxout_type_index (integer_type_node);
2013           stabstr_S (";0;-1;");
2014         }
2015       else
2016         {
2017           stabstr_C ('a');
2018           dbxout_range_type (tem);
2019         }
2020
2021       dbxout_type (TREE_TYPE (type), 0);
2022       break;
2023
2024     case RECORD_TYPE:
2025     case UNION_TYPE:
2026     case QUAL_UNION_TYPE:
2027       {
2028         tree binfo = TYPE_BINFO (type);
2029
2030         /* Output a structure type.  We must use the same test here as we
2031            use in the DBX_NO_XREFS case above.  */
2032         if ((TYPE_NAME (type) != 0
2033              && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2034                    && DECL_IGNORED_P (TYPE_NAME (type)))
2035              && !full)
2036             || !COMPLETE_TYPE_P (type)
2037             /* No way in DBX fmt to describe a variable size.  */
2038             || ! host_integerp (TYPE_SIZE (type), 1))
2039           {
2040             /* If the type is just a cross reference, output one
2041                and mark the type as partially described.
2042                If it later becomes defined, we will output
2043                its real definition.
2044                If the type has a name, don't nest its definition within
2045                another type's definition; instead, output an xref
2046                and let the definition come when the name is defined.  */
2047             stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
2048             if (TYPE_NAME (type) != 0)
2049               dbxout_type_name (type);
2050             else
2051               {
2052                 stabstr_S ("$$");
2053                 stabstr_D (anonymous_type_number++);
2054               }
2055
2056             stabstr_C (':');
2057             typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2058             break;
2059           }
2060
2061         /* Identify record or union, and print its size.  */
2062         stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u');
2063         stabstr_D (int_size_in_bytes (type));
2064
2065         if (binfo)
2066           {
2067             int i;
2068             tree child;
2069             VEC (tree) *accesses = BINFO_BASE_ACCESSES (binfo);
2070             
2071             if (use_gnu_debug_info_extensions)
2072               {
2073                 if (BINFO_N_BASE_BINFOS (binfo))
2074                   {
2075                     have_used_extensions = 1;
2076                     stabstr_C ('!');
2077                     stabstr_U (BINFO_N_BASE_BINFOS (binfo));
2078                     stabstr_C (',');
2079                   }
2080               }
2081             for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++)
2082               {
2083                 tree access = (accesses ? VEC_index (tree, accesses, i)
2084                                : access_public_node);
2085
2086                 if (use_gnu_debug_info_extensions)
2087                   {
2088                     have_used_extensions = 1;
2089                     stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0');
2090                     stabstr_C (access == access_public_node ? '2' :
2091                                    access == access_protected_node
2092                                    ? '1' :'0');
2093                     if (BINFO_VIRTUAL_P (child)
2094                         && strcmp (lang_hooks.name, "GNU C++") == 0)
2095                       /* For a virtual base, print the (negative)
2096                          offset within the vtable where we must look
2097                          to find the necessary adjustment.  */
2098                       stabstr_D
2099                         (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
2100                          * BITS_PER_UNIT);
2101                     else
2102                       stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2103                                        * BITS_PER_UNIT);
2104                     stabstr_C (',');
2105                     dbxout_type (BINFO_TYPE (child), 0);
2106                     stabstr_C (';');
2107                   }
2108                 else
2109                   {
2110                     /* Print out the base class information with
2111                        fields which have the same names at the types
2112                        they hold.  */
2113                     dbxout_type_name (BINFO_TYPE (child));
2114                     stabstr_C (':');
2115                     dbxout_type (BINFO_TYPE (child), full);
2116                     stabstr_C (',');
2117                     stabstr_D (tree_low_cst (BINFO_OFFSET (child), 0)
2118                                      * BITS_PER_UNIT);
2119                     stabstr_C (',');
2120                     stabstr_D
2121                       (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)), 0)
2122                        * BITS_PER_UNIT);
2123                     stabstr_C (';');
2124                   }
2125               }
2126           }
2127       }
2128
2129       /* Write out the field declarations.  */
2130       dbxout_type_fields (type);
2131       if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
2132         {
2133           have_used_extensions = 1;
2134           dbxout_type_methods (type);
2135         }
2136
2137       stabstr_C (';');
2138
2139       if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
2140           /* Avoid the ~ if we don't really need it--it confuses dbx.  */
2141           && TYPE_VFIELD (type))
2142         {
2143           have_used_extensions = 1;
2144
2145           /* We need to write out info about what field this class
2146              uses as its "main" vtable pointer field, because if this
2147              field is inherited from a base class, GDB cannot necessarily
2148              figure out which field it's using in time.  */
2149           stabstr_S ("~%");
2150           dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
2151           stabstr_C (';');
2152         }
2153       break;
2154
2155     case ENUMERAL_TYPE:
2156       /* We must use the same test here as we use in the DBX_NO_XREFS case
2157          above.  We simplify it a bit since an enum will never have a variable
2158          size.  */
2159       if ((TYPE_NAME (type) != 0
2160            && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2161                  && DECL_IGNORED_P (TYPE_NAME (type)))
2162            && !full)
2163           || !COMPLETE_TYPE_P (type))
2164         {
2165           stabstr_S ("xe");
2166           dbxout_type_name (type);
2167           typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
2168           stabstr_C (':');
2169           return;
2170         }
2171       if (use_gnu_debug_info_extensions
2172           && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
2173         {
2174           have_used_extensions = 1;
2175           stabstr_S ("@s");
2176           stabstr_D (TYPE_PRECISION (type));
2177           stabstr_C (';');
2178         }
2179
2180       stabstr_C ('e');
2181       for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
2182         {
2183           stabstr_I (TREE_PURPOSE (tem));
2184           stabstr_C (':');
2185
2186           if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
2187             stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2188           else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
2189                    && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
2190             stabstr_D (TREE_INT_CST_LOW (TREE_VALUE (tem)));
2191           else
2192             stabstr_O (TREE_VALUE (tem));
2193
2194           stabstr_C (',');
2195           if (TREE_CHAIN (tem) != 0)
2196             CONTIN;
2197         }
2198
2199       stabstr_C (';');
2200       break;
2201
2202     case POINTER_TYPE:
2203       stabstr_C ('*');
2204       dbxout_type (TREE_TYPE (type), 0);
2205       break;
2206
2207     case METHOD_TYPE:
2208       if (use_gnu_debug_info_extensions)
2209         {
2210           have_used_extensions = 1;
2211           stabstr_C ('#');
2212
2213           /* Write the argument types out longhand.  */
2214           dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
2215           stabstr_C (',');
2216           dbxout_type (TREE_TYPE (type), 0);
2217           dbxout_args (TYPE_ARG_TYPES (type));
2218           stabstr_C (';');
2219         }
2220       else
2221         /* Treat it as a function type.  */
2222         dbxout_type (TREE_TYPE (type), 0);
2223       break;
2224
2225     case OFFSET_TYPE:
2226       if (use_gnu_debug_info_extensions)
2227         {
2228           have_used_extensions = 1;
2229           stabstr_C ('@');
2230           dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
2231           stabstr_C (',');
2232           dbxout_type (TREE_TYPE (type), 0);
2233         }
2234       else
2235         /* Should print as an int, because it is really just an offset.  */
2236         dbxout_type (integer_type_node, 0);
2237       break;
2238
2239     case REFERENCE_TYPE:
2240       if (use_gnu_debug_info_extensions)
2241         {
2242           have_used_extensions = 1;
2243           stabstr_C ('&');
2244         }
2245       else
2246         stabstr_C ('*');
2247       dbxout_type (TREE_TYPE (type), 0);
2248       break;
2249
2250     case FUNCTION_TYPE:
2251       stabstr_C ('f');
2252       dbxout_type (TREE_TYPE (type), 0);
2253       break;
2254
2255     default:
2256       gcc_unreachable ();
2257     }
2258 }
2259
2260 /* Return nonzero if the given type represents an integer whose bounds
2261    should be printed in octal format.  */
2262
2263 static bool
2264 print_int_cst_bounds_in_octal_p (tree type)
2265 {
2266   /* If we can use GDB extensions and the size is wider than a long
2267      (the size used by GDB to read them) or we may have trouble writing
2268      the bounds the usual way, write them in octal.  Note the test is for
2269      the *target's* size of "long", not that of the host.  The host test
2270      is just to make sure we can write it out in case the host wide int
2271      is narrower than the target "long".
2272
2273      For unsigned types, we use octal if they are the same size or larger.
2274      This is because we print the bounds as signed decimal, and hence they
2275      can't span same size unsigned types.  */
2276
2277   if (use_gnu_debug_info_extensions
2278       && TYPE_MIN_VALUE (type) != 0
2279       && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
2280       && TYPE_MAX_VALUE (type) != 0
2281       && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
2282       && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
2283           || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2284               && TYPE_UNSIGNED (type))
2285           || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
2286           || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
2287               && TYPE_UNSIGNED (type))))
2288     return TRUE;
2289   else
2290     return FALSE;
2291 }
2292
2293 /* Output the name of type TYPE, with no punctuation.
2294    Such names can be set up either by typedef declarations
2295    or by struct, enum and union tags.  */
2296
2297 static void
2298 dbxout_type_name (tree type)
2299 {
2300   tree t = TYPE_NAME (type);
2301   
2302   gcc_assert (t);
2303   switch (TREE_CODE (t))
2304     {
2305     case IDENTIFIER_NODE:
2306       break;
2307     case TYPE_DECL:
2308       t = DECL_NAME (t);
2309       break;
2310     default:
2311       gcc_unreachable ();
2312     }
2313
2314   stabstr_I (t);
2315 }
2316
2317 /* Output leading leading struct or class names needed for qualifying
2318    type whose scope is limited to a struct or class.  */
2319
2320 static void
2321 dbxout_class_name_qualifiers (tree decl)
2322 {
2323   tree context = decl_type_context (decl);
2324
2325   if (context != NULL_TREE
2326       && TREE_CODE(context) == RECORD_TYPE
2327       && TYPE_NAME (context) != 0
2328       && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2329           || (DECL_NAME (TYPE_NAME (context)) != 0)))
2330     {
2331       tree name = TYPE_NAME (context);
2332
2333       if (TREE_CODE (name) == TYPE_DECL)
2334         {
2335           dbxout_class_name_qualifiers (name);
2336           name = DECL_NAME (name);
2337         }
2338       stabstr_I (name);
2339       stabstr_S ("::");
2340     }
2341 }
2342 \f
2343 /* Output a .stabs for the symbol defined by DECL,
2344    which must be a ..._DECL node in the normal namespace.
2345    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2346    LOCAL is nonzero if the scope is less than the entire file.
2347    Return 1 if a stabs might have been emitted.  */
2348
2349 int
2350 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2351 {
2352   tree type = TREE_TYPE (decl);
2353   tree context = NULL_TREE;
2354   int result = 0;
2355
2356   /* "Intercept" dbxout_symbol() calls like we do all debug_hooks.  */
2357   ++debug_nesting;
2358
2359   /* Ignore nameless syms, but don't ignore type tags.  */
2360
2361   if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2362       || DECL_IGNORED_P (decl))
2363     DBXOUT_DECR_NESTING_AND_RETURN (0);
2364
2365   /* If we are to generate only the symbols actually used then such
2366      symbol nodes are flagged with TREE_USED.  Ignore any that
2367      aren't flaged as TREE_USED.  */
2368
2369   if (flag_debug_only_used_symbols
2370       && (!TREE_USED (decl)
2371           && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2372     DBXOUT_DECR_NESTING_AND_RETURN (0);
2373
2374   /* If dbxout_init has not yet run, queue this symbol for later.  */
2375   if (!typevec)
2376     {
2377       preinit_symbols = tree_cons (0, decl, preinit_symbols);
2378       DBXOUT_DECR_NESTING_AND_RETURN (0);
2379     }
2380
2381   if (flag_debug_only_used_symbols)
2382     {
2383       tree t;
2384
2385       /* We now have a used symbol.  We need to generate the info for
2386          the symbol's type in addition to the symbol itself.  These
2387          type symbols are queued to be generated after were done with
2388          the symbol itself (otherwise they would fight over the
2389          stabstr obstack).
2390
2391          Note, because the TREE_TYPE(type) might be something like a
2392          pointer to a named type we need to look for the first name
2393          we see following the TREE_TYPE chain.  */
2394
2395       t = type;
2396       while (POINTER_TYPE_P (t))
2397         t = TREE_TYPE (t);
2398
2399       /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2400          need special treatment.  The TYPE_STUB_DECL field in these
2401          types generally represents the tag name type we want to
2402          output.  In addition there  could be a typedef type with
2403          a different name.  In that case we also want to output
2404          that.  */
2405
2406       if (TREE_CODE (t) == RECORD_TYPE
2407            || TREE_CODE (t) == UNION_TYPE
2408            || TREE_CODE (t) == QUAL_UNION_TYPE
2409            || TREE_CODE (t) == ENUMERAL_TYPE)
2410         {
2411             if (TYPE_STUB_DECL (t)
2412                 && TYPE_STUB_DECL (t) != decl
2413                 && DECL_P (TYPE_STUB_DECL (t))
2414                 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2415             {
2416               debug_queue_symbol (TYPE_STUB_DECL (t));
2417               if (TYPE_NAME (t)
2418                   && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2419                   && TYPE_NAME (t) != decl
2420                   && DECL_P (TYPE_NAME (t)))
2421                 debug_queue_symbol (TYPE_NAME (t));
2422             }
2423         }
2424       else if (TYPE_NAME (t)
2425                && TYPE_NAME (t) != decl
2426                && DECL_P (TYPE_NAME (t)))
2427         debug_queue_symbol (TYPE_NAME (t));
2428     }
2429
2430   emit_pending_bincls_if_required ();
2431
2432   switch (TREE_CODE (decl))
2433     {
2434     case CONST_DECL:
2435       /* Enum values are defined by defining the enum type.  */
2436       break;
2437
2438     case FUNCTION_DECL:
2439       if (DECL_RTL (decl) == 0)
2440         DBXOUT_DECR_NESTING_AND_RETURN (0);
2441       if (DECL_EXTERNAL (decl))
2442         break;
2443       /* Don't mention a nested function under its parent.  */
2444       context = decl_function_context (decl);
2445       if (context == current_function_decl)
2446         break;
2447       /* Don't mention an inline instance of a nested function.  */
2448       if (context && DECL_FROM_INLINE (decl))
2449         break;
2450       if (!MEM_P (DECL_RTL (decl))
2451           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2452         break;
2453
2454       dbxout_begin_complex_stabs ();
2455       stabstr_I (DECL_ASSEMBLER_NAME (decl));
2456       stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f");
2457       result = 1;
2458
2459       if (TREE_TYPE (type))
2460         dbxout_type (TREE_TYPE (type), 0);
2461       else
2462         dbxout_type (void_type_node, 0);
2463
2464       /* For a nested function, when that function is compiled,
2465          mention the containing function name
2466          as well as (since dbx wants it) our own assembler-name.  */
2467       if (context != 0)
2468         {
2469           stabstr_C (',');
2470           stabstr_I (DECL_ASSEMBLER_NAME (decl));
2471           stabstr_C (',');
2472           stabstr_I (DECL_NAME (context));
2473         }
2474
2475       dbxout_finish_complex_stabs (decl, N_FUN, XEXP (DECL_RTL (decl), 0),
2476                                    0, 0);
2477       break;
2478
2479     case TYPE_DECL:
2480       /* Don't output the same typedef twice.
2481          And don't output what language-specific stuff doesn't want output.  */
2482       if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2483         DBXOUT_DECR_NESTING_AND_RETURN (0);
2484
2485       /* Don't output typedefs for types with magic type numbers (XCOFF).  */
2486 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2487       {
2488         int fundamental_type_number =
2489           DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2490
2491         if (fundamental_type_number != 0)
2492           {
2493             TREE_ASM_WRITTEN (decl) = 1;
2494             TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2495             DBXOUT_DECR_NESTING_AND_RETURN (0);
2496           }
2497       }
2498 #endif
2499       FORCE_TEXT;
2500       result = 1;
2501       {
2502         int tag_needed = 1;
2503         int did_output = 0;
2504
2505         if (DECL_NAME (decl))
2506           {
2507             /* Nonzero means we must output a tag as well as a typedef.  */
2508             tag_needed = 0;
2509
2510             /* Handle the case of a C++ structure or union
2511                where the TYPE_NAME is a TYPE_DECL
2512                which gives both a typedef name and a tag.  */
2513             /* dbx requires the tag first and the typedef second.  */
2514             if ((TREE_CODE (type) == RECORD_TYPE
2515                  || TREE_CODE (type) == UNION_TYPE
2516                  || TREE_CODE (type) == QUAL_UNION_TYPE)
2517                 && TYPE_NAME (type) == decl
2518                 && !(use_gnu_debug_info_extensions && have_used_extensions)
2519                 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2520                 /* Distinguish the implicit typedefs of C++
2521                    from explicit ones that might be found in C.  */
2522                 && DECL_ARTIFICIAL (decl)
2523                 /* Do not generate a tag for incomplete records.  */
2524                 && COMPLETE_TYPE_P (type)
2525                 /* Do not generate a tag for records of variable size,
2526                    since this type can not be properly described in the
2527                    DBX format, and it confuses some tools such as objdump.  */
2528                 && host_integerp (TYPE_SIZE (type), 1))
2529               {
2530                 tree name = TYPE_NAME (type);
2531                 if (TREE_CODE (name) == TYPE_DECL)
2532                   name = DECL_NAME (name);
2533
2534                 dbxout_begin_complex_stabs ();
2535                 stabstr_I (name);
2536                 stabstr_S (":T");
2537                 dbxout_type (type, 1);
2538                 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE,
2539                                              0, 0, 0);
2540               }
2541
2542             dbxout_begin_complex_stabs ();
2543
2544             /* Output leading class/struct qualifiers.
2545                ??? why not set have_used_extensions here ... because
2546                then the test of it below would always be true, I
2547                guess.  But it's not clear to me why we shouldn't do
2548                that always in extended mode.  */
2549             if (use_gnu_debug_info_extensions)
2550               dbxout_class_name_qualifiers (decl);
2551
2552             /* Output typedef name.  */
2553             stabstr_I (DECL_NAME (decl));
2554             stabstr_C (':');
2555
2556             /* Short cut way to output a tag also.  */
2557             if ((TREE_CODE (type) == RECORD_TYPE
2558                  || TREE_CODE (type) == UNION_TYPE
2559                  || TREE_CODE (type) == QUAL_UNION_TYPE)
2560                 && TYPE_NAME (type) == decl
2561                 /* Distinguish the implicit typedefs of C++
2562                    from explicit ones that might be found in C.  */
2563                 && DECL_ARTIFICIAL (decl))
2564               {
2565                 if (use_gnu_debug_info_extensions && have_used_extensions)
2566                   {
2567                     stabstr_C ('T');
2568                     TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2569                   }
2570               }
2571
2572             stabstr_C ('t');
2573             dbxout_type (type, 1);
2574             dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE,
2575                                          0, 0, 0);
2576             did_output = 1;
2577           }
2578
2579         /* Don't output a tag if this is an incomplete type.  This prevents
2580            the sun4 Sun OS 4.x dbx from crashing.  */
2581
2582         if (tag_needed && TYPE_NAME (type) != 0
2583             && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2584                 || (DECL_NAME (TYPE_NAME (type)) != 0))
2585             && COMPLETE_TYPE_P (type)
2586             && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2587           {
2588             /* For a TYPE_DECL with no name, but the type has a name,
2589                output a tag.
2590                This is what represents `struct foo' with no typedef.  */
2591             /* In C++, the name of a type is the corresponding typedef.
2592                In C, it is an IDENTIFIER_NODE.  */
2593             tree name = TYPE_NAME (type);
2594             if (TREE_CODE (name) == TYPE_DECL)
2595               name = DECL_NAME (name);
2596
2597             dbxout_begin_complex_stabs ();
2598             stabstr_I (name);
2599             stabstr_S (":T");
2600             dbxout_type (type, 1);
2601             dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2602             did_output = 1;
2603           }
2604
2605         /* If an enum type has no name, it cannot be referred to, but
2606            we must output it anyway, to record the enumeration
2607            constants.  */
2608
2609         if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2610           {
2611             dbxout_begin_complex_stabs ();
2612             /* Some debuggers fail when given NULL names, so give this a
2613                harmless name of " " (Why not "(anon)"?).  */
2614             stabstr_S (" :T");
2615             dbxout_type (type, 1);
2616             dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0);
2617           }
2618
2619         /* Prevent duplicate output of a typedef.  */
2620         TREE_ASM_WRITTEN (decl) = 1;
2621         break;
2622       }
2623
2624     case PARM_DECL:
2625       /* Parm decls go in their own separate chains
2626          and are output by dbxout_reg_parms and dbxout_parms.  */
2627       gcc_unreachable ();
2628
2629     case RESULT_DECL:
2630       /* Named return value, treat like a VAR_DECL.  */
2631     case VAR_DECL:
2632       if (! DECL_RTL_SET_P (decl))
2633         DBXOUT_DECR_NESTING_AND_RETURN (0);
2634       /* Don't mention a variable that is external.
2635          Let the file that defines it describe it.  */
2636       if (DECL_EXTERNAL (decl))
2637         break;
2638
2639       /* If the variable is really a constant
2640          and not written in memory, inform the debugger.
2641
2642          ??? Why do we skip emitting the type and location in this case?  */
2643       if (TREE_STATIC (decl) && TREE_READONLY (decl)
2644           && DECL_INITIAL (decl) != 0
2645           && host_integerp (DECL_INITIAL (decl), 0)
2646           && ! TREE_ASM_WRITTEN (decl)
2647           && (DECL_CONTEXT (decl) == NULL_TREE
2648               || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK)
2649           && TREE_PUBLIC (decl) == 0)
2650         {
2651           /* The sun4 assembler does not grok this.  */
2652
2653           if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2654               || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2655             {
2656               HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
2657
2658               dbxout_begin_complex_stabs ();
2659               stabstr_I (DECL_NAME (decl));
2660               stabstr_S (":c=i");
2661               stabstr_D (ival);
2662               dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0);
2663               DBXOUT_DECR_NESTING;
2664               return 1;
2665             }
2666           else
2667             break;
2668         }
2669       /* else it is something we handle like a normal variable.  */
2670
2671       SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2672 #ifdef LEAF_REG_REMAP
2673       if (current_function_uses_only_leaf_regs)
2674         leaf_renumber_regs_insn (DECL_RTL (decl));
2675 #endif
2676
2677       result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2678       break;
2679
2680     default:
2681       break;
2682     }
2683   DBXOUT_DECR_NESTING;
2684   return result;
2685 }
2686 \f
2687 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2688    Add SUFFIX to its name, if SUFFIX is not 0.
2689    Describe the variable as residing in HOME
2690    (usually HOME is DECL_RTL (DECL), but not always).
2691    Returns 1 if the stab was really emitted.  */
2692
2693 static int
2694 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2695 {
2696   int letter = 0;
2697   STAB_CODE_TYPE code;
2698   rtx addr = 0;
2699   int number = 0;
2700   int regno = -1;
2701
2702   /* Don't mention a variable at all
2703      if it was completely optimized into nothingness.
2704
2705      If the decl was from an inline function, then its rtl
2706      is not identically the rtl that was used in this
2707      particular compilation.  */
2708   if (GET_CODE (home) == SUBREG)
2709     {
2710       rtx value = home;
2711
2712       while (GET_CODE (value) == SUBREG)
2713         value = SUBREG_REG (value);
2714       if (REG_P (value))
2715         {
2716           if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2717             return 0;
2718         }
2719       home = alter_subreg (&home);
2720     }
2721   if (REG_P (home))
2722     {
2723       regno = REGNO (home);
2724       if (regno >= FIRST_PSEUDO_REGISTER)
2725         return 0;
2726     }
2727
2728   /* The kind-of-variable letter depends on where
2729      the variable is and on the scope of its name:
2730      G and N_GSYM for static storage and global scope,
2731      S for static storage and file scope,
2732      V for static storage and local scope,
2733      for those two, use N_LCSYM if data is in bss segment,
2734      N_STSYM if in data segment, N_FUN otherwise.
2735      (We used N_FUN originally, then changed to N_STSYM
2736      to please GDB.  However, it seems that confused ld.
2737      Now GDB has been fixed to like N_FUN, says Kingdon.)
2738      no letter at all, and N_LSYM, for auto variable,
2739      r and N_RSYM for register variable.  */
2740
2741   if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2742     {
2743       if (TREE_PUBLIC (decl))
2744         {
2745           letter = 'G';
2746           code = N_GSYM;
2747         }
2748       else
2749         {
2750           addr = XEXP (home, 0);
2751
2752           letter = decl_function_context (decl) ? 'V' : 'S';
2753
2754           /* Some ports can transform a symbol ref into a label ref,
2755              because the symbol ref is too far away and has to be
2756              dumped into a constant pool.  Alternatively, the symbol
2757              in the constant pool might be referenced by a different
2758              symbol.  */
2759           if (GET_CODE (addr) == SYMBOL_REF
2760               && CONSTANT_POOL_ADDRESS_P (addr))
2761             {
2762               bool marked;
2763               rtx tmp = get_pool_constant_mark (addr, &marked);
2764
2765               if (GET_CODE (tmp) == SYMBOL_REF)
2766                 {
2767                   addr = tmp;
2768                   if (CONSTANT_POOL_ADDRESS_P (addr))
2769                     get_pool_constant_mark (addr, &marked);
2770                   else
2771                     marked = true;
2772                 }
2773               else if (GET_CODE (tmp) == LABEL_REF)
2774                 {
2775                   addr = tmp;
2776                   marked = true;
2777                 }
2778
2779               /* If all references to the constant pool were optimized
2780                  out, we just ignore the symbol.  */
2781               if (!marked)
2782                 return 0;
2783             }
2784
2785           /* This should be the same condition as in assemble_variable, but
2786              we don't have access to dont_output_data here.  So, instead,
2787              we rely on the fact that error_mark_node initializers always
2788              end up in bss for C++ and never end up in bss for C.  */
2789           if (DECL_INITIAL (decl) == 0
2790               || (!strcmp (lang_hooks.name, "GNU C++")
2791                   && DECL_INITIAL (decl) == error_mark_node))
2792             code = N_LCSYM;
2793           else if (DECL_IN_TEXT_SECTION (decl))
2794             /* This is not quite right, but it's the closest
2795                of all the codes that Unix defines.  */
2796             code = DBX_STATIC_CONST_VAR_CODE;
2797           else
2798             {
2799               /* Ultrix `as' seems to need this.  */
2800 #ifdef DBX_STATIC_STAB_DATA_SECTION
2801               data_section ();
2802 #endif
2803               code = N_STSYM;
2804             }
2805         }
2806     }
2807   else if (regno >= 0)
2808     {
2809       letter = 'r';
2810       code = N_RSYM;
2811       number = DBX_REGISTER_NUMBER (regno);
2812     }
2813   else if (MEM_P (home)
2814            && (MEM_P (XEXP (home, 0))
2815                || (REG_P (XEXP (home, 0))
2816                    && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2817                    && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2818 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2819                    && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2820 #endif
2821                    )))
2822     /* If the value is indirect by memory or by a register
2823        that isn't the frame pointer
2824        then it means the object is variable-sized and address through
2825        that register or stack slot.  DBX has no way to represent this
2826        so all we can do is output the variable as a pointer.
2827        If it's not a parameter, ignore it.  */
2828     {
2829       if (REG_P (XEXP (home, 0)))
2830         {
2831           letter = 'r';
2832           code = N_RSYM;
2833           if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2834             return 0;
2835           number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2836         }
2837       else
2838         {
2839           code = N_LSYM;
2840           /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2841              We want the value of that CONST_INT.  */
2842           number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2843         }
2844
2845       /* Effectively do build_pointer_type, but don't cache this type,
2846          since it might be temporary whereas the type it points to
2847          might have been saved for inlining.  */
2848       /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
2849       type = make_node (POINTER_TYPE);
2850       TREE_TYPE (type) = TREE_TYPE (decl);
2851     }
2852   else if (MEM_P (home)
2853            && REG_P (XEXP (home, 0)))
2854     {
2855       code = N_LSYM;
2856       number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2857     }
2858   else if (MEM_P (home)
2859            && GET_CODE (XEXP (home, 0)) == PLUS
2860            && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2861     {
2862       code = N_LSYM;
2863       /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2864          We want the value of that CONST_INT.  */
2865       number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2866     }
2867   else if (MEM_P (home)
2868            && GET_CODE (XEXP (home, 0)) == CONST)
2869     {
2870       /* Handle an obscure case which can arise when optimizing and
2871          when there are few available registers.  (This is *always*
2872          the case for i386/i486 targets).  The RTL looks like
2873          (MEM (CONST ...)) even though this variable is a local `auto'
2874          or a local `register' variable.  In effect, what has happened
2875          is that the reload pass has seen that all assignments and
2876          references for one such a local variable can be replaced by
2877          equivalent assignments and references to some static storage
2878          variable, thereby avoiding the need for a register.  In such
2879          cases we're forced to lie to debuggers and tell them that
2880          this variable was itself `static'.  */
2881       code = N_LCSYM;
2882       letter = 'V';
2883       addr = XEXP (XEXP (home, 0), 0);
2884     }
2885   else if (GET_CODE (home) == CONCAT)
2886     {
2887       tree subtype;
2888
2889       /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2890          for example), then there is no easy way to figure out
2891          what SUBTYPE should be.  So, we give up.  */
2892       if (TREE_CODE (type) != COMPLEX_TYPE)
2893         return 0;
2894
2895       subtype = TREE_TYPE (type);
2896
2897       /* If the variable's storage is in two parts,
2898          output each as a separate stab with a modified name.  */
2899       if (WORDS_BIG_ENDIAN)
2900         dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2901       else
2902         dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2903
2904       if (WORDS_BIG_ENDIAN)
2905         dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2906       else
2907         dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2908       return 1;
2909     }
2910   else
2911     /* Address might be a MEM, when DECL is a variable-sized object.
2912        Or it might be const0_rtx, meaning previous passes
2913        want us to ignore this variable.  */
2914     return 0;
2915
2916   /* Ok, start a symtab entry and output the variable name.  */
2917   emit_pending_bincls_if_required ();
2918   FORCE_TEXT;
2919
2920 #ifdef DBX_STATIC_BLOCK_START
2921   DBX_STATIC_BLOCK_START (asm_out_file, code);
2922 #endif
2923
2924   dbxout_begin_complex_stabs_noforcetext ();
2925   dbxout_symbol_name (decl, suffix, letter);
2926   dbxout_type (type, 0);
2927   dbxout_finish_complex_stabs (decl, code, addr, 0, number);
2928
2929 #ifdef DBX_STATIC_BLOCK_END
2930   DBX_STATIC_BLOCK_END (asm_out_file, code);
2931 #endif
2932   return 1;
2933 }
2934 \f
2935 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2936    Then output LETTER to indicate the kind of location the symbol has.  */
2937
2938 static void
2939 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2940 {
2941   tree name;
2942
2943   if (DECL_CONTEXT (decl) 
2944       && (TYPE_P (DECL_CONTEXT (decl))
2945           || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
2946     /* One slight hitch: if this is a VAR_DECL which is a class member
2947        or a namespace member, we must put out the mangled name instead of the
2948        DECL_NAME.  Note also that static member (variable) names DO NOT begin
2949        with underscores in .stabs directives.  */
2950     name = DECL_ASSEMBLER_NAME (decl);
2951   else
2952     /* ...but if we're function-local, we don't want to include the junk
2953        added by ASM_FORMAT_PRIVATE_NAME.  */
2954     name = DECL_NAME (decl);
2955
2956   if (name)
2957     stabstr_I (name);
2958   else
2959     stabstr_S ("(anon)");
2960
2961   if (suffix)
2962     stabstr_S (suffix);
2963   stabstr_C (':');
2964   if (letter)
2965     stabstr_C (letter);
2966 }
2967
2968 /* Output definitions of all the decls in a chain. Return nonzero if
2969    anything was output */
2970
2971 int
2972 dbxout_syms (tree syms)
2973 {
2974   int result = 0;
2975   while (syms)
2976     {
2977       result += dbxout_symbol (syms, 1);
2978       syms = TREE_CHAIN (syms);
2979     }
2980   return result;
2981 }
2982 \f
2983 /* The following two functions output definitions of function parameters.
2984    Each parameter gets a definition locating it in the parameter list.
2985    Each parameter that is a register variable gets a second definition
2986    locating it in the register.
2987
2988    Printing or argument lists in gdb uses the definitions that
2989    locate in the parameter list.  But reference to the variable in
2990    expressions uses preferentially the definition as a register.  */
2991
2992 /* Output definitions, referring to storage in the parmlist,
2993    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
2994
2995 void
2996 dbxout_parms (tree parms)
2997 {
2998   ++debug_nesting;
2999   emit_pending_bincls_if_required ();
3000
3001   for (; parms; parms = TREE_CHAIN (parms))
3002     if (DECL_NAME (parms)
3003         && TREE_TYPE (parms) != error_mark_node
3004         && DECL_RTL_SET_P (parms)
3005         && DECL_INCOMING_RTL (parms))
3006       {
3007         tree eff_type;
3008         char letter;
3009         STAB_CODE_TYPE code;
3010         int number;
3011
3012         /* Perform any necessary register eliminations on the parameter's rtl,
3013            so that the debugging output will be accurate.  */
3014         DECL_INCOMING_RTL (parms)
3015           = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
3016         SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
3017 #ifdef LEAF_REG_REMAP
3018         if (current_function_uses_only_leaf_regs)
3019           {
3020             leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
3021             leaf_renumber_regs_insn (DECL_RTL (parms));
3022           }
3023 #endif
3024
3025         if (PARM_PASSED_IN_MEMORY (parms))
3026           {
3027             rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0);
3028
3029             /* ??? Here we assume that the parm address is indexed
3030                off the frame pointer or arg pointer.
3031                If that is not true, we produce meaningless results,
3032                but do not crash.  */
3033             if (GET_CODE (inrtl) == PLUS
3034                 && GET_CODE (XEXP (inrtl, 1)) == CONST_INT)
3035               number = INTVAL (XEXP (inrtl, 1));
3036             else
3037               number = 0;
3038
3039             code = N_PSYM;
3040             number = DEBUGGER_ARG_OFFSET (number, inrtl);
3041             letter = 'p';
3042
3043             /* It is quite tempting to use TREE_TYPE (parms) instead
3044                of DECL_ARG_TYPE (parms) for the eff_type, so that gcc
3045                reports the actual type of the parameter, rather than
3046                the promoted type.  This certainly makes GDB's life
3047                easier, at least for some ports.  The change is a bad
3048                idea however, since GDB expects to be able access the
3049                type without performing any conversions.  So for
3050                example, if we were passing a float to an unprototyped
3051                function, gcc will store a double on the stack, but if
3052                we emit a stab saying the type is a float, then gdb
3053                will only read in a single value, and this will produce
3054                an erroneous value.  */
3055             eff_type = DECL_ARG_TYPE (parms);
3056           }
3057         else if (REG_P (DECL_RTL (parms)))
3058           {
3059             rtx best_rtl;
3060
3061             /* Parm passed in registers and lives in registers or nowhere.  */
3062             code = DBX_REGPARM_STABS_CODE;
3063             letter = DBX_REGPARM_STABS_LETTER;
3064
3065             /* For parms passed in registers, it is better to use the
3066                declared type of the variable, not the type it arrived in.  */
3067             eff_type = TREE_TYPE (parms);
3068
3069             /* If parm lives in a register, use that register; pretend
3070                the parm was passed there.  It would be more consistent
3071                to describe the register where the parm was passed, but
3072                in practice that register usually holds something else.
3073                If the parm lives nowhere, use the register where it
3074                was passed.  */
3075             if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3076               best_rtl = DECL_RTL (parms);
3077             else
3078               best_rtl = DECL_INCOMING_RTL (parms);
3079
3080             number = DBX_REGISTER_NUMBER (REGNO (best_rtl));
3081           }
3082         else if (MEM_P (DECL_RTL (parms))
3083                  && REG_P (XEXP (DECL_RTL (parms), 0))
3084                  && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
3085                  && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
3086 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3087                  && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
3088 #endif
3089                  )
3090           {
3091             /* Parm was passed via invisible reference.
3092                That is, its address was passed in a register.
3093                Output it as if it lived in that register.
3094                The debugger will know from the type
3095                that it was actually passed by invisible reference.  */
3096
3097             code = DBX_REGPARM_STABS_CODE;
3098  
3099             /* GDB likes this marked with a special letter.  */
3100             letter = (use_gnu_debug_info_extensions
3101                       ? 'a' : DBX_REGPARM_STABS_LETTER);
3102             eff_type = TREE_TYPE (parms);
3103
3104             /* DECL_RTL looks like (MEM (REG...).  Get the register number.
3105                If it is an unallocated pseudo-reg, then use the register where
3106                it was passed instead.
3107                ??? Why is DBX_REGISTER_NUMBER not used here?  */
3108
3109             if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
3110               number = REGNO (XEXP (DECL_RTL (parms), 0));
3111             else
3112               number = REGNO (DECL_INCOMING_RTL (parms));
3113           }
3114         else if (MEM_P (DECL_RTL (parms))
3115                  && MEM_P (XEXP (DECL_RTL (parms), 0)))
3116           {
3117             /* Parm was passed via invisible reference, with the reference
3118                living on the stack.  DECL_RTL looks like
3119                (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
3120                could look like (MEM (MEM (REG))).  */
3121
3122             code = N_PSYM;
3123             letter = 'v';
3124             eff_type = TREE_TYPE (parms);
3125
3126             if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0)))
3127               number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
3128             else
3129               number = 0;
3130
3131             number = DEBUGGER_ARG_OFFSET (number,
3132                                           XEXP (XEXP (DECL_RTL (parms), 0), 0));
3133           }
3134         else if (MEM_P (DECL_RTL (parms))
3135                  && XEXP (DECL_RTL (parms), 0) != const0_rtx
3136                  /* ??? A constant address for a parm can happen
3137                     when the reg it lives in is equiv to a constant in memory.
3138                     Should make this not happen, after 2.4.  */
3139                  && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
3140           {
3141             /* Parm was passed in registers but lives on the stack.  */
3142
3143             code = N_PSYM;
3144             letter = 'p';
3145             eff_type = TREE_TYPE (parms);
3146
3147             /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
3148                in which case we want the value of that CONST_INT,
3149                or (MEM (REG ...)),
3150                in which case we use a value of zero.  */
3151             if (!REG_P (XEXP (DECL_RTL (parms), 0)))
3152               number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
3153             else
3154               number = 0;
3155
3156             /* Make a big endian correction if the mode of the type of the
3157                parameter is not the same as the mode of the rtl.  */
3158             if (BYTES_BIG_ENDIAN
3159                 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
3160                 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
3161               number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
3162                          - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))));
3163           }
3164         else
3165           /* ??? We don't know how to represent this argument.  */
3166           continue;
3167
3168         dbxout_begin_complex_stabs ();
3169             
3170         if (DECL_NAME (parms))
3171           {
3172             stabstr_I (DECL_NAME (parms));
3173             stabstr_C (':');
3174           }
3175         else
3176           stabstr_S ("(anon):");
3177         stabstr_C (letter);
3178         dbxout_type (eff_type, 0);
3179         dbxout_finish_complex_stabs (parms, code, 0, 0, number);
3180       }
3181   DBXOUT_DECR_NESTING;
3182 }
3183
3184 /* Output definitions for the places where parms live during the function,
3185    when different from where they were passed, when the parms were passed
3186    in memory.
3187
3188    It is not useful to do this for parms passed in registers
3189    that live during the function in different registers, because it is
3190    impossible to look in the passed register for the passed value,
3191    so we use the within-the-function register to begin with.
3192
3193    PARMS is a chain of PARM_DECL nodes.  */
3194
3195 void
3196 dbxout_reg_parms (tree parms)
3197 {
3198   ++debug_nesting;
3199
3200   for (; parms; parms = TREE_CHAIN (parms))
3201     if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3202       {
3203         /* Report parms that live in registers during the function
3204            but were passed in memory.  */
3205         if (REG_P (DECL_RTL (parms))
3206             && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3207           dbxout_symbol_location (parms, TREE_TYPE (parms),
3208                                   0, DECL_RTL (parms));
3209         else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3210           dbxout_symbol_location (parms, TREE_TYPE (parms),
3211                                   0, DECL_RTL (parms));
3212         /* Report parms that live in memory but not where they were passed.  */
3213         else if (MEM_P (DECL_RTL (parms))
3214                  && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3215           dbxout_symbol_location (parms, TREE_TYPE (parms),
3216                                   0, DECL_RTL (parms));
3217       }
3218   DBXOUT_DECR_NESTING;
3219 }
3220 \f
3221 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3222    output definitions of those names, in raw form */
3223
3224 static void
3225 dbxout_args (tree args)
3226 {
3227   while (args)
3228     {
3229       stabstr_C (',');
3230       dbxout_type (TREE_VALUE (args), 0);
3231       args = TREE_CHAIN (args);
3232     }
3233 }
3234 \f
3235 /* Subroutine of dbxout_block.  Emit an N_LBRAC stab referencing LABEL.
3236    BEGIN_LABEL is the name of the beginning of the function, which may
3237    be required.  */
3238 static void
3239 dbx_output_lbrac (const char *label,
3240                   const char *begin_label ATTRIBUTE_UNUSED)
3241 {
3242 #ifdef DBX_OUTPUT_LBRAC
3243   DBX_OUTPUT_LBRAC (asm_out_file, label);
3244 #else
3245   dbxout_begin_stabn (N_LBRAC);
3246   if (DBX_BLOCKS_FUNCTION_RELATIVE)
3247     dbxout_stab_value_label_diff (label, begin_label);
3248   else
3249     dbxout_stab_value_label (label);
3250 #endif
3251 }
3252
3253 /* Subroutine of dbxout_block.  Emit an N_RBRAC stab referencing LABEL.
3254    BEGIN_LABEL is the name of the beginning of the function, which may
3255    be required.  */
3256 static void
3257 dbx_output_rbrac (const char *label,
3258                   const char *begin_label ATTRIBUTE_UNUSED)
3259 {
3260 #ifdef DBX_OUTPUT_RBRAC
3261   DBX_OUTPUT_RBRAC (asm_out_file, label);
3262 #else
3263   dbxout_begin_stabn (N_RBRAC);
3264   if (DBX_BLOCKS_FUNCTION_RELATIVE)
3265     dbxout_stab_value_label_diff (label, begin_label);
3266   else
3267     dbxout_stab_value_label (label);
3268 #endif
3269 }
3270
3271 /* Output everything about a symbol block (a BLOCK node
3272    that represents a scope level),
3273    including recursive output of contained blocks.
3274
3275    BLOCK is the BLOCK node.
3276    DEPTH is its depth within containing symbol blocks.
3277    ARGS is usually zero; but for the outermost block of the
3278    body of a function, it is a chain of PARM_DECLs for the function parameters.
3279    We output definitions of all the register parms
3280    as if they were local variables of that block.
3281
3282    If -g1 was used, we count blocks just the same, but output nothing
3283    except for the outermost block.
3284
3285    Actually, BLOCK may be several blocks chained together.
3286    We handle them all in sequence.  */
3287
3288 static void
3289 dbxout_block (tree block, int depth, tree args)
3290 {
3291   const char *begin_label
3292     = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3293
3294   while (block)
3295     {
3296       /* Ignore blocks never expanded or otherwise marked as real.  */
3297       if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3298         {
3299           int did_output;
3300           int blocknum = BLOCK_NUMBER (block);
3301
3302           /* In dbx format, the syms of a block come before the N_LBRAC.
3303              If nothing is output, we don't need the N_LBRAC, either.  */
3304           did_output = 0;
3305           if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3306             did_output = dbxout_syms (BLOCK_VARS (block));
3307           if (args)
3308             dbxout_reg_parms (args);
3309
3310           /* Now output an N_LBRAC symbol to represent the beginning of
3311              the block.  Use the block's tree-walk order to generate
3312              the assembler symbols LBBn and LBEn
3313              that final will define around the code in this block.  */
3314           if (did_output)
3315             {
3316               char buf[20];
3317               const char *scope_start;
3318
3319               if (depth == 0)
3320                 /* The outermost block doesn't get LBB labels; use
3321                    the function symbol.  */
3322                 scope_start = begin_label;
3323               else
3324                 {
3325                   ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3326                   scope_start = buf;
3327                 }
3328
3329               if (BLOCK_HANDLER_BLOCK (block))
3330                 {
3331                   /* A catch block.  Must precede N_LBRAC.  */
3332                   tree decl = BLOCK_VARS (block);
3333                   while (decl)
3334                     {
3335                       dbxout_begin_complex_stabs ();
3336                       stabstr_I (DECL_NAME (decl));
3337                       stabstr_S (":C1");
3338                       dbxout_finish_complex_stabs (0, N_CATCH, 0,
3339                                                    scope_start, 0);
3340                       decl = TREE_CHAIN (decl);
3341                     }
3342                 }
3343               dbx_output_lbrac (scope_start, begin_label);
3344             }
3345
3346           /* Output the subblocks.  */
3347           dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3348
3349           /* Refer to the marker for the end of the block.  */
3350           if (did_output)
3351             {
3352               char buf[100];
3353               if (depth == 0)
3354                 /* The outermost block doesn't get LBE labels;
3355                    use the "scope" label which will be emitted
3356                    by dbxout_function_end.  */
3357                 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno);
3358               else
3359                 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3360
3361               dbx_output_rbrac (buf, begin_label);
3362             }
3363         }
3364       block = BLOCK_CHAIN (block);
3365     }
3366 }
3367
3368 /* Output the information about a function and its arguments and result.
3369    Usually this follows the function's code,
3370    but on some systems, it comes before.  */
3371
3372 #if defined (DBX_DEBUGGING_INFO)
3373 static void
3374 dbxout_begin_function (tree decl)
3375 {
3376   int saved_tree_used1;
3377
3378   if (DECL_IGNORED_P (decl))
3379     return;
3380
3381   saved_tree_used1 = TREE_USED (decl);
3382   TREE_USED (decl) = 1;
3383   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3384     {
3385       int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3386       TREE_USED (DECL_RESULT (decl)) = 1;
3387       dbxout_symbol (decl, 0);
3388       TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3389     }
3390   else
3391     dbxout_symbol (decl, 0);
3392   TREE_USED (decl) = saved_tree_used1;
3393
3394   dbxout_parms (DECL_ARGUMENTS (decl));
3395   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3396     dbxout_symbol (DECL_RESULT (decl), 1);
3397 }
3398 #endif /* DBX_DEBUGGING_INFO */
3399
3400 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3401
3402 #include "gt-dbxout.h"