1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 95-98, 1999 Free Software Foundation, Inc.
3 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* $FreeBSD: src/contrib/gcc/dwarfout.c,v 1.4 1999/10/26 08:38:21 obrien Exp $ */
26 #ifdef DWARF_DEBUGGING_INFO
32 #include "hard-reg-set.h"
33 #include "insn-config.h"
40 #if defined(DWARF_TIMESTAMPS)
42 extern time_t time PROTO ((time_t *)); /* FIXME: use NEED_DECLARATION_TIME */
43 #endif /* !defined(POSIX) */
44 #endif /* defined(DWARF_TIMESTAMPS) */
46 /* We cannot use <assert.h> in GCC source, since that would include
47 GCC's assert.h, which may not be compatible with the host compiler. */
52 # define assert(e) do { if (! (e)) abort (); } while (0)
55 extern char *getpwd PROTO((void));
57 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
58 regarding the GNU implementation of Dwarf. */
60 /* NOTE: In the comments in this file, many references are made to
61 so called "Debugging Information Entries". For the sake of brevity,
62 this term is abbreviated to `DIE' throughout the remainder of this
65 /* Note that the implementation of C++ support herein is (as yet) unfinished.
66 If you want to try to complete it, more power to you. */
68 /* How to start an assembler comment. */
69 #ifndef ASM_COMMENT_START
70 #define ASM_COMMENT_START ";#"
73 /* How to print out a register name. */
75 #define PRINT_REG(RTX, CODE, FILE) \
76 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
79 /* Define a macro which returns non-zero for any tagged type which is
80 used (directly or indirectly) in the specification of either some
81 function's return type or some formal parameter of some function.
82 We use this macro when we are operating in "terse" mode to help us
83 know what tagged types have to be represented in Dwarf (even in
84 terse mode) and which ones don't.
86 A flag bit with this meaning really should be a part of the normal
87 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
88 for these nodes. For now, we have to just fake it. It it safe for
89 us to simply return zero for all complete tagged types (which will
90 get forced out anyway if they were used in the specification of some
91 formal or return type) and non-zero for all incomplete tagged types.
94 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
96 /* Define a macro which returns non-zero for a TYPE_DECL which was
97 implicitly generated for a tagged type.
99 Note that unlike the gcc front end (which generates a NULL named
100 TYPE_DECL node for each complete tagged type, each array type, and
101 each function type node created) the g++ front end generates a
102 _named_ TYPE_DECL node for each tagged type node created.
103 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
104 generate a DW_TAG_typedef DIE for them. */
105 #define TYPE_DECL_IS_STUB(decl) \
106 (DECL_NAME (decl) == NULL \
107 || (DECL_ARTIFICIAL (decl) \
108 && is_tagged_type (TREE_TYPE (decl)) \
109 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
111 extern int flag_traditional;
112 extern char *version_string;
113 extern char *language_string;
115 /* Maximum size (in bytes) of an artificially generated label. */
117 #define MAX_ARTIFICIAL_LABEL_BYTES 30
119 /* Make sure we know the sizes of the various types dwarf can describe.
120 These are only defaults. If the sizes are different for your target,
121 you should override these values by defining the appropriate symbols
122 in your tm.h file. */
124 #ifndef CHAR_TYPE_SIZE
125 #define CHAR_TYPE_SIZE BITS_PER_UNIT
128 #ifndef SHORT_TYPE_SIZE
129 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
132 #ifndef INT_TYPE_SIZE
133 #define INT_TYPE_SIZE BITS_PER_WORD
136 #ifndef LONG_TYPE_SIZE
137 #define LONG_TYPE_SIZE BITS_PER_WORD
140 #ifndef LONG_LONG_TYPE_SIZE
141 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
144 #ifndef WCHAR_TYPE_SIZE
145 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
148 #ifndef WCHAR_UNSIGNED
149 #define WCHAR_UNSIGNED 0
152 #ifndef FLOAT_TYPE_SIZE
153 #define FLOAT_TYPE_SIZE BITS_PER_WORD
156 #ifndef DOUBLE_TYPE_SIZE
157 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
160 #ifndef LONG_DOUBLE_TYPE_SIZE
161 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
164 /* Structure to keep track of source filenames. */
166 struct filename_entry {
171 typedef struct filename_entry filename_entry;
173 /* Pointer to an array of elements, each one having the structure above. */
175 static filename_entry *filename_table;
177 /* Total number of entries in the table (i.e. array) pointed to by
178 `filename_table'. This is the *total* and includes both used and
181 static unsigned ft_entries_allocated;
183 /* Number of entries in the filename_table which are actually in use. */
185 static unsigned ft_entries;
187 /* Size (in elements) of increments by which we may expand the filename
188 table. Actually, a single hunk of space of this size should be enough
189 for most typical programs. */
191 #define FT_ENTRIES_INCREMENT 64
193 /* Local pointer to the name of the main input file. Initialized in
196 static char *primary_filename;
198 /* Pointer to the most recent filename for which we produced some line info. */
200 static char *last_filename;
202 /* For Dwarf output, we must assign lexical-blocks id numbers
203 in the order in which their beginnings are encountered.
204 We output Dwarf debugging info that refers to the beginnings
205 and ends of the ranges of code for each lexical block with
206 assembler labels ..Bn and ..Bn.e, where n is the block number.
207 The labels themselves are generated in final.c, which assigns
208 numbers to the blocks in the same way. */
210 static unsigned next_block_number = 2;
212 /* Counter to generate unique names for DIEs. */
214 static unsigned next_unused_dienum = 1;
216 /* Number of the DIE which is currently being generated. */
218 static unsigned current_dienum;
220 /* Number to use for the special "pubname" label on the next DIE which
221 represents a function or data object defined in this compilation
222 unit which has "extern" linkage. */
224 static int next_pubname_number = 0;
226 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
228 /* Pointer to a dynamically allocated list of pre-reserved and still
229 pending sibling DIE numbers. Note that this list will grow as needed. */
231 static unsigned *pending_sibling_stack;
233 /* Counter to keep track of the number of pre-reserved and still pending
234 sibling DIE numbers. */
236 static unsigned pending_siblings;
238 /* The currently allocated size of the above list (expressed in number of
241 static unsigned pending_siblings_allocated;
243 /* Size (in elements) of increments by which we may expand the pending
244 sibling stack. Actually, a single hunk of space of this size should
245 be enough for most typical programs. */
247 #define PENDING_SIBLINGS_INCREMENT 64
249 /* Non-zero if we are performing our file-scope finalization pass and if
250 we should force out Dwarf descriptions of any and all file-scope
251 tagged types which are still incomplete types. */
253 static int finalizing = 0;
255 /* A pointer to the base of a list of pending types which we haven't
256 generated DIEs for yet, but which we will have to come back to
259 static tree *pending_types_list;
261 /* Number of elements currently allocated for the pending_types_list. */
263 static unsigned pending_types_allocated;
265 /* Number of elements of pending_types_list currently in use. */
267 static unsigned pending_types;
269 /* Size (in elements) of increments by which we may expand the pending
270 types list. Actually, a single hunk of space of this size should
271 be enough for most typical programs. */
273 #define PENDING_TYPES_INCREMENT 64
275 /* A pointer to the base of a list of incomplete types which might be
276 completed at some later time. */
278 static tree *incomplete_types_list;
280 /* Number of elements currently allocated for the incomplete_types_list. */
281 static unsigned incomplete_types_allocated;
283 /* Number of elements of incomplete_types_list currently in use. */
284 static unsigned incomplete_types;
286 /* Size (in elements) of increments by which we may expand the incomplete
287 types list. Actually, a single hunk of space of this size should
288 be enough for most typical programs. */
289 #define INCOMPLETE_TYPES_INCREMENT 64
291 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
292 This is used in a hack to help us get the DIEs describing types of
293 formal parameters to come *after* all of the DIEs describing the formal
294 parameters themselves. That's necessary in order to be compatible
295 with what the brain-damaged svr4 SDB debugger requires. */
297 static tree fake_containing_scope;
299 /* The number of the current function definition that we are generating
300 debugging information for. These numbers range from 1 up to the maximum
301 number of function definitions contained within the current compilation
302 unit. These numbers are used to create unique labels for various things
303 contained within various function definitions. */
305 static unsigned current_funcdef_number = 1;
307 /* A pointer to the ..._DECL node which we have most recently been working
308 on. We keep this around just in case something about it looks screwy
309 and we want to tell the user what the source coordinates for the actual
312 static tree dwarf_last_decl;
314 /* A flag indicating that we are emitting the member declarations of a
315 class, so member functions and variables should not be entirely emitted.
316 This is a kludge to avoid passing a second argument to output_*_die. */
320 /* Forward declarations for functions defined in this file. */
322 static char *dwarf_tag_name PROTO((unsigned));
323 static char *dwarf_attr_name PROTO((unsigned));
324 static char *dwarf_stack_op_name PROTO((unsigned));
325 static char *dwarf_typemod_name PROTO((unsigned));
326 static char *dwarf_fmt_byte_name PROTO((unsigned));
327 static char *dwarf_fund_type_name PROTO((unsigned));
328 static tree decl_ultimate_origin PROTO((tree));
329 static tree block_ultimate_origin PROTO((tree));
330 static tree decl_class_context PROTO((tree));
332 static void output_unsigned_leb128 PROTO((unsigned long));
333 static void output_signed_leb128 PROTO((long));
335 static inline int is_body_block PROTO((tree));
336 static int fundamental_type_code PROTO((tree));
337 static tree root_type_1 PROTO((tree, int));
338 static tree root_type PROTO((tree));
339 static void write_modifier_bytes_1 PROTO((tree, int, int, int));
340 static void write_modifier_bytes PROTO((tree, int, int));
341 static inline int type_is_fundamental PROTO((tree));
342 static void equate_decl_number_to_die_number PROTO((tree));
343 static inline void equate_type_number_to_die_number PROTO((tree));
344 static void output_reg_number PROTO((rtx));
345 static void output_mem_loc_descriptor PROTO((rtx));
346 static void output_loc_descriptor PROTO((rtx));
347 static void output_bound_representation PROTO((tree, unsigned, int));
348 static void output_enumeral_list PROTO((tree));
349 static inline unsigned ceiling PROTO((unsigned, unsigned));
350 static inline tree field_type PROTO((tree));
351 static inline unsigned simple_type_align_in_bits PROTO((tree));
352 static inline unsigned simple_type_size_in_bits PROTO((tree));
353 static unsigned field_byte_offset PROTO((tree));
354 static inline void sibling_attribute PROTO((void));
355 static void location_attribute PROTO((rtx));
356 static void data_member_location_attribute PROTO((tree));
357 static void const_value_attribute PROTO((rtx));
358 static void location_or_const_value_attribute PROTO((tree));
359 static inline void name_attribute PROTO((char *));
360 static inline void fund_type_attribute PROTO((unsigned));
361 static void mod_fund_type_attribute PROTO((tree, int, int));
362 static inline void user_def_type_attribute PROTO((tree));
363 static void mod_u_d_type_attribute PROTO((tree, int, int));
364 #ifdef USE_ORDERING_ATTRIBUTE
365 static inline void ordering_attribute PROTO((unsigned));
366 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
367 static void subscript_data_attribute PROTO((tree));
368 static void byte_size_attribute PROTO((tree));
369 static inline void bit_offset_attribute PROTO((tree));
370 static inline void bit_size_attribute PROTO((tree));
371 static inline void element_list_attribute PROTO((tree));
372 static inline void stmt_list_attribute PROTO((char *));
373 static inline void low_pc_attribute PROTO((char *));
374 static inline void high_pc_attribute PROTO((char *));
375 static inline void body_begin_attribute PROTO((char *));
376 static inline void body_end_attribute PROTO((char *));
377 static inline void language_attribute PROTO((unsigned));
378 static inline void member_attribute PROTO((tree));
380 static inline void string_length_attribute PROTO((tree));
382 static inline void comp_dir_attribute PROTO((char *));
383 static inline void sf_names_attribute PROTO((char *));
384 static inline void src_info_attribute PROTO((char *));
385 static inline void mac_info_attribute PROTO((char *));
386 static inline void prototyped_attribute PROTO((tree));
387 static inline void producer_attribute PROTO((char *));
388 static inline void inline_attribute PROTO((tree));
389 static inline void containing_type_attribute PROTO((tree));
390 static inline void abstract_origin_attribute PROTO((tree));
391 #ifdef DWARF_DECL_COORDINATES
392 static inline void src_coords_attribute PROTO((unsigned, unsigned));
393 #endif /* defined(DWARF_DECL_COORDINATES) */
394 static inline void pure_or_virtual_attribute PROTO((tree));
395 static void name_and_src_coords_attributes PROTO((tree));
396 static void type_attribute PROTO((tree, int, int));
397 static char *type_tag PROTO((tree));
398 static inline void dienum_push PROTO((void));
399 static inline void dienum_pop PROTO((void));
400 static inline tree member_declared_type PROTO((tree));
401 static char *function_start_label PROTO((tree));
402 static void output_array_type_die PROTO((void *));
403 static void output_set_type_die PROTO((void *));
405 static void output_entry_point_die PROTO((void *));
407 static void output_inlined_enumeration_type_die PROTO((void *));
408 static void output_inlined_structure_type_die PROTO((void *));
409 static void output_inlined_union_type_die PROTO((void *));
410 static void output_enumeration_type_die PROTO((void *));
411 static void output_formal_parameter_die PROTO((void *));
412 static void output_global_subroutine_die PROTO((void *));
413 static void output_global_variable_die PROTO((void *));
414 static void output_label_die PROTO((void *));
415 static void output_lexical_block_die PROTO((void *));
416 static void output_inlined_subroutine_die PROTO((void *));
417 static void output_local_variable_die PROTO((void *));
418 static void output_member_die PROTO((void *));
420 static void output_pointer_type_die PROTO((void *));
421 static void output_reference_type_die PROTO((void *));
423 static void output_ptr_to_mbr_type_die PROTO((void *));
424 static void output_compile_unit_die PROTO((void *));
425 static void output_string_type_die PROTO((void *));
426 static void output_inheritance_die PROTO((void *));
427 static void output_structure_type_die PROTO((void *));
428 static void output_local_subroutine_die PROTO((void *));
429 static void output_subroutine_type_die PROTO((void *));
430 static void output_typedef_die PROTO((void *));
431 static void output_union_type_die PROTO((void *));
432 static void output_unspecified_parameters_die PROTO((void *));
433 static void output_padded_null_die PROTO((void *));
434 static void output_die PROTO((void (*) PROTO((void *)), void *));
435 static void end_sibling_chain PROTO((void));
436 static void output_formal_types PROTO((tree));
437 static void pend_type PROTO((tree));
438 static int type_ok_for_scope PROTO((tree, tree));
439 static void output_pending_types_for_scope PROTO((tree));
440 static void output_type PROTO((tree, tree));
441 static void output_tagged_type_instantiation PROTO((tree));
442 static void output_block PROTO((tree, int));
443 static void output_decls_for_scope PROTO((tree, int));
444 static void output_decl PROTO((tree, tree));
445 static void shuffle_filename_entry PROTO((filename_entry *));
446 static void generate_new_sfname_entry PROTO((void));
447 static unsigned lookup_filename PROTO((char *));
448 static void generate_srcinfo_entry PROTO((unsigned, unsigned));
449 static void generate_macinfo_entry PROTO((char *, char *));
450 static int is_pseudo_reg PROTO((rtx));
451 static tree type_main_variant PROTO((tree));
452 static int is_tagged_type PROTO((tree));
453 static int is_redundant_typedef PROTO((tree));
455 /* Definitions of defaults for assembler-dependent names of various
456 pseudo-ops and section names.
458 Theses may be overridden in your tm.h file (if necessary) for your
459 particular assembler. The default values provided here correspond to
460 what is expected by "standard" AT&T System V.4 assemblers. */
463 #define FILE_ASM_OP ".file"
465 #ifndef VERSION_ASM_OP
466 #define VERSION_ASM_OP ".version"
468 #ifndef UNALIGNED_SHORT_ASM_OP
469 #define UNALIGNED_SHORT_ASM_OP ".2byte"
471 #ifndef UNALIGNED_INT_ASM_OP
472 #define UNALIGNED_INT_ASM_OP ".4byte"
475 #define ASM_BYTE_OP ".byte"
478 #define SET_ASM_OP ".set"
481 /* Pseudo-ops for pushing the current section onto the section stack (and
482 simultaneously changing to a new section) and for poping back to the
483 section we were in immediately before this one. Note that most svr4
484 assemblers only maintain a one level stack... you can push all the
485 sections you want, but you can only pop out one level. (The sparc
486 svr4 assembler is an exception to this general rule.) That's
487 OK because we only use at most one level of the section stack herein. */
489 #ifndef PUSHSECTION_ASM_OP
490 #define PUSHSECTION_ASM_OP ".section"
492 #ifndef POPSECTION_ASM_OP
493 #define POPSECTION_ASM_OP ".previous"
496 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
497 to print the PUSHSECTION_ASM_OP and the section name. The default here
498 works for almost all svr4 assemblers, except for the sparc, where the
499 section name must be enclosed in double quotes. (See sparcv4.h.) */
501 #ifndef PUSHSECTION_FORMAT
502 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
505 #ifndef DEBUG_SECTION
506 #define DEBUG_SECTION ".debug"
509 #define LINE_SECTION ".line"
511 #ifndef SFNAMES_SECTION
512 #define SFNAMES_SECTION ".debug_sfnames"
514 #ifndef SRCINFO_SECTION
515 #define SRCINFO_SECTION ".debug_srcinfo"
517 #ifndef MACINFO_SECTION
518 #define MACINFO_SECTION ".debug_macinfo"
520 #ifndef PUBNAMES_SECTION
521 #define PUBNAMES_SECTION ".debug_pubnames"
523 #ifndef ARANGES_SECTION
524 #define ARANGES_SECTION ".debug_aranges"
527 #define TEXT_SECTION ".text"
530 #define DATA_SECTION ".data"
532 #ifndef DATA1_SECTION
533 #define DATA1_SECTION ".data1"
535 #ifndef RODATA_SECTION
536 #define RODATA_SECTION ".rodata"
538 #ifndef RODATA1_SECTION
539 #define RODATA1_SECTION ".rodata1"
542 #define BSS_SECTION ".bss"
545 /* Definitions of defaults for formats and names of various special
546 (artificial) labels which may be generated within this file (when
547 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
549 If necessary, these may be overridden from within your tm.h file,
550 but typically, you should never need to override these.
552 These labels have been hacked (temporarily) so that they all begin with
553 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
554 stock m88k/svr4 assembler, both of which need to see .L at the start of
555 a label in order to prevent that label from going into the linker symbol
556 table). When I get time, I'll have to fix this the right way so that we
557 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
558 but that will require a rather massive set of changes. For the moment,
559 the following definitions out to produce the right results for all svr4
560 and svr3 assemblers. -- rfg
563 #ifndef TEXT_BEGIN_LABEL
564 #define TEXT_BEGIN_LABEL "*.L_text_b"
566 #ifndef TEXT_END_LABEL
567 #define TEXT_END_LABEL "*.L_text_e"
570 #ifndef DATA_BEGIN_LABEL
571 #define DATA_BEGIN_LABEL "*.L_data_b"
573 #ifndef DATA_END_LABEL
574 #define DATA_END_LABEL "*.L_data_e"
577 #ifndef DATA1_BEGIN_LABEL
578 #define DATA1_BEGIN_LABEL "*.L_data1_b"
580 #ifndef DATA1_END_LABEL
581 #define DATA1_END_LABEL "*.L_data1_e"
584 #ifndef RODATA_BEGIN_LABEL
585 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
587 #ifndef RODATA_END_LABEL
588 #define RODATA_END_LABEL "*.L_rodata_e"
591 #ifndef RODATA1_BEGIN_LABEL
592 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
594 #ifndef RODATA1_END_LABEL
595 #define RODATA1_END_LABEL "*.L_rodata1_e"
598 #ifndef BSS_BEGIN_LABEL
599 #define BSS_BEGIN_LABEL "*.L_bss_b"
601 #ifndef BSS_END_LABEL
602 #define BSS_END_LABEL "*.L_bss_e"
605 #ifndef LINE_BEGIN_LABEL
606 #define LINE_BEGIN_LABEL "*.L_line_b"
608 #ifndef LINE_LAST_ENTRY_LABEL
609 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
611 #ifndef LINE_END_LABEL
612 #define LINE_END_LABEL "*.L_line_e"
615 #ifndef DEBUG_BEGIN_LABEL
616 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
618 #ifndef SFNAMES_BEGIN_LABEL
619 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
621 #ifndef SRCINFO_BEGIN_LABEL
622 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
624 #ifndef MACINFO_BEGIN_LABEL
625 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
628 #ifndef DIE_BEGIN_LABEL_FMT
629 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
631 #ifndef DIE_END_LABEL_FMT
632 #define DIE_END_LABEL_FMT "*.L_D%u_e"
634 #ifndef PUB_DIE_LABEL_FMT
635 #define PUB_DIE_LABEL_FMT "*.L_P%u"
637 #ifndef INSN_LABEL_FMT
638 #define INSN_LABEL_FMT "*.L_I%u_%u"
640 #ifndef BLOCK_BEGIN_LABEL_FMT
641 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
643 #ifndef BLOCK_END_LABEL_FMT
644 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
646 #ifndef SS_BEGIN_LABEL_FMT
647 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
649 #ifndef SS_END_LABEL_FMT
650 #define SS_END_LABEL_FMT "*.L_s%u_e"
652 #ifndef EE_BEGIN_LABEL_FMT
653 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
655 #ifndef EE_END_LABEL_FMT
656 #define EE_END_LABEL_FMT "*.L_e%u_e"
658 #ifndef MT_BEGIN_LABEL_FMT
659 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
661 #ifndef MT_END_LABEL_FMT
662 #define MT_END_LABEL_FMT "*.L_t%u_e"
664 #ifndef LOC_BEGIN_LABEL_FMT
665 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
667 #ifndef LOC_END_LABEL_FMT
668 #define LOC_END_LABEL_FMT "*.L_l%u_e"
670 #ifndef BOUND_BEGIN_LABEL_FMT
671 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
673 #ifndef BOUND_END_LABEL_FMT
674 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
676 #ifndef DERIV_BEGIN_LABEL_FMT
677 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
679 #ifndef DERIV_END_LABEL_FMT
680 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
682 #ifndef SL_BEGIN_LABEL_FMT
683 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
685 #ifndef SL_END_LABEL_FMT
686 #define SL_END_LABEL_FMT "*.L_sl%u_e"
688 #ifndef BODY_BEGIN_LABEL_FMT
689 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
691 #ifndef BODY_END_LABEL_FMT
692 #define BODY_END_LABEL_FMT "*.L_b%u_e"
694 #ifndef FUNC_END_LABEL_FMT
695 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
697 #ifndef TYPE_NAME_FMT
698 #define TYPE_NAME_FMT "*.L_T%u"
700 #ifndef DECL_NAME_FMT
701 #define DECL_NAME_FMT "*.L_E%u"
703 #ifndef LINE_CODE_LABEL_FMT
704 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
706 #ifndef SFNAMES_ENTRY_LABEL_FMT
707 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
709 #ifndef LINE_ENTRY_LABEL_FMT
710 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
713 /* Definitions of defaults for various types of primitive assembly language
716 If necessary, these may be overridden from within your tm.h file,
717 but typically, you shouldn't need to override these. */
719 #ifndef ASM_OUTPUT_PUSH_SECTION
720 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
721 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
724 #ifndef ASM_OUTPUT_POP_SECTION
725 #define ASM_OUTPUT_POP_SECTION(FILE) \
726 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
729 #ifndef ASM_OUTPUT_DWARF_DELTA2
730 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
731 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
732 assemble_name (FILE, LABEL1); \
733 fprintf (FILE, "-"); \
734 assemble_name (FILE, LABEL2); \
735 fprintf (FILE, "\n"); \
739 #ifndef ASM_OUTPUT_DWARF_DELTA4
740 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
741 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
742 assemble_name (FILE, LABEL1); \
743 fprintf (FILE, "-"); \
744 assemble_name (FILE, LABEL2); \
745 fprintf (FILE, "\n"); \
749 #ifndef ASM_OUTPUT_DWARF_TAG
750 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
752 fprintf ((FILE), "\t%s\t0x%x", \
753 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
754 if (flag_debug_asm) \
755 fprintf ((FILE), "\t%s %s", \
756 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
757 fputc ('\n', (FILE)); \
761 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
762 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
764 fprintf ((FILE), "\t%s\t0x%x", \
765 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
766 if (flag_debug_asm) \
767 fprintf ((FILE), "\t%s %s", \
768 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
769 fputc ('\n', (FILE)); \
773 #ifndef ASM_OUTPUT_DWARF_STACK_OP
774 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
776 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
777 if (flag_debug_asm) \
778 fprintf ((FILE), "\t%s %s", \
779 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
780 fputc ('\n', (FILE)); \
784 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
785 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
787 fprintf ((FILE), "\t%s\t0x%x", \
788 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
789 if (flag_debug_asm) \
790 fprintf ((FILE), "\t%s %s", \
791 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
792 fputc ('\n', (FILE)); \
796 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
797 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
799 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
800 if (flag_debug_asm) \
801 fprintf ((FILE), "\t%s %s", \
802 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
803 fputc ('\n', (FILE)); \
807 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
808 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
810 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
811 if (flag_debug_asm) \
812 fprintf ((FILE), "\t%s %s", \
813 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
814 fputc ('\n', (FILE)); \
818 #ifndef ASM_OUTPUT_DWARF_ADDR
819 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
820 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
821 assemble_name (FILE, LABEL); \
822 fprintf (FILE, "\n"); \
826 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
827 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
829 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
830 output_addr_const ((FILE), (RTX)); \
831 fputc ('\n', (FILE)); \
835 #ifndef ASM_OUTPUT_DWARF_REF
836 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
837 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
838 assemble_name (FILE, LABEL); \
839 fprintf (FILE, "\n"); \
843 #ifndef ASM_OUTPUT_DWARF_DATA1
844 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
845 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
848 #ifndef ASM_OUTPUT_DWARF_DATA2
849 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
850 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
853 #ifndef ASM_OUTPUT_DWARF_DATA4
854 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
855 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
858 #ifndef ASM_OUTPUT_DWARF_DATA8
859 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
861 if (WORDS_BIG_ENDIAN) \
863 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
864 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
868 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
869 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
874 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
875 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
876 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
877 defined, we call it, then issue the line feed. If not, we supply a
878 default defintion of calling ASM_OUTPUT_ASCII */
880 #ifndef ASM_OUTPUT_DWARF_STRING
881 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
882 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
884 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
885 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
889 /************************ general utility functions **************************/
895 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
896 || ((GET_CODE (rtl) == SUBREG)
897 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
901 type_main_variant (type)
904 type = TYPE_MAIN_VARIANT (type);
906 /* There really should be only one main variant among any group of variants
907 of a given type (and all of the MAIN_VARIANT values for all members of
908 the group should point to that one type) but sometimes the C front-end
909 messes this up for array types, so we work around that bug here. */
911 if (TREE_CODE (type) == ARRAY_TYPE)
913 while (type != TYPE_MAIN_VARIANT (type))
914 type = TYPE_MAIN_VARIANT (type);
920 /* Return non-zero if the given type node represents a tagged type. */
923 is_tagged_type (type)
926 register enum tree_code code = TREE_CODE (type);
928 return (code == RECORD_TYPE || code == UNION_TYPE
929 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
934 register unsigned tag;
938 case TAG_padding: return "TAG_padding";
939 case TAG_array_type: return "TAG_array_type";
940 case TAG_class_type: return "TAG_class_type";
941 case TAG_entry_point: return "TAG_entry_point";
942 case TAG_enumeration_type: return "TAG_enumeration_type";
943 case TAG_formal_parameter: return "TAG_formal_parameter";
944 case TAG_global_subroutine: return "TAG_global_subroutine";
945 case TAG_global_variable: return "TAG_global_variable";
946 case TAG_label: return "TAG_label";
947 case TAG_lexical_block: return "TAG_lexical_block";
948 case TAG_local_variable: return "TAG_local_variable";
949 case TAG_member: return "TAG_member";
950 case TAG_pointer_type: return "TAG_pointer_type";
951 case TAG_reference_type: return "TAG_reference_type";
952 case TAG_compile_unit: return "TAG_compile_unit";
953 case TAG_string_type: return "TAG_string_type";
954 case TAG_structure_type: return "TAG_structure_type";
955 case TAG_subroutine: return "TAG_subroutine";
956 case TAG_subroutine_type: return "TAG_subroutine_type";
957 case TAG_typedef: return "TAG_typedef";
958 case TAG_union_type: return "TAG_union_type";
959 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
960 case TAG_variant: return "TAG_variant";
961 case TAG_common_block: return "TAG_common_block";
962 case TAG_common_inclusion: return "TAG_common_inclusion";
963 case TAG_inheritance: return "TAG_inheritance";
964 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
965 case TAG_module: return "TAG_module";
966 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
967 case TAG_set_type: return "TAG_set_type";
968 case TAG_subrange_type: return "TAG_subrange_type";
969 case TAG_with_stmt: return "TAG_with_stmt";
971 /* GNU extensions. */
973 case TAG_format_label: return "TAG_format_label";
974 case TAG_namelist: return "TAG_namelist";
975 case TAG_function_template: return "TAG_function_template";
976 case TAG_class_template: return "TAG_class_template";
978 default: return "TAG_<unknown>";
983 dwarf_attr_name (attr)
984 register unsigned attr;
988 case AT_sibling: return "AT_sibling";
989 case AT_location: return "AT_location";
990 case AT_name: return "AT_name";
991 case AT_fund_type: return "AT_fund_type";
992 case AT_mod_fund_type: return "AT_mod_fund_type";
993 case AT_user_def_type: return "AT_user_def_type";
994 case AT_mod_u_d_type: return "AT_mod_u_d_type";
995 case AT_ordering: return "AT_ordering";
996 case AT_subscr_data: return "AT_subscr_data";
997 case AT_byte_size: return "AT_byte_size";
998 case AT_bit_offset: return "AT_bit_offset";
999 case AT_bit_size: return "AT_bit_size";
1000 case AT_element_list: return "AT_element_list";
1001 case AT_stmt_list: return "AT_stmt_list";
1002 case AT_low_pc: return "AT_low_pc";
1003 case AT_high_pc: return "AT_high_pc";
1004 case AT_language: return "AT_language";
1005 case AT_member: return "AT_member";
1006 case AT_discr: return "AT_discr";
1007 case AT_discr_value: return "AT_discr_value";
1008 case AT_string_length: return "AT_string_length";
1009 case AT_common_reference: return "AT_common_reference";
1010 case AT_comp_dir: return "AT_comp_dir";
1011 case AT_const_value_string: return "AT_const_value_string";
1012 case AT_const_value_data2: return "AT_const_value_data2";
1013 case AT_const_value_data4: return "AT_const_value_data4";
1014 case AT_const_value_data8: return "AT_const_value_data8";
1015 case AT_const_value_block2: return "AT_const_value_block2";
1016 case AT_const_value_block4: return "AT_const_value_block4";
1017 case AT_containing_type: return "AT_containing_type";
1018 case AT_default_value_addr: return "AT_default_value_addr";
1019 case AT_default_value_data2: return "AT_default_value_data2";
1020 case AT_default_value_data4: return "AT_default_value_data4";
1021 case AT_default_value_data8: return "AT_default_value_data8";
1022 case AT_default_value_string: return "AT_default_value_string";
1023 case AT_friends: return "AT_friends";
1024 case AT_inline: return "AT_inline";
1025 case AT_is_optional: return "AT_is_optional";
1026 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1027 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1028 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1029 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1030 case AT_private: return "AT_private";
1031 case AT_producer: return "AT_producer";
1032 case AT_program: return "AT_program";
1033 case AT_protected: return "AT_protected";
1034 case AT_prototyped: return "AT_prototyped";
1035 case AT_public: return "AT_public";
1036 case AT_pure_virtual: return "AT_pure_virtual";
1037 case AT_return_addr: return "AT_return_addr";
1038 case AT_abstract_origin: return "AT_abstract_origin";
1039 case AT_start_scope: return "AT_start_scope";
1040 case AT_stride_size: return "AT_stride_size";
1041 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1042 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1043 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1044 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1045 case AT_virtual: return "AT_virtual";
1047 /* GNU extensions */
1049 case AT_sf_names: return "AT_sf_names";
1050 case AT_src_info: return "AT_src_info";
1051 case AT_mac_info: return "AT_mac_info";
1052 case AT_src_coords: return "AT_src_coords";
1053 case AT_body_begin: return "AT_body_begin";
1054 case AT_body_end: return "AT_body_end";
1056 default: return "AT_<unknown>";
1061 dwarf_stack_op_name (op)
1062 register unsigned op;
1066 case OP_REG: return "OP_REG";
1067 case OP_BASEREG: return "OP_BASEREG";
1068 case OP_ADDR: return "OP_ADDR";
1069 case OP_CONST: return "OP_CONST";
1070 case OP_DEREF2: return "OP_DEREF2";
1071 case OP_DEREF4: return "OP_DEREF4";
1072 case OP_ADD: return "OP_ADD";
1073 default: return "OP_<unknown>";
1078 dwarf_typemod_name (mod)
1079 register unsigned mod;
1083 case MOD_pointer_to: return "MOD_pointer_to";
1084 case MOD_reference_to: return "MOD_reference_to";
1085 case MOD_const: return "MOD_const";
1086 case MOD_volatile: return "MOD_volatile";
1087 default: return "MOD_<unknown>";
1092 dwarf_fmt_byte_name (fmt)
1093 register unsigned fmt;
1097 case FMT_FT_C_C: return "FMT_FT_C_C";
1098 case FMT_FT_C_X: return "FMT_FT_C_X";
1099 case FMT_FT_X_C: return "FMT_FT_X_C";
1100 case FMT_FT_X_X: return "FMT_FT_X_X";
1101 case FMT_UT_C_C: return "FMT_UT_C_C";
1102 case FMT_UT_C_X: return "FMT_UT_C_X";
1103 case FMT_UT_X_C: return "FMT_UT_X_C";
1104 case FMT_UT_X_X: return "FMT_UT_X_X";
1105 case FMT_ET: return "FMT_ET";
1106 default: return "FMT_<unknown>";
1111 dwarf_fund_type_name (ft)
1112 register unsigned ft;
1116 case FT_char: return "FT_char";
1117 case FT_signed_char: return "FT_signed_char";
1118 case FT_unsigned_char: return "FT_unsigned_char";
1119 case FT_short: return "FT_short";
1120 case FT_signed_short: return "FT_signed_short";
1121 case FT_unsigned_short: return "FT_unsigned_short";
1122 case FT_integer: return "FT_integer";
1123 case FT_signed_integer: return "FT_signed_integer";
1124 case FT_unsigned_integer: return "FT_unsigned_integer";
1125 case FT_long: return "FT_long";
1126 case FT_signed_long: return "FT_signed_long";
1127 case FT_unsigned_long: return "FT_unsigned_long";
1128 case FT_pointer: return "FT_pointer";
1129 case FT_float: return "FT_float";
1130 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1131 case FT_ext_prec_float: return "FT_ext_prec_float";
1132 case FT_complex: return "FT_complex";
1133 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1134 case FT_void: return "FT_void";
1135 case FT_boolean: return "FT_boolean";
1136 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1137 case FT_label: return "FT_label";
1139 /* GNU extensions. */
1141 case FT_long_long: return "FT_long_long";
1142 case FT_signed_long_long: return "FT_signed_long_long";
1143 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1145 case FT_int8: return "FT_int8";
1146 case FT_signed_int8: return "FT_signed_int8";
1147 case FT_unsigned_int8: return "FT_unsigned_int8";
1148 case FT_int16: return "FT_int16";
1149 case FT_signed_int16: return "FT_signed_int16";
1150 case FT_unsigned_int16: return "FT_unsigned_int16";
1151 case FT_int32: return "FT_int32";
1152 case FT_signed_int32: return "FT_signed_int32";
1153 case FT_unsigned_int32: return "FT_unsigned_int32";
1154 case FT_int64: return "FT_int64";
1155 case FT_signed_int64: return "FT_signed_int64";
1156 case FT_unsigned_int64: return "FT_unsigned_int64";
1158 case FT_real32: return "FT_real32";
1159 case FT_real64: return "FT_real64";
1160 case FT_real96: return "FT_real96";
1161 case FT_real128: return "FT_real128";
1163 default: return "FT_<unknown>";
1167 /* Determine the "ultimate origin" of a decl. The decl may be an
1168 inlined instance of an inlined instance of a decl which is local
1169 to an inline function, so we have to trace all of the way back
1170 through the origin chain to find out what sort of node actually
1171 served as the original seed for the given block. */
1174 decl_ultimate_origin (decl)
1177 #ifdef ENABLE_CHECKING
1178 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1179 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1180 most distant ancestor, this should never happen. */
1184 return DECL_ABSTRACT_ORIGIN (decl);
1187 /* Determine the "ultimate origin" of a block. The block may be an
1188 inlined instance of an inlined instance of a block which is local
1189 to an inline function, so we have to trace all of the way back
1190 through the origin chain to find out what sort of node actually
1191 served as the original seed for the given block. */
1194 block_ultimate_origin (block)
1195 register tree block;
1197 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1199 if (immediate_origin == NULL)
1203 register tree ret_val;
1204 register tree lookahead = immediate_origin;
1208 ret_val = lookahead;
1209 lookahead = (TREE_CODE (ret_val) == BLOCK)
1210 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1213 while (lookahead != NULL && lookahead != ret_val);
1218 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1219 of a virtual function may refer to a base class, so we check the 'this'
1223 decl_class_context (decl)
1226 tree context = NULL_TREE;
1227 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1228 context = DECL_CONTEXT (decl);
1230 context = TYPE_MAIN_VARIANT
1231 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1233 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1234 context = NULL_TREE;
1241 output_unsigned_leb128 (value)
1242 register unsigned long value;
1244 register unsigned long orig_value = value;
1248 register unsigned byte = (value & 0x7f);
1251 if (value != 0) /* more bytes to follow */
1253 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1254 if (flag_debug_asm && value == 0)
1255 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1256 ASM_COMMENT_START, orig_value);
1257 fputc ('\n', asm_out_file);
1263 output_signed_leb128 (value)
1264 register long value;
1266 register long orig_value = value;
1267 register int negative = (value < 0);
1272 register unsigned byte = (value & 0x7f);
1276 value |= 0xfe000000; /* manually sign extend */
1277 if (((value == 0) && ((byte & 0x40) == 0))
1278 || ((value == -1) && ((byte & 0x40) == 1)))
1285 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1286 if (flag_debug_asm && more == 0)
1287 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1288 ASM_COMMENT_START, orig_value);
1289 fputc ('\n', asm_out_file);
1295 /**************** utility functions for attribute functions ******************/
1297 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1298 node in question represents the outermost pair of curly braces (i.e.
1299 the "body block") of a function or method.
1301 For any BLOCK node representing a "body block" of a function or method,
1302 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1303 which represents the outermost (function) scope for the function or
1304 method (i.e. the one which includes the formal parameters). The
1305 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1310 is_body_block (stmt)
1313 if (TREE_CODE (stmt) == BLOCK)
1315 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1317 if (TREE_CODE (parent) == BLOCK)
1319 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1321 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1328 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1329 type code for the given type.
1331 This routine must only be called for GCC type nodes that correspond to
1332 Dwarf fundamental types.
1334 The current Dwarf draft specification calls for Dwarf fundamental types
1335 to accurately reflect the fact that a given type was either a "plain"
1336 integral type or an explicitly "signed" integral type. Unfortunately,
1337 we can't always do this, because GCC may already have thrown away the
1338 information about the precise way in which the type was originally
1341 typedef signed int my_type;
1343 struct s { my_type f; };
1345 Since we may be stuck here without enought information to do exactly
1346 what is called for in the Dwarf draft specification, we do the best
1347 that we can under the circumstances and always use the "plain" integral
1348 fundamental type codes for int, short, and long types. That's probably
1349 good enough. The additional accuracy called for in the current DWARF
1350 draft specification is probably never even useful in practice. */
1353 fundamental_type_code (type)
1356 if (TREE_CODE (type) == ERROR_MARK)
1359 switch (TREE_CODE (type))
1368 /* Carefully distinguish all the standard types of C,
1369 without messing up if the language is not C.
1370 Note that we check only for the names that contain spaces;
1371 other names might occur by coincidence in other languages. */
1372 if (TYPE_NAME (type) != 0
1373 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1374 && DECL_NAME (TYPE_NAME (type)) != 0
1375 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1377 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1379 if (!strcmp (name, "unsigned char"))
1380 return FT_unsigned_char;
1381 if (!strcmp (name, "signed char"))
1382 return FT_signed_char;
1383 if (!strcmp (name, "unsigned int"))
1384 return FT_unsigned_integer;
1385 if (!strcmp (name, "short int"))
1387 if (!strcmp (name, "short unsigned int"))
1388 return FT_unsigned_short;
1389 if (!strcmp (name, "long int"))
1391 if (!strcmp (name, "long unsigned int"))
1392 return FT_unsigned_long;
1393 if (!strcmp (name, "long long int"))
1394 return FT_long_long; /* Not grok'ed by svr4 SDB */
1395 if (!strcmp (name, "long long unsigned int"))
1396 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1399 /* Most integer types will be sorted out above, however, for the
1400 sake of special `array index' integer types, the following code
1401 is also provided. */
1403 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1404 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1406 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1407 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1409 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1410 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1412 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1413 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1415 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1416 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1418 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1419 if (TYPE_PRECISION (type) == 1)
1425 /* Carefully distinguish all the standard types of C,
1426 without messing up if the language is not C. */
1427 if (TYPE_NAME (type) != 0
1428 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1429 && DECL_NAME (TYPE_NAME (type)) != 0
1430 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1432 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1434 /* Note that here we can run afowl of a serious bug in "classic"
1435 svr4 SDB debuggers. They don't seem to understand the
1436 FT_ext_prec_float type (even though they should). */
1438 if (!strcmp (name, "long double"))
1439 return FT_ext_prec_float;
1442 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1444 /* On the SH, when compiling with -m3e or -m4-single-only, both
1445 float and double are 32 bits. But since the debugger doesn't
1446 know about the subtarget, it always thinks double is 64 bits.
1447 So we have to tell the debugger that the type is float to
1448 make the output of the 'print' command etc. readable. */
1449 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1451 return FT_dbl_prec_float;
1453 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1456 /* Note that here we can run afowl of a serious bug in "classic"
1457 svr4 SDB debuggers. They don't seem to understand the
1458 FT_ext_prec_float type (even though they should). */
1460 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1461 return FT_ext_prec_float;
1465 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1468 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1471 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1474 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1479 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1480 the Dwarf "root" type for the given input type. The Dwarf "root" type
1481 of a given type is generally the same as the given type, except that if
1482 the given type is a pointer or reference type, then the root type of
1483 the given type is the root type of the "basis" type for the pointer or
1484 reference type. (This definition of the "root" type is recursive.)
1485 Also, the root type of a `const' qualified type or a `volatile'
1486 qualified type is the root type of the given type without the
1490 root_type_1 (type, count)
1494 /* Give up after searching 1000 levels, in case this is a recursive
1495 pointer type. Such types are possible in Ada, but it is not possible
1496 to represent them in DWARF1 debug info. */
1498 return error_mark_node;
1500 switch (TREE_CODE (type))
1503 return error_mark_node;
1506 case REFERENCE_TYPE:
1507 return root_type_1 (TREE_TYPE (type), count+1);
1518 type = root_type_1 (type, 0);
1519 if (type != error_mark_node)
1520 type = type_main_variant (type);
1524 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1525 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1528 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1530 register int decl_const;
1531 register int decl_volatile;
1534 if (TREE_CODE (type) == ERROR_MARK)
1537 /* Give up after searching 1000 levels, in case this is a recursive
1538 pointer type. Such types are possible in Ada, but it is not possible
1539 to represent them in DWARF1 debug info. */
1543 if (TYPE_READONLY (type) || decl_const)
1544 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1545 if (TYPE_VOLATILE (type) || decl_volatile)
1546 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1547 switch (TREE_CODE (type))
1550 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1551 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1554 case REFERENCE_TYPE:
1555 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1556 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1566 write_modifier_bytes (type, decl_const, decl_volatile)
1568 register int decl_const;
1569 register int decl_volatile;
1571 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1574 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1575 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1578 type_is_fundamental (type)
1581 switch (TREE_CODE (type))
1596 case QUAL_UNION_TYPE:
1601 case REFERENCE_TYPE:
1613 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1614 equate directive which will associate a symbolic name with the current DIE.
1616 The name used is an artificial label generated from the DECL_UID number
1617 associated with the given decl node. The name it gets equated to is the
1618 symbolic label that we (previously) output at the start of the DIE that
1619 we are currently generating.
1621 Calling this function while generating some "decl related" form of DIE
1622 makes it possible to later refer to the DIE which represents the given
1623 decl simply by re-generating the symbolic name from the ..._DECL node's
1627 equate_decl_number_to_die_number (decl)
1630 /* In the case where we are generating a DIE for some ..._DECL node
1631 which represents either some inline function declaration or some
1632 entity declared within an inline function declaration/definition,
1633 setup a symbolic name for the current DIE so that we have a name
1634 for this DIE that we can easily refer to later on within
1635 AT_abstract_origin attributes. */
1637 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1638 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1640 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1641 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1642 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1645 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1646 equate directive which will associate a symbolic name with the current DIE.
1648 The name used is an artificial label generated from the TYPE_UID number
1649 associated with the given type node. The name it gets equated to is the
1650 symbolic label that we (previously) output at the start of the DIE that
1651 we are currently generating.
1653 Calling this function while generating some "type related" form of DIE
1654 makes it easy to later refer to the DIE which represents the given type
1655 simply by re-generating the alternative name from the ..._TYPE node's
1659 equate_type_number_to_die_number (type)
1662 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1663 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1665 /* We are generating a DIE to represent the main variant of this type
1666 (i.e the type without any const or volatile qualifiers) so in order
1667 to get the equate to come out right, we need to get the main variant
1670 type = type_main_variant (type);
1672 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1673 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1674 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1678 output_reg_number (rtl)
1681 register unsigned regno = REGNO (rtl);
1683 if (regno >= FIRST_PSEUDO_REGISTER)
1685 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1689 fprintf (asm_out_file, "\t%s\t0x%x",
1690 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1693 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1694 PRINT_REG (rtl, 0, asm_out_file);
1696 fputc ('\n', asm_out_file);
1699 /* The following routine is a nice and simple transducer. It converts the
1700 RTL for a variable or parameter (resident in memory) into an equivalent
1701 Dwarf representation of a mechanism for getting the address of that same
1702 variable onto the top of a hypothetical "address evaluation" stack.
1704 When creating memory location descriptors, we are effectively trans-
1705 forming the RTL for a memory-resident object into its Dwarf postfix
1706 expression equivalent. This routine just recursively descends an
1707 RTL tree, turning it into Dwarf postfix code as it goes. */
1710 output_mem_loc_descriptor (rtl)
1713 /* Note that for a dynamically sized array, the location we will
1714 generate a description of here will be the lowest numbered location
1715 which is actually within the array. That's *not* necessarily the
1716 same as the zeroth element of the array. */
1718 switch (GET_CODE (rtl))
1722 /* The case of a subreg may arise when we have a local (register)
1723 variable or a formal (register) parameter which doesn't quite
1724 fill up an entire register. For now, just assume that it is
1725 legitimate to make the Dwarf info refer to the whole register
1726 which contains the given subreg. */
1728 rtl = XEXP (rtl, 0);
1733 /* Whenever a register number forms a part of the description of
1734 the method for calculating the (dynamic) address of a memory
1735 resident object, DWARF rules require the register number to
1736 be referred to as a "base register". This distinction is not
1737 based in any way upon what category of register the hardware
1738 believes the given register belongs to. This is strictly
1739 DWARF terminology we're dealing with here.
1741 Note that in cases where the location of a memory-resident data
1742 object could be expressed as:
1744 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1746 the actual DWARF location descriptor that we generate may just
1747 be OP_BASEREG (basereg). This may look deceptively like the
1748 object in question was allocated to a register (rather than
1749 in memory) so DWARF consumers need to be aware of the subtle
1750 distinction between OP_REG and OP_BASEREG. */
1752 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1753 output_reg_number (rtl);
1757 output_mem_loc_descriptor (XEXP (rtl, 0));
1758 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1763 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1764 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1768 output_mem_loc_descriptor (XEXP (rtl, 0));
1769 output_mem_loc_descriptor (XEXP (rtl, 1));
1770 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1774 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1775 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1779 /* If a pseudo-reg is optimized away, it is possible for it to
1780 be replaced with a MEM containing a multiply. Use a GNU extension
1782 output_mem_loc_descriptor (XEXP (rtl, 0));
1783 output_mem_loc_descriptor (XEXP (rtl, 1));
1784 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1792 /* Output a proper Dwarf location descriptor for a variable or parameter
1793 which is either allocated in a register or in a memory location. For
1794 a register, we just generate an OP_REG and the register number. For a
1795 memory location we provide a Dwarf postfix expression describing how to
1796 generate the (dynamic) address of the object onto the address stack. */
1799 output_loc_descriptor (rtl)
1802 switch (GET_CODE (rtl))
1806 /* The case of a subreg may arise when we have a local (register)
1807 variable or a formal (register) parameter which doesn't quite
1808 fill up an entire register. For now, just assume that it is
1809 legitimate to make the Dwarf info refer to the whole register
1810 which contains the given subreg. */
1812 rtl = XEXP (rtl, 0);
1816 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1817 output_reg_number (rtl);
1821 output_mem_loc_descriptor (XEXP (rtl, 0));
1825 abort (); /* Should never happen */
1829 /* Given a tree node describing an array bound (either lower or upper)
1830 output a representation for that bound. */
1833 output_bound_representation (bound, dim_num, u_or_l)
1834 register tree bound;
1835 register unsigned dim_num; /* For multi-dimensional arrays. */
1836 register char u_or_l; /* Designates upper or lower bound. */
1838 switch (TREE_CODE (bound))
1844 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1847 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1848 (unsigned) TREE_INT_CST_LOW (bound));
1853 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1854 SAVE_EXPR nodes, in which case we can do something, or as
1855 an expression, which we cannot represent. */
1857 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1858 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1860 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1861 current_dienum, dim_num, u_or_l);
1863 sprintf (end_label, BOUND_END_LABEL_FMT,
1864 current_dienum, dim_num, u_or_l);
1866 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1867 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1869 /* If optimization is turned on, the SAVE_EXPRs that describe
1870 how to access the upper bound values are essentially bogus.
1871 They only describe (at best) how to get at these values at
1872 the points in the generated code right after they have just
1873 been computed. Worse yet, in the typical case, the upper
1874 bound values will not even *be* computed in the optimized
1875 code, so these SAVE_EXPRs are entirely bogus.
1877 In order to compensate for this fact, we check here to see
1878 if optimization is enabled, and if so, we effectively create
1879 an empty location description for the (unknown and unknowable)
1882 This should not cause too much trouble for existing (stupid?)
1883 debuggers because they have to deal with empty upper bounds
1884 location descriptions anyway in order to be able to deal with
1885 incomplete array types.
1887 Of course an intelligent debugger (GDB?) should be able to
1888 comprehend that a missing upper bound specification in a
1889 array type used for a storage class `auto' local array variable
1890 indicates that the upper bound is both unknown (at compile-
1891 time) and unknowable (at run-time) due to optimization. */
1895 while (TREE_CODE (bound) == NOP_EXPR
1896 || TREE_CODE (bound) == CONVERT_EXPR)
1897 bound = TREE_OPERAND (bound, 0);
1899 if (TREE_CODE (bound) == SAVE_EXPR)
1900 output_loc_descriptor
1901 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1904 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1911 /* Recursive function to output a sequence of value/name pairs for
1912 enumeration constants in reversed order. This is called from
1913 enumeration_type_die. */
1916 output_enumeral_list (link)
1921 output_enumeral_list (TREE_CHAIN (link));
1922 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1923 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1924 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
1925 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1929 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1930 which is not less than the value itself. */
1932 static inline unsigned
1933 ceiling (value, boundary)
1934 register unsigned value;
1935 register unsigned boundary;
1937 return (((value + boundary - 1) / boundary) * boundary);
1940 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1941 pointer to the declared type for the relevant field variable, or return
1942 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1950 if (TREE_CODE (decl) == ERROR_MARK)
1951 return integer_type_node;
1953 type = DECL_BIT_FIELD_TYPE (decl);
1955 type = TREE_TYPE (decl);
1959 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1960 node, return the alignment in bits for the type, or else return
1961 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1963 static inline unsigned
1964 simple_type_align_in_bits (type)
1967 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1970 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1971 node, return the size in bits for the type if it is a constant, or
1972 else return the alignment for the type if the type's size is not
1973 constant, or else return BITS_PER_WORD if the type actually turns out
1974 to be an ERROR_MARK node. */
1976 static inline unsigned
1977 simple_type_size_in_bits (type)
1980 if (TREE_CODE (type) == ERROR_MARK)
1981 return BITS_PER_WORD;
1984 register tree type_size_tree = TYPE_SIZE (type);
1986 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1987 return TYPE_ALIGN (type);
1989 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1993 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1994 return the byte offset of the lowest addressed byte of the "containing
1995 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1996 mine what that offset is, either because the argument turns out to be a
1997 pointer to an ERROR_MARK node, or because the offset is actually variable.
1998 (We can't handle the latter case just yet.) */
2001 field_byte_offset (decl)
2004 register unsigned type_align_in_bytes;
2005 register unsigned type_align_in_bits;
2006 register unsigned type_size_in_bits;
2007 register unsigned object_offset_in_align_units;
2008 register unsigned object_offset_in_bits;
2009 register unsigned object_offset_in_bytes;
2011 register tree bitpos_tree;
2012 register tree field_size_tree;
2013 register unsigned bitpos_int;
2014 register unsigned deepest_bitpos;
2015 register unsigned field_size_in_bits;
2017 if (TREE_CODE (decl) == ERROR_MARK)
2020 if (TREE_CODE (decl) != FIELD_DECL)
2023 type = field_type (decl);
2025 bitpos_tree = DECL_FIELD_BITPOS (decl);
2026 field_size_tree = DECL_SIZE (decl);
2028 /* We cannot yet cope with fields whose positions or sizes are variable,
2029 so for now, when we see such things, we simply return 0. Someday,
2030 we may be able to handle such cases, but it will be damn difficult. */
2032 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2034 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2036 if (TREE_CODE (field_size_tree) != INTEGER_CST)
2038 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
2040 type_size_in_bits = simple_type_size_in_bits (type);
2042 type_align_in_bits = simple_type_align_in_bits (type);
2043 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2045 /* Note that the GCC front-end doesn't make any attempt to keep track
2046 of the starting bit offset (relative to the start of the containing
2047 structure type) of the hypothetical "containing object" for a bit-
2048 field. Thus, when computing the byte offset value for the start of
2049 the "containing object" of a bit-field, we must deduce this infor-
2052 This can be rather tricky to do in some cases. For example, handling
2053 the following structure type definition when compiling for an i386/i486
2054 target (which only aligns long long's to 32-bit boundaries) can be very
2059 long long field2:31;
2062 Fortunately, there is a simple rule-of-thumb which can be used in such
2063 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2064 the structure shown above. It decides to do this based upon one simple
2065 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2066 taining object" for each bit-field at the first (i.e. lowest addressed)
2067 legitimate alignment boundary (based upon the required minimum alignment
2068 for the declared type of the field) which it can possibly use, subject
2069 to the condition that there is still enough available space remaining
2070 in the containing object (when allocated at the selected point) to
2071 fully accommodate all of the bits of the bit-field itself.
2073 This simple rule makes it obvious why GCC allocates 8 bytes for each
2074 object of the structure type shown above. When looking for a place to
2075 allocate the "containing object" for `field2', the compiler simply tries
2076 to allocate a 64-bit "containing object" at each successive 32-bit
2077 boundary (starting at zero) until it finds a place to allocate that 64-
2078 bit field such that at least 31 contiguous (and previously unallocated)
2079 bits remain within that selected 64 bit field. (As it turns out, for
2080 the example above, the compiler finds that it is OK to allocate the
2081 "containing object" 64-bit field at bit-offset zero within the
2084 Here we attempt to work backwards from the limited set of facts we're
2085 given, and we try to deduce from those facts, where GCC must have
2086 believed that the containing object started (within the structure type).
2088 The value we deduce is then used (by the callers of this routine) to
2089 generate AT_location and AT_bit_offset attributes for fields (both
2090 bit-fields and, in the case of AT_location, regular fields as well).
2093 /* Figure out the bit-distance from the start of the structure to the
2094 "deepest" bit of the bit-field. */
2095 deepest_bitpos = bitpos_int + field_size_in_bits;
2097 /* This is the tricky part. Use some fancy footwork to deduce where the
2098 lowest addressed bit of the containing object must be. */
2099 object_offset_in_bits
2100 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2102 /* Compute the offset of the containing object in "alignment units". */
2103 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2105 /* Compute the offset of the containing object in bytes. */
2106 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2108 /* The above code assumes that the field does not cross an alignment
2109 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2110 or if the structure is packed. If this happens, then we get an object
2111 which starts after the bitfield, which means that the bit offset is
2112 negative. Gdb fails when given negative bit offsets. We avoid this
2113 by recomputing using the first bit of the bitfield. This will give
2114 us an object which does not completely contain the bitfield, but it
2115 will be aligned, and it will contain the first bit of the bitfield.
2117 However, only do this for a BYTES_BIG_ENDIAN target. For a
2118 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2119 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2120 then we end up computing the object byte offset for the wrong word of the
2121 desired bitfield, which in turn causes the field offset to be negative
2122 in bit_offset_attribute. */
2123 if (BYTES_BIG_ENDIAN
2124 && object_offset_in_bits > bitpos_int)
2126 deepest_bitpos = bitpos_int + 1;
2127 object_offset_in_bits
2128 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2129 object_offset_in_align_units = (object_offset_in_bits
2130 / type_align_in_bits);
2131 object_offset_in_bytes = (object_offset_in_align_units
2132 * type_align_in_bytes);
2135 return object_offset_in_bytes;
2138 /****************************** attributes *********************************/
2140 /* The following routines are responsible for writing out the various types
2141 of Dwarf attributes (and any following data bytes associated with them).
2142 These routines are listed in order based on the numerical codes of their
2143 associated attributes. */
2145 /* Generate an AT_sibling attribute. */
2148 sibling_attribute ()
2150 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2152 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2153 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2154 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2157 /* Output the form of location attributes suitable for whole variables and
2158 whole parameters. Note that the location attributes for struct fields
2159 are generated by the routine `data_member_location_attribute' below. */
2162 location_attribute (rtl)
2165 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2166 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2168 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2169 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2170 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2171 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2172 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2174 /* Handle a special case. If we are about to output a location descriptor
2175 for a variable or parameter which has been optimized out of existence,
2176 don't do that. Instead we output a zero-length location descriptor
2177 value as part of the location attribute.
2179 A variable which has been optimized out of existence will have a
2180 DECL_RTL value which denotes a pseudo-reg.
2182 Currently, in some rare cases, variables can have DECL_RTL values
2183 which look like (MEM (REG pseudo-reg#)). These cases are due to
2184 bugs elsewhere in the compiler. We treat such cases
2185 as if the variable(s) in question had been optimized out of existence.
2187 Note that in all cases where we wish to express the fact that a
2188 variable has been optimized out of existence, we do not simply
2189 suppress the generation of the entire location attribute because
2190 the absence of a location attribute in certain kinds of DIEs is
2191 used to indicate something else entirely... i.e. that the DIE
2192 represents an object declaration, but not a definition. So saith
2196 if (! is_pseudo_reg (rtl)
2197 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2198 output_loc_descriptor (rtl);
2200 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2203 /* Output the specialized form of location attribute used for data members
2204 of struct and union types.
2206 In the special case of a FIELD_DECL node which represents a bit-field,
2207 the "offset" part of this special location descriptor must indicate the
2208 distance in bytes from the lowest-addressed byte of the containing
2209 struct or union type to the lowest-addressed byte of the "containing
2210 object" for the bit-field. (See the `field_byte_offset' function above.)
2212 For any given bit-field, the "containing object" is a hypothetical
2213 object (of some integral or enum type) within which the given bit-field
2214 lives. The type of this hypothetical "containing object" is always the
2215 same as the declared type of the individual bit-field itself (for GCC
2216 anyway... the DWARF spec doesn't actually mandate this).
2218 Note that it is the size (in bytes) of the hypothetical "containing
2219 object" which will be given in the AT_byte_size attribute for this
2220 bit-field. (See the `byte_size_attribute' function below.) It is
2221 also used when calculating the value of the AT_bit_offset attribute.
2222 (See the `bit_offset_attribute' function below.) */
2225 data_member_location_attribute (t)
2228 register unsigned object_offset_in_bytes;
2229 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2230 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2232 if (TREE_CODE (t) == TREE_VEC)
2233 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2235 object_offset_in_bytes = field_byte_offset (t);
2237 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2238 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2239 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2240 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2241 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2242 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2243 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2244 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2245 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2248 /* Output an AT_const_value attribute for a variable or a parameter which
2249 does not have a "location" either in memory or in a register. These
2250 things can arise in GNU C when a constant is passed as an actual
2251 parameter to an inlined function. They can also arise in C++ where
2252 declared constants do not necessarily get memory "homes". */
2255 const_value_attribute (rtl)
2258 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2259 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2261 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2262 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2263 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2264 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2265 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2267 switch (GET_CODE (rtl))
2270 /* Note that a CONST_INT rtx could represent either an integer or
2271 a floating-point constant. A CONST_INT is used whenever the
2272 constant will fit into a single word. In all such cases, the
2273 original mode of the constant value is wiped out, and the
2274 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2275 precise mode information for these constants, we always just
2276 output them using 4 bytes. */
2278 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2282 /* Note that a CONST_DOUBLE rtx could represent either an integer
2283 or a floating-point constant. A CONST_DOUBLE is used whenever
2284 the constant requires more than one word in order to be adequately
2285 represented. In all such cases, the original mode of the constant
2286 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2287 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2289 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2290 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2291 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2295 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2301 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2305 /* In cases where an inlined instance of an inline function is passed
2306 the address of an `auto' variable (which is local to the caller)
2307 we can get a situation where the DECL_RTL of the artificial
2308 local variable (for the inlining) which acts as a stand-in for
2309 the corresponding formal parameter (of the inline function)
2310 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2311 This is not exactly a compile-time constant expression, but it
2312 isn't the address of the (artificial) local variable either.
2313 Rather, it represents the *value* which the artificial local
2314 variable always has during its lifetime. We currently have no
2315 way to represent such quasi-constant values in Dwarf, so for now
2316 we just punt and generate an AT_const_value attribute with form
2317 FORM_BLOCK4 and a length of zero. */
2321 abort (); /* No other kinds of rtx should be possible here. */
2324 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2327 /* Generate *either* an AT_location attribute or else an AT_const_value
2328 data attribute for a variable or a parameter. We generate the
2329 AT_const_value attribute only in those cases where the given
2330 variable or parameter does not have a true "location" either in
2331 memory or in a register. This can happen (for example) when a
2332 constant is passed as an actual argument in a call to an inline
2333 function. (It's possible that these things can crop up in other
2334 ways also.) Note that one type of constant value which can be
2335 passed into an inlined function is a constant pointer. This can
2336 happen for example if an actual argument in an inlined function
2337 call evaluates to a compile-time constant address. */
2340 location_or_const_value_attribute (decl)
2345 if (TREE_CODE (decl) == ERROR_MARK)
2348 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2350 /* Should never happen. */
2355 /* Here we have to decide where we are going to say the parameter "lives"
2356 (as far as the debugger is concerned). We only have a couple of choices.
2357 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2358 normally indicates where the parameter lives during most of the activa-
2359 tion of the function. If optimization is enabled however, this could
2360 be either NULL or else a pseudo-reg. Both of those cases indicate that
2361 the parameter doesn't really live anywhere (as far as the code generation
2362 parts of GCC are concerned) during most of the function's activation.
2363 That will happen (for example) if the parameter is never referenced
2364 within the function.
2366 We could just generate a location descriptor here for all non-NULL
2367 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2368 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2369 cases where DECL_RTL is NULL or is a pseudo-reg.
2371 Note however that we can only get away with using DECL_INCOMING_RTL as
2372 a backup substitute for DECL_RTL in certain limited cases. In cases
2373 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2374 we can be sure that the parameter was passed using the same type as it
2375 is declared to have within the function, and that its DECL_INCOMING_RTL
2376 points us to a place where a value of that type is passed. In cases
2377 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2378 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2379 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2380 points us to a value of some type which is *different* from the type
2381 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2382 to generate a location attribute in such cases, the debugger would
2383 end up (for example) trying to fetch a `float' from a place which
2384 actually contains the first part of a `double'. That would lead to
2385 really incorrect and confusing output at debug-time, and we don't
2386 want that now do we?
2388 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2389 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2390 couple of cute exceptions however. On little-endian machines we can
2391 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2392 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2393 an integral type which is smaller than TREE_TYPE(decl). These cases
2394 arise when (on a little-endian machine) a non-prototyped function has
2395 a parameter declared to be of type `short' or `char'. In such cases,
2396 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2397 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2398 passed `int' value. If the debugger then uses that address to fetch a
2399 `short' or a `char' (on a little-endian machine) the result will be the
2400 correct data, so we allow for such exceptional cases below.
2402 Note that our goal here is to describe the place where the given formal
2403 parameter lives during most of the function's activation (i.e. between
2404 the end of the prologue and the start of the epilogue). We'll do that
2405 as best as we can. Note however that if the given formal parameter is
2406 modified sometime during the execution of the function, then a stack
2407 backtrace (at debug-time) will show the function as having been called
2408 with the *new* value rather than the value which was originally passed
2409 in. This happens rarely enough that it is not a major problem, but it
2410 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2411 may generate two additional attributes for any given TAG_formal_parameter
2412 DIE which will describe the "passed type" and the "passed location" for
2413 the given formal parameter in addition to the attributes we now generate
2414 to indicate the "declared type" and the "active location" for each
2415 parameter. This additional set of attributes could be used by debuggers
2416 for stack backtraces.
2418 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2419 can be NULL also. This happens (for example) for inlined-instances of
2420 inline function formal parameters which are never referenced. This really
2421 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2422 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2423 these values for inlined instances of inline function parameters, so
2424 when we see such cases, we are just out-of-luck for the time
2425 being (until integrate.c gets fixed).
2428 /* Use DECL_RTL as the "location" unless we find something better. */
2429 rtl = DECL_RTL (decl);
2431 if (TREE_CODE (decl) == PARM_DECL)
2432 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2434 /* This decl represents a formal parameter which was optimized out. */
2435 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2436 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2438 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2439 *all* cases where (rtl == NULL_RTX) just below. */
2441 if (declared_type == passed_type)
2442 rtl = DECL_INCOMING_RTL (decl);
2443 else if (! BYTES_BIG_ENDIAN)
2444 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2445 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2446 rtl = DECL_INCOMING_RTL (decl);
2449 if (rtl == NULL_RTX)
2452 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2453 #ifdef LEAF_REG_REMAP
2454 if (current_function_uses_only_leaf_regs)
2455 leaf_renumber_regs_insn (rtl);
2458 switch (GET_CODE (rtl))
2461 /* The address of a variable that was optimized away; don't emit
2471 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2472 const_value_attribute (rtl);
2478 location_attribute (rtl);
2482 /* ??? CONCAT is used for complex variables, which may have the real
2483 part stored in one place and the imag part stored somewhere else.
2484 DWARF1 has no way to describe a variable that lives in two different
2485 places, so we just describe where the first part lives, and hope that
2486 the second part is stored after it. */
2487 location_attribute (XEXP (rtl, 0));
2491 abort (); /* Should never happen. */
2495 /* Generate an AT_name attribute given some string value to be included as
2496 the value of the attribute. */
2499 name_attribute (name_string)
2500 register char *name_string;
2502 if (name_string && *name_string)
2504 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2505 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2510 fund_type_attribute (ft_code)
2511 register unsigned ft_code;
2513 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2514 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2518 mod_fund_type_attribute (type, decl_const, decl_volatile)
2520 register int decl_const;
2521 register int decl_volatile;
2523 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2524 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2526 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2527 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2528 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2529 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2530 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2531 write_modifier_bytes (type, decl_const, decl_volatile);
2532 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2533 fundamental_type_code (root_type (type)));
2534 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2538 user_def_type_attribute (type)
2541 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2543 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2544 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2545 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2549 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2551 register int decl_const;
2552 register int decl_volatile;
2554 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2555 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2556 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2558 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2559 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2560 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2561 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2562 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2563 write_modifier_bytes (type, decl_const, decl_volatile);
2564 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2565 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2566 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2569 #ifdef USE_ORDERING_ATTRIBUTE
2571 ordering_attribute (ordering)
2572 register unsigned ordering;
2574 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2575 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2577 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2579 /* Note that the block of subscript information for an array type also
2580 includes information about the element type of type given array type. */
2583 subscript_data_attribute (type)
2586 register unsigned dimension_number;
2587 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2588 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2590 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2591 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2592 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2593 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2594 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2596 /* The GNU compilers represent multidimensional array types as sequences
2597 of one dimensional array types whose element types are themselves array
2598 types. Here we squish that down, so that each multidimensional array
2599 type gets only one array_type DIE in the Dwarf debugging info. The
2600 draft Dwarf specification say that we are allowed to do this kind
2601 of compression in C (because there is no difference between an
2602 array or arrays and a multidimensional array in C) but for other
2603 source languages (e.g. Ada) we probably shouldn't do this. */
2605 for (dimension_number = 0;
2606 TREE_CODE (type) == ARRAY_TYPE;
2607 type = TREE_TYPE (type), dimension_number++)
2609 register tree domain = TYPE_DOMAIN (type);
2611 /* Arrays come in three flavors. Unspecified bounds, fixed
2612 bounds, and (in GNU C only) variable bounds. Handle all
2613 three forms here. */
2617 /* We have an array type with specified bounds. */
2619 register tree lower = TYPE_MIN_VALUE (domain);
2620 register tree upper = TYPE_MAX_VALUE (domain);
2622 /* Handle only fundamental types as index types for now. */
2624 if (! type_is_fundamental (domain))
2627 /* Output the representation format byte for this dimension. */
2629 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2630 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2631 (upper && TREE_CODE (upper) == INTEGER_CST)));
2633 /* Output the index type for this dimension. */
2635 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2636 fundamental_type_code (domain));
2638 /* Output the representation for the lower bound. */
2640 output_bound_representation (lower, dimension_number, 'l');
2642 /* Output the representation for the upper bound. */
2644 output_bound_representation (upper, dimension_number, 'u');
2648 /* We have an array type with an unspecified length. For C and
2649 C++ we can assume that this really means that (a) the index
2650 type is an integral type, and (b) the lower bound is zero.
2651 Note that Dwarf defines the representation of an unspecified
2652 (upper) bound as being a zero-length location description. */
2654 /* Output the array-bounds format byte. */
2656 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2658 /* Output the (assumed) index type. */
2660 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2662 /* Output the (assumed) lower bound (constant) value. */
2664 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2666 /* Output the (empty) location description for the upper bound. */
2668 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2672 /* Output the prefix byte that says that the element type is coming up. */
2674 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2676 /* Output a representation of the type of the elements of this array type. */
2678 type_attribute (type, 0, 0);
2680 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2684 byte_size_attribute (tree_node)
2685 register tree tree_node;
2687 register unsigned size;
2689 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2690 switch (TREE_CODE (tree_node))
2699 case QUAL_UNION_TYPE:
2701 size = int_size_in_bytes (tree_node);
2705 /* For a data member of a struct or union, the AT_byte_size is
2706 generally given as the number of bytes normally allocated for
2707 an object of the *declared* type of the member itself. This
2708 is true even for bit-fields. */
2709 size = simple_type_size_in_bits (field_type (tree_node))
2717 /* Note that `size' might be -1 when we get to this point. If it
2718 is, that indicates that the byte size of the entity in question
2719 is variable. We have no good way of expressing this fact in Dwarf
2720 at the present time, so just let the -1 pass on through. */
2722 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2725 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2726 which specifies the distance in bits from the highest order bit of the
2727 "containing object" for the bit-field to the highest order bit of the
2730 For any given bit-field, the "containing object" is a hypothetical
2731 object (of some integral or enum type) within which the given bit-field
2732 lives. The type of this hypothetical "containing object" is always the
2733 same as the declared type of the individual bit-field itself.
2735 The determination of the exact location of the "containing object" for
2736 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2739 Note that it is the size (in bytes) of the hypothetical "containing
2740 object" which will be given in the AT_byte_size attribute for this
2741 bit-field. (See `byte_size_attribute' above.) */
2744 bit_offset_attribute (decl)
2747 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2748 register tree type = DECL_BIT_FIELD_TYPE (decl);
2749 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2750 register unsigned bitpos_int;
2751 register unsigned highest_order_object_bit_offset;
2752 register unsigned highest_order_field_bit_offset;
2753 register unsigned bit_offset;
2755 /* Must be a bit field. */
2757 || TREE_CODE (decl) != FIELD_DECL)
2760 /* We can't yet handle bit-fields whose offsets are variable, so if we
2761 encounter such things, just return without generating any attribute
2764 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2766 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2768 /* Note that the bit offset is always the distance (in bits) from the
2769 highest-order bit of the "containing object" to the highest-order
2770 bit of the bit-field itself. Since the "high-order end" of any
2771 object or field is different on big-endian and little-endian machines,
2772 the computation below must take account of these differences. */
2774 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2775 highest_order_field_bit_offset = bitpos_int;
2777 if (! BYTES_BIG_ENDIAN)
2779 highest_order_field_bit_offset
2780 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2782 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2787 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2788 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2790 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2791 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2794 /* For a FIELD_DECL node which represents a bit field, output an attribute
2795 which specifies the length in bits of the given field. */
2798 bit_size_attribute (decl)
2801 /* Must be a field and a bit field. */
2802 if (TREE_CODE (decl) != FIELD_DECL
2803 || ! DECL_BIT_FIELD_TYPE (decl))
2806 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2807 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2808 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2811 /* The following routine outputs the `element_list' attribute for enumeration
2812 type DIEs. The element_lits attribute includes the names and values of
2813 all of the enumeration constants associated with the given enumeration
2817 element_list_attribute (element)
2818 register tree element;
2820 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2821 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2823 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2824 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2825 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2826 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2827 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2829 /* Here we output a list of value/name pairs for each enumeration constant
2830 defined for this enumeration type (as required), but we do it in REVERSE
2831 order. The order is the one required by the draft #5 Dwarf specification
2832 published by the UI/PLSIG. */
2834 output_enumeral_list (element); /* Recursively output the whole list. */
2836 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2839 /* Generate an AT_stmt_list attribute. These are normally present only in
2840 DIEs with a TAG_compile_unit tag. */
2843 stmt_list_attribute (label)
2844 register char *label;
2846 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2847 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2848 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2851 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2852 for a subroutine DIE. */
2855 low_pc_attribute (asm_low_label)
2856 register char *asm_low_label;
2858 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2859 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2862 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2866 high_pc_attribute (asm_high_label)
2867 register char *asm_high_label;
2869 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2870 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2873 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2876 body_begin_attribute (asm_begin_label)
2877 register char *asm_begin_label;
2879 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2880 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2883 /* Generate an AT_body_end attribute for a subroutine DIE. */
2886 body_end_attribute (asm_end_label)
2887 register char *asm_end_label;
2889 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2890 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2893 /* Generate an AT_language attribute given a LANG value. These attributes
2894 are used only within TAG_compile_unit DIEs. */
2897 language_attribute (language_code)
2898 register unsigned language_code;
2900 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2901 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2905 member_attribute (context)
2906 register tree context;
2908 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2910 /* Generate this attribute only for members in C++. */
2912 if (context != NULL && is_tagged_type (context))
2914 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2915 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2916 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2922 string_length_attribute (upper_bound)
2923 register tree upper_bound;
2925 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2926 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2928 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2929 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2930 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2931 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2932 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2933 output_bound_representation (upper_bound, 0, 'u');
2934 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2939 comp_dir_attribute (dirname)
2940 register char *dirname;
2942 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2943 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
2947 sf_names_attribute (sf_names_start_label)
2948 register char *sf_names_start_label;
2950 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2951 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2952 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2956 src_info_attribute (src_info_start_label)
2957 register char *src_info_start_label;
2959 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2960 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2961 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2965 mac_info_attribute (mac_info_start_label)
2966 register char *mac_info_start_label;
2968 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2969 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2970 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2974 prototyped_attribute (func_type)
2975 register tree func_type;
2977 if ((strcmp (language_string, "GNU C") == 0)
2978 && (TYPE_ARG_TYPES (func_type) != NULL))
2980 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2981 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2986 producer_attribute (producer)
2987 register char *producer;
2989 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2990 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
2994 inline_attribute (decl)
2997 if (DECL_INLINE (decl))
2999 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3000 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3005 containing_type_attribute (containing_type)
3006 register tree containing_type;
3008 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3010 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3011 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3012 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3016 abstract_origin_attribute (origin)
3017 register tree origin;
3019 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3021 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3022 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3025 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3029 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3033 abort (); /* Should never happen. */
3036 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3039 #ifdef DWARF_DECL_COORDINATES
3041 src_coords_attribute (src_fileno, src_lineno)
3042 register unsigned src_fileno;
3043 register unsigned src_lineno;
3045 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3046 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3047 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3049 #endif /* defined(DWARF_DECL_COORDINATES) */
3052 pure_or_virtual_attribute (func_decl)
3053 register tree func_decl;
3055 if (DECL_VIRTUAL_P (func_decl))
3057 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3058 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3059 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3062 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3063 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3067 /************************* end of attributes *****************************/
3069 /********************* utility routines for DIEs *************************/
3071 /* Output an AT_name attribute and an AT_src_coords attribute for the
3072 given decl, but only if it actually has a name. */
3075 name_and_src_coords_attributes (decl)
3078 register tree decl_name = DECL_NAME (decl);
3080 if (decl_name && IDENTIFIER_POINTER (decl_name))
3082 name_attribute (IDENTIFIER_POINTER (decl_name));
3083 #ifdef DWARF_DECL_COORDINATES
3085 register unsigned file_index;
3087 /* This is annoying, but we have to pop out of the .debug section
3088 for a moment while we call `lookup_filename' because calling it
3089 may cause a temporary switch into the .debug_sfnames section and
3090 most svr4 assemblers are not smart enough to be able to nest
3091 section switches to any depth greater than one. Note that we
3092 also can't skirt this issue by delaying all output to the
3093 .debug_sfnames section unit the end of compilation because that
3094 would cause us to have inter-section forward references and
3095 Fred Fish sez that m68k/svr4 assemblers botch those. */
3097 ASM_OUTPUT_POP_SECTION (asm_out_file);
3098 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3099 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3101 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3103 #endif /* defined(DWARF_DECL_COORDINATES) */
3107 /* Many forms of DIEs contain a "type description" part. The following
3108 routine writes out these "type descriptor" parts. */
3111 type_attribute (type, decl_const, decl_volatile)
3113 register int decl_const;
3114 register int decl_volatile;
3116 register enum tree_code code = TREE_CODE (type);
3117 register int root_type_modified;
3119 if (code == ERROR_MARK)
3122 /* Handle a special case. For functions whose return type is void,
3123 we generate *no* type attribute. (Note that no object may have
3124 type `void', so this only applies to function return types. */
3126 if (code == VOID_TYPE)
3129 /* If this is a subtype, find the underlying type. Eventually,
3130 this should write out the appropriate subtype info. */
3131 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3132 && TREE_TYPE (type) != 0)
3133 type = TREE_TYPE (type), code = TREE_CODE (type);
3135 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3136 || decl_const || decl_volatile
3137 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3139 if (type_is_fundamental (root_type (type)))
3141 if (root_type_modified)
3142 mod_fund_type_attribute (type, decl_const, decl_volatile);
3144 fund_type_attribute (fundamental_type_code (type));
3148 if (root_type_modified)
3149 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3151 /* We have to get the type_main_variant here (and pass that to the
3152 `user_def_type_attribute' routine) because the ..._TYPE node we
3153 have might simply be a *copy* of some original type node (where
3154 the copy was created to help us keep track of typedef names)
3155 and that copy might have a different TYPE_UID from the original
3156 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3157 is labeling a given type DIE for future reference, it always and
3158 only creates labels for DIEs representing *main variants*, and it
3159 never even knows about non-main-variants.) */
3160 user_def_type_attribute (type_main_variant (type));
3164 /* Given a tree pointer to a struct, class, union, or enum type node, return
3165 a pointer to the (string) tag name for the given type, or zero if the
3166 type was declared without a tag. */
3172 register char *name = 0;
3174 if (TYPE_NAME (type) != 0)
3176 register tree t = 0;
3178 /* Find the IDENTIFIER_NODE for the type name. */
3179 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3180 t = TYPE_NAME (type);
3182 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3183 a TYPE_DECL node, regardless of whether or not a `typedef' was
3185 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3186 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3187 t = DECL_NAME (TYPE_NAME (type));
3189 /* Now get the name as a string, or invent one. */
3191 name = IDENTIFIER_POINTER (t);
3194 return (name == 0 || *name == '\0') ? 0 : name;
3200 /* Start by checking if the pending_sibling_stack needs to be expanded.
3201 If necessary, expand it. */
3203 if (pending_siblings == pending_siblings_allocated)
3205 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3206 pending_sibling_stack
3207 = (unsigned *) xrealloc (pending_sibling_stack,
3208 pending_siblings_allocated * sizeof(unsigned));
3212 NEXT_DIE_NUM = next_unused_dienum++;
3215 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3225 member_declared_type (member)
3226 register tree member;
3228 return (DECL_BIT_FIELD_TYPE (member))
3229 ? DECL_BIT_FIELD_TYPE (member)
3230 : TREE_TYPE (member);
3233 /* Get the function's label, as described by its RTL.
3234 This may be different from the DECL_NAME name used
3235 in the source file. */
3238 function_start_label (decl)
3244 x = DECL_RTL (decl);
3245 if (GET_CODE (x) != MEM)
3248 if (GET_CODE (x) != SYMBOL_REF)
3250 fnname = XSTR (x, 0);
3255 /******************************* DIEs ************************************/
3257 /* Output routines for individual types of DIEs. */
3259 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3262 output_array_type_die (arg)
3265 register tree type = arg;
3267 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3268 sibling_attribute ();
3269 equate_type_number_to_die_number (type);
3270 member_attribute (TYPE_CONTEXT (type));
3272 /* I believe that we can default the array ordering. SDB will probably
3273 do the right things even if AT_ordering is not present. It's not
3274 even an issue until we start to get into multidimensional arrays
3275 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3276 dimensional arrays, then we'll have to put the AT_ordering attribute
3277 back in. (But if and when we find out that we need to put these in,
3278 we will only do so for multidimensional arrays. After all, we don't
3279 want to waste space in the .debug section now do we?) */
3281 #ifdef USE_ORDERING_ATTRIBUTE
3282 ordering_attribute (ORD_row_major);
3283 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3285 subscript_data_attribute (type);
3289 output_set_type_die (arg)
3292 register tree type = arg;
3294 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3295 sibling_attribute ();
3296 equate_type_number_to_die_number (type);
3297 member_attribute (TYPE_CONTEXT (type));
3298 type_attribute (TREE_TYPE (type), 0, 0);
3302 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3305 output_entry_point_die (arg)
3308 register tree decl = arg;
3309 register tree origin = decl_ultimate_origin (decl);
3311 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3312 sibling_attribute ();
3315 abstract_origin_attribute (origin);
3318 name_and_src_coords_attributes (decl);
3319 member_attribute (DECL_CONTEXT (decl));
3320 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3322 if (DECL_ABSTRACT (decl))
3323 equate_decl_number_to_die_number (decl);
3325 low_pc_attribute (function_start_label (decl));
3329 /* Output a DIE to represent an inlined instance of an enumeration type. */
3332 output_inlined_enumeration_type_die (arg)
3335 register tree type = arg;
3337 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3338 sibling_attribute ();
3339 if (!TREE_ASM_WRITTEN (type))
3341 abstract_origin_attribute (type);
3344 /* Output a DIE to represent an inlined instance of a structure type. */
3347 output_inlined_structure_type_die (arg)
3350 register tree type = arg;
3352 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3353 sibling_attribute ();
3354 if (!TREE_ASM_WRITTEN (type))
3356 abstract_origin_attribute (type);
3359 /* Output a DIE to represent an inlined instance of a union type. */
3362 output_inlined_union_type_die (arg)
3365 register tree type = arg;
3367 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3368 sibling_attribute ();
3369 if (!TREE_ASM_WRITTEN (type))
3371 abstract_origin_attribute (type);
3374 /* Output a DIE to represent an enumeration type. Note that these DIEs
3375 include all of the information about the enumeration values also.
3376 This information is encoded into the element_list attribute. */
3379 output_enumeration_type_die (arg)
3382 register tree type = arg;
3384 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3385 sibling_attribute ();
3386 equate_type_number_to_die_number (type);
3387 name_attribute (type_tag (type));
3388 member_attribute (TYPE_CONTEXT (type));
3390 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3391 given enum type is incomplete, do not generate the AT_byte_size
3392 attribute or the AT_element_list attribute. */
3394 if (TYPE_SIZE (type))
3396 byte_size_attribute (type);
3397 element_list_attribute (TYPE_FIELDS (type));
3401 /* Output a DIE to represent either a real live formal parameter decl or
3402 to represent just the type of some formal parameter position in some
3405 Note that this routine is a bit unusual because its argument may be
3406 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3407 represents an inlining of some PARM_DECL) or else some sort of a
3408 ..._TYPE node. If it's the former then this function is being called
3409 to output a DIE to represent a formal parameter object (or some inlining
3410 thereof). If it's the latter, then this function is only being called
3411 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3412 formal argument type of some subprogram type. */
3415 output_formal_parameter_die (arg)
3418 register tree node = arg;
3420 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3421 sibling_attribute ();
3423 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3425 case 'd': /* We were called with some kind of a ..._DECL node. */
3427 register tree origin = decl_ultimate_origin (node);
3430 abstract_origin_attribute (origin);
3433 name_and_src_coords_attributes (node);
3434 type_attribute (TREE_TYPE (node),
3435 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3437 if (DECL_ABSTRACT (node))
3438 equate_decl_number_to_die_number (node);
3440 location_or_const_value_attribute (node);
3444 case 't': /* We were called with some kind of a ..._TYPE node. */
3445 type_attribute (node, 0, 0);
3449 abort (); /* Should never happen. */
3453 /* Output a DIE to represent a declared function (either file-scope
3454 or block-local) which has "external linkage" (according to ANSI-C). */
3457 output_global_subroutine_die (arg)
3460 register tree decl = arg;
3461 register tree origin = decl_ultimate_origin (decl);
3463 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3464 sibling_attribute ();
3467 abstract_origin_attribute (origin);
3470 register tree type = TREE_TYPE (decl);
3472 name_and_src_coords_attributes (decl);
3473 inline_attribute (decl);
3474 prototyped_attribute (type);
3475 member_attribute (DECL_CONTEXT (decl));
3476 type_attribute (TREE_TYPE (type), 0, 0);
3477 pure_or_virtual_attribute (decl);
3479 if (DECL_ABSTRACT (decl))
3480 equate_decl_number_to_die_number (decl);
3483 if (! DECL_EXTERNAL (decl) && ! in_class
3484 && decl == current_function_decl)
3486 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3488 low_pc_attribute (function_start_label (decl));
3489 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3490 high_pc_attribute (label);
3491 if (use_gnu_debug_info_extensions)
3493 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3494 body_begin_attribute (label);
3495 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3496 body_end_attribute (label);
3502 /* Output a DIE to represent a declared data object (either file-scope
3503 or block-local) which has "external linkage" (according to ANSI-C). */
3506 output_global_variable_die (arg)
3509 register tree decl = arg;
3510 register tree origin = decl_ultimate_origin (decl);
3512 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3513 sibling_attribute ();
3515 abstract_origin_attribute (origin);
3518 name_and_src_coords_attributes (decl);
3519 member_attribute (DECL_CONTEXT (decl));
3520 type_attribute (TREE_TYPE (decl),
3521 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3523 if (DECL_ABSTRACT (decl))
3524 equate_decl_number_to_die_number (decl);
3527 if (! DECL_EXTERNAL (decl) && ! in_class
3528 && current_function_decl == decl_function_context (decl))
3529 location_or_const_value_attribute (decl);
3534 output_label_die (arg)
3537 register tree decl = arg;
3538 register tree origin = decl_ultimate_origin (decl);
3540 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3541 sibling_attribute ();
3543 abstract_origin_attribute (origin);
3545 name_and_src_coords_attributes (decl);
3546 if (DECL_ABSTRACT (decl))
3547 equate_decl_number_to_die_number (decl);
3550 register rtx insn = DECL_RTL (decl);
3552 /* Deleted labels are programmer specified labels which have been
3553 eliminated because of various optimisations. We still emit them
3554 here so that it is possible to put breakpoints on them. */
3555 if (GET_CODE (insn) == CODE_LABEL
3556 || ((GET_CODE (insn) == NOTE
3557 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3559 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3561 /* When optimization is enabled (via -O) some parts of the compiler
3562 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3563 represent source-level labels which were explicitly declared by
3564 the user. This really shouldn't be happening though, so catch
3565 it if it ever does happen. */
3567 if (INSN_DELETED_P (insn))
3568 abort (); /* Should never happen. */
3570 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3571 (unsigned) INSN_UID (insn));
3572 low_pc_attribute (label);
3578 output_lexical_block_die (arg)
3581 register tree stmt = arg;
3583 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3584 sibling_attribute ();
3586 if (! BLOCK_ABSTRACT (stmt))
3588 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3589 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3591 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3592 low_pc_attribute (begin_label);
3593 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3594 high_pc_attribute (end_label);
3599 output_inlined_subroutine_die (arg)
3602 register tree stmt = arg;
3604 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3605 sibling_attribute ();
3607 abstract_origin_attribute (block_ultimate_origin (stmt));
3608 if (! BLOCK_ABSTRACT (stmt))
3610 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3611 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3613 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3614 low_pc_attribute (begin_label);
3615 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3616 high_pc_attribute (end_label);
3620 /* Output a DIE to represent a declared data object (either file-scope
3621 or block-local) which has "internal linkage" (according to ANSI-C). */
3624 output_local_variable_die (arg)
3627 register tree decl = arg;
3628 register tree origin = decl_ultimate_origin (decl);
3630 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3631 sibling_attribute ();
3633 abstract_origin_attribute (origin);
3636 name_and_src_coords_attributes (decl);
3637 member_attribute (DECL_CONTEXT (decl));
3638 type_attribute (TREE_TYPE (decl),
3639 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3641 if (DECL_ABSTRACT (decl))
3642 equate_decl_number_to_die_number (decl);
3644 location_or_const_value_attribute (decl);
3648 output_member_die (arg)
3651 register tree decl = arg;
3653 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3654 sibling_attribute ();
3655 name_and_src_coords_attributes (decl);
3656 member_attribute (DECL_CONTEXT (decl));
3657 type_attribute (member_declared_type (decl),
3658 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3659 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3661 byte_size_attribute (decl);
3662 bit_size_attribute (decl);
3663 bit_offset_attribute (decl);
3665 data_member_location_attribute (decl);
3669 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3670 modified types instead.
3672 We keep this code here just in case these types of DIEs may be
3673 needed to represent certain things in other languages (e.g. Pascal)
3677 output_pointer_type_die (arg)
3680 register tree type = arg;
3682 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3683 sibling_attribute ();
3684 equate_type_number_to_die_number (type);
3685 member_attribute (TYPE_CONTEXT (type));
3686 type_attribute (TREE_TYPE (type), 0, 0);
3690 output_reference_type_die (arg)
3693 register tree type = arg;
3695 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3696 sibling_attribute ();
3697 equate_type_number_to_die_number (type);
3698 member_attribute (TYPE_CONTEXT (type));
3699 type_attribute (TREE_TYPE (type), 0, 0);
3704 output_ptr_to_mbr_type_die (arg)
3707 register tree type = arg;
3709 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3710 sibling_attribute ();
3711 equate_type_number_to_die_number (type);
3712 member_attribute (TYPE_CONTEXT (type));
3713 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3714 type_attribute (TREE_TYPE (type), 0, 0);
3718 output_compile_unit_die (arg)
3721 register char *main_input_filename = arg;
3723 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3724 sibling_attribute ();
3726 name_attribute (main_input_filename);
3731 sprintf (producer, "%s %s", language_string, version_string);
3732 producer_attribute (producer);
3735 if (strcmp (language_string, "GNU C++") == 0)
3736 language_attribute (LANG_C_PLUS_PLUS);
3737 else if (strcmp (language_string, "GNU Ada") == 0)
3738 language_attribute (LANG_ADA83);
3739 else if (strcmp (language_string, "GNU F77") == 0)
3740 language_attribute (LANG_FORTRAN77);
3741 else if (strcmp (language_string, "GNU Pascal") == 0)
3742 language_attribute (LANG_PASCAL83);
3743 else if (flag_traditional)
3744 language_attribute (LANG_C);
3746 language_attribute (LANG_C89);
3747 low_pc_attribute (TEXT_BEGIN_LABEL);
3748 high_pc_attribute (TEXT_END_LABEL);
3749 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3750 stmt_list_attribute (LINE_BEGIN_LABEL);
3751 last_filename = xstrdup (main_input_filename);
3754 char *wd = getpwd ();
3756 comp_dir_attribute (wd);
3759 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3761 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3762 src_info_attribute (SRCINFO_BEGIN_LABEL);
3763 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3764 mac_info_attribute (MACINFO_BEGIN_LABEL);
3769 output_string_type_die (arg)
3772 register tree type = arg;
3774 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3775 sibling_attribute ();
3776 equate_type_number_to_die_number (type);
3777 member_attribute (TYPE_CONTEXT (type));
3778 /* this is a fixed length string */
3779 byte_size_attribute (type);
3783 output_inheritance_die (arg)
3786 register tree binfo = arg;
3788 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3789 sibling_attribute ();
3790 type_attribute (BINFO_TYPE (binfo), 0, 0);
3791 data_member_location_attribute (binfo);
3792 if (TREE_VIA_VIRTUAL (binfo))
3794 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3795 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3797 if (TREE_VIA_PUBLIC (binfo))
3799 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3800 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3802 else if (TREE_VIA_PROTECTED (binfo))
3804 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3805 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3810 output_structure_type_die (arg)
3813 register tree type = arg;
3815 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3816 sibling_attribute ();
3817 equate_type_number_to_die_number (type);
3818 name_attribute (type_tag (type));
3819 member_attribute (TYPE_CONTEXT (type));
3821 /* If this type has been completed, then give it a byte_size attribute
3822 and prepare to give a list of members. Otherwise, don't do either of
3823 these things. In the latter case, we will not be generating a list
3824 of members (since we don't have any idea what they might be for an
3825 incomplete type). */
3827 if (TYPE_SIZE (type))
3830 byte_size_attribute (type);
3834 /* Output a DIE to represent a declared function (either file-scope
3835 or block-local) which has "internal linkage" (according to ANSI-C). */
3838 output_local_subroutine_die (arg)
3841 register tree decl = arg;
3842 register tree origin = decl_ultimate_origin (decl);
3844 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3845 sibling_attribute ();
3848 abstract_origin_attribute (origin);
3851 register tree type = TREE_TYPE (decl);
3853 name_and_src_coords_attributes (decl);
3854 inline_attribute (decl);
3855 prototyped_attribute (type);
3856 member_attribute (DECL_CONTEXT (decl));
3857 type_attribute (TREE_TYPE (type), 0, 0);
3858 pure_or_virtual_attribute (decl);
3860 if (DECL_ABSTRACT (decl))
3861 equate_decl_number_to_die_number (decl);
3864 /* Avoid getting screwed up in cases where a function was declared
3865 static but where no definition was ever given for it. */
3867 if (TREE_ASM_WRITTEN (decl))
3869 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3870 low_pc_attribute (function_start_label (decl));
3871 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3872 high_pc_attribute (label);
3873 if (use_gnu_debug_info_extensions)
3875 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3876 body_begin_attribute (label);
3877 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3878 body_end_attribute (label);
3885 output_subroutine_type_die (arg)
3888 register tree type = arg;
3889 register tree return_type = TREE_TYPE (type);
3891 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3892 sibling_attribute ();
3894 equate_type_number_to_die_number (type);
3895 prototyped_attribute (type);
3896 member_attribute (TYPE_CONTEXT (type));
3897 type_attribute (return_type, 0, 0);
3901 output_typedef_die (arg)
3904 register tree decl = arg;
3905 register tree origin = decl_ultimate_origin (decl);
3907 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3908 sibling_attribute ();
3910 abstract_origin_attribute (origin);
3913 name_and_src_coords_attributes (decl);
3914 member_attribute (DECL_CONTEXT (decl));
3915 type_attribute (TREE_TYPE (decl),
3916 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3918 if (DECL_ABSTRACT (decl))
3919 equate_decl_number_to_die_number (decl);
3923 output_union_type_die (arg)
3926 register tree type = arg;
3928 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3929 sibling_attribute ();
3930 equate_type_number_to_die_number (type);
3931 name_attribute (type_tag (type));
3932 member_attribute (TYPE_CONTEXT (type));
3934 /* If this type has been completed, then give it a byte_size attribute
3935 and prepare to give a list of members. Otherwise, don't do either of
3936 these things. In the latter case, we will not be generating a list
3937 of members (since we don't have any idea what they might be for an
3938 incomplete type). */
3940 if (TYPE_SIZE (type))
3943 byte_size_attribute (type);
3947 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3948 at the end of an (ANSI prototyped) formal parameters list. */
3951 output_unspecified_parameters_die (arg)
3954 register tree decl_or_type = arg;
3956 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3957 sibling_attribute ();
3959 /* This kludge is here only for the sake of being compatible with what
3960 the USL CI5 C compiler does. The specification of Dwarf Version 1
3961 doesn't say that TAG_unspecified_parameters DIEs should contain any
3962 attributes other than the AT_sibling attribute, but they are certainly
3963 allowed to contain additional attributes, and the CI5 compiler
3964 generates AT_name, AT_fund_type, and AT_location attributes within
3965 TAG_unspecified_parameters DIEs which appear in the child lists for
3966 DIEs representing function definitions, so we do likewise here. */
3968 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3970 name_attribute ("...");
3971 fund_type_attribute (FT_pointer);
3972 /* location_attribute (?); */
3977 output_padded_null_die (arg)
3978 register void *arg ATTRIBUTE_UNUSED;
3980 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3983 /*************************** end of DIEs *********************************/
3985 /* Generate some type of DIE. This routine generates the generic outer
3986 wrapper stuff which goes around all types of DIE's (regardless of their
3987 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3988 DIE-length word, followed by the guts of the DIE itself. After the guts
3989 of the DIE, there must always be a terminator label for the DIE. */
3992 output_die (die_specific_output_function, param)
3993 register void (*die_specific_output_function) PROTO ((void *));
3994 register void *param;
3996 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3997 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3999 current_dienum = NEXT_DIE_NUM;
4000 NEXT_DIE_NUM = next_unused_dienum;
4002 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4003 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4005 /* Write a label which will act as the name for the start of this DIE. */
4007 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4009 /* Write the DIE-length word. */
4011 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4013 /* Fill in the guts of the DIE. */
4015 next_unused_dienum++;
4016 die_specific_output_function (param);
4018 /* Write a label which will act as the name for the end of this DIE. */
4020 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4024 end_sibling_chain ()
4026 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4028 current_dienum = NEXT_DIE_NUM;
4029 NEXT_DIE_NUM = next_unused_dienum;
4031 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4033 /* Write a label which will act as the name for the start of this DIE. */
4035 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4037 /* Write the DIE-length word. */
4039 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4044 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4045 TAG_unspecified_parameters DIE) to represent the types of the formal
4046 parameters as specified in some function type specification (except
4047 for those which appear as part of a function *definition*).
4049 Note that we must be careful here to output all of the parameter
4050 DIEs *before* we output any DIEs needed to represent the types of
4051 the formal parameters. This keeps svr4 SDB happy because it
4052 (incorrectly) thinks that the first non-parameter DIE it sees ends
4053 the formal parameter list. */
4056 output_formal_types (function_or_method_type)
4057 register tree function_or_method_type;
4060 register tree formal_type = NULL;
4061 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4063 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4064 get bogus recursion when outputting tagged types local to a
4065 function declaration. */
4066 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4067 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4069 /* In the case where we are generating a formal types list for a C++
4070 non-static member function type, skip over the first thing on the
4071 TYPE_ARG_TYPES list because it only represents the type of the
4072 hidden `this pointer'. The debugger should be able to figure
4073 out (without being explicitly told) that this non-static member
4074 function type takes a `this pointer' and should be able to figure
4075 what the type of that hidden parameter is from the AT_member
4076 attribute of the parent TAG_subroutine_type DIE. */
4078 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4079 first_parm_type = TREE_CHAIN (first_parm_type);
4081 /* Make our first pass over the list of formal parameter types and output
4082 a TAG_formal_parameter DIE for each one. */
4084 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4086 formal_type = TREE_VALUE (link);
4087 if (formal_type == void_type_node)
4090 /* Output a (nameless) DIE to represent the formal parameter itself. */
4092 output_die (output_formal_parameter_die, formal_type);
4095 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4096 DIE to the end of the parameter list. */
4098 if (formal_type != void_type_node)
4099 output_die (output_unspecified_parameters_die, function_or_method_type);
4101 /* Make our second (and final) pass over the list of formal parameter types
4102 and output DIEs to represent those types (as necessary). */
4104 for (link = TYPE_ARG_TYPES (function_or_method_type);
4106 link = TREE_CHAIN (link))
4108 formal_type = TREE_VALUE (link);
4109 if (formal_type == void_type_node)
4112 output_type (formal_type, function_or_method_type);
4115 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4118 /* Remember a type in the pending_types_list. */
4124 if (pending_types == pending_types_allocated)
4126 pending_types_allocated += PENDING_TYPES_INCREMENT;
4128 = (tree *) xrealloc (pending_types_list,
4129 sizeof (tree) * pending_types_allocated);
4131 pending_types_list[pending_types++] = type;
4133 /* Mark the pending type as having been output already (even though
4134 it hasn't been). This prevents the type from being added to the
4135 pending_types_list more than once. */
4137 TREE_ASM_WRITTEN (type) = 1;
4140 /* Return non-zero if it is legitimate to output DIEs to represent a
4141 given type while we are generating the list of child DIEs for some
4142 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4144 See the comments within the function for a description of when it is
4145 considered legitimate to output DIEs for various kinds of types.
4147 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4148 or it may point to a BLOCK node (for types local to a block), or to a
4149 FUNCTION_DECL node (for types local to the heading of some function
4150 definition), or to a FUNCTION_TYPE node (for types local to the
4151 prototyped parameter list of a function type specification), or to a
4152 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4153 (in the case of C++ nested types).
4155 The `scope' parameter should likewise be NULL or should point to a
4156 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4157 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4159 This function is used only for deciding when to "pend" and when to
4160 "un-pend" types to/from the pending_types_list.
4162 Note that we sometimes make use of this "type pending" feature in a
4163 rather twisted way to temporarily delay the production of DIEs for the
4164 types of formal parameters. (We do this just to make svr4 SDB happy.)
4165 It order to delay the production of DIEs representing types of formal
4166 parameters, callers of this function supply `fake_containing_scope' as
4167 the `scope' parameter to this function. Given that fake_containing_scope
4168 is a tagged type which is *not* the containing scope for *any* other type,
4169 the desired effect is achieved, i.e. output of DIEs representing types
4170 is temporarily suspended, and any type DIEs which would have otherwise
4171 been output are instead placed onto the pending_types_list. Later on,
4172 we force these (temporarily pended) types to be output simply by calling
4173 `output_pending_types_for_scope' with an actual argument equal to the
4174 true scope of the types we temporarily pended. */
4177 type_ok_for_scope (type, scope)
4179 register tree scope;
4181 /* Tagged types (i.e. struct, union, and enum types) must always be
4182 output only in the scopes where they actually belong (or else the
4183 scoping of their own tag names and the scoping of their member
4184 names will be incorrect). Non-tagged-types on the other hand can
4185 generally be output anywhere, except that svr4 SDB really doesn't
4186 want to see them nested within struct or union types, so here we
4187 say it is always OK to immediately output any such a (non-tagged)
4188 type, so long as we are not within such a context. Note that the
4189 only kinds of non-tagged types which we will be dealing with here
4190 (for C and C++ anyway) will be array types and function types. */
4192 return is_tagged_type (type)
4193 ? (TYPE_CONTEXT (type) == scope
4194 /* Ignore namespaces for the moment. */
4195 || (scope == NULL_TREE
4196 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4197 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4198 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4199 : (scope == NULL_TREE || ! is_tagged_type (scope));
4202 /* Output any pending types (from the pending_types list) which we can output
4203 now (taking into account the scope that we are working on now).
4205 For each type output, remove the given type from the pending_types_list
4206 *before* we try to output it.
4208 Note that we have to process the list in beginning-to-end order,
4209 because the call made here to output_type may cause yet more types
4210 to be added to the end of the list, and we may have to output some
4214 output_pending_types_for_scope (containing_scope)
4215 register tree containing_scope;
4217 register unsigned i;
4219 for (i = 0; i < pending_types; )
4221 register tree type = pending_types_list[i];
4223 if (type_ok_for_scope (type, containing_scope))
4225 register tree *mover;
4226 register tree *limit;
4229 limit = &pending_types_list[pending_types];
4230 for (mover = &pending_types_list[i]; mover < limit; mover++)
4231 *mover = *(mover+1);
4233 /* Un-mark the type as having been output already (because it
4234 hasn't been, really). Then call output_type to generate a
4235 Dwarf representation of it. */
4237 TREE_ASM_WRITTEN (type) = 0;
4238 output_type (type, containing_scope);
4240 /* Don't increment the loop counter in this case because we
4241 have shifted all of the subsequent pending types down one
4242 element in the pending_types_list array. */
4249 /* Remember a type in the incomplete_types_list. */
4252 add_incomplete_type (type)
4255 if (incomplete_types == incomplete_types_allocated)
4257 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4258 incomplete_types_list
4259 = (tree *) xrealloc (incomplete_types_list,
4260 sizeof (tree) * incomplete_types_allocated);
4263 incomplete_types_list[incomplete_types++] = type;
4266 /* Walk through the list of incomplete types again, trying once more to
4267 emit full debugging info for them. */
4270 retry_incomplete_types ()
4275 while (incomplete_types)
4278 type = incomplete_types_list[incomplete_types];
4279 output_type (type, NULL_TREE);
4284 output_type (type, containing_scope)
4286 register tree containing_scope;
4288 if (type == 0 || type == error_mark_node)
4291 /* We are going to output a DIE to represent the unqualified version of
4292 this type (i.e. without any const or volatile qualifiers) so get
4293 the main variant (i.e. the unqualified version) of this type now. */
4295 type = type_main_variant (type);
4297 if (TREE_ASM_WRITTEN (type))
4299 if (finalizing && AGGREGATE_TYPE_P (type))
4301 register tree member;
4303 /* Some of our nested types might not have been defined when we
4304 were written out before; force them out now. */
4306 for (member = TYPE_FIELDS (type); member;
4307 member = TREE_CHAIN (member))
4308 if (TREE_CODE (member) == TYPE_DECL
4309 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4310 output_type (TREE_TYPE (member), containing_scope);
4315 /* If this is a nested type whose containing class hasn't been
4316 written out yet, writing it out will cover this one, too. */
4318 if (TYPE_CONTEXT (type)
4319 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4320 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4322 output_type (TYPE_CONTEXT (type), containing_scope);
4326 /* Don't generate any DIEs for this type now unless it is OK to do so
4327 (based upon what `type_ok_for_scope' tells us). */
4329 if (! type_ok_for_scope (type, containing_scope))
4335 switch (TREE_CODE (type))
4341 case REFERENCE_TYPE:
4342 /* Prevent infinite recursion in cases where this is a recursive
4343 type. Recursive types are possible in Ada. */
4344 TREE_ASM_WRITTEN (type) = 1;
4345 /* For these types, all that is required is that we output a DIE
4346 (or a set of DIEs) to represent the "basis" type. */
4347 output_type (TREE_TYPE (type), containing_scope);
4351 /* This code is used for C++ pointer-to-data-member types. */
4352 /* Output a description of the relevant class type. */
4353 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4354 /* Output a description of the type of the object pointed to. */
4355 output_type (TREE_TYPE (type), containing_scope);
4356 /* Now output a DIE to represent this pointer-to-data-member type
4358 output_die (output_ptr_to_mbr_type_die, type);
4362 output_type (TYPE_DOMAIN (type), containing_scope);
4363 output_die (output_set_type_die, type);
4367 output_type (TREE_TYPE (type), containing_scope);
4368 abort (); /* No way to represent these in Dwarf yet! */
4372 /* Force out return type (in case it wasn't forced out already). */
4373 output_type (TREE_TYPE (type), containing_scope);
4374 output_die (output_subroutine_type_die, type);
4375 output_formal_types (type);
4376 end_sibling_chain ();
4380 /* Force out return type (in case it wasn't forced out already). */
4381 output_type (TREE_TYPE (type), containing_scope);
4382 output_die (output_subroutine_type_die, type);
4383 output_formal_types (type);
4384 end_sibling_chain ();
4388 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4390 output_type (TREE_TYPE (type), containing_scope);
4391 output_die (output_string_type_die, type);
4395 register tree element_type;
4397 element_type = TREE_TYPE (type);
4398 while (TREE_CODE (element_type) == ARRAY_TYPE)
4399 element_type = TREE_TYPE (element_type);
4401 output_type (element_type, containing_scope);
4402 output_die (output_array_type_die, type);
4409 case QUAL_UNION_TYPE:
4411 /* For a non-file-scope tagged type, we can always go ahead and
4412 output a Dwarf description of this type right now, even if
4413 the type in question is still incomplete, because if this
4414 local type *was* ever completed anywhere within its scope,
4415 that complete definition would already have been attached to
4416 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4417 node by the time we reach this point. That's true because of the
4418 way the front-end does its processing of file-scope declarations (of
4419 functions and class types) within which other types might be
4420 nested. The C and C++ front-ends always gobble up such "local
4421 scope" things en-mass before they try to output *any* debugging
4422 information for any of the stuff contained inside them and thus,
4423 we get the benefit here of what is (in effect) a pre-resolution
4424 of forward references to tagged types in local scopes.
4426 Note however that for file-scope tagged types we cannot assume
4427 that such pre-resolution of forward references has taken place.
4428 A given file-scope tagged type may appear to be incomplete when
4429 we reach this point, but it may yet be given a full definition
4430 (at file-scope) later on during compilation. In order to avoid
4431 generating a premature (and possibly incorrect) set of Dwarf
4432 DIEs for such (as yet incomplete) file-scope tagged types, we
4433 generate nothing at all for as-yet incomplete file-scope tagged
4434 types here unless we are making our special "finalization" pass
4435 for file-scope things at the very end of compilation. At that
4436 time, we will certainly know as much about each file-scope tagged
4437 type as we are ever going to know, so at that point in time, we
4438 can safely generate correct Dwarf descriptions for these file-
4439 scope tagged types. */
4441 if (TYPE_SIZE (type) == 0
4442 && (TYPE_CONTEXT (type) == NULL
4443 || (TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4444 && TREE_CODE (TYPE_CONTEXT (type)) != FUNCTION_TYPE
4445 && TREE_CODE (TYPE_CONTEXT (type)) != METHOD_TYPE))
4448 /* We can't do this for function-local types, and we don't need
4450 if (TREE_PERMANENT (type))
4451 add_incomplete_type (type);
4452 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4455 /* Prevent infinite recursion in cases where the type of some
4456 member of this type is expressed in terms of this type itself. */
4458 TREE_ASM_WRITTEN (type) = 1;
4460 /* Output a DIE to represent the tagged type itself. */
4462 switch (TREE_CODE (type))
4465 output_die (output_enumeration_type_die, type);
4466 return; /* a special case -- nothing left to do so just return */
4469 output_die (output_structure_type_die, type);
4473 case QUAL_UNION_TYPE:
4474 output_die (output_union_type_die, type);
4478 abort (); /* Should never happen. */
4481 /* If this is not an incomplete type, output descriptions of
4482 each of its members.
4484 Note that as we output the DIEs necessary to represent the
4485 members of this record or union type, we will also be trying
4486 to output DIEs to represent the *types* of those members.
4487 However the `output_type' function (above) will specifically
4488 avoid generating type DIEs for member types *within* the list
4489 of member DIEs for this (containing) type execpt for those
4490 types (of members) which are explicitly marked as also being
4491 members of this (containing) type themselves. The g++ front-
4492 end can force any given type to be treated as a member of some
4493 other (containing) type by setting the TYPE_CONTEXT of the
4494 given (member) type to point to the TREE node representing the
4495 appropriate (containing) type.
4498 if (TYPE_SIZE (type))
4500 /* First output info about the base classes. */
4501 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4503 register tree bases = TYPE_BINFO_BASETYPES (type);
4504 register int n_bases = TREE_VEC_LENGTH (bases);
4507 for (i = 0; i < n_bases; i++)
4509 tree binfo = TREE_VEC_ELT (bases, i);
4510 output_type (BINFO_TYPE (binfo), containing_scope);
4511 output_die (output_inheritance_die, binfo);
4518 register tree normal_member;
4520 /* Now output info about the data members and type members. */
4522 for (normal_member = TYPE_FIELDS (type);
4524 normal_member = TREE_CHAIN (normal_member))
4525 output_decl (normal_member, type);
4529 register tree func_member;
4531 /* Now output info about the function members (if any). */
4533 for (func_member = TYPE_METHODS (type);
4535 func_member = TREE_CHAIN (func_member))
4536 output_decl (func_member, type);
4541 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4542 scopes (at least in C++) so we must now output any nested
4543 pending types which are local just to this type. */
4545 output_pending_types_for_scope (type);
4547 end_sibling_chain (); /* Terminate member chain. */
4558 break; /* No DIEs needed for fundamental types. */
4560 case LANG_TYPE: /* No Dwarf representation currently defined. */
4567 TREE_ASM_WRITTEN (type) = 1;
4571 output_tagged_type_instantiation (type)
4574 if (type == 0 || type == error_mark_node)
4577 /* We are going to output a DIE to represent the unqualified version of
4578 this type (i.e. without any const or volatile qualifiers) so make
4579 sure that we have the main variant (i.e. the unqualified version) of
4582 if (type != type_main_variant (type))
4585 if (!TREE_ASM_WRITTEN (type))
4588 switch (TREE_CODE (type))
4594 output_die (output_inlined_enumeration_type_die, type);
4598 output_die (output_inlined_structure_type_die, type);
4602 case QUAL_UNION_TYPE:
4603 output_die (output_inlined_union_type_die, type);
4607 abort (); /* Should never happen. */
4611 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4612 the things which are local to the given block. */
4615 output_block (stmt, depth)
4619 register int must_output_die = 0;
4620 register tree origin;
4621 register enum tree_code origin_code;
4623 /* Ignore blocks never really used to make RTL. */
4625 if (! stmt || ! TREE_USED (stmt))
4628 /* Determine the "ultimate origin" of this block. This block may be an
4629 inlined instance of an inlined instance of inline function, so we
4630 have to trace all of the way back through the origin chain to find
4631 out what sort of node actually served as the original seed for the
4632 creation of the current block. */
4634 origin = block_ultimate_origin (stmt);
4635 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4637 /* Determine if we need to output any Dwarf DIEs at all to represent this
4640 if (origin_code == FUNCTION_DECL)
4641 /* The outer scopes for inlinings *must* always be represented. We
4642 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4643 must_output_die = 1;
4646 /* In the case where the current block represents an inlining of the
4647 "body block" of an inline function, we must *NOT* output any DIE
4648 for this block because we have already output a DIE to represent
4649 the whole inlined function scope and the "body block" of any
4650 function doesn't really represent a different scope according to
4651 ANSI C rules. So we check here to make sure that this block does
4652 not represent a "body block inlining" before trying to set the
4653 `must_output_die' flag. */
4655 if (! is_body_block (origin ? origin : stmt))
4657 /* Determine if this block directly contains any "significant"
4658 local declarations which we will need to output DIEs for. */
4660 if (debug_info_level > DINFO_LEVEL_TERSE)
4661 /* We are not in terse mode so *any* local declaration counts
4662 as being a "significant" one. */
4663 must_output_die = (BLOCK_VARS (stmt) != NULL);
4668 /* We are in terse mode, so only local (nested) function
4669 definitions count as "significant" local declarations. */
4671 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4672 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4674 must_output_die = 1;
4681 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4682 DIE for any block which contains no significant local declarations
4683 at all. Rather, in such cases we just call `output_decls_for_scope'
4684 so that any needed Dwarf info for any sub-blocks will get properly
4685 generated. Note that in terse mode, our definition of what constitutes
4686 a "significant" local declaration gets restricted to include only
4687 inlined function instances and local (nested) function definitions. */
4689 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4690 /* We don't care about an abstract inlined subroutine. */;
4691 else if (must_output_die)
4693 output_die ((origin_code == FUNCTION_DECL)
4694 ? output_inlined_subroutine_die
4695 : output_lexical_block_die,
4697 output_decls_for_scope (stmt, depth);
4698 end_sibling_chain ();
4701 output_decls_for_scope (stmt, depth);
4704 /* Output all of the decls declared within a given scope (also called
4705 a `binding contour') and (recursively) all of it's sub-blocks. */
4708 output_decls_for_scope (stmt, depth)
4712 /* Ignore blocks never really used to make RTL. */
4714 if (! stmt || ! TREE_USED (stmt))
4717 if (! BLOCK_ABSTRACT (stmt) && depth > 0)
4718 next_block_number++;
4720 /* Output the DIEs to represent all of the data objects, functions,
4721 typedefs, and tagged types declared directly within this block
4722 but not within any nested sub-blocks. */
4727 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4728 output_decl (decl, stmt);
4731 output_pending_types_for_scope (stmt);
4733 /* Output the DIEs to represent all sub-blocks (and the items declared
4734 therein) of this block. */
4737 register tree subblocks;
4739 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4741 subblocks = BLOCK_CHAIN (subblocks))
4742 output_block (subblocks, depth + 1);
4746 /* Is this a typedef we can avoid emitting? */
4749 is_redundant_typedef (decl)
4752 if (TYPE_DECL_IS_STUB (decl))
4754 if (DECL_ARTIFICIAL (decl)
4755 && DECL_CONTEXT (decl)
4756 && is_tagged_type (DECL_CONTEXT (decl))
4757 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4758 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4759 /* Also ignore the artificial member typedef for the class name. */
4764 /* Output Dwarf .debug information for a decl described by DECL. */
4767 output_decl (decl, containing_scope)
4769 register tree containing_scope;
4771 /* Make a note of the decl node we are going to be working on. We may
4772 need to give the user the source coordinates of where it appeared in
4773 case we notice (later on) that something about it looks screwy. */
4775 dwarf_last_decl = decl;
4777 if (TREE_CODE (decl) == ERROR_MARK)
4780 /* If a structure is declared within an initialization, e.g. as the
4781 operand of a sizeof, then it will not have a name. We don't want
4782 to output a DIE for it, as the tree nodes are in the temporary obstack */
4784 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4785 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4786 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4787 || (TYPE_FIELDS (TREE_TYPE (decl))
4788 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4791 /* If this ..._DECL node is marked to be ignored, then ignore it.
4792 But don't ignore a function definition, since that would screw
4793 up our count of blocks, and that it turn will completely screw up the
4794 labels we will reference in subsequent AT_low_pc and AT_high_pc
4795 attributes (for subsequent blocks). */
4797 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4800 switch (TREE_CODE (decl))
4803 /* The individual enumerators of an enum type get output when we
4804 output the Dwarf representation of the relevant enum type itself. */
4808 /* If we are in terse mode, don't output any DIEs to represent
4809 mere function declarations. Also, if we are conforming
4810 to the DWARF version 1 specification, don't output DIEs for
4811 mere function declarations. */
4813 if (DECL_INITIAL (decl) == NULL_TREE)
4814 #if (DWARF_VERSION > 1)
4815 if (debug_info_level <= DINFO_LEVEL_TERSE)
4819 /* Before we describe the FUNCTION_DECL itself, make sure that we
4820 have described its return type. */
4822 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4825 /* And its containing type. */
4826 register tree origin = decl_class_context (decl);
4828 output_type (origin, containing_scope);
4831 /* If the following DIE will represent a function definition for a
4832 function with "extern" linkage, output a special "pubnames" DIE
4833 label just ahead of the actual DIE. A reference to this label
4834 was already generated in the .debug_pubnames section sub-entry
4835 for this function definition. */
4837 if (TREE_PUBLIC (decl))
4839 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4841 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4842 ASM_OUTPUT_LABEL (asm_out_file, label);
4845 /* Now output a DIE to represent the function itself. */
4847 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4848 ? output_global_subroutine_die
4849 : output_local_subroutine_die,
4852 /* Now output descriptions of the arguments for this function.
4853 This gets (unnecessarily?) complex because of the fact that
4854 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4855 cases where there was a trailing `...' at the end of the formal
4856 parameter list. In order to find out if there was a trailing
4857 ellipsis or not, we must instead look at the type associated
4858 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4859 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4860 ends with a void_type_node then there should *not* be an ellipsis
4863 /* In the case where we are describing a mere function declaration, all
4864 we need to do here (and all we *can* do here) is to describe
4865 the *types* of its formal parameters. */
4867 if (decl != current_function_decl || in_class)
4868 output_formal_types (TREE_TYPE (decl));
4871 /* Generate DIEs to represent all known formal parameters */
4873 register tree arg_decls = DECL_ARGUMENTS (decl);
4876 /* WARNING! Kludge zone ahead! Here we have a special
4877 hack for svr4 SDB compatibility. Instead of passing the
4878 current FUNCTION_DECL node as the second parameter (i.e.
4879 the `containing_scope' parameter) to `output_decl' (as
4880 we ought to) we instead pass a pointer to our own private
4881 fake_containing_scope node. That node is a RECORD_TYPE
4882 node which NO OTHER TYPE may ever actually be a member of.
4884 This pointer will ultimately get passed into `output_type'
4885 as its `containing_scope' parameter. `Output_type' will
4886 then perform its part in the hack... i.e. it will pend
4887 the type of the formal parameter onto the pending_types
4888 list. Later on, when we are done generating the whole
4889 sequence of formal parameter DIEs for this function
4890 definition, we will un-pend all previously pended types
4891 of formal parameters for this function definition.
4893 This whole kludge prevents any type DIEs from being
4894 mixed in with the formal parameter DIEs. That's good
4895 because svr4 SDB believes that the list of formal
4896 parameter DIEs for a function ends wherever the first
4897 non-formal-parameter DIE appears. Thus, we have to
4898 keep the formal parameter DIEs segregated. They must
4899 all appear (consecutively) at the start of the list of
4900 children for the DIE representing the function definition.
4901 Then (and only then) may we output any additional DIEs
4902 needed to represent the types of these formal parameters.
4906 When generating DIEs, generate the unspecified_parameters
4907 DIE instead if we come across the arg "__builtin_va_alist"
4910 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4911 if (TREE_CODE (parm) == PARM_DECL)
4913 if (DECL_NAME(parm) &&
4914 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4915 "__builtin_va_alist") )
4916 output_die (output_unspecified_parameters_die, decl);
4918 output_decl (parm, fake_containing_scope);
4922 Now that we have finished generating all of the DIEs to
4923 represent the formal parameters themselves, force out
4924 any DIEs needed to represent their types. We do this
4925 simply by un-pending all previously pended types which
4926 can legitimately go into the chain of children DIEs for
4927 the current FUNCTION_DECL.
4930 output_pending_types_for_scope (decl);
4933 Decide whether we need a unspecified_parameters DIE at the end.
4934 There are 2 more cases to do this for:
4935 1) the ansi ... declaration - this is detectable when the end
4936 of the arg list is not a void_type_node
4937 2) an unprototyped function declaration (not a definition). This
4938 just means that we have no info about the parameters at all.
4942 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4946 /* this is the prototyped case, check for ... */
4947 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4948 output_die (output_unspecified_parameters_die, decl);
4952 /* this is unprototyped, check for undefined (just declaration) */
4953 if (!DECL_INITIAL (decl))
4954 output_die (output_unspecified_parameters_die, decl);
4958 /* Output Dwarf info for all of the stuff within the body of the
4959 function (if it has one - it may be just a declaration). */
4962 register tree outer_scope = DECL_INITIAL (decl);
4964 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4966 /* Note that here, `outer_scope' is a pointer to the outermost
4967 BLOCK node created to represent a function.
4968 This outermost BLOCK actually represents the outermost
4969 binding contour for the function, i.e. the contour in which
4970 the function's formal parameters and labels get declared.
4972 Curiously, it appears that the front end doesn't actually
4973 put the PARM_DECL nodes for the current function onto the
4974 BLOCK_VARS list for this outer scope. (They are strung
4975 off of the DECL_ARGUMENTS list for the function instead.)
4976 The BLOCK_VARS list for the `outer_scope' does provide us
4977 with a list of the LABEL_DECL nodes for the function however,
4978 and we output DWARF info for those here.
4980 Just within the `outer_scope' there will be a BLOCK node
4981 representing the function's outermost pair of curly braces,
4982 and any blocks used for the base and member initializers of
4983 a C++ constructor function. */
4985 output_decls_for_scope (outer_scope, 0);
4987 /* Finally, force out any pending types which are local to the
4988 outermost block of this function definition. These will
4989 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4992 output_pending_types_for_scope (decl);
4997 /* Generate a terminator for the list of stuff `owned' by this
5000 end_sibling_chain ();
5005 /* If we are in terse mode, don't generate any DIEs to represent
5006 any actual typedefs. Note that even when we are in terse mode,
5007 we must still output DIEs to represent those tagged types which
5008 are used (directly or indirectly) in the specification of either
5009 a return type or a formal parameter type of some function. */
5011 if (debug_info_level <= DINFO_LEVEL_TERSE)
5012 if (! TYPE_DECL_IS_STUB (decl)
5013 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5016 /* In the special case of a TYPE_DECL node representing
5017 the declaration of some type tag, if the given TYPE_DECL is
5018 marked as having been instantiated from some other (original)
5019 TYPE_DECL node (e.g. one which was generated within the original
5020 definition of an inline function) we have to generate a special
5021 (abbreviated) TAG_structure_type, TAG_union_type, or
5022 TAG_enumeration-type DIE here. */
5024 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5026 output_tagged_type_instantiation (TREE_TYPE (decl));
5030 output_type (TREE_TYPE (decl), containing_scope);
5032 if (! is_redundant_typedef (decl))
5033 /* Output a DIE to represent the typedef itself. */
5034 output_die (output_typedef_die, decl);
5038 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5039 output_die (output_label_die, decl);
5043 /* If we are conforming to the DWARF version 1 specification, don't
5044 generated any DIEs to represent mere external object declarations. */
5046 #if (DWARF_VERSION <= 1)
5047 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5051 /* If we are in terse mode, don't generate any DIEs to represent
5052 any variable declarations or definitions. */
5054 if (debug_info_level <= DINFO_LEVEL_TERSE)
5057 /* Output any DIEs that are needed to specify the type of this data
5060 output_type (TREE_TYPE (decl), containing_scope);
5063 /* And its containing type. */
5064 register tree origin = decl_class_context (decl);
5066 output_type (origin, containing_scope);
5069 /* If the following DIE will represent a data object definition for a
5070 data object with "extern" linkage, output a special "pubnames" DIE
5071 label just ahead of the actual DIE. A reference to this label
5072 was already generated in the .debug_pubnames section sub-entry
5073 for this data object definition. */
5075 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5077 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5079 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5080 ASM_OUTPUT_LABEL (asm_out_file, label);
5083 /* Now output the DIE to represent the data object itself. This gets
5084 complicated because of the possibility that the VAR_DECL really
5085 represents an inlined instance of a formal parameter for an inline
5089 register void (*func) PROTO((void *));
5090 register tree origin = decl_ultimate_origin (decl);
5092 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5093 func = output_formal_parameter_die;
5096 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5097 func = output_global_variable_die;
5099 func = output_local_variable_die;
5101 output_die (func, decl);
5106 /* Ignore the nameless fields that are used to skip bits. */
5107 if (DECL_NAME (decl) != 0)
5109 output_type (member_declared_type (decl), containing_scope);
5110 output_die (output_member_die, decl);
5115 /* Force out the type of this formal, if it was not forced out yet.
5116 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5117 It should be able to grok the presence of type DIEs within a list
5118 of TAG_formal_parameter DIEs, but it doesn't. */
5120 output_type (TREE_TYPE (decl), containing_scope);
5121 output_die (output_formal_parameter_die, decl);
5130 dwarfout_file_scope_decl (decl, set_finalizing)
5132 register int set_finalizing;
5134 if (TREE_CODE (decl) == ERROR_MARK)
5137 /* If this ..._DECL node is marked to be ignored, then ignore it. We
5138 gotta hope that the node in question doesn't represent a function
5139 definition. If it does, then totally ignoring it is bound to screw
5140 up our count of blocks, and that it turn will completely screw up the
5141 labels we will reference in subsequent AT_low_pc and AT_high_pc
5142 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
5143 don't carry their own sequence numbers with them!) */
5145 if (DECL_IGNORED_P (decl))
5147 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5152 switch (TREE_CODE (decl))
5156 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5157 a builtin function. Explicit programmer-supplied declarations of
5158 these same functions should NOT be ignored however. */
5160 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5163 /* What we would really like to do here is to filter out all mere
5164 file-scope declarations of file-scope functions which are never
5165 referenced later within this translation unit (and keep all of
5166 ones that *are* referenced later on) but we aren't clairvoyant,
5167 so we have no idea which functions will be referenced in the
5168 future (i.e. later on within the current translation unit).
5169 So here we just ignore all file-scope function declarations
5170 which are not also definitions. If and when the debugger needs
5171 to know something about these functions, it wil have to hunt
5172 around and find the DWARF information associated with the
5173 *definition* of the function.
5175 Note that we can't just check `DECL_EXTERNAL' to find out which
5176 FUNCTION_DECL nodes represent definitions and which ones represent
5177 mere declarations. We have to check `DECL_INITIAL' instead. That's
5178 because the C front-end supports some weird semantics for "extern
5179 inline" function definitions. These can get inlined within the
5180 current translation unit (an thus, we need to generate DWARF info
5181 for their abstract instances so that the DWARF info for the
5182 concrete inlined instances can have something to refer to) but
5183 the compiler never generates any out-of-lines instances of such
5184 things (despite the fact that they *are* definitions). The
5185 important point is that the C front-end marks these "extern inline"
5186 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5189 Note that the C++ front-end also plays some similar games for inline
5190 function definitions appearing within include files which also
5191 contain `#pragma interface' pragmas. */
5193 if (DECL_INITIAL (decl) == NULL_TREE)
5196 if (TREE_PUBLIC (decl)
5197 && ! DECL_EXTERNAL (decl)
5198 && ! DECL_ABSTRACT (decl))
5200 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5202 /* Output a .debug_pubnames entry for a public function
5203 defined in this compilation unit. */
5205 fputc ('\n', asm_out_file);
5206 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5207 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5208 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5209 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5210 IDENTIFIER_POINTER (DECL_NAME (decl)));
5211 ASM_OUTPUT_POP_SECTION (asm_out_file);
5218 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5219 object declaration and if the declaration was never even
5220 referenced from within this entire compilation unit. We
5221 suppress these DIEs in order to save space in the .debug section
5222 (by eliminating entries which are probably useless). Note that
5223 we must not suppress block-local extern declarations (whether
5224 used or not) because that would screw-up the debugger's name
5225 lookup mechanism and cause it to miss things which really ought
5226 to be in scope at a given point. */
5228 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5231 if (TREE_PUBLIC (decl)
5232 && ! DECL_EXTERNAL (decl)
5233 && GET_CODE (DECL_RTL (decl)) == MEM
5234 && ! DECL_ABSTRACT (decl))
5236 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5238 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5240 /* Output a .debug_pubnames entry for a public variable
5241 defined in this compilation unit. */
5243 fputc ('\n', asm_out_file);
5244 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5245 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5246 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5247 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5248 IDENTIFIER_POINTER (DECL_NAME (decl)));
5249 ASM_OUTPUT_POP_SECTION (asm_out_file);
5252 if (DECL_INITIAL (decl) == NULL)
5254 /* Output a .debug_aranges entry for a public variable
5255 which is tentatively defined in this compilation unit. */
5257 fputc ('\n', asm_out_file);
5258 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5259 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5260 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5261 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5262 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5263 ASM_OUTPUT_POP_SECTION (asm_out_file);
5267 /* If we are in terse mode, don't generate any DIEs to represent
5268 any variable declarations or definitions. */
5270 if (debug_info_level <= DINFO_LEVEL_TERSE)
5276 /* Don't bother trying to generate any DIEs to represent any of the
5277 normal built-in types for the language we are compiling, except
5278 in cases where the types in question are *not* DWARF fundamental
5279 types. We make an exception in the case of non-fundamental types
5280 for the sake of objective C (and perhaps C++) because the GNU
5281 front-ends for these languages may in fact create certain "built-in"
5282 types which are (for example) RECORD_TYPEs. In such cases, we
5283 really need to output these (non-fundamental) types because other
5284 DIEs may contain references to them. */
5286 /* Also ignore language dependent types here, because they are probably
5287 also built-in types. If we didn't ignore them, then we would get
5288 references to undefined labels because output_type doesn't support
5289 them. So, for now, we need to ignore them to avoid assembler
5292 /* ??? This code is different than the equivalent code in dwarf2out.c.
5293 The dwarf2out.c code is probably more correct. */
5295 if (DECL_SOURCE_LINE (decl) == 0
5296 && (type_is_fundamental (TREE_TYPE (decl))
5297 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5300 /* If we are in terse mode, don't generate any DIEs to represent
5301 any actual typedefs. Note that even when we are in terse mode,
5302 we must still output DIEs to represent those tagged types which
5303 are used (directly or indirectly) in the specification of either
5304 a return type or a formal parameter type of some function. */
5306 if (debug_info_level <= DINFO_LEVEL_TERSE)
5307 if (! TYPE_DECL_IS_STUB (decl)
5308 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5317 fputc ('\n', asm_out_file);
5318 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5319 finalizing = set_finalizing;
5320 output_decl (decl, NULL_TREE);
5322 /* NOTE: The call above to `output_decl' may have caused one or more
5323 file-scope named types (i.e. tagged types) to be placed onto the
5324 pending_types_list. We have to get those types off of that list
5325 at some point, and this is the perfect time to do it. If we didn't
5326 take them off now, they might still be on the list when cc1 finally
5327 exits. That might be OK if it weren't for the fact that when we put
5328 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5329 for these types, and that causes them never to be output unless
5330 `output_pending_types_for_scope' takes them off of the list and un-sets
5331 their TREE_ASM_WRITTEN flags. */
5333 output_pending_types_for_scope (NULL_TREE);
5335 /* The above call should have totally emptied the pending_types_list
5336 if this is not a nested function or class. If this is a nested type,
5337 then the remaining pending_types will be emitted when the containing type
5340 if (! DECL_CONTEXT (decl))
5342 if (pending_types != 0)
5346 ASM_OUTPUT_POP_SECTION (asm_out_file);
5348 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5349 current_funcdef_number++;
5352 /* Output a marker (i.e. a label) for the beginning of the generated code
5353 for a lexical block. */
5356 dwarfout_begin_block (blocknum)
5357 register unsigned blocknum;
5359 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5361 function_section (current_function_decl);
5362 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5363 ASM_OUTPUT_LABEL (asm_out_file, label);
5366 /* Output a marker (i.e. a label) for the end of the generated code
5367 for a lexical block. */
5370 dwarfout_end_block (blocknum)
5371 register unsigned blocknum;
5373 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5375 function_section (current_function_decl);
5376 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5377 ASM_OUTPUT_LABEL (asm_out_file, label);
5380 /* Output a marker (i.e. a label) at a point in the assembly code which
5381 corresponds to a given source level label. */
5384 dwarfout_label (insn)
5387 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5389 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5391 function_section (current_function_decl);
5392 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5393 (unsigned) INSN_UID (insn));
5394 ASM_OUTPUT_LABEL (asm_out_file, label);
5398 /* Output a marker (i.e. a label) for the point in the generated code where
5399 the real body of the function begins (after parameters have been moved
5400 to their home locations). */
5403 dwarfout_begin_function ()
5405 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5407 if (! use_gnu_debug_info_extensions)
5409 function_section (current_function_decl);
5410 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5411 ASM_OUTPUT_LABEL (asm_out_file, label);
5414 /* Output a marker (i.e. a label) for the point in the generated code where
5415 the real body of the function ends (just before the epilogue code). */
5418 dwarfout_end_function ()
5420 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5422 if (! use_gnu_debug_info_extensions)
5424 function_section (current_function_decl);
5425 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5426 ASM_OUTPUT_LABEL (asm_out_file, label);
5429 /* Output a marker (i.e. a label) for the absolute end of the generated code
5430 for a function definition. This gets called *after* the epilogue code
5431 has been generated. */
5434 dwarfout_end_epilogue ()
5436 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5438 /* Output a label to mark the endpoint of the code generated for this
5441 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5442 ASM_OUTPUT_LABEL (asm_out_file, label);
5446 shuffle_filename_entry (new_zeroth)
5447 register filename_entry *new_zeroth;
5449 filename_entry temp_entry;
5450 register filename_entry *limit_p;
5451 register filename_entry *move_p;
5453 if (new_zeroth == &filename_table[0])
5456 temp_entry = *new_zeroth;
5458 /* Shift entries up in the table to make room at [0]. */
5460 limit_p = &filename_table[0];
5461 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5462 *move_p = *(move_p-1);
5464 /* Install the found entry at [0]. */
5466 filename_table[0] = temp_entry;
5469 /* Create a new (string) entry for the .debug_sfnames section. */
5472 generate_new_sfname_entry ()
5474 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5476 fputc ('\n', asm_out_file);
5477 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5478 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5479 ASM_OUTPUT_LABEL (asm_out_file, label);
5480 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5481 filename_table[0].name
5482 ? filename_table[0].name
5484 ASM_OUTPUT_POP_SECTION (asm_out_file);
5487 /* Lookup a filename (in the list of filenames that we know about here in
5488 dwarfout.c) and return its "index". The index of each (known) filename
5489 is just a unique number which is associated with only that one filename.
5490 We need such numbers for the sake of generating labels (in the
5491 .debug_sfnames section) and references to those unique labels (in the
5492 .debug_srcinfo and .debug_macinfo sections).
5494 If the filename given as an argument is not found in our current list,
5495 add it to the list and assign it the next available unique index number.
5497 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5498 one), we shuffle the filename found (or added) up to the zeroth entry of
5499 our list of filenames (which is always searched linearly). We do this so
5500 as to optimize the most common case for these filename lookups within
5501 dwarfout.c. The most common case by far is the case where we call
5502 lookup_filename to lookup the very same filename that we did a lookup
5503 on the last time we called lookup_filename. We make sure that this
5504 common case is fast because such cases will constitute 99.9% of the
5505 lookups we ever do (in practice).
5507 If we add a new filename entry to our table, we go ahead and generate
5508 the corresponding entry in the .debug_sfnames section right away.
5509 Doing so allows us to avoid tickling an assembler bug (present in some
5510 m68k assemblers) which yields assembly-time errors in cases where the
5511 difference of two label addresses is taken and where the two labels
5512 are in a section *other* than the one where the difference is being
5513 calculated, and where at least one of the two symbol references is a
5514 forward reference. (This bug could be tickled by our .debug_srcinfo
5515 entries if we don't output their corresponding .debug_sfnames entries
5519 lookup_filename (file_name)
5522 register filename_entry *search_p;
5523 register filename_entry *limit_p = &filename_table[ft_entries];
5525 for (search_p = filename_table; search_p < limit_p; search_p++)
5526 if (!strcmp (file_name, search_p->name))
5528 /* When we get here, we have found the filename that we were
5529 looking for in the filename_table. Now we want to make sure
5530 that it gets moved to the zero'th entry in the table (if it
5531 is not already there) so that subsequent attempts to find the
5532 same filename will find it as quickly as possible. */
5534 shuffle_filename_entry (search_p);
5535 return filename_table[0].number;
5538 /* We come here whenever we have a new filename which is not registered
5539 in the current table. Here we add it to the table. */
5541 /* Prepare to add a new table entry by making sure there is enough space
5542 in the table to do so. If not, expand the current table. */
5544 if (ft_entries == ft_entries_allocated)
5546 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5548 = (filename_entry *)
5549 xrealloc (filename_table,
5550 ft_entries_allocated * sizeof (filename_entry));
5553 /* Initially, add the new entry at the end of the filename table. */
5555 filename_table[ft_entries].number = ft_entries;
5556 filename_table[ft_entries].name = xstrdup (file_name);
5558 /* Shuffle the new entry into filename_table[0]. */
5560 shuffle_filename_entry (&filename_table[ft_entries]);
5562 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5563 generate_new_sfname_entry ();
5566 return filename_table[0].number;
5570 generate_srcinfo_entry (line_entry_num, files_entry_num)
5571 unsigned line_entry_num;
5572 unsigned files_entry_num;
5574 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5576 fputc ('\n', asm_out_file);
5577 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5578 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5579 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5580 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5581 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5582 ASM_OUTPUT_POP_SECTION (asm_out_file);
5586 dwarfout_line (filename, line)
5587 register char *filename;
5588 register unsigned line;
5590 if (debug_info_level >= DINFO_LEVEL_NORMAL
5591 /* We can't emit line number info for functions in separate sections,
5592 because the assembler can't subtract labels in different sections. */
5593 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5595 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5596 static unsigned last_line_entry_num = 0;
5597 static unsigned prev_file_entry_num = (unsigned) -1;
5598 register unsigned this_file_entry_num;
5600 function_section (current_function_decl);
5601 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5602 ASM_OUTPUT_LABEL (asm_out_file, label);
5604 fputc ('\n', asm_out_file);
5606 if (use_gnu_debug_info_extensions)
5607 this_file_entry_num = lookup_filename (filename);
5609 this_file_entry_num = (unsigned) -1;
5611 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5612 if (this_file_entry_num != prev_file_entry_num)
5614 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5616 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5617 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5621 register char *tail = rindex (filename, '/');
5627 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5628 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5630 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5631 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5632 ASM_OUTPUT_POP_SECTION (asm_out_file);
5634 if (this_file_entry_num != prev_file_entry_num)
5635 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5636 prev_file_entry_num = this_file_entry_num;
5640 /* Generate an entry in the .debug_macinfo section. */
5643 generate_macinfo_entry (type_and_offset, string)
5644 register char *type_and_offset;
5645 register char *string;
5647 if (! use_gnu_debug_info_extensions)
5650 fputc ('\n', asm_out_file);
5651 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5652 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5653 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
5654 ASM_OUTPUT_POP_SECTION (asm_out_file);
5658 dwarfout_start_new_source_file (filename)
5659 register char *filename;
5661 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5662 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5664 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5665 sprintf (type_and_offset, "0x%08x+%s-%s",
5666 ((unsigned) MACINFO_start << 24),
5667 /* Hack: skip leading '*' . */
5668 (*label == '*') + label,
5669 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5670 generate_macinfo_entry (type_and_offset, "");
5674 dwarfout_resume_previous_source_file (lineno)
5675 register unsigned lineno;
5677 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5679 sprintf (type_and_offset, "0x%08x+%u",
5680 ((unsigned) MACINFO_resume << 24), lineno);
5681 generate_macinfo_entry (type_and_offset, "");
5684 /* Called from check_newline in c-parse.y. The `buffer' parameter
5685 contains the tail part of the directive line, i.e. the part which
5686 is past the initial whitespace, #, whitespace, directive-name,
5690 dwarfout_define (lineno, buffer)
5691 register unsigned lineno;
5692 register char *buffer;
5694 static int initialized = 0;
5695 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5699 dwarfout_start_new_source_file (primary_filename);
5702 sprintf (type_and_offset, "0x%08x+%u",
5703 ((unsigned) MACINFO_define << 24), lineno);
5704 generate_macinfo_entry (type_and_offset, buffer);
5707 /* Called from check_newline in c-parse.y. The `buffer' parameter
5708 contains the tail part of the directive line, i.e. the part which
5709 is past the initial whitespace, #, whitespace, directive-name,
5713 dwarfout_undef (lineno, buffer)
5714 register unsigned lineno;
5715 register char *buffer;
5717 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5719 sprintf (type_and_offset, "0x%08x+%u",
5720 ((unsigned) MACINFO_undef << 24), lineno);
5721 generate_macinfo_entry (type_and_offset, buffer);
5724 /* Set up for Dwarf output at the start of compilation. */
5727 dwarfout_init (asm_out_file, main_input_filename)
5728 register FILE *asm_out_file;
5729 register char *main_input_filename;
5731 /* Remember the name of the primary input file. */
5733 primary_filename = main_input_filename;
5735 /* Allocate the initial hunk of the pending_sibling_stack. */
5737 pending_sibling_stack
5739 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5740 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5741 pending_siblings = 1;
5743 /* Allocate the initial hunk of the filename_table. */
5746 = (filename_entry *)
5747 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5748 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5751 /* Allocate the initial hunk of the pending_types_list. */
5754 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5755 pending_types_allocated = PENDING_TYPES_INCREMENT;
5758 /* Create an artificial RECORD_TYPE node which we can use in our hack
5759 to get the DIEs representing types of formal parameters to come out
5760 only *after* the DIEs for the formal parameters themselves. */
5762 fake_containing_scope = make_node (RECORD_TYPE);
5764 /* Output a starting label for the .text section. */
5766 fputc ('\n', asm_out_file);
5767 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5768 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5769 ASM_OUTPUT_POP_SECTION (asm_out_file);
5771 /* Output a starting label for the .data section. */
5773 fputc ('\n', asm_out_file);
5774 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5775 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5776 ASM_OUTPUT_POP_SECTION (asm_out_file);
5778 #if 0 /* GNU C doesn't currently use .data1. */
5779 /* Output a starting label for the .data1 section. */
5781 fputc ('\n', asm_out_file);
5782 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5783 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5784 ASM_OUTPUT_POP_SECTION (asm_out_file);
5787 /* Output a starting label for the .rodata section. */
5789 fputc ('\n', asm_out_file);
5790 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5791 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5792 ASM_OUTPUT_POP_SECTION (asm_out_file);
5794 #if 0 /* GNU C doesn't currently use .rodata1. */
5795 /* Output a starting label for the .rodata1 section. */
5797 fputc ('\n', asm_out_file);
5798 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5799 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5800 ASM_OUTPUT_POP_SECTION (asm_out_file);
5803 /* Output a starting label for the .bss section. */
5805 fputc ('\n', asm_out_file);
5806 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5807 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5808 ASM_OUTPUT_POP_SECTION (asm_out_file);
5810 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5812 if (use_gnu_debug_info_extensions)
5814 /* Output a starting label and an initial (compilation directory)
5815 entry for the .debug_sfnames section. The starting label will be
5816 referenced by the initial entry in the .debug_srcinfo section. */
5818 fputc ('\n', asm_out_file);
5819 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5820 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5823 register unsigned len;
5824 register char *dirname;
5828 pfatal_with_name ("getpwd");
5830 dirname = (char *) xmalloc (len + 2);
5832 strcpy (dirname, pwd);
5833 strcpy (dirname + len, "/");
5834 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
5837 ASM_OUTPUT_POP_SECTION (asm_out_file);
5840 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5841 && use_gnu_debug_info_extensions)
5843 /* Output a starting label for the .debug_macinfo section. This
5844 label will be referenced by the AT_mac_info attribute in the
5845 TAG_compile_unit DIE. */
5847 fputc ('\n', asm_out_file);
5848 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5849 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5850 ASM_OUTPUT_POP_SECTION (asm_out_file);
5853 /* Generate the initial entry for the .line section. */
5855 fputc ('\n', asm_out_file);
5856 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5857 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5858 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5859 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5860 ASM_OUTPUT_POP_SECTION (asm_out_file);
5862 if (use_gnu_debug_info_extensions)
5864 /* Generate the initial entry for the .debug_srcinfo section. */
5866 fputc ('\n', asm_out_file);
5867 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5868 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5869 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5870 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5871 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5872 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5873 #ifdef DWARF_TIMESTAMPS
5874 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5876 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5878 ASM_OUTPUT_POP_SECTION (asm_out_file);
5881 /* Generate the initial entry for the .debug_pubnames section. */
5883 fputc ('\n', asm_out_file);
5884 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5885 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5886 ASM_OUTPUT_POP_SECTION (asm_out_file);
5888 /* Generate the initial entry for the .debug_aranges section. */
5890 fputc ('\n', asm_out_file);
5891 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5892 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5893 ASM_OUTPUT_POP_SECTION (asm_out_file);
5896 /* Setup first DIE number == 1. */
5897 NEXT_DIE_NUM = next_unused_dienum++;
5899 /* Generate the initial DIE for the .debug section. Note that the
5900 (string) value given in the AT_name attribute of the TAG_compile_unit
5901 DIE will (typically) be a relative pathname and that this pathname
5902 should be taken as being relative to the directory from which the
5903 compiler was invoked when the given (base) source file was compiled. */
5905 fputc ('\n', asm_out_file);
5906 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5907 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5908 output_die (output_compile_unit_die, main_input_filename);
5909 ASM_OUTPUT_POP_SECTION (asm_out_file);
5911 fputc ('\n', asm_out_file);
5914 /* Output stuff that dwarf requires at the end of every file. */
5919 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5921 retry_incomplete_types ();
5923 fputc ('\n', asm_out_file);
5924 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5926 /* Mark the end of the chain of siblings which represent all file-scope
5927 declarations in this compilation unit. */
5929 /* The (null) DIE which represents the terminator for the (sibling linked)
5930 list of file-scope items is *special*. Normally, we would just call
5931 end_sibling_chain at this point in order to output a word with the
5932 value `4' and that word would act as the terminator for the list of
5933 DIEs describing file-scope items. Unfortunately, if we were to simply
5934 do that, the label that would follow this DIE in the .debug section
5935 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5936 machines) to a 4 byte boundary.
5938 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5939 the trick used is to insert extra (otherwise useless) padding bytes
5940 into the (null) DIE that we know must precede the ..D2 label in the
5941 .debug section. The amount of padding required can be anywhere between
5942 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5943 with the padding) would normally contain the value 4, but now it will
5944 also have to include the padding bytes, so it will instead have some
5945 value in the range 4..7.
5947 Fortunately, the rules of Dwarf say that any DIE whose length word
5948 contains *any* value less than 8 should be treated as a null DIE, so
5949 this trick works out nicely. Clever, eh? Don't give me any credit
5950 (or blame). I didn't think of this scheme. I just conformed to it.
5953 output_die (output_padded_null_die, (void *) 0);
5956 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5957 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5958 ASM_OUTPUT_POP_SECTION (asm_out_file);
5960 /* Output a terminator label for the .text section. */
5962 fputc ('\n', asm_out_file);
5963 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5964 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5965 ASM_OUTPUT_POP_SECTION (asm_out_file);
5967 /* Output a terminator label for the .data section. */
5969 fputc ('\n', asm_out_file);
5970 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5971 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5972 ASM_OUTPUT_POP_SECTION (asm_out_file);
5974 #if 0 /* GNU C doesn't currently use .data1. */
5975 /* Output a terminator label for the .data1 section. */
5977 fputc ('\n', asm_out_file);
5978 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5979 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5980 ASM_OUTPUT_POP_SECTION (asm_out_file);
5983 /* Output a terminator label for the .rodata section. */
5985 fputc ('\n', asm_out_file);
5986 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5987 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5988 ASM_OUTPUT_POP_SECTION (asm_out_file);
5990 #if 0 /* GNU C doesn't currently use .rodata1. */
5991 /* Output a terminator label for the .rodata1 section. */
5993 fputc ('\n', asm_out_file);
5994 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5995 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5996 ASM_OUTPUT_POP_SECTION (asm_out_file);
5999 /* Output a terminator label for the .bss section. */
6001 fputc ('\n', asm_out_file);
6002 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
6003 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
6004 ASM_OUTPUT_POP_SECTION (asm_out_file);
6006 if (debug_info_level >= DINFO_LEVEL_NORMAL)
6008 /* Output a terminating entry for the .line section. */
6010 fputc ('\n', asm_out_file);
6011 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
6012 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
6013 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6014 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
6015 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6016 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
6017 ASM_OUTPUT_POP_SECTION (asm_out_file);
6019 if (use_gnu_debug_info_extensions)
6021 /* Output a terminating entry for the .debug_srcinfo section. */
6023 fputc ('\n', asm_out_file);
6024 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
6025 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6026 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6027 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6028 ASM_OUTPUT_POP_SECTION (asm_out_file);
6031 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6033 /* Output terminating entries for the .debug_macinfo section. */
6035 dwarfout_resume_previous_source_file (0);
6037 fputc ('\n', asm_out_file);
6038 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
6039 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6040 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6041 ASM_OUTPUT_POP_SECTION (asm_out_file);
6044 /* Generate the terminating entry for the .debug_pubnames section. */
6046 fputc ('\n', asm_out_file);
6047 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
6048 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6049 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6050 ASM_OUTPUT_POP_SECTION (asm_out_file);
6052 /* Generate the terminating entries for the .debug_aranges section.
6054 Note that we want to do this only *after* we have output the end
6055 labels (for the various program sections) which we are going to
6056 refer to here. This allows us to work around a bug in the m68k
6057 svr4 assembler. That assembler gives bogus assembly-time errors
6058 if (within any given section) you try to take the difference of
6059 two relocatable symbols, both of which are located within some
6060 other section, and if one (or both?) of the symbols involved is
6061 being forward-referenced. By generating the .debug_aranges
6062 entries at this late point in the assembly output, we skirt the
6063 issue simply by avoiding forward-references.
6066 fputc ('\n', asm_out_file);
6067 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
6069 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6070 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6072 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6073 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6075 #if 0 /* GNU C doesn't currently use .data1. */
6076 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6077 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6081 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6082 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6083 RODATA_BEGIN_LABEL);
6085 #if 0 /* GNU C doesn't currently use .rodata1. */
6086 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6087 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6088 RODATA1_BEGIN_LABEL);
6091 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6092 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6094 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6095 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6097 ASM_OUTPUT_POP_SECTION (asm_out_file);
6100 /* There should not be any pending types left at the end. We need
6101 this now because it may not have been checked on the last call to
6102 dwarfout_file_scope_decl. */
6103 if (pending_types != 0)
6107 #endif /* DWARF_DEBUGGING_INFO */