]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/dwarfout.c
getopt.h (getopt): Also check HAVE_DECL_* when prototyping.
[thirdparty/gcc.git] / gcc / dwarfout.c
CommitLineData
ed1817c6 1/* Output Dwarf format symbol table information from the GNU C compiler.
ef58a523
JL
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
461b77c8 4 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
ed1817c6 5
340ccaab
TW
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13GNU CC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU CC; see the file COPYING. If not, write to
940d9d63
RK
20the Free Software Foundation, 59 Temple Place - Suite 330,
21Boston, MA 02111-1307, USA. */
340ccaab
TW
22
23#include "config.h"
24
9a666dda 25#ifdef DWARF_DEBUGGING_INFO
670ee920 26#include "system.h"
340ccaab
TW
27#include "dwarf.h"
28#include "tree.h"
29#include "flags.h"
30#include "rtl.h"
7f7429ca 31#include "hard-reg-set.h"
340ccaab
TW
32#include "insn-config.h"
33#include "reload.h"
34#include "output.h"
9a631e8e 35#include "defaults.h"
76ead72b 36#include "dwarfout.h"
f103890b 37#include "toplev.h"
272df862 38#include "tm_p.h"
340ccaab 39
c85f7c16
JL
40/* We cannot use <assert.h> in GCC source, since that would include
41 GCC's assert.h, which may not be compatible with the host compiler. */
42#undef assert
43#ifdef NDEBUG
44# define assert(e)
45#else
46# define assert(e) do { if (! (e)) abort (); } while (0)
47#endif
48
340ccaab
TW
49/* IMPORTANT NOTE: Please see the file README.DWARF for important details
50 regarding the GNU implementation of Dwarf. */
51
52/* NOTE: In the comments in this file, many references are made to
53 so called "Debugging Information Entries". For the sake of brevity,
54 this term is abbreviated to `DIE' throughout the remainder of this
55 file. */
56
57/* Note that the implementation of C++ support herein is (as yet) unfinished.
58 If you want to try to complete it, more power to you. */
59
340ccaab
TW
60/* How to start an assembler comment. */
61#ifndef ASM_COMMENT_START
62#define ASM_COMMENT_START ";#"
63#endif
64
7f7429ca
RS
65/* How to print out a register name. */
66#ifndef PRINT_REG
67#define PRINT_REG(RTX, CODE, FILE) \
68 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
69#endif
70
340ccaab
TW
71/* Define a macro which returns non-zero for any tagged type which is
72 used (directly or indirectly) in the specification of either some
73 function's return type or some formal parameter of some function.
74 We use this macro when we are operating in "terse" mode to help us
75 know what tagged types have to be represented in Dwarf (even in
76 terse mode) and which ones don't.
77
78 A flag bit with this meaning really should be a part of the normal
79 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
80 for these nodes. For now, we have to just fake it. It it safe for
81 us to simply return zero for all complete tagged types (which will
82 get forced out anyway if they were used in the specification of some
83 formal or return type) and non-zero for all incomplete tagged types.
84*/
85
86#define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
87
a94dbf2c
JM
88/* Define a macro which returns non-zero for a TYPE_DECL which was
89 implicitly generated for a tagged type.
90
91 Note that unlike the gcc front end (which generates a NULL named
92 TYPE_DECL node for each complete tagged type, each array type, and
93 each function type node created) the g++ front end generates a
94 _named_ TYPE_DECL node for each tagged type node created.
95 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
96 generate a DW_TAG_typedef DIE for them. */
97#define TYPE_DECL_IS_STUB(decl) \
98 (DECL_NAME (decl) == NULL \
99 || (DECL_ARTIFICIAL (decl) \
100 && is_tagged_type (TREE_TYPE (decl)) \
101 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
102
340ccaab 103extern int flag_traditional;
340ccaab
TW
104
105/* Maximum size (in bytes) of an artificially generated label. */
106
107#define MAX_ARTIFICIAL_LABEL_BYTES 30
108\f
109/* Make sure we know the sizes of the various types dwarf can describe.
110 These are only defaults. If the sizes are different for your target,
111 you should override these values by defining the appropriate symbols
112 in your tm.h file. */
113
114#ifndef CHAR_TYPE_SIZE
115#define CHAR_TYPE_SIZE BITS_PER_UNIT
116#endif
117
118#ifndef SHORT_TYPE_SIZE
c294bd99 119#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
340ccaab
TW
120#endif
121
122#ifndef INT_TYPE_SIZE
123#define INT_TYPE_SIZE BITS_PER_WORD
124#endif
125
126#ifndef LONG_TYPE_SIZE
127#define LONG_TYPE_SIZE BITS_PER_WORD
128#endif
129
130#ifndef LONG_LONG_TYPE_SIZE
131#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
132#endif
133
134#ifndef WCHAR_TYPE_SIZE
135#define WCHAR_TYPE_SIZE INT_TYPE_SIZE
136#endif
137
138#ifndef WCHAR_UNSIGNED
139#define WCHAR_UNSIGNED 0
140#endif
141
142#ifndef FLOAT_TYPE_SIZE
143#define FLOAT_TYPE_SIZE BITS_PER_WORD
144#endif
145
146#ifndef DOUBLE_TYPE_SIZE
147#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
148#endif
149
150#ifndef LONG_DOUBLE_TYPE_SIZE
151#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
152#endif
153\f
154/* Structure to keep track of source filenames. */
155
156struct filename_entry {
157 unsigned number;
d3e3972c 158 const char * name;
340ccaab
TW
159};
160
161typedef struct filename_entry filename_entry;
162
0f41302f 163/* Pointer to an array of elements, each one having the structure above. */
340ccaab
TW
164
165static filename_entry *filename_table;
166
167/* Total number of entries in the table (i.e. array) pointed to by
168 `filename_table'. This is the *total* and includes both used and
169 unused slots. */
170
171static unsigned ft_entries_allocated;
172
173/* Number of entries in the filename_table which are actually in use. */
174
175static unsigned ft_entries;
176
177/* Size (in elements) of increments by which we may expand the filename
178 table. Actually, a single hunk of space of this size should be enough
179 for most typical programs. */
180
181#define FT_ENTRIES_INCREMENT 64
182
183/* Local pointer to the name of the main input file. Initialized in
184 dwarfout_init. */
185
d3e3972c 186static const char *primary_filename;
340ccaab
TW
187
188/* Pointer to the most recent filename for which we produced some line info. */
189
d3e3972c 190static const char *last_filename;
340ccaab 191
0f41302f 192/* Counter to generate unique names for DIEs. */
340ccaab
TW
193
194static unsigned next_unused_dienum = 1;
195
196/* Number of the DIE which is currently being generated. */
197
198static unsigned current_dienum;
199
200/* Number to use for the special "pubname" label on the next DIE which
201 represents a function or data object defined in this compilation
202 unit which has "extern" linkage. */
203
5e9defae 204static int next_pubname_number = 0;
340ccaab
TW
205
206#define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
207
208/* Pointer to a dynamically allocated list of pre-reserved and still
209 pending sibling DIE numbers. Note that this list will grow as needed. */
210
211static unsigned *pending_sibling_stack;
212
213/* Counter to keep track of the number of pre-reserved and still pending
214 sibling DIE numbers. */
215
216static unsigned pending_siblings;
217
218/* The currently allocated size of the above list (expressed in number of
219 list elements). */
220
221static unsigned pending_siblings_allocated;
222
223/* Size (in elements) of increments by which we may expand the pending
224 sibling stack. Actually, a single hunk of space of this size should
225 be enough for most typical programs. */
226
227#define PENDING_SIBLINGS_INCREMENT 64
228
229/* Non-zero if we are performing our file-scope finalization pass and if
6dc42e49 230 we should force out Dwarf descriptions of any and all file-scope
340ccaab
TW
231 tagged types which are still incomplete types. */
232
233static int finalizing = 0;
234
235/* A pointer to the base of a list of pending types which we haven't
236 generated DIEs for yet, but which we will have to come back to
237 later on. */
238
239static tree *pending_types_list;
240
241/* Number of elements currently allocated for the pending_types_list. */
242
243static unsigned pending_types_allocated;
244
245/* Number of elements of pending_types_list currently in use. */
246
247static unsigned pending_types;
248
249/* Size (in elements) of increments by which we may expand the pending
250 types list. Actually, a single hunk of space of this size should
251 be enough for most typical programs. */
252
253#define PENDING_TYPES_INCREMENT 64
254
75c613db
JM
255/* A pointer to the base of a list of incomplete types which might be
256 completed at some later time. */
257
258static tree *incomplete_types_list;
259
260/* Number of elements currently allocated for the incomplete_types_list. */
261static unsigned incomplete_types_allocated;
262
263/* Number of elements of incomplete_types_list currently in use. */
264static unsigned incomplete_types;
265
266/* Size (in elements) of increments by which we may expand the incomplete
267 types list. Actually, a single hunk of space of this size should
268 be enough for most typical programs. */
269#define INCOMPLETE_TYPES_INCREMENT 64
270
6dc42e49 271/* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
340ccaab
TW
272 This is used in a hack to help us get the DIEs describing types of
273 formal parameters to come *after* all of the DIEs describing the formal
274 parameters themselves. That's necessary in order to be compatible
6dc42e49 275 with what the brain-damaged svr4 SDB debugger requires. */
340ccaab
TW
276
277static tree fake_containing_scope;
278
279/* The number of the current function definition that we are generating
280 debugging information for. These numbers range from 1 up to the maximum
281 number of function definitions contained within the current compilation
282 unit. These numbers are used to create unique labels for various things
283 contained within various function definitions. */
284
285static unsigned current_funcdef_number = 1;
286
7f7429ca
RS
287/* A pointer to the ..._DECL node which we have most recently been working
288 on. We keep this around just in case something about it looks screwy
289 and we want to tell the user what the source coordinates for the actual
290 declaration are. */
291
292static tree dwarf_last_decl;
293
a94dbf2c
JM
294/* A flag indicating that we are emitting the member declarations of a
295 class, so member functions and variables should not be entirely emitted.
296 This is a kludge to avoid passing a second argument to output_*_die. */
297
298static int in_class;
299
340ccaab
TW
300/* Forward declarations for functions defined in this file. */
301
83d2b3b9
KG
302static const char *dwarf_tag_name PARAMS ((unsigned));
303static const char *dwarf_attr_name PARAMS ((unsigned));
304static const char *dwarf_stack_op_name PARAMS ((unsigned));
305static const char *dwarf_typemod_name PARAMS ((unsigned));
306static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
307static const char *dwarf_fund_type_name PARAMS ((unsigned));
308static tree decl_ultimate_origin PARAMS ((tree));
309static tree block_ultimate_origin PARAMS ((tree));
310static tree decl_class_context PARAMS ((tree));
487a6e06 311#if 0
83d2b3b9
KG
312static void output_unsigned_leb128 PARAMS ((unsigned long));
313static void output_signed_leb128 PARAMS ((long));
487a6e06 314#endif
83d2b3b9
KG
315static int fundamental_type_code PARAMS ((tree));
316static tree root_type_1 PARAMS ((tree, int));
317static tree root_type PARAMS ((tree));
318static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
319static void write_modifier_bytes PARAMS ((tree, int, int));
320static inline int type_is_fundamental PARAMS ((tree));
321static void equate_decl_number_to_die_number PARAMS ((tree));
322static inline void equate_type_number_to_die_number PARAMS ((tree));
323static void output_reg_number PARAMS ((rtx));
324static void output_mem_loc_descriptor PARAMS ((rtx));
325static void output_loc_descriptor PARAMS ((rtx));
326static void output_bound_representation PARAMS ((tree, unsigned, int));
327static void output_enumeral_list PARAMS ((tree));
665f2503 328static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
83d2b3b9 329static inline tree field_type PARAMS ((tree));
665f2503
RK
330static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
331static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
332static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
83d2b3b9
KG
333static inline void sibling_attribute PARAMS ((void));
334static void location_attribute PARAMS ((rtx));
335static void data_member_location_attribute PARAMS ((tree));
336static void const_value_attribute PARAMS ((rtx));
337static void location_or_const_value_attribute PARAMS ((tree));
338static inline void name_attribute PARAMS ((const char *));
339static inline void fund_type_attribute PARAMS ((unsigned));
340static void mod_fund_type_attribute PARAMS ((tree, int, int));
341static inline void user_def_type_attribute PARAMS ((tree));
342static void mod_u_d_type_attribute PARAMS ((tree, int, int));
5e9defae 343#ifdef USE_ORDERING_ATTRIBUTE
83d2b3b9 344static inline void ordering_attribute PARAMS ((unsigned));
5e9defae 345#endif /* defined(USE_ORDERING_ATTRIBUTE) */
83d2b3b9
KG
346static void subscript_data_attribute PARAMS ((tree));
347static void byte_size_attribute PARAMS ((tree));
348static inline void bit_offset_attribute PARAMS ((tree));
349static inline void bit_size_attribute PARAMS ((tree));
350static inline void element_list_attribute PARAMS ((tree));
351static inline void stmt_list_attribute PARAMS ((const char *));
352static inline void low_pc_attribute PARAMS ((const char *));
353static inline void high_pc_attribute PARAMS ((const char *));
354static inline void body_begin_attribute PARAMS ((const char *));
355static inline void body_end_attribute PARAMS ((const char *));
356static inline void language_attribute PARAMS ((unsigned));
357static inline void member_attribute PARAMS ((tree));
7a87758d 358#if 0
83d2b3b9 359static inline void string_length_attribute PARAMS ((tree));
7a87758d 360#endif
83d2b3b9
KG
361static inline void comp_dir_attribute PARAMS ((const char *));
362static inline void sf_names_attribute PARAMS ((const char *));
363static inline void src_info_attribute PARAMS ((const char *));
364static inline void mac_info_attribute PARAMS ((const char *));
365static inline void prototyped_attribute PARAMS ((tree));
366static inline void producer_attribute PARAMS ((const char *));
367static inline void inline_attribute PARAMS ((tree));
368static inline void containing_type_attribute PARAMS ((tree));
369static inline void abstract_origin_attribute PARAMS ((tree));
5e9defae 370#ifdef DWARF_DECL_COORDINATES
83d2b3b9 371static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
5e9defae 372#endif /* defined(DWARF_DECL_COORDINATES) */
83d2b3b9
KG
373static inline void pure_or_virtual_attribute PARAMS ((tree));
374static void name_and_src_coords_attributes PARAMS ((tree));
375static void type_attribute PARAMS ((tree, int, int));
d3e3972c 376static const char *type_tag PARAMS ((tree));
83d2b3b9
KG
377static inline void dienum_push PARAMS ((void));
378static inline void dienum_pop PARAMS ((void));
379static inline tree member_declared_type PARAMS ((tree));
3cce094d 380static const char *function_start_label PARAMS ((tree));
83d2b3b9
KG
381static void output_array_type_die PARAMS ((void *));
382static void output_set_type_die PARAMS ((void *));
5e9defae 383#if 0
83d2b3b9 384static void output_entry_point_die PARAMS ((void *));
5e9defae 385#endif
83d2b3b9
KG
386static void output_inlined_enumeration_type_die PARAMS ((void *));
387static void output_inlined_structure_type_die PARAMS ((void *));
388static void output_inlined_union_type_die PARAMS ((void *));
389static void output_enumeration_type_die PARAMS ((void *));
390static void output_formal_parameter_die PARAMS ((void *));
391static void output_global_subroutine_die PARAMS ((void *));
392static void output_global_variable_die PARAMS ((void *));
393static void output_label_die PARAMS ((void *));
394static void output_lexical_block_die PARAMS ((void *));
395static void output_inlined_subroutine_die PARAMS ((void *));
396static void output_local_variable_die PARAMS ((void *));
397static void output_member_die PARAMS ((void *));
5e9defae 398#if 0
83d2b3b9
KG
399static void output_pointer_type_die PARAMS ((void *));
400static void output_reference_type_die PARAMS ((void *));
5e9defae 401#endif
83d2b3b9
KG
402static void output_ptr_to_mbr_type_die PARAMS ((void *));
403static void output_compile_unit_die PARAMS ((void *));
404static void output_string_type_die PARAMS ((void *));
405static void output_inheritance_die PARAMS ((void *));
406static void output_structure_type_die PARAMS ((void *));
407static void output_local_subroutine_die PARAMS ((void *));
408static void output_subroutine_type_die PARAMS ((void *));
409static void output_typedef_die PARAMS ((void *));
410static void output_union_type_die PARAMS ((void *));
411static void output_unspecified_parameters_die PARAMS ((void *));
412static void output_padded_null_die PARAMS ((void *));
413static void output_die PARAMS ((void (*)(void *), void *));
414static void end_sibling_chain PARAMS ((void));
415static void output_formal_types PARAMS ((tree));
416static void pend_type PARAMS ((tree));
417static int type_ok_for_scope PARAMS ((tree, tree));
418static void output_pending_types_for_scope PARAMS ((tree));
419static void output_type PARAMS ((tree, tree));
420static void output_tagged_type_instantiation PARAMS ((tree));
421static void output_block PARAMS ((tree, int));
422static void output_decls_for_scope PARAMS ((tree, int));
423static void output_decl PARAMS ((tree, tree));
424static void shuffle_filename_entry PARAMS ((filename_entry *));
425static void generate_new_sfname_entry PARAMS ((void));
426static unsigned lookup_filename PARAMS ((const char *));
427static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
428static void generate_macinfo_entry PARAMS ((const char *, const char *));
429static int is_pseudo_reg PARAMS ((rtx));
430static tree type_main_variant PARAMS ((tree));
431static int is_tagged_type PARAMS ((tree));
432static int is_redundant_typedef PARAMS ((tree));
433static void add_incomplete_type PARAMS ((tree));
434static void retry_incomplete_types PARAMS ((void));
340ccaab
TW
435\f
436/* Definitions of defaults for assembler-dependent names of various
437 pseudo-ops and section names.
438
439 Theses may be overridden in your tm.h file (if necessary) for your
440 particular assembler. The default values provided here correspond to
441 what is expected by "standard" AT&T System V.4 assemblers. */
442
443#ifndef FILE_ASM_OP
2e494f70 444#define FILE_ASM_OP ".file"
340ccaab
TW
445#endif
446#ifndef VERSION_ASM_OP
2e494f70 447#define VERSION_ASM_OP ".version"
340ccaab 448#endif
340ccaab 449#ifndef UNALIGNED_SHORT_ASM_OP
2e494f70 450#define UNALIGNED_SHORT_ASM_OP ".2byte"
340ccaab
TW
451#endif
452#ifndef UNALIGNED_INT_ASM_OP
2e494f70 453#define UNALIGNED_INT_ASM_OP ".4byte"
340ccaab 454#endif
9a631e8e
RS
455#ifndef ASM_BYTE_OP
456#define ASM_BYTE_OP ".byte"
457#endif
648ebe7b
RS
458#ifndef SET_ASM_OP
459#define SET_ASM_OP ".set"
340ccaab 460#endif
85595d1a
RS
461
462/* Pseudo-ops for pushing the current section onto the section stack (and
463 simultaneously changing to a new section) and for poping back to the
464 section we were in immediately before this one. Note that most svr4
465 assemblers only maintain a one level stack... you can push all the
466 sections you want, but you can only pop out one level. (The sparc
648ebe7b 467 svr4 assembler is an exception to this general rule.) That's
85595d1a
RS
468 OK because we only use at most one level of the section stack herein. */
469
470#ifndef PUSHSECTION_ASM_OP
9a631e8e 471#define PUSHSECTION_ASM_OP ".section"
85595d1a
RS
472#endif
473#ifndef POPSECTION_ASM_OP
9a631e8e 474#define POPSECTION_ASM_OP ".previous"
85595d1a
RS
475#endif
476
477/* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
478 to print the PUSHSECTION_ASM_OP and the section name. The default here
479 works for almost all svr4 assemblers, except for the sparc, where the
480 section name must be enclosed in double quotes. (See sparcv4.h.) */
481
482#ifndef PUSHSECTION_FORMAT
dfe8a5ac 483#define PUSHSECTION_FORMAT "\t%s\t%s\n"
85595d1a
RS
484#endif
485
486#ifndef DEBUG_SECTION
487#define DEBUG_SECTION ".debug"
488#endif
489#ifndef LINE_SECTION
490#define LINE_SECTION ".line"
491#endif
492#ifndef SFNAMES_SECTION
493#define SFNAMES_SECTION ".debug_sfnames"
494#endif
495#ifndef SRCINFO_SECTION
496#define SRCINFO_SECTION ".debug_srcinfo"
497#endif
498#ifndef MACINFO_SECTION
499#define MACINFO_SECTION ".debug_macinfo"
500#endif
501#ifndef PUBNAMES_SECTION
502#define PUBNAMES_SECTION ".debug_pubnames"
503#endif
504#ifndef ARANGES_SECTION
505#define ARANGES_SECTION ".debug_aranges"
506#endif
507#ifndef TEXT_SECTION
508#define TEXT_SECTION ".text"
509#endif
510#ifndef DATA_SECTION
511#define DATA_SECTION ".data"
512#endif
513#ifndef DATA1_SECTION
514#define DATA1_SECTION ".data1"
515#endif
516#ifndef RODATA_SECTION
517#define RODATA_SECTION ".rodata"
518#endif
519#ifndef RODATA1_SECTION
520#define RODATA1_SECTION ".rodata1"
521#endif
522#ifndef BSS_SECTION
523#define BSS_SECTION ".bss"
524#endif
340ccaab
TW
525\f
526/* Definitions of defaults for formats and names of various special
527 (artificial) labels which may be generated within this file (when
528 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
529
530 If necessary, these may be overridden from within your tm.h file,
9a631e8e
RS
531 but typically, you should never need to override these.
532
533 These labels have been hacked (temporarily) so that they all begin with
648ebe7b
RS
534 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
535 stock m88k/svr4 assembler, both of which need to see .L at the start of
536 a label in order to prevent that label from going into the linker symbol
537 table). When I get time, I'll have to fix this the right way so that we
538 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
539 but that will require a rather massive set of changes. For the moment,
540 the following definitions out to produce the right results for all svr4
541 and svr3 assemblers. -- rfg
9a631e8e 542*/
340ccaab
TW
543
544#ifndef TEXT_BEGIN_LABEL
e9a25f70 545#define TEXT_BEGIN_LABEL "*.L_text_b"
340ccaab
TW
546#endif
547#ifndef TEXT_END_LABEL
e9a25f70 548#define TEXT_END_LABEL "*.L_text_e"
340ccaab
TW
549#endif
550
551#ifndef DATA_BEGIN_LABEL
e9a25f70 552#define DATA_BEGIN_LABEL "*.L_data_b"
340ccaab
TW
553#endif
554#ifndef DATA_END_LABEL
e9a25f70 555#define DATA_END_LABEL "*.L_data_e"
340ccaab
TW
556#endif
557
558#ifndef DATA1_BEGIN_LABEL
e9a25f70 559#define DATA1_BEGIN_LABEL "*.L_data1_b"
340ccaab
TW
560#endif
561#ifndef DATA1_END_LABEL
e9a25f70 562#define DATA1_END_LABEL "*.L_data1_e"
340ccaab
TW
563#endif
564
565#ifndef RODATA_BEGIN_LABEL
e9a25f70 566#define RODATA_BEGIN_LABEL "*.L_rodata_b"
340ccaab
TW
567#endif
568#ifndef RODATA_END_LABEL
e9a25f70 569#define RODATA_END_LABEL "*.L_rodata_e"
340ccaab
TW
570#endif
571
572#ifndef RODATA1_BEGIN_LABEL
e9a25f70 573#define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
340ccaab
TW
574#endif
575#ifndef RODATA1_END_LABEL
e9a25f70 576#define RODATA1_END_LABEL "*.L_rodata1_e"
340ccaab
TW
577#endif
578
579#ifndef BSS_BEGIN_LABEL
e9a25f70 580#define BSS_BEGIN_LABEL "*.L_bss_b"
340ccaab
TW
581#endif
582#ifndef BSS_END_LABEL
e9a25f70 583#define BSS_END_LABEL "*.L_bss_e"
340ccaab
TW
584#endif
585
586#ifndef LINE_BEGIN_LABEL
e9a25f70 587#define LINE_BEGIN_LABEL "*.L_line_b"
340ccaab
TW
588#endif
589#ifndef LINE_LAST_ENTRY_LABEL
e9a25f70 590#define LINE_LAST_ENTRY_LABEL "*.L_line_last"
340ccaab
TW
591#endif
592#ifndef LINE_END_LABEL
e9a25f70 593#define LINE_END_LABEL "*.L_line_e"
340ccaab
TW
594#endif
595
596#ifndef DEBUG_BEGIN_LABEL
e9a25f70 597#define DEBUG_BEGIN_LABEL "*.L_debug_b"
340ccaab
TW
598#endif
599#ifndef SFNAMES_BEGIN_LABEL
e9a25f70 600#define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
340ccaab
TW
601#endif
602#ifndef SRCINFO_BEGIN_LABEL
e9a25f70 603#define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
340ccaab
TW
604#endif
605#ifndef MACINFO_BEGIN_LABEL
e9a25f70 606#define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
340ccaab
TW
607#endif
608
609#ifndef DIE_BEGIN_LABEL_FMT
e9a25f70 610#define DIE_BEGIN_LABEL_FMT "*.L_D%u"
340ccaab
TW
611#endif
612#ifndef DIE_END_LABEL_FMT
e9a25f70 613#define DIE_END_LABEL_FMT "*.L_D%u_e"
340ccaab
TW
614#endif
615#ifndef PUB_DIE_LABEL_FMT
e9a25f70 616#define PUB_DIE_LABEL_FMT "*.L_P%u"
340ccaab
TW
617#endif
618#ifndef INSN_LABEL_FMT
e9a25f70 619#define INSN_LABEL_FMT "*.L_I%u_%u"
340ccaab
TW
620#endif
621#ifndef BLOCK_BEGIN_LABEL_FMT
e9a25f70 622#define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
340ccaab
TW
623#endif
624#ifndef BLOCK_END_LABEL_FMT
e9a25f70 625#define BLOCK_END_LABEL_FMT "*.L_B%u_e"
340ccaab
TW
626#endif
627#ifndef SS_BEGIN_LABEL_FMT
e9a25f70 628#define SS_BEGIN_LABEL_FMT "*.L_s%u"
340ccaab
TW
629#endif
630#ifndef SS_END_LABEL_FMT
e9a25f70 631#define SS_END_LABEL_FMT "*.L_s%u_e"
340ccaab
TW
632#endif
633#ifndef EE_BEGIN_LABEL_FMT
e9a25f70 634#define EE_BEGIN_LABEL_FMT "*.L_e%u"
340ccaab
TW
635#endif
636#ifndef EE_END_LABEL_FMT
e9a25f70 637#define EE_END_LABEL_FMT "*.L_e%u_e"
340ccaab
TW
638#endif
639#ifndef MT_BEGIN_LABEL_FMT
e9a25f70 640#define MT_BEGIN_LABEL_FMT "*.L_t%u"
340ccaab
TW
641#endif
642#ifndef MT_END_LABEL_FMT
e9a25f70 643#define MT_END_LABEL_FMT "*.L_t%u_e"
340ccaab
TW
644#endif
645#ifndef LOC_BEGIN_LABEL_FMT
e9a25f70 646#define LOC_BEGIN_LABEL_FMT "*.L_l%u"
340ccaab
TW
647#endif
648#ifndef LOC_END_LABEL_FMT
e9a25f70 649#define LOC_END_LABEL_FMT "*.L_l%u_e"
340ccaab
TW
650#endif
651#ifndef BOUND_BEGIN_LABEL_FMT
e9a25f70 652#define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
340ccaab
TW
653#endif
654#ifndef BOUND_END_LABEL_FMT
e9a25f70 655#define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
340ccaab
TW
656#endif
657#ifndef DERIV_BEGIN_LABEL_FMT
e9a25f70 658#define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
340ccaab
TW
659#endif
660#ifndef DERIV_END_LABEL_FMT
e9a25f70 661#define DERIV_END_LABEL_FMT "*.L_d%u_e"
340ccaab
TW
662#endif
663#ifndef SL_BEGIN_LABEL_FMT
e9a25f70 664#define SL_BEGIN_LABEL_FMT "*.L_sl%u"
340ccaab
TW
665#endif
666#ifndef SL_END_LABEL_FMT
e9a25f70 667#define SL_END_LABEL_FMT "*.L_sl%u_e"
340ccaab 668#endif
2a819d04 669#ifndef BODY_BEGIN_LABEL_FMT
e9a25f70 670#define BODY_BEGIN_LABEL_FMT "*.L_b%u"
2a819d04
TW
671#endif
672#ifndef BODY_END_LABEL_FMT
e9a25f70 673#define BODY_END_LABEL_FMT "*.L_b%u_e"
2a819d04 674#endif
340ccaab 675#ifndef FUNC_END_LABEL_FMT
e9a25f70 676#define FUNC_END_LABEL_FMT "*.L_f%u_e"
340ccaab
TW
677#endif
678#ifndef TYPE_NAME_FMT
e9a25f70 679#define TYPE_NAME_FMT "*.L_T%u"
340ccaab 680#endif
04077c53 681#ifndef DECL_NAME_FMT
e9a25f70 682#define DECL_NAME_FMT "*.L_E%u"
04077c53 683#endif
340ccaab 684#ifndef LINE_CODE_LABEL_FMT
e9a25f70 685#define LINE_CODE_LABEL_FMT "*.L_LC%u"
340ccaab
TW
686#endif
687#ifndef SFNAMES_ENTRY_LABEL_FMT
e9a25f70 688#define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
340ccaab
TW
689#endif
690#ifndef LINE_ENTRY_LABEL_FMT
e9a25f70 691#define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
340ccaab
TW
692#endif
693\f
694/* Definitions of defaults for various types of primitive assembly language
695 output operations.
696
697 If necessary, these may be overridden from within your tm.h file,
609380f6 698 but typically, you shouldn't need to override these. */
85595d1a
RS
699
700#ifndef ASM_OUTPUT_PUSH_SECTION
701#define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
702 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
703#endif
704
705#ifndef ASM_OUTPUT_POP_SECTION
706#define ASM_OUTPUT_POP_SECTION(FILE) \
9a631e8e 707 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
85595d1a 708#endif
340ccaab 709
340ccaab
TW
710#ifndef ASM_OUTPUT_DWARF_DELTA2
711#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
2e494f70 712 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
340ccaab
TW
713 assemble_name (FILE, LABEL1); \
714 fprintf (FILE, "-"); \
715 assemble_name (FILE, LABEL2); \
716 fprintf (FILE, "\n"); \
717 } while (0)
718#endif
719
720#ifndef ASM_OUTPUT_DWARF_DELTA4
721#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
2e494f70 722 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
723 assemble_name (FILE, LABEL1); \
724 fprintf (FILE, "-"); \
725 assemble_name (FILE, LABEL2); \
726 fprintf (FILE, "\n"); \
727 } while (0)
728#endif
729
730#ifndef ASM_OUTPUT_DWARF_TAG
731#define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
9a631e8e
RS
732 do { \
733 fprintf ((FILE), "\t%s\t0x%x", \
734 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
c773653b 735 if (flag_debug_asm) \
9a631e8e
RS
736 fprintf ((FILE), "\t%s %s", \
737 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
738 fputc ('\n', (FILE)); \
739 } while (0)
340ccaab
TW
740#endif
741
742#ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
9a631e8e
RS
743#define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
744 do { \
745 fprintf ((FILE), "\t%s\t0x%x", \
746 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
c773653b 747 if (flag_debug_asm) \
9a631e8e
RS
748 fprintf ((FILE), "\t%s %s", \
749 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
750 fputc ('\n', (FILE)); \
751 } while (0)
340ccaab
TW
752#endif
753
754#ifndef ASM_OUTPUT_DWARF_STACK_OP
755#define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
9a631e8e 756 do { \
648ebe7b 757 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
c773653b 758 if (flag_debug_asm) \
9a631e8e
RS
759 fprintf ((FILE), "\t%s %s", \
760 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
761 fputc ('\n', (FILE)); \
762 } while (0)
340ccaab
TW
763#endif
764
765#ifndef ASM_OUTPUT_DWARF_FUND_TYPE
766#define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
9a631e8e
RS
767 do { \
768 fprintf ((FILE), "\t%s\t0x%x", \
769 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
c773653b 770 if (flag_debug_asm) \
9a631e8e
RS
771 fprintf ((FILE), "\t%s %s", \
772 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
773 fputc ('\n', (FILE)); \
774 } while (0)
340ccaab
TW
775#endif
776
777#ifndef ASM_OUTPUT_DWARF_FMT_BYTE
778#define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
9a631e8e 779 do { \
648ebe7b 780 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
c773653b 781 if (flag_debug_asm) \
9a631e8e
RS
782 fprintf ((FILE), "\t%s %s", \
783 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
784 fputc ('\n', (FILE)); \
785 } while (0)
340ccaab
TW
786#endif
787
788#ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
789#define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
9a631e8e 790 do { \
648ebe7b 791 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
c773653b 792 if (flag_debug_asm) \
9a631e8e
RS
793 fprintf ((FILE), "\t%s %s", \
794 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
795 fputc ('\n', (FILE)); \
796 } while (0)
340ccaab
TW
797#endif
798\f
799#ifndef ASM_OUTPUT_DWARF_ADDR
800#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
2e494f70 801 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
802 assemble_name (FILE, LABEL); \
803 fprintf (FILE, "\n"); \
804 } while (0)
805#endif
806
807#ifndef ASM_OUTPUT_DWARF_ADDR_CONST
808#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
648ebe7b
RS
809 do { \
810 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
811 output_addr_const ((FILE), (RTX)); \
812 fputc ('\n', (FILE)); \
813 } while (0)
340ccaab
TW
814#endif
815
816#ifndef ASM_OUTPUT_DWARF_REF
817#define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
2e494f70 818 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
340ccaab
TW
819 assemble_name (FILE, LABEL); \
820 fprintf (FILE, "\n"); \
821 } while (0)
822#endif
823
824#ifndef ASM_OUTPUT_DWARF_DATA1
825#define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
648ebe7b 826 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
340ccaab
TW
827#endif
828
829#ifndef ASM_OUTPUT_DWARF_DATA2
830#define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
2e494f70 831 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
340ccaab
TW
832#endif
833
834#ifndef ASM_OUTPUT_DWARF_DATA4
835#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
2e494f70 836 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
340ccaab
TW
837#endif
838
839#ifndef ASM_OUTPUT_DWARF_DATA8
840#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
841 do { \
842 if (WORDS_BIG_ENDIAN) \
843 { \
2e494f70
RS
844 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
845 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
340ccaab
TW
846 } \
847 else \
848 { \
2e494f70
RS
849 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
850 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
340ccaab
TW
851 } \
852 } while (0)
853#endif
854
74153f8e
AM
855/* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
856 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
857 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
858 defined, we call it, then issue the line feed. If not, we supply a
859 default defintion of calling ASM_OUTPUT_ASCII */
860
340ccaab 861#ifndef ASM_OUTPUT_DWARF_STRING
74153f8e 862#define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
340ccaab 863 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
74153f8e
AM
864#else
865#define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
866 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
340ccaab 867#endif
74153f8e 868
340ccaab
TW
869\f
870/************************ general utility functions **************************/
871
24e75411 872inline static int
648ebe7b
RS
873is_pseudo_reg (rtl)
874 register rtx rtl;
875{
876 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
877 || ((GET_CODE (rtl) == SUBREG)
878 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
879}
880
24e75411 881inline static tree
69d6b01d
RS
882type_main_variant (type)
883 register tree type;
884{
885 type = TYPE_MAIN_VARIANT (type);
886
887 /* There really should be only one main variant among any group of variants
888 of a given type (and all of the MAIN_VARIANT values for all members of
889 the group should point to that one type) but sometimes the C front-end
890 messes this up for array types, so we work around that bug here. */
891
892 if (TREE_CODE (type) == ARRAY_TYPE)
893 {
894 while (type != TYPE_MAIN_VARIANT (type))
895 type = TYPE_MAIN_VARIANT (type);
896 }
897
898 return type;
899}
900
c7d6dca2
RS
901/* Return non-zero if the given type node represents a tagged type. */
902
24e75411 903inline static int
c7d6dca2
RS
904is_tagged_type (type)
905 register tree type;
906{
907 register enum tree_code code = TREE_CODE (type);
908
c1b98a95
RK
909 return (code == RECORD_TYPE || code == UNION_TYPE
910 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
c7d6dca2
RS
911}
912
a996cbd4 913static const char *
9a631e8e 914dwarf_tag_name (tag)
340ccaab
TW
915 register unsigned tag;
916{
917 switch (tag)
918 {
9a631e8e
RS
919 case TAG_padding: return "TAG_padding";
920 case TAG_array_type: return "TAG_array_type";
921 case TAG_class_type: return "TAG_class_type";
922 case TAG_entry_point: return "TAG_entry_point";
923 case TAG_enumeration_type: return "TAG_enumeration_type";
924 case TAG_formal_parameter: return "TAG_formal_parameter";
925 case TAG_global_subroutine: return "TAG_global_subroutine";
926 case TAG_global_variable: return "TAG_global_variable";
927 case TAG_label: return "TAG_label";
928 case TAG_lexical_block: return "TAG_lexical_block";
929 case TAG_local_variable: return "TAG_local_variable";
930 case TAG_member: return "TAG_member";
931 case TAG_pointer_type: return "TAG_pointer_type";
932 case TAG_reference_type: return "TAG_reference_type";
933 case TAG_compile_unit: return "TAG_compile_unit";
934 case TAG_string_type: return "TAG_string_type";
935 case TAG_structure_type: return "TAG_structure_type";
936 case TAG_subroutine: return "TAG_subroutine";
937 case TAG_subroutine_type: return "TAG_subroutine_type";
938 case TAG_typedef: return "TAG_typedef";
939 case TAG_union_type: return "TAG_union_type";
340ccaab 940 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
9a631e8e
RS
941 case TAG_variant: return "TAG_variant";
942 case TAG_common_block: return "TAG_common_block";
943 case TAG_common_inclusion: return "TAG_common_inclusion";
944 case TAG_inheritance: return "TAG_inheritance";
945 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
946 case TAG_module: return "TAG_module";
947 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
948 case TAG_set_type: return "TAG_set_type";
949 case TAG_subrange_type: return "TAG_subrange_type";
950 case TAG_with_stmt: return "TAG_with_stmt";
951
952 /* GNU extensions. */
953
954 case TAG_format_label: return "TAG_format_label";
955 case TAG_namelist: return "TAG_namelist";
956 case TAG_function_template: return "TAG_function_template";
957 case TAG_class_template: return "TAG_class_template";
958
04077c53 959 default: return "TAG_<unknown>";
340ccaab
TW
960 }
961}
962
a996cbd4 963static const char *
9a631e8e 964dwarf_attr_name (attr)
340ccaab
TW
965 register unsigned attr;
966{
967 switch (attr)
968 {
9a631e8e
RS
969 case AT_sibling: return "AT_sibling";
970 case AT_location: return "AT_location";
971 case AT_name: return "AT_name";
972 case AT_fund_type: return "AT_fund_type";
973 case AT_mod_fund_type: return "AT_mod_fund_type";
974 case AT_user_def_type: return "AT_user_def_type";
975 case AT_mod_u_d_type: return "AT_mod_u_d_type";
976 case AT_ordering: return "AT_ordering";
977 case AT_subscr_data: return "AT_subscr_data";
978 case AT_byte_size: return "AT_byte_size";
979 case AT_bit_offset: return "AT_bit_offset";
980 case AT_bit_size: return "AT_bit_size";
981 case AT_element_list: return "AT_element_list";
982 case AT_stmt_list: return "AT_stmt_list";
983 case AT_low_pc: return "AT_low_pc";
984 case AT_high_pc: return "AT_high_pc";
985 case AT_language: return "AT_language";
986 case AT_member: return "AT_member";
987 case AT_discr: return "AT_discr";
988 case AT_discr_value: return "AT_discr_value";
989 case AT_string_length: return "AT_string_length";
990 case AT_common_reference: return "AT_common_reference";
991 case AT_comp_dir: return "AT_comp_dir";
992 case AT_const_value_string: return "AT_const_value_string";
993 case AT_const_value_data2: return "AT_const_value_data2";
994 case AT_const_value_data4: return "AT_const_value_data4";
995 case AT_const_value_data8: return "AT_const_value_data8";
996 case AT_const_value_block2: return "AT_const_value_block2";
340ccaab 997 case AT_const_value_block4: return "AT_const_value_block4";
9a631e8e
RS
998 case AT_containing_type: return "AT_containing_type";
999 case AT_default_value_addr: return "AT_default_value_addr";
1000 case AT_default_value_data2: return "AT_default_value_data2";
1001 case AT_default_value_data4: return "AT_default_value_data4";
1002 case AT_default_value_data8: return "AT_default_value_data8";
1003 case AT_default_value_string: return "AT_default_value_string";
1004 case AT_friends: return "AT_friends";
1005 case AT_inline: return "AT_inline";
1006 case AT_is_optional: return "AT_is_optional";
1007 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1008 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1009 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1010 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1011 case AT_private: return "AT_private";
1012 case AT_producer: return "AT_producer";
1013 case AT_program: return "AT_program";
1014 case AT_protected: return "AT_protected";
1015 case AT_prototyped: return "AT_prototyped";
1016 case AT_public: return "AT_public";
1017 case AT_pure_virtual: return "AT_pure_virtual";
1018 case AT_return_addr: return "AT_return_addr";
04077c53 1019 case AT_abstract_origin: return "AT_abstract_origin";
9a631e8e
RS
1020 case AT_start_scope: return "AT_start_scope";
1021 case AT_stride_size: return "AT_stride_size";
1022 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1023 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1024 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1025 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1026 case AT_virtual: return "AT_virtual";
1027
1028 /* GNU extensions */
1029
1030 case AT_sf_names: return "AT_sf_names";
1031 case AT_src_info: return "AT_src_info";
1032 case AT_mac_info: return "AT_mac_info";
1033 case AT_src_coords: return "AT_src_coords";
2a819d04
TW
1034 case AT_body_begin: return "AT_body_begin";
1035 case AT_body_end: return "AT_body_end";
9a631e8e 1036
04077c53 1037 default: return "AT_<unknown>";
340ccaab
TW
1038 }
1039}
1040
a996cbd4 1041static const char *
9a631e8e 1042dwarf_stack_op_name (op)
340ccaab
TW
1043 register unsigned op;
1044{
1045 switch (op)
1046 {
1047 case OP_REG: return "OP_REG";
1048 case OP_BASEREG: return "OP_BASEREG";
1049 case OP_ADDR: return "OP_ADDR";
1050 case OP_CONST: return "OP_CONST";
1051 case OP_DEREF2: return "OP_DEREF2";
1052 case OP_DEREF4: return "OP_DEREF4";
1053 case OP_ADD: return "OP_ADD";
04077c53 1054 default: return "OP_<unknown>";
340ccaab
TW
1055 }
1056}
1057
a996cbd4 1058static const char *
9a631e8e 1059dwarf_typemod_name (mod)
340ccaab
TW
1060 register unsigned mod;
1061{
1062 switch (mod)
1063 {
1064 case MOD_pointer_to: return "MOD_pointer_to";
1065 case MOD_reference_to: return "MOD_reference_to";
1066 case MOD_const: return "MOD_const";
1067 case MOD_volatile: return "MOD_volatile";
04077c53 1068 default: return "MOD_<unknown>";
340ccaab
TW
1069 }
1070}
1071
a996cbd4 1072static const char *
9a631e8e 1073dwarf_fmt_byte_name (fmt)
340ccaab
TW
1074 register unsigned fmt;
1075{
1076 switch (fmt)
1077 {
1078 case FMT_FT_C_C: return "FMT_FT_C_C";
1079 case FMT_FT_C_X: return "FMT_FT_C_X";
1080 case FMT_FT_X_C: return "FMT_FT_X_C";
1081 case FMT_FT_X_X: return "FMT_FT_X_X";
1082 case FMT_UT_C_C: return "FMT_UT_C_C";
1083 case FMT_UT_C_X: return "FMT_UT_C_X";
1084 case FMT_UT_X_C: return "FMT_UT_X_C";
1085 case FMT_UT_X_X: return "FMT_UT_X_X";
1086 case FMT_ET: return "FMT_ET";
04077c53 1087 default: return "FMT_<unknown>";
340ccaab
TW
1088 }
1089}
461b77c8 1090
a996cbd4 1091static const char *
9a631e8e 1092dwarf_fund_type_name (ft)
340ccaab
TW
1093 register unsigned ft;
1094{
1095 switch (ft)
1096 {
1097 case FT_char: return "FT_char";
1098 case FT_signed_char: return "FT_signed_char";
1099 case FT_unsigned_char: return "FT_unsigned_char";
1100 case FT_short: return "FT_short";
1101 case FT_signed_short: return "FT_signed_short";
1102 case FT_unsigned_short: return "FT_unsigned_short";
1103 case FT_integer: return "FT_integer";
1104 case FT_signed_integer: return "FT_signed_integer";
1105 case FT_unsigned_integer: return "FT_unsigned_integer";
1106 case FT_long: return "FT_long";
1107 case FT_signed_long: return "FT_signed_long";
1108 case FT_unsigned_long: return "FT_unsigned_long";
1109 case FT_pointer: return "FT_pointer";
1110 case FT_float: return "FT_float";
1111 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1112 case FT_ext_prec_float: return "FT_ext_prec_float";
1113 case FT_complex: return "FT_complex";
1114 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1115 case FT_void: return "FT_void";
1116 case FT_boolean: return "FT_boolean";
9a631e8e
RS
1117 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1118 case FT_label: return "FT_label";
1119
1120 /* GNU extensions. */
1121
340ccaab
TW
1122 case FT_long_long: return "FT_long_long";
1123 case FT_signed_long_long: return "FT_signed_long_long";
1124 case FT_unsigned_long_long: return "FT_unsigned_long_long";
9a631e8e
RS
1125
1126 case FT_int8: return "FT_int8";
1127 case FT_signed_int8: return "FT_signed_int8";
1128 case FT_unsigned_int8: return "FT_unsigned_int8";
1129 case FT_int16: return "FT_int16";
1130 case FT_signed_int16: return "FT_signed_int16";
1131 case FT_unsigned_int16: return "FT_unsigned_int16";
1132 case FT_int32: return "FT_int32";
1133 case FT_signed_int32: return "FT_signed_int32";
1134 case FT_unsigned_int32: return "FT_unsigned_int32";
1135 case FT_int64: return "FT_int64";
1136 case FT_signed_int64: return "FT_signed_int64";
c21ee927 1137 case FT_unsigned_int64: return "FT_unsigned_int64";
9a631e8e
RS
1138
1139 case FT_real32: return "FT_real32";
1140 case FT_real64: return "FT_real64";
1141 case FT_real96: return "FT_real96";
1142 case FT_real128: return "FT_real128";
1143
cb712ad4 1144 default: return "FT_<unknown>";
340ccaab
TW
1145 }
1146}
cb712ad4
RS
1147
1148/* Determine the "ultimate origin" of a decl. The decl may be an
1149 inlined instance of an inlined instance of a decl which is local
1150 to an inline function, so we have to trace all of the way back
1151 through the origin chain to find out what sort of node actually
1152 served as the original seed for the given block. */
1153
1154static tree
1155decl_ultimate_origin (decl)
1156 register tree decl;
1157{
02e24c7a
MM
1158#ifdef ENABLE_CHECKING
1159 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1160 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1161 most distant ancestor, this should never happen. */
1162 abort ();
1163#endif
cb712ad4 1164
02e24c7a 1165 return DECL_ABSTRACT_ORIGIN (decl);
cb712ad4
RS
1166}
1167
ece0ca60
RS
1168/* Determine the "ultimate origin" of a block. The block may be an
1169 inlined instance of an inlined instance of a block which is local
1170 to an inline function, so we have to trace all of the way back
1171 through the origin chain to find out what sort of node actually
1172 served as the original seed for the given block. */
1173
1174static tree
1175block_ultimate_origin (block)
1176 register tree block;
1177{
1178 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1179
1180 if (immediate_origin == NULL)
1181 return NULL;
1182 else
1183 {
1184 register tree ret_val;
1185 register tree lookahead = immediate_origin;
1186
1187 do
1188 {
1189 ret_val = lookahead;
1190 lookahead = (TREE_CODE (ret_val) == BLOCK)
1191 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1192 : NULL;
1193 }
1194 while (lookahead != NULL && lookahead != ret_val);
1195 return ret_val;
1196 }
1197}
1198
a94dbf2c
JM
1199/* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1200 of a virtual function may refer to a base class, so we check the 'this'
1201 parameter. */
1202
1203static tree
1204decl_class_context (decl)
1205 tree decl;
1206{
1207 tree context = NULL_TREE;
1208 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1209 context = DECL_CONTEXT (decl);
1210 else
1211 context = TYPE_MAIN_VARIANT
1212 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1213
2f939d94 1214 if (context && !TYPE_P (context))
a94dbf2c
JM
1215 context = NULL_TREE;
1216
1217 return context;
1218}
1219
487a6e06 1220#if 0
cb712ad4
RS
1221static void
1222output_unsigned_leb128 (value)
1223 register unsigned long value;
1224{
1225 register unsigned long orig_value = value;
1226
1227 do
1228 {
1229 register unsigned byte = (value & 0x7f);
1230
1231 value >>= 7;
1232 if (value != 0) /* more bytes to follow */
1233 byte |= 0x80;
1234 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
c773653b 1235 if (flag_debug_asm && value == 0)
5e9defae 1236 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
cb712ad4
RS
1237 ASM_COMMENT_START, orig_value);
1238 fputc ('\n', asm_out_file);
1239 }
1240 while (value != 0);
1241}
1242
1243static void
1244output_signed_leb128 (value)
1245 register long value;
1246{
1247 register long orig_value = value;
1248 register int negative = (value < 0);
1249 register int more;
1250
1251 do
1252 {
1253 register unsigned byte = (value & 0x7f);
1254
1255 value >>= 7;
1256 if (negative)
1257 value |= 0xfe000000; /* manually sign extend */
1258 if (((value == 0) && ((byte & 0x40) == 0))
1259 || ((value == -1) && ((byte & 0x40) == 1)))
1260 more = 0;
1261 else
1262 {
1263 byte |= 0x80;
1264 more = 1;
1265 }
1266 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
c773653b 1267 if (flag_debug_asm && more == 0)
5e9defae 1268 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
cb712ad4
RS
1269 ASM_COMMENT_START, orig_value);
1270 fputc ('\n', asm_out_file);
1271 }
1272 while (more);
1273}
487a6e06 1274#endif
340ccaab
TW
1275\f
1276/**************** utility functions for attribute functions ******************/
1277
1278/* Given a pointer to a tree node for some type, return a Dwarf fundamental
1279 type code for the given type.
1280
1281 This routine must only be called for GCC type nodes that correspond to
1282 Dwarf fundamental types.
1283
1284 The current Dwarf draft specification calls for Dwarf fundamental types
1285 to accurately reflect the fact that a given type was either a "plain"
3f7cc57a 1286 integral type or an explicitly "signed" integral type. Unfortunately,
340ccaab
TW
1287 we can't always do this, because GCC may already have thrown away the
1288 information about the precise way in which the type was originally
1289 specified, as in:
1290
b083f44d 1291 typedef signed int my_type;
340ccaab 1292
b083f44d 1293 struct s { my_type f; };
340ccaab
TW
1294
1295 Since we may be stuck here without enought information to do exactly
1296 what is called for in the Dwarf draft specification, we do the best
1297 that we can under the circumstances and always use the "plain" integral
1298 fundamental type codes for int, short, and long types. That's probably
1299 good enough. The additional accuracy called for in the current DWARF
1300 draft specification is probably never even useful in practice. */
1301
1302static int
1303fundamental_type_code (type)
1304 register tree type;
1305{
1306 if (TREE_CODE (type) == ERROR_MARK)
1307 return 0;
1308
1309 switch (TREE_CODE (type))
1310 {
1311 case ERROR_MARK:
1312 return FT_void;
1313
1314 case VOID_TYPE:
1315 return FT_void;
1316
1317 case INTEGER_TYPE:
1318 /* Carefully distinguish all the standard types of C,
1319 without messing up if the language is not C.
1320 Note that we check only for the names that contain spaces;
1321 other names might occur by coincidence in other languages. */
1322 if (TYPE_NAME (type) != 0
1323 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1324 && DECL_NAME (TYPE_NAME (type)) != 0
1325 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1326 {
a996cbd4
KG
1327 const char *name =
1328 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
340ccaab
TW
1329
1330 if (!strcmp (name, "unsigned char"))
1331 return FT_unsigned_char;
1332 if (!strcmp (name, "signed char"))
1333 return FT_signed_char;
1334 if (!strcmp (name, "unsigned int"))
1335 return FT_unsigned_integer;
1336 if (!strcmp (name, "short int"))
1337 return FT_short;
1338 if (!strcmp (name, "short unsigned int"))
1339 return FT_unsigned_short;
1340 if (!strcmp (name, "long int"))
1341 return FT_long;
1342 if (!strcmp (name, "long unsigned int"))
1343 return FT_unsigned_long;
1344 if (!strcmp (name, "long long int"))
1345 return FT_long_long; /* Not grok'ed by svr4 SDB */
1346 if (!strcmp (name, "long long unsigned int"))
1347 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1348 }
1349
1350 /* Most integer types will be sorted out above, however, for the
1351 sake of special `array index' integer types, the following code
1352 is also provided. */
1353
1354 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1355 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1356
1357 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1358 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1359
1360 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1361 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1362
1363 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1364 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1365
1366 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1367 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1368
e139d296
AO
1369 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1370 if (TYPE_PRECISION (type) == 1)
1371 return FT_boolean;
1372
340ccaab
TW
1373 abort ();
1374
1375 case REAL_TYPE:
1376 /* Carefully distinguish all the standard types of C,
1377 without messing up if the language is not C. */
1378 if (TYPE_NAME (type) != 0
1379 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1380 && DECL_NAME (TYPE_NAME (type)) != 0
1381 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1382 {
a996cbd4
KG
1383 const char *name =
1384 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
340ccaab
TW
1385
1386 /* Note that here we can run afowl of a serious bug in "classic"
1387 svr4 SDB debuggers. They don't seem to understand the
1388 FT_ext_prec_float type (even though they should). */
1389
1390 if (!strcmp (name, "long double"))
1391 return FT_ext_prec_float;
1392 }
1393
1394 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
33368c84
R
1395 {
1396 /* On the SH, when compiling with -m3e or -m4-single-only, both
1397 float and double are 32 bits. But since the debugger doesn't
1398 know about the subtarget, it always thinks double is 64 bits.
1399 So we have to tell the debugger that the type is float to
1400 make the output of the 'print' command etc. readable. */
1401 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
f0da48d2 1402 return FT_float;
33368c84
R
1403 return FT_dbl_prec_float;
1404 }
340ccaab
TW
1405 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1406 return FT_float;
1407
1408 /* Note that here we can run afowl of a serious bug in "classic"
1409 svr4 SDB debuggers. They don't seem to understand the
1410 FT_ext_prec_float type (even though they should). */
1411
1412 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1413 return FT_ext_prec_float;
1414 abort ();
1415
1416 case COMPLEX_TYPE:
1417 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1418
1419 case CHAR_TYPE:
1420 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1421
1422 case BOOLEAN_TYPE:
1423 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1424
1425 default:
1426 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1427 }
1428 return 0;
1429}
1430\f
1431/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1432 the Dwarf "root" type for the given input type. The Dwarf "root" type
1433 of a given type is generally the same as the given type, except that if
1434 the given type is a pointer or reference type, then the root type of
1435 the given type is the root type of the "basis" type for the pointer or
1436 reference type. (This definition of the "root" type is recursive.)
1437 Also, the root type of a `const' qualified type or a `volatile'
1438 qualified type is the root type of the given type without the
1439 qualifiers. */
1440
1441static tree
b1357021 1442root_type_1 (type, count)
340ccaab 1443 register tree type;
b1357021 1444 register int count;
340ccaab 1445{
b1357021
JW
1446 /* Give up after searching 1000 levels, in case this is a recursive
1447 pointer type. Such types are possible in Ada, but it is not possible
1448 to represent them in DWARF1 debug info. */
1449 if (count > 1000)
340ccaab
TW
1450 return error_mark_node;
1451
1452 switch (TREE_CODE (type))
1453 {
1454 case ERROR_MARK:
1455 return error_mark_node;
1456
1457 case POINTER_TYPE:
1458 case REFERENCE_TYPE:
b1357021 1459 return root_type_1 (TREE_TYPE (type), count+1);
340ccaab
TW
1460
1461 default:
b1357021 1462 return type;
340ccaab
TW
1463 }
1464}
1465
b1357021
JW
1466static tree
1467root_type (type)
1468 register tree type;
1469{
1470 type = root_type_1 (type, 0);
1471 if (type != error_mark_node)
1472 type = type_main_variant (type);
1473 return type;
1474}
1475
340ccaab
TW
1476/* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1477 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1478
1479static void
b1357021 1480write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
340ccaab
TW
1481 register tree type;
1482 register int decl_const;
1483 register int decl_volatile;
b1357021 1484 register int count;
340ccaab
TW
1485{
1486 if (TREE_CODE (type) == ERROR_MARK)
1487 return;
1488
b1357021
JW
1489 /* Give up after searching 1000 levels, in case this is a recursive
1490 pointer type. Such types are possible in Ada, but it is not possible
1491 to represent them in DWARF1 debug info. */
1492 if (count > 1000)
1493 return;
1494
340ccaab
TW
1495 if (TYPE_READONLY (type) || decl_const)
1496 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1497 if (TYPE_VOLATILE (type) || decl_volatile)
1498 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1499 switch (TREE_CODE (type))
1500 {
1501 case POINTER_TYPE:
1502 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
b1357021 1503 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
340ccaab
TW
1504 return;
1505
1506 case REFERENCE_TYPE:
1507 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
b1357021 1508 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
340ccaab
TW
1509 return;
1510
1511 case ERROR_MARK:
1512 default:
1513 return;
1514 }
1515}
b1357021
JW
1516
1517static void
1518write_modifier_bytes (type, decl_const, decl_volatile)
1519 register tree type;
1520 register int decl_const;
1521 register int decl_volatile;
1522{
1523 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1524}
340ccaab
TW
1525\f
1526/* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1527 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1528
461b77c8 1529static inline int
340ccaab
TW
1530type_is_fundamental (type)
1531 register tree type;
1532{
1533 switch (TREE_CODE (type))
1534 {
1535 case ERROR_MARK:
1536 case VOID_TYPE:
1537 case INTEGER_TYPE:
1538 case REAL_TYPE:
1539 case COMPLEX_TYPE:
1540 case BOOLEAN_TYPE:
1541 case CHAR_TYPE:
1542 return 1;
1543
1544 case SET_TYPE:
1545 case ARRAY_TYPE:
1546 case RECORD_TYPE:
1547 case UNION_TYPE:
c1b98a95 1548 case QUAL_UNION_TYPE:
340ccaab
TW
1549 case ENUMERAL_TYPE:
1550 case FUNCTION_TYPE:
1551 case METHOD_TYPE:
1552 case POINTER_TYPE:
1553 case REFERENCE_TYPE:
340ccaab
TW
1554 case FILE_TYPE:
1555 case OFFSET_TYPE:
1556 case LANG_TYPE:
1557 return 0;
1558
1559 default:
1560 abort ();
1561 }
1562 return 0;
1563}
1564
04077c53
RS
1565/* Given a pointer to some ..._DECL tree node, generate an assembly language
1566 equate directive which will associate a symbolic name with the current DIE.
1567
1568 The name used is an artificial label generated from the DECL_UID number
1569 associated with the given decl node. The name it gets equated to is the
1570 symbolic label that we (previously) output at the start of the DIE that
1571 we are currently generating.
1572
1573 Calling this function while generating some "decl related" form of DIE
1574 makes it possible to later refer to the DIE which represents the given
1575 decl simply by re-generating the symbolic name from the ..._DECL node's
1576 UID number. */
1577
1578static void
1579equate_decl_number_to_die_number (decl)
1580 register tree decl;
1581{
1582 /* In the case where we are generating a DIE for some ..._DECL node
1583 which represents either some inline function declaration or some
1584 entity declared within an inline function declaration/definition,
1585 setup a symbolic name for the current DIE so that we have a name
1586 for this DIE that we can easily refer to later on within
1587 AT_abstract_origin attributes. */
1588
1589 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1590 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1591
1592 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1593 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1594 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1595}
1596
340ccaab 1597/* Given a pointer to some ..._TYPE tree node, generate an assembly language
04077c53 1598 equate directive which will associate a symbolic name with the current DIE.
340ccaab
TW
1599
1600 The name used is an artificial label generated from the TYPE_UID number
1601 associated with the given type node. The name it gets equated to is the
1602 symbolic label that we (previously) output at the start of the DIE that
1603 we are currently generating.
1604
1605 Calling this function while generating some "type related" form of DIE
1606 makes it easy to later refer to the DIE which represents the given type
1607 simply by re-generating the alternative name from the ..._TYPE node's
1608 UID number. */
1609
461b77c8 1610static inline void
340ccaab
TW
1611equate_type_number_to_die_number (type)
1612 register tree type;
1613{
1614 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1615 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1616
1617 /* We are generating a DIE to represent the main variant of this type
1618 (i.e the type without any const or volatile qualifiers) so in order
1619 to get the equate to come out right, we need to get the main variant
1620 itself here. */
1621
69d6b01d 1622 type = type_main_variant (type);
340ccaab
TW
1623
1624 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1625 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1626 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1627}
1628
7f7429ca
RS
1629static void
1630output_reg_number (rtl)
1631 register rtx rtl;
1632{
1633 register unsigned regno = REGNO (rtl);
1634
3073d01c 1635 if (regno >= DWARF_FRAME_REGISTERS)
7f7429ca
RS
1636 {
1637 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1638 regno);
1639 regno = 0;
1640 }
1641 fprintf (asm_out_file, "\t%s\t0x%x",
1642 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
c773653b 1643 if (flag_debug_asm)
7f7429ca
RS
1644 {
1645 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1646 PRINT_REG (rtl, 0, asm_out_file);
1647 }
1648 fputc ('\n', asm_out_file);
1649}
1650
340ccaab
TW
1651/* The following routine is a nice and simple transducer. It converts the
1652 RTL for a variable or parameter (resident in memory) into an equivalent
1653 Dwarf representation of a mechanism for getting the address of that same
1654 variable onto the top of a hypothetical "address evaluation" stack.
1655
1656 When creating memory location descriptors, we are effectively trans-
1657 forming the RTL for a memory-resident object into its Dwarf postfix
1658 expression equivalent. This routine just recursively descends an
1659 RTL tree, turning it into Dwarf postfix code as it goes. */
1660
1661static void
1662output_mem_loc_descriptor (rtl)
1663 register rtx rtl;
1664{
1665 /* Note that for a dynamically sized array, the location we will
1666 generate a description of here will be the lowest numbered location
1667 which is actually within the array. That's *not* necessarily the
1668 same as the zeroth element of the array. */
1669
1865dbb5
JM
1670#ifdef ASM_SIMPLIFY_DWARF_ADDR
1671 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
1672#endif
1673
340ccaab
TW
1674 switch (GET_CODE (rtl))
1675 {
1676 case SUBREG:
1677
1678 /* The case of a subreg may arise when we have a local (register)
1679 variable or a formal (register) parameter which doesn't quite
1680 fill up an entire register. For now, just assume that it is
1681 legitimate to make the Dwarf info refer to the whole register
1682 which contains the given subreg. */
1683
1684 rtl = XEXP (rtl, 0);
1685 /* Drop thru. */
1686
1687 case REG:
1688
1689 /* Whenever a register number forms a part of the description of
1690 the method for calculating the (dynamic) address of a memory
52cdd5e5 1691 resident object, DWARF rules require the register number to
340ccaab
TW
1692 be referred to as a "base register". This distinction is not
1693 based in any way upon what category of register the hardware
1694 believes the given register belongs to. This is strictly
8c24a2ce 1695 DWARF terminology we're dealing with here.
28b039e3
RS
1696
1697 Note that in cases where the location of a memory-resident data
1698 object could be expressed as:
1699
1700 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1701
1702 the actual DWARF location descriptor that we generate may just
1703 be OP_BASEREG (basereg). This may look deceptively like the
1704 object in question was allocated to a register (rather than
1705 in memory) so DWARF consumers need to be aware of the subtle
52cdd5e5 1706 distinction between OP_REG and OP_BASEREG. */
340ccaab
TW
1707
1708 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
7f7429ca 1709 output_reg_number (rtl);
340ccaab
TW
1710 break;
1711
1712 case MEM:
1713 output_mem_loc_descriptor (XEXP (rtl, 0));
1714 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1715 break;
1716
1717 case CONST:
1718 case SYMBOL_REF:
1719 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1720 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1721 break;
1722
1723 case PLUS:
1724 output_mem_loc_descriptor (XEXP (rtl, 0));
1725 output_mem_loc_descriptor (XEXP (rtl, 1));
1726 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1727 break;
1728
1729 case CONST_INT:
1730 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1731 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1732 break;
1733
c21ee927
JW
1734 case MULT:
1735 /* If a pseudo-reg is optimized away, it is possible for it to
1736 be replaced with a MEM containing a multiply. Use a GNU extension
1737 to describe it. */
1738 output_mem_loc_descriptor (XEXP (rtl, 0));
1739 output_mem_loc_descriptor (XEXP (rtl, 1));
1740 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1741 break;
1742
340ccaab
TW
1743 default:
1744 abort ();
1745 }
1746}
1747
1748/* Output a proper Dwarf location descriptor for a variable or parameter
1749 which is either allocated in a register or in a memory location. For
1750 a register, we just generate an OP_REG and the register number. For a
1751 memory location we provide a Dwarf postfix expression describing how to
1752 generate the (dynamic) address of the object onto the address stack. */
1753
1754static void
1755output_loc_descriptor (rtl)
1756 register rtx rtl;
1757{
1758 switch (GET_CODE (rtl))
1759 {
1760 case SUBREG:
1761
1762 /* The case of a subreg may arise when we have a local (register)
1763 variable or a formal (register) parameter which doesn't quite
1764 fill up an entire register. For now, just assume that it is
1765 legitimate to make the Dwarf info refer to the whole register
1766 which contains the given subreg. */
1767
1768 rtl = XEXP (rtl, 0);
1769 /* Drop thru. */
1770
1771 case REG:
1772 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
7f7429ca 1773 output_reg_number (rtl);
340ccaab
TW
1774 break;
1775
1776 case MEM:
1777 output_mem_loc_descriptor (XEXP (rtl, 0));
1778 break;
1779
1780 default:
1781 abort (); /* Should never happen */
1782 }
1783}
1784
1785/* Given a tree node describing an array bound (either lower or upper)
1786 output a representation for that bound. */
1787
1788static void
1789output_bound_representation (bound, dim_num, u_or_l)
1790 register tree bound;
1791 register unsigned dim_num; /* For multi-dimensional arrays. */
1792 register char u_or_l; /* Designates upper or lower bound. */
1793{
1794 switch (TREE_CODE (bound))
1795 {
1796
56b3408d
RK
1797 case ERROR_MARK:
1798 return;
340ccaab
TW
1799
1800 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1801
56b3408d 1802 case INTEGER_CST:
665f2503
RK
1803 if (host_integerp (bound, 0))
1804 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
56b3408d
RK
1805 break;
1806
1807 default:
340ccaab
TW
1808
1809 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
56b3408d
RK
1810 SAVE_EXPR nodes, in which case we can do something, or as
1811 an expression, which we cannot represent. */
1812 {
1813 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1814 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1815
1816 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1817 current_dienum, dim_num, u_or_l);
1818
1819 sprintf (end_label, BOUND_END_LABEL_FMT,
1820 current_dienum, dim_num, u_or_l);
1821
1822 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1823 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1824
1825 /* If optimization is turned on, the SAVE_EXPRs that describe
1826 how to access the upper bound values are essentially bogus.
1827 They only describe (at best) how to get at these values at
1828 the points in the generated code right after they have just
1829 been computed. Worse yet, in the typical case, the upper
1830 bound values will not even *be* computed in the optimized
1831 code, so these SAVE_EXPRs are entirely bogus.
1832
1833 In order to compensate for this fact, we check here to see
1834 if optimization is enabled, and if so, we effectively create
1835 an empty location description for the (unknown and unknowable)
1836 upper bound.
1837
1838 This should not cause too much trouble for existing (stupid?)
1839 debuggers because they have to deal with empty upper bounds
1840 location descriptions anyway in order to be able to deal with
1841 incomplete array types.
1842
1843 Of course an intelligent debugger (GDB?) should be able to
1844 comprehend that a missing upper bound specification in a
1845 array type used for a storage class `auto' local array variable
1846 indicates that the upper bound is both unknown (at compile-
1847 time) and unknowable (at run-time) due to optimization. */
1848
1849 if (! optimize)
1850 {
1851 while (TREE_CODE (bound) == NOP_EXPR
1852 || TREE_CODE (bound) == CONVERT_EXPR)
1853 bound = TREE_OPERAND (bound, 0);
340ccaab 1854
4513a33c 1855 if (TREE_CODE (bound) == SAVE_EXPR)
56b3408d 1856 output_loc_descriptor
1914f5da 1857 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
56b3408d 1858 }
340ccaab 1859
56b3408d
RK
1860 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1861 }
1862 break;
340ccaab 1863
340ccaab
TW
1864 }
1865}
1866
1867/* Recursive function to output a sequence of value/name pairs for
1868 enumeration constants in reversed order. This is called from
1869 enumeration_type_die. */
1870
1871static void
1872output_enumeral_list (link)
1873 register tree link;
1874{
1875 if (link)
1876 {
1877 output_enumeral_list (TREE_CHAIN (link));
665f2503
RK
1878
1879 if (host_integerp (TREE_VALUE (link), 0))
1880 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1881 tree_low_cst (TREE_VALUE (link), 0));
1882
74153f8e 1883 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
340ccaab
TW
1884 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1885 }
1886}
1887
d4d4c5a8
RS
1888/* Given an unsigned value, round it up to the lowest multiple of `boundary'
1889 which is not less than the value itself. */
1890
665f2503 1891static inline HOST_WIDE_INT
d4d4c5a8 1892ceiling (value, boundary)
665f2503
RK
1893 register HOST_WIDE_INT value;
1894 register unsigned int boundary;
d4d4c5a8
RS
1895{
1896 return (((value + boundary - 1) / boundary) * boundary);
1897}
1898
1899/* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1900 pointer to the declared type for the relevant field variable, or return
1901 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1902
461b77c8 1903static inline tree
d4d4c5a8
RS
1904field_type (decl)
1905 register tree decl;
1906{
1907 register tree type;
1908
1909 if (TREE_CODE (decl) == ERROR_MARK)
1910 return integer_type_node;
1911
1912 type = DECL_BIT_FIELD_TYPE (decl);
1913 if (type == NULL)
1914 type = TREE_TYPE (decl);
1915 return type;
1916}
1917
1918/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1919 node, return the alignment in bits for the type, or else return
1920 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1921
665f2503 1922static inline unsigned int
d4d4c5a8
RS
1923simple_type_align_in_bits (type)
1924 register tree type;
1925{
1926 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1927}
1928
1929/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1930 node, return the size in bits for the type if it is a constant, or
1931 else return the alignment for the type if the type's size is not
1932 constant, or else return BITS_PER_WORD if the type actually turns out
1933 to be an ERROR_MARK node. */
1934
665f2503 1935static inline unsigned HOST_WIDE_INT
d4d4c5a8
RS
1936simple_type_size_in_bits (type)
1937 register tree type;
1938{
1939 if (TREE_CODE (type) == ERROR_MARK)
1940 return BITS_PER_WORD;
1941 else
1942 {
1943 register tree type_size_tree = TYPE_SIZE (type);
1944
665f2503 1945 if (! host_integerp (type_size_tree, 1))
d4d4c5a8
RS
1946 return TYPE_ALIGN (type);
1947
665f2503 1948 return tree_low_cst (type_size_tree, 1);
d4d4c5a8
RS
1949 }
1950}
1951
1952/* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1953 return the byte offset of the lowest addressed byte of the "containing
1954 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1955 mine what that offset is, either because the argument turns out to be a
1956 pointer to an ERROR_MARK node, or because the offset is actually variable.
1957 (We can't handle the latter case just yet.) */
1958
665f2503 1959static HOST_WIDE_INT
d4d4c5a8
RS
1960field_byte_offset (decl)
1961 register tree decl;
1962{
665f2503
RK
1963 unsigned int type_align_in_bytes;
1964 unsigned int type_align_in_bits;
1965 unsigned HOST_WIDE_INT type_size_in_bits;
1966 HOST_WIDE_INT object_offset_in_align_units;
1967 HOST_WIDE_INT object_offset_in_bits;
1968 HOST_WIDE_INT object_offset_in_bytes;
1969 tree type;
1970 tree field_size_tree;
1971 HOST_WIDE_INT bitpos_int;
1972 HOST_WIDE_INT deepest_bitpos;
1973 unsigned HOST_WIDE_INT field_size_in_bits;
d4d4c5a8
RS
1974
1975 if (TREE_CODE (decl) == ERROR_MARK)
1976 return 0;
1977
1978 if (TREE_CODE (decl) != FIELD_DECL)
1979 abort ();
1980
1981 type = field_type (decl);
d4d4c5a8
RS
1982 field_size_tree = DECL_SIZE (decl);
1983
d0f89bfc
R
1984 /* If there was an error, the size could be zero. */
1985 if (! field_size_tree)
1986 {
1987 if (errorcount)
1988 return 0;
665f2503 1989
d0f89bfc
R
1990 abort ();
1991 }
1992
d4d4c5a8
RS
1993 /* We cannot yet cope with fields whose positions or sizes are variable,
1994 so for now, when we see such things, we simply return 0. Someday,
1995 we may be able to handle such cases, but it will be damn difficult. */
1996
665f2503
RK
1997 if (! host_integerp (bit_position (decl), 0)
1998 || ! host_integerp (field_size_tree, 1))
d4d4c5a8 1999 return 0;
d4d4c5a8 2000
665f2503
RK
2001 bitpos_int = int_bit_position (decl);
2002 field_size_in_bits = tree_low_cst (field_size_tree, 1);
d4d4c5a8
RS
2003
2004 type_size_in_bits = simple_type_size_in_bits (type);
d4d4c5a8
RS
2005 type_align_in_bits = simple_type_align_in_bits (type);
2006 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2007
2008 /* Note that the GCC front-end doesn't make any attempt to keep track
2009 of the starting bit offset (relative to the start of the containing
2010 structure type) of the hypothetical "containing object" for a bit-
2011 field. Thus, when computing the byte offset value for the start of
2012 the "containing object" of a bit-field, we must deduce this infor-
2013 mation on our own.
2014
2015 This can be rather tricky to do in some cases. For example, handling
2016 the following structure type definition when compiling for an i386/i486
2017 target (which only aligns long long's to 32-bit boundaries) can be very
2018 tricky:
2019
2020 struct S {
2021 int field1;
2022 long long field2:31;
2023 };
2024
2025 Fortunately, there is a simple rule-of-thumb which can be used in such
2026 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2027 the structure shown above. It decides to do this based upon one simple
2028 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2029 taining object" for each bit-field at the first (i.e. lowest addressed)
2030 legitimate alignment boundary (based upon the required minimum alignment
2031 for the declared type of the field) which it can possibly use, subject
2032 to the condition that there is still enough available space remaining
2033 in the containing object (when allocated at the selected point) to
8008b228 2034 fully accommodate all of the bits of the bit-field itself.
d4d4c5a8
RS
2035
2036 This simple rule makes it obvious why GCC allocates 8 bytes for each
2037 object of the structure type shown above. When looking for a place to
2038 allocate the "containing object" for `field2', the compiler simply tries
2039 to allocate a 64-bit "containing object" at each successive 32-bit
2040 boundary (starting at zero) until it finds a place to allocate that 64-
2041 bit field such that at least 31 contiguous (and previously unallocated)
2042 bits remain within that selected 64 bit field. (As it turns out, for
2043 the example above, the compiler finds that it is OK to allocate the
2044 "containing object" 64-bit field at bit-offset zero within the
2045 structure type.)
2046
2047 Here we attempt to work backwards from the limited set of facts we're
2048 given, and we try to deduce from those facts, where GCC must have
2049 believed that the containing object started (within the structure type).
2050
2051 The value we deduce is then used (by the callers of this routine) to
2052 generate AT_location and AT_bit_offset attributes for fields (both
665f2503 2053 bit-fields and, in the case of AT_location, regular fields as well). */
d4d4c5a8
RS
2054
2055 /* Figure out the bit-distance from the start of the structure to the
2056 "deepest" bit of the bit-field. */
2057 deepest_bitpos = bitpos_int + field_size_in_bits;
2058
2059 /* This is the tricky part. Use some fancy footwork to deduce where the
2060 lowest addressed bit of the containing object must be. */
2061 object_offset_in_bits
2062 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2063
2064 /* Compute the offset of the containing object in "alignment units". */
2065 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2066
2067 /* Compute the offset of the containing object in bytes. */
2068 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2069
d5042f7b
JW
2070 /* The above code assumes that the field does not cross an alignment
2071 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2072 or if the structure is packed. If this happens, then we get an object
2073 which starts after the bitfield, which means that the bit offset is
2074 negative. Gdb fails when given negative bit offsets. We avoid this
2075 by recomputing using the first bit of the bitfield. This will give
2076 us an object which does not completely contain the bitfield, but it
84d59453
JL
2077 will be aligned, and it will contain the first bit of the bitfield.
2078
2079 However, only do this for a BYTES_BIG_ENDIAN target. For a
2080 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2081 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2082 then we end up computing the object byte offset for the wrong word of the
2083 desired bitfield, which in turn causes the field offset to be negative
2084 in bit_offset_attribute. */
2085 if (BYTES_BIG_ENDIAN
2086 && object_offset_in_bits > bitpos_int)
d5042f7b
JW
2087 {
2088 deepest_bitpos = bitpos_int + 1;
2089 object_offset_in_bits
2090 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2091 object_offset_in_align_units = (object_offset_in_bits
2092 / type_align_in_bits);
2093 object_offset_in_bytes = (object_offset_in_align_units
2094 * type_align_in_bytes);
2095 }
2096
d4d4c5a8
RS
2097 return object_offset_in_bytes;
2098}
2099
340ccaab
TW
2100/****************************** attributes *********************************/
2101
2102/* The following routines are responsible for writing out the various types
2103 of Dwarf attributes (and any following data bytes associated with them).
2104 These routines are listed in order based on the numerical codes of their
2105 associated attributes. */
2106
2107/* Generate an AT_sibling attribute. */
2108
461b77c8 2109static inline void
340ccaab
TW
2110sibling_attribute ()
2111{
2112 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2113
2114 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2115 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2116 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2117}
2118
2119/* Output the form of location attributes suitable for whole variables and
2120 whole parameters. Note that the location attributes for struct fields
2121 are generated by the routine `data_member_location_attribute' below. */
2122
2123static void
2124location_attribute (rtl)
2125 register rtx rtl;
2126{
2127 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2128 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2129
2130 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2131 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2132 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2133 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2134 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2135
2136 /* Handle a special case. If we are about to output a location descriptor
2e494f70 2137 for a variable or parameter which has been optimized out of existence,
340ccaab 2138 don't do that. Instead we output a zero-length location descriptor
28b039e3
RS
2139 value as part of the location attribute.
2140
8008b228 2141 A variable which has been optimized out of existence will have a
28b039e3
RS
2142 DECL_RTL value which denotes a pseudo-reg.
2143
2144 Currently, in some rare cases, variables can have DECL_RTL values
2145 which look like (MEM (REG pseudo-reg#)). These cases are due to
2146 bugs elsewhere in the compiler. We treat such cases
8008b228 2147 as if the variable(s) in question had been optimized out of existence.
28b039e3
RS
2148
2149 Note that in all cases where we wish to express the fact that a
8008b228 2150 variable has been optimized out of existence, we do not simply
28b039e3
RS
2151 suppress the generation of the entire location attribute because
2152 the absence of a location attribute in certain kinds of DIEs is
2153 used to indicate something else entirely... i.e. that the DIE
9faa82d8 2154 represents an object declaration, but not a definition. So saith
28b039e3
RS
2155 the PLSIG.
2156 */
340ccaab 2157
28b039e3
RS
2158 if (! is_pseudo_reg (rtl)
2159 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
6a7a9f01 2160 output_loc_descriptor (rtl);
340ccaab
TW
2161
2162 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2163}
2164
2165/* Output the specialized form of location attribute used for data members
d4d4c5a8 2166 of struct and union types.
9a631e8e
RS
2167
2168 In the special case of a FIELD_DECL node which represents a bit-field,
2169 the "offset" part of this special location descriptor must indicate the
2170 distance in bytes from the lowest-addressed byte of the containing
2171 struct or union type to the lowest-addressed byte of the "containing
d4d4c5a8 2172 object" for the bit-field. (See the `field_byte_offset' function above.)
9a631e8e
RS
2173
2174 For any given bit-field, the "containing object" is a hypothetical
2175 object (of some integral or enum type) within which the given bit-field
2176 lives. The type of this hypothetical "containing object" is always the
d4d4c5a8
RS
2177 same as the declared type of the individual bit-field itself (for GCC
2178 anyway... the DWARF spec doesn't actually mandate this).
9a631e8e
RS
2179
2180 Note that it is the size (in bytes) of the hypothetical "containing
2181 object" which will be given in the AT_byte_size attribute for this
d4d4c5a8
RS
2182 bit-field. (See the `byte_size_attribute' function below.) It is
2183 also used when calculating the value of the AT_bit_offset attribute.
0f41302f 2184 (See the `bit_offset_attribute' function below.) */
9a631e8e 2185
340ccaab 2186static void
f37230f0
JM
2187data_member_location_attribute (t)
2188 register tree t;
340ccaab 2189{
f37230f0 2190 register unsigned object_offset_in_bytes;
340ccaab
TW
2191 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2192 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
9a631e8e 2193
f37230f0 2194 if (TREE_CODE (t) == TREE_VEC)
665f2503 2195 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
f37230f0
JM
2196 else
2197 object_offset_in_bytes = field_byte_offset (t);
2198
340ccaab
TW
2199 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2200 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2201 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2202 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2203 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2204 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
d4d4c5a8 2205 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
340ccaab
TW
2206 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2207 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2208}
2209
2210/* Output an AT_const_value attribute for a variable or a parameter which
2211 does not have a "location" either in memory or in a register. These
2212 things can arise in GNU C when a constant is passed as an actual
2213 parameter to an inlined function. They can also arise in C++ where
2214 declared constants do not necessarily get memory "homes". */
2215
2216static void
2217const_value_attribute (rtl)
2218 register rtx rtl;
2219{
2220 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2221 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2222
2223 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2224 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2225 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2226 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2227 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2228
2229 switch (GET_CODE (rtl))
2230 {
2231 case CONST_INT:
2232 /* Note that a CONST_INT rtx could represent either an integer or
2233 a floating-point constant. A CONST_INT is used whenever the
2234 constant will fit into a single word. In all such cases, the
2235 original mode of the constant value is wiped out, and the
2236 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2237 precise mode information for these constants, we always just
2238 output them using 4 bytes. */
2239
2240 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2241 break;
2242
2243 case CONST_DOUBLE:
2244 /* Note that a CONST_DOUBLE rtx could represent either an integer
2245 or a floating-point constant. A CONST_DOUBLE is used whenever
2246 the constant requires more than one word in order to be adequately
2247 represented. In all such cases, the original mode of the constant
2248 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2249 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2250
2251 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
665f2503
RK
2252 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2253 (unsigned int) CONST_DOUBLE_LOW (rtl));
340ccaab
TW
2254 break;
2255
2256 case CONST_STRING:
74153f8e 2257 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
340ccaab
TW
2258 break;
2259
2260 case SYMBOL_REF:
2261 case LABEL_REF:
2262 case CONST:
2263 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2264 break;
2265
2266 case PLUS:
2267 /* In cases where an inlined instance of an inline function is passed
2268 the address of an `auto' variable (which is local to the caller)
2269 we can get a situation where the DECL_RTL of the artificial
2270 local variable (for the inlining) which acts as a stand-in for
2271 the corresponding formal parameter (of the inline function)
2272 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2273 This is not exactly a compile-time constant expression, but it
2274 isn't the address of the (artificial) local variable either.
2275 Rather, it represents the *value* which the artificial local
2276 variable always has during its lifetime. We currently have no
2277 way to represent such quasi-constant values in Dwarf, so for now
2278 we just punt and generate an AT_const_value attribute with form
2279 FORM_BLOCK4 and a length of zero. */
2280 break;
d4d4c5a8
RS
2281
2282 default:
2283 abort (); /* No other kinds of rtx should be possible here. */
340ccaab
TW
2284 }
2285
2286 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2287}
2288
2289/* Generate *either* an AT_location attribute or else an AT_const_value
2290 data attribute for a variable or a parameter. We generate the
2291 AT_const_value attribute only in those cases where the given
2292 variable or parameter does not have a true "location" either in
2293 memory or in a register. This can happen (for example) when a
2294 constant is passed as an actual argument in a call to an inline
2295 function. (It's possible that these things can crop up in other
2296 ways also.) Note that one type of constant value which can be
2297 passed into an inlined function is a constant pointer. This can
2298 happen for example if an actual argument in an inlined function
2299 call evaluates to a compile-time constant address. */
2300
2301static void
2302location_or_const_value_attribute (decl)
2303 register tree decl;
2304{
2305 register rtx rtl;
2306
2307 if (TREE_CODE (decl) == ERROR_MARK)
2308 return;
2309
2310 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
648ebe7b 2311 {
0e02aa7e
RK
2312 /* Should never happen. */
2313 abort ();
2314 return;
648ebe7b 2315 }
340ccaab 2316
0e02aa7e
RK
2317 /* Here we have to decide where we are going to say the parameter "lives"
2318 (as far as the debugger is concerned). We only have a couple of choices.
2319 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2320 normally indicates where the parameter lives during most of the activa-
2321 tion of the function. If optimization is enabled however, this could
2322 be either NULL or else a pseudo-reg. Both of those cases indicate that
2323 the parameter doesn't really live anywhere (as far as the code generation
2324 parts of GCC are concerned) during most of the function's activation.
2325 That will happen (for example) if the parameter is never referenced
2326 within the function.
2327
2328 We could just generate a location descriptor here for all non-NULL
2329 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2330 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2331 cases where DECL_RTL is NULL or is a pseudo-reg.
2332
2333 Note however that we can only get away with using DECL_INCOMING_RTL as
2334 a backup substitute for DECL_RTL in certain limited cases. In cases
2335 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2336 we can be sure that the parameter was passed using the same type as it
2337 is declared to have within the function, and that its DECL_INCOMING_RTL
2338 points us to a place where a value of that type is passed. In cases
2339 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2340 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2341 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2342 points us to a value of some type which is *different* from the type
2343 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2344 to generate a location attribute in such cases, the debugger would
2345 end up (for example) trying to fetch a `float' from a place which
2346 actually contains the first part of a `double'. That would lead to
2347 really incorrect and confusing output at debug-time, and we don't
2348 want that now do we?
2349
2350 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2351 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2352 couple of cute exceptions however. On little-endian machines we can
2353 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2354 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2355 an integral type which is smaller than TREE_TYPE(decl). These cases
2356 arise when (on a little-endian machine) a non-prototyped function has
2357 a parameter declared to be of type `short' or `char'. In such cases,
2358 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2359 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2360 passed `int' value. If the debugger then uses that address to fetch a
2361 `short' or a `char' (on a little-endian machine) the result will be the
2362 correct data, so we allow for such exceptional cases below.
2363
2364 Note that our goal here is to describe the place where the given formal
2365 parameter lives during most of the function's activation (i.e. between
2366 the end of the prologue and the start of the epilogue). We'll do that
2367 as best as we can. Note however that if the given formal parameter is
2368 modified sometime during the execution of the function, then a stack
2369 backtrace (at debug-time) will show the function as having been called
2370 with the *new* value rather than the value which was originally passed
2371 in. This happens rarely enough that it is not a major problem, but it
2372 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2373 may generate two additional attributes for any given TAG_formal_parameter
2374 DIE which will describe the "passed type" and the "passed location" for
2375 the given formal parameter in addition to the attributes we now generate
2376 to indicate the "declared type" and the "active location" for each
2377 parameter. This additional set of attributes could be used by debuggers
2378 for stack backtraces.
2379
2380 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2381 can be NULL also. This happens (for example) for inlined-instances of
2382 inline function formal parameters which are never referenced. This really
2383 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2384 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2385 these values for inlined instances of inline function parameters, so
956d6950 2386 when we see such cases, we are just out-of-luck for the time
0e02aa7e
RK
2387 being (until integrate.c gets fixed).
2388 */
2389
2390 /* Use DECL_RTL as the "location" unless we find something better. */
2391 rtl = DECL_RTL (decl);
2392
2393 if (TREE_CODE (decl) == PARM_DECL)
2394 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2395 {
2396 /* This decl represents a formal parameter which was optimized out. */
69d6b01d
RS
2397 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2398 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
0e02aa7e
RK
2399
2400 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2401 *all* cases where (rtl == NULL_RTX) just below. */
2402
2403 if (declared_type == passed_type)
2404 rtl = DECL_INCOMING_RTL (decl);
f76b9db2 2405 else if (! BYTES_BIG_ENDIAN)
0e02aa7e 2406 if (TREE_CODE (declared_type) == INTEGER_TYPE)
d0f062fb 2407 /* NMS WTF? */
0e02aa7e
RK
2408 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2409 rtl = DECL_INCOMING_RTL (decl);
0e02aa7e
RK
2410 }
2411
2412 if (rtl == NULL_RTX)
340ccaab
TW
2413 return;
2414
1914f5da 2415 rtl = eliminate_regs (rtl, 0, NULL_RTX);
6a7a9f01 2416#ifdef LEAF_REG_REMAP
54ff41b7 2417 if (current_function_uses_only_leaf_regs)
5f52dcfe 2418 leaf_renumber_regs_insn (rtl);
6a7a9f01
JM
2419#endif
2420
340ccaab
TW
2421 switch (GET_CODE (rtl))
2422 {
e9a25f70
JL
2423 case ADDRESSOF:
2424 /* The address of a variable that was optimized away; don't emit
2425 anything. */
2426 break;
2427
340ccaab
TW
2428 case CONST_INT:
2429 case CONST_DOUBLE:
2430 case CONST_STRING:
2431 case SYMBOL_REF:
2432 case LABEL_REF:
2433 case CONST:
2434 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2435 const_value_attribute (rtl);
2436 break;
2437
2438 case MEM:
2439 case REG:
2440 case SUBREG:
2441 location_attribute (rtl);
2442 break;
2443
7b1bcb49
JW
2444 case CONCAT:
2445 /* ??? CONCAT is used for complex variables, which may have the real
2446 part stored in one place and the imag part stored somewhere else.
2447 DWARF1 has no way to describe a variable that lives in two different
2448 places, so we just describe where the first part lives, and hope that
2449 the second part is stored after it. */
2450 location_attribute (XEXP (rtl, 0));
2451 break;
2452
340ccaab
TW
2453 default:
2454 abort (); /* Should never happen. */
2455 }
2456}
2457
2458/* Generate an AT_name attribute given some string value to be included as
9a631e8e 2459 the value of the attribute. */
340ccaab 2460
461b77c8 2461static inline void
340ccaab 2462name_attribute (name_string)
a996cbd4 2463 register const char *name_string;
340ccaab 2464{
75791cee
TW
2465 if (name_string && *name_string)
2466 {
2467 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
74153f8e 2468 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
75791cee 2469 }
340ccaab
TW
2470}
2471
461b77c8 2472static inline void
340ccaab
TW
2473fund_type_attribute (ft_code)
2474 register unsigned ft_code;
2475{
2476 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2477 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2478}
2479
2480static void
2481mod_fund_type_attribute (type, decl_const, decl_volatile)
2482 register tree type;
2483 register int decl_const;
2484 register int decl_volatile;
2485{
2486 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2487 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2488
2489 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2490 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2491 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2492 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2493 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2494 write_modifier_bytes (type, decl_const, decl_volatile);
2495 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2496 fundamental_type_code (root_type (type)));
2497 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2498}
2499
461b77c8 2500static inline void
340ccaab
TW
2501user_def_type_attribute (type)
2502 register tree type;
2503{
2504 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2505
2506 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2507 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2508 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2509}
2510
2511static void
2512mod_u_d_type_attribute (type, decl_const, decl_volatile)
2513 register tree type;
2514 register int decl_const;
2515 register int decl_volatile;
2516{
2517 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2518 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2519 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2520
2521 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2522 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2523 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2524 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2525 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2526 write_modifier_bytes (type, decl_const, decl_volatile);
2527 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2528 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2529 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2530}
2531
d4d4c5a8 2532#ifdef USE_ORDERING_ATTRIBUTE
461b77c8 2533static inline void
340ccaab
TW
2534ordering_attribute (ordering)
2535 register unsigned ordering;
2536{
2537 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2538 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2539}
d4d4c5a8 2540#endif /* defined(USE_ORDERING_ATTRIBUTE) */
340ccaab
TW
2541
2542/* Note that the block of subscript information for an array type also
2543 includes information about the element type of type given array type. */
2544
2545static void
2546subscript_data_attribute (type)
2547 register tree type;
2548{
2549 register unsigned dimension_number;
2550 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2551 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2552
2553 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2554 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2555 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2556 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2557 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2558
2559 /* The GNU compilers represent multidimensional array types as sequences
2560 of one dimensional array types whose element types are themselves array
2561 types. Here we squish that down, so that each multidimensional array
2562 type gets only one array_type DIE in the Dwarf debugging info. The
2563 draft Dwarf specification say that we are allowed to do this kind
2564 of compression in C (because there is no difference between an
2565 array or arrays and a multidimensional array in C) but for other
2566 source languages (e.g. Ada) we probably shouldn't do this. */
2567
2568 for (dimension_number = 0;
2569 TREE_CODE (type) == ARRAY_TYPE;
2570 type = TREE_TYPE (type), dimension_number++)
2571 {
2572 register tree domain = TYPE_DOMAIN (type);
2573
2574 /* Arrays come in three flavors. Unspecified bounds, fixed
2575 bounds, and (in GNU C only) variable bounds. Handle all
2576 three forms here. */
2577
2578 if (domain)
2579 {
2580 /* We have an array type with specified bounds. */
2581
2582 register tree lower = TYPE_MIN_VALUE (domain);
2583 register tree upper = TYPE_MAX_VALUE (domain);
2584
2585 /* Handle only fundamental types as index types for now. */
2586
2587 if (! type_is_fundamental (domain))
2588 abort ();
2589
0f41302f 2590 /* Output the representation format byte for this dimension. */
340ccaab
TW
2591
2592 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
e1ee5cdc
RH
2593 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2594 (upper && TREE_CODE (upper) == INTEGER_CST)));
340ccaab
TW
2595
2596 /* Output the index type for this dimension. */
2597
2598 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2599 fundamental_type_code (domain));
2600
2601 /* Output the representation for the lower bound. */
2602
2603 output_bound_representation (lower, dimension_number, 'l');
2604
2605 /* Output the representation for the upper bound. */
2606
2607 output_bound_representation (upper, dimension_number, 'u');
2608 }
2609 else
2610 {
2611 /* We have an array type with an unspecified length. For C and
2612 C++ we can assume that this really means that (a) the index
2613 type is an integral type, and (b) the lower bound is zero.
2614 Note that Dwarf defines the representation of an unspecified
2615 (upper) bound as being a zero-length location description. */
2616
2617 /* Output the array-bounds format byte. */
2618
2619 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2620
2621 /* Output the (assumed) index type. */
2622
2623 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2624
2625 /* Output the (assumed) lower bound (constant) value. */
2626
2627 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2628
2629 /* Output the (empty) location description for the upper bound. */
2630
2631 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2632 }
2633 }
2634
9faa82d8 2635 /* Output the prefix byte that says that the element type is coming up. */
340ccaab
TW
2636
2637 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2638
2639 /* Output a representation of the type of the elements of this array type. */
2640
2641 type_attribute (type, 0, 0);
2642
2643 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2644}
2645
2646static void
2647byte_size_attribute (tree_node)
2648 register tree tree_node;
2649{
2650 register unsigned size;
2651
2652 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2653 switch (TREE_CODE (tree_node))
2654 {
2655 case ERROR_MARK:
2656 size = 0;
2657 break;
2658
2659 case ENUMERAL_TYPE:
2660 case RECORD_TYPE:
2661 case UNION_TYPE:
c1b98a95 2662 case QUAL_UNION_TYPE:
fa405625 2663 case ARRAY_TYPE:
340ccaab
TW
2664 size = int_size_in_bytes (tree_node);
2665 break;
2666
2667 case FIELD_DECL:
9a631e8e 2668 /* For a data member of a struct or union, the AT_byte_size is
d4d4c5a8 2669 generally given as the number of bytes normally allocated for
9a631e8e
RS
2670 an object of the *declared* type of the member itself. This
2671 is true even for bit-fields. */
d4d4c5a8
RS
2672 size = simple_type_size_in_bits (field_type (tree_node))
2673 / BITS_PER_UNIT;
340ccaab
TW
2674 break;
2675
2676 default:
2677 abort ();
2678 }
9a631e8e
RS
2679
2680 /* Note that `size' might be -1 when we get to this point. If it
2681 is, that indicates that the byte size of the entity in question
2682 is variable. We have no good way of expressing this fact in Dwarf
2683 at the present time, so just let the -1 pass on through. */
2684
340ccaab
TW
2685 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2686}
2687
9a631e8e
RS
2688/* For a FIELD_DECL node which represents a bit-field, output an attribute
2689 which specifies the distance in bits from the highest order bit of the
2690 "containing object" for the bit-field to the highest order bit of the
2691 bit-field itself.
2692
2693 For any given bit-field, the "containing object" is a hypothetical
2694 object (of some integral or enum type) within which the given bit-field
2695 lives. The type of this hypothetical "containing object" is always the
2696 same as the declared type of the individual bit-field itself.
2697
d4d4c5a8
RS
2698 The determination of the exact location of the "containing object" for
2699 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2700 function (above).
2701
9a631e8e
RS
2702 Note that it is the size (in bytes) of the hypothetical "containing
2703 object" which will be given in the AT_byte_size attribute for this
461b77c8 2704 bit-field. (See `byte_size_attribute' above.) */
340ccaab 2705
461b77c8 2706static inline void
340ccaab
TW
2707bit_offset_attribute (decl)
2708 register tree decl;
2709{
665f2503
RK
2710 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
2711 tree type = DECL_BIT_FIELD_TYPE (decl);
2712 HOST_WIDE_INT bitpos_int;
2713 HOST_WIDE_INT highest_order_object_bit_offset;
2714 HOST_WIDE_INT highest_order_field_bit_offset;
2715 HOST_WIDE_INT bit_offset;
9a631e8e 2716
3a88cbd1
JL
2717 /* Must be a bit field. */
2718 if (!type
2719 || TREE_CODE (decl) != FIELD_DECL)
2720 abort ();
9a631e8e 2721
665f2503
RK
2722 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
2723 if we encounter such things, just return without generating any
2724 attribute whatsoever. */
9a631e8e 2725
665f2503
RK
2726 if (! host_integerp (bit_position (decl), 0)
2727 || ! host_integerp (DECL_SIZE (decl), 1))
9a631e8e 2728 return;
665f2503
RK
2729
2730 bitpos_int = int_bit_position (decl);
9a631e8e 2731
d4d4c5a8
RS
2732 /* Note that the bit offset is always the distance (in bits) from the
2733 highest-order bit of the "containing object" to the highest-order
2734 bit of the bit-field itself. Since the "high-order end" of any
2735 object or field is different on big-endian and little-endian machines,
2736 the computation below must take account of these differences. */
9a631e8e 2737
d4d4c5a8
RS
2738 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2739 highest_order_field_bit_offset = bitpos_int;
648ebe7b 2740
f76b9db2
ILT
2741 if (! BYTES_BIG_ENDIAN)
2742 {
665f2503 2743 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
f76b9db2
ILT
2744 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2745 }
d4d4c5a8
RS
2746
2747 bit_offset =
f76b9db2
ILT
2748 (! BYTES_BIG_ENDIAN
2749 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2750 : highest_order_field_bit_offset - highest_order_object_bit_offset);
340ccaab
TW
2751
2752 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
d4d4c5a8 2753 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
340ccaab
TW
2754}
2755
2756/* For a FIELD_DECL node which represents a bit field, output an attribute
2757 which specifies the length in bits of the given field. */
2758
461b77c8 2759static inline void
340ccaab
TW
2760bit_size_attribute (decl)
2761 register tree decl;
2762{
3a88cbd1
JL
2763 /* Must be a field and a bit field. */
2764 if (TREE_CODE (decl) != FIELD_DECL
2765 || ! DECL_BIT_FIELD_TYPE (decl))
2766 abort ();
340ccaab 2767
665f2503
RK
2768 if (host_integerp (DECL_SIZE (decl), 1))
2769 {
2770 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2771 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2772 tree_low_cst (DECL_SIZE (decl), 1));
2773 }
340ccaab
TW
2774}
2775
2776/* The following routine outputs the `element_list' attribute for enumeration
2777 type DIEs. The element_lits attribute includes the names and values of
2778 all of the enumeration constants associated with the given enumeration
2779 type. */
2780
461b77c8 2781static inline void
340ccaab
TW
2782element_list_attribute (element)
2783 register tree element;
2784{
2785 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2786 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2787
2788 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2789 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2790 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2791 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2792 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2793
2794 /* Here we output a list of value/name pairs for each enumeration constant
2795 defined for this enumeration type (as required), but we do it in REVERSE
2796 order. The order is the one required by the draft #5 Dwarf specification
2797 published by the UI/PLSIG. */
2798
2799 output_enumeral_list (element); /* Recursively output the whole list. */
2800
2801 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2802}
2803
2804/* Generate an AT_stmt_list attribute. These are normally present only in
2805 DIEs with a TAG_compile_unit tag. */
2806
461b77c8 2807static inline void
340ccaab 2808stmt_list_attribute (label)
a996cbd4 2809 register const char *label;
340ccaab
TW
2810{
2811 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2812 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2813 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2814}
2815
2816/* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2817 for a subroutine DIE. */
2818
461b77c8 2819static inline void
340ccaab 2820low_pc_attribute (asm_low_label)
a996cbd4 2821 register const char *asm_low_label;
340ccaab
TW
2822{
2823 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2824 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2825}
2826
2827/* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2828 subroutine DIE. */
2829
461b77c8 2830static inline void
340ccaab 2831high_pc_attribute (asm_high_label)
a996cbd4 2832 register const char *asm_high_label;
340ccaab
TW
2833{
2834 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2835 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2836}
2837
2a819d04
TW
2838/* Generate an AT_body_begin attribute for a subroutine DIE. */
2839
461b77c8 2840static inline void
2a819d04 2841body_begin_attribute (asm_begin_label)
a996cbd4 2842 register const char *asm_begin_label;
2a819d04
TW
2843{
2844 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2845 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2846}
2847
2848/* Generate an AT_body_end attribute for a subroutine DIE. */
2849
461b77c8 2850static inline void
2a819d04 2851body_end_attribute (asm_end_label)
a996cbd4 2852 register const char *asm_end_label;
2a819d04
TW
2853{
2854 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2855 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2856}
2857
340ccaab
TW
2858/* Generate an AT_language attribute given a LANG value. These attributes
2859 are used only within TAG_compile_unit DIEs. */
2860
461b77c8 2861static inline void
340ccaab
TW
2862language_attribute (language_code)
2863 register unsigned language_code;
2864{
2865 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2866 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2867}
2868
461b77c8 2869static inline void
340ccaab
TW
2870member_attribute (context)
2871 register tree context;
2872{
2873 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2874
2875 /* Generate this attribute only for members in C++. */
2876
c7d6dca2 2877 if (context != NULL && is_tagged_type (context))
340ccaab
TW
2878 {
2879 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2880 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2881 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2882 }
2883}
2884
7a87758d 2885#if 0
461b77c8 2886static inline void
340ccaab
TW
2887string_length_attribute (upper_bound)
2888 register tree upper_bound;
2889{
2890 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2891 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2892
2893 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2894 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2895 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2896 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2897 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2898 output_bound_representation (upper_bound, 0, 'u');
2899 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2900}
7a87758d 2901#endif
340ccaab 2902
461b77c8 2903static inline void
340ccaab 2904comp_dir_attribute (dirname)
a996cbd4 2905 register const char *dirname;
340ccaab
TW
2906{
2907 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
74153f8e 2908 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
340ccaab
TW
2909}
2910
461b77c8 2911static inline void
340ccaab 2912sf_names_attribute (sf_names_start_label)
a996cbd4 2913 register const char *sf_names_start_label;
340ccaab
TW
2914{
2915 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2916 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2917 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2918}
2919
461b77c8 2920static inline void
340ccaab 2921src_info_attribute (src_info_start_label)
a996cbd4 2922 register const char *src_info_start_label;
340ccaab
TW
2923{
2924 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2925 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2926 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2927}
2928
461b77c8 2929static inline void
340ccaab 2930mac_info_attribute (mac_info_start_label)
a996cbd4 2931 register const char *mac_info_start_label;
340ccaab
TW
2932{
2933 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2934 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2935 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2936}
2937
461b77c8 2938static inline void
340ccaab
TW
2939prototyped_attribute (func_type)
2940 register tree func_type;
2941{
2942 if ((strcmp (language_string, "GNU C") == 0)
2943 && (TYPE_ARG_TYPES (func_type) != NULL))
2944 {
2945 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
74153f8e 2946 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
340ccaab
TW
2947 }
2948}
2949
461b77c8 2950static inline void
340ccaab 2951producer_attribute (producer)
a996cbd4 2952 register const char *producer;
340ccaab
TW
2953{
2954 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
74153f8e 2955 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
340ccaab
TW
2956}
2957
461b77c8 2958static inline void
340ccaab
TW
2959inline_attribute (decl)
2960 register tree decl;
2961{
0924ddef 2962 if (DECL_INLINE (decl))
340ccaab
TW
2963 {
2964 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
74153f8e 2965 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
340ccaab
TW
2966 }
2967}
2968
461b77c8 2969static inline void
340ccaab
TW
2970containing_type_attribute (containing_type)
2971 register tree containing_type;
2972{
2973 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2974
2975 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2976 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2977 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2978}
2979
461b77c8 2980static inline void
04077c53
RS
2981abstract_origin_attribute (origin)
2982 register tree origin;
2983{
2984 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2985
2986 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2987 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2988 {
2989 case 'd':
2990 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2991 break;
2992
2993 case 't':
2994 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2995 break;
2996
2997 default:
2998 abort (); /* Should never happen. */
2999
3000 }
3001 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3002}
3003
3004#ifdef DWARF_DECL_COORDINATES
461b77c8 3005static inline void
9a631e8e
RS
3006src_coords_attribute (src_fileno, src_lineno)
3007 register unsigned src_fileno;
3008 register unsigned src_lineno;
3009{
9a631e8e
RS
3010 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3011 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3012 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
9a631e8e 3013}
04077c53
RS
3014#endif /* defined(DWARF_DECL_COORDINATES) */
3015
461b77c8 3016static inline void
04077c53
RS
3017pure_or_virtual_attribute (func_decl)
3018 register tree func_decl;
3019{
3020 if (DECL_VIRTUAL_P (func_decl))
3021 {
ece0ca60 3022#if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
04077c53
RS
3023 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3024 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3025 else
ece0ca60 3026#endif
04077c53 3027 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
74153f8e 3028 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
04077c53
RS
3029 }
3030}
9a631e8e 3031
340ccaab
TW
3032/************************* end of attributes *****************************/
3033
3034/********************* utility routines for DIEs *************************/
3035
9a631e8e
RS
3036/* Output an AT_name attribute and an AT_src_coords attribute for the
3037 given decl, but only if it actually has a name. */
3038
d4d4c5a8 3039static void
9a631e8e
RS
3040name_and_src_coords_attributes (decl)
3041 register tree decl;
3042{
3043 register tree decl_name = DECL_NAME (decl);
3044
3045 if (decl_name && IDENTIFIER_POINTER (decl_name))
3046 {
3047 name_attribute (IDENTIFIER_POINTER (decl_name));
75791cee
TW
3048#ifdef DWARF_DECL_COORDINATES
3049 {
3050 register unsigned file_index;
3051
3052 /* This is annoying, but we have to pop out of the .debug section
3053 for a moment while we call `lookup_filename' because calling it
3054 may cause a temporary switch into the .debug_sfnames section and
38e01259 3055 most svr4 assemblers are not smart enough to be able to nest
75791cee
TW
3056 section switches to any depth greater than one. Note that we
3057 also can't skirt this issue by delaying all output to the
3058 .debug_sfnames section unit the end of compilation because that
3059 would cause us to have inter-section forward references and
3060 Fred Fish sez that m68k/svr4 assemblers botch those. */
3061
3062 ASM_OUTPUT_POP_SECTION (asm_out_file);
3063 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3064 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3065
3066 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3067 }
d4d4c5a8 3068#endif /* defined(DWARF_DECL_COORDINATES) */
9a631e8e
RS
3069 }
3070}
3071
340ccaab
TW
3072/* Many forms of DIEs contain a "type description" part. The following
3073 routine writes out these "type descriptor" parts. */
3074
3075static void
3076type_attribute (type, decl_const, decl_volatile)
3077 register tree type;
3078 register int decl_const;
3079 register int decl_volatile;
3080{
3081 register enum tree_code code = TREE_CODE (type);
3082 register int root_type_modified;
3083
f01ea0c6 3084 if (code == ERROR_MARK)
340ccaab
TW
3085 return;
3086
3087 /* Handle a special case. For functions whose return type is void,
3088 we generate *no* type attribute. (Note that no object may have
3089 type `void', so this only applies to function return types. */
3090
f01ea0c6 3091 if (code == VOID_TYPE)
340ccaab
TW
3092 return;
3093
f01ea0c6
RK
3094 /* If this is a subtype, find the underlying type. Eventually,
3095 this should write out the appropriate subtype info. */
3096 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3097 && TREE_TYPE (type) != 0)
3098 type = TREE_TYPE (type), code = TREE_CODE (type);
3099
340ccaab
TW
3100 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3101 || decl_const || decl_volatile
3102 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3103
3104 if (type_is_fundamental (root_type (type)))
5e9defae
KG
3105 {
3106 if (root_type_modified)
340ccaab 3107 mod_fund_type_attribute (type, decl_const, decl_volatile);
5e9defae 3108 else
340ccaab 3109 fund_type_attribute (fundamental_type_code (type));
5e9defae 3110 }
340ccaab 3111 else
5e9defae
KG
3112 {
3113 if (root_type_modified)
340ccaab 3114 mod_u_d_type_attribute (type, decl_const, decl_volatile);
5e9defae 3115 else
69d6b01d 3116 /* We have to get the type_main_variant here (and pass that to the
0591b9c6
RS
3117 `user_def_type_attribute' routine) because the ..._TYPE node we
3118 have might simply be a *copy* of some original type node (where
3119 the copy was created to help us keep track of typedef names)
3120 and that copy might have a different TYPE_UID from the original
3121 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3122 is labeling a given type DIE for future reference, it always and
3123 only creates labels for DIEs representing *main variants*, and it
3124 never even knows about non-main-variants.) */
69d6b01d 3125 user_def_type_attribute (type_main_variant (type));
5e9defae 3126 }
340ccaab
TW
3127}
3128
3129/* Given a tree pointer to a struct, class, union, or enum type node, return
3130 a pointer to the (string) tag name for the given type, or zero if the
3131 type was declared without a tag. */
3132
d3e3972c 3133static const char *
340ccaab
TW
3134type_tag (type)
3135 register tree type;
3136{
d3e3972c 3137 register const char *name = 0;
340ccaab
TW
3138
3139 if (TYPE_NAME (type) != 0)
3140 {
3141 register tree t = 0;
3142
3143 /* Find the IDENTIFIER_NODE for the type name. */
3144 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3145 t = TYPE_NAME (type);
340ccaab 3146
85f8926e
JM
3147 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3148 a TYPE_DECL node, regardless of whether or not a `typedef' was
3149 involved. */
a94dbf2c
JM
3150 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3151 && ! DECL_IGNORED_P (TYPE_NAME (type)))
340ccaab 3152 t = DECL_NAME (TYPE_NAME (type));
85f8926e 3153
340ccaab
TW
3154 /* Now get the name as a string, or invent one. */
3155 if (t != 0)
3156 name = IDENTIFIER_POINTER (t);
3157 }
3158
3159 return (name == 0 || *name == '\0') ? 0 : name;
3160}
3161
461b77c8 3162static inline void
340ccaab
TW
3163dienum_push ()
3164{
3165 /* Start by checking if the pending_sibling_stack needs to be expanded.
3166 If necessary, expand it. */
3167
3168 if (pending_siblings == pending_siblings_allocated)
3169 {
3170 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3171 pending_sibling_stack
3172 = (unsigned *) xrealloc (pending_sibling_stack,
3173 pending_siblings_allocated * sizeof(unsigned));
3174 }
3175
3176 pending_siblings++;
3177 NEXT_DIE_NUM = next_unused_dienum++;
3178}
3179
3180/* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3181 NEXT_DIE_NUM. */
3182
461b77c8 3183static inline void
340ccaab
TW
3184dienum_pop ()
3185{
3186 pending_siblings--;
3187}
3188
461b77c8 3189static inline tree
340ccaab
TW
3190member_declared_type (member)
3191 register tree member;
3192{
3193 return (DECL_BIT_FIELD_TYPE (member))
3194 ? DECL_BIT_FIELD_TYPE (member)
3195 : TREE_TYPE (member);
3196}
3197
692e06f5
RS
3198/* Get the function's label, as described by its RTL.
3199 This may be different from the DECL_NAME name used
3200 in the source file. */
3201
3cce094d 3202static const char *
692e06f5
RS
3203function_start_label (decl)
3204 register tree decl;
3205{
3206 rtx x;
3cce094d 3207 const char *fnname;
692e06f5
RS
3208
3209 x = DECL_RTL (decl);
3210 if (GET_CODE (x) != MEM)
3211 abort ();
3212 x = XEXP (x, 0);
3213 if (GET_CODE (x) != SYMBOL_REF)
3214 abort ();
3215 fnname = XSTR (x, 0);
3216 return fnname;
3217}
3218
3219
340ccaab
TW
3220/******************************* DIEs ************************************/
3221
3222/* Output routines for individual types of DIEs. */
3223
3224/* Note that every type of DIE (except a null DIE) gets a sibling. */
3225
3226static void
3227output_array_type_die (arg)
3228 register void *arg;
3229{
3230 register tree type = arg;
3231
3232 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3233 sibling_attribute ();
3234 equate_type_number_to_die_number (type);
3235 member_attribute (TYPE_CONTEXT (type));
3236
3237 /* I believe that we can default the array ordering. SDB will probably
3238 do the right things even if AT_ordering is not present. It's not
3239 even an issue until we start to get into multidimensional arrays
9a631e8e
RS
3240 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3241 dimensional arrays, then we'll have to put the AT_ordering attribute
3242 back in. (But if and when we find out that we need to put these in,
3243 we will only do so for multidimensional arrays. After all, we don't
3244 want to waste space in the .debug section now do we?) */
340ccaab 3245
d4d4c5a8 3246#ifdef USE_ORDERING_ATTRIBUTE
340ccaab 3247 ordering_attribute (ORD_row_major);
d4d4c5a8 3248#endif /* defined(USE_ORDERING_ATTRIBUTE) */
340ccaab
TW
3249
3250 subscript_data_attribute (type);
3251}
3252
3253static void
3254output_set_type_die (arg)
3255 register void *arg;
3256{
3257 register tree type = arg;
3258
3259 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3260 sibling_attribute ();
3261 equate_type_number_to_die_number (type);
3262 member_attribute (TYPE_CONTEXT (type));
3263 type_attribute (TREE_TYPE (type), 0, 0);
3264}
3265
3266#if 0
3267/* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
0f41302f 3268
340ccaab
TW
3269static void
3270output_entry_point_die (arg)
3271 register void *arg;
3272{
3273 register tree decl = arg;
d4d4c5a8 3274 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3275
3276 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3277 sibling_attribute ();
3278 dienum_push ();
d4d4c5a8
RS
3279 if (origin != NULL)
3280 abstract_origin_attribute (origin);
3281 else
3282 {
3283 name_and_src_coords_attributes (decl);
3284 member_attribute (DECL_CONTEXT (decl));
3285 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3286 }
3287 if (DECL_ABSTRACT (decl))
3288 equate_decl_number_to_die_number (decl);
3289 else
692e06f5 3290 low_pc_attribute (function_start_label (decl));
340ccaab
TW
3291}
3292#endif
3293
d4d4c5a8
RS
3294/* Output a DIE to represent an inlined instance of an enumeration type. */
3295
3296static void
3297output_inlined_enumeration_type_die (arg)
3298 register void *arg;
3299{
3300 register tree type = arg;
3301
3302 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3303 sibling_attribute ();
3a88cbd1
JL
3304 if (!TREE_ASM_WRITTEN (type))
3305 abort ();
d4d4c5a8
RS
3306 abstract_origin_attribute (type);
3307}
3308
3309/* Output a DIE to represent an inlined instance of a structure type. */
3310
3311static void
3312output_inlined_structure_type_die (arg)
3313 register void *arg;
3314{
3315 register tree type = arg;
3316
3317 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3318 sibling_attribute ();
3a88cbd1
JL
3319 if (!TREE_ASM_WRITTEN (type))
3320 abort ();
d4d4c5a8
RS
3321 abstract_origin_attribute (type);
3322}
3323
3324/* Output a DIE to represent an inlined instance of a union type. */
3325
3326static void
3327output_inlined_union_type_die (arg)
3328 register void *arg;
3329{
3330 register tree type = arg;
3331
3332 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3333 sibling_attribute ();
3a88cbd1
JL
3334 if (!TREE_ASM_WRITTEN (type))
3335 abort ();
d4d4c5a8
RS
3336 abstract_origin_attribute (type);
3337}
3338
340ccaab
TW
3339/* Output a DIE to represent an enumeration type. Note that these DIEs
3340 include all of the information about the enumeration values also.
3341 This information is encoded into the element_list attribute. */
3342
3343static void
3344output_enumeration_type_die (arg)
3345 register void *arg;
3346{
3347 register tree type = arg;
3348
3349 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3350 sibling_attribute ();
3351 equate_type_number_to_die_number (type);
3352 name_attribute (type_tag (type));
3353 member_attribute (TYPE_CONTEXT (type));
3354
3355 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3356 given enum type is incomplete, do not generate the AT_byte_size
3357 attribute or the AT_element_list attribute. */
3358
d0f062fb 3359 if (COMPLETE_TYPE_P (type))
340ccaab
TW
3360 {
3361 byte_size_attribute (type);
3362 element_list_attribute (TYPE_FIELDS (type));
3363 }
3364}
3365
3366/* Output a DIE to represent either a real live formal parameter decl or
3367 to represent just the type of some formal parameter position in some
3368 function type.
3369
3370 Note that this routine is a bit unusual because its argument may be
d4d4c5a8
RS
3371 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3372 represents an inlining of some PARM_DECL) or else some sort of a
3373 ..._TYPE node. If it's the former then this function is being called
3374 to output a DIE to represent a formal parameter object (or some inlining
3375 thereof). If it's the latter, then this function is only being called
3376 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3377 formal argument type of some subprogram type. */
340ccaab
TW
3378
3379static void
3380output_formal_parameter_die (arg)
3381 register void *arg;
3382{
d4d4c5a8 3383 register tree node = arg;
340ccaab
TW
3384
3385 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3386 sibling_attribute ();
d4d4c5a8
RS
3387
3388 switch (TREE_CODE_CLASS (TREE_CODE (node)))
340ccaab 3389 {
d4d4c5a8
RS
3390 case 'd': /* We were called with some kind of a ..._DECL node. */
3391 {
3392 register tree origin = decl_ultimate_origin (node);
3393
3394 if (origin != NULL)
3395 abstract_origin_attribute (origin);
3396 else
3397 {
3398 name_and_src_coords_attributes (node);
3399 type_attribute (TREE_TYPE (node),
3400 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3401 }
3402 if (DECL_ABSTRACT (node))
3403 equate_decl_number_to_die_number (node);
3404 else
3405 location_or_const_value_attribute (node);
3406 }
3407 break;
3408
3409 case 't': /* We were called with some kind of a ..._TYPE node. */
3410 type_attribute (node, 0, 0);
3411 break;
3412
3413 default:
3414 abort (); /* Should never happen. */
340ccaab 3415 }
340ccaab
TW
3416}
3417
3418/* Output a DIE to represent a declared function (either file-scope
3419 or block-local) which has "external linkage" (according to ANSI-C). */
3420
3421static void
3422output_global_subroutine_die (arg)
3423 register void *arg;
3424{
3425 register tree decl = arg;
d4d4c5a8 3426 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3427
3428 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3429 sibling_attribute ();
3430 dienum_push ();
d4d4c5a8
RS
3431 if (origin != NULL)
3432 abstract_origin_attribute (origin);
3433 else
340ccaab 3434 {
d4d4c5a8 3435 register tree type = TREE_TYPE (decl);
340ccaab 3436
d4d4c5a8
RS
3437 name_and_src_coords_attributes (decl);
3438 inline_attribute (decl);
3439 prototyped_attribute (type);
3440 member_attribute (DECL_CONTEXT (decl));
3441 type_attribute (TREE_TYPE (type), 0, 0);
3442 pure_or_virtual_attribute (decl);
3443 }
3444 if (DECL_ABSTRACT (decl))
3445 equate_decl_number_to_die_number (decl);
3446 else
3447 {
a94dbf2c
JM
3448 if (! DECL_EXTERNAL (decl) && ! in_class
3449 && decl == current_function_decl)
d4d4c5a8 3450 {
2a819d04 3451 char label[MAX_ARTIFICIAL_LABEL_BYTES];
d4d4c5a8 3452
692e06f5 3453 low_pc_attribute (function_start_label (decl));
2a819d04
TW
3454 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3455 high_pc_attribute (label);
a94dbf2c
JM
3456 if (use_gnu_debug_info_extensions)
3457 {
3458 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3459 body_begin_attribute (label);
3460 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3461 body_end_attribute (label);
3462 }
d4d4c5a8 3463 }
340ccaab
TW
3464 }
3465}
3466
3467/* Output a DIE to represent a declared data object (either file-scope
3468 or block-local) which has "external linkage" (according to ANSI-C). */
3469
3470static void
3471output_global_variable_die (arg)
3472 register void *arg;
3473{
3474 register tree decl = arg;
d4d4c5a8 3475 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3476
3477 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3478 sibling_attribute ();
d4d4c5a8
RS
3479 if (origin != NULL)
3480 abstract_origin_attribute (origin);
3481 else
340ccaab 3482 {
d4d4c5a8
RS
3483 name_and_src_coords_attributes (decl);
3484 member_attribute (DECL_CONTEXT (decl));
3485 type_attribute (TREE_TYPE (decl),
3486 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3487 }
3488 if (DECL_ABSTRACT (decl))
3489 equate_decl_number_to_die_number (decl);
3490 else
3491 {
a94dbf2c
JM
3492 if (! DECL_EXTERNAL (decl) && ! in_class
3493 && current_function_decl == decl_function_context (decl))
d4d4c5a8 3494 location_or_const_value_attribute (decl);
340ccaab
TW
3495 }
3496}
340ccaab
TW
3497
3498static void
3499output_label_die (arg)
3500 register void *arg;
3501{
3502 register tree decl = arg;
d4d4c5a8 3503 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3504
3505 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3506 sibling_attribute ();
d4d4c5a8
RS
3507 if (origin != NULL)
3508 abstract_origin_attribute (origin);
3509 else
3510 name_and_src_coords_attributes (decl);
3511 if (DECL_ABSTRACT (decl))
3512 equate_decl_number_to_die_number (decl);
3513 else
3514 {
3515 register rtx insn = DECL_RTL (decl);
340ccaab 3516
088e7160
NC
3517 /* Deleted labels are programmer specified labels which have been
3518 eliminated because of various optimisations. We still emit them
3519 here so that it is possible to put breakpoints on them. */
3520 if (GET_CODE (insn) == CODE_LABEL
3521 || ((GET_CODE (insn) == NOTE
3522 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
d4d4c5a8
RS
3523 {
3524 char label[MAX_ARTIFICIAL_LABEL_BYTES];
340ccaab 3525
d4d4c5a8
RS
3526 /* When optimization is enabled (via -O) some parts of the compiler
3527 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3528 represent source-level labels which were explicitly declared by
3529 the user. This really shouldn't be happening though, so catch
3530 it if it ever does happen. */
340ccaab 3531
d4d4c5a8
RS
3532 if (INSN_DELETED_P (insn))
3533 abort (); /* Should never happen. */
340ccaab 3534
d4d4c5a8
RS
3535 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3536 (unsigned) INSN_UID (insn));
3537 low_pc_attribute (label);
3538 }
340ccaab
TW
3539 }
3540}
3541
3542static void
3543output_lexical_block_die (arg)
3544 register void *arg;
3545{
3546 register tree stmt = arg;
340ccaab
TW
3547
3548 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3549 sibling_attribute ();
3550 dienum_push ();
d4d4c5a8
RS
3551 if (! BLOCK_ABSTRACT (stmt))
3552 {
3553 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3554 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3555
18c038b9 3556 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
d4d4c5a8 3557 low_pc_attribute (begin_label);
18c038b9 3558 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
d4d4c5a8
RS
3559 high_pc_attribute (end_label);
3560 }
340ccaab
TW
3561}
3562
3563static void
3564output_inlined_subroutine_die (arg)
3565 register void *arg;
3566{
3567 register tree stmt = arg;
340ccaab
TW
3568
3569 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3570 sibling_attribute ();
3571 dienum_push ();
d4d4c5a8
RS
3572 abstract_origin_attribute (block_ultimate_origin (stmt));
3573 if (! BLOCK_ABSTRACT (stmt))
3574 {
3575 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3576 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3577
18c038b9 3578 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
d4d4c5a8 3579 low_pc_attribute (begin_label);
18c038b9 3580 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
d4d4c5a8
RS
3581 high_pc_attribute (end_label);
3582 }
340ccaab
TW
3583}
3584
3585/* Output a DIE to represent a declared data object (either file-scope
3586 or block-local) which has "internal linkage" (according to ANSI-C). */
3587
3588static void
3589output_local_variable_die (arg)
3590 register void *arg;
3591{
3592 register tree decl = arg;
d4d4c5a8 3593 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3594
3595 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3596 sibling_attribute ();
d4d4c5a8
RS
3597 if (origin != NULL)
3598 abstract_origin_attribute (origin);
3599 else
3600 {
3601 name_and_src_coords_attributes (decl);
3602 member_attribute (DECL_CONTEXT (decl));
3603 type_attribute (TREE_TYPE (decl),
3604 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3605 }
3606 if (DECL_ABSTRACT (decl))
3607 equate_decl_number_to_die_number (decl);
3608 else
3609 location_or_const_value_attribute (decl);
340ccaab
TW
3610}
3611
3612static void
3613output_member_die (arg)
3614 register void *arg;
3615{
3616 register tree decl = arg;
3617
3618 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3619 sibling_attribute ();
9a631e8e 3620 name_and_src_coords_attributes (decl);
340ccaab
TW
3621 member_attribute (DECL_CONTEXT (decl));
3622 type_attribute (member_declared_type (decl),
3623 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
0f41302f 3624 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
340ccaab
TW
3625 {
3626 byte_size_attribute (decl);
3627 bit_size_attribute (decl);
3628 bit_offset_attribute (decl);
3629 }
3630 data_member_location_attribute (decl);
3631}
3632
3633#if 0
d4d4c5a8
RS
3634/* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3635 modified types instead.
340ccaab 3636
0f41302f
MS
3637 We keep this code here just in case these types of DIEs may be
3638 needed to represent certain things in other languages (e.g. Pascal)
3639 someday. */
340ccaab
TW
3640
3641static void
3642output_pointer_type_die (arg)
3643 register void *arg;
3644{
3645 register tree type = arg;
3646
3647 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3648 sibling_attribute ();
3649 equate_type_number_to_die_number (type);
3650 member_attribute (TYPE_CONTEXT (type));
3651 type_attribute (TREE_TYPE (type), 0, 0);
3652}
3653
3654static void
3655output_reference_type_die (arg)
3656 register void *arg;
3657{
3658 register tree type = arg;
3659
3660 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3661 sibling_attribute ();
3662 equate_type_number_to_die_number (type);
3663 member_attribute (TYPE_CONTEXT (type));
3664 type_attribute (TREE_TYPE (type), 0, 0);
3665}
3666#endif
3667
d4d4c5a8 3668static void
340ccaab
TW
3669output_ptr_to_mbr_type_die (arg)
3670 register void *arg;
3671{
3672 register tree type = arg;
3673
3674 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3675 sibling_attribute ();
3676 equate_type_number_to_die_number (type);
3677 member_attribute (TYPE_CONTEXT (type));
3678 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3679 type_attribute (TREE_TYPE (type), 0, 0);
3680}
3681
3682static void
3683output_compile_unit_die (arg)
3684 register void *arg;
3685{
d3e3972c 3686 register const char *main_input_filename = arg;
340ccaab
TW
3687
3688 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3689 sibling_attribute ();
3690 dienum_push ();
3691 name_attribute (main_input_filename);
3692
3693 {
3694 char producer[250];
3695
3696 sprintf (producer, "%s %s", language_string, version_string);
3697 producer_attribute (producer);
3698 }
3699
3700 if (strcmp (language_string, "GNU C++") == 0)
3701 language_attribute (LANG_C_PLUS_PLUS);
77b83b95
RK
3702 else if (strcmp (language_string, "GNU Ada") == 0)
3703 language_attribute (LANG_ADA83);
439eb776
RK
3704 else if (strcmp (language_string, "GNU F77") == 0)
3705 language_attribute (LANG_FORTRAN77);
7532a0fb
RK
3706 else if (strcmp (language_string, "GNU Pascal") == 0)
3707 language_attribute (LANG_PASCAL83);
340ccaab
TW
3708 else if (flag_traditional)
3709 language_attribute (LANG_C);
3710 else
3711 language_attribute (LANG_C89);
3712 low_pc_attribute (TEXT_BEGIN_LABEL);
3713 high_pc_attribute (TEXT_END_LABEL);
3714 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3715 stmt_list_attribute (LINE_BEGIN_LABEL);
3716 last_filename = xstrdup (main_input_filename);
3717
3718 {
d3e3972c 3719 const char *wd = getpwd ();
2e494f70
RS
3720 if (wd)
3721 comp_dir_attribute (wd);
340ccaab
TW
3722 }
3723
a94dbf2c 3724 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
340ccaab
TW
3725 {
3726 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3727 src_info_attribute (SRCINFO_BEGIN_LABEL);
3728 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3729 mac_info_attribute (MACINFO_BEGIN_LABEL);
3730 }
3731}
3732
3733static void
3734output_string_type_die (arg)
3735 register void *arg;
3736{
3737 register tree type = arg;
3738
3739 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3740 sibling_attribute ();
874a8709 3741 equate_type_number_to_die_number (type);
340ccaab 3742 member_attribute (TYPE_CONTEXT (type));
874a8709
FF
3743 /* this is a fixed length string */
3744 byte_size_attribute (type);
340ccaab
TW
3745}
3746
f37230f0
JM
3747static void
3748output_inheritance_die (arg)
3749 register void *arg;
3750{
3751 register tree binfo = arg;
3752
3753 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3754 sibling_attribute ();
3755 type_attribute (BINFO_TYPE (binfo), 0, 0);
3756 data_member_location_attribute (binfo);
3757 if (TREE_VIA_VIRTUAL (binfo))
3758 {
3759 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
74153f8e 3760 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
f37230f0
JM
3761 }
3762 if (TREE_VIA_PUBLIC (binfo))
3763 {
3764 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
74153f8e 3765 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
f37230f0
JM
3766 }
3767 else if (TREE_VIA_PROTECTED (binfo))
3768 {
3769 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
74153f8e 3770 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
f37230f0
JM
3771 }
3772}
3773
340ccaab
TW
3774static void
3775output_structure_type_die (arg)
3776 register void *arg;
3777{
3778 register tree type = arg;
3779
3780 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3781 sibling_attribute ();
3782 equate_type_number_to_die_number (type);
3783 name_attribute (type_tag (type));
3784 member_attribute (TYPE_CONTEXT (type));
3785
3786 /* If this type has been completed, then give it a byte_size attribute
3787 and prepare to give a list of members. Otherwise, don't do either of
3788 these things. In the latter case, we will not be generating a list
3789 of members (since we don't have any idea what they might be for an
3790 incomplete type). */
3791
d0f062fb 3792 if (COMPLETE_TYPE_P (type))
340ccaab
TW
3793 {
3794 dienum_push ();
3795 byte_size_attribute (type);
3796 }
3797}
3798
3799/* Output a DIE to represent a declared function (either file-scope
3800 or block-local) which has "internal linkage" (according to ANSI-C). */
3801
3802static void
3803output_local_subroutine_die (arg)
3804 register void *arg;
3805{
3806 register tree decl = arg;
d4d4c5a8 3807 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3808
3809 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3810 sibling_attribute ();
3811 dienum_push ();
d4d4c5a8
RS
3812 if (origin != NULL)
3813 abstract_origin_attribute (origin);
3814 else
3815 {
3816 register tree type = TREE_TYPE (decl);
340ccaab 3817
d4d4c5a8
RS
3818 name_and_src_coords_attributes (decl);
3819 inline_attribute (decl);
3820 prototyped_attribute (type);
3821 member_attribute (DECL_CONTEXT (decl));
3822 type_attribute (TREE_TYPE (type), 0, 0);
3823 pure_or_virtual_attribute (decl);
3824 }
3825 if (DECL_ABSTRACT (decl))
3826 equate_decl_number_to_die_number (decl);
3827 else
340ccaab 3828 {
d4d4c5a8
RS
3829 /* Avoid getting screwed up in cases where a function was declared
3830 static but where no definition was ever given for it. */
3831
3832 if (TREE_ASM_WRITTEN (decl))
3833 {
2a819d04 3834 char label[MAX_ARTIFICIAL_LABEL_BYTES];
692e06f5 3835 low_pc_attribute (function_start_label (decl));
2a819d04
TW
3836 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3837 high_pc_attribute (label);
a94dbf2c
JM
3838 if (use_gnu_debug_info_extensions)
3839 {
3840 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3841 body_begin_attribute (label);
3842 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3843 body_end_attribute (label);
3844 }
d4d4c5a8 3845 }
340ccaab
TW
3846 }
3847}
3848
3849static void
3850output_subroutine_type_die (arg)
3851 register void *arg;
3852{
3853 register tree type = arg;
3854 register tree return_type = TREE_TYPE (type);
3855
3856 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3857 sibling_attribute ();
3858 dienum_push ();
3859 equate_type_number_to_die_number (type);
3860 prototyped_attribute (type);
3861 member_attribute (TYPE_CONTEXT (type));
3862 type_attribute (return_type, 0, 0);
3863}
3864
3865static void
3866output_typedef_die (arg)
3867 register void *arg;
3868{
3869 register tree decl = arg;
d4d4c5a8 3870 register tree origin = decl_ultimate_origin (decl);
340ccaab
TW
3871
3872 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3873 sibling_attribute ();
d4d4c5a8
RS
3874 if (origin != NULL)
3875 abstract_origin_attribute (origin);
3876 else
3877 {
3878 name_and_src_coords_attributes (decl);
3879 member_attribute (DECL_CONTEXT (decl));
3880 type_attribute (TREE_TYPE (decl),
3881 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3882 }
3883 if (DECL_ABSTRACT (decl))
3884 equate_decl_number_to_die_number (decl);
340ccaab
TW
3885}
3886
3887static void
3888output_union_type_die (arg)
3889 register void *arg;
3890{
3891 register tree type = arg;
3892
3893 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3894 sibling_attribute ();
3895 equate_type_number_to_die_number (type);
3896 name_attribute (type_tag (type));
3897 member_attribute (TYPE_CONTEXT (type));
3898
3899 /* If this type has been completed, then give it a byte_size attribute
3900 and prepare to give a list of members. Otherwise, don't do either of
3901 these things. In the latter case, we will not be generating a list
3902 of members (since we don't have any idea what they might be for an
3903 incomplete type). */
3904
d0f062fb 3905 if (COMPLETE_TYPE_P (type))
340ccaab
TW
3906 {
3907 dienum_push ();
3908 byte_size_attribute (type);
3909 }
3910}
3911
3912/* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3913 at the end of an (ANSI prototyped) formal parameters list. */
3914
3915static void
3916output_unspecified_parameters_die (arg)
3917 register void *arg;
3918{
3919 register tree decl_or_type = arg;
3920
3921 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3922 sibling_attribute ();
3923
3924 /* This kludge is here only for the sake of being compatible with what
3925 the USL CI5 C compiler does. The specification of Dwarf Version 1
3926 doesn't say that TAG_unspecified_parameters DIEs should contain any
3927 attributes other than the AT_sibling attribute, but they are certainly
3928 allowed to contain additional attributes, and the CI5 compiler
3929 generates AT_name, AT_fund_type, and AT_location attributes within
3930 TAG_unspecified_parameters DIEs which appear in the child lists for
3931 DIEs representing function definitions, so we do likewise here. */
3932
3933 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3934 {
3935 name_attribute ("...");
3936 fund_type_attribute (FT_pointer);
3937 /* location_attribute (?); */
3938 }
3939}
3940
3941static void
3942output_padded_null_die (arg)
487a6e06 3943 register void *arg ATTRIBUTE_UNUSED;
340ccaab
TW
3944{
3945 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3946}
3947
3948/*************************** end of DIEs *********************************/
3949
3950/* Generate some type of DIE. This routine generates the generic outer
3951 wrapper stuff which goes around all types of DIE's (regardless of their
3952 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3953 DIE-length word, followed by the guts of the DIE itself. After the guts
3954 of the DIE, there must always be a terminator label for the DIE. */
3955
3956static void
3957output_die (die_specific_output_function, param)
83d2b3b9 3958 register void (*die_specific_output_function) PARAMS ((void *));
340ccaab
TW
3959 register void *param;
3960{
3961 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3962 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3963
3964 current_dienum = NEXT_DIE_NUM;
3965 NEXT_DIE_NUM = next_unused_dienum;
3966
3967 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3968 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3969
3970 /* Write a label which will act as the name for the start of this DIE. */
3971
3972 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3973
3974 /* Write the DIE-length word. */
3975
3976 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3977
3978 /* Fill in the guts of the DIE. */
3979
3980 next_unused_dienum++;
3981 die_specific_output_function (param);
3982
3983 /* Write a label which will act as the name for the end of this DIE. */
3984
3985 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3986}
3987
3988static void
3989end_sibling_chain ()
3990{
3991 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3992
3993 current_dienum = NEXT_DIE_NUM;
3994 NEXT_DIE_NUM = next_unused_dienum;
3995
3996 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3997
3998 /* Write a label which will act as the name for the start of this DIE. */
3999
4000 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4001
4002 /* Write the DIE-length word. */
4003
4004 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4005
4006 dienum_pop ();
4007}
4008\f
4009/* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4010 TAG_unspecified_parameters DIE) to represent the types of the formal
4011 parameters as specified in some function type specification (except
4012 for those which appear as part of a function *definition*).
4013
0f41302f
MS
4014 Note that we must be careful here to output all of the parameter
4015 DIEs *before* we output any DIEs needed to represent the types of
4016 the formal parameters. This keeps svr4 SDB happy because it
4017 (incorrectly) thinks that the first non-parameter DIE it sees ends
4018 the formal parameter list. */
340ccaab
TW
4019
4020static void
4021output_formal_types (function_or_method_type)
4022 register tree function_or_method_type;
4023{
4024 register tree link;
d4d4c5a8 4025 register tree formal_type = NULL;
340ccaab
TW
4026 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4027
2a851b5c
R
4028 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4029 get bogus recursion when outputting tagged types local to a
4030 function declaration. */
4031 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4032 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4033
340ccaab
TW
4034 /* In the case where we are generating a formal types list for a C++
4035 non-static member function type, skip over the first thing on the
4036 TYPE_ARG_TYPES list because it only represents the type of the
4037 hidden `this pointer'. The debugger should be able to figure
4038 out (without being explicitly told) that this non-static member
4039 function type takes a `this pointer' and should be able to figure
4040 what the type of that hidden parameter is from the AT_member
4041 attribute of the parent TAG_subroutine_type DIE. */
4042
4043 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4044 first_parm_type = TREE_CHAIN (first_parm_type);
4045
4046 /* Make our first pass over the list of formal parameter types and output
4047 a TAG_formal_parameter DIE for each one. */
4048
4049 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4050 {
4051 formal_type = TREE_VALUE (link);
4052 if (formal_type == void_type_node)
4053 break;
4054
4055 /* Output a (nameless) DIE to represent the formal parameter itself. */
4056
4057 output_die (output_formal_parameter_die, formal_type);
4058 }
4059
4060 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4061 DIE to the end of the parameter list. */
4062
4063 if (formal_type != void_type_node)
4064 output_die (output_unspecified_parameters_die, function_or_method_type);
4065
4066 /* Make our second (and final) pass over the list of formal parameter types
4067 and output DIEs to represent those types (as necessary). */
4068
4069 for (link = TYPE_ARG_TYPES (function_or_method_type);
4070 link;
4071 link = TREE_CHAIN (link))
4072 {
4073 formal_type = TREE_VALUE (link);
4074 if (formal_type == void_type_node)
4075 break;
4076
4077 output_type (formal_type, function_or_method_type);
4078 }
2a851b5c
R
4079
4080 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
340ccaab
TW
4081}
4082\f
4083/* Remember a type in the pending_types_list. */
4084
4085static void
4086pend_type (type)
4087 register tree type;
4088{
4089 if (pending_types == pending_types_allocated)
4090 {
4091 pending_types_allocated += PENDING_TYPES_INCREMENT;
4092 pending_types_list
4093 = (tree *) xrealloc (pending_types_list,
4094 sizeof (tree) * pending_types_allocated);
4095 }
4096 pending_types_list[pending_types++] = type;
4097
4098 /* Mark the pending type as having been output already (even though
4099 it hasn't been). This prevents the type from being added to the
4100 pending_types_list more than once. */
4101
4102 TREE_ASM_WRITTEN (type) = 1;
4103}
4104
4105/* Return non-zero if it is legitimate to output DIEs to represent a
4106 given type while we are generating the list of child DIEs for some
c7d6dca2 4107 DIE (e.g. a function or lexical block DIE) associated with a given scope.
340ccaab 4108
c7d6dca2
RS
4109 See the comments within the function for a description of when it is
4110 considered legitimate to output DIEs for various kinds of types.
340ccaab
TW
4111
4112 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4113 or it may point to a BLOCK node (for types local to a block), or to a
4114 FUNCTION_DECL node (for types local to the heading of some function
4115 definition), or to a FUNCTION_TYPE node (for types local to the
4116 prototyped parameter list of a function type specification), or to a
c1b98a95
RK
4117 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4118 (in the case of C++ nested types).
340ccaab
TW
4119
4120 The `scope' parameter should likewise be NULL or should point to a
4121 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
c1b98a95 4122 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
340ccaab
TW
4123
4124 This function is used only for deciding when to "pend" and when to
4125 "un-pend" types to/from the pending_types_list.
4126
4127 Note that we sometimes make use of this "type pending" feature in a
4128 rather twisted way to temporarily delay the production of DIEs for the
4129 types of formal parameters. (We do this just to make svr4 SDB happy.)
4130 It order to delay the production of DIEs representing types of formal
4131 parameters, callers of this function supply `fake_containing_scope' as
4132 the `scope' parameter to this function. Given that fake_containing_scope
c7d6dca2
RS
4133 is a tagged type which is *not* the containing scope for *any* other type,
4134 the desired effect is achieved, i.e. output of DIEs representing types
4135 is temporarily suspended, and any type DIEs which would have otherwise
4136 been output are instead placed onto the pending_types_list. Later on,
4137 we force these (temporarily pended) types to be output simply by calling
340ccaab 4138 `output_pending_types_for_scope' with an actual argument equal to the
461b77c8 4139 true scope of the types we temporarily pended. */
340ccaab 4140
461b77c8 4141static inline int
340ccaab
TW
4142type_ok_for_scope (type, scope)
4143 register tree type;
4144 register tree scope;
4145{
c7d6dca2
RS
4146 /* Tagged types (i.e. struct, union, and enum types) must always be
4147 output only in the scopes where they actually belong (or else the
4148 scoping of their own tag names and the scoping of their member
4149 names will be incorrect). Non-tagged-types on the other hand can
4150 generally be output anywhere, except that svr4 SDB really doesn't
4151 want to see them nested within struct or union types, so here we
4152 say it is always OK to immediately output any such a (non-tagged)
4153 type, so long as we are not within such a context. Note that the
4154 only kinds of non-tagged types which we will be dealing with here
4155 (for C and C++ anyway) will be array types and function types. */
4156
4157 return is_tagged_type (type)
a94dbf2c 4158 ? (TYPE_CONTEXT (type) == scope
2addbe1d
JM
4159 /* Ignore namespaces for the moment. */
4160 || (scope == NULL_TREE
4161 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
a94dbf2c
JM
4162 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4163 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
c7d6dca2 4164 : (scope == NULL_TREE || ! is_tagged_type (scope));
340ccaab
TW
4165}
4166
4167/* Output any pending types (from the pending_types list) which we can output
c7d6dca2 4168 now (taking into account the scope that we are working on now).
340ccaab
TW
4169
4170 For each type output, remove the given type from the pending_types_list
4171 *before* we try to output it.
4172
4173 Note that we have to process the list in beginning-to-end order,
4174 because the call made here to output_type may cause yet more types
4175 to be added to the end of the list, and we may have to output some
0f41302f 4176 of them too. */
340ccaab
TW
4177
4178static void
4179output_pending_types_for_scope (containing_scope)
4180 register tree containing_scope;
4181{
4182 register unsigned i;
4183
4184 for (i = 0; i < pending_types; )
4185 {
4186 register tree type = pending_types_list[i];
4187
4188 if (type_ok_for_scope (type, containing_scope))
4189 {
4190 register tree *mover;
4191 register tree *limit;
4192
4193 pending_types--;
4194 limit = &pending_types_list[pending_types];
4195 for (mover = &pending_types_list[i]; mover < limit; mover++)
4196 *mover = *(mover+1);
4197
4198 /* Un-mark the type as having been output already (because it
4199 hasn't been, really). Then call output_type to generate a
4200 Dwarf representation of it. */
4201
4202 TREE_ASM_WRITTEN (type) = 0;
4203 output_type (type, containing_scope);
4204
4205 /* Don't increment the loop counter in this case because we
4206 have shifted all of the subsequent pending types down one
4207 element in the pending_types_list array. */
4208 }
4209 else
4210 i++;
4211 }
4212}
4213
75c613db
JM
4214/* Remember a type in the incomplete_types_list. */
4215
4216static void
4217add_incomplete_type (type)
4218 tree type;
4219{
4220 if (incomplete_types == incomplete_types_allocated)
4221 {
4222 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4223 incomplete_types_list
4224 = (tree *) xrealloc (incomplete_types_list,
4225 sizeof (tree) * incomplete_types_allocated);
4226 }
4227
4228 incomplete_types_list[incomplete_types++] = type;
4229}
4230
4231/* Walk through the list of incomplete types again, trying once more to
4232 emit full debugging info for them. */
4233
4234static void
4235retry_incomplete_types ()
4236{
4237 register tree type;
4238
4239 finalizing = 1;
4240 while (incomplete_types)
4241 {
4242 --incomplete_types;
4243 type = incomplete_types_list[incomplete_types];
4244 output_type (type, NULL_TREE);
4245 }
4246}
4247
340ccaab
TW
4248static void
4249output_type (type, containing_scope)
4250 register tree type;
4251 register tree containing_scope;
4252{
4253 if (type == 0 || type == error_mark_node)
4254 return;
4255
4256 /* We are going to output a DIE to represent the unqualified version of
38e01259 4257 this type (i.e. without any const or volatile qualifiers) so get
340ccaab
TW
4258 the main variant (i.e. the unqualified version) of this type now. */
4259
69d6b01d 4260 type = type_main_variant (type);
340ccaab
TW
4261
4262 if (TREE_ASM_WRITTEN (type))
f45ebe47
JL
4263 {
4264 if (finalizing && AGGREGATE_TYPE_P (type))
4265 {
4266 register tree member;
4267
4268 /* Some of our nested types might not have been defined when we
4269 were written out before; force them out now. */
4270
4271 for (member = TYPE_FIELDS (type); member;
4272 member = TREE_CHAIN (member))
4273 if (TREE_CODE (member) == TYPE_DECL
4274 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4275 output_type (TREE_TYPE (member), containing_scope);
4276 }
4277 return;
4278 }
340ccaab 4279
a94dbf2c
JM
4280 /* If this is a nested type whose containing class hasn't been
4281 written out yet, writing it out will cover this one, too. */
4282
4283 if (TYPE_CONTEXT (type)
2f939d94 4284 && TYPE_P (TYPE_CONTEXT (type))
a94dbf2c
JM
4285 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4286 {
4287 output_type (TYPE_CONTEXT (type), containing_scope);
4288 return;
4289 }
4290
340ccaab
TW
4291 /* Don't generate any DIEs for this type now unless it is OK to do so
4292 (based upon what `type_ok_for_scope' tells us). */
4293
4294 if (! type_ok_for_scope (type, containing_scope))
4295 {
4296 pend_type (type);
4297 return;
4298 }
4299
4300 switch (TREE_CODE (type))
4301 {
4302 case ERROR_MARK:
4303 break;
4304
4305 case POINTER_TYPE:
4306 case REFERENCE_TYPE:
b1357021
JW
4307 /* Prevent infinite recursion in cases where this is a recursive
4308 type. Recursive types are possible in Ada. */
4309 TREE_ASM_WRITTEN (type) = 1;
340ccaab 4310 /* For these types, all that is required is that we output a DIE
e6d9804c 4311 (or a set of DIEs) to represent the "basis" type. */
340ccaab
TW
4312 output_type (TREE_TYPE (type), containing_scope);
4313 break;
4314
4315 case OFFSET_TYPE:
4316 /* This code is used for C++ pointer-to-data-member types. */
4317 /* Output a description of the relevant class type. */
4318 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4319 /* Output a description of the type of the object pointed to. */
4320 output_type (TREE_TYPE (type), containing_scope);
4321 /* Now output a DIE to represent this pointer-to-data-member type
4322 itself. */
4323 output_die (output_ptr_to_mbr_type_die, type);
4324 break;
4325
4326 case SET_TYPE:
f29a425b 4327 output_type (TYPE_DOMAIN (type), containing_scope);
340ccaab
TW
4328 output_die (output_set_type_die, type);
4329 break;
4330
4331 case FILE_TYPE:
4332 output_type (TREE_TYPE (type), containing_scope);
6dc42e49 4333 abort (); /* No way to represent these in Dwarf yet! */
340ccaab
TW
4334 break;
4335
340ccaab
TW
4336 case FUNCTION_TYPE:
4337 /* Force out return type (in case it wasn't forced out already). */
4338 output_type (TREE_TYPE (type), containing_scope);
4339 output_die (output_subroutine_type_die, type);
4340 output_formal_types (type);
4341 end_sibling_chain ();
4342 break;
4343
4344 case METHOD_TYPE:
4345 /* Force out return type (in case it wasn't forced out already). */
4346 output_type (TREE_TYPE (type), containing_scope);
4347 output_die (output_subroutine_type_die, type);
4348 output_formal_types (type);
4349 end_sibling_chain ();
4350 break;
4351
4042d440
PB
4352 case ARRAY_TYPE:
4353 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4354 {
4355 output_type (TREE_TYPE (type), containing_scope);
4356 output_die (output_string_type_die, type);
4357 }
4358 else
4359 {
4360 register tree element_type;
340ccaab 4361
4042d440
PB
4362 element_type = TREE_TYPE (type);
4363 while (TREE_CODE (element_type) == ARRAY_TYPE)
4364 element_type = TREE_TYPE (element_type);
340ccaab 4365
4042d440
PB
4366 output_type (element_type, containing_scope);
4367 output_die (output_array_type_die, type);
4368 }
340ccaab
TW
4369 break;
4370
4371 case ENUMERAL_TYPE:
4372 case RECORD_TYPE:
4373 case UNION_TYPE:
c1b98a95 4374 case QUAL_UNION_TYPE:
340ccaab
TW
4375
4376 /* For a non-file-scope tagged type, we can always go ahead and
4377 output a Dwarf description of this type right now, even if
4378 the type in question is still incomplete, because if this
4379 local type *was* ever completed anywhere within its scope,
4380 that complete definition would already have been attached to
c1b98a95
RK
4381 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4382 node by the time we reach this point. That's true because of the
4383 way the front-end does its processing of file-scope declarations (of
340ccaab
TW
4384 functions and class types) within which other types might be
4385 nested. The C and C++ front-ends always gobble up such "local
4386 scope" things en-mass before they try to output *any* debugging
4387 information for any of the stuff contained inside them and thus,
4388 we get the benefit here of what is (in effect) a pre-resolution
4389 of forward references to tagged types in local scopes.
4390
4391 Note however that for file-scope tagged types we cannot assume
4392 that such pre-resolution of forward references has taken place.
4393 A given file-scope tagged type may appear to be incomplete when
4394 we reach this point, but it may yet be given a full definition
4395 (at file-scope) later on during compilation. In order to avoid
4396 generating a premature (and possibly incorrect) set of Dwarf
4397 DIEs for such (as yet incomplete) file-scope tagged types, we
4398 generate nothing at all for as-yet incomplete file-scope tagged
4399 types here unless we are making our special "finalization" pass
4400 for file-scope things at the very end of compilation. At that
4401 time, we will certainly know as much about each file-scope tagged
4402 type as we are ever going to know, so at that point in time, we
4403 can safely generate correct Dwarf descriptions for these file-
a94dbf2c 4404 scope tagged types. */
340ccaab 4405
d0f062fb 4406 if (!COMPLETE_TYPE_P (type)
ff1ff056 4407 && (TYPE_CONTEXT (type) == NULL
6ff7fb95
JM
4408 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4409 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
ff1ff056 4410 && !finalizing)
75c613db 4411 {
f19f17e0
JM
4412 /* We don't need to do this for function-local types. */
4413 if (! decl_function_context (TYPE_STUB_DECL (type)))
a30d4514 4414 add_incomplete_type (type);
75c613db
JM
4415 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4416 }
340ccaab
TW
4417
4418 /* Prevent infinite recursion in cases where the type of some
4419 member of this type is expressed in terms of this type itself. */
4420
4421 TREE_ASM_WRITTEN (type) = 1;
4422
4423 /* Output a DIE to represent the tagged type itself. */
4424
4425 switch (TREE_CODE (type))
4426 {
4427 case ENUMERAL_TYPE:
4428 output_die (output_enumeration_type_die, type);
4429 return; /* a special case -- nothing left to do so just return */
4430
4431 case RECORD_TYPE:
4432 output_die (output_structure_type_die, type);
4433 break;
4434
4435 case UNION_TYPE:
c1b98a95 4436 case QUAL_UNION_TYPE:
340ccaab
TW
4437 output_die (output_union_type_die, type);
4438 break;
d4d4c5a8
RS
4439
4440 default:
4441 abort (); /* Should never happen. */
340ccaab
TW
4442 }
4443
4444 /* If this is not an incomplete type, output descriptions of
4445 each of its members.
4446
4447 Note that as we output the DIEs necessary to represent the
4448 members of this record or union type, we will also be trying
4449 to output DIEs to represent the *types* of those members.
4450 However the `output_type' function (above) will specifically
4451 avoid generating type DIEs for member types *within* the list
4452 of member DIEs for this (containing) type execpt for those
4453 types (of members) which are explicitly marked as also being
4454 members of this (containing) type themselves. The g++ front-
4455 end can force any given type to be treated as a member of some
4456 other (containing) type by setting the TYPE_CONTEXT of the
4457 given (member) type to point to the TREE node representing the
4458 appropriate (containing) type.
4459 */
4460
d0f062fb 4461 if (COMPLETE_TYPE_P (type))
340ccaab 4462 {
f37230f0
JM
4463 /* First output info about the base classes. */
4464 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4465 {
4466 register tree bases = TYPE_BINFO_BASETYPES (type);
4467 register int n_bases = TREE_VEC_LENGTH (bases);
4468 register int i;
4469
4470 for (i = 0; i < n_bases; i++)
75c613db
JM
4471 {
4472 tree binfo = TREE_VEC_ELT (bases, i);
4473 output_type (BINFO_TYPE (binfo), containing_scope);
4474 output_die (output_inheritance_die, binfo);
4475 }
f37230f0
JM
4476 }
4477
a94dbf2c
JM
4478 ++in_class;
4479
9a631e8e
RS
4480 {
4481 register tree normal_member;
340ccaab 4482
f37230f0 4483 /* Now output info about the data members and type members. */
340ccaab 4484
9a631e8e
RS
4485 for (normal_member = TYPE_FIELDS (type);
4486 normal_member;
4487 normal_member = TREE_CHAIN (normal_member))
4488 output_decl (normal_member, type);
4489 }
340ccaab 4490
9a631e8e 4491 {
85f8926e 4492 register tree func_member;
9a631e8e
RS
4493
4494 /* Now output info about the function members (if any). */
4495
85f8926e
JM
4496 for (func_member = TYPE_METHODS (type);
4497 func_member;
4498 func_member = TREE_CHAIN (func_member))
4499 output_decl (func_member, type);
9a631e8e 4500 }
340ccaab 4501
a94dbf2c
JM
4502 --in_class;
4503
c1b98a95
RK
4504 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4505 scopes (at least in C++) so we must now output any nested
4506 pending types which are local just to this type. */
c7d6dca2
RS
4507
4508 output_pending_types_for_scope (type);
4509
340ccaab
TW
4510 end_sibling_chain (); /* Terminate member chain. */
4511 }
4512
4513 break;
4514
4515 case VOID_TYPE:
4516 case INTEGER_TYPE:
4517 case REAL_TYPE:
4518 case COMPLEX_TYPE:
4519 case BOOLEAN_TYPE:
4520 case CHAR_TYPE:
4521 break; /* No DIEs needed for fundamental types. */
4522
4523 case LANG_TYPE: /* No Dwarf representation currently defined. */
4524 break;
4525
4526 default:
4527 abort ();
4528 }
4529
4530 TREE_ASM_WRITTEN (type) = 1;
4531}
d4d4c5a8
RS
4532
4533static void
4534output_tagged_type_instantiation (type)
4535 register tree type;
4536{
4537 if (type == 0 || type == error_mark_node)
4538 return;
4539
4540 /* We are going to output a DIE to represent the unqualified version of
38e01259 4541 this type (i.e. without any const or volatile qualifiers) so make
d4d4c5a8
RS
4542 sure that we have the main variant (i.e. the unqualified version) of
4543 this type now. */
4544
3a88cbd1
JL
4545 if (type != type_main_variant (type))
4546 abort ();
d4d4c5a8 4547
3a88cbd1
JL
4548 if (!TREE_ASM_WRITTEN (type))
4549 abort ();
d4d4c5a8
RS
4550
4551 switch (TREE_CODE (type))
4552 {
4553 case ERROR_MARK:
4554 break;
4555
4556 case ENUMERAL_TYPE:
4557 output_die (output_inlined_enumeration_type_die, type);
4558 break;
4559
4560 case RECORD_TYPE:
4561 output_die (output_inlined_structure_type_die, type);
4562 break;
4563
4564 case UNION_TYPE:
c1b98a95 4565 case QUAL_UNION_TYPE:
d4d4c5a8
RS
4566 output_die (output_inlined_union_type_die, type);
4567 break;
4568
4569 default:
4570 abort (); /* Should never happen. */
4571 }
4572}
340ccaab
TW
4573\f
4574/* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4575 the things which are local to the given block. */
4576
4577static void
85f8926e 4578output_block (stmt, depth)
340ccaab 4579 register tree stmt;
85f8926e 4580 int depth;
340ccaab 4581{
ece0ca60
RS
4582 register int must_output_die = 0;
4583 register tree origin;
4584 register enum tree_code origin_code;
340ccaab
TW
4585
4586 /* Ignore blocks never really used to make RTL. */
4587
bad8ed14
JM
4588 if (! stmt || ! TREE_USED (stmt)
4589 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
340ccaab
TW
4590 return;
4591
ece0ca60
RS
4592 /* Determine the "ultimate origin" of this block. This block may be an
4593 inlined instance of an inlined instance of inline function, so we
4594 have to trace all of the way back through the origin chain to find
4595 out what sort of node actually served as the original seed for the
4596 creation of the current block. */
340ccaab 4597
ece0ca60
RS
4598 origin = block_ultimate_origin (stmt);
4599 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4600
4601 /* Determine if we need to output any Dwarf DIEs at all to represent this
4602 block. */
340ccaab 4603
ece0ca60
RS
4604 if (origin_code == FUNCTION_DECL)
4605 /* The outer scopes for inlinings *must* always be represented. We
4606 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4607 must_output_die = 1;
4608 else
4609 {
4610 /* In the case where the current block represents an inlining of the
4611 "body block" of an inline function, we must *NOT* output any DIE
4612 for this block because we have already output a DIE to represent
4613 the whole inlined function scope and the "body block" of any
4614 function doesn't really represent a different scope according to
4615 ANSI C rules. So we check here to make sure that this block does
4616 not represent a "body block inlining" before trying to set the
4617 `must_output_die' flag. */
4618
85f8926e 4619 if (! is_body_block (origin ? origin : stmt))
ece0ca60
RS
4620 {
4621 /* Determine if this block directly contains any "significant"
4622 local declarations which we will need to output DIEs for. */
4623
4624 if (debug_info_level > DINFO_LEVEL_TERSE)
4625 /* We are not in terse mode so *any* local declaration counts
4626 as being a "significant" one. */
4627 must_output_die = (BLOCK_VARS (stmt) != NULL);
4628 else
340ccaab 4629 {
ece0ca60
RS
4630 register tree decl;
4631
4632 /* We are in terse mode, so only local (nested) function
4633 definitions count as "significant" local declarations. */
4634
4635 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4636 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4637 {
4638 must_output_die = 1;
4639 break;
4640 }
340ccaab 4641 }
ece0ca60
RS
4642 }
4643 }
340ccaab
TW
4644
4645 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4646 DIE for any block which contains no significant local declarations
4647 at all. Rather, in such cases we just call `output_decls_for_scope'
4648 so that any needed Dwarf info for any sub-blocks will get properly
4649 generated. Note that in terse mode, our definition of what constitutes
4650 a "significant" local declaration gets restricted to include only
4651 inlined function instances and local (nested) function definitions. */
4652
85f8926e
JM
4653 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4654 /* We don't care about an abstract inlined subroutine. */;
4655 else if (must_output_die)
340ccaab 4656 {
ece0ca60
RS
4657 output_die ((origin_code == FUNCTION_DECL)
4658 ? output_inlined_subroutine_die
4659 : output_lexical_block_die,
340ccaab 4660 stmt);
85f8926e 4661 output_decls_for_scope (stmt, depth);
340ccaab
TW
4662 end_sibling_chain ();
4663 }
4664 else
85f8926e 4665 output_decls_for_scope (stmt, depth);
340ccaab
TW
4666}
4667
4668/* Output all of the decls declared within a given scope (also called
4669 a `binding contour') and (recursively) all of it's sub-blocks. */
4670
4671static void
85f8926e 4672output_decls_for_scope (stmt, depth)
340ccaab 4673 register tree stmt;
85f8926e 4674 int depth;
340ccaab
TW
4675{
4676 /* Ignore blocks never really used to make RTL. */
4677
4678 if (! stmt || ! TREE_USED (stmt))
4679 return;
4680
340ccaab
TW
4681 /* Output the DIEs to represent all of the data objects, functions,
4682 typedefs, and tagged types declared directly within this block
4683 but not within any nested sub-blocks. */
4684
4685 {
4686 register tree decl;
4687
4688 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4689 output_decl (decl, stmt);
4690 }
4691
4692 output_pending_types_for_scope (stmt);
4693
4694 /* Output the DIEs to represent all sub-blocks (and the items declared
4695 therein) of this block. */
4696
4697 {
4698 register tree subblocks;
4699
4700 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4701 subblocks;
4702 subblocks = BLOCK_CHAIN (subblocks))
85f8926e 4703 output_block (subblocks, depth + 1);
340ccaab
TW
4704 }
4705}
4706
a94dbf2c
JM
4707/* Is this a typedef we can avoid emitting? */
4708
24e75411 4709inline static int
a94dbf2c
JM
4710is_redundant_typedef (decl)
4711 register tree decl;
4712{
4713 if (TYPE_DECL_IS_STUB (decl))
4714 return 1;
4715 if (DECL_ARTIFICIAL (decl)
4716 && DECL_CONTEXT (decl)
4717 && is_tagged_type (DECL_CONTEXT (decl))
4718 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4719 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4720 /* Also ignore the artificial member typedef for the class name. */
4721 return 1;
4722 return 0;
4723}
4724
340ccaab
TW
4725/* Output Dwarf .debug information for a decl described by DECL. */
4726
4727static void
4728output_decl (decl, containing_scope)
4729 register tree decl;
4730 register tree containing_scope;
4731{
7f7429ca
RS
4732 /* Make a note of the decl node we are going to be working on. We may
4733 need to give the user the source coordinates of where it appeared in
4734 case we notice (later on) that something about it looks screwy. */
4735
4736 dwarf_last_decl = decl;
4737
8ac9cb56
RS
4738 if (TREE_CODE (decl) == ERROR_MARK)
4739 return;
4740
58add97a
JW
4741 /* If a structure is declared within an initialization, e.g. as the
4742 operand of a sizeof, then it will not have a name. We don't want
4743 to output a DIE for it, as the tree nodes are in the temporary obstack */
4744
4745 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4746 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4747 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4748 || (TYPE_FIELDS (TREE_TYPE (decl))
4749 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4750 return;
4751
fcd7f76b 4752 /* If this ..._DECL node is marked to be ignored, then ignore it. */
8ac9cb56 4753
fcd7f76b 4754 if (DECL_IGNORED_P (decl))
8ac9cb56
RS
4755 return;
4756
340ccaab
TW
4757 switch (TREE_CODE (decl))
4758 {
340ccaab
TW
4759 case CONST_DECL:
4760 /* The individual enumerators of an enum type get output when we
4761 output the Dwarf representation of the relevant enum type itself. */
4762 break;
4763
4764 case FUNCTION_DECL:
4765 /* If we are in terse mode, don't output any DIEs to represent
0020519f 4766 mere function declarations. Also, if we are conforming
648ebe7b 4767 to the DWARF version 1 specification, don't output DIEs for
0020519f 4768 mere function declarations. */
340ccaab 4769
0020519f 4770 if (DECL_INITIAL (decl) == NULL_TREE)
648ebe7b
RS
4771#if (DWARF_VERSION > 1)
4772 if (debug_info_level <= DINFO_LEVEL_TERSE)
4773#endif
4774 break;
340ccaab
TW
4775
4776 /* Before we describe the FUNCTION_DECL itself, make sure that we
4777 have described its return type. */
4778
4779 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4780
a94dbf2c
JM
4781 {
4782 /* And its containing type. */
4783 register tree origin = decl_class_context (decl);
4784 if (origin)
4785 output_type (origin, containing_scope);
4786 }
4787
1cfdcc15
JM
4788 /* If we're emitting an out-of-line copy of an inline function,
4789 set up to refer to the abstract instance emitted from
4790 note_deferral_of_defined_inline_function. */
4791 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
4792 && ! (containing_scope && TYPE_P (containing_scope)))
4793 set_decl_origin_self (decl);
4794
340ccaab
TW
4795 /* If the following DIE will represent a function definition for a
4796 function with "extern" linkage, output a special "pubnames" DIE
4797 label just ahead of the actual DIE. A reference to this label
4798 was already generated in the .debug_pubnames section sub-entry
4799 for this function definition. */
4800
4801 if (TREE_PUBLIC (decl))
4802 {
4803 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4804
4805 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4806 ASM_OUTPUT_LABEL (asm_out_file, label);
4807 }
4808
4809 /* Now output a DIE to represent the function itself. */
4810
0924ddef 4811 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
340ccaab
TW
4812 ? output_global_subroutine_die
4813 : output_local_subroutine_die,
4814 decl);
4815
4816 /* Now output descriptions of the arguments for this function.
4817 This gets (unnecessarily?) complex because of the fact that
4818 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4819 cases where there was a trailing `...' at the end of the formal
4820 parameter list. In order to find out if there was a trailing
4821 ellipsis or not, we must instead look at the type associated
4822 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4823 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4824 ends with a void_type_node then there should *not* be an ellipsis
4825 at the end. */
4826
0020519f 4827 /* In the case where we are describing a mere function declaration, all
340ccaab
TW
4828 we need to do here (and all we *can* do here) is to describe
4829 the *types* of its formal parameters. */
4830
a94dbf2c 4831 if (decl != current_function_decl || in_class)
340ccaab
TW
4832 output_formal_types (TREE_TYPE (decl));
4833 else
4834 {
2c1c10ec
RK
4835 /* Generate DIEs to represent all known formal parameters */
4836
340ccaab 4837 register tree arg_decls = DECL_ARGUMENTS (decl);
2c1c10ec
RK
4838 register tree parm;
4839
4840 /* WARNING! Kludge zone ahead! Here we have a special
4841 hack for svr4 SDB compatibility. Instead of passing the
4842 current FUNCTION_DECL node as the second parameter (i.e.
4843 the `containing_scope' parameter) to `output_decl' (as
4844 we ought to) we instead pass a pointer to our own private
4845 fake_containing_scope node. That node is a RECORD_TYPE
4846 node which NO OTHER TYPE may ever actually be a member of.
4847
4848 This pointer will ultimately get passed into `output_type'
4849 as its `containing_scope' parameter. `Output_type' will
4850 then perform its part in the hack... i.e. it will pend
4851 the type of the formal parameter onto the pending_types
4852 list. Later on, when we are done generating the whole
4853 sequence of formal parameter DIEs for this function
4854 definition, we will un-pend all previously pended types
4855 of formal parameters for this function definition.
4856
4857 This whole kludge prevents any type DIEs from being
4858 mixed in with the formal parameter DIEs. That's good
4859 because svr4 SDB believes that the list of formal
4860 parameter DIEs for a function ends wherever the first
4861 non-formal-parameter DIE appears. Thus, we have to
4862 keep the formal parameter DIEs segregated. They must
4863 all appear (consecutively) at the start of the list of
4864 children for the DIE representing the function definition.
4865 Then (and only then) may we output any additional DIEs
4866 needed to represent the types of these formal parameters.
4867 */
340ccaab 4868
2c1c10ec
RK
4869 /*
4870 When generating DIEs, generate the unspecified_parameters
4871 DIE instead if we come across the arg "__builtin_va_alist"
4872 */
340ccaab 4873
2c1c10ec
RK
4874 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4875 if (TREE_CODE (parm) == PARM_DECL)
4876 {
4877 if (DECL_NAME(parm) &&
4878 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4879 "__builtin_va_alist") )
4880 output_die (output_unspecified_parameters_die, decl);
4881 else
4882 output_decl (parm, fake_containing_scope);
4883 }
340ccaab 4884
2c1c10ec
RK
4885 /*
4886 Now that we have finished generating all of the DIEs to
4887 represent the formal parameters themselves, force out
4888 any DIEs needed to represent their types. We do this
4889 simply by un-pending all previously pended types which
4890 can legitimately go into the chain of children DIEs for
4891 the current FUNCTION_DECL.
4892 */
340ccaab 4893
2c1c10ec 4894 output_pending_types_for_scope (decl);
340ccaab 4895
2c1c10ec
RK
4896 /*
4897 Decide whether we need a unspecified_parameters DIE at the end.
4898 There are 2 more cases to do this for:
4899 1) the ansi ... declaration - this is detectable when the end
4900 of the arg list is not a void_type_node
4901 2) an unprototyped function declaration (not a definition). This
4902 just means that we have no info about the parameters at all.
4903 */
340ccaab
TW
4904
4905 {
340ccaab
TW
4906 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4907
4908 if (fn_arg_types)
4909 {
0f41302f 4910 /* this is the prototyped case, check for ... */
2c1c10ec
RK
4911 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4912 output_die (output_unspecified_parameters_die, decl);
4913 }
4914 else
4915 {
9faa82d8 4916 /* this is unprototyped, check for undefined (just declaration) */
2c1c10ec
RK
4917 if (!DECL_INITIAL (decl))
4918 output_die (output_unspecified_parameters_die, decl);
4919 }
340ccaab 4920 }
340ccaab 4921
a94dbf2c
JM
4922 /* Output Dwarf info for all of the stuff within the body of the
4923 function (if it has one - it may be just a declaration). */
340ccaab 4924
340ccaab 4925 {
a94dbf2c
JM
4926 register tree outer_scope = DECL_INITIAL (decl);
4927
4928 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4929 {
4930 /* Note that here, `outer_scope' is a pointer to the outermost
4931 BLOCK node created to represent a function.
4932 This outermost BLOCK actually represents the outermost
4933 binding contour for the function, i.e. the contour in which
4934 the function's formal parameters and labels get declared.
4935
4936 Curiously, it appears that the front end doesn't actually
4937 put the PARM_DECL nodes for the current function onto the
4938 BLOCK_VARS list for this outer scope. (They are strung
4939 off of the DECL_ARGUMENTS list for the function instead.)
4940 The BLOCK_VARS list for the `outer_scope' does provide us
4941 with a list of the LABEL_DECL nodes for the function however,
4942 and we output DWARF info for those here.
4943
4944 Just within the `outer_scope' there will be a BLOCK node
4945 representing the function's outermost pair of curly braces,
4946 and any blocks used for the base and member initializers of
4947 a C++ constructor function. */
4948
4949 output_decls_for_scope (outer_scope, 0);
4950
4951 /* Finally, force out any pending types which are local to the
4952 outermost block of this function definition. These will
4953 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4954 node itself. */
4955
4956 output_pending_types_for_scope (decl);
4957 }
340ccaab 4958 }
a94dbf2c 4959 }
340ccaab
TW
4960
4961 /* Generate a terminator for the list of stuff `owned' by this
4962 function. */
4963
4964 end_sibling_chain ();
4965
4966 break;
4967
4968 case TYPE_DECL:
4969 /* If we are in terse mode, don't generate any DIEs to represent
4970 any actual typedefs. Note that even when we are in terse mode,
4971 we must still output DIEs to represent those tagged types which
4972 are used (directly or indirectly) in the specification of either
4973 a return type or a formal parameter type of some function. */
4974
4975 if (debug_info_level <= DINFO_LEVEL_TERSE)
a94dbf2c
JM
4976 if (! TYPE_DECL_IS_STUB (decl)
4977 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
340ccaab
TW
4978 return;
4979
a94dbf2c
JM
4980 /* In the special case of a TYPE_DECL node representing
4981 the declaration of some type tag, if the given TYPE_DECL is
d4d4c5a8
RS
4982 marked as having been instantiated from some other (original)
4983 TYPE_DECL node (e.g. one which was generated within the original
4984 definition of an inline function) we have to generate a special
4985 (abbreviated) TAG_structure_type, TAG_union_type, or
4986 TAG_enumeration-type DIE here. */
4987
a94dbf2c 4988 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
d4d4c5a8
RS
4989 {
4990 output_tagged_type_instantiation (TREE_TYPE (decl));
4991 return;
4992 }
4993
340ccaab
TW
4994 output_type (TREE_TYPE (decl), containing_scope);
4995
a94dbf2c 4996 if (! is_redundant_typedef (decl))
340ccaab
TW
4997 /* Output a DIE to represent the typedef itself. */
4998 output_die (output_typedef_die, decl);
4999 break;
5000
5001 case LABEL_DECL:
5002 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5003 output_die (output_label_die, decl);
5004 break;
5005
5006 case VAR_DECL:
648ebe7b
RS
5007 /* If we are conforming to the DWARF version 1 specification, don't
5008 generated any DIEs to represent mere external object declarations. */
5009
5010#if (DWARF_VERSION <= 1)
0924ddef 5011 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
648ebe7b
RS
5012 break;
5013#endif
5014
340ccaab
TW
5015 /* If we are in terse mode, don't generate any DIEs to represent
5016 any variable declarations or definitions. */
5017
5018 if (debug_info_level <= DINFO_LEVEL_TERSE)
5019 break;
5020
5021 /* Output any DIEs that are needed to specify the type of this data
5022 object. */
5023
5024 output_type (TREE_TYPE (decl), containing_scope);
5025
a94dbf2c
JM
5026 {
5027 /* And its containing type. */
5028 register tree origin = decl_class_context (decl);
5029 if (origin)
5030 output_type (origin, containing_scope);
5031 }
5032
340ccaab
TW
5033 /* If the following DIE will represent a data object definition for a
5034 data object with "extern" linkage, output a special "pubnames" DIE
5035 label just ahead of the actual DIE. A reference to this label
5036 was already generated in the .debug_pubnames section sub-entry
5037 for this data object definition. */
5038
d4d4c5a8 5039 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
340ccaab
TW
5040 {
5041 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5042
5043 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5044 ASM_OUTPUT_LABEL (asm_out_file, label);
5045 }
5046
d4d4c5a8
RS
5047 /* Now output the DIE to represent the data object itself. This gets
5048 complicated because of the possibility that the VAR_DECL really
5049 represents an inlined instance of a formal parameter for an inline
5050 function. */
5051
5052 {
83d2b3b9 5053 register void (*func) PARAMS ((void *));
d4d4c5a8 5054 register tree origin = decl_ultimate_origin (decl);
340ccaab 5055
d4d4c5a8
RS
5056 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5057 func = output_formal_parameter_die;
5058 else
5059 {
0924ddef 5060 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
d4d4c5a8
RS
5061 func = output_global_variable_die;
5062 else
5063 func = output_local_variable_die;
5064 }
5065 output_die (func, decl);
5066 }
340ccaab
TW
5067 break;
5068
5069 case FIELD_DECL:
5070 /* Ignore the nameless fields that are used to skip bits. */
5071 if (DECL_NAME (decl) != 0)
5072 {
5073 output_type (member_declared_type (decl), containing_scope);
5074 output_die (output_member_die, decl);
5075 }
5076 break;
5077
5078 case PARM_DECL:
5079 /* Force out the type of this formal, if it was not forced out yet.
5080 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5081 It should be able to grok the presence of type DIEs within a list
5082 of TAG_formal_parameter DIEs, but it doesn't. */
5083
5084 output_type (TREE_TYPE (decl), containing_scope);
5085 output_die (output_formal_parameter_die, decl);
5086 break;
5087
1cfdcc15
JM
5088 case NAMESPACE_DECL:
5089 /* Ignore for now. */
5090 break;
5091
340ccaab
TW
5092 default:
5093 abort ();
5094 }
5095}
5096\f
5097void
5098dwarfout_file_scope_decl (decl, set_finalizing)
5099 register tree decl;
5100 register int set_finalizing;
5101{
8ac9cb56
RS
5102 if (TREE_CODE (decl) == ERROR_MARK)
5103 return;
5104
fcd7f76b 5105 /* If this ..._DECL node is marked to be ignored, then ignore it. */
8ac9cb56
RS
5106
5107 if (DECL_IGNORED_P (decl))
fcd7f76b 5108 return;
8ac9cb56 5109
340ccaab
TW
5110 switch (TREE_CODE (decl))
5111 {
5112 case FUNCTION_DECL:
5113
8ac9cb56
RS
5114 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5115 a builtin function. Explicit programmer-supplied declarations of
5116 these same functions should NOT be ignored however. */
340ccaab 5117
0924ddef 5118 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
340ccaab
TW
5119 return;
5120
0020519f
RK
5121 /* What we would really like to do here is to filter out all mere
5122 file-scope declarations of file-scope functions which are never
5123 referenced later within this translation unit (and keep all of
9faa82d8 5124 ones that *are* referenced later on) but we aren't clairvoyant,
0020519f
RK
5125 so we have no idea which functions will be referenced in the
5126 future (i.e. later on within the current translation unit).
5127 So here we just ignore all file-scope function declarations
5128 which are not also definitions. If and when the debugger needs
9faa82d8 5129 to know something about these functions, it wil have to hunt
0020519f
RK
5130 around and find the DWARF information associated with the
5131 *definition* of the function.
5132
5133 Note that we can't just check `DECL_EXTERNAL' to find out which
5134 FUNCTION_DECL nodes represent definitions and which ones represent
5135 mere declarations. We have to check `DECL_INITIAL' instead. That's
5136 because the C front-end supports some weird semantics for "extern
5137 inline" function definitions. These can get inlined within the
5138 current translation unit (an thus, we need to generate DWARF info
5139 for their abstract instances so that the DWARF info for the
5140 concrete inlined instances can have something to refer to) but
5141 the compiler never generates any out-of-lines instances of such
5142 things (despite the fact that they *are* definitions). The
5143 important point is that the C front-end marks these "extern inline"
85f8926e 5144 functions as DECL_EXTERNAL, but we need to generate DWARF for them
0020519f
RK
5145 anyway.
5146
5147 Note that the C++ front-end also plays some similar games for inline
5148 function definitions appearing within include files which also
5149 contain `#pragma interface' pragmas. */
5150
5151 if (DECL_INITIAL (decl) == NULL_TREE)
340ccaab
TW
5152 return;
5153
d4d4c5a8 5154 if (TREE_PUBLIC (decl)
0924ddef 5155 && ! DECL_EXTERNAL (decl)
d4d4c5a8 5156 && ! DECL_ABSTRACT (decl))
340ccaab
TW
5157 {
5158 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5159
5160 /* Output a .debug_pubnames entry for a public function
5161 defined in this compilation unit. */
5162
5163 fputc ('\n', asm_out_file);
85595d1a 5164 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
5165 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5166 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
74153f8e 5167 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
340ccaab 5168 IDENTIFIER_POINTER (DECL_NAME (decl)));
85595d1a 5169 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5170 }
5171
5172 break;
5173
5174 case VAR_DECL:
5175
5176 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5177 object declaration and if the declaration was never even
5178 referenced from within this entire compilation unit. We
5179 suppress these DIEs in order to save space in the .debug section
5180 (by eliminating entries which are probably useless). Note that
5181 we must not suppress block-local extern declarations (whether
5182 used or not) because that would screw-up the debugger's name
5183 lookup mechanism and cause it to miss things which really ought
5184 to be in scope at a given point. */
5185
0924ddef 5186 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
340ccaab
TW
5187 return;
5188
6dc42e49 5189 if (TREE_PUBLIC (decl)
0924ddef 5190 && ! DECL_EXTERNAL (decl)
d4d4c5a8
RS
5191 && GET_CODE (DECL_RTL (decl)) == MEM
5192 && ! DECL_ABSTRACT (decl))
340ccaab
TW
5193 {
5194 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5195
5196 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5197 {
5198 /* Output a .debug_pubnames entry for a public variable
5199 defined in this compilation unit. */
5200
5201 fputc ('\n', asm_out_file);
85595d1a 5202 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab
TW
5203 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5204 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
74153f8e 5205 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
340ccaab 5206 IDENTIFIER_POINTER (DECL_NAME (decl)));
85595d1a 5207 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5208 }
5209
5210 if (DECL_INITIAL (decl) == NULL)
5211 {
5212 /* Output a .debug_aranges entry for a public variable
6dc42e49 5213 which is tentatively defined in this compilation unit. */
340ccaab
TW
5214
5215 fputc ('\n', asm_out_file);
85595d1a 5216 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab 5217 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
9a631e8e 5218 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
340ccaab
TW
5219 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5220 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
85595d1a 5221 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5222 }
5223 }
5224
5225 /* If we are in terse mode, don't generate any DIEs to represent
5226 any variable declarations or definitions. */
5227
5228 if (debug_info_level <= DINFO_LEVEL_TERSE)
5229 return;
5230
5231 break;
5232
5233 case TYPE_DECL:
e6d9804c
TW
5234 /* Don't bother trying to generate any DIEs to represent any of the
5235 normal built-in types for the language we are compiling, except
5236 in cases where the types in question are *not* DWARF fundamental
5237 types. We make an exception in the case of non-fundamental types
5238 for the sake of objective C (and perhaps C++) because the GNU
5239 front-ends for these languages may in fact create certain "built-in"
5240 types which are (for example) RECORD_TYPEs. In such cases, we
5241 really need to output these (non-fundamental) types because other
5242 DIEs may contain references to them. */
5243
af02da67
JW
5244 /* Also ignore language dependent types here, because they are probably
5245 also built-in types. If we didn't ignore them, then we would get
5246 references to undefined labels because output_type doesn't support
5247 them. So, for now, we need to ignore them to avoid assembler
5248 errors. */
5249
5250 /* ??? This code is different than the equivalent code in dwarf2out.c.
5251 The dwarf2out.c code is probably more correct. */
5252
e6d9804c 5253 if (DECL_SOURCE_LINE (decl) == 0
af02da67
JW
5254 && (type_is_fundamental (TREE_TYPE (decl))
5255 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
340ccaab
TW
5256 return;
5257
5258 /* If we are in terse mode, don't generate any DIEs to represent
5259 any actual typedefs. Note that even when we are in terse mode,
5260 we must still output DIEs to represent those tagged types which
5261 are used (directly or indirectly) in the specification of either
5262 a return type or a formal parameter type of some function. */
5263
5264 if (debug_info_level <= DINFO_LEVEL_TERSE)
d4ef15f2 5265 if (! TYPE_DECL_IS_STUB (decl)
340ccaab
TW
5266 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5267 return;
5268
5269 break;
5270
5271 default:
5272 return;
5273 }
5274
5275 fputc ('\n', asm_out_file);
85595d1a 5276 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab 5277 finalizing = set_finalizing;
906c4e36 5278 output_decl (decl, NULL_TREE);
340ccaab
TW
5279
5280 /* NOTE: The call above to `output_decl' may have caused one or more
5281 file-scope named types (i.e. tagged types) to be placed onto the
5282 pending_types_list. We have to get those types off of that list
5283 at some point, and this is the perfect time to do it. If we didn't
5284 take them off now, they might still be on the list when cc1 finally
5285 exits. That might be OK if it weren't for the fact that when we put
5286 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5287 for these types, and that causes them never to be output unless
5288 `output_pending_types_for_scope' takes them off of the list and un-sets
5289 their TREE_ASM_WRITTEN flags. */
5290
906c4e36 5291 output_pending_types_for_scope (NULL_TREE);
340ccaab 5292
0a4be913
JW
5293 /* The above call should have totally emptied the pending_types_list
5294 if this is not a nested function or class. If this is a nested type,
5295 then the remaining pending_types will be emitted when the containing type
5296 is handled. */
5297
5298 if (! DECL_CONTEXT (decl))
5299 {
5300 if (pending_types != 0)
5301 abort ();
5302 }
340ccaab 5303
85595d1a 5304 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5305
5306 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5307 current_funcdef_number++;
5308}
5309\f
5310/* Output a marker (i.e. a label) for the beginning of the generated code
5311 for a lexical block. */
5312
5313void
5314dwarfout_begin_block (blocknum)
5315 register unsigned blocknum;
5316{
5317 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5318
4d1065ed 5319 function_section (current_function_decl);
340ccaab
TW
5320 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5321 ASM_OUTPUT_LABEL (asm_out_file, label);
5322}
5323
5324/* Output a marker (i.e. a label) for the end of the generated code
5325 for a lexical block. */
5326
5327void
5328dwarfout_end_block (blocknum)
5329 register unsigned blocknum;
5330{
5331 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5332
4d1065ed 5333 function_section (current_function_decl);
340ccaab
TW
5334 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5335 ASM_OUTPUT_LABEL (asm_out_file, label);
5336}
5337
5338/* Output a marker (i.e. a label) at a point in the assembly code which
5339 corresponds to a given source level label. */
5340
5341void
5342dwarfout_label (insn)
5343 register rtx insn;
5344{
5345 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5346 {
5347 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5348
4d1065ed 5349 function_section (current_function_decl);
340ccaab
TW
5350 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5351 (unsigned) INSN_UID (insn));
5352 ASM_OUTPUT_LABEL (asm_out_file, label);
5353 }
5354}
5355
2a819d04
TW
5356/* Output a marker (i.e. a label) for the point in the generated code where
5357 the real body of the function begins (after parameters have been moved
5358 to their home locations). */
5359
5360void
5361dwarfout_begin_function ()
5362{
5363 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5364
a94dbf2c
JM
5365 if (! use_gnu_debug_info_extensions)
5366 return;
4d1065ed 5367 function_section (current_function_decl);
2a819d04
TW
5368 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5369 ASM_OUTPUT_LABEL (asm_out_file, label);
5370}
5371
5372/* Output a marker (i.e. a label) for the point in the generated code where
5373 the real body of the function ends (just before the epilogue code). */
5374
5375void
5376dwarfout_end_function ()
5377{
5378 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5379
a94dbf2c
JM
5380 if (! use_gnu_debug_info_extensions)
5381 return;
4d1065ed 5382 function_section (current_function_decl);
2a819d04
TW
5383 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5384 ASM_OUTPUT_LABEL (asm_out_file, label);
5385}
5386
340ccaab
TW
5387/* Output a marker (i.e. a label) for the absolute end of the generated code
5388 for a function definition. This gets called *after* the epilogue code
5389 has been generated. */
5390
5391void
5392dwarfout_end_epilogue ()
5393{
5394 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5395
5396 /* Output a label to mark the endpoint of the code generated for this
5397 function. */
5398
5399 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5400 ASM_OUTPUT_LABEL (asm_out_file, label);
5401}
5402
5403static void
5404shuffle_filename_entry (new_zeroth)
5405 register filename_entry *new_zeroth;
5406{
5407 filename_entry temp_entry;
5408 register filename_entry *limit_p;
5409 register filename_entry *move_p;
5410
5411 if (new_zeroth == &filename_table[0])
5412 return;
5413
5414 temp_entry = *new_zeroth;
5415
5416 /* Shift entries up in the table to make room at [0]. */
5417
5418 limit_p = &filename_table[0];
5419 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5420 *move_p = *(move_p-1);
5421
5422 /* Install the found entry at [0]. */
5423
5424 filename_table[0] = temp_entry;
5425}
5426
5427/* Create a new (string) entry for the .debug_sfnames section. */
5428
5429static void
5430generate_new_sfname_entry ()
5431{
5432 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5433
5434 fputc ('\n', asm_out_file);
85595d1a 5435 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
340ccaab
TW
5436 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5437 ASM_OUTPUT_LABEL (asm_out_file, label);
74153f8e 5438 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
340ccaab
TW
5439 filename_table[0].name
5440 ? filename_table[0].name
5441 : "");
85595d1a 5442 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5443}
5444
5445/* Lookup a filename (in the list of filenames that we know about here in
5446 dwarfout.c) and return its "index". The index of each (known) filename
5447 is just a unique number which is associated with only that one filename.
5448 We need such numbers for the sake of generating labels (in the
5449 .debug_sfnames section) and references to those unique labels (in the
5450 .debug_srcinfo and .debug_macinfo sections).
5451
5452 If the filename given as an argument is not found in our current list,
5453 add it to the list and assign it the next available unique index number.
5454
5455 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5456 one), we shuffle the filename found (or added) up to the zeroth entry of
5457 our list of filenames (which is always searched linearly). We do this so
5458 as to optimize the most common case for these filename lookups within
5459 dwarfout.c. The most common case by far is the case where we call
5460 lookup_filename to lookup the very same filename that we did a lookup
5461 on the last time we called lookup_filename. We make sure that this
5462 common case is fast because such cases will constitute 99.9% of the
5463 lookups we ever do (in practice).
5464
5465 If we add a new filename entry to our table, we go ahead and generate
5466 the corresponding entry in the .debug_sfnames section right away.
5467 Doing so allows us to avoid tickling an assembler bug (present in some
5468 m68k assemblers) which yields assembly-time errors in cases where the
5469 difference of two label addresses is taken and where the two labels
5470 are in a section *other* than the one where the difference is being
5471 calculated, and where at least one of the two symbol references is a
5472 forward reference. (This bug could be tickled by our .debug_srcinfo
5473 entries if we don't output their corresponding .debug_sfnames entries
461b77c8 5474 before them.) */
340ccaab
TW
5475
5476static unsigned
5477lookup_filename (file_name)
a996cbd4 5478 const char *file_name;
340ccaab
TW
5479{
5480 register filename_entry *search_p;
5481 register filename_entry *limit_p = &filename_table[ft_entries];
5482
5483 for (search_p = filename_table; search_p < limit_p; search_p++)
5484 if (!strcmp (file_name, search_p->name))
5485 {
5486 /* When we get here, we have found the filename that we were
5487 looking for in the filename_table. Now we want to make sure
5488 that it gets moved to the zero'th entry in the table (if it
5489 is not already there) so that subsequent attempts to find the
5490 same filename will find it as quickly as possible. */
5491
5492 shuffle_filename_entry (search_p);
5493 return filename_table[0].number;
5494 }
5495
5496 /* We come here whenever we have a new filename which is not registered
5497 in the current table. Here we add it to the table. */
5498
5499 /* Prepare to add a new table entry by making sure there is enough space
5500 in the table to do so. If not, expand the current table. */
5501
5502 if (ft_entries == ft_entries_allocated)
5503 {
5504 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5505 filename_table
5506 = (filename_entry *)
5507 xrealloc (filename_table,
5508 ft_entries_allocated * sizeof (filename_entry));
5509 }
5510
5511 /* Initially, add the new entry at the end of the filename table. */
5512
5513 filename_table[ft_entries].number = ft_entries;
5514 filename_table[ft_entries].name = xstrdup (file_name);
5515
5516 /* Shuffle the new entry into filename_table[0]. */
5517
5518 shuffle_filename_entry (&filename_table[ft_entries]);
5519
5520 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5521 generate_new_sfname_entry ();
5522
5523 ft_entries++;
5524 return filename_table[0].number;
5525}
5526
5527static void
5528generate_srcinfo_entry (line_entry_num, files_entry_num)
5529 unsigned line_entry_num;
5530 unsigned files_entry_num;
5531{
5532 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5533
5534 fputc ('\n', asm_out_file);
85595d1a 5535 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
340ccaab
TW
5536 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5537 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5538 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5539 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
85595d1a 5540 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5541}
5542
5543void
5544dwarfout_line (filename, line)
a996cbd4 5545 register const char *filename;
340ccaab
TW
5546 register unsigned line;
5547{
6619df07
JM
5548 if (debug_info_level >= DINFO_LEVEL_NORMAL
5549 /* We can't emit line number info for functions in separate sections,
5550 because the assembler can't subtract labels in different sections. */
5551 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
340ccaab
TW
5552 {
5553 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5554 static unsigned last_line_entry_num = 0;
5555 static unsigned prev_file_entry_num = (unsigned) -1;
a94dbf2c 5556 register unsigned this_file_entry_num;
340ccaab 5557
4d1065ed 5558 function_section (current_function_decl);
340ccaab
TW
5559 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5560 ASM_OUTPUT_LABEL (asm_out_file, label);
5561
5562 fputc ('\n', asm_out_file);
340ccaab 5563
a94dbf2c
JM
5564 if (use_gnu_debug_info_extensions)
5565 this_file_entry_num = lookup_filename (filename);
5566 else
5567 this_file_entry_num = (unsigned) -1;
5568
3800b162 5569 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
5570 if (this_file_entry_num != prev_file_entry_num)
5571 {
5572 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5573
5574 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5575 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5576 }
5577
5578 {
a996cbd4 5579 register const char *tail = rindex (filename, '/');
340ccaab
TW
5580
5581 if (tail != NULL)
5582 filename = tail;
5583 }
5584
2e494f70 5585 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
340ccaab
TW
5586 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5587 filename, line);
5588 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5589 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
85595d1a 5590 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5591
5592 if (this_file_entry_num != prev_file_entry_num)
5593 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5594 prev_file_entry_num = this_file_entry_num;
5595 }
5596}
5597
5598/* Generate an entry in the .debug_macinfo section. */
5599
5600static void
5601generate_macinfo_entry (type_and_offset, string)
a996cbd4
KG
5602 register const char *type_and_offset;
5603 register const char *string;
340ccaab 5604{
a94dbf2c
JM
5605 if (! use_gnu_debug_info_extensions)
5606 return;
5607
340ccaab 5608 fputc ('\n', asm_out_file);
85595d1a 5609 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
2e494f70 5610 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
74153f8e 5611 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
85595d1a 5612 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5613}
5614
5615void
5616dwarfout_start_new_source_file (filename)
a996cbd4 5617 register const char *filename;
340ccaab
TW
5618{
5619 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5620 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5621
5622 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5623 sprintf (type_and_offset, "0x%08x+%s-%s",
e9a25f70
JL
5624 ((unsigned) MACINFO_start << 24),
5625 /* Hack: skip leading '*' . */
5626 (*label == '*') + label,
5627 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
340ccaab
TW
5628 generate_macinfo_entry (type_and_offset, "");
5629}
5630
5631void
5632dwarfout_resume_previous_source_file (lineno)
5633 register unsigned lineno;
5634{
5635 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5636
5637 sprintf (type_and_offset, "0x%08x+%u",
5638 ((unsigned) MACINFO_resume << 24), lineno);
5639 generate_macinfo_entry (type_and_offset, "");
5640}
5641
5642/* Called from check_newline in c-parse.y. The `buffer' parameter
5643 contains the tail part of the directive line, i.e. the part which
5644 is past the initial whitespace, #, whitespace, directive-name,
5645 whitespace part. */
5646
5647void
5648dwarfout_define (lineno, buffer)
5649 register unsigned lineno;
a996cbd4 5650 register const char *buffer;
340ccaab
TW
5651{
5652 static int initialized = 0;
5653 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5654
5655 if (!initialized)
5656 {
5657 dwarfout_start_new_source_file (primary_filename);
5658 initialized = 1;
5659 }
5660 sprintf (type_and_offset, "0x%08x+%u",
5661 ((unsigned) MACINFO_define << 24), lineno);
5662 generate_macinfo_entry (type_and_offset, buffer);
5663}
5664
5665/* Called from check_newline in c-parse.y. The `buffer' parameter
5666 contains the tail part of the directive line, i.e. the part which
5667 is past the initial whitespace, #, whitespace, directive-name,
5668 whitespace part. */
5669
5670void
5671dwarfout_undef (lineno, buffer)
5672 register unsigned lineno;
a996cbd4 5673 register const char *buffer;
340ccaab
TW
5674{
5675 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5676
5677 sprintf (type_and_offset, "0x%08x+%u",
5678 ((unsigned) MACINFO_undef << 24), lineno);
5679 generate_macinfo_entry (type_and_offset, buffer);
5680}
5681
5682/* Set up for Dwarf output at the start of compilation. */
5683
5684void
5685dwarfout_init (asm_out_file, main_input_filename)
5686 register FILE *asm_out_file;
3b304f5b 5687 register const char *main_input_filename;
340ccaab
TW
5688{
5689 /* Remember the name of the primary input file. */
5690
5691 primary_filename = main_input_filename;
5692
5693 /* Allocate the initial hunk of the pending_sibling_stack. */
5694
5695 pending_sibling_stack
5696 = (unsigned *)
5697 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5698 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5699 pending_siblings = 1;
5700
5701 /* Allocate the initial hunk of the filename_table. */
5702
5703 filename_table
5704 = (filename_entry *)
5705 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5706 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5707 ft_entries = 0;
5708
5709 /* Allocate the initial hunk of the pending_types_list. */
5710
5711 pending_types_list
5712 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5713 pending_types_allocated = PENDING_TYPES_INCREMENT;
5714 pending_types = 0;
5715
5716 /* Create an artificial RECORD_TYPE node which we can use in our hack
5717 to get the DIEs representing types of formal parameters to come out
5718 only *after* the DIEs for the formal parameters themselves. */
5719
5720 fake_containing_scope = make_node (RECORD_TYPE);
5721
5722 /* Output a starting label for the .text section. */
5723
5724 fputc ('\n', asm_out_file);
85595d1a 5725 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
340ccaab 5726 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
85595d1a 5727 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5728
5729 /* Output a starting label for the .data section. */
5730
5731 fputc ('\n', asm_out_file);
85595d1a 5732 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
340ccaab 5733 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
85595d1a 5734 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab 5735
13963720 5736#if 0 /* GNU C doesn't currently use .data1. */
340ccaab
TW
5737 /* Output a starting label for the .data1 section. */
5738
5739 fputc ('\n', asm_out_file);
85595d1a 5740 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
340ccaab 5741 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
85595d1a 5742 ASM_OUTPUT_POP_SECTION (asm_out_file);
13963720 5743#endif
340ccaab
TW
5744
5745 /* Output a starting label for the .rodata section. */
5746
5747 fputc ('\n', asm_out_file);
85595d1a 5748 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
340ccaab 5749 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
85595d1a 5750 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab 5751
13963720 5752#if 0 /* GNU C doesn't currently use .rodata1. */
340ccaab
TW
5753 /* Output a starting label for the .rodata1 section. */
5754
5755 fputc ('\n', asm_out_file);
85595d1a 5756 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
340ccaab 5757 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
85595d1a 5758 ASM_OUTPUT_POP_SECTION (asm_out_file);
13963720 5759#endif
340ccaab
TW
5760
5761 /* Output a starting label for the .bss section. */
5762
5763 fputc ('\n', asm_out_file);
85595d1a 5764 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
340ccaab 5765 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
85595d1a 5766 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5767
5768 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5769 {
a94dbf2c
JM
5770 if (use_gnu_debug_info_extensions)
5771 {
5772 /* Output a starting label and an initial (compilation directory)
5773 entry for the .debug_sfnames section. The starting label will be
5774 referenced by the initial entry in the .debug_srcinfo section. */
340ccaab 5775
a94dbf2c
JM
5776 fputc ('\n', asm_out_file);
5777 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5778 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5779 {
d3e3972c 5780 register const char *pwd = getpwd ();
a94dbf2c
JM
5781 register char *dirname;
5782
a94dbf2c
JM
5783 if (!pwd)
5784 pfatal_with_name ("getpwd");
ad85216e 5785 dirname = concat (pwd, "/", NULL);
74153f8e 5786 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
a94dbf2c
JM
5787 free (dirname);
5788 }
5789 ASM_OUTPUT_POP_SECTION (asm_out_file);
5790 }
340ccaab 5791
a94dbf2c
JM
5792 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5793 && use_gnu_debug_info_extensions)
340ccaab
TW
5794 {
5795 /* Output a starting label for the .debug_macinfo section. This
5796 label will be referenced by the AT_mac_info attribute in the
5797 TAG_compile_unit DIE. */
5798
5799 fputc ('\n', asm_out_file);
85595d1a 5800 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
340ccaab 5801 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
85595d1a 5802 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5803 }
5804
5805 /* Generate the initial entry for the .line section. */
5806
5807 fputc ('\n', asm_out_file);
85595d1a 5808 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
5809 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5810 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5811 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
85595d1a 5812 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab 5813
a94dbf2c
JM
5814 if (use_gnu_debug_info_extensions)
5815 {
5816 /* Generate the initial entry for the .debug_srcinfo section. */
5817
5818 fputc ('\n', asm_out_file);
5819 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5820 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5821 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5822 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5823 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5824 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
340ccaab 5825#ifdef DWARF_TIMESTAMPS
a94dbf2c 5826 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
340ccaab 5827#else
a94dbf2c 5828 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
340ccaab 5829#endif
a94dbf2c
JM
5830 ASM_OUTPUT_POP_SECTION (asm_out_file);
5831 }
340ccaab
TW
5832
5833 /* Generate the initial entry for the .debug_pubnames section. */
5834
5835 fputc ('\n', asm_out_file);
85595d1a 5836 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab 5837 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
85595d1a 5838 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5839
5840 /* Generate the initial entry for the .debug_aranges section. */
5841
5842 fputc ('\n', asm_out_file);
85595d1a 5843 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab 5844 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
85595d1a 5845 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5846 }
5847
5848 /* Setup first DIE number == 1. */
5849 NEXT_DIE_NUM = next_unused_dienum++;
5850
5851 /* Generate the initial DIE for the .debug section. Note that the
5852 (string) value given in the AT_name attribute of the TAG_compile_unit
5853 DIE will (typically) be a relative pathname and that this pathname
5854 should be taken as being relative to the directory from which the
5855 compiler was invoked when the given (base) source file was compiled. */
5856
5857 fputc ('\n', asm_out_file);
85595d1a 5858 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
340ccaab
TW
5859 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5860 output_die (output_compile_unit_die, main_input_filename);
85595d1a 5861 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5862
5863 fputc ('\n', asm_out_file);
5864}
5865
5866/* Output stuff that dwarf requires at the end of every file. */
5867
5868void
5869dwarfout_finish ()
5870{
5871 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5872
5873 fputc ('\n', asm_out_file);
85595d1a 5874 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
ede1dbac
ES
5875 retry_incomplete_types ();
5876 fputc ('\n', asm_out_file);
340ccaab
TW
5877
5878 /* Mark the end of the chain of siblings which represent all file-scope
5879 declarations in this compilation unit. */
5880
5881 /* The (null) DIE which represents the terminator for the (sibling linked)
5882 list of file-scope items is *special*. Normally, we would just call
5883 end_sibling_chain at this point in order to output a word with the
5884 value `4' and that word would act as the terminator for the list of
5885 DIEs describing file-scope items. Unfortunately, if we were to simply
5886 do that, the label that would follow this DIE in the .debug section
5887 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5888 machines) to a 4 byte boundary.
5889
5890 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5891 the trick used is to insert extra (otherwise useless) padding bytes
6dc42e49 5892 into the (null) DIE that we know must precede the ..D2 label in the
340ccaab
TW
5893 .debug section. The amount of padding required can be anywhere between
5894 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5895 with the padding) would normally contain the value 4, but now it will
5896 also have to include the padding bytes, so it will instead have some
5897 value in the range 4..7.
5898
5899 Fortunately, the rules of Dwarf say that any DIE whose length word
5900 contains *any* value less than 8 should be treated as a null DIE, so
5901 this trick works out nicely. Clever, eh? Don't give me any credit
5902 (or blame). I didn't think of this scheme. I just conformed to it.
5903 */
5904
0f41302f 5905 output_die (output_padded_null_die, (void *) 0);
340ccaab
TW
5906 dienum_pop ();
5907
5908 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5909 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
85595d1a 5910 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5911
5912 /* Output a terminator label for the .text section. */
5913
5914 fputc ('\n', asm_out_file);
85595d1a 5915 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
340ccaab 5916 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
85595d1a 5917 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5918
5919 /* Output a terminator label for the .data section. */
5920
5921 fputc ('\n', asm_out_file);
85595d1a 5922 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
340ccaab 5923 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
85595d1a 5924 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab 5925
13963720 5926#if 0 /* GNU C doesn't currently use .data1. */
340ccaab
TW
5927 /* Output a terminator label for the .data1 section. */
5928
5929 fputc ('\n', asm_out_file);
85595d1a 5930 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
340ccaab 5931 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
85595d1a 5932 ASM_OUTPUT_POP_SECTION (asm_out_file);
13963720 5933#endif
340ccaab
TW
5934
5935 /* Output a terminator label for the .rodata section. */
5936
5937 fputc ('\n', asm_out_file);
85595d1a 5938 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
340ccaab 5939 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
85595d1a 5940 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab 5941
13963720 5942#if 0 /* GNU C doesn't currently use .rodata1. */
340ccaab
TW
5943 /* Output a terminator label for the .rodata1 section. */
5944
5945 fputc ('\n', asm_out_file);
85595d1a 5946 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
340ccaab 5947 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
85595d1a 5948 ASM_OUTPUT_POP_SECTION (asm_out_file);
13963720 5949#endif
340ccaab
TW
5950
5951 /* Output a terminator label for the .bss section. */
5952
5953 fputc ('\n', asm_out_file);
85595d1a 5954 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
340ccaab 5955 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
85595d1a 5956 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5957
5958 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5959 {
5960 /* Output a terminating entry for the .line section. */
5961
5962 fputc ('\n', asm_out_file);
85595d1a 5963 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
340ccaab
TW
5964 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5965 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5966 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5967 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5968 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
85595d1a 5969 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab 5970
a94dbf2c
JM
5971 if (use_gnu_debug_info_extensions)
5972 {
5973 /* Output a terminating entry for the .debug_srcinfo section. */
5974
5975 fputc ('\n', asm_out_file);
5976 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5977 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5978 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5979 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5980 ASM_OUTPUT_POP_SECTION (asm_out_file);
5981 }
340ccaab
TW
5982
5983 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5984 {
5985 /* Output terminating entries for the .debug_macinfo section. */
5986
5987 dwarfout_resume_previous_source_file (0);
5988
5989 fputc ('\n', asm_out_file);
85595d1a 5990 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
340ccaab 5991 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
74153f8e 5992 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
85595d1a 5993 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
5994 }
5995
5996 /* Generate the terminating entry for the .debug_pubnames section. */
5997
5998 fputc ('\n', asm_out_file);
85595d1a 5999 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
340ccaab 6000 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
74153f8e 6001 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
85595d1a 6002 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab
TW
6003
6004 /* Generate the terminating entries for the .debug_aranges section.
6005
6006 Note that we want to do this only *after* we have output the end
6007 labels (for the various program sections) which we are going to
6008 refer to here. This allows us to work around a bug in the m68k
6009 svr4 assembler. That assembler gives bogus assembly-time errors
6010 if (within any given section) you try to take the difference of
6011 two relocatable symbols, both of which are located within some
6012 other section, and if one (or both?) of the symbols involved is
6013 being forward-referenced. By generating the .debug_aranges
6014 entries at this late point in the assembly output, we skirt the
6015 issue simply by avoiding forward-references.
6016 */
6017
6018 fputc ('\n', asm_out_file);
85595d1a 6019 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
340ccaab
TW
6020
6021 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6022 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6023
6024 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6025 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6026
13963720 6027#if 0 /* GNU C doesn't currently use .data1. */
340ccaab
TW
6028 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6029 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6030 DATA1_BEGIN_LABEL);
13963720 6031#endif
340ccaab
TW
6032
6033 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6034 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6035 RODATA_BEGIN_LABEL);
6036
13963720 6037#if 0 /* GNU C doesn't currently use .rodata1. */
340ccaab
TW
6038 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6039 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6040 RODATA1_BEGIN_LABEL);
13963720 6041#endif
340ccaab
TW
6042
6043 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6044 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6045
6046 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6047 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6048
85595d1a 6049 ASM_OUTPUT_POP_SECTION (asm_out_file);
340ccaab 6050 }
0a4be913
JW
6051
6052 /* There should not be any pending types left at the end. We need
6053 this now because it may not have been checked on the last call to
6054 dwarfout_file_scope_decl. */
6055 if (pending_types != 0)
6056 abort ();
340ccaab
TW
6057}
6058
9a666dda 6059#endif /* DWARF_DEBUGGING_INFO */