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