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