OSDN Git Service

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