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