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