1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #ifdef DWARF_DEBUGGING_INFO
31 #include "hard-reg-set.h"
32 #include "insn-config.h"
40 #if defined(DWARF_TIMESTAMPS)
42 extern time_t time PARAMS ((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 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
56 regarding the GNU implementation of Dwarf. */
58 /* NOTE: In the comments in this file, many references are made to
59 so called "Debugging Information Entries". For the sake of brevity,
60 this term is abbreviated to `DIE' throughout the remainder of this
63 /* Note that the implementation of C++ support herein is (as yet) unfinished.
64 If you want to try to complete it, more power to you. */
66 /* How to start an assembler comment. */
67 #ifndef ASM_COMMENT_START
68 #define ASM_COMMENT_START ";#"
71 /* How to print out a register name. */
73 #define PRINT_REG(RTX, CODE, FILE) \
74 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
77 /* Define a macro which returns non-zero for any tagged type which is
78 used (directly or indirectly) in the specification of either some
79 function's return type or some formal parameter of some function.
80 We use this macro when we are operating in "terse" mode to help us
81 know what tagged types have to be represented in Dwarf (even in
82 terse mode) and which ones don't.
84 A flag bit with this meaning really should be a part of the normal
85 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
86 for these nodes. For now, we have to just fake it. It it safe for
87 us to simply return zero for all complete tagged types (which will
88 get forced out anyway if they were used in the specification of some
89 formal or return type) and non-zero for all incomplete tagged types.
92 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
94 /* Define a macro which returns non-zero for a TYPE_DECL which was
95 implicitly generated for a tagged type.
97 Note that unlike the gcc front end (which generates a NULL named
98 TYPE_DECL node for each complete tagged type, each array type, and
99 each function type node created) the g++ front end generates a
100 _named_ TYPE_DECL node for each tagged type node created.
101 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
102 generate a DW_TAG_typedef DIE for them. */
103 #define TYPE_DECL_IS_STUB(decl) \
104 (DECL_NAME (decl) == NULL \
105 || (DECL_ARTIFICIAL (decl) \
106 && is_tagged_type (TREE_TYPE (decl)) \
107 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
109 extern int flag_traditional;
111 /* Maximum size (in bytes) of an artificially generated label. */
113 #define MAX_ARTIFICIAL_LABEL_BYTES 30
115 /* Make sure we know the sizes of the various types dwarf can describe.
116 These are only defaults. If the sizes are different for your target,
117 you should override these values by defining the appropriate symbols
118 in your tm.h file. */
120 #ifndef CHAR_TYPE_SIZE
121 #define CHAR_TYPE_SIZE BITS_PER_UNIT
124 #ifndef SHORT_TYPE_SIZE
125 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
128 #ifndef INT_TYPE_SIZE
129 #define INT_TYPE_SIZE BITS_PER_WORD
132 #ifndef LONG_TYPE_SIZE
133 #define LONG_TYPE_SIZE BITS_PER_WORD
136 #ifndef LONG_LONG_TYPE_SIZE
137 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
140 #ifndef WCHAR_TYPE_SIZE
141 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
144 #ifndef WCHAR_UNSIGNED
145 #define WCHAR_UNSIGNED 0
148 #ifndef FLOAT_TYPE_SIZE
149 #define FLOAT_TYPE_SIZE BITS_PER_WORD
152 #ifndef DOUBLE_TYPE_SIZE
153 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
156 #ifndef LONG_DOUBLE_TYPE_SIZE
157 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
160 /* Structure to keep track of source filenames. */
162 struct filename_entry {
167 typedef struct filename_entry filename_entry;
169 /* Pointer to an array of elements, each one having the structure above. */
171 static filename_entry *filename_table;
173 /* Total number of entries in the table (i.e. array) pointed to by
174 `filename_table'. This is the *total* and includes both used and
177 static unsigned ft_entries_allocated;
179 /* Number of entries in the filename_table which are actually in use. */
181 static unsigned ft_entries;
183 /* Size (in elements) of increments by which we may expand the filename
184 table. Actually, a single hunk of space of this size should be enough
185 for most typical programs. */
187 #define FT_ENTRIES_INCREMENT 64
189 /* Local pointer to the name of the main input file. Initialized in
192 static char *primary_filename;
194 /* Pointer to the most recent filename for which we produced some line info. */
196 static char *last_filename;
198 /* Counter to generate unique names for DIEs. */
200 static unsigned next_unused_dienum = 1;
202 /* Number of the DIE which is currently being generated. */
204 static unsigned current_dienum;
206 /* Number to use for the special "pubname" label on the next DIE which
207 represents a function or data object defined in this compilation
208 unit which has "extern" linkage. */
210 static int next_pubname_number = 0;
212 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
214 /* Pointer to a dynamically allocated list of pre-reserved and still
215 pending sibling DIE numbers. Note that this list will grow as needed. */
217 static unsigned *pending_sibling_stack;
219 /* Counter to keep track of the number of pre-reserved and still pending
220 sibling DIE numbers. */
222 static unsigned pending_siblings;
224 /* The currently allocated size of the above list (expressed in number of
227 static unsigned pending_siblings_allocated;
229 /* Size (in elements) of increments by which we may expand the pending
230 sibling stack. Actually, a single hunk of space of this size should
231 be enough for most typical programs. */
233 #define PENDING_SIBLINGS_INCREMENT 64
235 /* Non-zero if we are performing our file-scope finalization pass and if
236 we should force out Dwarf descriptions of any and all file-scope
237 tagged types which are still incomplete types. */
239 static int finalizing = 0;
241 /* A pointer to the base of a list of pending types which we haven't
242 generated DIEs for yet, but which we will have to come back to
245 static tree *pending_types_list;
247 /* Number of elements currently allocated for the pending_types_list. */
249 static unsigned pending_types_allocated;
251 /* Number of elements of pending_types_list currently in use. */
253 static unsigned pending_types;
255 /* Size (in elements) of increments by which we may expand the pending
256 types list. Actually, a single hunk of space of this size should
257 be enough for most typical programs. */
259 #define PENDING_TYPES_INCREMENT 64
261 /* A pointer to the base of a list of incomplete types which might be
262 completed at some later time. */
264 static tree *incomplete_types_list;
266 /* Number of elements currently allocated for the incomplete_types_list. */
267 static unsigned incomplete_types_allocated;
269 /* Number of elements of incomplete_types_list currently in use. */
270 static unsigned incomplete_types;
272 /* Size (in elements) of increments by which we may expand the incomplete
273 types list. Actually, a single hunk of space of this size should
274 be enough for most typical programs. */
275 #define INCOMPLETE_TYPES_INCREMENT 64
277 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
278 This is used in a hack to help us get the DIEs describing types of
279 formal parameters to come *after* all of the DIEs describing the formal
280 parameters themselves. That's necessary in order to be compatible
281 with what the brain-damaged svr4 SDB debugger requires. */
283 static tree fake_containing_scope;
285 /* The number of the current function definition that we are generating
286 debugging information for. These numbers range from 1 up to the maximum
287 number of function definitions contained within the current compilation
288 unit. These numbers are used to create unique labels for various things
289 contained within various function definitions. */
291 static unsigned current_funcdef_number = 1;
293 /* A pointer to the ..._DECL node which we have most recently been working
294 on. We keep this around just in case something about it looks screwy
295 and we want to tell the user what the source coordinates for the actual
298 static tree dwarf_last_decl;
300 /* A flag indicating that we are emitting the member declarations of a
301 class, so member functions and variables should not be entirely emitted.
302 This is a kludge to avoid passing a second argument to output_*_die. */
306 /* Forward declarations for functions defined in this file. */
308 static const char *dwarf_tag_name PARAMS ((unsigned));
309 static const char *dwarf_attr_name PARAMS ((unsigned));
310 static const char *dwarf_stack_op_name PARAMS ((unsigned));
311 static const char *dwarf_typemod_name PARAMS ((unsigned));
312 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
313 static const char *dwarf_fund_type_name PARAMS ((unsigned));
314 static tree decl_ultimate_origin PARAMS ((tree));
315 static tree block_ultimate_origin PARAMS ((tree));
316 static tree decl_class_context PARAMS ((tree));
318 static void output_unsigned_leb128 PARAMS ((unsigned long));
319 static void output_signed_leb128 PARAMS ((long));
321 static inline int is_body_block PARAMS ((tree));
322 static int fundamental_type_code PARAMS ((tree));
323 static tree root_type_1 PARAMS ((tree, int));
324 static tree root_type PARAMS ((tree));
325 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
326 static void write_modifier_bytes PARAMS ((tree, int, int));
327 static inline int type_is_fundamental PARAMS ((tree));
328 static void equate_decl_number_to_die_number PARAMS ((tree));
329 static inline void equate_type_number_to_die_number PARAMS ((tree));
330 static void output_reg_number PARAMS ((rtx));
331 static void output_mem_loc_descriptor PARAMS ((rtx));
332 static void output_loc_descriptor PARAMS ((rtx));
333 static void output_bound_representation PARAMS ((tree, unsigned, int));
334 static void output_enumeral_list PARAMS ((tree));
335 static inline unsigned ceiling PARAMS ((unsigned, unsigned));
336 static inline tree field_type PARAMS ((tree));
337 static inline unsigned simple_type_align_in_bits PARAMS ((tree));
338 static inline unsigned simple_type_size_in_bits PARAMS ((tree));
339 static unsigned field_byte_offset PARAMS ((tree));
340 static inline void sibling_attribute PARAMS ((void));
341 static void location_attribute PARAMS ((rtx));
342 static void data_member_location_attribute PARAMS ((tree));
343 static void const_value_attribute PARAMS ((rtx));
344 static void location_or_const_value_attribute PARAMS ((tree));
345 static inline void name_attribute PARAMS ((const char *));
346 static inline void fund_type_attribute PARAMS ((unsigned));
347 static void mod_fund_type_attribute PARAMS ((tree, int, int));
348 static inline void user_def_type_attribute PARAMS ((tree));
349 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
350 #ifdef USE_ORDERING_ATTRIBUTE
351 static inline void ordering_attribute PARAMS ((unsigned));
352 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
353 static void subscript_data_attribute PARAMS ((tree));
354 static void byte_size_attribute PARAMS ((tree));
355 static inline void bit_offset_attribute PARAMS ((tree));
356 static inline void bit_size_attribute PARAMS ((tree));
357 static inline void element_list_attribute PARAMS ((tree));
358 static inline void stmt_list_attribute PARAMS ((const char *));
359 static inline void low_pc_attribute PARAMS ((const char *));
360 static inline void high_pc_attribute PARAMS ((const char *));
361 static inline void body_begin_attribute PARAMS ((const char *));
362 static inline void body_end_attribute PARAMS ((const char *));
363 static inline void language_attribute PARAMS ((unsigned));
364 static inline void member_attribute PARAMS ((tree));
366 static inline void string_length_attribute PARAMS ((tree));
368 static inline void comp_dir_attribute PARAMS ((const char *));
369 static inline void sf_names_attribute PARAMS ((const char *));
370 static inline void src_info_attribute PARAMS ((const char *));
371 static inline void mac_info_attribute PARAMS ((const char *));
372 static inline void prototyped_attribute PARAMS ((tree));
373 static inline void producer_attribute PARAMS ((const char *));
374 static inline void inline_attribute PARAMS ((tree));
375 static inline void containing_type_attribute PARAMS ((tree));
376 static inline void abstract_origin_attribute PARAMS ((tree));
377 #ifdef DWARF_DECL_COORDINATES
378 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
379 #endif /* defined(DWARF_DECL_COORDINATES) */
380 static inline void pure_or_virtual_attribute PARAMS ((tree));
381 static void name_and_src_coords_attributes PARAMS ((tree));
382 static void type_attribute PARAMS ((tree, int, int));
383 static char *type_tag PARAMS ((tree));
384 static inline void dienum_push PARAMS ((void));
385 static inline void dienum_pop PARAMS ((void));
386 static inline tree member_declared_type PARAMS ((tree));
387 static char *function_start_label PARAMS ((tree));
388 static void output_array_type_die PARAMS ((void *));
389 static void output_set_type_die PARAMS ((void *));
391 static void output_entry_point_die PARAMS ((void *));
393 static void output_inlined_enumeration_type_die PARAMS ((void *));
394 static void output_inlined_structure_type_die PARAMS ((void *));
395 static void output_inlined_union_type_die PARAMS ((void *));
396 static void output_enumeration_type_die PARAMS ((void *));
397 static void output_formal_parameter_die PARAMS ((void *));
398 static void output_global_subroutine_die PARAMS ((void *));
399 static void output_global_variable_die PARAMS ((void *));
400 static void output_label_die PARAMS ((void *));
401 static void output_lexical_block_die PARAMS ((void *));
402 static void output_inlined_subroutine_die PARAMS ((void *));
403 static void output_local_variable_die PARAMS ((void *));
404 static void output_member_die PARAMS ((void *));
406 static void output_pointer_type_die PARAMS ((void *));
407 static void output_reference_type_die PARAMS ((void *));
409 static void output_ptr_to_mbr_type_die PARAMS ((void *));
410 static void output_compile_unit_die PARAMS ((void *));
411 static void output_string_type_die PARAMS ((void *));
412 static void output_inheritance_die PARAMS ((void *));
413 static void output_structure_type_die PARAMS ((void *));
414 static void output_local_subroutine_die PARAMS ((void *));
415 static void output_subroutine_type_die PARAMS ((void *));
416 static void output_typedef_die PARAMS ((void *));
417 static void output_union_type_die PARAMS ((void *));
418 static void output_unspecified_parameters_die PARAMS ((void *));
419 static void output_padded_null_die PARAMS ((void *));
420 static void output_die PARAMS ((void (*)(void *), void *));
421 static void end_sibling_chain PARAMS ((void));
422 static void output_formal_types PARAMS ((tree));
423 static void pend_type PARAMS ((tree));
424 static int type_ok_for_scope PARAMS ((tree, tree));
425 static void output_pending_types_for_scope PARAMS ((tree));
426 static void output_type PARAMS ((tree, tree));
427 static void output_tagged_type_instantiation PARAMS ((tree));
428 static void output_block PARAMS ((tree, int));
429 static void output_decls_for_scope PARAMS ((tree, int));
430 static void output_decl PARAMS ((tree, tree));
431 static void shuffle_filename_entry PARAMS ((filename_entry *));
432 static void generate_new_sfname_entry PARAMS ((void));
433 static unsigned lookup_filename PARAMS ((const char *));
434 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
435 static void generate_macinfo_entry PARAMS ((const char *, const char *));
436 static int is_pseudo_reg PARAMS ((rtx));
437 static tree type_main_variant PARAMS ((tree));
438 static int is_tagged_type PARAMS ((tree));
439 static int is_redundant_typedef PARAMS ((tree));
440 static void add_incomplete_type PARAMS ((tree));
441 static void retry_incomplete_types PARAMS ((void));
443 /* Definitions of defaults for assembler-dependent names of various
444 pseudo-ops and section names.
446 Theses may be overridden in your tm.h file (if necessary) for your
447 particular assembler. The default values provided here correspond to
448 what is expected by "standard" AT&T System V.4 assemblers. */
451 #define FILE_ASM_OP ".file"
453 #ifndef VERSION_ASM_OP
454 #define VERSION_ASM_OP ".version"
456 #ifndef UNALIGNED_SHORT_ASM_OP
457 #define UNALIGNED_SHORT_ASM_OP ".2byte"
459 #ifndef UNALIGNED_INT_ASM_OP
460 #define UNALIGNED_INT_ASM_OP ".4byte"
463 #define ASM_BYTE_OP ".byte"
466 #define SET_ASM_OP ".set"
469 /* Pseudo-ops for pushing the current section onto the section stack (and
470 simultaneously changing to a new section) and for poping back to the
471 section we were in immediately before this one. Note that most svr4
472 assemblers only maintain a one level stack... you can push all the
473 sections you want, but you can only pop out one level. (The sparc
474 svr4 assembler is an exception to this general rule.) That's
475 OK because we only use at most one level of the section stack herein. */
477 #ifndef PUSHSECTION_ASM_OP
478 #define PUSHSECTION_ASM_OP ".section"
480 #ifndef POPSECTION_ASM_OP
481 #define POPSECTION_ASM_OP ".previous"
484 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
485 to print the PUSHSECTION_ASM_OP and the section name. The default here
486 works for almost all svr4 assemblers, except for the sparc, where the
487 section name must be enclosed in double quotes. (See sparcv4.h.) */
489 #ifndef PUSHSECTION_FORMAT
490 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
493 #ifndef DEBUG_SECTION
494 #define DEBUG_SECTION ".debug"
497 #define LINE_SECTION ".line"
499 #ifndef SFNAMES_SECTION
500 #define SFNAMES_SECTION ".debug_sfnames"
502 #ifndef SRCINFO_SECTION
503 #define SRCINFO_SECTION ".debug_srcinfo"
505 #ifndef MACINFO_SECTION
506 #define MACINFO_SECTION ".debug_macinfo"
508 #ifndef PUBNAMES_SECTION
509 #define PUBNAMES_SECTION ".debug_pubnames"
511 #ifndef ARANGES_SECTION
512 #define ARANGES_SECTION ".debug_aranges"
515 #define TEXT_SECTION ".text"
518 #define DATA_SECTION ".data"
520 #ifndef DATA1_SECTION
521 #define DATA1_SECTION ".data1"
523 #ifndef RODATA_SECTION
524 #define RODATA_SECTION ".rodata"
526 #ifndef RODATA1_SECTION
527 #define RODATA1_SECTION ".rodata1"
530 #define BSS_SECTION ".bss"
533 /* Definitions of defaults for formats and names of various special
534 (artificial) labels which may be generated within this file (when
535 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
537 If necessary, these may be overridden from within your tm.h file,
538 but typically, you should never need to override these.
540 These labels have been hacked (temporarily) so that they all begin with
541 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
542 stock m88k/svr4 assembler, both of which need to see .L at the start of
543 a label in order to prevent that label from going into the linker symbol
544 table). When I get time, I'll have to fix this the right way so that we
545 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
546 but that will require a rather massive set of changes. For the moment,
547 the following definitions out to produce the right results for all svr4
548 and svr3 assemblers. -- rfg
551 #ifndef TEXT_BEGIN_LABEL
552 #define TEXT_BEGIN_LABEL "*.L_text_b"
554 #ifndef TEXT_END_LABEL
555 #define TEXT_END_LABEL "*.L_text_e"
558 #ifndef DATA_BEGIN_LABEL
559 #define DATA_BEGIN_LABEL "*.L_data_b"
561 #ifndef DATA_END_LABEL
562 #define DATA_END_LABEL "*.L_data_e"
565 #ifndef DATA1_BEGIN_LABEL
566 #define DATA1_BEGIN_LABEL "*.L_data1_b"
568 #ifndef DATA1_END_LABEL
569 #define DATA1_END_LABEL "*.L_data1_e"
572 #ifndef RODATA_BEGIN_LABEL
573 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
575 #ifndef RODATA_END_LABEL
576 #define RODATA_END_LABEL "*.L_rodata_e"
579 #ifndef RODATA1_BEGIN_LABEL
580 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
582 #ifndef RODATA1_END_LABEL
583 #define RODATA1_END_LABEL "*.L_rodata1_e"
586 #ifndef BSS_BEGIN_LABEL
587 #define BSS_BEGIN_LABEL "*.L_bss_b"
589 #ifndef BSS_END_LABEL
590 #define BSS_END_LABEL "*.L_bss_e"
593 #ifndef LINE_BEGIN_LABEL
594 #define LINE_BEGIN_LABEL "*.L_line_b"
596 #ifndef LINE_LAST_ENTRY_LABEL
597 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
599 #ifndef LINE_END_LABEL
600 #define LINE_END_LABEL "*.L_line_e"
603 #ifndef DEBUG_BEGIN_LABEL
604 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
606 #ifndef SFNAMES_BEGIN_LABEL
607 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
609 #ifndef SRCINFO_BEGIN_LABEL
610 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
612 #ifndef MACINFO_BEGIN_LABEL
613 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
616 #ifndef DIE_BEGIN_LABEL_FMT
617 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
619 #ifndef DIE_END_LABEL_FMT
620 #define DIE_END_LABEL_FMT "*.L_D%u_e"
622 #ifndef PUB_DIE_LABEL_FMT
623 #define PUB_DIE_LABEL_FMT "*.L_P%u"
625 #ifndef INSN_LABEL_FMT
626 #define INSN_LABEL_FMT "*.L_I%u_%u"
628 #ifndef BLOCK_BEGIN_LABEL_FMT
629 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
631 #ifndef BLOCK_END_LABEL_FMT
632 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
634 #ifndef SS_BEGIN_LABEL_FMT
635 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
637 #ifndef SS_END_LABEL_FMT
638 #define SS_END_LABEL_FMT "*.L_s%u_e"
640 #ifndef EE_BEGIN_LABEL_FMT
641 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
643 #ifndef EE_END_LABEL_FMT
644 #define EE_END_LABEL_FMT "*.L_e%u_e"
646 #ifndef MT_BEGIN_LABEL_FMT
647 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
649 #ifndef MT_END_LABEL_FMT
650 #define MT_END_LABEL_FMT "*.L_t%u_e"
652 #ifndef LOC_BEGIN_LABEL_FMT
653 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
655 #ifndef LOC_END_LABEL_FMT
656 #define LOC_END_LABEL_FMT "*.L_l%u_e"
658 #ifndef BOUND_BEGIN_LABEL_FMT
659 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
661 #ifndef BOUND_END_LABEL_FMT
662 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
664 #ifndef DERIV_BEGIN_LABEL_FMT
665 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
667 #ifndef DERIV_END_LABEL_FMT
668 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
670 #ifndef SL_BEGIN_LABEL_FMT
671 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
673 #ifndef SL_END_LABEL_FMT
674 #define SL_END_LABEL_FMT "*.L_sl%u_e"
676 #ifndef BODY_BEGIN_LABEL_FMT
677 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
679 #ifndef BODY_END_LABEL_FMT
680 #define BODY_END_LABEL_FMT "*.L_b%u_e"
682 #ifndef FUNC_END_LABEL_FMT
683 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
685 #ifndef TYPE_NAME_FMT
686 #define TYPE_NAME_FMT "*.L_T%u"
688 #ifndef DECL_NAME_FMT
689 #define DECL_NAME_FMT "*.L_E%u"
691 #ifndef LINE_CODE_LABEL_FMT
692 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
694 #ifndef SFNAMES_ENTRY_LABEL_FMT
695 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
697 #ifndef LINE_ENTRY_LABEL_FMT
698 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
701 /* Definitions of defaults for various types of primitive assembly language
704 If necessary, these may be overridden from within your tm.h file,
705 but typically, you shouldn't need to override these. */
707 #ifndef ASM_OUTPUT_PUSH_SECTION
708 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
709 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
712 #ifndef ASM_OUTPUT_POP_SECTION
713 #define ASM_OUTPUT_POP_SECTION(FILE) \
714 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
717 #ifndef ASM_OUTPUT_DWARF_DELTA2
718 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
719 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
720 assemble_name (FILE, LABEL1); \
721 fprintf (FILE, "-"); \
722 assemble_name (FILE, LABEL2); \
723 fprintf (FILE, "\n"); \
727 #ifndef ASM_OUTPUT_DWARF_DELTA4
728 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
729 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
730 assemble_name (FILE, LABEL1); \
731 fprintf (FILE, "-"); \
732 assemble_name (FILE, LABEL2); \
733 fprintf (FILE, "\n"); \
737 #ifndef ASM_OUTPUT_DWARF_TAG
738 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
740 fprintf ((FILE), "\t%s\t0x%x", \
741 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
742 if (flag_debug_asm) \
743 fprintf ((FILE), "\t%s %s", \
744 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
745 fputc ('\n', (FILE)); \
749 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
750 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
752 fprintf ((FILE), "\t%s\t0x%x", \
753 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
754 if (flag_debug_asm) \
755 fprintf ((FILE), "\t%s %s", \
756 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
757 fputc ('\n', (FILE)); \
761 #ifndef ASM_OUTPUT_DWARF_STACK_OP
762 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
764 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
765 if (flag_debug_asm) \
766 fprintf ((FILE), "\t%s %s", \
767 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
768 fputc ('\n', (FILE)); \
772 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
773 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
775 fprintf ((FILE), "\t%s\t0x%x", \
776 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
777 if (flag_debug_asm) \
778 fprintf ((FILE), "\t%s %s", \
779 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
780 fputc ('\n', (FILE)); \
784 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
785 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
787 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
788 if (flag_debug_asm) \
789 fprintf ((FILE), "\t%s %s", \
790 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
791 fputc ('\n', (FILE)); \
795 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
796 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
798 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
799 if (flag_debug_asm) \
800 fprintf ((FILE), "\t%s %s", \
801 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
802 fputc ('\n', (FILE)); \
806 #ifndef ASM_OUTPUT_DWARF_ADDR
807 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
808 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
809 assemble_name (FILE, LABEL); \
810 fprintf (FILE, "\n"); \
814 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
815 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
817 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
818 output_addr_const ((FILE), (RTX)); \
819 fputc ('\n', (FILE)); \
823 #ifndef ASM_OUTPUT_DWARF_REF
824 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
825 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
826 assemble_name (FILE, LABEL); \
827 fprintf (FILE, "\n"); \
831 #ifndef ASM_OUTPUT_DWARF_DATA1
832 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
833 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
836 #ifndef ASM_OUTPUT_DWARF_DATA2
837 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
838 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
841 #ifndef ASM_OUTPUT_DWARF_DATA4
842 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
843 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
846 #ifndef ASM_OUTPUT_DWARF_DATA8
847 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
849 if (WORDS_BIG_ENDIAN) \
851 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
852 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
856 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
857 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
862 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
863 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
864 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
865 defined, we call it, then issue the line feed. If not, we supply a
866 default defintion of calling ASM_OUTPUT_ASCII */
868 #ifndef ASM_OUTPUT_DWARF_STRING
869 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
870 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
872 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
873 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
877 /************************ general utility functions **************************/
883 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
884 || ((GET_CODE (rtl) == SUBREG)
885 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
889 type_main_variant (type)
892 type = TYPE_MAIN_VARIANT (type);
894 /* There really should be only one main variant among any group of variants
895 of a given type (and all of the MAIN_VARIANT values for all members of
896 the group should point to that one type) but sometimes the C front-end
897 messes this up for array types, so we work around that bug here. */
899 if (TREE_CODE (type) == ARRAY_TYPE)
901 while (type != TYPE_MAIN_VARIANT (type))
902 type = TYPE_MAIN_VARIANT (type);
908 /* Return non-zero if the given type node represents a tagged type. */
911 is_tagged_type (type)
914 register enum tree_code code = TREE_CODE (type);
916 return (code == RECORD_TYPE || code == UNION_TYPE
917 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
922 register unsigned tag;
926 case TAG_padding: return "TAG_padding";
927 case TAG_array_type: return "TAG_array_type";
928 case TAG_class_type: return "TAG_class_type";
929 case TAG_entry_point: return "TAG_entry_point";
930 case TAG_enumeration_type: return "TAG_enumeration_type";
931 case TAG_formal_parameter: return "TAG_formal_parameter";
932 case TAG_global_subroutine: return "TAG_global_subroutine";
933 case TAG_global_variable: return "TAG_global_variable";
934 case TAG_label: return "TAG_label";
935 case TAG_lexical_block: return "TAG_lexical_block";
936 case TAG_local_variable: return "TAG_local_variable";
937 case TAG_member: return "TAG_member";
938 case TAG_pointer_type: return "TAG_pointer_type";
939 case TAG_reference_type: return "TAG_reference_type";
940 case TAG_compile_unit: return "TAG_compile_unit";
941 case TAG_string_type: return "TAG_string_type";
942 case TAG_structure_type: return "TAG_structure_type";
943 case TAG_subroutine: return "TAG_subroutine";
944 case TAG_subroutine_type: return "TAG_subroutine_type";
945 case TAG_typedef: return "TAG_typedef";
946 case TAG_union_type: return "TAG_union_type";
947 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
948 case TAG_variant: return "TAG_variant";
949 case TAG_common_block: return "TAG_common_block";
950 case TAG_common_inclusion: return "TAG_common_inclusion";
951 case TAG_inheritance: return "TAG_inheritance";
952 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
953 case TAG_module: return "TAG_module";
954 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
955 case TAG_set_type: return "TAG_set_type";
956 case TAG_subrange_type: return "TAG_subrange_type";
957 case TAG_with_stmt: return "TAG_with_stmt";
959 /* GNU extensions. */
961 case TAG_format_label: return "TAG_format_label";
962 case TAG_namelist: return "TAG_namelist";
963 case TAG_function_template: return "TAG_function_template";
964 case TAG_class_template: return "TAG_class_template";
966 default: return "TAG_<unknown>";
971 dwarf_attr_name (attr)
972 register unsigned attr;
976 case AT_sibling: return "AT_sibling";
977 case AT_location: return "AT_location";
978 case AT_name: return "AT_name";
979 case AT_fund_type: return "AT_fund_type";
980 case AT_mod_fund_type: return "AT_mod_fund_type";
981 case AT_user_def_type: return "AT_user_def_type";
982 case AT_mod_u_d_type: return "AT_mod_u_d_type";
983 case AT_ordering: return "AT_ordering";
984 case AT_subscr_data: return "AT_subscr_data";
985 case AT_byte_size: return "AT_byte_size";
986 case AT_bit_offset: return "AT_bit_offset";
987 case AT_bit_size: return "AT_bit_size";
988 case AT_element_list: return "AT_element_list";
989 case AT_stmt_list: return "AT_stmt_list";
990 case AT_low_pc: return "AT_low_pc";
991 case AT_high_pc: return "AT_high_pc";
992 case AT_language: return "AT_language";
993 case AT_member: return "AT_member";
994 case AT_discr: return "AT_discr";
995 case AT_discr_value: return "AT_discr_value";
996 case AT_string_length: return "AT_string_length";
997 case AT_common_reference: return "AT_common_reference";
998 case AT_comp_dir: return "AT_comp_dir";
999 case AT_const_value_string: return "AT_const_value_string";
1000 case AT_const_value_data2: return "AT_const_value_data2";
1001 case AT_const_value_data4: return "AT_const_value_data4";
1002 case AT_const_value_data8: return "AT_const_value_data8";
1003 case AT_const_value_block2: return "AT_const_value_block2";
1004 case AT_const_value_block4: return "AT_const_value_block4";
1005 case AT_containing_type: return "AT_containing_type";
1006 case AT_default_value_addr: return "AT_default_value_addr";
1007 case AT_default_value_data2: return "AT_default_value_data2";
1008 case AT_default_value_data4: return "AT_default_value_data4";
1009 case AT_default_value_data8: return "AT_default_value_data8";
1010 case AT_default_value_string: return "AT_default_value_string";
1011 case AT_friends: return "AT_friends";
1012 case AT_inline: return "AT_inline";
1013 case AT_is_optional: return "AT_is_optional";
1014 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1015 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1016 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1017 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1018 case AT_private: return "AT_private";
1019 case AT_producer: return "AT_producer";
1020 case AT_program: return "AT_program";
1021 case AT_protected: return "AT_protected";
1022 case AT_prototyped: return "AT_prototyped";
1023 case AT_public: return "AT_public";
1024 case AT_pure_virtual: return "AT_pure_virtual";
1025 case AT_return_addr: return "AT_return_addr";
1026 case AT_abstract_origin: return "AT_abstract_origin";
1027 case AT_start_scope: return "AT_start_scope";
1028 case AT_stride_size: return "AT_stride_size";
1029 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1030 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1031 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1032 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1033 case AT_virtual: return "AT_virtual";
1035 /* GNU extensions */
1037 case AT_sf_names: return "AT_sf_names";
1038 case AT_src_info: return "AT_src_info";
1039 case AT_mac_info: return "AT_mac_info";
1040 case AT_src_coords: return "AT_src_coords";
1041 case AT_body_begin: return "AT_body_begin";
1042 case AT_body_end: return "AT_body_end";
1044 default: return "AT_<unknown>";
1049 dwarf_stack_op_name (op)
1050 register unsigned op;
1054 case OP_REG: return "OP_REG";
1055 case OP_BASEREG: return "OP_BASEREG";
1056 case OP_ADDR: return "OP_ADDR";
1057 case OP_CONST: return "OP_CONST";
1058 case OP_DEREF2: return "OP_DEREF2";
1059 case OP_DEREF4: return "OP_DEREF4";
1060 case OP_ADD: return "OP_ADD";
1061 default: return "OP_<unknown>";
1066 dwarf_typemod_name (mod)
1067 register unsigned mod;
1071 case MOD_pointer_to: return "MOD_pointer_to";
1072 case MOD_reference_to: return "MOD_reference_to";
1073 case MOD_const: return "MOD_const";
1074 case MOD_volatile: return "MOD_volatile";
1075 default: return "MOD_<unknown>";
1080 dwarf_fmt_byte_name (fmt)
1081 register unsigned fmt;
1085 case FMT_FT_C_C: return "FMT_FT_C_C";
1086 case FMT_FT_C_X: return "FMT_FT_C_X";
1087 case FMT_FT_X_C: return "FMT_FT_X_C";
1088 case FMT_FT_X_X: return "FMT_FT_X_X";
1089 case FMT_UT_C_C: return "FMT_UT_C_C";
1090 case FMT_UT_C_X: return "FMT_UT_C_X";
1091 case FMT_UT_X_C: return "FMT_UT_X_C";
1092 case FMT_UT_X_X: return "FMT_UT_X_X";
1093 case FMT_ET: return "FMT_ET";
1094 default: return "FMT_<unknown>";
1099 dwarf_fund_type_name (ft)
1100 register unsigned ft;
1104 case FT_char: return "FT_char";
1105 case FT_signed_char: return "FT_signed_char";
1106 case FT_unsigned_char: return "FT_unsigned_char";
1107 case FT_short: return "FT_short";
1108 case FT_signed_short: return "FT_signed_short";
1109 case FT_unsigned_short: return "FT_unsigned_short";
1110 case FT_integer: return "FT_integer";
1111 case FT_signed_integer: return "FT_signed_integer";
1112 case FT_unsigned_integer: return "FT_unsigned_integer";
1113 case FT_long: return "FT_long";
1114 case FT_signed_long: return "FT_signed_long";
1115 case FT_unsigned_long: return "FT_unsigned_long";
1116 case FT_pointer: return "FT_pointer";
1117 case FT_float: return "FT_float";
1118 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1119 case FT_ext_prec_float: return "FT_ext_prec_float";
1120 case FT_complex: return "FT_complex";
1121 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1122 case FT_void: return "FT_void";
1123 case FT_boolean: return "FT_boolean";
1124 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1125 case FT_label: return "FT_label";
1127 /* GNU extensions. */
1129 case FT_long_long: return "FT_long_long";
1130 case FT_signed_long_long: return "FT_signed_long_long";
1131 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1133 case FT_int8: return "FT_int8";
1134 case FT_signed_int8: return "FT_signed_int8";
1135 case FT_unsigned_int8: return "FT_unsigned_int8";
1136 case FT_int16: return "FT_int16";
1137 case FT_signed_int16: return "FT_signed_int16";
1138 case FT_unsigned_int16: return "FT_unsigned_int16";
1139 case FT_int32: return "FT_int32";
1140 case FT_signed_int32: return "FT_signed_int32";
1141 case FT_unsigned_int32: return "FT_unsigned_int32";
1142 case FT_int64: return "FT_int64";
1143 case FT_signed_int64: return "FT_signed_int64";
1144 case FT_unsigned_int64: return "FT_unsigned_int64";
1146 case FT_real32: return "FT_real32";
1147 case FT_real64: return "FT_real64";
1148 case FT_real96: return "FT_real96";
1149 case FT_real128: return "FT_real128";
1151 default: return "FT_<unknown>";
1155 /* Determine the "ultimate origin" of a decl. The decl may be an
1156 inlined instance of an inlined instance of a decl which is local
1157 to an inline function, so we have to trace all of the way back
1158 through the origin chain to find out what sort of node actually
1159 served as the original seed for the given block. */
1162 decl_ultimate_origin (decl)
1165 #ifdef ENABLE_CHECKING
1166 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1167 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1168 most distant ancestor, this should never happen. */
1172 return DECL_ABSTRACT_ORIGIN (decl);
1175 /* Determine the "ultimate origin" of a block. The block may be an
1176 inlined instance of an inlined instance of a block which is local
1177 to an inline function, so we have to trace all of the way back
1178 through the origin chain to find out what sort of node actually
1179 served as the original seed for the given block. */
1182 block_ultimate_origin (block)
1183 register tree block;
1185 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1187 if (immediate_origin == NULL)
1191 register tree ret_val;
1192 register tree lookahead = immediate_origin;
1196 ret_val = lookahead;
1197 lookahead = (TREE_CODE (ret_val) == BLOCK)
1198 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1201 while (lookahead != NULL && lookahead != ret_val);
1206 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1207 of a virtual function may refer to a base class, so we check the 'this'
1211 decl_class_context (decl)
1214 tree context = NULL_TREE;
1215 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1216 context = DECL_CONTEXT (decl);
1218 context = TYPE_MAIN_VARIANT
1219 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1221 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1222 context = NULL_TREE;
1229 output_unsigned_leb128 (value)
1230 register unsigned long value;
1232 register unsigned long orig_value = value;
1236 register unsigned byte = (value & 0x7f);
1239 if (value != 0) /* more bytes to follow */
1241 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1242 if (flag_debug_asm && value == 0)
1243 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1244 ASM_COMMENT_START, orig_value);
1245 fputc ('\n', asm_out_file);
1251 output_signed_leb128 (value)
1252 register long value;
1254 register long orig_value = value;
1255 register int negative = (value < 0);
1260 register unsigned byte = (value & 0x7f);
1264 value |= 0xfe000000; /* manually sign extend */
1265 if (((value == 0) && ((byte & 0x40) == 0))
1266 || ((value == -1) && ((byte & 0x40) == 1)))
1273 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1274 if (flag_debug_asm && more == 0)
1275 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1276 ASM_COMMENT_START, orig_value);
1277 fputc ('\n', asm_out_file);
1283 /**************** utility functions for attribute functions ******************/
1285 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1286 node in question represents the outermost pair of curly braces (i.e.
1287 the "body block") of a function or method.
1289 For any BLOCK node representing a "body block" of a function or method,
1290 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1291 which represents the outermost (function) scope for the function or
1292 method (i.e. the one which includes the formal parameters). The
1293 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1298 is_body_block (stmt)
1301 if (TREE_CODE (stmt) == BLOCK)
1303 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1305 if (TREE_CODE (parent) == BLOCK)
1307 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1309 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1316 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1317 type code for the given type.
1319 This routine must only be called for GCC type nodes that correspond to
1320 Dwarf fundamental types.
1322 The current Dwarf draft specification calls for Dwarf fundamental types
1323 to accurately reflect the fact that a given type was either a "plain"
1324 integral type or an explicitly "signed" integral type. Unfortunately,
1325 we can't always do this, because GCC may already have thrown away the
1326 information about the precise way in which the type was originally
1329 typedef signed int my_type;
1331 struct s { my_type f; };
1333 Since we may be stuck here without enought information to do exactly
1334 what is called for in the Dwarf draft specification, we do the best
1335 that we can under the circumstances and always use the "plain" integral
1336 fundamental type codes for int, short, and long types. That's probably
1337 good enough. The additional accuracy called for in the current DWARF
1338 draft specification is probably never even useful in practice. */
1341 fundamental_type_code (type)
1344 if (TREE_CODE (type) == ERROR_MARK)
1347 switch (TREE_CODE (type))
1356 /* Carefully distinguish all the standard types of C,
1357 without messing up if the language is not C.
1358 Note that we check only for the names that contain spaces;
1359 other names might occur by coincidence in other languages. */
1360 if (TYPE_NAME (type) != 0
1361 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1362 && DECL_NAME (TYPE_NAME (type)) != 0
1363 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1366 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1368 if (!strcmp (name, "unsigned char"))
1369 return FT_unsigned_char;
1370 if (!strcmp (name, "signed char"))
1371 return FT_signed_char;
1372 if (!strcmp (name, "unsigned int"))
1373 return FT_unsigned_integer;
1374 if (!strcmp (name, "short int"))
1376 if (!strcmp (name, "short unsigned int"))
1377 return FT_unsigned_short;
1378 if (!strcmp (name, "long int"))
1380 if (!strcmp (name, "long unsigned int"))
1381 return FT_unsigned_long;
1382 if (!strcmp (name, "long long int"))
1383 return FT_long_long; /* Not grok'ed by svr4 SDB */
1384 if (!strcmp (name, "long long unsigned int"))
1385 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1388 /* Most integer types will be sorted out above, however, for the
1389 sake of special `array index' integer types, the following code
1390 is also provided. */
1392 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1393 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1395 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1396 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1398 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1399 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1401 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1402 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1404 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1405 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1407 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1408 if (TYPE_PRECISION (type) == 1)
1414 /* Carefully distinguish all the standard types of C,
1415 without messing up if the language is not C. */
1416 if (TYPE_NAME (type) != 0
1417 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1418 && DECL_NAME (TYPE_NAME (type)) != 0
1419 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1422 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1424 /* Note that here we can run afowl of a serious bug in "classic"
1425 svr4 SDB debuggers. They don't seem to understand the
1426 FT_ext_prec_float type (even though they should). */
1428 if (!strcmp (name, "long double"))
1429 return FT_ext_prec_float;
1432 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1434 /* On the SH, when compiling with -m3e or -m4-single-only, both
1435 float and double are 32 bits. But since the debugger doesn't
1436 know about the subtarget, it always thinks double is 64 bits.
1437 So we have to tell the debugger that the type is float to
1438 make the output of the 'print' command etc. readable. */
1439 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1441 return FT_dbl_prec_float;
1443 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1446 /* Note that here we can run afowl of a serious bug in "classic"
1447 svr4 SDB debuggers. They don't seem to understand the
1448 FT_ext_prec_float type (even though they should). */
1450 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1451 return FT_ext_prec_float;
1455 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1458 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1461 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1464 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1469 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1470 the Dwarf "root" type for the given input type. The Dwarf "root" type
1471 of a given type is generally the same as the given type, except that if
1472 the given type is a pointer or reference type, then the root type of
1473 the given type is the root type of the "basis" type for the pointer or
1474 reference type. (This definition of the "root" type is recursive.)
1475 Also, the root type of a `const' qualified type or a `volatile'
1476 qualified type is the root type of the given type without the
1480 root_type_1 (type, count)
1484 /* Give up after searching 1000 levels, in case this is a recursive
1485 pointer type. Such types are possible in Ada, but it is not possible
1486 to represent them in DWARF1 debug info. */
1488 return error_mark_node;
1490 switch (TREE_CODE (type))
1493 return error_mark_node;
1496 case REFERENCE_TYPE:
1497 return root_type_1 (TREE_TYPE (type), count+1);
1508 type = root_type_1 (type, 0);
1509 if (type != error_mark_node)
1510 type = type_main_variant (type);
1514 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1515 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1518 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1520 register int decl_const;
1521 register int decl_volatile;
1524 if (TREE_CODE (type) == ERROR_MARK)
1527 /* Give up after searching 1000 levels, in case this is a recursive
1528 pointer type. Such types are possible in Ada, but it is not possible
1529 to represent them in DWARF1 debug info. */
1533 if (TYPE_READONLY (type) || decl_const)
1534 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1535 if (TYPE_VOLATILE (type) || decl_volatile)
1536 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1537 switch (TREE_CODE (type))
1540 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1541 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1544 case REFERENCE_TYPE:
1545 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1546 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1556 write_modifier_bytes (type, decl_const, decl_volatile)
1558 register int decl_const;
1559 register int decl_volatile;
1561 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1564 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1565 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1568 type_is_fundamental (type)
1571 switch (TREE_CODE (type))
1586 case QUAL_UNION_TYPE:
1591 case REFERENCE_TYPE:
1603 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1604 equate directive which will associate a symbolic name with the current DIE.
1606 The name used is an artificial label generated from the DECL_UID number
1607 associated with the given decl node. The name it gets equated to is the
1608 symbolic label that we (previously) output at the start of the DIE that
1609 we are currently generating.
1611 Calling this function while generating some "decl related" form of DIE
1612 makes it possible to later refer to the DIE which represents the given
1613 decl simply by re-generating the symbolic name from the ..._DECL node's
1617 equate_decl_number_to_die_number (decl)
1620 /* In the case where we are generating a DIE for some ..._DECL node
1621 which represents either some inline function declaration or some
1622 entity declared within an inline function declaration/definition,
1623 setup a symbolic name for the current DIE so that we have a name
1624 for this DIE that we can easily refer to later on within
1625 AT_abstract_origin attributes. */
1627 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1628 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1630 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1631 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1632 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1635 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1636 equate directive which will associate a symbolic name with the current DIE.
1638 The name used is an artificial label generated from the TYPE_UID number
1639 associated with the given type node. The name it gets equated to is the
1640 symbolic label that we (previously) output at the start of the DIE that
1641 we are currently generating.
1643 Calling this function while generating some "type related" form of DIE
1644 makes it easy to later refer to the DIE which represents the given type
1645 simply by re-generating the alternative name from the ..._TYPE node's
1649 equate_type_number_to_die_number (type)
1652 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1653 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1655 /* We are generating a DIE to represent the main variant of this type
1656 (i.e the type without any const or volatile qualifiers) so in order
1657 to get the equate to come out right, we need to get the main variant
1660 type = type_main_variant (type);
1662 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1663 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1664 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1668 output_reg_number (rtl)
1671 register unsigned regno = REGNO (rtl);
1673 if (regno >= DWARF_FRAME_REGISTERS)
1675 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1679 fprintf (asm_out_file, "\t%s\t0x%x",
1680 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1683 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1684 PRINT_REG (rtl, 0, asm_out_file);
1686 fputc ('\n', asm_out_file);
1689 /* The following routine is a nice and simple transducer. It converts the
1690 RTL for a variable or parameter (resident in memory) into an equivalent
1691 Dwarf representation of a mechanism for getting the address of that same
1692 variable onto the top of a hypothetical "address evaluation" stack.
1694 When creating memory location descriptors, we are effectively trans-
1695 forming the RTL for a memory-resident object into its Dwarf postfix
1696 expression equivalent. This routine just recursively descends an
1697 RTL tree, turning it into Dwarf postfix code as it goes. */
1700 output_mem_loc_descriptor (rtl)
1703 /* Note that for a dynamically sized array, the location we will
1704 generate a description of here will be the lowest numbered location
1705 which is actually within the array. That's *not* necessarily the
1706 same as the zeroth element of the array. */
1708 #ifdef ASM_SIMPLIFY_DWARF_ADDR
1709 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
1712 switch (GET_CODE (rtl))
1716 /* The case of a subreg may arise when we have a local (register)
1717 variable or a formal (register) parameter which doesn't quite
1718 fill up an entire register. For now, just assume that it is
1719 legitimate to make the Dwarf info refer to the whole register
1720 which contains the given subreg. */
1722 rtl = XEXP (rtl, 0);
1727 /* Whenever a register number forms a part of the description of
1728 the method for calculating the (dynamic) address of a memory
1729 resident object, DWARF rules require the register number to
1730 be referred to as a "base register". This distinction is not
1731 based in any way upon what category of register the hardware
1732 believes the given register belongs to. This is strictly
1733 DWARF terminology we're dealing with here.
1735 Note that in cases where the location of a memory-resident data
1736 object could be expressed as:
1738 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1740 the actual DWARF location descriptor that we generate may just
1741 be OP_BASEREG (basereg). This may look deceptively like the
1742 object in question was allocated to a register (rather than
1743 in memory) so DWARF consumers need to be aware of the subtle
1744 distinction between OP_REG and OP_BASEREG. */
1746 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1747 output_reg_number (rtl);
1751 output_mem_loc_descriptor (XEXP (rtl, 0));
1752 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1757 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1758 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1762 output_mem_loc_descriptor (XEXP (rtl, 0));
1763 output_mem_loc_descriptor (XEXP (rtl, 1));
1764 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1768 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1769 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1773 /* If a pseudo-reg is optimized away, it is possible for it to
1774 be replaced with a MEM containing a multiply. Use a GNU extension
1776 output_mem_loc_descriptor (XEXP (rtl, 0));
1777 output_mem_loc_descriptor (XEXP (rtl, 1));
1778 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1786 /* Output a proper Dwarf location descriptor for a variable or parameter
1787 which is either allocated in a register or in a memory location. For
1788 a register, we just generate an OP_REG and the register number. For a
1789 memory location we provide a Dwarf postfix expression describing how to
1790 generate the (dynamic) address of the object onto the address stack. */
1793 output_loc_descriptor (rtl)
1796 switch (GET_CODE (rtl))
1800 /* The case of a subreg may arise when we have a local (register)
1801 variable or a formal (register) parameter which doesn't quite
1802 fill up an entire register. For now, just assume that it is
1803 legitimate to make the Dwarf info refer to the whole register
1804 which contains the given subreg. */
1806 rtl = XEXP (rtl, 0);
1810 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1811 output_reg_number (rtl);
1815 output_mem_loc_descriptor (XEXP (rtl, 0));
1819 abort (); /* Should never happen */
1823 /* Given a tree node describing an array bound (either lower or upper)
1824 output a representation for that bound. */
1827 output_bound_representation (bound, dim_num, u_or_l)
1828 register tree bound;
1829 register unsigned dim_num; /* For multi-dimensional arrays. */
1830 register char u_or_l; /* Designates upper or lower bound. */
1832 switch (TREE_CODE (bound))
1838 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1841 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1842 (unsigned) TREE_INT_CST_LOW (bound));
1847 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1848 SAVE_EXPR nodes, in which case we can do something, or as
1849 an expression, which we cannot represent. */
1851 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1852 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1854 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1855 current_dienum, dim_num, u_or_l);
1857 sprintf (end_label, BOUND_END_LABEL_FMT,
1858 current_dienum, dim_num, u_or_l);
1860 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1861 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1863 /* If optimization is turned on, the SAVE_EXPRs that describe
1864 how to access the upper bound values are essentially bogus.
1865 They only describe (at best) how to get at these values at
1866 the points in the generated code right after they have just
1867 been computed. Worse yet, in the typical case, the upper
1868 bound values will not even *be* computed in the optimized
1869 code, so these SAVE_EXPRs are entirely bogus.
1871 In order to compensate for this fact, we check here to see
1872 if optimization is enabled, and if so, we effectively create
1873 an empty location description for the (unknown and unknowable)
1876 This should not cause too much trouble for existing (stupid?)
1877 debuggers because they have to deal with empty upper bounds
1878 location descriptions anyway in order to be able to deal with
1879 incomplete array types.
1881 Of course an intelligent debugger (GDB?) should be able to
1882 comprehend that a missing upper bound specification in a
1883 array type used for a storage class `auto' local array variable
1884 indicates that the upper bound is both unknown (at compile-
1885 time) and unknowable (at run-time) due to optimization. */
1889 while (TREE_CODE (bound) == NOP_EXPR
1890 || TREE_CODE (bound) == CONVERT_EXPR)
1891 bound = TREE_OPERAND (bound, 0);
1893 if (TREE_CODE (bound) == SAVE_EXPR)
1894 output_loc_descriptor
1895 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1898 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1905 /* Recursive function to output a sequence of value/name pairs for
1906 enumeration constants in reversed order. This is called from
1907 enumeration_type_die. */
1910 output_enumeral_list (link)
1915 output_enumeral_list (TREE_CHAIN (link));
1916 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1917 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1918 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
1919 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1923 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1924 which is not less than the value itself. */
1926 static inline unsigned
1927 ceiling (value, boundary)
1928 register unsigned value;
1929 register unsigned boundary;
1931 return (((value + boundary - 1) / boundary) * boundary);
1934 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1935 pointer to the declared type for the relevant field variable, or return
1936 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1944 if (TREE_CODE (decl) == ERROR_MARK)
1945 return integer_type_node;
1947 type = DECL_BIT_FIELD_TYPE (decl);
1949 type = TREE_TYPE (decl);
1953 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1954 node, return the alignment in bits for the type, or else return
1955 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1957 static inline unsigned
1958 simple_type_align_in_bits (type)
1961 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1964 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1965 node, return the size in bits for the type if it is a constant, or
1966 else return the alignment for the type if the type's size is not
1967 constant, or else return BITS_PER_WORD if the type actually turns out
1968 to be an ERROR_MARK node. */
1970 static inline unsigned
1971 simple_type_size_in_bits (type)
1974 if (TREE_CODE (type) == ERROR_MARK)
1975 return BITS_PER_WORD;
1978 register tree type_size_tree = TYPE_SIZE (type);
1980 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1981 return TYPE_ALIGN (type);
1983 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1987 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1988 return the byte offset of the lowest addressed byte of the "containing
1989 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1990 mine what that offset is, either because the argument turns out to be a
1991 pointer to an ERROR_MARK node, or because the offset is actually variable.
1992 (We can't handle the latter case just yet.) */
1995 field_byte_offset (decl)
1998 register unsigned type_align_in_bytes;
1999 register unsigned type_align_in_bits;
2000 register unsigned type_size_in_bits;
2001 register unsigned object_offset_in_align_units;
2002 register unsigned object_offset_in_bits;
2003 register unsigned object_offset_in_bytes;
2005 register tree bitpos_tree;
2006 register tree field_size_tree;
2007 register unsigned bitpos_int;
2008 register unsigned deepest_bitpos;
2009 register unsigned field_size_in_bits;
2011 if (TREE_CODE (decl) == ERROR_MARK)
2014 if (TREE_CODE (decl) != FIELD_DECL)
2017 type = field_type (decl);
2019 bitpos_tree = DECL_FIELD_BITPOS (decl);
2020 field_size_tree = DECL_SIZE (decl);
2022 /* If there was an error, the size could be zero. */
2023 if (! field_size_tree)
2031 /* We cannot yet cope with fields whose positions or sizes are variable,
2032 so for now, when we see such things, we simply return 0. Someday,
2033 we may be able to handle such cases, but it will be damn difficult. */
2035 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2037 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2039 if (TREE_CODE (field_size_tree) != INTEGER_CST)
2041 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
2043 type_size_in_bits = simple_type_size_in_bits (type);
2045 type_align_in_bits = simple_type_align_in_bits (type);
2046 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2048 /* Note that the GCC front-end doesn't make any attempt to keep track
2049 of the starting bit offset (relative to the start of the containing
2050 structure type) of the hypothetical "containing object" for a bit-
2051 field. Thus, when computing the byte offset value for the start of
2052 the "containing object" of a bit-field, we must deduce this infor-
2055 This can be rather tricky to do in some cases. For example, handling
2056 the following structure type definition when compiling for an i386/i486
2057 target (which only aligns long long's to 32-bit boundaries) can be very
2062 long long field2:31;
2065 Fortunately, there is a simple rule-of-thumb which can be used in such
2066 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2067 the structure shown above. It decides to do this based upon one simple
2068 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2069 taining object" for each bit-field at the first (i.e. lowest addressed)
2070 legitimate alignment boundary (based upon the required minimum alignment
2071 for the declared type of the field) which it can possibly use, subject
2072 to the condition that there is still enough available space remaining
2073 in the containing object (when allocated at the selected point) to
2074 fully accommodate all of the bits of the bit-field itself.
2076 This simple rule makes it obvious why GCC allocates 8 bytes for each
2077 object of the structure type shown above. When looking for a place to
2078 allocate the "containing object" for `field2', the compiler simply tries
2079 to allocate a 64-bit "containing object" at each successive 32-bit
2080 boundary (starting at zero) until it finds a place to allocate that 64-
2081 bit field such that at least 31 contiguous (and previously unallocated)
2082 bits remain within that selected 64 bit field. (As it turns out, for
2083 the example above, the compiler finds that it is OK to allocate the
2084 "containing object" 64-bit field at bit-offset zero within the
2087 Here we attempt to work backwards from the limited set of facts we're
2088 given, and we try to deduce from those facts, where GCC must have
2089 believed that the containing object started (within the structure type).
2091 The value we deduce is then used (by the callers of this routine) to
2092 generate AT_location and AT_bit_offset attributes for fields (both
2093 bit-fields and, in the case of AT_location, regular fields as well).
2096 /* Figure out the bit-distance from the start of the structure to the
2097 "deepest" bit of the bit-field. */
2098 deepest_bitpos = bitpos_int + field_size_in_bits;
2100 /* This is the tricky part. Use some fancy footwork to deduce where the
2101 lowest addressed bit of the containing object must be. */
2102 object_offset_in_bits
2103 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2105 /* Compute the offset of the containing object in "alignment units". */
2106 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2108 /* Compute the offset of the containing object in bytes. */
2109 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2111 /* The above code assumes that the field does not cross an alignment
2112 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2113 or if the structure is packed. If this happens, then we get an object
2114 which starts after the bitfield, which means that the bit offset is
2115 negative. Gdb fails when given negative bit offsets. We avoid this
2116 by recomputing using the first bit of the bitfield. This will give
2117 us an object which does not completely contain the bitfield, but it
2118 will be aligned, and it will contain the first bit of the bitfield.
2120 However, only do this for a BYTES_BIG_ENDIAN target. For a
2121 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2122 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2123 then we end up computing the object byte offset for the wrong word of the
2124 desired bitfield, which in turn causes the field offset to be negative
2125 in bit_offset_attribute. */
2126 if (BYTES_BIG_ENDIAN
2127 && object_offset_in_bits > bitpos_int)
2129 deepest_bitpos = bitpos_int + 1;
2130 object_offset_in_bits
2131 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2132 object_offset_in_align_units = (object_offset_in_bits
2133 / type_align_in_bits);
2134 object_offset_in_bytes = (object_offset_in_align_units
2135 * type_align_in_bytes);
2138 return object_offset_in_bytes;
2141 /****************************** attributes *********************************/
2143 /* The following routines are responsible for writing out the various types
2144 of Dwarf attributes (and any following data bytes associated with them).
2145 These routines are listed in order based on the numerical codes of their
2146 associated attributes. */
2148 /* Generate an AT_sibling attribute. */
2151 sibling_attribute ()
2153 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2155 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2156 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2157 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2160 /* Output the form of location attributes suitable for whole variables and
2161 whole parameters. Note that the location attributes for struct fields
2162 are generated by the routine `data_member_location_attribute' below. */
2165 location_attribute (rtl)
2168 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2169 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2171 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2172 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2173 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2174 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2175 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2177 /* Handle a special case. If we are about to output a location descriptor
2178 for a variable or parameter which has been optimized out of existence,
2179 don't do that. Instead we output a zero-length location descriptor
2180 value as part of the location attribute.
2182 A variable which has been optimized out of existence will have a
2183 DECL_RTL value which denotes a pseudo-reg.
2185 Currently, in some rare cases, variables can have DECL_RTL values
2186 which look like (MEM (REG pseudo-reg#)). These cases are due to
2187 bugs elsewhere in the compiler. We treat such cases
2188 as if the variable(s) in question had been optimized out of existence.
2190 Note that in all cases where we wish to express the fact that a
2191 variable has been optimized out of existence, we do not simply
2192 suppress the generation of the entire location attribute because
2193 the absence of a location attribute in certain kinds of DIEs is
2194 used to indicate something else entirely... i.e. that the DIE
2195 represents an object declaration, but not a definition. So saith
2199 if (! is_pseudo_reg (rtl)
2200 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2201 output_loc_descriptor (rtl);
2203 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2206 /* Output the specialized form of location attribute used for data members
2207 of struct and union types.
2209 In the special case of a FIELD_DECL node which represents a bit-field,
2210 the "offset" part of this special location descriptor must indicate the
2211 distance in bytes from the lowest-addressed byte of the containing
2212 struct or union type to the lowest-addressed byte of the "containing
2213 object" for the bit-field. (See the `field_byte_offset' function above.)
2215 For any given bit-field, the "containing object" is a hypothetical
2216 object (of some integral or enum type) within which the given bit-field
2217 lives. The type of this hypothetical "containing object" is always the
2218 same as the declared type of the individual bit-field itself (for GCC
2219 anyway... the DWARF spec doesn't actually mandate this).
2221 Note that it is the size (in bytes) of the hypothetical "containing
2222 object" which will be given in the AT_byte_size attribute for this
2223 bit-field. (See the `byte_size_attribute' function below.) It is
2224 also used when calculating the value of the AT_bit_offset attribute.
2225 (See the `bit_offset_attribute' function below.) */
2228 data_member_location_attribute (t)
2231 register unsigned object_offset_in_bytes;
2232 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2233 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2235 if (TREE_CODE (t) == TREE_VEC)
2236 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2238 object_offset_in_bytes = field_byte_offset (t);
2240 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2241 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2242 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2243 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2244 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2245 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2246 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2247 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2248 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2251 /* Output an AT_const_value attribute for a variable or a parameter which
2252 does not have a "location" either in memory or in a register. These
2253 things can arise in GNU C when a constant is passed as an actual
2254 parameter to an inlined function. They can also arise in C++ where
2255 declared constants do not necessarily get memory "homes". */
2258 const_value_attribute (rtl)
2261 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2262 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2264 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2265 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2266 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2267 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2268 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2270 switch (GET_CODE (rtl))
2273 /* Note that a CONST_INT rtx could represent either an integer or
2274 a floating-point constant. A CONST_INT is used whenever the
2275 constant will fit into a single word. In all such cases, the
2276 original mode of the constant value is wiped out, and the
2277 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2278 precise mode information for these constants, we always just
2279 output them using 4 bytes. */
2281 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2285 /* Note that a CONST_DOUBLE rtx could represent either an integer
2286 or a floating-point constant. A CONST_DOUBLE is used whenever
2287 the constant requires more than one word in order to be adequately
2288 represented. In all such cases, the original mode of the constant
2289 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2290 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2292 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2293 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2294 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2298 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2304 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2308 /* In cases where an inlined instance of an inline function is passed
2309 the address of an `auto' variable (which is local to the caller)
2310 we can get a situation where the DECL_RTL of the artificial
2311 local variable (for the inlining) which acts as a stand-in for
2312 the corresponding formal parameter (of the inline function)
2313 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2314 This is not exactly a compile-time constant expression, but it
2315 isn't the address of the (artificial) local variable either.
2316 Rather, it represents the *value* which the artificial local
2317 variable always has during its lifetime. We currently have no
2318 way to represent such quasi-constant values in Dwarf, so for now
2319 we just punt and generate an AT_const_value attribute with form
2320 FORM_BLOCK4 and a length of zero. */
2324 abort (); /* No other kinds of rtx should be possible here. */
2327 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2330 /* Generate *either* an AT_location attribute or else an AT_const_value
2331 data attribute for a variable or a parameter. We generate the
2332 AT_const_value attribute only in those cases where the given
2333 variable or parameter does not have a true "location" either in
2334 memory or in a register. This can happen (for example) when a
2335 constant is passed as an actual argument in a call to an inline
2336 function. (It's possible that these things can crop up in other
2337 ways also.) Note that one type of constant value which can be
2338 passed into an inlined function is a constant pointer. This can
2339 happen for example if an actual argument in an inlined function
2340 call evaluates to a compile-time constant address. */
2343 location_or_const_value_attribute (decl)
2348 if (TREE_CODE (decl) == ERROR_MARK)
2351 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2353 /* Should never happen. */
2358 /* Here we have to decide where we are going to say the parameter "lives"
2359 (as far as the debugger is concerned). We only have a couple of choices.
2360 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2361 normally indicates where the parameter lives during most of the activa-
2362 tion of the function. If optimization is enabled however, this could
2363 be either NULL or else a pseudo-reg. Both of those cases indicate that
2364 the parameter doesn't really live anywhere (as far as the code generation
2365 parts of GCC are concerned) during most of the function's activation.
2366 That will happen (for example) if the parameter is never referenced
2367 within the function.
2369 We could just generate a location descriptor here for all non-NULL
2370 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2371 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2372 cases where DECL_RTL is NULL or is a pseudo-reg.
2374 Note however that we can only get away with using DECL_INCOMING_RTL as
2375 a backup substitute for DECL_RTL in certain limited cases. In cases
2376 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2377 we can be sure that the parameter was passed using the same type as it
2378 is declared to have within the function, and that its DECL_INCOMING_RTL
2379 points us to a place where a value of that type is passed. In cases
2380 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2381 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2382 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2383 points us to a value of some type which is *different* from the type
2384 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2385 to generate a location attribute in such cases, the debugger would
2386 end up (for example) trying to fetch a `float' from a place which
2387 actually contains the first part of a `double'. That would lead to
2388 really incorrect and confusing output at debug-time, and we don't
2389 want that now do we?
2391 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2392 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2393 couple of cute exceptions however. On little-endian machines we can
2394 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2395 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2396 an integral type which is smaller than TREE_TYPE(decl). These cases
2397 arise when (on a little-endian machine) a non-prototyped function has
2398 a parameter declared to be of type `short' or `char'. In such cases,
2399 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2400 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2401 passed `int' value. If the debugger then uses that address to fetch a
2402 `short' or a `char' (on a little-endian machine) the result will be the
2403 correct data, so we allow for such exceptional cases below.
2405 Note that our goal here is to describe the place where the given formal
2406 parameter lives during most of the function's activation (i.e. between
2407 the end of the prologue and the start of the epilogue). We'll do that
2408 as best as we can. Note however that if the given formal parameter is
2409 modified sometime during the execution of the function, then a stack
2410 backtrace (at debug-time) will show the function as having been called
2411 with the *new* value rather than the value which was originally passed
2412 in. This happens rarely enough that it is not a major problem, but it
2413 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2414 may generate two additional attributes for any given TAG_formal_parameter
2415 DIE which will describe the "passed type" and the "passed location" for
2416 the given formal parameter in addition to the attributes we now generate
2417 to indicate the "declared type" and the "active location" for each
2418 parameter. This additional set of attributes could be used by debuggers
2419 for stack backtraces.
2421 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2422 can be NULL also. This happens (for example) for inlined-instances of
2423 inline function formal parameters which are never referenced. This really
2424 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2425 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2426 these values for inlined instances of inline function parameters, so
2427 when we see such cases, we are just out-of-luck for the time
2428 being (until integrate.c gets fixed).
2431 /* Use DECL_RTL as the "location" unless we find something better. */
2432 rtl = DECL_RTL (decl);
2434 if (TREE_CODE (decl) == PARM_DECL)
2435 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2437 /* This decl represents a formal parameter which was optimized out. */
2438 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2439 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2441 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2442 *all* cases where (rtl == NULL_RTX) just below. */
2444 if (declared_type == passed_type)
2445 rtl = DECL_INCOMING_RTL (decl);
2446 else if (! BYTES_BIG_ENDIAN)
2447 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2448 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2449 rtl = DECL_INCOMING_RTL (decl);
2452 if (rtl == NULL_RTX)
2455 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2456 #ifdef LEAF_REG_REMAP
2457 if (current_function_uses_only_leaf_regs)
2458 leaf_renumber_regs_insn (rtl);
2461 switch (GET_CODE (rtl))
2464 /* The address of a variable that was optimized away; don't emit
2474 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2475 const_value_attribute (rtl);
2481 location_attribute (rtl);
2485 /* ??? CONCAT is used for complex variables, which may have the real
2486 part stored in one place and the imag part stored somewhere else.
2487 DWARF1 has no way to describe a variable that lives in two different
2488 places, so we just describe where the first part lives, and hope that
2489 the second part is stored after it. */
2490 location_attribute (XEXP (rtl, 0));
2494 abort (); /* Should never happen. */
2498 /* Generate an AT_name attribute given some string value to be included as
2499 the value of the attribute. */
2502 name_attribute (name_string)
2503 register const char *name_string;
2505 if (name_string && *name_string)
2507 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2508 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2513 fund_type_attribute (ft_code)
2514 register unsigned ft_code;
2516 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2517 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2521 mod_fund_type_attribute (type, decl_const, decl_volatile)
2523 register int decl_const;
2524 register int decl_volatile;
2526 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2527 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2529 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2530 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2531 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2532 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2533 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2534 write_modifier_bytes (type, decl_const, decl_volatile);
2535 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2536 fundamental_type_code (root_type (type)));
2537 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2541 user_def_type_attribute (type)
2544 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2546 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2547 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2548 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2552 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2554 register int decl_const;
2555 register int decl_volatile;
2557 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2558 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2559 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2561 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2562 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2563 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2564 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2565 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2566 write_modifier_bytes (type, decl_const, decl_volatile);
2567 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2568 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2569 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2572 #ifdef USE_ORDERING_ATTRIBUTE
2574 ordering_attribute (ordering)
2575 register unsigned ordering;
2577 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2578 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2580 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2582 /* Note that the block of subscript information for an array type also
2583 includes information about the element type of type given array type. */
2586 subscript_data_attribute (type)
2589 register unsigned dimension_number;
2590 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2591 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2593 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2594 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2595 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2596 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2597 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2599 /* The GNU compilers represent multidimensional array types as sequences
2600 of one dimensional array types whose element types are themselves array
2601 types. Here we squish that down, so that each multidimensional array
2602 type gets only one array_type DIE in the Dwarf debugging info. The
2603 draft Dwarf specification say that we are allowed to do this kind
2604 of compression in C (because there is no difference between an
2605 array or arrays and a multidimensional array in C) but for other
2606 source languages (e.g. Ada) we probably shouldn't do this. */
2608 for (dimension_number = 0;
2609 TREE_CODE (type) == ARRAY_TYPE;
2610 type = TREE_TYPE (type), dimension_number++)
2612 register tree domain = TYPE_DOMAIN (type);
2614 /* Arrays come in three flavors. Unspecified bounds, fixed
2615 bounds, and (in GNU C only) variable bounds. Handle all
2616 three forms here. */
2620 /* We have an array type with specified bounds. */
2622 register tree lower = TYPE_MIN_VALUE (domain);
2623 register tree upper = TYPE_MAX_VALUE (domain);
2625 /* Handle only fundamental types as index types for now. */
2627 if (! type_is_fundamental (domain))
2630 /* Output the representation format byte for this dimension. */
2632 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2633 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2634 (upper && TREE_CODE (upper) == INTEGER_CST)));
2636 /* Output the index type for this dimension. */
2638 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2639 fundamental_type_code (domain));
2641 /* Output the representation for the lower bound. */
2643 output_bound_representation (lower, dimension_number, 'l');
2645 /* Output the representation for the upper bound. */
2647 output_bound_representation (upper, dimension_number, 'u');
2651 /* We have an array type with an unspecified length. For C and
2652 C++ we can assume that this really means that (a) the index
2653 type is an integral type, and (b) the lower bound is zero.
2654 Note that Dwarf defines the representation of an unspecified
2655 (upper) bound as being a zero-length location description. */
2657 /* Output the array-bounds format byte. */
2659 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2661 /* Output the (assumed) index type. */
2663 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2665 /* Output the (assumed) lower bound (constant) value. */
2667 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2669 /* Output the (empty) location description for the upper bound. */
2671 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2675 /* Output the prefix byte that says that the element type is coming up. */
2677 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2679 /* Output a representation of the type of the elements of this array type. */
2681 type_attribute (type, 0, 0);
2683 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2687 byte_size_attribute (tree_node)
2688 register tree tree_node;
2690 register unsigned size;
2692 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2693 switch (TREE_CODE (tree_node))
2702 case QUAL_UNION_TYPE:
2704 size = int_size_in_bytes (tree_node);
2708 /* For a data member of a struct or union, the AT_byte_size is
2709 generally given as the number of bytes normally allocated for
2710 an object of the *declared* type of the member itself. This
2711 is true even for bit-fields. */
2712 size = simple_type_size_in_bits (field_type (tree_node))
2720 /* Note that `size' might be -1 when we get to this point. If it
2721 is, that indicates that the byte size of the entity in question
2722 is variable. We have no good way of expressing this fact in Dwarf
2723 at the present time, so just let the -1 pass on through. */
2725 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2728 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2729 which specifies the distance in bits from the highest order bit of the
2730 "containing object" for the bit-field to the highest order bit of the
2733 For any given bit-field, the "containing object" is a hypothetical
2734 object (of some integral or enum type) within which the given bit-field
2735 lives. The type of this hypothetical "containing object" is always the
2736 same as the declared type of the individual bit-field itself.
2738 The determination of the exact location of the "containing object" for
2739 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2742 Note that it is the size (in bytes) of the hypothetical "containing
2743 object" which will be given in the AT_byte_size attribute for this
2744 bit-field. (See `byte_size_attribute' above.) */
2747 bit_offset_attribute (decl)
2750 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2751 register tree type = DECL_BIT_FIELD_TYPE (decl);
2752 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2753 register unsigned bitpos_int;
2754 register unsigned highest_order_object_bit_offset;
2755 register unsigned highest_order_field_bit_offset;
2756 register unsigned bit_offset;
2758 /* Must be a bit field. */
2760 || TREE_CODE (decl) != FIELD_DECL)
2763 /* We can't yet handle bit-fields whose offsets are variable, so if we
2764 encounter such things, just return without generating any attribute
2767 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2769 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2771 /* Note that the bit offset is always the distance (in bits) from the
2772 highest-order bit of the "containing object" to the highest-order
2773 bit of the bit-field itself. Since the "high-order end" of any
2774 object or field is different on big-endian and little-endian machines,
2775 the computation below must take account of these differences. */
2777 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2778 highest_order_field_bit_offset = bitpos_int;
2780 if (! BYTES_BIG_ENDIAN)
2782 highest_order_field_bit_offset
2783 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2785 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2790 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2791 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2793 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2794 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2797 /* For a FIELD_DECL node which represents a bit field, output an attribute
2798 which specifies the length in bits of the given field. */
2801 bit_size_attribute (decl)
2804 /* Must be a field and a bit field. */
2805 if (TREE_CODE (decl) != FIELD_DECL
2806 || ! DECL_BIT_FIELD_TYPE (decl))
2809 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2810 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2811 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2814 /* The following routine outputs the `element_list' attribute for enumeration
2815 type DIEs. The element_lits attribute includes the names and values of
2816 all of the enumeration constants associated with the given enumeration
2820 element_list_attribute (element)
2821 register tree element;
2823 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2824 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2826 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2827 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2828 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2829 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2830 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2832 /* Here we output a list of value/name pairs for each enumeration constant
2833 defined for this enumeration type (as required), but we do it in REVERSE
2834 order. The order is the one required by the draft #5 Dwarf specification
2835 published by the UI/PLSIG. */
2837 output_enumeral_list (element); /* Recursively output the whole list. */
2839 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2842 /* Generate an AT_stmt_list attribute. These are normally present only in
2843 DIEs with a TAG_compile_unit tag. */
2846 stmt_list_attribute (label)
2847 register const char *label;
2849 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2850 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2851 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2854 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2855 for a subroutine DIE. */
2858 low_pc_attribute (asm_low_label)
2859 register const char *asm_low_label;
2861 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2862 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2865 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2869 high_pc_attribute (asm_high_label)
2870 register const char *asm_high_label;
2872 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2873 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2876 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2879 body_begin_attribute (asm_begin_label)
2880 register const char *asm_begin_label;
2882 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2883 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2886 /* Generate an AT_body_end attribute for a subroutine DIE. */
2889 body_end_attribute (asm_end_label)
2890 register const char *asm_end_label;
2892 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2893 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2896 /* Generate an AT_language attribute given a LANG value. These attributes
2897 are used only within TAG_compile_unit DIEs. */
2900 language_attribute (language_code)
2901 register unsigned language_code;
2903 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2904 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2908 member_attribute (context)
2909 register tree context;
2911 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2913 /* Generate this attribute only for members in C++. */
2915 if (context != NULL && is_tagged_type (context))
2917 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2918 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2919 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2925 string_length_attribute (upper_bound)
2926 register tree upper_bound;
2928 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2929 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2931 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2932 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2933 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2934 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2935 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2936 output_bound_representation (upper_bound, 0, 'u');
2937 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2942 comp_dir_attribute (dirname)
2943 register const char *dirname;
2945 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2946 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
2950 sf_names_attribute (sf_names_start_label)
2951 register const char *sf_names_start_label;
2953 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2954 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2955 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2959 src_info_attribute (src_info_start_label)
2960 register const char *src_info_start_label;
2962 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2963 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2964 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2968 mac_info_attribute (mac_info_start_label)
2969 register const char *mac_info_start_label;
2971 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2972 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2973 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2977 prototyped_attribute (func_type)
2978 register tree func_type;
2980 if ((strcmp (language_string, "GNU C") == 0)
2981 && (TYPE_ARG_TYPES (func_type) != NULL))
2983 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2984 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2989 producer_attribute (producer)
2990 register const char *producer;
2992 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2993 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
2997 inline_attribute (decl)
3000 if (DECL_INLINE (decl))
3002 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
3003 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3008 containing_type_attribute (containing_type)
3009 register tree containing_type;
3011 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3013 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
3014 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
3015 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3019 abstract_origin_attribute (origin)
3020 register tree origin;
3022 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3024 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
3025 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
3028 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3032 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3036 abort (); /* Should never happen. */
3039 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3042 #ifdef DWARF_DECL_COORDINATES
3044 src_coords_attribute (src_fileno, src_lineno)
3045 register unsigned src_fileno;
3046 register unsigned src_lineno;
3048 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3049 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3050 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3052 #endif /* defined(DWARF_DECL_COORDINATES) */
3055 pure_or_virtual_attribute (func_decl)
3056 register tree func_decl;
3058 if (DECL_VIRTUAL_P (func_decl))
3060 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3061 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3062 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3065 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3066 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3070 /************************* end of attributes *****************************/
3072 /********************* utility routines for DIEs *************************/
3074 /* Output an AT_name attribute and an AT_src_coords attribute for the
3075 given decl, but only if it actually has a name. */
3078 name_and_src_coords_attributes (decl)
3081 register tree decl_name = DECL_NAME (decl);
3083 if (decl_name && IDENTIFIER_POINTER (decl_name))
3085 name_attribute (IDENTIFIER_POINTER (decl_name));
3086 #ifdef DWARF_DECL_COORDINATES
3088 register unsigned file_index;
3090 /* This is annoying, but we have to pop out of the .debug section
3091 for a moment while we call `lookup_filename' because calling it
3092 may cause a temporary switch into the .debug_sfnames section and
3093 most svr4 assemblers are not smart enough to be able to nest
3094 section switches to any depth greater than one. Note that we
3095 also can't skirt this issue by delaying all output to the
3096 .debug_sfnames section unit the end of compilation because that
3097 would cause us to have inter-section forward references and
3098 Fred Fish sez that m68k/svr4 assemblers botch those. */
3100 ASM_OUTPUT_POP_SECTION (asm_out_file);
3101 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3102 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3104 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3106 #endif /* defined(DWARF_DECL_COORDINATES) */
3110 /* Many forms of DIEs contain a "type description" part. The following
3111 routine writes out these "type descriptor" parts. */
3114 type_attribute (type, decl_const, decl_volatile)
3116 register int decl_const;
3117 register int decl_volatile;
3119 register enum tree_code code = TREE_CODE (type);
3120 register int root_type_modified;
3122 if (code == ERROR_MARK)
3125 /* Handle a special case. For functions whose return type is void,
3126 we generate *no* type attribute. (Note that no object may have
3127 type `void', so this only applies to function return types. */
3129 if (code == VOID_TYPE)
3132 /* If this is a subtype, find the underlying type. Eventually,
3133 this should write out the appropriate subtype info. */
3134 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3135 && TREE_TYPE (type) != 0)
3136 type = TREE_TYPE (type), code = TREE_CODE (type);
3138 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3139 || decl_const || decl_volatile
3140 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3142 if (type_is_fundamental (root_type (type)))
3144 if (root_type_modified)
3145 mod_fund_type_attribute (type, decl_const, decl_volatile);
3147 fund_type_attribute (fundamental_type_code (type));
3151 if (root_type_modified)
3152 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3154 /* We have to get the type_main_variant here (and pass that to the
3155 `user_def_type_attribute' routine) because the ..._TYPE node we
3156 have might simply be a *copy* of some original type node (where
3157 the copy was created to help us keep track of typedef names)
3158 and that copy might have a different TYPE_UID from the original
3159 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3160 is labeling a given type DIE for future reference, it always and
3161 only creates labels for DIEs representing *main variants*, and it
3162 never even knows about non-main-variants.) */
3163 user_def_type_attribute (type_main_variant (type));
3167 /* Given a tree pointer to a struct, class, union, or enum type node, return
3168 a pointer to the (string) tag name for the given type, or zero if the
3169 type was declared without a tag. */
3175 register char *name = 0;
3177 if (TYPE_NAME (type) != 0)
3179 register tree t = 0;
3181 /* Find the IDENTIFIER_NODE for the type name. */
3182 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3183 t = TYPE_NAME (type);
3185 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3186 a TYPE_DECL node, regardless of whether or not a `typedef' was
3188 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3189 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3190 t = DECL_NAME (TYPE_NAME (type));
3192 /* Now get the name as a string, or invent one. */
3194 name = IDENTIFIER_POINTER (t);
3197 return (name == 0 || *name == '\0') ? 0 : name;
3203 /* Start by checking if the pending_sibling_stack needs to be expanded.
3204 If necessary, expand it. */
3206 if (pending_siblings == pending_siblings_allocated)
3208 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3209 pending_sibling_stack
3210 = (unsigned *) xrealloc (pending_sibling_stack,
3211 pending_siblings_allocated * sizeof(unsigned));
3215 NEXT_DIE_NUM = next_unused_dienum++;
3218 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3228 member_declared_type (member)
3229 register tree member;
3231 return (DECL_BIT_FIELD_TYPE (member))
3232 ? DECL_BIT_FIELD_TYPE (member)
3233 : TREE_TYPE (member);
3236 /* Get the function's label, as described by its RTL.
3237 This may be different from the DECL_NAME name used
3238 in the source file. */
3241 function_start_label (decl)
3247 x = DECL_RTL (decl);
3248 if (GET_CODE (x) != MEM)
3251 if (GET_CODE (x) != SYMBOL_REF)
3253 fnname = XSTR (x, 0);
3258 /******************************* DIEs ************************************/
3260 /* Output routines for individual types of DIEs. */
3262 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3265 output_array_type_die (arg)
3268 register tree type = arg;
3270 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3271 sibling_attribute ();
3272 equate_type_number_to_die_number (type);
3273 member_attribute (TYPE_CONTEXT (type));
3275 /* I believe that we can default the array ordering. SDB will probably
3276 do the right things even if AT_ordering is not present. It's not
3277 even an issue until we start to get into multidimensional arrays
3278 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3279 dimensional arrays, then we'll have to put the AT_ordering attribute
3280 back in. (But if and when we find out that we need to put these in,
3281 we will only do so for multidimensional arrays. After all, we don't
3282 want to waste space in the .debug section now do we?) */
3284 #ifdef USE_ORDERING_ATTRIBUTE
3285 ordering_attribute (ORD_row_major);
3286 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3288 subscript_data_attribute (type);
3292 output_set_type_die (arg)
3295 register tree type = arg;
3297 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3298 sibling_attribute ();
3299 equate_type_number_to_die_number (type);
3300 member_attribute (TYPE_CONTEXT (type));
3301 type_attribute (TREE_TYPE (type), 0, 0);
3305 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3308 output_entry_point_die (arg)
3311 register tree decl = arg;
3312 register tree origin = decl_ultimate_origin (decl);
3314 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3315 sibling_attribute ();
3318 abstract_origin_attribute (origin);
3321 name_and_src_coords_attributes (decl);
3322 member_attribute (DECL_CONTEXT (decl));
3323 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3325 if (DECL_ABSTRACT (decl))
3326 equate_decl_number_to_die_number (decl);
3328 low_pc_attribute (function_start_label (decl));
3332 /* Output a DIE to represent an inlined instance of an enumeration type. */
3335 output_inlined_enumeration_type_die (arg)
3338 register tree type = arg;
3340 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3341 sibling_attribute ();
3342 if (!TREE_ASM_WRITTEN (type))
3344 abstract_origin_attribute (type);
3347 /* Output a DIE to represent an inlined instance of a structure type. */
3350 output_inlined_structure_type_die (arg)
3353 register tree type = arg;
3355 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3356 sibling_attribute ();
3357 if (!TREE_ASM_WRITTEN (type))
3359 abstract_origin_attribute (type);
3362 /* Output a DIE to represent an inlined instance of a union type. */
3365 output_inlined_union_type_die (arg)
3368 register tree type = arg;
3370 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3371 sibling_attribute ();
3372 if (!TREE_ASM_WRITTEN (type))
3374 abstract_origin_attribute (type);
3377 /* Output a DIE to represent an enumeration type. Note that these DIEs
3378 include all of the information about the enumeration values also.
3379 This information is encoded into the element_list attribute. */
3382 output_enumeration_type_die (arg)
3385 register tree type = arg;
3387 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3388 sibling_attribute ();
3389 equate_type_number_to_die_number (type);
3390 name_attribute (type_tag (type));
3391 member_attribute (TYPE_CONTEXT (type));
3393 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3394 given enum type is incomplete, do not generate the AT_byte_size
3395 attribute or the AT_element_list attribute. */
3397 if (TYPE_SIZE (type))
3399 byte_size_attribute (type);
3400 element_list_attribute (TYPE_FIELDS (type));
3404 /* Output a DIE to represent either a real live formal parameter decl or
3405 to represent just the type of some formal parameter position in some
3408 Note that this routine is a bit unusual because its argument may be
3409 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3410 represents an inlining of some PARM_DECL) or else some sort of a
3411 ..._TYPE node. If it's the former then this function is being called
3412 to output a DIE to represent a formal parameter object (or some inlining
3413 thereof). If it's the latter, then this function is only being called
3414 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3415 formal argument type of some subprogram type. */
3418 output_formal_parameter_die (arg)
3421 register tree node = arg;
3423 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3424 sibling_attribute ();
3426 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3428 case 'd': /* We were called with some kind of a ..._DECL node. */
3430 register tree origin = decl_ultimate_origin (node);
3433 abstract_origin_attribute (origin);
3436 name_and_src_coords_attributes (node);
3437 type_attribute (TREE_TYPE (node),
3438 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3440 if (DECL_ABSTRACT (node))
3441 equate_decl_number_to_die_number (node);
3443 location_or_const_value_attribute (node);
3447 case 't': /* We were called with some kind of a ..._TYPE node. */
3448 type_attribute (node, 0, 0);
3452 abort (); /* Should never happen. */
3456 /* Output a DIE to represent a declared function (either file-scope
3457 or block-local) which has "external linkage" (according to ANSI-C). */
3460 output_global_subroutine_die (arg)
3463 register tree decl = arg;
3464 register tree origin = decl_ultimate_origin (decl);
3466 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3467 sibling_attribute ();
3470 abstract_origin_attribute (origin);
3473 register tree type = TREE_TYPE (decl);
3475 name_and_src_coords_attributes (decl);
3476 inline_attribute (decl);
3477 prototyped_attribute (type);
3478 member_attribute (DECL_CONTEXT (decl));
3479 type_attribute (TREE_TYPE (type), 0, 0);
3480 pure_or_virtual_attribute (decl);
3482 if (DECL_ABSTRACT (decl))
3483 equate_decl_number_to_die_number (decl);
3486 if (! DECL_EXTERNAL (decl) && ! in_class
3487 && decl == current_function_decl)
3489 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3491 low_pc_attribute (function_start_label (decl));
3492 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3493 high_pc_attribute (label);
3494 if (use_gnu_debug_info_extensions)
3496 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3497 body_begin_attribute (label);
3498 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3499 body_end_attribute (label);
3505 /* Output a DIE to represent a declared data object (either file-scope
3506 or block-local) which has "external linkage" (according to ANSI-C). */
3509 output_global_variable_die (arg)
3512 register tree decl = arg;
3513 register tree origin = decl_ultimate_origin (decl);
3515 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3516 sibling_attribute ();
3518 abstract_origin_attribute (origin);
3521 name_and_src_coords_attributes (decl);
3522 member_attribute (DECL_CONTEXT (decl));
3523 type_attribute (TREE_TYPE (decl),
3524 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3526 if (DECL_ABSTRACT (decl))
3527 equate_decl_number_to_die_number (decl);
3530 if (! DECL_EXTERNAL (decl) && ! in_class
3531 && current_function_decl == decl_function_context (decl))
3532 location_or_const_value_attribute (decl);
3537 output_label_die (arg)
3540 register tree decl = arg;
3541 register tree origin = decl_ultimate_origin (decl);
3543 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3544 sibling_attribute ();
3546 abstract_origin_attribute (origin);
3548 name_and_src_coords_attributes (decl);
3549 if (DECL_ABSTRACT (decl))
3550 equate_decl_number_to_die_number (decl);
3553 register rtx insn = DECL_RTL (decl);
3555 /* Deleted labels are programmer specified labels which have been
3556 eliminated because of various optimisations. We still emit them
3557 here so that it is possible to put breakpoints on them. */
3558 if (GET_CODE (insn) == CODE_LABEL
3559 || ((GET_CODE (insn) == NOTE
3560 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3562 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3564 /* When optimization is enabled (via -O) some parts of the compiler
3565 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3566 represent source-level labels which were explicitly declared by
3567 the user. This really shouldn't be happening though, so catch
3568 it if it ever does happen. */
3570 if (INSN_DELETED_P (insn))
3571 abort (); /* Should never happen. */
3573 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3574 (unsigned) INSN_UID (insn));
3575 low_pc_attribute (label);
3581 output_lexical_block_die (arg)
3584 register tree stmt = arg;
3586 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3587 sibling_attribute ();
3589 if (! BLOCK_ABSTRACT (stmt))
3591 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3592 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3594 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3595 low_pc_attribute (begin_label);
3596 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3597 high_pc_attribute (end_label);
3602 output_inlined_subroutine_die (arg)
3605 register tree stmt = arg;
3607 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3608 sibling_attribute ();
3610 abstract_origin_attribute (block_ultimate_origin (stmt));
3611 if (! BLOCK_ABSTRACT (stmt))
3613 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3614 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3616 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3617 low_pc_attribute (begin_label);
3618 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3619 high_pc_attribute (end_label);
3623 /* Output a DIE to represent a declared data object (either file-scope
3624 or block-local) which has "internal linkage" (according to ANSI-C). */
3627 output_local_variable_die (arg)
3630 register tree decl = arg;
3631 register tree origin = decl_ultimate_origin (decl);
3633 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3634 sibling_attribute ();
3636 abstract_origin_attribute (origin);
3639 name_and_src_coords_attributes (decl);
3640 member_attribute (DECL_CONTEXT (decl));
3641 type_attribute (TREE_TYPE (decl),
3642 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3644 if (DECL_ABSTRACT (decl))
3645 equate_decl_number_to_die_number (decl);
3647 location_or_const_value_attribute (decl);
3651 output_member_die (arg)
3654 register tree decl = arg;
3656 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3657 sibling_attribute ();
3658 name_and_src_coords_attributes (decl);
3659 member_attribute (DECL_CONTEXT (decl));
3660 type_attribute (member_declared_type (decl),
3661 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3662 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3664 byte_size_attribute (decl);
3665 bit_size_attribute (decl);
3666 bit_offset_attribute (decl);
3668 data_member_location_attribute (decl);
3672 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3673 modified types instead.
3675 We keep this code here just in case these types of DIEs may be
3676 needed to represent certain things in other languages (e.g. Pascal)
3680 output_pointer_type_die (arg)
3683 register tree type = arg;
3685 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3686 sibling_attribute ();
3687 equate_type_number_to_die_number (type);
3688 member_attribute (TYPE_CONTEXT (type));
3689 type_attribute (TREE_TYPE (type), 0, 0);
3693 output_reference_type_die (arg)
3696 register tree type = arg;
3698 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3699 sibling_attribute ();
3700 equate_type_number_to_die_number (type);
3701 member_attribute (TYPE_CONTEXT (type));
3702 type_attribute (TREE_TYPE (type), 0, 0);
3707 output_ptr_to_mbr_type_die (arg)
3710 register tree type = arg;
3712 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3713 sibling_attribute ();
3714 equate_type_number_to_die_number (type);
3715 member_attribute (TYPE_CONTEXT (type));
3716 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3717 type_attribute (TREE_TYPE (type), 0, 0);
3721 output_compile_unit_die (arg)
3724 register char *main_input_filename = arg;
3726 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3727 sibling_attribute ();
3729 name_attribute (main_input_filename);
3734 sprintf (producer, "%s %s", language_string, version_string);
3735 producer_attribute (producer);
3738 if (strcmp (language_string, "GNU C++") == 0)
3739 language_attribute (LANG_C_PLUS_PLUS);
3740 else if (strcmp (language_string, "GNU Ada") == 0)
3741 language_attribute (LANG_ADA83);
3742 else if (strcmp (language_string, "GNU F77") == 0)
3743 language_attribute (LANG_FORTRAN77);
3744 else if (strcmp (language_string, "GNU Pascal") == 0)
3745 language_attribute (LANG_PASCAL83);
3746 else if (flag_traditional)
3747 language_attribute (LANG_C);
3749 language_attribute (LANG_C89);
3750 low_pc_attribute (TEXT_BEGIN_LABEL);
3751 high_pc_attribute (TEXT_END_LABEL);
3752 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3753 stmt_list_attribute (LINE_BEGIN_LABEL);
3754 last_filename = xstrdup (main_input_filename);
3757 char *wd = getpwd ();
3759 comp_dir_attribute (wd);
3762 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3764 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3765 src_info_attribute (SRCINFO_BEGIN_LABEL);
3766 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3767 mac_info_attribute (MACINFO_BEGIN_LABEL);
3772 output_string_type_die (arg)
3775 register tree type = arg;
3777 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3778 sibling_attribute ();
3779 equate_type_number_to_die_number (type);
3780 member_attribute (TYPE_CONTEXT (type));
3781 /* this is a fixed length string */
3782 byte_size_attribute (type);
3786 output_inheritance_die (arg)
3789 register tree binfo = arg;
3791 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3792 sibling_attribute ();
3793 type_attribute (BINFO_TYPE (binfo), 0, 0);
3794 data_member_location_attribute (binfo);
3795 if (TREE_VIA_VIRTUAL (binfo))
3797 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3798 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3800 if (TREE_VIA_PUBLIC (binfo))
3802 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3803 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3805 else if (TREE_VIA_PROTECTED (binfo))
3807 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3808 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3813 output_structure_type_die (arg)
3816 register tree type = arg;
3818 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3819 sibling_attribute ();
3820 equate_type_number_to_die_number (type);
3821 name_attribute (type_tag (type));
3822 member_attribute (TYPE_CONTEXT (type));
3824 /* If this type has been completed, then give it a byte_size attribute
3825 and prepare to give a list of members. Otherwise, don't do either of
3826 these things. In the latter case, we will not be generating a list
3827 of members (since we don't have any idea what they might be for an
3828 incomplete type). */
3830 if (TYPE_SIZE (type))
3833 byte_size_attribute (type);
3837 /* Output a DIE to represent a declared function (either file-scope
3838 or block-local) which has "internal linkage" (according to ANSI-C). */
3841 output_local_subroutine_die (arg)
3844 register tree decl = arg;
3845 register tree origin = decl_ultimate_origin (decl);
3847 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3848 sibling_attribute ();
3851 abstract_origin_attribute (origin);
3854 register tree type = TREE_TYPE (decl);
3856 name_and_src_coords_attributes (decl);
3857 inline_attribute (decl);
3858 prototyped_attribute (type);
3859 member_attribute (DECL_CONTEXT (decl));
3860 type_attribute (TREE_TYPE (type), 0, 0);
3861 pure_or_virtual_attribute (decl);
3863 if (DECL_ABSTRACT (decl))
3864 equate_decl_number_to_die_number (decl);
3867 /* Avoid getting screwed up in cases where a function was declared
3868 static but where no definition was ever given for it. */
3870 if (TREE_ASM_WRITTEN (decl))
3872 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3873 low_pc_attribute (function_start_label (decl));
3874 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3875 high_pc_attribute (label);
3876 if (use_gnu_debug_info_extensions)
3878 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3879 body_begin_attribute (label);
3880 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3881 body_end_attribute (label);
3888 output_subroutine_type_die (arg)
3891 register tree type = arg;
3892 register tree return_type = TREE_TYPE (type);
3894 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3895 sibling_attribute ();
3897 equate_type_number_to_die_number (type);
3898 prototyped_attribute (type);
3899 member_attribute (TYPE_CONTEXT (type));
3900 type_attribute (return_type, 0, 0);
3904 output_typedef_die (arg)
3907 register tree decl = arg;
3908 register tree origin = decl_ultimate_origin (decl);
3910 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3911 sibling_attribute ();
3913 abstract_origin_attribute (origin);
3916 name_and_src_coords_attributes (decl);
3917 member_attribute (DECL_CONTEXT (decl));
3918 type_attribute (TREE_TYPE (decl),
3919 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3921 if (DECL_ABSTRACT (decl))
3922 equate_decl_number_to_die_number (decl);
3926 output_union_type_die (arg)
3929 register tree type = arg;
3931 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3932 sibling_attribute ();
3933 equate_type_number_to_die_number (type);
3934 name_attribute (type_tag (type));
3935 member_attribute (TYPE_CONTEXT (type));
3937 /* If this type has been completed, then give it a byte_size attribute
3938 and prepare to give a list of members. Otherwise, don't do either of
3939 these things. In the latter case, we will not be generating a list
3940 of members (since we don't have any idea what they might be for an
3941 incomplete type). */
3943 if (TYPE_SIZE (type))
3946 byte_size_attribute (type);
3950 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3951 at the end of an (ANSI prototyped) formal parameters list. */
3954 output_unspecified_parameters_die (arg)
3957 register tree decl_or_type = arg;
3959 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3960 sibling_attribute ();
3962 /* This kludge is here only for the sake of being compatible with what
3963 the USL CI5 C compiler does. The specification of Dwarf Version 1
3964 doesn't say that TAG_unspecified_parameters DIEs should contain any
3965 attributes other than the AT_sibling attribute, but they are certainly
3966 allowed to contain additional attributes, and the CI5 compiler
3967 generates AT_name, AT_fund_type, and AT_location attributes within
3968 TAG_unspecified_parameters DIEs which appear in the child lists for
3969 DIEs representing function definitions, so we do likewise here. */
3971 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3973 name_attribute ("...");
3974 fund_type_attribute (FT_pointer);
3975 /* location_attribute (?); */
3980 output_padded_null_die (arg)
3981 register void *arg ATTRIBUTE_UNUSED;
3983 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3986 /*************************** end of DIEs *********************************/
3988 /* Generate some type of DIE. This routine generates the generic outer
3989 wrapper stuff which goes around all types of DIE's (regardless of their
3990 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3991 DIE-length word, followed by the guts of the DIE itself. After the guts
3992 of the DIE, there must always be a terminator label for the DIE. */
3995 output_die (die_specific_output_function, param)
3996 register void (*die_specific_output_function) PARAMS ((void *));
3997 register void *param;
3999 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4000 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4002 current_dienum = NEXT_DIE_NUM;
4003 NEXT_DIE_NUM = next_unused_dienum;
4005 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4006 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
4008 /* Write a label which will act as the name for the start of this DIE. */
4010 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4012 /* Write the DIE-length word. */
4014 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
4016 /* Fill in the guts of the DIE. */
4018 next_unused_dienum++;
4019 die_specific_output_function (param);
4021 /* Write a label which will act as the name for the end of this DIE. */
4023 ASM_OUTPUT_LABEL (asm_out_file, end_label);
4027 end_sibling_chain ()
4029 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4031 current_dienum = NEXT_DIE_NUM;
4032 NEXT_DIE_NUM = next_unused_dienum;
4034 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4036 /* Write a label which will act as the name for the start of this DIE. */
4038 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4040 /* Write the DIE-length word. */
4042 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4047 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4048 TAG_unspecified_parameters DIE) to represent the types of the formal
4049 parameters as specified in some function type specification (except
4050 for those which appear as part of a function *definition*).
4052 Note that we must be careful here to output all of the parameter
4053 DIEs *before* we output any DIEs needed to represent the types of
4054 the formal parameters. This keeps svr4 SDB happy because it
4055 (incorrectly) thinks that the first non-parameter DIE it sees ends
4056 the formal parameter list. */
4059 output_formal_types (function_or_method_type)
4060 register tree function_or_method_type;
4063 register tree formal_type = NULL;
4064 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4066 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4067 get bogus recursion when outputting tagged types local to a
4068 function declaration. */
4069 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4070 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4072 /* In the case where we are generating a formal types list for a C++
4073 non-static member function type, skip over the first thing on the
4074 TYPE_ARG_TYPES list because it only represents the type of the
4075 hidden `this pointer'. The debugger should be able to figure
4076 out (without being explicitly told) that this non-static member
4077 function type takes a `this pointer' and should be able to figure
4078 what the type of that hidden parameter is from the AT_member
4079 attribute of the parent TAG_subroutine_type DIE. */
4081 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4082 first_parm_type = TREE_CHAIN (first_parm_type);
4084 /* Make our first pass over the list of formal parameter types and output
4085 a TAG_formal_parameter DIE for each one. */
4087 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4089 formal_type = TREE_VALUE (link);
4090 if (formal_type == void_type_node)
4093 /* Output a (nameless) DIE to represent the formal parameter itself. */
4095 output_die (output_formal_parameter_die, formal_type);
4098 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4099 DIE to the end of the parameter list. */
4101 if (formal_type != void_type_node)
4102 output_die (output_unspecified_parameters_die, function_or_method_type);
4104 /* Make our second (and final) pass over the list of formal parameter types
4105 and output DIEs to represent those types (as necessary). */
4107 for (link = TYPE_ARG_TYPES (function_or_method_type);
4109 link = TREE_CHAIN (link))
4111 formal_type = TREE_VALUE (link);
4112 if (formal_type == void_type_node)
4115 output_type (formal_type, function_or_method_type);
4118 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4121 /* Remember a type in the pending_types_list. */
4127 if (pending_types == pending_types_allocated)
4129 pending_types_allocated += PENDING_TYPES_INCREMENT;
4131 = (tree *) xrealloc (pending_types_list,
4132 sizeof (tree) * pending_types_allocated);
4134 pending_types_list[pending_types++] = type;
4136 /* Mark the pending type as having been output already (even though
4137 it hasn't been). This prevents the type from being added to the
4138 pending_types_list more than once. */
4140 TREE_ASM_WRITTEN (type) = 1;
4143 /* Return non-zero if it is legitimate to output DIEs to represent a
4144 given type while we are generating the list of child DIEs for some
4145 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4147 See the comments within the function for a description of when it is
4148 considered legitimate to output DIEs for various kinds of types.
4150 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4151 or it may point to a BLOCK node (for types local to a block), or to a
4152 FUNCTION_DECL node (for types local to the heading of some function
4153 definition), or to a FUNCTION_TYPE node (for types local to the
4154 prototyped parameter list of a function type specification), or to a
4155 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4156 (in the case of C++ nested types).
4158 The `scope' parameter should likewise be NULL or should point to a
4159 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4160 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4162 This function is used only for deciding when to "pend" and when to
4163 "un-pend" types to/from the pending_types_list.
4165 Note that we sometimes make use of this "type pending" feature in a
4166 rather twisted way to temporarily delay the production of DIEs for the
4167 types of formal parameters. (We do this just to make svr4 SDB happy.)
4168 It order to delay the production of DIEs representing types of formal
4169 parameters, callers of this function supply `fake_containing_scope' as
4170 the `scope' parameter to this function. Given that fake_containing_scope
4171 is a tagged type which is *not* the containing scope for *any* other type,
4172 the desired effect is achieved, i.e. output of DIEs representing types
4173 is temporarily suspended, and any type DIEs which would have otherwise
4174 been output are instead placed onto the pending_types_list. Later on,
4175 we force these (temporarily pended) types to be output simply by calling
4176 `output_pending_types_for_scope' with an actual argument equal to the
4177 true scope of the types we temporarily pended. */
4180 type_ok_for_scope (type, scope)
4182 register tree scope;
4184 /* Tagged types (i.e. struct, union, and enum types) must always be
4185 output only in the scopes where they actually belong (or else the
4186 scoping of their own tag names and the scoping of their member
4187 names will be incorrect). Non-tagged-types on the other hand can
4188 generally be output anywhere, except that svr4 SDB really doesn't
4189 want to see them nested within struct or union types, so here we
4190 say it is always OK to immediately output any such a (non-tagged)
4191 type, so long as we are not within such a context. Note that the
4192 only kinds of non-tagged types which we will be dealing with here
4193 (for C and C++ anyway) will be array types and function types. */
4195 return is_tagged_type (type)
4196 ? (TYPE_CONTEXT (type) == scope
4197 /* Ignore namespaces for the moment. */
4198 || (scope == NULL_TREE
4199 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4200 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4201 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4202 : (scope == NULL_TREE || ! is_tagged_type (scope));
4205 /* Output any pending types (from the pending_types list) which we can output
4206 now (taking into account the scope that we are working on now).
4208 For each type output, remove the given type from the pending_types_list
4209 *before* we try to output it.
4211 Note that we have to process the list in beginning-to-end order,
4212 because the call made here to output_type may cause yet more types
4213 to be added to the end of the list, and we may have to output some
4217 output_pending_types_for_scope (containing_scope)
4218 register tree containing_scope;
4220 register unsigned i;
4222 for (i = 0; i < pending_types; )
4224 register tree type = pending_types_list[i];
4226 if (type_ok_for_scope (type, containing_scope))
4228 register tree *mover;
4229 register tree *limit;
4232 limit = &pending_types_list[pending_types];
4233 for (mover = &pending_types_list[i]; mover < limit; mover++)
4234 *mover = *(mover+1);
4236 /* Un-mark the type as having been output already (because it
4237 hasn't been, really). Then call output_type to generate a
4238 Dwarf representation of it. */
4240 TREE_ASM_WRITTEN (type) = 0;
4241 output_type (type, containing_scope);
4243 /* Don't increment the loop counter in this case because we
4244 have shifted all of the subsequent pending types down one
4245 element in the pending_types_list array. */
4252 /* Remember a type in the incomplete_types_list. */
4255 add_incomplete_type (type)
4258 if (incomplete_types == incomplete_types_allocated)
4260 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4261 incomplete_types_list
4262 = (tree *) xrealloc (incomplete_types_list,
4263 sizeof (tree) * incomplete_types_allocated);
4266 incomplete_types_list[incomplete_types++] = type;
4269 /* Walk through the list of incomplete types again, trying once more to
4270 emit full debugging info for them. */
4273 retry_incomplete_types ()
4278 while (incomplete_types)
4281 type = incomplete_types_list[incomplete_types];
4282 output_type (type, NULL_TREE);
4287 output_type (type, containing_scope)
4289 register tree containing_scope;
4291 if (type == 0 || type == error_mark_node)
4294 /* We are going to output a DIE to represent the unqualified version of
4295 this type (i.e. without any const or volatile qualifiers) so get
4296 the main variant (i.e. the unqualified version) of this type now. */
4298 type = type_main_variant (type);
4300 if (TREE_ASM_WRITTEN (type))
4302 if (finalizing && AGGREGATE_TYPE_P (type))
4304 register tree member;
4306 /* Some of our nested types might not have been defined when we
4307 were written out before; force them out now. */
4309 for (member = TYPE_FIELDS (type); member;
4310 member = TREE_CHAIN (member))
4311 if (TREE_CODE (member) == TYPE_DECL
4312 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4313 output_type (TREE_TYPE (member), containing_scope);
4318 /* If this is a nested type whose containing class hasn't been
4319 written out yet, writing it out will cover this one, too. */
4321 if (TYPE_CONTEXT (type)
4322 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4323 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4325 output_type (TYPE_CONTEXT (type), containing_scope);
4329 /* Don't generate any DIEs for this type now unless it is OK to do so
4330 (based upon what `type_ok_for_scope' tells us). */
4332 if (! type_ok_for_scope (type, containing_scope))
4338 switch (TREE_CODE (type))
4344 case REFERENCE_TYPE:
4345 /* Prevent infinite recursion in cases where this is a recursive
4346 type. Recursive types are possible in Ada. */
4347 TREE_ASM_WRITTEN (type) = 1;
4348 /* For these types, all that is required is that we output a DIE
4349 (or a set of DIEs) to represent the "basis" type. */
4350 output_type (TREE_TYPE (type), containing_scope);
4354 /* This code is used for C++ pointer-to-data-member types. */
4355 /* Output a description of the relevant class type. */
4356 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4357 /* Output a description of the type of the object pointed to. */
4358 output_type (TREE_TYPE (type), containing_scope);
4359 /* Now output a DIE to represent this pointer-to-data-member type
4361 output_die (output_ptr_to_mbr_type_die, type);
4365 output_type (TYPE_DOMAIN (type), containing_scope);
4366 output_die (output_set_type_die, type);
4370 output_type (TREE_TYPE (type), containing_scope);
4371 abort (); /* No way to represent these in Dwarf yet! */
4375 /* Force out return type (in case it wasn't forced out already). */
4376 output_type (TREE_TYPE (type), containing_scope);
4377 output_die (output_subroutine_type_die, type);
4378 output_formal_types (type);
4379 end_sibling_chain ();
4383 /* Force out return type (in case it wasn't forced out already). */
4384 output_type (TREE_TYPE (type), containing_scope);
4385 output_die (output_subroutine_type_die, type);
4386 output_formal_types (type);
4387 end_sibling_chain ();
4391 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4393 output_type (TREE_TYPE (type), containing_scope);
4394 output_die (output_string_type_die, type);
4398 register tree element_type;
4400 element_type = TREE_TYPE (type);
4401 while (TREE_CODE (element_type) == ARRAY_TYPE)
4402 element_type = TREE_TYPE (element_type);
4404 output_type (element_type, containing_scope);
4405 output_die (output_array_type_die, type);
4412 case QUAL_UNION_TYPE:
4414 /* For a non-file-scope tagged type, we can always go ahead and
4415 output a Dwarf description of this type right now, even if
4416 the type in question is still incomplete, because if this
4417 local type *was* ever completed anywhere within its scope,
4418 that complete definition would already have been attached to
4419 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4420 node by the time we reach this point. That's true because of the
4421 way the front-end does its processing of file-scope declarations (of
4422 functions and class types) within which other types might be
4423 nested. The C and C++ front-ends always gobble up such "local
4424 scope" things en-mass before they try to output *any* debugging
4425 information for any of the stuff contained inside them and thus,
4426 we get the benefit here of what is (in effect) a pre-resolution
4427 of forward references to tagged types in local scopes.
4429 Note however that for file-scope tagged types we cannot assume
4430 that such pre-resolution of forward references has taken place.
4431 A given file-scope tagged type may appear to be incomplete when
4432 we reach this point, but it may yet be given a full definition
4433 (at file-scope) later on during compilation. In order to avoid
4434 generating a premature (and possibly incorrect) set of Dwarf
4435 DIEs for such (as yet incomplete) file-scope tagged types, we
4436 generate nothing at all for as-yet incomplete file-scope tagged
4437 types here unless we are making our special "finalization" pass
4438 for file-scope things at the very end of compilation. At that
4439 time, we will certainly know as much about each file-scope tagged
4440 type as we are ever going to know, so at that point in time, we
4441 can safely generate correct Dwarf descriptions for these file-
4442 scope tagged types. */
4444 if (TYPE_SIZE (type) == 0
4445 && (TYPE_CONTEXT (type) == NULL
4446 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4447 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4450 /* We don't need to do this for function-local types. */
4451 if (! decl_function_context (TYPE_STUB_DECL (type)))
4452 add_incomplete_type (type);
4453 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4456 /* Prevent infinite recursion in cases where the type of some
4457 member of this type is expressed in terms of this type itself. */
4459 TREE_ASM_WRITTEN (type) = 1;
4461 /* Output a DIE to represent the tagged type itself. */
4463 switch (TREE_CODE (type))
4466 output_die (output_enumeration_type_die, type);
4467 return; /* a special case -- nothing left to do so just return */
4470 output_die (output_structure_type_die, type);
4474 case QUAL_UNION_TYPE:
4475 output_die (output_union_type_die, type);
4479 abort (); /* Should never happen. */
4482 /* If this is not an incomplete type, output descriptions of
4483 each of its members.
4485 Note that as we output the DIEs necessary to represent the
4486 members of this record or union type, we will also be trying
4487 to output DIEs to represent the *types* of those members.
4488 However the `output_type' function (above) will specifically
4489 avoid generating type DIEs for member types *within* the list
4490 of member DIEs for this (containing) type execpt for those
4491 types (of members) which are explicitly marked as also being
4492 members of this (containing) type themselves. The g++ front-
4493 end can force any given type to be treated as a member of some
4494 other (containing) type by setting the TYPE_CONTEXT of the
4495 given (member) type to point to the TREE node representing the
4496 appropriate (containing) type.
4499 if (TYPE_SIZE (type))
4501 /* First output info about the base classes. */
4502 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4504 register tree bases = TYPE_BINFO_BASETYPES (type);
4505 register int n_bases = TREE_VEC_LENGTH (bases);
4508 for (i = 0; i < n_bases; i++)
4510 tree binfo = TREE_VEC_ELT (bases, i);
4511 output_type (BINFO_TYPE (binfo), containing_scope);
4512 output_die (output_inheritance_die, binfo);
4519 register tree normal_member;
4521 /* Now output info about the data members and type members. */
4523 for (normal_member = TYPE_FIELDS (type);
4525 normal_member = TREE_CHAIN (normal_member))
4526 output_decl (normal_member, type);
4530 register tree func_member;
4532 /* Now output info about the function members (if any). */
4534 for (func_member = TYPE_METHODS (type);
4536 func_member = TREE_CHAIN (func_member))
4537 output_decl (func_member, type);
4542 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4543 scopes (at least in C++) so we must now output any nested
4544 pending types which are local just to this type. */
4546 output_pending_types_for_scope (type);
4548 end_sibling_chain (); /* Terminate member chain. */
4559 break; /* No DIEs needed for fundamental types. */
4561 case LANG_TYPE: /* No Dwarf representation currently defined. */
4568 TREE_ASM_WRITTEN (type) = 1;
4572 output_tagged_type_instantiation (type)
4575 if (type == 0 || type == error_mark_node)
4578 /* We are going to output a DIE to represent the unqualified version of
4579 this type (i.e. without any const or volatile qualifiers) so make
4580 sure that we have the main variant (i.e. the unqualified version) of
4583 if (type != type_main_variant (type))
4586 if (!TREE_ASM_WRITTEN (type))
4589 switch (TREE_CODE (type))
4595 output_die (output_inlined_enumeration_type_die, type);
4599 output_die (output_inlined_structure_type_die, type);
4603 case QUAL_UNION_TYPE:
4604 output_die (output_inlined_union_type_die, type);
4608 abort (); /* Should never happen. */
4612 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4613 the things which are local to the given block. */
4616 output_block (stmt, depth)
4620 register int must_output_die = 0;
4621 register tree origin;
4622 register enum tree_code origin_code;
4624 /* Ignore blocks never really used to make RTL. */
4626 if (! stmt || ! TREE_USED (stmt)
4627 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
4630 /* Determine the "ultimate origin" of this block. This block may be an
4631 inlined instance of an inlined instance of inline function, so we
4632 have to trace all of the way back through the origin chain to find
4633 out what sort of node actually served as the original seed for the
4634 creation of the current block. */
4636 origin = block_ultimate_origin (stmt);
4637 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4639 /* Determine if we need to output any Dwarf DIEs at all to represent this
4642 if (origin_code == FUNCTION_DECL)
4643 /* The outer scopes for inlinings *must* always be represented. We
4644 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4645 must_output_die = 1;
4648 /* In the case where the current block represents an inlining of the
4649 "body block" of an inline function, we must *NOT* output any DIE
4650 for this block because we have already output a DIE to represent
4651 the whole inlined function scope and the "body block" of any
4652 function doesn't really represent a different scope according to
4653 ANSI C rules. So we check here to make sure that this block does
4654 not represent a "body block inlining" before trying to set the
4655 `must_output_die' flag. */
4657 if (! is_body_block (origin ? origin : stmt))
4659 /* Determine if this block directly contains any "significant"
4660 local declarations which we will need to output DIEs for. */
4662 if (debug_info_level > DINFO_LEVEL_TERSE)
4663 /* We are not in terse mode so *any* local declaration counts
4664 as being a "significant" one. */
4665 must_output_die = (BLOCK_VARS (stmt) != NULL);
4670 /* We are in terse mode, so only local (nested) function
4671 definitions count as "significant" local declarations. */
4673 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4674 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4676 must_output_die = 1;
4683 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4684 DIE for any block which contains no significant local declarations
4685 at all. Rather, in such cases we just call `output_decls_for_scope'
4686 so that any needed Dwarf info for any sub-blocks will get properly
4687 generated. Note that in terse mode, our definition of what constitutes
4688 a "significant" local declaration gets restricted to include only
4689 inlined function instances and local (nested) function definitions. */
4691 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4692 /* We don't care about an abstract inlined subroutine. */;
4693 else if (must_output_die)
4695 output_die ((origin_code == FUNCTION_DECL)
4696 ? output_inlined_subroutine_die
4697 : output_lexical_block_die,
4699 output_decls_for_scope (stmt, depth);
4700 end_sibling_chain ();
4703 output_decls_for_scope (stmt, depth);
4706 /* Output all of the decls declared within a given scope (also called
4707 a `binding contour') and (recursively) all of it's sub-blocks. */
4710 output_decls_for_scope (stmt, depth)
4714 /* Ignore blocks never really used to make RTL. */
4716 if (! stmt || ! TREE_USED (stmt))
4719 /* Output the DIEs to represent all of the data objects, functions,
4720 typedefs, and tagged types declared directly within this block
4721 but not within any nested sub-blocks. */
4726 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4727 output_decl (decl, stmt);
4730 output_pending_types_for_scope (stmt);
4732 /* Output the DIEs to represent all sub-blocks (and the items declared
4733 therein) of this block. */
4736 register tree subblocks;
4738 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4740 subblocks = BLOCK_CHAIN (subblocks))
4741 output_block (subblocks, depth + 1);
4745 /* Is this a typedef we can avoid emitting? */
4748 is_redundant_typedef (decl)
4751 if (TYPE_DECL_IS_STUB (decl))
4753 if (DECL_ARTIFICIAL (decl)
4754 && DECL_CONTEXT (decl)
4755 && is_tagged_type (DECL_CONTEXT (decl))
4756 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4757 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4758 /* Also ignore the artificial member typedef for the class name. */
4763 /* Output Dwarf .debug information for a decl described by DECL. */
4766 output_decl (decl, containing_scope)
4768 register tree containing_scope;
4770 /* Make a note of the decl node we are going to be working on. We may
4771 need to give the user the source coordinates of where it appeared in
4772 case we notice (later on) that something about it looks screwy. */
4774 dwarf_last_decl = decl;
4776 if (TREE_CODE (decl) == ERROR_MARK)
4779 /* If a structure is declared within an initialization, e.g. as the
4780 operand of a sizeof, then it will not have a name. We don't want
4781 to output a DIE for it, as the tree nodes are in the temporary obstack */
4783 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4784 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4785 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4786 || (TYPE_FIELDS (TREE_TYPE (decl))
4787 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4790 /* If this ..._DECL node is marked to be ignored, then ignore it. */
4792 if (DECL_IGNORED_P (decl))
4795 switch (TREE_CODE (decl))
4798 /* The individual enumerators of an enum type get output when we
4799 output the Dwarf representation of the relevant enum type itself. */
4803 /* If we are in terse mode, don't output any DIEs to represent
4804 mere function declarations. Also, if we are conforming
4805 to the DWARF version 1 specification, don't output DIEs for
4806 mere function declarations. */
4808 if (DECL_INITIAL (decl) == NULL_TREE)
4809 #if (DWARF_VERSION > 1)
4810 if (debug_info_level <= DINFO_LEVEL_TERSE)
4814 /* Before we describe the FUNCTION_DECL itself, make sure that we
4815 have described its return type. */
4817 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4820 /* And its containing type. */
4821 register tree origin = decl_class_context (decl);
4823 output_type (origin, containing_scope);
4826 /* If the following DIE will represent a function definition for a
4827 function with "extern" linkage, output a special "pubnames" DIE
4828 label just ahead of the actual DIE. A reference to this label
4829 was already generated in the .debug_pubnames section sub-entry
4830 for this function definition. */
4832 if (TREE_PUBLIC (decl))
4834 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4836 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4837 ASM_OUTPUT_LABEL (asm_out_file, label);
4840 /* Now output a DIE to represent the function itself. */
4842 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4843 ? output_global_subroutine_die
4844 : output_local_subroutine_die,
4847 /* Now output descriptions of the arguments for this function.
4848 This gets (unnecessarily?) complex because of the fact that
4849 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4850 cases where there was a trailing `...' at the end of the formal
4851 parameter list. In order to find out if there was a trailing
4852 ellipsis or not, we must instead look at the type associated
4853 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4854 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4855 ends with a void_type_node then there should *not* be an ellipsis
4858 /* In the case where we are describing a mere function declaration, all
4859 we need to do here (and all we *can* do here) is to describe
4860 the *types* of its formal parameters. */
4862 if (decl != current_function_decl || in_class)
4863 output_formal_types (TREE_TYPE (decl));
4866 /* Generate DIEs to represent all known formal parameters */
4868 register tree arg_decls = DECL_ARGUMENTS (decl);
4871 /* WARNING! Kludge zone ahead! Here we have a special
4872 hack for svr4 SDB compatibility. Instead of passing the
4873 current FUNCTION_DECL node as the second parameter (i.e.
4874 the `containing_scope' parameter) to `output_decl' (as
4875 we ought to) we instead pass a pointer to our own private
4876 fake_containing_scope node. That node is a RECORD_TYPE
4877 node which NO OTHER TYPE may ever actually be a member of.
4879 This pointer will ultimately get passed into `output_type'
4880 as its `containing_scope' parameter. `Output_type' will
4881 then perform its part in the hack... i.e. it will pend
4882 the type of the formal parameter onto the pending_types
4883 list. Later on, when we are done generating the whole
4884 sequence of formal parameter DIEs for this function
4885 definition, we will un-pend all previously pended types
4886 of formal parameters for this function definition.
4888 This whole kludge prevents any type DIEs from being
4889 mixed in with the formal parameter DIEs. That's good
4890 because svr4 SDB believes that the list of formal
4891 parameter DIEs for a function ends wherever the first
4892 non-formal-parameter DIE appears. Thus, we have to
4893 keep the formal parameter DIEs segregated. They must
4894 all appear (consecutively) at the start of the list of
4895 children for the DIE representing the function definition.
4896 Then (and only then) may we output any additional DIEs
4897 needed to represent the types of these formal parameters.
4901 When generating DIEs, generate the unspecified_parameters
4902 DIE instead if we come across the arg "__builtin_va_alist"
4905 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4906 if (TREE_CODE (parm) == PARM_DECL)
4908 if (DECL_NAME(parm) &&
4909 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4910 "__builtin_va_alist") )
4911 output_die (output_unspecified_parameters_die, decl);
4913 output_decl (parm, fake_containing_scope);
4917 Now that we have finished generating all of the DIEs to
4918 represent the formal parameters themselves, force out
4919 any DIEs needed to represent their types. We do this
4920 simply by un-pending all previously pended types which
4921 can legitimately go into the chain of children DIEs for
4922 the current FUNCTION_DECL.
4925 output_pending_types_for_scope (decl);
4928 Decide whether we need a unspecified_parameters DIE at the end.
4929 There are 2 more cases to do this for:
4930 1) the ansi ... declaration - this is detectable when the end
4931 of the arg list is not a void_type_node
4932 2) an unprototyped function declaration (not a definition). This
4933 just means that we have no info about the parameters at all.
4937 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4941 /* this is the prototyped case, check for ... */
4942 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4943 output_die (output_unspecified_parameters_die, decl);
4947 /* this is unprototyped, check for undefined (just declaration) */
4948 if (!DECL_INITIAL (decl))
4949 output_die (output_unspecified_parameters_die, decl);
4953 /* Output Dwarf info for all of the stuff within the body of the
4954 function (if it has one - it may be just a declaration). */
4957 register tree outer_scope = DECL_INITIAL (decl);
4959 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4961 /* Note that here, `outer_scope' is a pointer to the outermost
4962 BLOCK node created to represent a function.
4963 This outermost BLOCK actually represents the outermost
4964 binding contour for the function, i.e. the contour in which
4965 the function's formal parameters and labels get declared.
4967 Curiously, it appears that the front end doesn't actually
4968 put the PARM_DECL nodes for the current function onto the
4969 BLOCK_VARS list for this outer scope. (They are strung
4970 off of the DECL_ARGUMENTS list for the function instead.)
4971 The BLOCK_VARS list for the `outer_scope' does provide us
4972 with a list of the LABEL_DECL nodes for the function however,
4973 and we output DWARF info for those here.
4975 Just within the `outer_scope' there will be a BLOCK node
4976 representing the function's outermost pair of curly braces,
4977 and any blocks used for the base and member initializers of
4978 a C++ constructor function. */
4980 output_decls_for_scope (outer_scope, 0);
4982 /* Finally, force out any pending types which are local to the
4983 outermost block of this function definition. These will
4984 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4987 output_pending_types_for_scope (decl);
4992 /* Generate a terminator for the list of stuff `owned' by this
4995 end_sibling_chain ();
5000 /* If we are in terse mode, don't generate any DIEs to represent
5001 any actual typedefs. Note that even when we are in terse mode,
5002 we must still output DIEs to represent those tagged types which
5003 are used (directly or indirectly) in the specification of either
5004 a return type or a formal parameter type of some function. */
5006 if (debug_info_level <= DINFO_LEVEL_TERSE)
5007 if (! TYPE_DECL_IS_STUB (decl)
5008 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
5011 /* In the special case of a TYPE_DECL node representing
5012 the declaration of some type tag, if the given TYPE_DECL is
5013 marked as having been instantiated from some other (original)
5014 TYPE_DECL node (e.g. one which was generated within the original
5015 definition of an inline function) we have to generate a special
5016 (abbreviated) TAG_structure_type, TAG_union_type, or
5017 TAG_enumeration-type DIE here. */
5019 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5021 output_tagged_type_instantiation (TREE_TYPE (decl));
5025 output_type (TREE_TYPE (decl), containing_scope);
5027 if (! is_redundant_typedef (decl))
5028 /* Output a DIE to represent the typedef itself. */
5029 output_die (output_typedef_die, decl);
5033 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5034 output_die (output_label_die, decl);
5038 /* If we are conforming to the DWARF version 1 specification, don't
5039 generated any DIEs to represent mere external object declarations. */
5041 #if (DWARF_VERSION <= 1)
5042 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5046 /* If we are in terse mode, don't generate any DIEs to represent
5047 any variable declarations or definitions. */
5049 if (debug_info_level <= DINFO_LEVEL_TERSE)
5052 /* Output any DIEs that are needed to specify the type of this data
5055 output_type (TREE_TYPE (decl), containing_scope);
5058 /* And its containing type. */
5059 register tree origin = decl_class_context (decl);
5061 output_type (origin, containing_scope);
5064 /* If the following DIE will represent a data object definition for a
5065 data object with "extern" linkage, output a special "pubnames" DIE
5066 label just ahead of the actual DIE. A reference to this label
5067 was already generated in the .debug_pubnames section sub-entry
5068 for this data object definition. */
5070 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5072 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5074 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5075 ASM_OUTPUT_LABEL (asm_out_file, label);
5078 /* Now output the DIE to represent the data object itself. This gets
5079 complicated because of the possibility that the VAR_DECL really
5080 represents an inlined instance of a formal parameter for an inline
5084 register void (*func) PARAMS ((void *));
5085 register tree origin = decl_ultimate_origin (decl);
5087 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5088 func = output_formal_parameter_die;
5091 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5092 func = output_global_variable_die;
5094 func = output_local_variable_die;
5096 output_die (func, decl);
5101 /* Ignore the nameless fields that are used to skip bits. */
5102 if (DECL_NAME (decl) != 0)
5104 output_type (member_declared_type (decl), containing_scope);
5105 output_die (output_member_die, decl);
5110 /* Force out the type of this formal, if it was not forced out yet.
5111 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5112 It should be able to grok the presence of type DIEs within a list
5113 of TAG_formal_parameter DIEs, but it doesn't. */
5115 output_type (TREE_TYPE (decl), containing_scope);
5116 output_die (output_formal_parameter_die, decl);
5125 dwarfout_file_scope_decl (decl, set_finalizing)
5127 register int set_finalizing;
5129 if (TREE_CODE (decl) == ERROR_MARK)
5132 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5134 if (DECL_IGNORED_P (decl))
5137 switch (TREE_CODE (decl))
5141 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5142 a builtin function. Explicit programmer-supplied declarations of
5143 these same functions should NOT be ignored however. */
5145 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5148 /* What we would really like to do here is to filter out all mere
5149 file-scope declarations of file-scope functions which are never
5150 referenced later within this translation unit (and keep all of
5151 ones that *are* referenced later on) but we aren't clairvoyant,
5152 so we have no idea which functions will be referenced in the
5153 future (i.e. later on within the current translation unit).
5154 So here we just ignore all file-scope function declarations
5155 which are not also definitions. If and when the debugger needs
5156 to know something about these functions, it wil have to hunt
5157 around and find the DWARF information associated with the
5158 *definition* of the function.
5160 Note that we can't just check `DECL_EXTERNAL' to find out which
5161 FUNCTION_DECL nodes represent definitions and which ones represent
5162 mere declarations. We have to check `DECL_INITIAL' instead. That's
5163 because the C front-end supports some weird semantics for "extern
5164 inline" function definitions. These can get inlined within the
5165 current translation unit (an thus, we need to generate DWARF info
5166 for their abstract instances so that the DWARF info for the
5167 concrete inlined instances can have something to refer to) but
5168 the compiler never generates any out-of-lines instances of such
5169 things (despite the fact that they *are* definitions). The
5170 important point is that the C front-end marks these "extern inline"
5171 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5174 Note that the C++ front-end also plays some similar games for inline
5175 function definitions appearing within include files which also
5176 contain `#pragma interface' pragmas. */
5178 if (DECL_INITIAL (decl) == NULL_TREE)
5181 if (TREE_PUBLIC (decl)
5182 && ! DECL_EXTERNAL (decl)
5183 && ! DECL_ABSTRACT (decl))
5185 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5187 /* Output a .debug_pubnames entry for a public function
5188 defined in this compilation unit. */
5190 fputc ('\n', asm_out_file);
5191 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5192 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5193 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5194 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5195 IDENTIFIER_POINTER (DECL_NAME (decl)));
5196 ASM_OUTPUT_POP_SECTION (asm_out_file);
5203 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5204 object declaration and if the declaration was never even
5205 referenced from within this entire compilation unit. We
5206 suppress these DIEs in order to save space in the .debug section
5207 (by eliminating entries which are probably useless). Note that
5208 we must not suppress block-local extern declarations (whether
5209 used or not) because that would screw-up the debugger's name
5210 lookup mechanism and cause it to miss things which really ought
5211 to be in scope at a given point. */
5213 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5216 if (TREE_PUBLIC (decl)
5217 && ! DECL_EXTERNAL (decl)
5218 && GET_CODE (DECL_RTL (decl)) == MEM
5219 && ! DECL_ABSTRACT (decl))
5221 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5223 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5225 /* Output a .debug_pubnames entry for a public variable
5226 defined in this compilation unit. */
5228 fputc ('\n', asm_out_file);
5229 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5230 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5231 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5232 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5233 IDENTIFIER_POINTER (DECL_NAME (decl)));
5234 ASM_OUTPUT_POP_SECTION (asm_out_file);
5237 if (DECL_INITIAL (decl) == NULL)
5239 /* Output a .debug_aranges entry for a public variable
5240 which is tentatively defined in this compilation unit. */
5242 fputc ('\n', asm_out_file);
5243 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5244 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5245 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5246 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5247 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5248 ASM_OUTPUT_POP_SECTION (asm_out_file);
5252 /* If we are in terse mode, don't generate any DIEs to represent
5253 any variable declarations or definitions. */
5255 if (debug_info_level <= DINFO_LEVEL_TERSE)
5261 /* Don't bother trying to generate any DIEs to represent any of the
5262 normal built-in types for the language we are compiling, except
5263 in cases where the types in question are *not* DWARF fundamental
5264 types. We make an exception in the case of non-fundamental types
5265 for the sake of objective C (and perhaps C++) because the GNU
5266 front-ends for these languages may in fact create certain "built-in"
5267 types which are (for example) RECORD_TYPEs. In such cases, we
5268 really need to output these (non-fundamental) types because other
5269 DIEs may contain references to them. */
5271 /* Also ignore language dependent types here, because they are probably
5272 also built-in types. If we didn't ignore them, then we would get
5273 references to undefined labels because output_type doesn't support
5274 them. So, for now, we need to ignore them to avoid assembler
5277 /* ??? This code is different than the equivalent code in dwarf2out.c.
5278 The dwarf2out.c code is probably more correct. */
5280 if (DECL_SOURCE_LINE (decl) == 0
5281 && (type_is_fundamental (TREE_TYPE (decl))
5282 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5285 /* If we are in terse mode, don't generate any DIEs to represent
5286 any actual typedefs. Note that even when we are in terse mode,
5287 we must still output DIEs to represent those tagged types which
5288 are used (directly or indirectly) in the specification of either
5289 a return type or a formal parameter type of some function. */
5291 if (debug_info_level <= DINFO_LEVEL_TERSE)
5292 if (! TYPE_DECL_IS_STUB (decl)
5293 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5302 fputc ('\n', asm_out_file);
5303 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5304 finalizing = set_finalizing;
5305 output_decl (decl, NULL_TREE);
5307 /* NOTE: The call above to `output_decl' may have caused one or more
5308 file-scope named types (i.e. tagged types) to be placed onto the
5309 pending_types_list. We have to get those types off of that list
5310 at some point, and this is the perfect time to do it. If we didn't
5311 take them off now, they might still be on the list when cc1 finally
5312 exits. That might be OK if it weren't for the fact that when we put
5313 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5314 for these types, and that causes them never to be output unless
5315 `output_pending_types_for_scope' takes them off of the list and un-sets
5316 their TREE_ASM_WRITTEN flags. */
5318 output_pending_types_for_scope (NULL_TREE);
5320 /* The above call should have totally emptied the pending_types_list
5321 if this is not a nested function or class. If this is a nested type,
5322 then the remaining pending_types will be emitted when the containing type
5325 if (! DECL_CONTEXT (decl))
5327 if (pending_types != 0)
5331 ASM_OUTPUT_POP_SECTION (asm_out_file);
5333 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5334 current_funcdef_number++;
5337 /* Output a marker (i.e. a label) for the beginning of the generated code
5338 for a lexical block. */
5341 dwarfout_begin_block (blocknum)
5342 register unsigned blocknum;
5344 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5346 function_section (current_function_decl);
5347 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5348 ASM_OUTPUT_LABEL (asm_out_file, label);
5351 /* Output a marker (i.e. a label) for the end of the generated code
5352 for a lexical block. */
5355 dwarfout_end_block (blocknum)
5356 register unsigned blocknum;
5358 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5360 function_section (current_function_decl);
5361 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5362 ASM_OUTPUT_LABEL (asm_out_file, label);
5365 /* Output a marker (i.e. a label) at a point in the assembly code which
5366 corresponds to a given source level label. */
5369 dwarfout_label (insn)
5372 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5374 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5376 function_section (current_function_decl);
5377 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5378 (unsigned) INSN_UID (insn));
5379 ASM_OUTPUT_LABEL (asm_out_file, label);
5383 /* Output a marker (i.e. a label) for the point in the generated code where
5384 the real body of the function begins (after parameters have been moved
5385 to their home locations). */
5388 dwarfout_begin_function ()
5390 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5392 if (! use_gnu_debug_info_extensions)
5394 function_section (current_function_decl);
5395 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5396 ASM_OUTPUT_LABEL (asm_out_file, label);
5399 /* Output a marker (i.e. a label) for the point in the generated code where
5400 the real body of the function ends (just before the epilogue code). */
5403 dwarfout_end_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_END_LABEL_FMT, current_funcdef_number);
5411 ASM_OUTPUT_LABEL (asm_out_file, label);
5414 /* Output a marker (i.e. a label) for the absolute end of the generated code
5415 for a function definition. This gets called *after* the epilogue code
5416 has been generated. */
5419 dwarfout_end_epilogue ()
5421 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5423 /* Output a label to mark the endpoint of the code generated for this
5426 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5427 ASM_OUTPUT_LABEL (asm_out_file, label);
5431 shuffle_filename_entry (new_zeroth)
5432 register filename_entry *new_zeroth;
5434 filename_entry temp_entry;
5435 register filename_entry *limit_p;
5436 register filename_entry *move_p;
5438 if (new_zeroth == &filename_table[0])
5441 temp_entry = *new_zeroth;
5443 /* Shift entries up in the table to make room at [0]. */
5445 limit_p = &filename_table[0];
5446 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5447 *move_p = *(move_p-1);
5449 /* Install the found entry at [0]. */
5451 filename_table[0] = temp_entry;
5454 /* Create a new (string) entry for the .debug_sfnames section. */
5457 generate_new_sfname_entry ()
5459 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5461 fputc ('\n', asm_out_file);
5462 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5463 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5464 ASM_OUTPUT_LABEL (asm_out_file, label);
5465 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5466 filename_table[0].name
5467 ? filename_table[0].name
5469 ASM_OUTPUT_POP_SECTION (asm_out_file);
5472 /* Lookup a filename (in the list of filenames that we know about here in
5473 dwarfout.c) and return its "index". The index of each (known) filename
5474 is just a unique number which is associated with only that one filename.
5475 We need such numbers for the sake of generating labels (in the
5476 .debug_sfnames section) and references to those unique labels (in the
5477 .debug_srcinfo and .debug_macinfo sections).
5479 If the filename given as an argument is not found in our current list,
5480 add it to the list and assign it the next available unique index number.
5482 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5483 one), we shuffle the filename found (or added) up to the zeroth entry of
5484 our list of filenames (which is always searched linearly). We do this so
5485 as to optimize the most common case for these filename lookups within
5486 dwarfout.c. The most common case by far is the case where we call
5487 lookup_filename to lookup the very same filename that we did a lookup
5488 on the last time we called lookup_filename. We make sure that this
5489 common case is fast because such cases will constitute 99.9% of the
5490 lookups we ever do (in practice).
5492 If we add a new filename entry to our table, we go ahead and generate
5493 the corresponding entry in the .debug_sfnames section right away.
5494 Doing so allows us to avoid tickling an assembler bug (present in some
5495 m68k assemblers) which yields assembly-time errors in cases where the
5496 difference of two label addresses is taken and where the two labels
5497 are in a section *other* than the one where the difference is being
5498 calculated, and where at least one of the two symbol references is a
5499 forward reference. (This bug could be tickled by our .debug_srcinfo
5500 entries if we don't output their corresponding .debug_sfnames entries
5504 lookup_filename (file_name)
5505 const char *file_name;
5507 register filename_entry *search_p;
5508 register filename_entry *limit_p = &filename_table[ft_entries];
5510 for (search_p = filename_table; search_p < limit_p; search_p++)
5511 if (!strcmp (file_name, search_p->name))
5513 /* When we get here, we have found the filename that we were
5514 looking for in the filename_table. Now we want to make sure
5515 that it gets moved to the zero'th entry in the table (if it
5516 is not already there) so that subsequent attempts to find the
5517 same filename will find it as quickly as possible. */
5519 shuffle_filename_entry (search_p);
5520 return filename_table[0].number;
5523 /* We come here whenever we have a new filename which is not registered
5524 in the current table. Here we add it to the table. */
5526 /* Prepare to add a new table entry by making sure there is enough space
5527 in the table to do so. If not, expand the current table. */
5529 if (ft_entries == ft_entries_allocated)
5531 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5533 = (filename_entry *)
5534 xrealloc (filename_table,
5535 ft_entries_allocated * sizeof (filename_entry));
5538 /* Initially, add the new entry at the end of the filename table. */
5540 filename_table[ft_entries].number = ft_entries;
5541 filename_table[ft_entries].name = xstrdup (file_name);
5543 /* Shuffle the new entry into filename_table[0]. */
5545 shuffle_filename_entry (&filename_table[ft_entries]);
5547 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5548 generate_new_sfname_entry ();
5551 return filename_table[0].number;
5555 generate_srcinfo_entry (line_entry_num, files_entry_num)
5556 unsigned line_entry_num;
5557 unsigned files_entry_num;
5559 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5561 fputc ('\n', asm_out_file);
5562 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5563 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5564 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5565 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5566 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5567 ASM_OUTPUT_POP_SECTION (asm_out_file);
5571 dwarfout_line (filename, line)
5572 register const char *filename;
5573 register unsigned line;
5575 if (debug_info_level >= DINFO_LEVEL_NORMAL
5576 /* We can't emit line number info for functions in separate sections,
5577 because the assembler can't subtract labels in different sections. */
5578 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5580 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5581 static unsigned last_line_entry_num = 0;
5582 static unsigned prev_file_entry_num = (unsigned) -1;
5583 register unsigned this_file_entry_num;
5585 function_section (current_function_decl);
5586 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5587 ASM_OUTPUT_LABEL (asm_out_file, label);
5589 fputc ('\n', asm_out_file);
5591 if (use_gnu_debug_info_extensions)
5592 this_file_entry_num = lookup_filename (filename);
5594 this_file_entry_num = (unsigned) -1;
5596 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5597 if (this_file_entry_num != prev_file_entry_num)
5599 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5601 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5602 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5606 register const char *tail = rindex (filename, '/');
5612 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5613 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5615 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5616 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5617 ASM_OUTPUT_POP_SECTION (asm_out_file);
5619 if (this_file_entry_num != prev_file_entry_num)
5620 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5621 prev_file_entry_num = this_file_entry_num;
5625 /* Generate an entry in the .debug_macinfo section. */
5628 generate_macinfo_entry (type_and_offset, string)
5629 register const char *type_and_offset;
5630 register const char *string;
5632 if (! use_gnu_debug_info_extensions)
5635 fputc ('\n', asm_out_file);
5636 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5637 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5638 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
5639 ASM_OUTPUT_POP_SECTION (asm_out_file);
5643 dwarfout_start_new_source_file (filename)
5644 register const char *filename;
5646 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5647 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5649 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5650 sprintf (type_and_offset, "0x%08x+%s-%s",
5651 ((unsigned) MACINFO_start << 24),
5652 /* Hack: skip leading '*' . */
5653 (*label == '*') + label,
5654 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5655 generate_macinfo_entry (type_and_offset, "");
5659 dwarfout_resume_previous_source_file (lineno)
5660 register unsigned lineno;
5662 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5664 sprintf (type_and_offset, "0x%08x+%u",
5665 ((unsigned) MACINFO_resume << 24), lineno);
5666 generate_macinfo_entry (type_and_offset, "");
5669 /* Called from check_newline in c-parse.y. The `buffer' parameter
5670 contains the tail part of the directive line, i.e. the part which
5671 is past the initial whitespace, #, whitespace, directive-name,
5675 dwarfout_define (lineno, buffer)
5676 register unsigned lineno;
5677 register const char *buffer;
5679 static int initialized = 0;
5680 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5684 dwarfout_start_new_source_file (primary_filename);
5687 sprintf (type_and_offset, "0x%08x+%u",
5688 ((unsigned) MACINFO_define << 24), lineno);
5689 generate_macinfo_entry (type_and_offset, buffer);
5692 /* Called from check_newline in c-parse.y. The `buffer' parameter
5693 contains the tail part of the directive line, i.e. the part which
5694 is past the initial whitespace, #, whitespace, directive-name,
5698 dwarfout_undef (lineno, buffer)
5699 register unsigned lineno;
5700 register const char *buffer;
5702 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5704 sprintf (type_and_offset, "0x%08x+%u",
5705 ((unsigned) MACINFO_undef << 24), lineno);
5706 generate_macinfo_entry (type_and_offset, buffer);
5709 /* Set up for Dwarf output at the start of compilation. */
5712 dwarfout_init (asm_out_file, main_input_filename)
5713 register FILE *asm_out_file;
5714 register char *main_input_filename;
5716 /* Remember the name of the primary input file. */
5718 primary_filename = main_input_filename;
5720 /* Allocate the initial hunk of the pending_sibling_stack. */
5722 pending_sibling_stack
5724 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5725 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5726 pending_siblings = 1;
5728 /* Allocate the initial hunk of the filename_table. */
5731 = (filename_entry *)
5732 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5733 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5736 /* Allocate the initial hunk of the pending_types_list. */
5739 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5740 pending_types_allocated = PENDING_TYPES_INCREMENT;
5743 /* Create an artificial RECORD_TYPE node which we can use in our hack
5744 to get the DIEs representing types of formal parameters to come out
5745 only *after* the DIEs for the formal parameters themselves. */
5747 fake_containing_scope = make_node (RECORD_TYPE);
5749 /* Output a starting label for the .text section. */
5751 fputc ('\n', asm_out_file);
5752 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5753 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5754 ASM_OUTPUT_POP_SECTION (asm_out_file);
5756 /* Output a starting label for the .data section. */
5758 fputc ('\n', asm_out_file);
5759 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5760 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5761 ASM_OUTPUT_POP_SECTION (asm_out_file);
5763 #if 0 /* GNU C doesn't currently use .data1. */
5764 /* Output a starting label for the .data1 section. */
5766 fputc ('\n', asm_out_file);
5767 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5768 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5769 ASM_OUTPUT_POP_SECTION (asm_out_file);
5772 /* Output a starting label for the .rodata section. */
5774 fputc ('\n', asm_out_file);
5775 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5776 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5777 ASM_OUTPUT_POP_SECTION (asm_out_file);
5779 #if 0 /* GNU C doesn't currently use .rodata1. */
5780 /* Output a starting label for the .rodata1 section. */
5782 fputc ('\n', asm_out_file);
5783 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5784 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5785 ASM_OUTPUT_POP_SECTION (asm_out_file);
5788 /* Output a starting label for the .bss section. */
5790 fputc ('\n', asm_out_file);
5791 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5792 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5793 ASM_OUTPUT_POP_SECTION (asm_out_file);
5795 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5797 if (use_gnu_debug_info_extensions)
5799 /* Output a starting label and an initial (compilation directory)
5800 entry for the .debug_sfnames section. The starting label will be
5801 referenced by the initial entry in the .debug_srcinfo section. */
5803 fputc ('\n', asm_out_file);
5804 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5805 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5807 register char *pwd = getpwd ();
5808 register char *dirname;
5811 pfatal_with_name ("getpwd");
5812 dirname = concat (pwd, "/", NULL);
5813 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
5816 ASM_OUTPUT_POP_SECTION (asm_out_file);
5819 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5820 && use_gnu_debug_info_extensions)
5822 /* Output a starting label for the .debug_macinfo section. This
5823 label will be referenced by the AT_mac_info attribute in the
5824 TAG_compile_unit DIE. */
5826 fputc ('\n', asm_out_file);
5827 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5828 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5829 ASM_OUTPUT_POP_SECTION (asm_out_file);
5832 /* Generate the initial entry for the .line section. */
5834 fputc ('\n', asm_out_file);
5835 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5836 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5837 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5838 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5839 ASM_OUTPUT_POP_SECTION (asm_out_file);
5841 if (use_gnu_debug_info_extensions)
5843 /* Generate the initial entry for the .debug_srcinfo section. */
5845 fputc ('\n', asm_out_file);
5846 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5847 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5848 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5849 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5850 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5851 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5852 #ifdef DWARF_TIMESTAMPS
5853 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5855 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5857 ASM_OUTPUT_POP_SECTION (asm_out_file);
5860 /* Generate the initial entry for the .debug_pubnames section. */
5862 fputc ('\n', asm_out_file);
5863 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5864 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5865 ASM_OUTPUT_POP_SECTION (asm_out_file);
5867 /* Generate the initial entry for the .debug_aranges section. */
5869 fputc ('\n', asm_out_file);
5870 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5871 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5872 ASM_OUTPUT_POP_SECTION (asm_out_file);
5875 /* Setup first DIE number == 1. */
5876 NEXT_DIE_NUM = next_unused_dienum++;
5878 /* Generate the initial DIE for the .debug section. Note that the
5879 (string) value given in the AT_name attribute of the TAG_compile_unit
5880 DIE will (typically) be a relative pathname and that this pathname
5881 should be taken as being relative to the directory from which the
5882 compiler was invoked when the given (base) source file was compiled. */
5884 fputc ('\n', asm_out_file);
5885 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5886 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5887 output_die (output_compile_unit_die, main_input_filename);
5888 ASM_OUTPUT_POP_SECTION (asm_out_file);
5890 fputc ('\n', asm_out_file);
5893 /* Output stuff that dwarf requires at the end of every file. */
5898 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5900 retry_incomplete_types ();
5902 fputc ('\n', asm_out_file);
5903 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5905 /* Mark the end of the chain of siblings which represent all file-scope
5906 declarations in this compilation unit. */
5908 /* The (null) DIE which represents the terminator for the (sibling linked)
5909 list of file-scope items is *special*. Normally, we would just call
5910 end_sibling_chain at this point in order to output a word with the
5911 value `4' and that word would act as the terminator for the list of
5912 DIEs describing file-scope items. Unfortunately, if we were to simply
5913 do that, the label that would follow this DIE in the .debug section
5914 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5915 machines) to a 4 byte boundary.
5917 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5918 the trick used is to insert extra (otherwise useless) padding bytes
5919 into the (null) DIE that we know must precede the ..D2 label in the
5920 .debug section. The amount of padding required can be anywhere between
5921 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5922 with the padding) would normally contain the value 4, but now it will
5923 also have to include the padding bytes, so it will instead have some
5924 value in the range 4..7.
5926 Fortunately, the rules of Dwarf say that any DIE whose length word
5927 contains *any* value less than 8 should be treated as a null DIE, so
5928 this trick works out nicely. Clever, eh? Don't give me any credit
5929 (or blame). I didn't think of this scheme. I just conformed to it.
5932 output_die (output_padded_null_die, (void *) 0);
5935 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5936 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5937 ASM_OUTPUT_POP_SECTION (asm_out_file);
5939 /* Output a terminator label for the .text section. */
5941 fputc ('\n', asm_out_file);
5942 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5943 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5944 ASM_OUTPUT_POP_SECTION (asm_out_file);
5946 /* Output a terminator label for the .data section. */
5948 fputc ('\n', asm_out_file);
5949 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5950 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5951 ASM_OUTPUT_POP_SECTION (asm_out_file);
5953 #if 0 /* GNU C doesn't currently use .data1. */
5954 /* Output a terminator label for the .data1 section. */
5956 fputc ('\n', asm_out_file);
5957 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5958 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5959 ASM_OUTPUT_POP_SECTION (asm_out_file);
5962 /* Output a terminator label for the .rodata section. */
5964 fputc ('\n', asm_out_file);
5965 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5966 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5967 ASM_OUTPUT_POP_SECTION (asm_out_file);
5969 #if 0 /* GNU C doesn't currently use .rodata1. */
5970 /* Output a terminator label for the .rodata1 section. */
5972 fputc ('\n', asm_out_file);
5973 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5974 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5975 ASM_OUTPUT_POP_SECTION (asm_out_file);
5978 /* Output a terminator label for the .bss section. */
5980 fputc ('\n', asm_out_file);
5981 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5982 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5983 ASM_OUTPUT_POP_SECTION (asm_out_file);
5985 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5987 /* Output a terminating entry for the .line section. */
5989 fputc ('\n', asm_out_file);
5990 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5991 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5992 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5993 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5994 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5995 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5996 ASM_OUTPUT_POP_SECTION (asm_out_file);
5998 if (use_gnu_debug_info_extensions)
6000 /* Output a terminating entry for the .debug_srcinfo section. */
6002 fputc ('\n', asm_out_file);
6003 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
6004 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
6005 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
6006 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
6007 ASM_OUTPUT_POP_SECTION (asm_out_file);
6010 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
6012 /* Output terminating entries for the .debug_macinfo section. */
6014 dwarfout_resume_previous_source_file (0);
6016 fputc ('\n', asm_out_file);
6017 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
6018 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6019 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6020 ASM_OUTPUT_POP_SECTION (asm_out_file);
6023 /* Generate the terminating entry for the .debug_pubnames section. */
6025 fputc ('\n', asm_out_file);
6026 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
6027 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6028 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6029 ASM_OUTPUT_POP_SECTION (asm_out_file);
6031 /* Generate the terminating entries for the .debug_aranges section.
6033 Note that we want to do this only *after* we have output the end
6034 labels (for the various program sections) which we are going to
6035 refer to here. This allows us to work around a bug in the m68k
6036 svr4 assembler. That assembler gives bogus assembly-time errors
6037 if (within any given section) you try to take the difference of
6038 two relocatable symbols, both of which are located within some
6039 other section, and if one (or both?) of the symbols involved is
6040 being forward-referenced. By generating the .debug_aranges
6041 entries at this late point in the assembly output, we skirt the
6042 issue simply by avoiding forward-references.
6045 fputc ('\n', asm_out_file);
6046 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
6048 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6049 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6051 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6052 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6054 #if 0 /* GNU C doesn't currently use .data1. */
6055 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6056 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6060 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6061 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6062 RODATA_BEGIN_LABEL);
6064 #if 0 /* GNU C doesn't currently use .rodata1. */
6065 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6066 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6067 RODATA1_BEGIN_LABEL);
6070 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6071 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6073 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6074 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6076 ASM_OUTPUT_POP_SECTION (asm_out_file);
6079 /* There should not be any pending types left at the end. We need
6080 this now because it may not have been checked on the last call to
6081 dwarfout_file_scope_decl. */
6082 if (pending_types != 0)
6086 #endif /* DWARF_DEBUGGING_INFO */