1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #ifdef DWARF_DEBUGGING_INFO
30 #include "hard-reg-set.h"
31 #include "insn-config.h"
36 #if defined(DWARF_TIMESTAMPS)
39 #else /* !defined(POSIX) */
40 #include <sys/types.h>
42 extern time_t time (time_t *);
43 #else /* !defined(__STDC__) */
44 extern time_t time ();
45 #endif /* !defined(__STDC__) */
46 #endif /* !defined(POSIX) */
47 #endif /* defined(DWARF_TIMESTAMPS) */
61 extern char *getpwd ();
63 #ifdef NEED_DECLARATION_INDEX
64 extern char *index ();
67 #ifdef NEED_DECLARATION_RINDEX
68 extern char *rindex ();
71 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
72 regarding the GNU implementation of Dwarf. */
74 /* NOTE: In the comments in this file, many references are made to
75 so called "Debugging Information Entries". For the sake of brevity,
76 this term is abbreviated to `DIE' throughout the remainder of this
79 /* Note that the implementation of C++ support herein is (as yet) unfinished.
80 If you want to try to complete it, more power to you. */
82 #if !defined(__GNUC__) || (NDEBUG != 1)
86 /* How to start an assembler comment. */
87 #ifndef ASM_COMMENT_START
88 #define ASM_COMMENT_START ";#"
91 /* How to print out a register name. */
93 #define PRINT_REG(RTX, CODE, FILE) \
94 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
97 /* Define a macro which returns non-zero for any tagged type which is
98 used (directly or indirectly) in the specification of either some
99 function's return type or some formal parameter of some function.
100 We use this macro when we are operating in "terse" mode to help us
101 know what tagged types have to be represented in Dwarf (even in
102 terse mode) and which ones don't.
104 A flag bit with this meaning really should be a part of the normal
105 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
106 for these nodes. For now, we have to just fake it. It it safe for
107 us to simply return zero for all complete tagged types (which will
108 get forced out anyway if they were used in the specification of some
109 formal or return type) and non-zero for all incomplete tagged types.
112 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
114 /* Define a macro which returns non-zero for a TYPE_DECL which was
115 implicitly generated for a tagged type.
117 Note that unlike the gcc front end (which generates a NULL named
118 TYPE_DECL node for each complete tagged type, each array type, and
119 each function type node created) the g++ front end generates a
120 _named_ TYPE_DECL node for each tagged type node created.
121 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
122 generate a DW_TAG_typedef DIE for them. */
123 #define TYPE_DECL_IS_STUB(decl) \
124 (DECL_NAME (decl) == NULL \
125 || (DECL_ARTIFICIAL (decl) \
126 && is_tagged_type (TREE_TYPE (decl)) \
127 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
129 extern int flag_traditional;
130 extern char *version_string;
131 extern char *language_string;
133 /* Maximum size (in bytes) of an artificially generated label. */
135 #define MAX_ARTIFICIAL_LABEL_BYTES 30
137 /* Make sure we know the sizes of the various types dwarf can describe.
138 These are only defaults. If the sizes are different for your target,
139 you should override these values by defining the appropriate symbols
140 in your tm.h file. */
142 #ifndef CHAR_TYPE_SIZE
143 #define CHAR_TYPE_SIZE BITS_PER_UNIT
146 #ifndef SHORT_TYPE_SIZE
147 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
150 #ifndef INT_TYPE_SIZE
151 #define INT_TYPE_SIZE BITS_PER_WORD
154 #ifndef LONG_TYPE_SIZE
155 #define LONG_TYPE_SIZE BITS_PER_WORD
158 #ifndef LONG_LONG_TYPE_SIZE
159 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
162 #ifndef WCHAR_TYPE_SIZE
163 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
166 #ifndef WCHAR_UNSIGNED
167 #define WCHAR_UNSIGNED 0
170 #ifndef FLOAT_TYPE_SIZE
171 #define FLOAT_TYPE_SIZE BITS_PER_WORD
174 #ifndef DOUBLE_TYPE_SIZE
175 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
178 #ifndef LONG_DOUBLE_TYPE_SIZE
179 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
182 /* Structure to keep track of source filenames. */
184 struct filename_entry {
189 typedef struct filename_entry filename_entry;
191 /* Pointer to an array of elements, each one having the structure above. */
193 static filename_entry *filename_table;
195 /* Total number of entries in the table (i.e. array) pointed to by
196 `filename_table'. This is the *total* and includes both used and
199 static unsigned ft_entries_allocated;
201 /* Number of entries in the filename_table which are actually in use. */
203 static unsigned ft_entries;
205 /* Size (in elements) of increments by which we may expand the filename
206 table. Actually, a single hunk of space of this size should be enough
207 for most typical programs. */
209 #define FT_ENTRIES_INCREMENT 64
211 /* Local pointer to the name of the main input file. Initialized in
214 static char *primary_filename;
216 /* Pointer to the most recent filename for which we produced some line info. */
218 static char *last_filename;
220 /* For Dwarf output, we must assign lexical-blocks id numbers
221 in the order in which their beginnings are encountered.
222 We output Dwarf debugging info that refers to the beginnings
223 and ends of the ranges of code for each lexical block with
224 assembler labels ..Bn and ..Bn.e, where n is the block number.
225 The labels themselves are generated in final.c, which assigns
226 numbers to the blocks in the same way. */
228 static unsigned next_block_number = 2;
230 /* Counter to generate unique names for DIEs. */
232 static unsigned next_unused_dienum = 1;
234 /* Number of the DIE which is currently being generated. */
236 static unsigned current_dienum;
238 /* Number to use for the special "pubname" label on the next DIE which
239 represents a function or data object defined in this compilation
240 unit which has "extern" linkage. */
242 static next_pubname_number = 0;
244 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
246 /* Pointer to a dynamically allocated list of pre-reserved and still
247 pending sibling DIE numbers. Note that this list will grow as needed. */
249 static unsigned *pending_sibling_stack;
251 /* Counter to keep track of the number of pre-reserved and still pending
252 sibling DIE numbers. */
254 static unsigned pending_siblings;
256 /* The currently allocated size of the above list (expressed in number of
259 static unsigned pending_siblings_allocated;
261 /* Size (in elements) of increments by which we may expand the pending
262 sibling stack. Actually, a single hunk of space of this size should
263 be enough for most typical programs. */
265 #define PENDING_SIBLINGS_INCREMENT 64
267 /* Non-zero if we are performing our file-scope finalization pass and if
268 we should force out Dwarf descriptions of any and all file-scope
269 tagged types which are still incomplete types. */
271 static int finalizing = 0;
273 /* A pointer to the base of a list of pending types which we haven't
274 generated DIEs for yet, but which we will have to come back to
277 static tree *pending_types_list;
279 /* Number of elements currently allocated for the pending_types_list. */
281 static unsigned pending_types_allocated;
283 /* Number of elements of pending_types_list currently in use. */
285 static unsigned pending_types;
287 /* Size (in elements) of increments by which we may expand the pending
288 types list. Actually, a single hunk of space of this size should
289 be enough for most typical programs. */
291 #define PENDING_TYPES_INCREMENT 64
293 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
294 This is used in a hack to help us get the DIEs describing types of
295 formal parameters to come *after* all of the DIEs describing the formal
296 parameters themselves. That's necessary in order to be compatible
297 with what the brain-damaged svr4 SDB debugger requires. */
299 static tree fake_containing_scope;
301 /* The number of the current function definition that we are generating
302 debugging information for. These numbers range from 1 up to the maximum
303 number of function definitions contained within the current compilation
304 unit. These numbers are used to create unique labels for various things
305 contained within various function definitions. */
307 static unsigned current_funcdef_number = 1;
309 /* A pointer to the ..._DECL node which we have most recently been working
310 on. We keep this around just in case something about it looks screwy
311 and we want to tell the user what the source coordinates for the actual
314 static tree dwarf_last_decl;
316 /* A flag indicating that we are emitting the member declarations of a
317 class, so member functions and variables should not be entirely emitted.
318 This is a kludge to avoid passing a second argument to output_*_die. */
322 /* Forward declarations for functions defined in this file. */
324 static char *dwarf_tag_name PROTO((unsigned));
325 static char *dwarf_attr_name PROTO((unsigned));
326 static char *dwarf_stack_op_name PROTO((unsigned));
327 static char *dwarf_typemod_name PROTO((unsigned));
328 static char *dwarf_fmt_byte_name PROTO((unsigned));
329 static char *dwarf_fund_type_name PROTO((unsigned));
330 static tree decl_ultimate_origin PROTO((tree));
331 static tree block_ultimate_origin PROTO((tree));
332 static void output_unsigned_leb128 PROTO((unsigned long));
333 static void output_signed_leb128 PROTO((long));
334 static inline int is_body_block PROTO((tree));
335 static int fundamental_type_code PROTO((tree));
336 static tree root_type_1 PROTO((tree, int));
337 static tree root_type PROTO((tree));
338 static void write_modifier_bytes_1 PROTO((tree, int, int, int));
339 static void write_modifier_bytes PROTO((tree, int, int));
340 static inline int type_is_fundamental PROTO((tree));
341 static void equate_decl_number_to_die_number PROTO((tree));
342 static inline void equate_type_number_to_die_number PROTO((tree));
343 static void output_reg_number PROTO((rtx));
344 static void output_mem_loc_descriptor PROTO((rtx));
345 static void output_loc_descriptor PROTO((rtx));
346 static void output_bound_representation PROTO((tree, unsigned, int));
347 static void output_enumeral_list PROTO((tree));
348 static inline unsigned ceiling PROTO((unsigned, unsigned));
349 static inline tree field_type PROTO((tree));
350 static inline unsigned simple_type_align_in_bits PROTO((tree));
351 static inline unsigned simple_type_size_in_bits PROTO((tree));
352 static unsigned field_byte_offset PROTO((tree));
353 static inline void sibling_attribute PROTO((void));
354 static void location_attribute PROTO((rtx));
355 static void data_member_location_attribute PROTO((tree));
356 static void const_value_attribute PROTO((rtx));
357 static void location_or_const_value_attribute PROTO((tree));
358 static inline void name_attribute PROTO((char *));
359 static inline void fund_type_attribute PROTO((unsigned));
360 static void mod_fund_type_attribute PROTO((tree, int, int));
361 static inline void user_def_type_attribute PROTO((tree));
362 static void mod_u_d_type_attribute PROTO((tree, int, int));
363 static inline void ordering_attribute PROTO((unsigned));
364 static void subscript_data_attribute PROTO((tree));
365 static void byte_size_attribute PROTO((tree));
366 static inline void bit_offset_attribute PROTO((tree));
367 static inline void bit_size_attribute PROTO((tree));
368 static inline void element_list_attribute PROTO((tree));
369 static inline void stmt_list_attribute PROTO((char *));
370 static inline void low_pc_attribute PROTO((char *));
371 static inline void high_pc_attribute PROTO((char *));
372 static inline void body_begin_attribute PROTO((char *));
373 static inline void body_end_attribute PROTO((char *));
374 static inline void language_attribute PROTO((unsigned));
375 static inline void member_attribute PROTO((tree));
376 static inline void string_length_attribute PROTO((tree));
377 static inline void comp_dir_attribute PROTO((char *));
378 static inline void sf_names_attribute PROTO((char *));
379 static inline void src_info_attribute PROTO((char *));
380 static inline void mac_info_attribute PROTO((char *));
381 static inline void prototyped_attribute PROTO((tree));
382 static inline void producer_attribute PROTO((char *));
383 static inline void inline_attribute PROTO((tree));
384 static inline void containing_type_attribute PROTO((tree));
385 static inline void abstract_origin_attribute PROTO((tree));
386 static inline void src_coords_attribute PROTO((unsigned, unsigned));
387 static inline void pure_or_virtual_attribute PROTO((tree));
388 static void name_and_src_coords_attributes PROTO((tree));
389 static void type_attribute PROTO((tree, int, int));
390 static char *type_tag PROTO((tree));
391 static inline void dienum_push PROTO((void));
392 static inline void dienum_pop PROTO((void));
393 static inline tree member_declared_type PROTO((tree));
394 static char *function_start_label PROTO((tree));
395 static void output_array_type_die PROTO((void *));
396 static void output_set_type_die PROTO((void *));
397 static void output_entry_point_die PROTO((void *));
398 static void output_inlined_enumeration_type_die PROTO((void *));
399 static void output_inlined_structure_type_die PROTO((void *));
400 static void output_inlined_union_type_die PROTO((void *));
401 static void output_enumeration_type_die PROTO((void *));
402 static void output_formal_parameter_die PROTO((void *));
403 static void output_global_subroutine_die PROTO((void *));
404 static void output_global_variable_die PROTO((void *));
405 static void output_label_die PROTO((void *));
406 static void output_lexical_block_die PROTO((void *));
407 static void output_inlined_subroutine_die PROTO((void *));
408 static void output_local_variable_die PROTO((void *));
409 static void output_member_die PROTO((void *));
410 static void output_pointer_type_die PROTO((void *));
411 static void output_reference_type_die PROTO((void *));
412 static void output_ptr_to_mbr_type_die PROTO((void *));
413 static void output_compile_unit_die PROTO((void *));
414 static void output_string_type_die PROTO((void *));
415 static void output_structure_type_die PROTO((void *));
416 static void output_local_subroutine_die PROTO((void *));
417 static void output_subroutine_type_die PROTO((void *));
418 static void output_typedef_die PROTO((void *));
419 static void output_union_type_die PROTO((void *));
420 static void output_unspecified_parameters_die PROTO((void *));
421 static void output_padded_null_die PROTO((void *));
422 static void output_die PROTO((void (*) (), void *));
423 static void end_sibling_chain PROTO((void));
424 static void output_formal_types PROTO((tree));
425 static void pend_type PROTO((tree));
426 static inline int type_of_for_scope PROTO((tree, tree));
427 static void output_pending_types_for_scope PROTO((tree));
428 static void output_type PROTO((tree, tree));
429 static void output_tagged_type_instantiation PROTO((tree));
430 static void output_block PROTO((tree, int));
431 static void output_decls_for_scope PROTO((tree, int));
432 static void output_decl PROTO((tree, tree));
433 static void shuffle_filename_entry PROTO((filename_entry *));
434 static void generate_new_sfname_entry PROTO((void));
435 static unsigned lookup_filename PROTO((char *));
436 static void generate_srcinfo_entry PROTO((unsigned, unsigned));
437 static void generate_macinfo_entry PROTO((char *, char *));
439 /* Definitions of defaults for assembler-dependent names of various
440 pseudo-ops and section names.
442 Theses may be overridden in your tm.h file (if necessary) for your
443 particular assembler. The default values provided here correspond to
444 what is expected by "standard" AT&T System V.4 assemblers. */
447 #define FILE_ASM_OP ".file"
449 #ifndef VERSION_ASM_OP
450 #define VERSION_ASM_OP ".version"
452 #ifndef UNALIGNED_SHORT_ASM_OP
453 #define UNALIGNED_SHORT_ASM_OP ".2byte"
455 #ifndef UNALIGNED_INT_ASM_OP
456 #define UNALIGNED_INT_ASM_OP ".4byte"
459 #define ASM_BYTE_OP ".byte"
462 #define SET_ASM_OP ".set"
465 /* Pseudo-ops for pushing the current section onto the section stack (and
466 simultaneously changing to a new section) and for poping back to the
467 section we were in immediately before this one. Note that most svr4
468 assemblers only maintain a one level stack... you can push all the
469 sections you want, but you can only pop out one level. (The sparc
470 svr4 assembler is an exception to this general rule.) That's
471 OK because we only use at most one level of the section stack herein. */
473 #ifndef PUSHSECTION_ASM_OP
474 #define PUSHSECTION_ASM_OP ".section"
476 #ifndef POPSECTION_ASM_OP
477 #define POPSECTION_ASM_OP ".previous"
480 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
481 to print the PUSHSECTION_ASM_OP and the section name. The default here
482 works for almost all svr4 assemblers, except for the sparc, where the
483 section name must be enclosed in double quotes. (See sparcv4.h.) */
485 #ifndef PUSHSECTION_FORMAT
486 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
489 #ifndef DEBUG_SECTION
490 #define DEBUG_SECTION ".debug"
493 #define LINE_SECTION ".line"
495 #ifndef SFNAMES_SECTION
496 #define SFNAMES_SECTION ".debug_sfnames"
498 #ifndef SRCINFO_SECTION
499 #define SRCINFO_SECTION ".debug_srcinfo"
501 #ifndef MACINFO_SECTION
502 #define MACINFO_SECTION ".debug_macinfo"
504 #ifndef PUBNAMES_SECTION
505 #define PUBNAMES_SECTION ".debug_pubnames"
507 #ifndef ARANGES_SECTION
508 #define ARANGES_SECTION ".debug_aranges"
511 #define TEXT_SECTION ".text"
514 #define DATA_SECTION ".data"
516 #ifndef DATA1_SECTION
517 #define DATA1_SECTION ".data1"
519 #ifndef RODATA_SECTION
520 #define RODATA_SECTION ".rodata"
522 #ifndef RODATA1_SECTION
523 #define RODATA1_SECTION ".rodata1"
526 #define BSS_SECTION ".bss"
529 /* Definitions of defaults for formats and names of various special
530 (artificial) labels which may be generated within this file (when
531 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
533 If necessary, these may be overridden from within your tm.h file,
534 but typically, you should never need to override these.
536 These labels have been hacked (temporarily) so that they all begin with
537 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
538 stock m88k/svr4 assembler, both of which need to see .L at the start of
539 a label in order to prevent that label from going into the linker symbol
540 table). When I get time, I'll have to fix this the right way so that we
541 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
542 but that will require a rather massive set of changes. For the moment,
543 the following definitions out to produce the right results for all svr4
544 and svr3 assemblers. -- rfg
547 #ifndef TEXT_BEGIN_LABEL
548 #define TEXT_BEGIN_LABEL "*.L_text_b"
550 #ifndef TEXT_END_LABEL
551 #define TEXT_END_LABEL "*.L_text_e"
554 #ifndef DATA_BEGIN_LABEL
555 #define DATA_BEGIN_LABEL "*.L_data_b"
557 #ifndef DATA_END_LABEL
558 #define DATA_END_LABEL "*.L_data_e"
561 #ifndef DATA1_BEGIN_LABEL
562 #define DATA1_BEGIN_LABEL "*.L_data1_b"
564 #ifndef DATA1_END_LABEL
565 #define DATA1_END_LABEL "*.L_data1_e"
568 #ifndef RODATA_BEGIN_LABEL
569 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
571 #ifndef RODATA_END_LABEL
572 #define RODATA_END_LABEL "*.L_rodata_e"
575 #ifndef RODATA1_BEGIN_LABEL
576 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
578 #ifndef RODATA1_END_LABEL
579 #define RODATA1_END_LABEL "*.L_rodata1_e"
582 #ifndef BSS_BEGIN_LABEL
583 #define BSS_BEGIN_LABEL "*.L_bss_b"
585 #ifndef BSS_END_LABEL
586 #define BSS_END_LABEL "*.L_bss_e"
589 #ifndef LINE_BEGIN_LABEL
590 #define LINE_BEGIN_LABEL "*.L_line_b"
592 #ifndef LINE_LAST_ENTRY_LABEL
593 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
595 #ifndef LINE_END_LABEL
596 #define LINE_END_LABEL "*.L_line_e"
599 #ifndef DEBUG_BEGIN_LABEL
600 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
602 #ifndef SFNAMES_BEGIN_LABEL
603 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
605 #ifndef SRCINFO_BEGIN_LABEL
606 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
608 #ifndef MACINFO_BEGIN_LABEL
609 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
612 #ifndef DIE_BEGIN_LABEL_FMT
613 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
615 #ifndef DIE_END_LABEL_FMT
616 #define DIE_END_LABEL_FMT "*.L_D%u_e"
618 #ifndef PUB_DIE_LABEL_FMT
619 #define PUB_DIE_LABEL_FMT "*.L_P%u"
621 #ifndef INSN_LABEL_FMT
622 #define INSN_LABEL_FMT "*.L_I%u_%u"
624 #ifndef BLOCK_BEGIN_LABEL_FMT
625 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
627 #ifndef BLOCK_END_LABEL_FMT
628 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
630 #ifndef SS_BEGIN_LABEL_FMT
631 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
633 #ifndef SS_END_LABEL_FMT
634 #define SS_END_LABEL_FMT "*.L_s%u_e"
636 #ifndef EE_BEGIN_LABEL_FMT
637 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
639 #ifndef EE_END_LABEL_FMT
640 #define EE_END_LABEL_FMT "*.L_e%u_e"
642 #ifndef MT_BEGIN_LABEL_FMT
643 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
645 #ifndef MT_END_LABEL_FMT
646 #define MT_END_LABEL_FMT "*.L_t%u_e"
648 #ifndef LOC_BEGIN_LABEL_FMT
649 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
651 #ifndef LOC_END_LABEL_FMT
652 #define LOC_END_LABEL_FMT "*.L_l%u_e"
654 #ifndef BOUND_BEGIN_LABEL_FMT
655 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
657 #ifndef BOUND_END_LABEL_FMT
658 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
660 #ifndef DERIV_BEGIN_LABEL_FMT
661 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
663 #ifndef DERIV_END_LABEL_FMT
664 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
666 #ifndef SL_BEGIN_LABEL_FMT
667 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
669 #ifndef SL_END_LABEL_FMT
670 #define SL_END_LABEL_FMT "*.L_sl%u_e"
672 #ifndef BODY_BEGIN_LABEL_FMT
673 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
675 #ifndef BODY_END_LABEL_FMT
676 #define BODY_END_LABEL_FMT "*.L_b%u_e"
678 #ifndef FUNC_END_LABEL_FMT
679 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
681 #ifndef TYPE_NAME_FMT
682 #define TYPE_NAME_FMT "*.L_T%u"
684 #ifndef DECL_NAME_FMT
685 #define DECL_NAME_FMT "*.L_E%u"
687 #ifndef LINE_CODE_LABEL_FMT
688 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
690 #ifndef SFNAMES_ENTRY_LABEL_FMT
691 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
693 #ifndef LINE_ENTRY_LABEL_FMT
694 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
697 /* Definitions of defaults for various types of primitive assembly language
700 If necessary, these may be overridden from within your tm.h file,
701 but typically, you shouldn't need to override these. */
703 #ifndef ASM_OUTPUT_PUSH_SECTION
704 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
705 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
708 #ifndef ASM_OUTPUT_POP_SECTION
709 #define ASM_OUTPUT_POP_SECTION(FILE) \
710 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
713 #ifndef ASM_OUTPUT_DWARF_DELTA2
714 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
715 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
716 assemble_name (FILE, LABEL1); \
717 fprintf (FILE, "-"); \
718 assemble_name (FILE, LABEL2); \
719 fprintf (FILE, "\n"); \
723 #ifndef ASM_OUTPUT_DWARF_DELTA4
724 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
725 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
726 assemble_name (FILE, LABEL1); \
727 fprintf (FILE, "-"); \
728 assemble_name (FILE, LABEL2); \
729 fprintf (FILE, "\n"); \
733 #ifndef ASM_OUTPUT_DWARF_TAG
734 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
736 fprintf ((FILE), "\t%s\t0x%x", \
737 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
738 if (flag_debug_asm) \
739 fprintf ((FILE), "\t%s %s", \
740 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
741 fputc ('\n', (FILE)); \
745 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
746 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
748 fprintf ((FILE), "\t%s\t0x%x", \
749 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
750 if (flag_debug_asm) \
751 fprintf ((FILE), "\t%s %s", \
752 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
753 fputc ('\n', (FILE)); \
757 #ifndef ASM_OUTPUT_DWARF_STACK_OP
758 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
760 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
761 if (flag_debug_asm) \
762 fprintf ((FILE), "\t%s %s", \
763 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
764 fputc ('\n', (FILE)); \
768 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
769 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
771 fprintf ((FILE), "\t%s\t0x%x", \
772 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
773 if (flag_debug_asm) \
774 fprintf ((FILE), "\t%s %s", \
775 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
776 fputc ('\n', (FILE)); \
780 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
781 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
783 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
784 if (flag_debug_asm) \
785 fprintf ((FILE), "\t%s %s", \
786 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
787 fputc ('\n', (FILE)); \
791 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
792 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
794 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
795 if (flag_debug_asm) \
796 fprintf ((FILE), "\t%s %s", \
797 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
798 fputc ('\n', (FILE)); \
802 #ifndef ASM_OUTPUT_DWARF_ADDR
803 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
804 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
805 assemble_name (FILE, LABEL); \
806 fprintf (FILE, "\n"); \
810 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
811 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
813 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
814 output_addr_const ((FILE), (RTX)); \
815 fputc ('\n', (FILE)); \
819 #ifndef ASM_OUTPUT_DWARF_REF
820 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
821 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
822 assemble_name (FILE, LABEL); \
823 fprintf (FILE, "\n"); \
827 #ifndef ASM_OUTPUT_DWARF_DATA1
828 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
829 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
832 #ifndef ASM_OUTPUT_DWARF_DATA2
833 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
834 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
837 #ifndef ASM_OUTPUT_DWARF_DATA4
838 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
839 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
842 #ifndef ASM_OUTPUT_DWARF_DATA8
843 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
845 if (WORDS_BIG_ENDIAN) \
847 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
848 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
852 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
853 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
858 #ifndef ASM_OUTPUT_DWARF_STRING
859 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
860 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
863 /************************ general utility functions **************************/
869 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
870 || ((GET_CODE (rtl) == SUBREG)
871 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
875 type_main_variant (type)
878 type = TYPE_MAIN_VARIANT (type);
880 /* There really should be only one main variant among any group of variants
881 of a given type (and all of the MAIN_VARIANT values for all members of
882 the group should point to that one type) but sometimes the C front-end
883 messes this up for array types, so we work around that bug here. */
885 if (TREE_CODE (type) == ARRAY_TYPE)
887 while (type != TYPE_MAIN_VARIANT (type))
888 type = TYPE_MAIN_VARIANT (type);
894 /* Return non-zero if the given type node represents a tagged type. */
897 is_tagged_type (type)
900 register enum tree_code code = TREE_CODE (type);
902 return (code == RECORD_TYPE || code == UNION_TYPE
903 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
908 register unsigned tag;
912 case TAG_padding: return "TAG_padding";
913 case TAG_array_type: return "TAG_array_type";
914 case TAG_class_type: return "TAG_class_type";
915 case TAG_entry_point: return "TAG_entry_point";
916 case TAG_enumeration_type: return "TAG_enumeration_type";
917 case TAG_formal_parameter: return "TAG_formal_parameter";
918 case TAG_global_subroutine: return "TAG_global_subroutine";
919 case TAG_global_variable: return "TAG_global_variable";
920 case TAG_label: return "TAG_label";
921 case TAG_lexical_block: return "TAG_lexical_block";
922 case TAG_local_variable: return "TAG_local_variable";
923 case TAG_member: return "TAG_member";
924 case TAG_pointer_type: return "TAG_pointer_type";
925 case TAG_reference_type: return "TAG_reference_type";
926 case TAG_compile_unit: return "TAG_compile_unit";
927 case TAG_string_type: return "TAG_string_type";
928 case TAG_structure_type: return "TAG_structure_type";
929 case TAG_subroutine: return "TAG_subroutine";
930 case TAG_subroutine_type: return "TAG_subroutine_type";
931 case TAG_typedef: return "TAG_typedef";
932 case TAG_union_type: return "TAG_union_type";
933 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
934 case TAG_variant: return "TAG_variant";
935 case TAG_common_block: return "TAG_common_block";
936 case TAG_common_inclusion: return "TAG_common_inclusion";
937 case TAG_inheritance: return "TAG_inheritance";
938 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
939 case TAG_module: return "TAG_module";
940 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
941 case TAG_set_type: return "TAG_set_type";
942 case TAG_subrange_type: return "TAG_subrange_type";
943 case TAG_with_stmt: return "TAG_with_stmt";
945 /* GNU extensions. */
947 case TAG_format_label: return "TAG_format_label";
948 case TAG_namelist: return "TAG_namelist";
949 case TAG_function_template: return "TAG_function_template";
950 case TAG_class_template: return "TAG_class_template";
952 default: return "TAG_<unknown>";
957 dwarf_attr_name (attr)
958 register unsigned attr;
962 case AT_sibling: return "AT_sibling";
963 case AT_location: return "AT_location";
964 case AT_name: return "AT_name";
965 case AT_fund_type: return "AT_fund_type";
966 case AT_mod_fund_type: return "AT_mod_fund_type";
967 case AT_user_def_type: return "AT_user_def_type";
968 case AT_mod_u_d_type: return "AT_mod_u_d_type";
969 case AT_ordering: return "AT_ordering";
970 case AT_subscr_data: return "AT_subscr_data";
971 case AT_byte_size: return "AT_byte_size";
972 case AT_bit_offset: return "AT_bit_offset";
973 case AT_bit_size: return "AT_bit_size";
974 case AT_element_list: return "AT_element_list";
975 case AT_stmt_list: return "AT_stmt_list";
976 case AT_low_pc: return "AT_low_pc";
977 case AT_high_pc: return "AT_high_pc";
978 case AT_language: return "AT_language";
979 case AT_member: return "AT_member";
980 case AT_discr: return "AT_discr";
981 case AT_discr_value: return "AT_discr_value";
982 case AT_string_length: return "AT_string_length";
983 case AT_common_reference: return "AT_common_reference";
984 case AT_comp_dir: return "AT_comp_dir";
985 case AT_const_value_string: return "AT_const_value_string";
986 case AT_const_value_data2: return "AT_const_value_data2";
987 case AT_const_value_data4: return "AT_const_value_data4";
988 case AT_const_value_data8: return "AT_const_value_data8";
989 case AT_const_value_block2: return "AT_const_value_block2";
990 case AT_const_value_block4: return "AT_const_value_block4";
991 case AT_containing_type: return "AT_containing_type";
992 case AT_default_value_addr: return "AT_default_value_addr";
993 case AT_default_value_data2: return "AT_default_value_data2";
994 case AT_default_value_data4: return "AT_default_value_data4";
995 case AT_default_value_data8: return "AT_default_value_data8";
996 case AT_default_value_string: return "AT_default_value_string";
997 case AT_friends: return "AT_friends";
998 case AT_inline: return "AT_inline";
999 case AT_is_optional: return "AT_is_optional";
1000 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1001 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1002 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1003 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1004 case AT_private: return "AT_private";
1005 case AT_producer: return "AT_producer";
1006 case AT_program: return "AT_program";
1007 case AT_protected: return "AT_protected";
1008 case AT_prototyped: return "AT_prototyped";
1009 case AT_public: return "AT_public";
1010 case AT_pure_virtual: return "AT_pure_virtual";
1011 case AT_return_addr: return "AT_return_addr";
1012 case AT_abstract_origin: return "AT_abstract_origin";
1013 case AT_start_scope: return "AT_start_scope";
1014 case AT_stride_size: return "AT_stride_size";
1015 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1016 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1017 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1018 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1019 case AT_virtual: return "AT_virtual";
1021 /* GNU extensions */
1023 case AT_sf_names: return "AT_sf_names";
1024 case AT_src_info: return "AT_src_info";
1025 case AT_mac_info: return "AT_mac_info";
1026 case AT_src_coords: return "AT_src_coords";
1027 case AT_body_begin: return "AT_body_begin";
1028 case AT_body_end: return "AT_body_end";
1030 default: return "AT_<unknown>";
1035 dwarf_stack_op_name (op)
1036 register unsigned op;
1040 case OP_REG: return "OP_REG";
1041 case OP_BASEREG: return "OP_BASEREG";
1042 case OP_ADDR: return "OP_ADDR";
1043 case OP_CONST: return "OP_CONST";
1044 case OP_DEREF2: return "OP_DEREF2";
1045 case OP_DEREF4: return "OP_DEREF4";
1046 case OP_ADD: return "OP_ADD";
1047 default: return "OP_<unknown>";
1052 dwarf_typemod_name (mod)
1053 register unsigned mod;
1057 case MOD_pointer_to: return "MOD_pointer_to";
1058 case MOD_reference_to: return "MOD_reference_to";
1059 case MOD_const: return "MOD_const";
1060 case MOD_volatile: return "MOD_volatile";
1061 default: return "MOD_<unknown>";
1066 dwarf_fmt_byte_name (fmt)
1067 register unsigned fmt;
1071 case FMT_FT_C_C: return "FMT_FT_C_C";
1072 case FMT_FT_C_X: return "FMT_FT_C_X";
1073 case FMT_FT_X_C: return "FMT_FT_X_C";
1074 case FMT_FT_X_X: return "FMT_FT_X_X";
1075 case FMT_UT_C_C: return "FMT_UT_C_C";
1076 case FMT_UT_C_X: return "FMT_UT_C_X";
1077 case FMT_UT_X_C: return "FMT_UT_X_C";
1078 case FMT_UT_X_X: return "FMT_UT_X_X";
1079 case FMT_ET: return "FMT_ET";
1080 default: return "FMT_<unknown>";
1085 dwarf_fund_type_name (ft)
1086 register unsigned ft;
1090 case FT_char: return "FT_char";
1091 case FT_signed_char: return "FT_signed_char";
1092 case FT_unsigned_char: return "FT_unsigned_char";
1093 case FT_short: return "FT_short";
1094 case FT_signed_short: return "FT_signed_short";
1095 case FT_unsigned_short: return "FT_unsigned_short";
1096 case FT_integer: return "FT_integer";
1097 case FT_signed_integer: return "FT_signed_integer";
1098 case FT_unsigned_integer: return "FT_unsigned_integer";
1099 case FT_long: return "FT_long";
1100 case FT_signed_long: return "FT_signed_long";
1101 case FT_unsigned_long: return "FT_unsigned_long";
1102 case FT_pointer: return "FT_pointer";
1103 case FT_float: return "FT_float";
1104 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1105 case FT_ext_prec_float: return "FT_ext_prec_float";
1106 case FT_complex: return "FT_complex";
1107 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1108 case FT_void: return "FT_void";
1109 case FT_boolean: return "FT_boolean";
1110 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1111 case FT_label: return "FT_label";
1113 /* GNU extensions. */
1115 case FT_long_long: return "FT_long_long";
1116 case FT_signed_long_long: return "FT_signed_long_long";
1117 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1119 case FT_int8: return "FT_int8";
1120 case FT_signed_int8: return "FT_signed_int8";
1121 case FT_unsigned_int8: return "FT_unsigned_int8";
1122 case FT_int16: return "FT_int16";
1123 case FT_signed_int16: return "FT_signed_int16";
1124 case FT_unsigned_int16: return "FT_unsigned_int16";
1125 case FT_int32: return "FT_int32";
1126 case FT_signed_int32: return "FT_signed_int32";
1127 case FT_unsigned_int32: return "FT_unsigned_int32";
1128 case FT_int64: return "FT_int64";
1129 case FT_signed_int64: return "FT_signed_int64";
1130 case FT_unsigned_int64: return "FT_unsigned_int64";
1132 case FT_real32: return "FT_real32";
1133 case FT_real64: return "FT_real64";
1134 case FT_real96: return "FT_real96";
1135 case FT_real128: return "FT_real128";
1137 default: return "FT_<unknown>";
1141 /* Determine the "ultimate origin" of a decl. The decl may be an
1142 inlined instance of an inlined instance of a decl which is local
1143 to an inline function, so we have to trace all of the way back
1144 through the origin chain to find out what sort of node actually
1145 served as the original seed for the given block. */
1148 decl_ultimate_origin (decl)
1151 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1153 if (immediate_origin == NULL)
1157 register tree ret_val;
1158 register tree lookahead = immediate_origin;
1162 ret_val = lookahead;
1163 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1165 while (lookahead != NULL && lookahead != ret_val);
1170 /* Determine the "ultimate origin" of a block. The block may be an
1171 inlined instance of an inlined instance of a block which is local
1172 to an inline function, so we have to trace all of the way back
1173 through the origin chain to find out what sort of node actually
1174 served as the original seed for the given block. */
1177 block_ultimate_origin (block)
1178 register tree block;
1180 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1182 if (immediate_origin == NULL)
1186 register tree ret_val;
1187 register tree lookahead = immediate_origin;
1191 ret_val = lookahead;
1192 lookahead = (TREE_CODE (ret_val) == BLOCK)
1193 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1196 while (lookahead != NULL && lookahead != ret_val);
1201 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1202 of a virtual function may refer to a base class, so we check the 'this'
1206 decl_class_context (decl)
1209 tree context = NULL_TREE;
1210 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1211 context = DECL_CONTEXT (decl);
1213 context = TYPE_MAIN_VARIANT
1214 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1216 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1217 context = NULL_TREE;
1223 output_unsigned_leb128 (value)
1224 register unsigned long value;
1226 register unsigned long orig_value = value;
1230 register unsigned byte = (value & 0x7f);
1233 if (value != 0) /* more bytes to follow */
1235 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1236 if (flag_debug_asm && value == 0)
1237 fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1238 ASM_COMMENT_START, orig_value);
1239 fputc ('\n', asm_out_file);
1245 output_signed_leb128 (value)
1246 register long value;
1248 register long orig_value = value;
1249 register int negative = (value < 0);
1254 register unsigned byte = (value & 0x7f);
1258 value |= 0xfe000000; /* manually sign extend */
1259 if (((value == 0) && ((byte & 0x40) == 0))
1260 || ((value == -1) && ((byte & 0x40) == 1)))
1267 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1268 if (flag_debug_asm && more == 0)
1269 fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1270 ASM_COMMENT_START, orig_value);
1271 fputc ('\n', asm_out_file);
1276 /**************** utility functions for attribute functions ******************/
1278 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1279 node in question represents the outermost pair of curly braces (i.e.
1280 the "body block") of a function or method.
1282 For any BLOCK node representing a "body block" of a function or method,
1283 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1284 which represents the outermost (function) scope for the function or
1285 method (i.e. the one which includes the formal parameters). The
1286 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1291 is_body_block (stmt)
1294 if (TREE_CODE (stmt) == BLOCK)
1296 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1298 if (TREE_CODE (parent) == BLOCK)
1300 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1302 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1309 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1310 type code for the given type.
1312 This routine must only be called for GCC type nodes that correspond to
1313 Dwarf fundamental types.
1315 The current Dwarf draft specification calls for Dwarf fundamental types
1316 to accurately reflect the fact that a given type was either a "plain"
1317 integral type or an explicitly "signed" integral type. Unfortunately,
1318 we can't always do this, because GCC may already have thrown away the
1319 information about the precise way in which the type was originally
1322 typedef signed int my_type;
1324 struct s { my_type f; };
1326 Since we may be stuck here without enought information to do exactly
1327 what is called for in the Dwarf draft specification, we do the best
1328 that we can under the circumstances and always use the "plain" integral
1329 fundamental type codes for int, short, and long types. That's probably
1330 good enough. The additional accuracy called for in the current DWARF
1331 draft specification is probably never even useful in practice. */
1334 fundamental_type_code (type)
1337 if (TREE_CODE (type) == ERROR_MARK)
1340 switch (TREE_CODE (type))
1349 /* Carefully distinguish all the standard types of C,
1350 without messing up if the language is not C.
1351 Note that we check only for the names that contain spaces;
1352 other names might occur by coincidence in other languages. */
1353 if (TYPE_NAME (type) != 0
1354 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1355 && DECL_NAME (TYPE_NAME (type)) != 0
1356 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1358 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1360 if (!strcmp (name, "unsigned char"))
1361 return FT_unsigned_char;
1362 if (!strcmp (name, "signed char"))
1363 return FT_signed_char;
1364 if (!strcmp (name, "unsigned int"))
1365 return FT_unsigned_integer;
1366 if (!strcmp (name, "short int"))
1368 if (!strcmp (name, "short unsigned int"))
1369 return FT_unsigned_short;
1370 if (!strcmp (name, "long int"))
1372 if (!strcmp (name, "long unsigned int"))
1373 return FT_unsigned_long;
1374 if (!strcmp (name, "long long int"))
1375 return FT_long_long; /* Not grok'ed by svr4 SDB */
1376 if (!strcmp (name, "long long unsigned int"))
1377 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1380 /* Most integer types will be sorted out above, however, for the
1381 sake of special `array index' integer types, the following code
1382 is also provided. */
1384 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1385 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1387 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1388 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1390 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1391 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1393 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1394 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1396 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1397 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1402 /* Carefully distinguish all the standard types of C,
1403 without messing up if the language is not C. */
1404 if (TYPE_NAME (type) != 0
1405 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1406 && DECL_NAME (TYPE_NAME (type)) != 0
1407 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1409 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1411 /* Note that here we can run afowl of a serious bug in "classic"
1412 svr4 SDB debuggers. They don't seem to understand the
1413 FT_ext_prec_float type (even though they should). */
1415 if (!strcmp (name, "long double"))
1416 return FT_ext_prec_float;
1419 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1420 return FT_dbl_prec_float;
1421 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
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 (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1429 return FT_ext_prec_float;
1433 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1436 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1439 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1442 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1447 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1448 the Dwarf "root" type for the given input type. The Dwarf "root" type
1449 of a given type is generally the same as the given type, except that if
1450 the given type is a pointer or reference type, then the root type of
1451 the given type is the root type of the "basis" type for the pointer or
1452 reference type. (This definition of the "root" type is recursive.)
1453 Also, the root type of a `const' qualified type or a `volatile'
1454 qualified type is the root type of the given type without the
1458 root_type_1 (type, count)
1462 /* Give up after searching 1000 levels, in case this is a recursive
1463 pointer type. Such types are possible in Ada, but it is not possible
1464 to represent them in DWARF1 debug info. */
1466 return error_mark_node;
1468 switch (TREE_CODE (type))
1471 return error_mark_node;
1474 case REFERENCE_TYPE:
1475 return root_type_1 (TREE_TYPE (type), count+1);
1486 type = root_type_1 (type, 0);
1487 if (type != error_mark_node)
1488 type = type_main_variant (type);
1492 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1493 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1496 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1498 register int decl_const;
1499 register int decl_volatile;
1502 if (TREE_CODE (type) == ERROR_MARK)
1505 /* Give up after searching 1000 levels, in case this is a recursive
1506 pointer type. Such types are possible in Ada, but it is not possible
1507 to represent them in DWARF1 debug info. */
1511 if (TYPE_READONLY (type) || decl_const)
1512 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1513 if (TYPE_VOLATILE (type) || decl_volatile)
1514 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1515 switch (TREE_CODE (type))
1518 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1519 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1522 case REFERENCE_TYPE:
1523 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1524 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1534 write_modifier_bytes (type, decl_const, decl_volatile)
1536 register int decl_const;
1537 register int decl_volatile;
1539 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1542 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1543 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1546 type_is_fundamental (type)
1549 switch (TREE_CODE (type))
1564 case QUAL_UNION_TYPE:
1569 case REFERENCE_TYPE:
1581 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1582 equate directive which will associate a symbolic name with the current DIE.
1584 The name used is an artificial label generated from the DECL_UID number
1585 associated with the given decl node. The name it gets equated to is the
1586 symbolic label that we (previously) output at the start of the DIE that
1587 we are currently generating.
1589 Calling this function while generating some "decl related" form of DIE
1590 makes it possible to later refer to the DIE which represents the given
1591 decl simply by re-generating the symbolic name from the ..._DECL node's
1595 equate_decl_number_to_die_number (decl)
1598 /* In the case where we are generating a DIE for some ..._DECL node
1599 which represents either some inline function declaration or some
1600 entity declared within an inline function declaration/definition,
1601 setup a symbolic name for the current DIE so that we have a name
1602 for this DIE that we can easily refer to later on within
1603 AT_abstract_origin attributes. */
1605 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1606 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1608 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1609 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1610 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1613 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1614 equate directive which will associate a symbolic name with the current DIE.
1616 The name used is an artificial label generated from the TYPE_UID number
1617 associated with the given type node. The name it gets equated to is the
1618 symbolic label that we (previously) output at the start of the DIE that
1619 we are currently generating.
1621 Calling this function while generating some "type related" form of DIE
1622 makes it easy to later refer to the DIE which represents the given type
1623 simply by re-generating the alternative name from the ..._TYPE node's
1627 equate_type_number_to_die_number (type)
1630 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1631 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1633 /* We are generating a DIE to represent the main variant of this type
1634 (i.e the type without any const or volatile qualifiers) so in order
1635 to get the equate to come out right, we need to get the main variant
1638 type = type_main_variant (type);
1640 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1641 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1642 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1646 output_reg_number (rtl)
1649 register unsigned regno = REGNO (rtl);
1651 if (regno >= FIRST_PSEUDO_REGISTER)
1653 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1657 fprintf (asm_out_file, "\t%s\t0x%x",
1658 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1661 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1662 PRINT_REG (rtl, 0, asm_out_file);
1664 fputc ('\n', asm_out_file);
1667 /* The following routine is a nice and simple transducer. It converts the
1668 RTL for a variable or parameter (resident in memory) into an equivalent
1669 Dwarf representation of a mechanism for getting the address of that same
1670 variable onto the top of a hypothetical "address evaluation" stack.
1672 When creating memory location descriptors, we are effectively trans-
1673 forming the RTL for a memory-resident object into its Dwarf postfix
1674 expression equivalent. This routine just recursively descends an
1675 RTL tree, turning it into Dwarf postfix code as it goes. */
1678 output_mem_loc_descriptor (rtl)
1681 /* Note that for a dynamically sized array, the location we will
1682 generate a description of here will be the lowest numbered location
1683 which is actually within the array. That's *not* necessarily the
1684 same as the zeroth element of the array. */
1686 switch (GET_CODE (rtl))
1690 /* The case of a subreg may arise when we have a local (register)
1691 variable or a formal (register) parameter which doesn't quite
1692 fill up an entire register. For now, just assume that it is
1693 legitimate to make the Dwarf info refer to the whole register
1694 which contains the given subreg. */
1696 rtl = XEXP (rtl, 0);
1701 /* Whenever a register number forms a part of the description of
1702 the method for calculating the (dynamic) address of a memory
1703 resident object, DWARF rules require the register number to
1704 be referred to as a "base register". This distinction is not
1705 based in any way upon what category of register the hardware
1706 believes the given register belongs to. This is strictly
1707 DWARF terminology we're dealing with here.
1709 Note that in cases where the location of a memory-resident data
1710 object could be expressed as:
1712 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1714 the actual DWARF location descriptor that we generate may just
1715 be OP_BASEREG (basereg). This may look deceptively like the
1716 object in question was allocated to a register (rather than
1717 in memory) so DWARF consumers need to be aware of the subtle
1718 distinction between OP_REG and OP_BASEREG. */
1720 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1721 output_reg_number (rtl);
1725 output_mem_loc_descriptor (XEXP (rtl, 0));
1726 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1731 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1732 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1736 output_mem_loc_descriptor (XEXP (rtl, 0));
1737 output_mem_loc_descriptor (XEXP (rtl, 1));
1738 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1742 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1743 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1747 /* If a pseudo-reg is optimized away, it is possible for it to
1748 be replaced with a MEM containing a multiply. Use a GNU extension
1750 output_mem_loc_descriptor (XEXP (rtl, 0));
1751 output_mem_loc_descriptor (XEXP (rtl, 1));
1752 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1760 /* Output a proper Dwarf location descriptor for a variable or parameter
1761 which is either allocated in a register or in a memory location. For
1762 a register, we just generate an OP_REG and the register number. For a
1763 memory location we provide a Dwarf postfix expression describing how to
1764 generate the (dynamic) address of the object onto the address stack. */
1767 output_loc_descriptor (rtl)
1770 switch (GET_CODE (rtl))
1774 /* The case of a subreg may arise when we have a local (register)
1775 variable or a formal (register) parameter which doesn't quite
1776 fill up an entire register. For now, just assume that it is
1777 legitimate to make the Dwarf info refer to the whole register
1778 which contains the given subreg. */
1780 rtl = XEXP (rtl, 0);
1784 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1785 output_reg_number (rtl);
1789 output_mem_loc_descriptor (XEXP (rtl, 0));
1793 abort (); /* Should never happen */
1797 /* Given a tree node describing an array bound (either lower or upper)
1798 output a representation for that bound. */
1801 output_bound_representation (bound, dim_num, u_or_l)
1802 register tree bound;
1803 register unsigned dim_num; /* For multi-dimensional arrays. */
1804 register char u_or_l; /* Designates upper or lower bound. */
1806 switch (TREE_CODE (bound))
1812 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1815 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1816 (unsigned) TREE_INT_CST_LOW (bound));
1821 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1822 SAVE_EXPR nodes, in which case we can do something, or as
1823 an expression, which we cannot represent. */
1825 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1826 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1828 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1829 current_dienum, dim_num, u_or_l);
1831 sprintf (end_label, BOUND_END_LABEL_FMT,
1832 current_dienum, dim_num, u_or_l);
1834 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1835 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1837 /* If optimization is turned on, the SAVE_EXPRs that describe
1838 how to access the upper bound values are essentially bogus.
1839 They only describe (at best) how to get at these values at
1840 the points in the generated code right after they have just
1841 been computed. Worse yet, in the typical case, the upper
1842 bound values will not even *be* computed in the optimized
1843 code, so these SAVE_EXPRs are entirely bogus.
1845 In order to compensate for this fact, we check here to see
1846 if optimization is enabled, and if so, we effectively create
1847 an empty location description for the (unknown and unknowable)
1850 This should not cause too much trouble for existing (stupid?)
1851 debuggers because they have to deal with empty upper bounds
1852 location descriptions anyway in order to be able to deal with
1853 incomplete array types.
1855 Of course an intelligent debugger (GDB?) should be able to
1856 comprehend that a missing upper bound specification in a
1857 array type used for a storage class `auto' local array variable
1858 indicates that the upper bound is both unknown (at compile-
1859 time) and unknowable (at run-time) due to optimization. */
1863 while (TREE_CODE (bound) == NOP_EXPR
1864 || TREE_CODE (bound) == CONVERT_EXPR)
1865 bound = TREE_OPERAND (bound, 0);
1867 if (TREE_CODE (bound) == SAVE_EXPR)
1868 output_loc_descriptor
1869 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX, 0));
1872 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1879 /* Recursive function to output a sequence of value/name pairs for
1880 enumeration constants in reversed order. This is called from
1881 enumeration_type_die. */
1884 output_enumeral_list (link)
1889 output_enumeral_list (TREE_CHAIN (link));
1890 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1891 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1892 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1893 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1897 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1898 which is not less than the value itself. */
1900 static inline unsigned
1901 ceiling (value, boundary)
1902 register unsigned value;
1903 register unsigned boundary;
1905 return (((value + boundary - 1) / boundary) * boundary);
1908 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1909 pointer to the declared type for the relevant field variable, or return
1910 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1918 if (TREE_CODE (decl) == ERROR_MARK)
1919 return integer_type_node;
1921 type = DECL_BIT_FIELD_TYPE (decl);
1923 type = TREE_TYPE (decl);
1927 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1928 node, return the alignment in bits for the type, or else return
1929 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1931 static inline unsigned
1932 simple_type_align_in_bits (type)
1935 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1938 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1939 node, return the size in bits for the type if it is a constant, or
1940 else return the alignment for the type if the type's size is not
1941 constant, or else return BITS_PER_WORD if the type actually turns out
1942 to be an ERROR_MARK node. */
1944 static inline unsigned
1945 simple_type_size_in_bits (type)
1948 if (TREE_CODE (type) == ERROR_MARK)
1949 return BITS_PER_WORD;
1952 register tree type_size_tree = TYPE_SIZE (type);
1954 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1955 return TYPE_ALIGN (type);
1957 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1961 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1962 return the byte offset of the lowest addressed byte of the "containing
1963 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1964 mine what that offset is, either because the argument turns out to be a
1965 pointer to an ERROR_MARK node, or because the offset is actually variable.
1966 (We can't handle the latter case just yet.) */
1969 field_byte_offset (decl)
1972 register unsigned type_align_in_bytes;
1973 register unsigned type_align_in_bits;
1974 register unsigned type_size_in_bits;
1975 register unsigned object_offset_in_align_units;
1976 register unsigned object_offset_in_bits;
1977 register unsigned object_offset_in_bytes;
1979 register tree bitpos_tree;
1980 register tree field_size_tree;
1981 register unsigned bitpos_int;
1982 register unsigned deepest_bitpos;
1983 register unsigned field_size_in_bits;
1985 if (TREE_CODE (decl) == ERROR_MARK)
1988 if (TREE_CODE (decl) != FIELD_DECL)
1991 type = field_type (decl);
1993 bitpos_tree = DECL_FIELD_BITPOS (decl);
1994 field_size_tree = DECL_SIZE (decl);
1996 /* We cannot yet cope with fields whose positions or sizes are variable,
1997 so for now, when we see such things, we simply return 0. Someday,
1998 we may be able to handle such cases, but it will be damn difficult. */
2000 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2002 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2004 if (TREE_CODE (field_size_tree) != INTEGER_CST)
2006 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
2008 type_size_in_bits = simple_type_size_in_bits (type);
2010 type_align_in_bits = simple_type_align_in_bits (type);
2011 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2013 /* Note that the GCC front-end doesn't make any attempt to keep track
2014 of the starting bit offset (relative to the start of the containing
2015 structure type) of the hypothetical "containing object" for a bit-
2016 field. Thus, when computing the byte offset value for the start of
2017 the "containing object" of a bit-field, we must deduce this infor-
2020 This can be rather tricky to do in some cases. For example, handling
2021 the following structure type definition when compiling for an i386/i486
2022 target (which only aligns long long's to 32-bit boundaries) can be very
2027 long long field2:31;
2030 Fortunately, there is a simple rule-of-thumb which can be used in such
2031 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2032 the structure shown above. It decides to do this based upon one simple
2033 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2034 taining object" for each bit-field at the first (i.e. lowest addressed)
2035 legitimate alignment boundary (based upon the required minimum alignment
2036 for the declared type of the field) which it can possibly use, subject
2037 to the condition that there is still enough available space remaining
2038 in the containing object (when allocated at the selected point) to
2039 fully accommodate all of the bits of the bit-field itself.
2041 This simple rule makes it obvious why GCC allocates 8 bytes for each
2042 object of the structure type shown above. When looking for a place to
2043 allocate the "containing object" for `field2', the compiler simply tries
2044 to allocate a 64-bit "containing object" at each successive 32-bit
2045 boundary (starting at zero) until it finds a place to allocate that 64-
2046 bit field such that at least 31 contiguous (and previously unallocated)
2047 bits remain within that selected 64 bit field. (As it turns out, for
2048 the example above, the compiler finds that it is OK to allocate the
2049 "containing object" 64-bit field at bit-offset zero within the
2052 Here we attempt to work backwards from the limited set of facts we're
2053 given, and we try to deduce from those facts, where GCC must have
2054 believed that the containing object started (within the structure type).
2056 The value we deduce is then used (by the callers of this routine) to
2057 generate AT_location and AT_bit_offset attributes for fields (both
2058 bit-fields and, in the case of AT_location, regular fields as well).
2061 /* Figure out the bit-distance from the start of the structure to the
2062 "deepest" bit of the bit-field. */
2063 deepest_bitpos = bitpos_int + field_size_in_bits;
2065 /* This is the tricky part. Use some fancy footwork to deduce where the
2066 lowest addressed bit of the containing object must be. */
2067 object_offset_in_bits
2068 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2070 /* Compute the offset of the containing object in "alignment units". */
2071 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2073 /* Compute the offset of the containing object in bytes. */
2074 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2076 /* The above code assumes that the field does not cross an alignment
2077 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2078 or if the structure is packed. If this happens, then we get an object
2079 which starts after the bitfield, which means that the bit offset is
2080 negative. Gdb fails when given negative bit offsets. We avoid this
2081 by recomputing using the first bit of the bitfield. This will give
2082 us an object which does not completely contain the bitfield, but it
2083 will be aligned, and it will contain the first bit of the bitfield. */
2084 if (object_offset_in_bits > bitpos_int)
2086 deepest_bitpos = bitpos_int + 1;
2087 object_offset_in_bits
2088 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2089 object_offset_in_align_units = (object_offset_in_bits
2090 / type_align_in_bits);
2091 object_offset_in_bytes = (object_offset_in_align_units
2092 * type_align_in_bytes);
2095 return object_offset_in_bytes;
2098 /****************************** attributes *********************************/
2100 /* The following routines are responsible for writing out the various types
2101 of Dwarf attributes (and any following data bytes associated with them).
2102 These routines are listed in order based on the numerical codes of their
2103 associated attributes. */
2105 /* Generate an AT_sibling attribute. */
2108 sibling_attribute ()
2110 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2112 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2113 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2114 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2117 /* Output the form of location attributes suitable for whole variables and
2118 whole parameters. Note that the location attributes for struct fields
2119 are generated by the routine `data_member_location_attribute' below. */
2122 location_attribute (rtl)
2125 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2126 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2128 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2129 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2130 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2131 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2132 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2134 /* Handle a special case. If we are about to output a location descriptor
2135 for a variable or parameter which has been optimized out of existence,
2136 don't do that. Instead we output a zero-length location descriptor
2137 value as part of the location attribute.
2139 A variable which has been optimized out of existence will have a
2140 DECL_RTL value which denotes a pseudo-reg.
2142 Currently, in some rare cases, variables can have DECL_RTL values
2143 which look like (MEM (REG pseudo-reg#)). These cases are due to
2144 bugs elsewhere in the compiler. We treat such cases
2145 as if the variable(s) in question had been optimized out of existence.
2147 Note that in all cases where we wish to express the fact that a
2148 variable has been optimized out of existence, we do not simply
2149 suppress the generation of the entire location attribute because
2150 the absence of a location attribute in certain kinds of DIEs is
2151 used to indicate something else entirely... i.e. that the DIE
2152 represents an object declaration, but not a definition. So saith
2156 if (! is_pseudo_reg (rtl)
2157 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2158 output_loc_descriptor (rtl);
2160 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2163 /* Output the specialized form of location attribute used for data members
2164 of struct and union types.
2166 In the special case of a FIELD_DECL node which represents a bit-field,
2167 the "offset" part of this special location descriptor must indicate the
2168 distance in bytes from the lowest-addressed byte of the containing
2169 struct or union type to the lowest-addressed byte of the "containing
2170 object" for the bit-field. (See the `field_byte_offset' function above.)
2172 For any given bit-field, the "containing object" is a hypothetical
2173 object (of some integral or enum type) within which the given bit-field
2174 lives. The type of this hypothetical "containing object" is always the
2175 same as the declared type of the individual bit-field itself (for GCC
2176 anyway... the DWARF spec doesn't actually mandate this).
2178 Note that it is the size (in bytes) of the hypothetical "containing
2179 object" which will be given in the AT_byte_size attribute for this
2180 bit-field. (See the `byte_size_attribute' function below.) It is
2181 also used when calculating the value of the AT_bit_offset attribute.
2182 (See the `bit_offset_attribute' function below.) */
2185 data_member_location_attribute (t)
2188 register unsigned object_offset_in_bytes;
2189 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2190 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2192 if (TREE_CODE (t) == TREE_VEC)
2193 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2195 object_offset_in_bytes = field_byte_offset (t);
2197 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2198 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2199 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2200 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2201 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2202 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2203 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2204 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2205 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2208 /* Output an AT_const_value attribute for a variable or a parameter which
2209 does not have a "location" either in memory or in a register. These
2210 things can arise in GNU C when a constant is passed as an actual
2211 parameter to an inlined function. They can also arise in C++ where
2212 declared constants do not necessarily get memory "homes". */
2215 const_value_attribute (rtl)
2218 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2219 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2221 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2222 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2223 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2224 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2225 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2227 switch (GET_CODE (rtl))
2230 /* Note that a CONST_INT rtx could represent either an integer or
2231 a floating-point constant. A CONST_INT is used whenever the
2232 constant will fit into a single word. In all such cases, the
2233 original mode of the constant value is wiped out, and the
2234 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2235 precise mode information for these constants, we always just
2236 output them using 4 bytes. */
2238 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2242 /* Note that a CONST_DOUBLE rtx could represent either an integer
2243 or a floating-point constant. A CONST_DOUBLE is used whenever
2244 the constant requires more than one word in order to be adequately
2245 represented. In all such cases, the original mode of the constant
2246 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2247 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2249 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2250 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2251 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2255 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2261 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2265 /* In cases where an inlined instance of an inline function is passed
2266 the address of an `auto' variable (which is local to the caller)
2267 we can get a situation where the DECL_RTL of the artificial
2268 local variable (for the inlining) which acts as a stand-in for
2269 the corresponding formal parameter (of the inline function)
2270 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2271 This is not exactly a compile-time constant expression, but it
2272 isn't the address of the (artificial) local variable either.
2273 Rather, it represents the *value* which the artificial local
2274 variable always has during its lifetime. We currently have no
2275 way to represent such quasi-constant values in Dwarf, so for now
2276 we just punt and generate an AT_const_value attribute with form
2277 FORM_BLOCK4 and a length of zero. */
2281 abort (); /* No other kinds of rtx should be possible here. */
2284 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2287 /* Generate *either* an AT_location attribute or else an AT_const_value
2288 data attribute for a variable or a parameter. We generate the
2289 AT_const_value attribute only in those cases where the given
2290 variable or parameter does not have a true "location" either in
2291 memory or in a register. This can happen (for example) when a
2292 constant is passed as an actual argument in a call to an inline
2293 function. (It's possible that these things can crop up in other
2294 ways also.) Note that one type of constant value which can be
2295 passed into an inlined function is a constant pointer. This can
2296 happen for example if an actual argument in an inlined function
2297 call evaluates to a compile-time constant address. */
2300 location_or_const_value_attribute (decl)
2305 if (TREE_CODE (decl) == ERROR_MARK)
2308 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2310 /* Should never happen. */
2315 /* Here we have to decide where we are going to say the parameter "lives"
2316 (as far as the debugger is concerned). We only have a couple of choices.
2317 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2318 normally indicates where the parameter lives during most of the activa-
2319 tion of the function. If optimization is enabled however, this could
2320 be either NULL or else a pseudo-reg. Both of those cases indicate that
2321 the parameter doesn't really live anywhere (as far as the code generation
2322 parts of GCC are concerned) during most of the function's activation.
2323 That will happen (for example) if the parameter is never referenced
2324 within the function.
2326 We could just generate a location descriptor here for all non-NULL
2327 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2328 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2329 cases where DECL_RTL is NULL or is a pseudo-reg.
2331 Note however that we can only get away with using DECL_INCOMING_RTL as
2332 a backup substitute for DECL_RTL in certain limited cases. In cases
2333 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2334 we can be sure that the parameter was passed using the same type as it
2335 is declared to have within the function, and that its DECL_INCOMING_RTL
2336 points us to a place where a value of that type is passed. In cases
2337 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2338 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2339 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2340 points us to a value of some type which is *different* from the type
2341 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2342 to generate a location attribute in such cases, the debugger would
2343 end up (for example) trying to fetch a `float' from a place which
2344 actually contains the first part of a `double'. That would lead to
2345 really incorrect and confusing output at debug-time, and we don't
2346 want that now do we?
2348 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2349 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2350 couple of cute exceptions however. On little-endian machines we can
2351 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2352 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2353 an integral type which is smaller than TREE_TYPE(decl). These cases
2354 arise when (on a little-endian machine) a non-prototyped function has
2355 a parameter declared to be of type `short' or `char'. In such cases,
2356 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2357 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2358 passed `int' value. If the debugger then uses that address to fetch a
2359 `short' or a `char' (on a little-endian machine) the result will be the
2360 correct data, so we allow for such exceptional cases below.
2362 Note that our goal here is to describe the place where the given formal
2363 parameter lives during most of the function's activation (i.e. between
2364 the end of the prologue and the start of the epilogue). We'll do that
2365 as best as we can. Note however that if the given formal parameter is
2366 modified sometime during the execution of the function, then a stack
2367 backtrace (at debug-time) will show the function as having been called
2368 with the *new* value rather than the value which was originally passed
2369 in. This happens rarely enough that it is not a major problem, but it
2370 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2371 may generate two additional attributes for any given TAG_formal_parameter
2372 DIE which will describe the "passed type" and the "passed location" for
2373 the given formal parameter in addition to the attributes we now generate
2374 to indicate the "declared type" and the "active location" for each
2375 parameter. This additional set of attributes could be used by debuggers
2376 for stack backtraces.
2378 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2379 can be NULL also. This happens (for example) for inlined-instances of
2380 inline function formal parameters which are never referenced. This really
2381 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2382 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2383 these values for inlined instances of inline function parameters, so
2384 when we see such cases, we are just out-of-luck for the time
2385 being (until integrate.c gets fixed).
2388 /* Use DECL_RTL as the "location" unless we find something better. */
2389 rtl = DECL_RTL (decl);
2391 if (TREE_CODE (decl) == PARM_DECL)
2392 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2394 /* This decl represents a formal parameter which was optimized out. */
2395 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2396 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2398 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2399 *all* cases where (rtl == NULL_RTX) just below. */
2401 if (declared_type == passed_type)
2402 rtl = DECL_INCOMING_RTL (decl);
2403 else if (! BYTES_BIG_ENDIAN)
2404 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2405 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2406 rtl = DECL_INCOMING_RTL (decl);
2409 if (rtl == NULL_RTX)
2412 rtl = eliminate_regs (rtl, 0, NULL_RTX, 0);
2413 #ifdef LEAF_REG_REMAP
2415 leaf_renumber_regs_insn (rtl);
2418 switch (GET_CODE (rtl))
2421 /* The address of a variable that was optimized away; don't emit
2431 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2432 const_value_attribute (rtl);
2438 location_attribute (rtl);
2442 /* ??? CONCAT is used for complex variables, which may have the real
2443 part stored in one place and the imag part stored somewhere else.
2444 DWARF1 has no way to describe a variable that lives in two different
2445 places, so we just describe where the first part lives, and hope that
2446 the second part is stored after it. */
2447 location_attribute (XEXP (rtl, 0));
2451 abort (); /* Should never happen. */
2455 /* Generate an AT_name attribute given some string value to be included as
2456 the value of the attribute. */
2459 name_attribute (name_string)
2460 register char *name_string;
2462 if (name_string && *name_string)
2464 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2465 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2470 fund_type_attribute (ft_code)
2471 register unsigned ft_code;
2473 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2474 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2478 mod_fund_type_attribute (type, decl_const, decl_volatile)
2480 register int decl_const;
2481 register int decl_volatile;
2483 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2484 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2486 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2487 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2488 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2489 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2490 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2491 write_modifier_bytes (type, decl_const, decl_volatile);
2492 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2493 fundamental_type_code (root_type (type)));
2494 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2498 user_def_type_attribute (type)
2501 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2503 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2504 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2505 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2509 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2511 register int decl_const;
2512 register int decl_volatile;
2514 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2515 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2516 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2518 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2519 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2520 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2521 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2522 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2523 write_modifier_bytes (type, decl_const, decl_volatile);
2524 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2525 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2526 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2529 #ifdef USE_ORDERING_ATTRIBUTE
2531 ordering_attribute (ordering)
2532 register unsigned ordering;
2534 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2535 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2537 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2539 /* Note that the block of subscript information for an array type also
2540 includes information about the element type of type given array type. */
2543 subscript_data_attribute (type)
2546 register unsigned dimension_number;
2547 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2548 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2550 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2551 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2552 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2553 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2554 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2556 /* The GNU compilers represent multidimensional array types as sequences
2557 of one dimensional array types whose element types are themselves array
2558 types. Here we squish that down, so that each multidimensional array
2559 type gets only one array_type DIE in the Dwarf debugging info. The
2560 draft Dwarf specification say that we are allowed to do this kind
2561 of compression in C (because there is no difference between an
2562 array or arrays and a multidimensional array in C) but for other
2563 source languages (e.g. Ada) we probably shouldn't do this. */
2565 for (dimension_number = 0;
2566 TREE_CODE (type) == ARRAY_TYPE;
2567 type = TREE_TYPE (type), dimension_number++)
2569 register tree domain = TYPE_DOMAIN (type);
2571 /* Arrays come in three flavors. Unspecified bounds, fixed
2572 bounds, and (in GNU C only) variable bounds. Handle all
2573 three forms here. */
2577 /* We have an array type with specified bounds. */
2579 register tree lower = TYPE_MIN_VALUE (domain);
2580 register tree upper = TYPE_MAX_VALUE (domain);
2582 /* Handle only fundamental types as index types for now. */
2584 if (! type_is_fundamental (domain))
2587 /* Output the representation format byte for this dimension. */
2589 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2591 TREE_CODE (lower) == INTEGER_CST,
2592 TREE_CODE (upper) == INTEGER_CST));
2594 /* Output the index type for this dimension. */
2596 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2597 fundamental_type_code (domain));
2599 /* Output the representation for the lower bound. */
2601 output_bound_representation (lower, dimension_number, 'l');
2603 /* Output the representation for the upper bound. */
2605 output_bound_representation (upper, dimension_number, 'u');
2609 /* We have an array type with an unspecified length. For C and
2610 C++ we can assume that this really means that (a) the index
2611 type is an integral type, and (b) the lower bound is zero.
2612 Note that Dwarf defines the representation of an unspecified
2613 (upper) bound as being a zero-length location description. */
2615 /* Output the array-bounds format byte. */
2617 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2619 /* Output the (assumed) index type. */
2621 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2623 /* Output the (assumed) lower bound (constant) value. */
2625 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2627 /* Output the (empty) location description for the upper bound. */
2629 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2633 /* Output the prefix byte that says that the element type is coming up. */
2635 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2637 /* Output a representation of the type of the elements of this array type. */
2639 type_attribute (type, 0, 0);
2641 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2645 byte_size_attribute (tree_node)
2646 register tree tree_node;
2648 register unsigned size;
2650 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2651 switch (TREE_CODE (tree_node))
2660 case QUAL_UNION_TYPE:
2661 size = int_size_in_bytes (tree_node);
2665 /* For a data member of a struct or union, the AT_byte_size is
2666 generally given as the number of bytes normally allocated for
2667 an object of the *declared* type of the member itself. This
2668 is true even for bit-fields. */
2669 size = simple_type_size_in_bits (field_type (tree_node))
2673 /* This goes with the hack for case ARRAY_TYPE in output_type() since
2674 the Chill front end represents strings using ARRAY_TYPE. */
2677 /* The lower bound is zero, so the length is the upper bound + 1. */
2678 register tree upper_bound;
2679 upper_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (tree_node));
2680 size = (unsigned) TREE_INT_CST_LOW (upper_bound) + 1;
2688 /* Note that `size' might be -1 when we get to this point. If it
2689 is, that indicates that the byte size of the entity in question
2690 is variable. We have no good way of expressing this fact in Dwarf
2691 at the present time, so just let the -1 pass on through. */
2693 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2696 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2697 which specifies the distance in bits from the highest order bit of the
2698 "containing object" for the bit-field to the highest order bit of the
2701 For any given bit-field, the "containing object" is a hypothetical
2702 object (of some integral or enum type) within which the given bit-field
2703 lives. The type of this hypothetical "containing object" is always the
2704 same as the declared type of the individual bit-field itself.
2706 The determination of the exact location of the "containing object" for
2707 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2710 Note that it is the size (in bytes) of the hypothetical "containing
2711 object" which will be given in the AT_byte_size attribute for this
2712 bit-field. (See `byte_size_attribute' above.) */
2715 bit_offset_attribute (decl)
2718 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2719 register tree type = DECL_BIT_FIELD_TYPE (decl);
2720 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2721 register unsigned bitpos_int;
2722 register unsigned highest_order_object_bit_offset;
2723 register unsigned highest_order_field_bit_offset;
2724 register unsigned bit_offset;
2726 /* Must be a bit field. */
2728 || TREE_CODE (decl) != FIELD_DECL)
2731 /* We can't yet handle bit-fields whose offsets are variable, so if we
2732 encounter such things, just return without generating any attribute
2735 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2737 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2739 /* Note that the bit offset is always the distance (in bits) from the
2740 highest-order bit of the "containing object" to the highest-order
2741 bit of the bit-field itself. Since the "high-order end" of any
2742 object or field is different on big-endian and little-endian machines,
2743 the computation below must take account of these differences. */
2745 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2746 highest_order_field_bit_offset = bitpos_int;
2748 if (! BYTES_BIG_ENDIAN)
2750 highest_order_field_bit_offset
2751 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2753 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2758 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2759 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2761 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2762 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2765 /* For a FIELD_DECL node which represents a bit field, output an attribute
2766 which specifies the length in bits of the given field. */
2769 bit_size_attribute (decl)
2772 /* Must be a field and a bit field. */
2773 if (TREE_CODE (decl) != FIELD_DECL
2774 || ! DECL_BIT_FIELD_TYPE (decl))
2777 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2778 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2779 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2782 /* The following routine outputs the `element_list' attribute for enumeration
2783 type DIEs. The element_lits attribute includes the names and values of
2784 all of the enumeration constants associated with the given enumeration
2788 element_list_attribute (element)
2789 register tree element;
2791 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2792 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2794 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2795 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2796 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2797 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2798 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2800 /* Here we output a list of value/name pairs for each enumeration constant
2801 defined for this enumeration type (as required), but we do it in REVERSE
2802 order. The order is the one required by the draft #5 Dwarf specification
2803 published by the UI/PLSIG. */
2805 output_enumeral_list (element); /* Recursively output the whole list. */
2807 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2810 /* Generate an AT_stmt_list attribute. These are normally present only in
2811 DIEs with a TAG_compile_unit tag. */
2814 stmt_list_attribute (label)
2815 register char *label;
2817 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2818 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2819 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2822 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2823 for a subroutine DIE. */
2826 low_pc_attribute (asm_low_label)
2827 register char *asm_low_label;
2829 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2830 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2833 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2837 high_pc_attribute (asm_high_label)
2838 register char *asm_high_label;
2840 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2841 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2844 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2847 body_begin_attribute (asm_begin_label)
2848 register char *asm_begin_label;
2850 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2851 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2854 /* Generate an AT_body_end attribute for a subroutine DIE. */
2857 body_end_attribute (asm_end_label)
2858 register char *asm_end_label;
2860 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2861 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2864 /* Generate an AT_language attribute given a LANG value. These attributes
2865 are used only within TAG_compile_unit DIEs. */
2868 language_attribute (language_code)
2869 register unsigned language_code;
2871 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2872 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2876 member_attribute (context)
2877 register tree context;
2879 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2881 /* Generate this attribute only for members in C++. */
2883 if (context != NULL && is_tagged_type (context))
2885 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2886 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2887 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2892 string_length_attribute (upper_bound)
2893 register tree upper_bound;
2895 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2896 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2898 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2899 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2900 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2901 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2902 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2903 output_bound_representation (upper_bound, 0, 'u');
2904 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2908 comp_dir_attribute (dirname)
2909 register char *dirname;
2911 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2912 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2916 sf_names_attribute (sf_names_start_label)
2917 register char *sf_names_start_label;
2919 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2920 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2921 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2925 src_info_attribute (src_info_start_label)
2926 register char *src_info_start_label;
2928 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2929 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2930 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2934 mac_info_attribute (mac_info_start_label)
2935 register char *mac_info_start_label;
2937 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2938 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2939 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2943 prototyped_attribute (func_type)
2944 register tree func_type;
2946 if ((strcmp (language_string, "GNU C") == 0)
2947 && (TYPE_ARG_TYPES (func_type) != NULL))
2949 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2950 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2955 producer_attribute (producer)
2956 register char *producer;
2958 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2959 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2963 inline_attribute (decl)
2966 if (DECL_INLINE (decl))
2968 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2969 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2974 containing_type_attribute (containing_type)
2975 register tree containing_type;
2977 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2979 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2980 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2981 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2985 abstract_origin_attribute (origin)
2986 register tree origin;
2988 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2990 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2991 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2994 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2998 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3002 abort (); /* Should never happen. */
3005 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3008 #ifdef DWARF_DECL_COORDINATES
3010 src_coords_attribute (src_fileno, src_lineno)
3011 register unsigned src_fileno;
3012 register unsigned src_lineno;
3014 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3015 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3016 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3018 #endif /* defined(DWARF_DECL_COORDINATES) */
3021 pure_or_virtual_attribute (func_decl)
3022 register tree func_decl;
3024 if (DECL_VIRTUAL_P (func_decl))
3026 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3027 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3028 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3031 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3032 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3036 /************************* end of attributes *****************************/
3038 /********************* utility routines for DIEs *************************/
3040 /* Output an AT_name attribute and an AT_src_coords attribute for the
3041 given decl, but only if it actually has a name. */
3044 name_and_src_coords_attributes (decl)
3047 register tree decl_name = DECL_NAME (decl);
3049 if (decl_name && IDENTIFIER_POINTER (decl_name))
3051 name_attribute (IDENTIFIER_POINTER (decl_name));
3052 #ifdef DWARF_DECL_COORDINATES
3054 register unsigned file_index;
3056 /* This is annoying, but we have to pop out of the .debug section
3057 for a moment while we call `lookup_filename' because calling it
3058 may cause a temporary switch into the .debug_sfnames section and
3059 most svr4 assemblers are not smart enough be be able to nest
3060 section switches to any depth greater than one. Note that we
3061 also can't skirt this issue by delaying all output to the
3062 .debug_sfnames section unit the end of compilation because that
3063 would cause us to have inter-section forward references and
3064 Fred Fish sez that m68k/svr4 assemblers botch those. */
3066 ASM_OUTPUT_POP_SECTION (asm_out_file);
3067 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3068 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3070 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3072 #endif /* defined(DWARF_DECL_COORDINATES) */
3076 /* Many forms of DIEs contain a "type description" part. The following
3077 routine writes out these "type descriptor" parts. */
3080 type_attribute (type, decl_const, decl_volatile)
3082 register int decl_const;
3083 register int decl_volatile;
3085 register enum tree_code code = TREE_CODE (type);
3086 register int root_type_modified;
3088 if (code == ERROR_MARK)
3091 /* Handle a special case. For functions whose return type is void,
3092 we generate *no* type attribute. (Note that no object may have
3093 type `void', so this only applies to function return types. */
3095 if (code == VOID_TYPE)
3098 /* If this is a subtype, find the underlying type. Eventually,
3099 this should write out the appropriate subtype info. */
3100 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3101 && TREE_TYPE (type) != 0)
3102 type = TREE_TYPE (type), code = TREE_CODE (type);
3104 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3105 || decl_const || decl_volatile
3106 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3108 if (type_is_fundamental (root_type (type)))
3109 if (root_type_modified)
3110 mod_fund_type_attribute (type, decl_const, decl_volatile);
3112 fund_type_attribute (fundamental_type_code (type));
3114 if (root_type_modified)
3115 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3117 /* We have to get the type_main_variant here (and pass that to the
3118 `user_def_type_attribute' routine) because the ..._TYPE node we
3119 have might simply be a *copy* of some original type node (where
3120 the copy was created to help us keep track of typedef names)
3121 and that copy might have a different TYPE_UID from the original
3122 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3123 is labeling a given type DIE for future reference, it always and
3124 only creates labels for DIEs representing *main variants*, and it
3125 never even knows about non-main-variants.) */
3126 user_def_type_attribute (type_main_variant (type));
3129 /* Given a tree pointer to a struct, class, union, or enum type node, return
3130 a pointer to the (string) tag name for the given type, or zero if the
3131 type was declared without a tag. */
3137 register char *name = 0;
3139 if (TYPE_NAME (type) != 0)
3141 register tree t = 0;
3143 /* Find the IDENTIFIER_NODE for the type name. */
3144 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3145 t = TYPE_NAME (type);
3147 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3148 a TYPE_DECL node, regardless of whether or not a `typedef' was
3150 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3151 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3152 t = DECL_NAME (TYPE_NAME (type));
3154 /* Now get the name as a string, or invent one. */
3156 name = IDENTIFIER_POINTER (t);
3159 return (name == 0 || *name == '\0') ? 0 : name;
3165 /* Start by checking if the pending_sibling_stack needs to be expanded.
3166 If necessary, expand it. */
3168 if (pending_siblings == pending_siblings_allocated)
3170 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3171 pending_sibling_stack
3172 = (unsigned *) xrealloc (pending_sibling_stack,
3173 pending_siblings_allocated * sizeof(unsigned));
3177 NEXT_DIE_NUM = next_unused_dienum++;
3180 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3190 member_declared_type (member)
3191 register tree member;
3193 return (DECL_BIT_FIELD_TYPE (member))
3194 ? DECL_BIT_FIELD_TYPE (member)
3195 : TREE_TYPE (member);
3198 /* Get the function's label, as described by its RTL.
3199 This may be different from the DECL_NAME name used
3200 in the source file. */
3203 function_start_label (decl)
3209 x = DECL_RTL (decl);
3210 if (GET_CODE (x) != MEM)
3213 if (GET_CODE (x) != SYMBOL_REF)
3215 fnname = XSTR (x, 0);
3220 /******************************* DIEs ************************************/
3222 /* Output routines for individual types of DIEs. */
3224 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3227 output_array_type_die (arg)
3230 register tree type = arg;
3232 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3233 sibling_attribute ();
3234 equate_type_number_to_die_number (type);
3235 member_attribute (TYPE_CONTEXT (type));
3237 /* I believe that we can default the array ordering. SDB will probably
3238 do the right things even if AT_ordering is not present. It's not
3239 even an issue until we start to get into multidimensional arrays
3240 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3241 dimensional arrays, then we'll have to put the AT_ordering attribute
3242 back in. (But if and when we find out that we need to put these in,
3243 we will only do so for multidimensional arrays. After all, we don't
3244 want to waste space in the .debug section now do we?) */
3246 #ifdef USE_ORDERING_ATTRIBUTE
3247 ordering_attribute (ORD_row_major);
3248 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3250 subscript_data_attribute (type);
3254 output_set_type_die (arg)
3257 register tree type = arg;
3259 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3260 sibling_attribute ();
3261 equate_type_number_to_die_number (type);
3262 member_attribute (TYPE_CONTEXT (type));
3263 type_attribute (TREE_TYPE (type), 0, 0);
3267 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3270 output_entry_point_die (arg)
3273 register tree decl = arg;
3274 register tree origin = decl_ultimate_origin (decl);
3276 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3277 sibling_attribute ();
3280 abstract_origin_attribute (origin);
3283 name_and_src_coords_attributes (decl);
3284 member_attribute (DECL_CONTEXT (decl));
3285 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3287 if (DECL_ABSTRACT (decl))
3288 equate_decl_number_to_die_number (decl);
3290 low_pc_attribute (function_start_label (decl));
3294 /* Output a DIE to represent an inlined instance of an enumeration type. */
3297 output_inlined_enumeration_type_die (arg)
3300 register tree type = arg;
3302 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3303 sibling_attribute ();
3304 if (!TREE_ASM_WRITTEN (type))
3306 abstract_origin_attribute (type);
3309 /* Output a DIE to represent an inlined instance of a structure type. */
3312 output_inlined_structure_type_die (arg)
3315 register tree type = arg;
3317 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3318 sibling_attribute ();
3319 if (!TREE_ASM_WRITTEN (type))
3321 abstract_origin_attribute (type);
3324 /* Output a DIE to represent an inlined instance of a union type. */
3327 output_inlined_union_type_die (arg)
3330 register tree type = arg;
3332 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3333 sibling_attribute ();
3334 if (!TREE_ASM_WRITTEN (type))
3336 abstract_origin_attribute (type);
3339 /* Output a DIE to represent an enumeration type. Note that these DIEs
3340 include all of the information about the enumeration values also.
3341 This information is encoded into the element_list attribute. */
3344 output_enumeration_type_die (arg)
3347 register tree type = arg;
3349 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3350 sibling_attribute ();
3351 equate_type_number_to_die_number (type);
3352 name_attribute (type_tag (type));
3353 member_attribute (TYPE_CONTEXT (type));
3355 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3356 given enum type is incomplete, do not generate the AT_byte_size
3357 attribute or the AT_element_list attribute. */
3359 if (TYPE_SIZE (type))
3361 byte_size_attribute (type);
3362 element_list_attribute (TYPE_FIELDS (type));
3366 /* Output a DIE to represent either a real live formal parameter decl or
3367 to represent just the type of some formal parameter position in some
3370 Note that this routine is a bit unusual because its argument may be
3371 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3372 represents an inlining of some PARM_DECL) or else some sort of a
3373 ..._TYPE node. If it's the former then this function is being called
3374 to output a DIE to represent a formal parameter object (or some inlining
3375 thereof). If it's the latter, then this function is only being called
3376 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3377 formal argument type of some subprogram type. */
3380 output_formal_parameter_die (arg)
3383 register tree node = arg;
3385 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3386 sibling_attribute ();
3388 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3390 case 'd': /* We were called with some kind of a ..._DECL node. */
3392 register tree origin = decl_ultimate_origin (node);
3395 abstract_origin_attribute (origin);
3398 name_and_src_coords_attributes (node);
3399 type_attribute (TREE_TYPE (node),
3400 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3402 if (DECL_ABSTRACT (node))
3403 equate_decl_number_to_die_number (node);
3405 location_or_const_value_attribute (node);
3409 case 't': /* We were called with some kind of a ..._TYPE node. */
3410 type_attribute (node, 0, 0);
3414 abort (); /* Should never happen. */
3418 /* Output a DIE to represent a declared function (either file-scope
3419 or block-local) which has "external linkage" (according to ANSI-C). */
3422 output_global_subroutine_die (arg)
3425 register tree decl = arg;
3426 register tree origin = decl_ultimate_origin (decl);
3428 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3429 sibling_attribute ();
3432 abstract_origin_attribute (origin);
3435 register tree type = TREE_TYPE (decl);
3437 name_and_src_coords_attributes (decl);
3438 inline_attribute (decl);
3439 prototyped_attribute (type);
3440 member_attribute (DECL_CONTEXT (decl));
3441 type_attribute (TREE_TYPE (type), 0, 0);
3442 pure_or_virtual_attribute (decl);
3444 if (DECL_ABSTRACT (decl))
3445 equate_decl_number_to_die_number (decl);
3448 if (! DECL_EXTERNAL (decl) && ! in_class
3449 && decl == current_function_decl)
3451 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3453 low_pc_attribute (function_start_label (decl));
3454 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3455 high_pc_attribute (label);
3456 if (use_gnu_debug_info_extensions)
3458 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3459 body_begin_attribute (label);
3460 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3461 body_end_attribute (label);
3467 /* Output a DIE to represent a declared data object (either file-scope
3468 or block-local) which has "external linkage" (according to ANSI-C). */
3471 output_global_variable_die (arg)
3474 register tree decl = arg;
3475 register tree origin = decl_ultimate_origin (decl);
3477 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3478 sibling_attribute ();
3480 abstract_origin_attribute (origin);
3483 name_and_src_coords_attributes (decl);
3484 member_attribute (DECL_CONTEXT (decl));
3485 type_attribute (TREE_TYPE (decl),
3486 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3488 if (DECL_ABSTRACT (decl))
3489 equate_decl_number_to_die_number (decl);
3492 if (! DECL_EXTERNAL (decl) && ! in_class
3493 && current_function_decl == decl_function_context (decl))
3494 location_or_const_value_attribute (decl);
3499 output_label_die (arg)
3502 register tree decl = arg;
3503 register tree origin = decl_ultimate_origin (decl);
3505 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3506 sibling_attribute ();
3508 abstract_origin_attribute (origin);
3510 name_and_src_coords_attributes (decl);
3511 if (DECL_ABSTRACT (decl))
3512 equate_decl_number_to_die_number (decl);
3515 register rtx insn = DECL_RTL (decl);
3517 if (GET_CODE (insn) == CODE_LABEL)
3519 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3521 /* When optimization is enabled (via -O) some parts of the compiler
3522 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3523 represent source-level labels which were explicitly declared by
3524 the user. This really shouldn't be happening though, so catch
3525 it if it ever does happen. */
3527 if (INSN_DELETED_P (insn))
3528 abort (); /* Should never happen. */
3530 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3531 (unsigned) INSN_UID (insn));
3532 low_pc_attribute (label);
3538 output_lexical_block_die (arg)
3541 register tree stmt = arg;
3543 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3544 sibling_attribute ();
3546 if (! BLOCK_ABSTRACT (stmt))
3548 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3549 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3551 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3552 low_pc_attribute (begin_label);
3553 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3554 high_pc_attribute (end_label);
3559 output_inlined_subroutine_die (arg)
3562 register tree stmt = arg;
3564 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3565 sibling_attribute ();
3567 abstract_origin_attribute (block_ultimate_origin (stmt));
3568 if (! BLOCK_ABSTRACT (stmt))
3570 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3571 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3573 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3574 low_pc_attribute (begin_label);
3575 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3576 high_pc_attribute (end_label);
3580 /* Output a DIE to represent a declared data object (either file-scope
3581 or block-local) which has "internal linkage" (according to ANSI-C). */
3584 output_local_variable_die (arg)
3587 register tree decl = arg;
3588 register tree origin = decl_ultimate_origin (decl);
3590 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3591 sibling_attribute ();
3593 abstract_origin_attribute (origin);
3596 name_and_src_coords_attributes (decl);
3597 member_attribute (DECL_CONTEXT (decl));
3598 type_attribute (TREE_TYPE (decl),
3599 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3601 if (DECL_ABSTRACT (decl))
3602 equate_decl_number_to_die_number (decl);
3604 location_or_const_value_attribute (decl);
3608 output_member_die (arg)
3611 register tree decl = arg;
3613 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3614 sibling_attribute ();
3615 name_and_src_coords_attributes (decl);
3616 member_attribute (DECL_CONTEXT (decl));
3617 type_attribute (member_declared_type (decl),
3618 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3619 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3621 byte_size_attribute (decl);
3622 bit_size_attribute (decl);
3623 bit_offset_attribute (decl);
3625 data_member_location_attribute (decl);
3629 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3630 modified types instead.
3632 We keep this code here just in case these types of DIEs may be
3633 needed to represent certain things in other languages (e.g. Pascal)
3637 output_pointer_type_die (arg)
3640 register tree type = arg;
3642 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3643 sibling_attribute ();
3644 equate_type_number_to_die_number (type);
3645 member_attribute (TYPE_CONTEXT (type));
3646 type_attribute (TREE_TYPE (type), 0, 0);
3650 output_reference_type_die (arg)
3653 register tree type = arg;
3655 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3656 sibling_attribute ();
3657 equate_type_number_to_die_number (type);
3658 member_attribute (TYPE_CONTEXT (type));
3659 type_attribute (TREE_TYPE (type), 0, 0);
3664 output_ptr_to_mbr_type_die (arg)
3667 register tree type = arg;
3669 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3670 sibling_attribute ();
3671 equate_type_number_to_die_number (type);
3672 member_attribute (TYPE_CONTEXT (type));
3673 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3674 type_attribute (TREE_TYPE (type), 0, 0);
3678 output_compile_unit_die (arg)
3681 register char *main_input_filename = arg;
3683 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3684 sibling_attribute ();
3686 name_attribute (main_input_filename);
3691 sprintf (producer, "%s %s", language_string, version_string);
3692 producer_attribute (producer);
3695 if (strcmp (language_string, "GNU C++") == 0)
3696 language_attribute (LANG_C_PLUS_PLUS);
3697 else if (strcmp (language_string, "GNU Ada") == 0)
3698 language_attribute (LANG_ADA83);
3699 else if (strcmp (language_string, "GNU F77") == 0)
3700 language_attribute (LANG_FORTRAN77);
3701 else if (strcmp (language_string, "GNU Pascal") == 0)
3702 language_attribute (LANG_PASCAL83);
3703 else if (flag_traditional)
3704 language_attribute (LANG_C);
3706 language_attribute (LANG_C89);
3707 low_pc_attribute (TEXT_BEGIN_LABEL);
3708 high_pc_attribute (TEXT_END_LABEL);
3709 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3710 stmt_list_attribute (LINE_BEGIN_LABEL);
3711 last_filename = xstrdup (main_input_filename);
3714 char *wd = getpwd ();
3716 comp_dir_attribute (wd);
3719 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3721 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3722 src_info_attribute (SRCINFO_BEGIN_LABEL);
3723 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3724 mac_info_attribute (MACINFO_BEGIN_LABEL);
3729 output_string_type_die (arg)
3732 register tree type = arg;
3734 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3735 sibling_attribute ();
3736 equate_type_number_to_die_number (type);
3737 member_attribute (TYPE_CONTEXT (type));
3738 /* this is a fixed length string */
3739 byte_size_attribute (type);
3743 output_inheritance_die (arg)
3746 register tree binfo = arg;
3748 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3749 sibling_attribute ();
3750 type_attribute (BINFO_TYPE (binfo), 0, 0);
3751 data_member_location_attribute (binfo);
3752 if (TREE_VIA_VIRTUAL (binfo))
3754 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3755 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3757 if (TREE_VIA_PUBLIC (binfo))
3759 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3760 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3762 else if (TREE_VIA_PROTECTED (binfo))
3764 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3765 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3770 output_structure_type_die (arg)
3773 register tree type = arg;
3775 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3776 sibling_attribute ();
3777 equate_type_number_to_die_number (type);
3778 name_attribute (type_tag (type));
3779 member_attribute (TYPE_CONTEXT (type));
3781 /* If this type has been completed, then give it a byte_size attribute
3782 and prepare to give a list of members. Otherwise, don't do either of
3783 these things. In the latter case, we will not be generating a list
3784 of members (since we don't have any idea what they might be for an
3785 incomplete type). */
3787 if (TYPE_SIZE (type))
3790 byte_size_attribute (type);
3794 /* Output a DIE to represent a declared function (either file-scope
3795 or block-local) which has "internal linkage" (according to ANSI-C). */
3798 output_local_subroutine_die (arg)
3801 register tree decl = arg;
3802 register tree origin = decl_ultimate_origin (decl);
3804 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3805 sibling_attribute ();
3808 abstract_origin_attribute (origin);
3811 register tree type = TREE_TYPE (decl);
3813 name_and_src_coords_attributes (decl);
3814 inline_attribute (decl);
3815 prototyped_attribute (type);
3816 member_attribute (DECL_CONTEXT (decl));
3817 type_attribute (TREE_TYPE (type), 0, 0);
3818 pure_or_virtual_attribute (decl);
3820 if (DECL_ABSTRACT (decl))
3821 equate_decl_number_to_die_number (decl);
3824 /* Avoid getting screwed up in cases where a function was declared
3825 static but where no definition was ever given for it. */
3827 if (TREE_ASM_WRITTEN (decl))
3829 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3830 low_pc_attribute (function_start_label (decl));
3831 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3832 high_pc_attribute (label);
3833 if (use_gnu_debug_info_extensions)
3835 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3836 body_begin_attribute (label);
3837 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3838 body_end_attribute (label);
3845 output_subroutine_type_die (arg)
3848 register tree type = arg;
3849 register tree return_type = TREE_TYPE (type);
3851 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3852 sibling_attribute ();
3854 equate_type_number_to_die_number (type);
3855 prototyped_attribute (type);
3856 member_attribute (TYPE_CONTEXT (type));
3857 type_attribute (return_type, 0, 0);
3861 output_typedef_die (arg)
3864 register tree decl = arg;
3865 register tree origin = decl_ultimate_origin (decl);
3867 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3868 sibling_attribute ();
3870 abstract_origin_attribute (origin);
3873 name_and_src_coords_attributes (decl);
3874 member_attribute (DECL_CONTEXT (decl));
3875 type_attribute (TREE_TYPE (decl),
3876 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3878 if (DECL_ABSTRACT (decl))
3879 equate_decl_number_to_die_number (decl);
3883 output_union_type_die (arg)
3886 register tree type = arg;
3888 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3889 sibling_attribute ();
3890 equate_type_number_to_die_number (type);
3891 name_attribute (type_tag (type));
3892 member_attribute (TYPE_CONTEXT (type));
3894 /* If this type has been completed, then give it a byte_size attribute
3895 and prepare to give a list of members. Otherwise, don't do either of
3896 these things. In the latter case, we will not be generating a list
3897 of members (since we don't have any idea what they might be for an
3898 incomplete type). */
3900 if (TYPE_SIZE (type))
3903 byte_size_attribute (type);
3907 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3908 at the end of an (ANSI prototyped) formal parameters list. */
3911 output_unspecified_parameters_die (arg)
3914 register tree decl_or_type = arg;
3916 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3917 sibling_attribute ();
3919 /* This kludge is here only for the sake of being compatible with what
3920 the USL CI5 C compiler does. The specification of Dwarf Version 1
3921 doesn't say that TAG_unspecified_parameters DIEs should contain any
3922 attributes other than the AT_sibling attribute, but they are certainly
3923 allowed to contain additional attributes, and the CI5 compiler
3924 generates AT_name, AT_fund_type, and AT_location attributes within
3925 TAG_unspecified_parameters DIEs which appear in the child lists for
3926 DIEs representing function definitions, so we do likewise here. */
3928 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3930 name_attribute ("...");
3931 fund_type_attribute (FT_pointer);
3932 /* location_attribute (?); */
3937 output_padded_null_die (arg)
3940 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3943 /*************************** end of DIEs *********************************/
3945 /* Generate some type of DIE. This routine generates the generic outer
3946 wrapper stuff which goes around all types of DIE's (regardless of their
3947 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3948 DIE-length word, followed by the guts of the DIE itself. After the guts
3949 of the DIE, there must always be a terminator label for the DIE. */
3952 output_die (die_specific_output_function, param)
3953 register void (*die_specific_output_function)();
3954 register void *param;
3956 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3957 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3959 current_dienum = NEXT_DIE_NUM;
3960 NEXT_DIE_NUM = next_unused_dienum;
3962 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3963 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3965 /* Write a label which will act as the name for the start of this DIE. */
3967 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3969 /* Write the DIE-length word. */
3971 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3973 /* Fill in the guts of the DIE. */
3975 next_unused_dienum++;
3976 die_specific_output_function (param);
3978 /* Write a label which will act as the name for the end of this DIE. */
3980 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3984 end_sibling_chain ()
3986 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3988 current_dienum = NEXT_DIE_NUM;
3989 NEXT_DIE_NUM = next_unused_dienum;
3991 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3993 /* Write a label which will act as the name for the start of this DIE. */
3995 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3997 /* Write the DIE-length word. */
3999 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4004 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4005 TAG_unspecified_parameters DIE) to represent the types of the formal
4006 parameters as specified in some function type specification (except
4007 for those which appear as part of a function *definition*).
4009 Note that we must be careful here to output all of the parameter
4010 DIEs *before* we output any DIEs needed to represent the types of
4011 the formal parameters. This keeps svr4 SDB happy because it
4012 (incorrectly) thinks that the first non-parameter DIE it sees ends
4013 the formal parameter list. */
4016 output_formal_types (function_or_method_type)
4017 register tree function_or_method_type;
4020 register tree formal_type = NULL;
4021 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4023 /* In the case where we are generating a formal types list for a C++
4024 non-static member function type, skip over the first thing on the
4025 TYPE_ARG_TYPES list because it only represents the type of the
4026 hidden `this pointer'. The debugger should be able to figure
4027 out (without being explicitly told) that this non-static member
4028 function type takes a `this pointer' and should be able to figure
4029 what the type of that hidden parameter is from the AT_member
4030 attribute of the parent TAG_subroutine_type DIE. */
4032 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4033 first_parm_type = TREE_CHAIN (first_parm_type);
4035 /* Make our first pass over the list of formal parameter types and output
4036 a TAG_formal_parameter DIE for each one. */
4038 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4040 formal_type = TREE_VALUE (link);
4041 if (formal_type == void_type_node)
4044 /* Output a (nameless) DIE to represent the formal parameter itself. */
4046 output_die (output_formal_parameter_die, formal_type);
4049 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4050 DIE to the end of the parameter list. */
4052 if (formal_type != void_type_node)
4053 output_die (output_unspecified_parameters_die, function_or_method_type);
4055 /* Make our second (and final) pass over the list of formal parameter types
4056 and output DIEs to represent those types (as necessary). */
4058 for (link = TYPE_ARG_TYPES (function_or_method_type);
4060 link = TREE_CHAIN (link))
4062 formal_type = TREE_VALUE (link);
4063 if (formal_type == void_type_node)
4066 output_type (formal_type, function_or_method_type);
4070 /* Remember a type in the pending_types_list. */
4076 if (pending_types == pending_types_allocated)
4078 pending_types_allocated += PENDING_TYPES_INCREMENT;
4080 = (tree *) xrealloc (pending_types_list,
4081 sizeof (tree) * pending_types_allocated);
4083 pending_types_list[pending_types++] = type;
4085 /* Mark the pending type as having been output already (even though
4086 it hasn't been). This prevents the type from being added to the
4087 pending_types_list more than once. */
4089 TREE_ASM_WRITTEN (type) = 1;
4092 /* Return non-zero if it is legitimate to output DIEs to represent a
4093 given type while we are generating the list of child DIEs for some
4094 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4096 See the comments within the function for a description of when it is
4097 considered legitimate to output DIEs for various kinds of types.
4099 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4100 or it may point to a BLOCK node (for types local to a block), or to a
4101 FUNCTION_DECL node (for types local to the heading of some function
4102 definition), or to a FUNCTION_TYPE node (for types local to the
4103 prototyped parameter list of a function type specification), or to a
4104 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4105 (in the case of C++ nested types).
4107 The `scope' parameter should likewise be NULL or should point to a
4108 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4109 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4111 This function is used only for deciding when to "pend" and when to
4112 "un-pend" types to/from the pending_types_list.
4114 Note that we sometimes make use of this "type pending" feature in a
4115 rather twisted way to temporarily delay the production of DIEs for the
4116 types of formal parameters. (We do this just to make svr4 SDB happy.)
4117 It order to delay the production of DIEs representing types of formal
4118 parameters, callers of this function supply `fake_containing_scope' as
4119 the `scope' parameter to this function. Given that fake_containing_scope
4120 is a tagged type which is *not* the containing scope for *any* other type,
4121 the desired effect is achieved, i.e. output of DIEs representing types
4122 is temporarily suspended, and any type DIEs which would have otherwise
4123 been output are instead placed onto the pending_types_list. Later on,
4124 we force these (temporarily pended) types to be output simply by calling
4125 `output_pending_types_for_scope' with an actual argument equal to the
4126 true scope of the types we temporarily pended. */
4129 type_ok_for_scope (type, scope)
4131 register tree scope;
4133 /* Tagged types (i.e. struct, union, and enum types) must always be
4134 output only in the scopes where they actually belong (or else the
4135 scoping of their own tag names and the scoping of their member
4136 names will be incorrect). Non-tagged-types on the other hand can
4137 generally be output anywhere, except that svr4 SDB really doesn't
4138 want to see them nested within struct or union types, so here we
4139 say it is always OK to immediately output any such a (non-tagged)
4140 type, so long as we are not within such a context. Note that the
4141 only kinds of non-tagged types which we will be dealing with here
4142 (for C and C++ anyway) will be array types and function types. */
4144 return is_tagged_type (type)
4145 ? (TYPE_CONTEXT (type) == scope
4146 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4147 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4148 : (scope == NULL_TREE || ! is_tagged_type (scope));
4151 /* Output any pending types (from the pending_types list) which we can output
4152 now (taking into account the scope that we are working on now).
4154 For each type output, remove the given type from the pending_types_list
4155 *before* we try to output it.
4157 Note that we have to process the list in beginning-to-end order,
4158 because the call made here to output_type may cause yet more types
4159 to be added to the end of the list, and we may have to output some
4163 output_pending_types_for_scope (containing_scope)
4164 register tree containing_scope;
4166 register unsigned i;
4168 for (i = 0; i < pending_types; )
4170 register tree type = pending_types_list[i];
4172 if (type_ok_for_scope (type, containing_scope))
4174 register tree *mover;
4175 register tree *limit;
4178 limit = &pending_types_list[pending_types];
4179 for (mover = &pending_types_list[i]; mover < limit; mover++)
4180 *mover = *(mover+1);
4182 /* Un-mark the type as having been output already (because it
4183 hasn't been, really). Then call output_type to generate a
4184 Dwarf representation of it. */
4186 TREE_ASM_WRITTEN (type) = 0;
4187 output_type (type, containing_scope);
4189 /* Don't increment the loop counter in this case because we
4190 have shifted all of the subsequent pending types down one
4191 element in the pending_types_list array. */
4199 output_type (type, containing_scope)
4201 register tree containing_scope;
4203 if (type == 0 || type == error_mark_node)
4206 /* We are going to output a DIE to represent the unqualified version of
4207 of this type (i.e. without any const or volatile qualifiers) so get
4208 the main variant (i.e. the unqualified version) of this type now. */
4210 type = type_main_variant (type);
4212 if (TREE_ASM_WRITTEN (type))
4214 if (finalizing && AGGREGATE_TYPE_P (type))
4216 register tree member;
4218 /* Some of our nested types might not have been defined when we
4219 were written out before; force them out now. */
4221 for (member = TYPE_FIELDS (type); member;
4222 member = TREE_CHAIN (member))
4223 if (TREE_CODE (member) == TYPE_DECL
4224 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4225 output_type (TREE_TYPE (member), containing_scope);
4230 /* If this is a nested type whose containing class hasn't been
4231 written out yet, writing it out will cover this one, too. */
4233 if (TYPE_CONTEXT (type)
4234 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4235 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4237 output_type (TYPE_CONTEXT (type), containing_scope);
4241 /* Don't generate any DIEs for this type now unless it is OK to do so
4242 (based upon what `type_ok_for_scope' tells us). */
4244 if (! type_ok_for_scope (type, containing_scope))
4250 switch (TREE_CODE (type))
4256 case REFERENCE_TYPE:
4257 /* Prevent infinite recursion in cases where this is a recursive
4258 type. Recursive types are possible in Ada. */
4259 TREE_ASM_WRITTEN (type) = 1;
4260 /* For these types, all that is required is that we output a DIE
4261 (or a set of DIEs) to represent the "basis" type. */
4262 output_type (TREE_TYPE (type), containing_scope);
4266 /* This code is used for C++ pointer-to-data-member types. */
4267 /* Output a description of the relevant class type. */
4268 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4269 /* Output a description of the type of the object pointed to. */
4270 output_type (TREE_TYPE (type), containing_scope);
4271 /* Now output a DIE to represent this pointer-to-data-member type
4273 output_die (output_ptr_to_mbr_type_die, type);
4277 output_type (TYPE_DOMAIN (type), containing_scope);
4278 output_die (output_set_type_die, type);
4282 output_type (TREE_TYPE (type), containing_scope);
4283 abort (); /* No way to represent these in Dwarf yet! */
4287 /* Force out return type (in case it wasn't forced out already). */
4288 output_type (TREE_TYPE (type), containing_scope);
4289 output_die (output_subroutine_type_die, type);
4290 output_formal_types (type);
4291 end_sibling_chain ();
4295 /* Force out return type (in case it wasn't forced out already). */
4296 output_type (TREE_TYPE (type), containing_scope);
4297 output_die (output_subroutine_type_die, type);
4298 output_formal_types (type);
4299 end_sibling_chain ();
4303 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4305 output_type (TREE_TYPE (type), containing_scope);
4306 output_die (output_string_type_die, type);
4310 register tree element_type;
4312 element_type = TREE_TYPE (type);
4313 while (TREE_CODE (element_type) == ARRAY_TYPE)
4314 element_type = TREE_TYPE (element_type);
4316 output_type (element_type, containing_scope);
4317 output_die (output_array_type_die, type);
4324 case QUAL_UNION_TYPE:
4326 /* For a non-file-scope tagged type, we can always go ahead and
4327 output a Dwarf description of this type right now, even if
4328 the type in question is still incomplete, because if this
4329 local type *was* ever completed anywhere within its scope,
4330 that complete definition would already have been attached to
4331 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4332 node by the time we reach this point. That's true because of the
4333 way the front-end does its processing of file-scope declarations (of
4334 functions and class types) within which other types might be
4335 nested. The C and C++ front-ends always gobble up such "local
4336 scope" things en-mass before they try to output *any* debugging
4337 information for any of the stuff contained inside them and thus,
4338 we get the benefit here of what is (in effect) a pre-resolution
4339 of forward references to tagged types in local scopes.
4341 Note however that for file-scope tagged types we cannot assume
4342 that such pre-resolution of forward references has taken place.
4343 A given file-scope tagged type may appear to be incomplete when
4344 we reach this point, but it may yet be given a full definition
4345 (at file-scope) later on during compilation. In order to avoid
4346 generating a premature (and possibly incorrect) set of Dwarf
4347 DIEs for such (as yet incomplete) file-scope tagged types, we
4348 generate nothing at all for as-yet incomplete file-scope tagged
4349 types here unless we are making our special "finalization" pass
4350 for file-scope things at the very end of compilation. At that
4351 time, we will certainly know as much about each file-scope tagged
4352 type as we are ever going to know, so at that point in time, we
4353 can safely generate correct Dwarf descriptions for these file-
4354 scope tagged types. */
4356 if (TYPE_SIZE (type) == 0
4357 && (TYPE_CONTEXT (type) == NULL
4358 || TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
4360 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4362 /* Prevent infinite recursion in cases where the type of some
4363 member of this type is expressed in terms of this type itself. */
4365 TREE_ASM_WRITTEN (type) = 1;
4367 /* Output a DIE to represent the tagged type itself. */
4369 switch (TREE_CODE (type))
4372 output_die (output_enumeration_type_die, type);
4373 return; /* a special case -- nothing left to do so just return */
4376 output_die (output_structure_type_die, type);
4380 case QUAL_UNION_TYPE:
4381 output_die (output_union_type_die, type);
4385 abort (); /* Should never happen. */
4388 /* If this is not an incomplete type, output descriptions of
4389 each of its members.
4391 Note that as we output the DIEs necessary to represent the
4392 members of this record or union type, we will also be trying
4393 to output DIEs to represent the *types* of those members.
4394 However the `output_type' function (above) will specifically
4395 avoid generating type DIEs for member types *within* the list
4396 of member DIEs for this (containing) type execpt for those
4397 types (of members) which are explicitly marked as also being
4398 members of this (containing) type themselves. The g++ front-
4399 end can force any given type to be treated as a member of some
4400 other (containing) type by setting the TYPE_CONTEXT of the
4401 given (member) type to point to the TREE node representing the
4402 appropriate (containing) type.
4405 if (TYPE_SIZE (type))
4407 /* First output info about the base classes. */
4408 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4410 register tree bases = TYPE_BINFO_BASETYPES (type);
4411 register int n_bases = TREE_VEC_LENGTH (bases);
4414 for (i = 0; i < n_bases; i++)
4415 output_die (output_inheritance_die, TREE_VEC_ELT (bases, i));
4421 register tree normal_member;
4423 /* Now output info about the data members and type members. */
4425 for (normal_member = TYPE_FIELDS (type);
4427 normal_member = TREE_CHAIN (normal_member))
4428 output_decl (normal_member, type);
4432 register tree func_member;
4434 /* Now output info about the function members (if any). */
4436 for (func_member = TYPE_METHODS (type);
4438 func_member = TREE_CHAIN (func_member))
4439 output_decl (func_member, type);
4444 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4445 scopes (at least in C++) so we must now output any nested
4446 pending types which are local just to this type. */
4448 output_pending_types_for_scope (type);
4450 end_sibling_chain (); /* Terminate member chain. */
4461 break; /* No DIEs needed for fundamental types. */
4463 case LANG_TYPE: /* No Dwarf representation currently defined. */
4470 TREE_ASM_WRITTEN (type) = 1;
4474 output_tagged_type_instantiation (type)
4477 if (type == 0 || type == error_mark_node)
4480 /* We are going to output a DIE to represent the unqualified version of
4481 of this type (i.e. without any const or volatile qualifiers) so make
4482 sure that we have the main variant (i.e. the unqualified version) of
4485 if (type != type_main_variant (type))
4488 if (!TREE_ASM_WRITTEN (type))
4491 switch (TREE_CODE (type))
4497 output_die (output_inlined_enumeration_type_die, type);
4501 output_die (output_inlined_structure_type_die, type);
4505 case QUAL_UNION_TYPE:
4506 output_die (output_inlined_union_type_die, type);
4510 abort (); /* Should never happen. */
4514 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4515 the things which are local to the given block. */
4518 output_block (stmt, depth)
4522 register int must_output_die = 0;
4523 register tree origin;
4524 register enum tree_code origin_code;
4526 /* Ignore blocks never really used to make RTL. */
4528 if (! stmt || ! TREE_USED (stmt))
4531 /* Determine the "ultimate origin" of this block. This block may be an
4532 inlined instance of an inlined instance of inline function, so we
4533 have to trace all of the way back through the origin chain to find
4534 out what sort of node actually served as the original seed for the
4535 creation of the current block. */
4537 origin = block_ultimate_origin (stmt);
4538 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4540 /* Determine if we need to output any Dwarf DIEs at all to represent this
4543 if (origin_code == FUNCTION_DECL)
4544 /* The outer scopes for inlinings *must* always be represented. We
4545 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4546 must_output_die = 1;
4549 /* In the case where the current block represents an inlining of the
4550 "body block" of an inline function, we must *NOT* output any DIE
4551 for this block because we have already output a DIE to represent
4552 the whole inlined function scope and the "body block" of any
4553 function doesn't really represent a different scope according to
4554 ANSI C rules. So we check here to make sure that this block does
4555 not represent a "body block inlining" before trying to set the
4556 `must_output_die' flag. */
4558 if (! is_body_block (origin ? origin : stmt))
4560 /* Determine if this block directly contains any "significant"
4561 local declarations which we will need to output DIEs for. */
4563 if (debug_info_level > DINFO_LEVEL_TERSE)
4564 /* We are not in terse mode so *any* local declaration counts
4565 as being a "significant" one. */
4566 must_output_die = (BLOCK_VARS (stmt) != NULL);
4571 /* We are in terse mode, so only local (nested) function
4572 definitions count as "significant" local declarations. */
4574 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4575 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4577 must_output_die = 1;
4584 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4585 DIE for any block which contains no significant local declarations
4586 at all. Rather, in such cases we just call `output_decls_for_scope'
4587 so that any needed Dwarf info for any sub-blocks will get properly
4588 generated. Note that in terse mode, our definition of what constitutes
4589 a "significant" local declaration gets restricted to include only
4590 inlined function instances and local (nested) function definitions. */
4592 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4593 /* We don't care about an abstract inlined subroutine. */;
4594 else if (must_output_die)
4596 output_die ((origin_code == FUNCTION_DECL)
4597 ? output_inlined_subroutine_die
4598 : output_lexical_block_die,
4600 output_decls_for_scope (stmt, depth);
4601 end_sibling_chain ();
4604 output_decls_for_scope (stmt, depth);
4607 /* Output all of the decls declared within a given scope (also called
4608 a `binding contour') and (recursively) all of it's sub-blocks. */
4611 output_decls_for_scope (stmt, depth)
4615 /* Ignore blocks never really used to make RTL. */
4617 if (! stmt || ! TREE_USED (stmt))
4620 if (! BLOCK_ABSTRACT (stmt) && depth > 0)
4621 next_block_number++;
4623 /* Output the DIEs to represent all of the data objects, functions,
4624 typedefs, and tagged types declared directly within this block
4625 but not within any nested sub-blocks. */
4630 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4631 output_decl (decl, stmt);
4634 output_pending_types_for_scope (stmt);
4636 /* Output the DIEs to represent all sub-blocks (and the items declared
4637 therein) of this block. */
4640 register tree subblocks;
4642 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4644 subblocks = BLOCK_CHAIN (subblocks))
4645 output_block (subblocks, depth + 1);
4649 /* Is this a typedef we can avoid emitting? */
4652 is_redundant_typedef (decl)
4655 if (TYPE_DECL_IS_STUB (decl))
4657 if (DECL_ARTIFICIAL (decl)
4658 && DECL_CONTEXT (decl)
4659 && is_tagged_type (DECL_CONTEXT (decl))
4660 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4661 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4662 /* Also ignore the artificial member typedef for the class name. */
4667 /* Output Dwarf .debug information for a decl described by DECL. */
4670 output_decl (decl, containing_scope)
4672 register tree containing_scope;
4674 /* Make a note of the decl node we are going to be working on. We may
4675 need to give the user the source coordinates of where it appeared in
4676 case we notice (later on) that something about it looks screwy. */
4678 dwarf_last_decl = decl;
4680 if (TREE_CODE (decl) == ERROR_MARK)
4683 /* If a structure is declared within an initialization, e.g. as the
4684 operand of a sizeof, then it will not have a name. We don't want
4685 to output a DIE for it, as the tree nodes are in the temporary obstack */
4687 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4688 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4689 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4690 || (TYPE_FIELDS (TREE_TYPE (decl))
4691 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4694 /* If this ..._DECL node is marked to be ignored, then ignore it.
4695 But don't ignore a function definition, since that would screw
4696 up our count of blocks, and that it turn will completely screw up the
4697 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4698 attributes (for subsequent blocks). */
4700 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4703 switch (TREE_CODE (decl))
4706 /* The individual enumerators of an enum type get output when we
4707 output the Dwarf representation of the relevant enum type itself. */
4711 /* If we are in terse mode, don't output any DIEs to represent
4712 mere function declarations. Also, if we are conforming
4713 to the DWARF version 1 specification, don't output DIEs for
4714 mere function declarations. */
4716 if (DECL_INITIAL (decl) == NULL_TREE)
4717 #if (DWARF_VERSION > 1)
4718 if (debug_info_level <= DINFO_LEVEL_TERSE)
4722 /* Before we describe the FUNCTION_DECL itself, make sure that we
4723 have described its return type. */
4725 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4728 /* And its containing type. */
4729 register tree origin = decl_class_context (decl);
4731 output_type (origin, containing_scope);
4734 /* If the following DIE will represent a function definition for a
4735 function with "extern" linkage, output a special "pubnames" DIE
4736 label just ahead of the actual DIE. A reference to this label
4737 was already generated in the .debug_pubnames section sub-entry
4738 for this function definition. */
4740 if (TREE_PUBLIC (decl))
4742 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4744 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4745 ASM_OUTPUT_LABEL (asm_out_file, label);
4748 /* Now output a DIE to represent the function itself. */
4750 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4751 ? output_global_subroutine_die
4752 : output_local_subroutine_die,
4755 /* Now output descriptions of the arguments for this function.
4756 This gets (unnecessarily?) complex because of the fact that
4757 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4758 cases where there was a trailing `...' at the end of the formal
4759 parameter list. In order to find out if there was a trailing
4760 ellipsis or not, we must instead look at the type associated
4761 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4762 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4763 ends with a void_type_node then there should *not* be an ellipsis
4766 /* In the case where we are describing a mere function declaration, all
4767 we need to do here (and all we *can* do here) is to describe
4768 the *types* of its formal parameters. */
4770 if (decl != current_function_decl || in_class)
4771 output_formal_types (TREE_TYPE (decl));
4774 /* Generate DIEs to represent all known formal parameters */
4776 register tree arg_decls = DECL_ARGUMENTS (decl);
4779 /* WARNING! Kludge zone ahead! Here we have a special
4780 hack for svr4 SDB compatibility. Instead of passing the
4781 current FUNCTION_DECL node as the second parameter (i.e.
4782 the `containing_scope' parameter) to `output_decl' (as
4783 we ought to) we instead pass a pointer to our own private
4784 fake_containing_scope node. That node is a RECORD_TYPE
4785 node which NO OTHER TYPE may ever actually be a member of.
4787 This pointer will ultimately get passed into `output_type'
4788 as its `containing_scope' parameter. `Output_type' will
4789 then perform its part in the hack... i.e. it will pend
4790 the type of the formal parameter onto the pending_types
4791 list. Later on, when we are done generating the whole
4792 sequence of formal parameter DIEs for this function
4793 definition, we will un-pend all previously pended types
4794 of formal parameters for this function definition.
4796 This whole kludge prevents any type DIEs from being
4797 mixed in with the formal parameter DIEs. That's good
4798 because svr4 SDB believes that the list of formal
4799 parameter DIEs for a function ends wherever the first
4800 non-formal-parameter DIE appears. Thus, we have to
4801 keep the formal parameter DIEs segregated. They must
4802 all appear (consecutively) at the start of the list of
4803 children for the DIE representing the function definition.
4804 Then (and only then) may we output any additional DIEs
4805 needed to represent the types of these formal parameters.
4809 When generating DIEs, generate the unspecified_parameters
4810 DIE instead if we come across the arg "__builtin_va_alist"
4813 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4814 if (TREE_CODE (parm) == PARM_DECL)
4816 if (DECL_NAME(parm) &&
4817 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4818 "__builtin_va_alist") )
4819 output_die (output_unspecified_parameters_die, decl);
4821 output_decl (parm, fake_containing_scope);
4825 Now that we have finished generating all of the DIEs to
4826 represent the formal parameters themselves, force out
4827 any DIEs needed to represent their types. We do this
4828 simply by un-pending all previously pended types which
4829 can legitimately go into the chain of children DIEs for
4830 the current FUNCTION_DECL.
4833 output_pending_types_for_scope (decl);
4836 Decide whether we need a unspecified_parameters DIE at the end.
4837 There are 2 more cases to do this for:
4838 1) the ansi ... declaration - this is detectable when the end
4839 of the arg list is not a void_type_node
4840 2) an unprototyped function declaration (not a definition). This
4841 just means that we have no info about the parameters at all.
4845 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4849 /* this is the prototyped case, check for ... */
4850 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4851 output_die (output_unspecified_parameters_die, decl);
4855 /* this is unprototyped, check for undefined (just declaration) */
4856 if (!DECL_INITIAL (decl))
4857 output_die (output_unspecified_parameters_die, decl);
4861 /* Output Dwarf info for all of the stuff within the body of the
4862 function (if it has one - it may be just a declaration). */
4865 register tree outer_scope = DECL_INITIAL (decl);
4867 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4869 /* Note that here, `outer_scope' is a pointer to the outermost
4870 BLOCK node created to represent a function.
4871 This outermost BLOCK actually represents the outermost
4872 binding contour for the function, i.e. the contour in which
4873 the function's formal parameters and labels get declared.
4875 Curiously, it appears that the front end doesn't actually
4876 put the PARM_DECL nodes for the current function onto the
4877 BLOCK_VARS list for this outer scope. (They are strung
4878 off of the DECL_ARGUMENTS list for the function instead.)
4879 The BLOCK_VARS list for the `outer_scope' does provide us
4880 with a list of the LABEL_DECL nodes for the function however,
4881 and we output DWARF info for those here.
4883 Just within the `outer_scope' there will be a BLOCK node
4884 representing the function's outermost pair of curly braces,
4885 and any blocks used for the base and member initializers of
4886 a C++ constructor function. */
4888 output_decls_for_scope (outer_scope, 0);
4890 /* Finally, force out any pending types which are local to the
4891 outermost block of this function definition. These will
4892 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4895 output_pending_types_for_scope (decl);
4900 /* Generate a terminator for the list of stuff `owned' by this
4903 end_sibling_chain ();
4908 /* If we are in terse mode, don't generate any DIEs to represent
4909 any actual typedefs. Note that even when we are in terse mode,
4910 we must still output DIEs to represent those tagged types which
4911 are used (directly or indirectly) in the specification of either
4912 a return type or a formal parameter type of some function. */
4914 if (debug_info_level <= DINFO_LEVEL_TERSE)
4915 if (! TYPE_DECL_IS_STUB (decl)
4916 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4919 /* In the special case of a TYPE_DECL node representing
4920 the declaration of some type tag, if the given TYPE_DECL is
4921 marked as having been instantiated from some other (original)
4922 TYPE_DECL node (e.g. one which was generated within the original
4923 definition of an inline function) we have to generate a special
4924 (abbreviated) TAG_structure_type, TAG_union_type, or
4925 TAG_enumeration-type DIE here. */
4927 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4929 output_tagged_type_instantiation (TREE_TYPE (decl));
4933 output_type (TREE_TYPE (decl), containing_scope);
4935 if (! is_redundant_typedef (decl))
4936 /* Output a DIE to represent the typedef itself. */
4937 output_die (output_typedef_die, decl);
4941 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4942 output_die (output_label_die, decl);
4946 /* If we are conforming to the DWARF version 1 specification, don't
4947 generated any DIEs to represent mere external object declarations. */
4949 #if (DWARF_VERSION <= 1)
4950 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4954 /* If we are in terse mode, don't generate any DIEs to represent
4955 any variable declarations or definitions. */
4957 if (debug_info_level <= DINFO_LEVEL_TERSE)
4960 /* Output any DIEs that are needed to specify the type of this data
4963 output_type (TREE_TYPE (decl), containing_scope);
4966 /* And its containing type. */
4967 register tree origin = decl_class_context (decl);
4969 output_type (origin, containing_scope);
4972 /* If the following DIE will represent a data object definition for a
4973 data object with "extern" linkage, output a special "pubnames" DIE
4974 label just ahead of the actual DIE. A reference to this label
4975 was already generated in the .debug_pubnames section sub-entry
4976 for this data object definition. */
4978 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4980 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4982 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4983 ASM_OUTPUT_LABEL (asm_out_file, label);
4986 /* Now output the DIE to represent the data object itself. This gets
4987 complicated because of the possibility that the VAR_DECL really
4988 represents an inlined instance of a formal parameter for an inline
4992 register void (*func) ();
4993 register tree origin = decl_ultimate_origin (decl);
4995 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
4996 func = output_formal_parameter_die;
4999 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5000 func = output_global_variable_die;
5002 func = output_local_variable_die;
5004 output_die (func, decl);
5009 /* Ignore the nameless fields that are used to skip bits. */
5010 if (DECL_NAME (decl) != 0)
5012 output_type (member_declared_type (decl), containing_scope);
5013 output_die (output_member_die, decl);
5018 /* Force out the type of this formal, if it was not forced out yet.
5019 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5020 It should be able to grok the presence of type DIEs within a list
5021 of TAG_formal_parameter DIEs, but it doesn't. */
5023 output_type (TREE_TYPE (decl), containing_scope);
5024 output_die (output_formal_parameter_die, decl);
5033 dwarfout_file_scope_decl (decl, set_finalizing)
5035 register int set_finalizing;
5037 if (TREE_CODE (decl) == ERROR_MARK)
5040 /* If this ..._DECL node is marked to be ignored, then ignore it. We
5041 gotta hope that the node in question doesn't represent a function
5042 definition. If it does, then totally ignoring it is bound to screw
5043 up our count of blocks, and that it turn will completely screw up the
5044 the labels we will reference in subsequent AT_low_pc and AT_high_pc
5045 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
5046 don't carry their own sequence numbers with them!) */
5048 if (DECL_IGNORED_P (decl))
5050 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5055 switch (TREE_CODE (decl))
5059 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5060 a builtin function. Explicit programmer-supplied declarations of
5061 these same functions should NOT be ignored however. */
5063 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5066 /* What we would really like to do here is to filter out all mere
5067 file-scope declarations of file-scope functions which are never
5068 referenced later within this translation unit (and keep all of
5069 ones that *are* referenced later on) but we aren't clairvoyant,
5070 so we have no idea which functions will be referenced in the
5071 future (i.e. later on within the current translation unit).
5072 So here we just ignore all file-scope function declarations
5073 which are not also definitions. If and when the debugger needs
5074 to know something about these functions, it wil have to hunt
5075 around and find the DWARF information associated with the
5076 *definition* of the function.
5078 Note that we can't just check `DECL_EXTERNAL' to find out which
5079 FUNCTION_DECL nodes represent definitions and which ones represent
5080 mere declarations. We have to check `DECL_INITIAL' instead. That's
5081 because the C front-end supports some weird semantics for "extern
5082 inline" function definitions. These can get inlined within the
5083 current translation unit (an thus, we need to generate DWARF info
5084 for their abstract instances so that the DWARF info for the
5085 concrete inlined instances can have something to refer to) but
5086 the compiler never generates any out-of-lines instances of such
5087 things (despite the fact that they *are* definitions). The
5088 important point is that the C front-end marks these "extern inline"
5089 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5092 Note that the C++ front-end also plays some similar games for inline
5093 function definitions appearing within include files which also
5094 contain `#pragma interface' pragmas. */
5096 if (DECL_INITIAL (decl) == NULL_TREE)
5099 if (TREE_PUBLIC (decl)
5100 && ! DECL_EXTERNAL (decl)
5101 && ! DECL_ABSTRACT (decl))
5103 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5105 /* Output a .debug_pubnames entry for a public function
5106 defined in this compilation unit. */
5108 fputc ('\n', asm_out_file);
5109 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5110 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5111 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5112 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5113 IDENTIFIER_POINTER (DECL_NAME (decl)));
5114 ASM_OUTPUT_POP_SECTION (asm_out_file);
5121 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5122 object declaration and if the declaration was never even
5123 referenced from within this entire compilation unit. We
5124 suppress these DIEs in order to save space in the .debug section
5125 (by eliminating entries which are probably useless). Note that
5126 we must not suppress block-local extern declarations (whether
5127 used or not) because that would screw-up the debugger's name
5128 lookup mechanism and cause it to miss things which really ought
5129 to be in scope at a given point. */
5131 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5134 if (TREE_PUBLIC (decl)
5135 && ! DECL_EXTERNAL (decl)
5136 && GET_CODE (DECL_RTL (decl)) == MEM
5137 && ! DECL_ABSTRACT (decl))
5139 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5141 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5143 /* Output a .debug_pubnames entry for a public variable
5144 defined in this compilation unit. */
5146 fputc ('\n', asm_out_file);
5147 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5148 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5149 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5150 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5151 IDENTIFIER_POINTER (DECL_NAME (decl)));
5152 ASM_OUTPUT_POP_SECTION (asm_out_file);
5155 if (DECL_INITIAL (decl) == NULL)
5157 /* Output a .debug_aranges entry for a public variable
5158 which is tentatively defined in this compilation unit. */
5160 fputc ('\n', asm_out_file);
5161 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5162 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5163 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5164 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5165 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5166 ASM_OUTPUT_POP_SECTION (asm_out_file);
5170 /* If we are in terse mode, don't generate any DIEs to represent
5171 any variable declarations or definitions. */
5173 if (debug_info_level <= DINFO_LEVEL_TERSE)
5179 /* Don't bother trying to generate any DIEs to represent any of the
5180 normal built-in types for the language we are compiling, except
5181 in cases where the types in question are *not* DWARF fundamental
5182 types. We make an exception in the case of non-fundamental types
5183 for the sake of objective C (and perhaps C++) because the GNU
5184 front-ends for these languages may in fact create certain "built-in"
5185 types which are (for example) RECORD_TYPEs. In such cases, we
5186 really need to output these (non-fundamental) types because other
5187 DIEs may contain references to them. */
5189 if (DECL_SOURCE_LINE (decl) == 0
5190 && type_is_fundamental (TREE_TYPE (decl)))
5193 /* If we are in terse mode, don't generate any DIEs to represent
5194 any actual typedefs. Note that even when we are in terse mode,
5195 we must still output DIEs to represent those tagged types which
5196 are used (directly or indirectly) in the specification of either
5197 a return type or a formal parameter type of some function. */
5199 if (debug_info_level <= DINFO_LEVEL_TERSE)
5200 if (! TYPE_DECL_IS_STUB (decl)
5201 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5210 fputc ('\n', asm_out_file);
5211 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5212 finalizing = set_finalizing;
5213 output_decl (decl, NULL_TREE);
5215 /* NOTE: The call above to `output_decl' may have caused one or more
5216 file-scope named types (i.e. tagged types) to be placed onto the
5217 pending_types_list. We have to get those types off of that list
5218 at some point, and this is the perfect time to do it. If we didn't
5219 take them off now, they might still be on the list when cc1 finally
5220 exits. That might be OK if it weren't for the fact that when we put
5221 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5222 for these types, and that causes them never to be output unless
5223 `output_pending_types_for_scope' takes them off of the list and un-sets
5224 their TREE_ASM_WRITTEN flags. */
5226 output_pending_types_for_scope (NULL_TREE);
5228 /* The above call should have totally emptied the pending_types_list. */
5230 if (pending_types != 0)
5233 ASM_OUTPUT_POP_SECTION (asm_out_file);
5235 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5236 current_funcdef_number++;
5239 /* Output a marker (i.e. a label) for the beginning of the generated code
5240 for a lexical block. */
5243 dwarfout_begin_block (blocknum)
5244 register unsigned blocknum;
5246 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5248 function_section (current_function_decl);
5249 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5250 ASM_OUTPUT_LABEL (asm_out_file, label);
5253 /* Output a marker (i.e. a label) for the end of the generated code
5254 for a lexical block. */
5257 dwarfout_end_block (blocknum)
5258 register unsigned blocknum;
5260 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5262 function_section (current_function_decl);
5263 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5264 ASM_OUTPUT_LABEL (asm_out_file, label);
5267 /* Output a marker (i.e. a label) at a point in the assembly code which
5268 corresponds to a given source level label. */
5271 dwarfout_label (insn)
5274 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5276 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5278 function_section (current_function_decl);
5279 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5280 (unsigned) INSN_UID (insn));
5281 ASM_OUTPUT_LABEL (asm_out_file, label);
5285 /* Output a marker (i.e. a label) for the point in the generated code where
5286 the real body of the function begins (after parameters have been moved
5287 to their home locations). */
5290 dwarfout_begin_function ()
5292 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5294 if (! use_gnu_debug_info_extensions)
5296 function_section (current_function_decl);
5297 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5298 ASM_OUTPUT_LABEL (asm_out_file, label);
5301 /* Output a marker (i.e. a label) for the point in the generated code where
5302 the real body of the function ends (just before the epilogue code). */
5305 dwarfout_end_function ()
5307 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5309 if (! use_gnu_debug_info_extensions)
5311 function_section (current_function_decl);
5312 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5313 ASM_OUTPUT_LABEL (asm_out_file, label);
5316 /* Output a marker (i.e. a label) for the absolute end of the generated code
5317 for a function definition. This gets called *after* the epilogue code
5318 has been generated. */
5321 dwarfout_end_epilogue ()
5323 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5325 /* Output a label to mark the endpoint of the code generated for this
5328 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5329 ASM_OUTPUT_LABEL (asm_out_file, label);
5333 shuffle_filename_entry (new_zeroth)
5334 register filename_entry *new_zeroth;
5336 filename_entry temp_entry;
5337 register filename_entry *limit_p;
5338 register filename_entry *move_p;
5340 if (new_zeroth == &filename_table[0])
5343 temp_entry = *new_zeroth;
5345 /* Shift entries up in the table to make room at [0]. */
5347 limit_p = &filename_table[0];
5348 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5349 *move_p = *(move_p-1);
5351 /* Install the found entry at [0]. */
5353 filename_table[0] = temp_entry;
5356 /* Create a new (string) entry for the .debug_sfnames section. */
5359 generate_new_sfname_entry ()
5361 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5363 fputc ('\n', asm_out_file);
5364 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5365 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5366 ASM_OUTPUT_LABEL (asm_out_file, label);
5367 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5368 filename_table[0].name
5369 ? filename_table[0].name
5371 ASM_OUTPUT_POP_SECTION (asm_out_file);
5374 /* Lookup a filename (in the list of filenames that we know about here in
5375 dwarfout.c) and return its "index". The index of each (known) filename
5376 is just a unique number which is associated with only that one filename.
5377 We need such numbers for the sake of generating labels (in the
5378 .debug_sfnames section) and references to those unique labels (in the
5379 .debug_srcinfo and .debug_macinfo sections).
5381 If the filename given as an argument is not found in our current list,
5382 add it to the list and assign it the next available unique index number.
5384 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5385 one), we shuffle the filename found (or added) up to the zeroth entry of
5386 our list of filenames (which is always searched linearly). We do this so
5387 as to optimize the most common case for these filename lookups within
5388 dwarfout.c. The most common case by far is the case where we call
5389 lookup_filename to lookup the very same filename that we did a lookup
5390 on the last time we called lookup_filename. We make sure that this
5391 common case is fast because such cases will constitute 99.9% of the
5392 lookups we ever do (in practice).
5394 If we add a new filename entry to our table, we go ahead and generate
5395 the corresponding entry in the .debug_sfnames section right away.
5396 Doing so allows us to avoid tickling an assembler bug (present in some
5397 m68k assemblers) which yields assembly-time errors in cases where the
5398 difference of two label addresses is taken and where the two labels
5399 are in a section *other* than the one where the difference is being
5400 calculated, and where at least one of the two symbol references is a
5401 forward reference. (This bug could be tickled by our .debug_srcinfo
5402 entries if we don't output their corresponding .debug_sfnames entries
5406 lookup_filename (file_name)
5409 register filename_entry *search_p;
5410 register filename_entry *limit_p = &filename_table[ft_entries];
5412 for (search_p = filename_table; search_p < limit_p; search_p++)
5413 if (!strcmp (file_name, search_p->name))
5415 /* When we get here, we have found the filename that we were
5416 looking for in the filename_table. Now we want to make sure
5417 that it gets moved to the zero'th entry in the table (if it
5418 is not already there) so that subsequent attempts to find the
5419 same filename will find it as quickly as possible. */
5421 shuffle_filename_entry (search_p);
5422 return filename_table[0].number;
5425 /* We come here whenever we have a new filename which is not registered
5426 in the current table. Here we add it to the table. */
5428 /* Prepare to add a new table entry by making sure there is enough space
5429 in the table to do so. If not, expand the current table. */
5431 if (ft_entries == ft_entries_allocated)
5433 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5435 = (filename_entry *)
5436 xrealloc (filename_table,
5437 ft_entries_allocated * sizeof (filename_entry));
5440 /* Initially, add the new entry at the end of the filename table. */
5442 filename_table[ft_entries].number = ft_entries;
5443 filename_table[ft_entries].name = xstrdup (file_name);
5445 /* Shuffle the new entry into filename_table[0]. */
5447 shuffle_filename_entry (&filename_table[ft_entries]);
5449 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5450 generate_new_sfname_entry ();
5453 return filename_table[0].number;
5457 generate_srcinfo_entry (line_entry_num, files_entry_num)
5458 unsigned line_entry_num;
5459 unsigned files_entry_num;
5461 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5463 fputc ('\n', asm_out_file);
5464 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5465 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5466 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5467 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5468 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5469 ASM_OUTPUT_POP_SECTION (asm_out_file);
5473 dwarfout_line (filename, line)
5474 register char *filename;
5475 register unsigned line;
5477 if (debug_info_level >= DINFO_LEVEL_NORMAL
5478 /* We can't emit line number info for functions in separate sections,
5479 because the assembler can't subtract labels in different sections. */
5480 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5482 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5483 static unsigned last_line_entry_num = 0;
5484 static unsigned prev_file_entry_num = (unsigned) -1;
5485 register unsigned this_file_entry_num;
5487 function_section (current_function_decl);
5488 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5489 ASM_OUTPUT_LABEL (asm_out_file, label);
5491 fputc ('\n', asm_out_file);
5493 if (use_gnu_debug_info_extensions)
5494 this_file_entry_num = lookup_filename (filename);
5496 this_file_entry_num = (unsigned) -1;
5498 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5499 if (this_file_entry_num != prev_file_entry_num)
5501 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5503 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5504 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5508 register char *tail = rindex (filename, '/');
5514 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5515 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5517 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5518 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5519 ASM_OUTPUT_POP_SECTION (asm_out_file);
5521 if (this_file_entry_num != prev_file_entry_num)
5522 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5523 prev_file_entry_num = this_file_entry_num;
5527 /* Generate an entry in the .debug_macinfo section. */
5530 generate_macinfo_entry (type_and_offset, string)
5531 register char *type_and_offset;
5532 register char *string;
5534 if (! use_gnu_debug_info_extensions)
5537 fputc ('\n', asm_out_file);
5538 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5539 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5540 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
5541 ASM_OUTPUT_POP_SECTION (asm_out_file);
5545 dwarfout_start_new_source_file (filename)
5546 register char *filename;
5548 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5549 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5551 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5552 sprintf (type_and_offset, "0x%08x+%s-%s",
5553 ((unsigned) MACINFO_start << 24),
5554 /* Hack: skip leading '*' . */
5555 (*label == '*') + label,
5556 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5557 generate_macinfo_entry (type_and_offset, "");
5561 dwarfout_resume_previous_source_file (lineno)
5562 register unsigned lineno;
5564 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5566 sprintf (type_and_offset, "0x%08x+%u",
5567 ((unsigned) MACINFO_resume << 24), lineno);
5568 generate_macinfo_entry (type_and_offset, "");
5571 /* Called from check_newline in c-parse.y. The `buffer' parameter
5572 contains the tail part of the directive line, i.e. the part which
5573 is past the initial whitespace, #, whitespace, directive-name,
5577 dwarfout_define (lineno, buffer)
5578 register unsigned lineno;
5579 register char *buffer;
5581 static int initialized = 0;
5582 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5586 dwarfout_start_new_source_file (primary_filename);
5589 sprintf (type_and_offset, "0x%08x+%u",
5590 ((unsigned) MACINFO_define << 24), lineno);
5591 generate_macinfo_entry (type_and_offset, buffer);
5594 /* Called from check_newline in c-parse.y. The `buffer' parameter
5595 contains the tail part of the directive line, i.e. the part which
5596 is past the initial whitespace, #, whitespace, directive-name,
5600 dwarfout_undef (lineno, buffer)
5601 register unsigned lineno;
5602 register char *buffer;
5604 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5606 sprintf (type_and_offset, "0x%08x+%u",
5607 ((unsigned) MACINFO_undef << 24), lineno);
5608 generate_macinfo_entry (type_and_offset, buffer);
5611 /* Set up for Dwarf output at the start of compilation. */
5614 dwarfout_init (asm_out_file, main_input_filename)
5615 register FILE *asm_out_file;
5616 register char *main_input_filename;
5618 /* Remember the name of the primary input file. */
5620 primary_filename = main_input_filename;
5622 /* Allocate the initial hunk of the pending_sibling_stack. */
5624 pending_sibling_stack
5626 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5627 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5628 pending_siblings = 1;
5630 /* Allocate the initial hunk of the filename_table. */
5633 = (filename_entry *)
5634 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5635 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5638 /* Allocate the initial hunk of the pending_types_list. */
5641 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5642 pending_types_allocated = PENDING_TYPES_INCREMENT;
5645 /* Create an artificial RECORD_TYPE node which we can use in our hack
5646 to get the DIEs representing types of formal parameters to come out
5647 only *after* the DIEs for the formal parameters themselves. */
5649 fake_containing_scope = make_node (RECORD_TYPE);
5651 /* Output a starting label for the .text section. */
5653 fputc ('\n', asm_out_file);
5654 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5655 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5656 ASM_OUTPUT_POP_SECTION (asm_out_file);
5658 /* Output a starting label for the .data section. */
5660 fputc ('\n', asm_out_file);
5661 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5662 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5663 ASM_OUTPUT_POP_SECTION (asm_out_file);
5665 #if 0 /* GNU C doesn't currently use .data1. */
5666 /* Output a starting label for the .data1 section. */
5668 fputc ('\n', asm_out_file);
5669 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5670 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5671 ASM_OUTPUT_POP_SECTION (asm_out_file);
5674 /* Output a starting label for the .rodata section. */
5676 fputc ('\n', asm_out_file);
5677 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5678 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5679 ASM_OUTPUT_POP_SECTION (asm_out_file);
5681 #if 0 /* GNU C doesn't currently use .rodata1. */
5682 /* Output a starting label for the .rodata1 section. */
5684 fputc ('\n', asm_out_file);
5685 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5686 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5687 ASM_OUTPUT_POP_SECTION (asm_out_file);
5690 /* Output a starting label for the .bss section. */
5692 fputc ('\n', asm_out_file);
5693 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5694 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5695 ASM_OUTPUT_POP_SECTION (asm_out_file);
5697 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5699 if (use_gnu_debug_info_extensions)
5701 /* Output a starting label and an initial (compilation directory)
5702 entry for the .debug_sfnames section. The starting label will be
5703 referenced by the initial entry in the .debug_srcinfo section. */
5705 fputc ('\n', asm_out_file);
5706 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5707 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5710 register unsigned len;
5711 register char *dirname;
5715 pfatal_with_name ("getpwd");
5717 dirname = (char *) xmalloc (len + 2);
5719 strcpy (dirname, pwd);
5720 strcpy (dirname + len, "/");
5721 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5724 ASM_OUTPUT_POP_SECTION (asm_out_file);
5727 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5728 && use_gnu_debug_info_extensions)
5730 /* Output a starting label for the .debug_macinfo section. This
5731 label will be referenced by the AT_mac_info attribute in the
5732 TAG_compile_unit DIE. */
5734 fputc ('\n', asm_out_file);
5735 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5736 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5737 ASM_OUTPUT_POP_SECTION (asm_out_file);
5740 /* Generate the initial entry for the .line section. */
5742 fputc ('\n', asm_out_file);
5743 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5744 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5745 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5746 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5747 ASM_OUTPUT_POP_SECTION (asm_out_file);
5749 if (use_gnu_debug_info_extensions)
5751 /* Generate the initial entry for the .debug_srcinfo section. */
5753 fputc ('\n', asm_out_file);
5754 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5755 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5756 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5757 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5758 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5759 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5760 #ifdef DWARF_TIMESTAMPS
5761 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5763 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5765 ASM_OUTPUT_POP_SECTION (asm_out_file);
5768 /* Generate the initial entry for the .debug_pubnames section. */
5770 fputc ('\n', asm_out_file);
5771 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5772 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5773 ASM_OUTPUT_POP_SECTION (asm_out_file);
5775 /* Generate the initial entry for the .debug_aranges section. */
5777 fputc ('\n', asm_out_file);
5778 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5779 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5780 ASM_OUTPUT_POP_SECTION (asm_out_file);
5783 /* Setup first DIE number == 1. */
5784 NEXT_DIE_NUM = next_unused_dienum++;
5786 /* Generate the initial DIE for the .debug section. Note that the
5787 (string) value given in the AT_name attribute of the TAG_compile_unit
5788 DIE will (typically) be a relative pathname and that this pathname
5789 should be taken as being relative to the directory from which the
5790 compiler was invoked when the given (base) source file was compiled. */
5792 fputc ('\n', asm_out_file);
5793 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5794 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5795 output_die (output_compile_unit_die, main_input_filename);
5796 ASM_OUTPUT_POP_SECTION (asm_out_file);
5798 fputc ('\n', asm_out_file);
5801 /* Output stuff that dwarf requires at the end of every file. */
5806 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5808 fputc ('\n', asm_out_file);
5809 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5811 /* Mark the end of the chain of siblings which represent all file-scope
5812 declarations in this compilation unit. */
5814 /* The (null) DIE which represents the terminator for the (sibling linked)
5815 list of file-scope items is *special*. Normally, we would just call
5816 end_sibling_chain at this point in order to output a word with the
5817 value `4' and that word would act as the terminator for the list of
5818 DIEs describing file-scope items. Unfortunately, if we were to simply
5819 do that, the label that would follow this DIE in the .debug section
5820 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5821 machines) to a 4 byte boundary.
5823 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5824 the trick used is to insert extra (otherwise useless) padding bytes
5825 into the (null) DIE that we know must precede the ..D2 label in the
5826 .debug section. The amount of padding required can be anywhere between
5827 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5828 with the padding) would normally contain the value 4, but now it will
5829 also have to include the padding bytes, so it will instead have some
5830 value in the range 4..7.
5832 Fortunately, the rules of Dwarf say that any DIE whose length word
5833 contains *any* value less than 8 should be treated as a null DIE, so
5834 this trick works out nicely. Clever, eh? Don't give me any credit
5835 (or blame). I didn't think of this scheme. I just conformed to it.
5838 output_die (output_padded_null_die, (void *) 0);
5841 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5842 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5843 ASM_OUTPUT_POP_SECTION (asm_out_file);
5845 /* Output a terminator label for the .text section. */
5847 fputc ('\n', asm_out_file);
5848 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5849 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5850 ASM_OUTPUT_POP_SECTION (asm_out_file);
5852 /* Output a terminator label for the .data section. */
5854 fputc ('\n', asm_out_file);
5855 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5856 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5857 ASM_OUTPUT_POP_SECTION (asm_out_file);
5859 #if 0 /* GNU C doesn't currently use .data1. */
5860 /* Output a terminator label for the .data1 section. */
5862 fputc ('\n', asm_out_file);
5863 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5864 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5865 ASM_OUTPUT_POP_SECTION (asm_out_file);
5868 /* Output a terminator label for the .rodata section. */
5870 fputc ('\n', asm_out_file);
5871 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5872 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5873 ASM_OUTPUT_POP_SECTION (asm_out_file);
5875 #if 0 /* GNU C doesn't currently use .rodata1. */
5876 /* Output a terminator label for the .rodata1 section. */
5878 fputc ('\n', asm_out_file);
5879 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5880 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5881 ASM_OUTPUT_POP_SECTION (asm_out_file);
5884 /* Output a terminator label for the .bss section. */
5886 fputc ('\n', asm_out_file);
5887 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5888 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5889 ASM_OUTPUT_POP_SECTION (asm_out_file);
5891 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5893 /* Output a terminating entry for the .line section. */
5895 fputc ('\n', asm_out_file);
5896 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5897 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5898 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5899 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5900 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5901 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5902 ASM_OUTPUT_POP_SECTION (asm_out_file);
5904 if (use_gnu_debug_info_extensions)
5906 /* Output a terminating entry for the .debug_srcinfo section. */
5908 fputc ('\n', asm_out_file);
5909 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5910 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5911 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5912 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5913 ASM_OUTPUT_POP_SECTION (asm_out_file);
5916 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5918 /* Output terminating entries for the .debug_macinfo section. */
5920 dwarfout_resume_previous_source_file (0);
5922 fputc ('\n', asm_out_file);
5923 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5924 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5925 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5926 ASM_OUTPUT_POP_SECTION (asm_out_file);
5929 /* Generate the terminating entry for the .debug_pubnames section. */
5931 fputc ('\n', asm_out_file);
5932 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5933 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5934 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5935 ASM_OUTPUT_POP_SECTION (asm_out_file);
5937 /* Generate the terminating entries for the .debug_aranges section.
5939 Note that we want to do this only *after* we have output the end
5940 labels (for the various program sections) which we are going to
5941 refer to here. This allows us to work around a bug in the m68k
5942 svr4 assembler. That assembler gives bogus assembly-time errors
5943 if (within any given section) you try to take the difference of
5944 two relocatable symbols, both of which are located within some
5945 other section, and if one (or both?) of the symbols involved is
5946 being forward-referenced. By generating the .debug_aranges
5947 entries at this late point in the assembly output, we skirt the
5948 issue simply by avoiding forward-references.
5951 fputc ('\n', asm_out_file);
5952 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5954 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5955 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5957 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5958 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5960 #if 0 /* GNU C doesn't currently use .data1. */
5961 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5962 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5966 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5967 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5968 RODATA_BEGIN_LABEL);
5970 #if 0 /* GNU C doesn't currently use .rodata1. */
5971 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5972 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5973 RODATA1_BEGIN_LABEL);
5976 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5977 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5979 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5980 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5982 ASM_OUTPUT_POP_SECTION (asm_out_file);
5986 #endif /* DWARF_DEBUGGING_INFO */