OSDN Git Service

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