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