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"
38 #if defined(DWARF_TIMESTAMPS)
40 extern time_t time PROTO ((time_t *)); /* FIXME: use NEED_DECLARATION_TIME */
41 #endif /* !defined(POSIX) */
42 #endif /* defined(DWARF_TIMESTAMPS) */
44 /* We cannot use <assert.h> in GCC source, since that would include
45 GCC's assert.h, which may not be compatible with the host compiler. */
50 # define assert(e) do { if (! (e)) abort (); } while (0)
53 extern char *getpwd ();
55 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
56 regarding the GNU implementation of Dwarf. */
58 /* NOTE: In the comments in this file, many references are made to
59 so called "Debugging Information Entries". For the sake of brevity,
60 this term is abbreviated to `DIE' throughout the remainder of this
63 /* Note that the implementation of C++ support herein is (as yet) unfinished.
64 If you want to try to complete it, more power to you. */
66 #if !defined(__GNUC__) || (NDEBUG != 1)
70 /* How to start an assembler comment. */
71 #ifndef ASM_COMMENT_START
72 #define ASM_COMMENT_START ";#"
75 /* How to print out a register name. */
77 #define PRINT_REG(RTX, CODE, FILE) \
78 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
81 /* Define a macro which returns non-zero for any tagged type which is
82 used (directly or indirectly) in the specification of either some
83 function's return type or some formal parameter of some function.
84 We use this macro when we are operating in "terse" mode to help us
85 know what tagged types have to be represented in Dwarf (even in
86 terse mode) and which ones don't.
88 A flag bit with this meaning really should be a part of the normal
89 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
90 for these nodes. For now, we have to just fake it. It it safe for
91 us to simply return zero for all complete tagged types (which will
92 get forced out anyway if they were used in the specification of some
93 formal or return type) and non-zero for all incomplete tagged types.
96 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
98 /* Define a macro which returns non-zero for a TYPE_DECL which was
99 implicitly generated for a tagged type.
101 Note that unlike the gcc front end (which generates a NULL named
102 TYPE_DECL node for each complete tagged type, each array type, and
103 each function type node created) the g++ front end generates a
104 _named_ TYPE_DECL node for each tagged type node created.
105 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
106 generate a DW_TAG_typedef DIE for them. */
107 #define TYPE_DECL_IS_STUB(decl) \
108 (DECL_NAME (decl) == NULL \
109 || (DECL_ARTIFICIAL (decl) \
110 && is_tagged_type (TREE_TYPE (decl)) \
111 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
113 extern int flag_traditional;
114 extern char *version_string;
115 extern char *language_string;
117 /* Maximum size (in bytes) of an artificially generated label. */
119 #define MAX_ARTIFICIAL_LABEL_BYTES 30
121 /* Make sure we know the sizes of the various types dwarf can describe.
122 These are only defaults. If the sizes are different for your target,
123 you should override these values by defining the appropriate symbols
124 in your tm.h file. */
126 #ifndef CHAR_TYPE_SIZE
127 #define CHAR_TYPE_SIZE BITS_PER_UNIT
130 #ifndef SHORT_TYPE_SIZE
131 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
134 #ifndef INT_TYPE_SIZE
135 #define INT_TYPE_SIZE BITS_PER_WORD
138 #ifndef LONG_TYPE_SIZE
139 #define LONG_TYPE_SIZE BITS_PER_WORD
142 #ifndef LONG_LONG_TYPE_SIZE
143 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
146 #ifndef WCHAR_TYPE_SIZE
147 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
150 #ifndef WCHAR_UNSIGNED
151 #define WCHAR_UNSIGNED 0
154 #ifndef FLOAT_TYPE_SIZE
155 #define FLOAT_TYPE_SIZE BITS_PER_WORD
158 #ifndef DOUBLE_TYPE_SIZE
159 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
162 #ifndef LONG_DOUBLE_TYPE_SIZE
163 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
166 /* Structure to keep track of source filenames. */
168 struct filename_entry {
173 typedef struct filename_entry filename_entry;
175 /* Pointer to an array of elements, each one having the structure above. */
177 static filename_entry *filename_table;
179 /* Total number of entries in the table (i.e. array) pointed to by
180 `filename_table'. This is the *total* and includes both used and
183 static unsigned ft_entries_allocated;
185 /* Number of entries in the filename_table which are actually in use. */
187 static unsigned ft_entries;
189 /* Size (in elements) of increments by which we may expand the filename
190 table. Actually, a single hunk of space of this size should be enough
191 for most typical programs. */
193 #define FT_ENTRIES_INCREMENT 64
195 /* Local pointer to the name of the main input file. Initialized in
198 static char *primary_filename;
200 /* Pointer to the most recent filename for which we produced some line info. */
202 static char *last_filename;
204 /* For Dwarf output, we must assign lexical-blocks id numbers
205 in the order in which their beginnings are encountered.
206 We output Dwarf debugging info that refers to the beginnings
207 and ends of the ranges of code for each lexical block with
208 assembler labels ..Bn and ..Bn.e, where n is the block number.
209 The labels themselves are generated in final.c, which assigns
210 numbers to the blocks in the same way. */
212 static unsigned next_block_number = 2;
214 /* Counter to generate unique names for DIEs. */
216 static unsigned next_unused_dienum = 1;
218 /* Number of the DIE which is currently being generated. */
220 static unsigned current_dienum;
222 /* Number to use for the special "pubname" label on the next DIE which
223 represents a function or data object defined in this compilation
224 unit which has "extern" linkage. */
226 static int next_pubname_number = 0;
228 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
230 /* Pointer to a dynamically allocated list of pre-reserved and still
231 pending sibling DIE numbers. Note that this list will grow as needed. */
233 static unsigned *pending_sibling_stack;
235 /* Counter to keep track of the number of pre-reserved and still pending
236 sibling DIE numbers. */
238 static unsigned pending_siblings;
240 /* The currently allocated size of the above list (expressed in number of
243 static unsigned pending_siblings_allocated;
245 /* Size (in elements) of increments by which we may expand the pending
246 sibling stack. Actually, a single hunk of space of this size should
247 be enough for most typical programs. */
249 #define PENDING_SIBLINGS_INCREMENT 64
251 /* Non-zero if we are performing our file-scope finalization pass and if
252 we should force out Dwarf descriptions of any and all file-scope
253 tagged types which are still incomplete types. */
255 static int finalizing = 0;
257 /* A pointer to the base of a list of pending types which we haven't
258 generated DIEs for yet, but which we will have to come back to
261 static tree *pending_types_list;
263 /* Number of elements currently allocated for the pending_types_list. */
265 static unsigned pending_types_allocated;
267 /* Number of elements of pending_types_list currently in use. */
269 static unsigned pending_types;
271 /* Size (in elements) of increments by which we may expand the pending
272 types list. Actually, a single hunk of space of this size should
273 be enough for most typical programs. */
275 #define PENDING_TYPES_INCREMENT 64
277 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
278 This is used in a hack to help us get the DIEs describing types of
279 formal parameters to come *after* all of the DIEs describing the formal
280 parameters themselves. That's necessary in order to be compatible
281 with what the brain-damaged svr4 SDB debugger requires. */
283 static tree fake_containing_scope;
285 /* The number of the current function definition that we are generating
286 debugging information for. These numbers range from 1 up to the maximum
287 number of function definitions contained within the current compilation
288 unit. These numbers are used to create unique labels for various things
289 contained within various function definitions. */
291 static unsigned current_funcdef_number = 1;
293 /* A pointer to the ..._DECL node which we have most recently been working
294 on. We keep this around just in case something about it looks screwy
295 and we want to tell the user what the source coordinates for the actual
298 static tree dwarf_last_decl;
300 /* A flag indicating that we are emitting the member declarations of a
301 class, so member functions and variables should not be entirely emitted.
302 This is a kludge to avoid passing a second argument to output_*_die. */
306 /* Forward declarations for functions defined in this file. */
308 static char *dwarf_tag_name PROTO((unsigned));
309 static char *dwarf_attr_name PROTO((unsigned));
310 static char *dwarf_stack_op_name PROTO((unsigned));
311 static char *dwarf_typemod_name PROTO((unsigned));
312 static char *dwarf_fmt_byte_name PROTO((unsigned));
313 static char *dwarf_fund_type_name PROTO((unsigned));
314 static tree decl_ultimate_origin PROTO((tree));
315 static tree block_ultimate_origin PROTO((tree));
316 static tree decl_class_context PROTO((tree));
317 static void output_unsigned_leb128 PROTO((unsigned long));
318 static void output_signed_leb128 PROTO((long));
319 static inline int is_body_block PROTO((tree));
320 static int fundamental_type_code PROTO((tree));
321 static tree root_type_1 PROTO((tree, int));
322 static tree root_type PROTO((tree));
323 static void write_modifier_bytes_1 PROTO((tree, int, int, int));
324 static void write_modifier_bytes PROTO((tree, int, int));
325 static inline int type_is_fundamental PROTO((tree));
326 static void equate_decl_number_to_die_number PROTO((tree));
327 static inline void equate_type_number_to_die_number PROTO((tree));
328 static void output_reg_number PROTO((rtx));
329 static void output_mem_loc_descriptor PROTO((rtx));
330 static void output_loc_descriptor PROTO((rtx));
331 static void output_bound_representation PROTO((tree, unsigned, int));
332 static void output_enumeral_list PROTO((tree));
333 static inline unsigned ceiling PROTO((unsigned, unsigned));
334 static inline tree field_type PROTO((tree));
335 static inline unsigned simple_type_align_in_bits PROTO((tree));
336 static inline unsigned simple_type_size_in_bits PROTO((tree));
337 static unsigned field_byte_offset PROTO((tree));
338 static inline void sibling_attribute PROTO((void));
339 static void location_attribute PROTO((rtx));
340 static void data_member_location_attribute PROTO((tree));
341 static void const_value_attribute PROTO((rtx));
342 static void location_or_const_value_attribute PROTO((tree));
343 static inline void name_attribute PROTO((char *));
344 static inline void fund_type_attribute PROTO((unsigned));
345 static void mod_fund_type_attribute PROTO((tree, int, int));
346 static inline void user_def_type_attribute PROTO((tree));
347 static void mod_u_d_type_attribute PROTO((tree, int, int));
348 #ifdef USE_ORDERING_ATTRIBUTE
349 static inline void ordering_attribute PROTO((unsigned));
350 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
351 static void subscript_data_attribute PROTO((tree));
352 static void byte_size_attribute PROTO((tree));
353 static inline void bit_offset_attribute PROTO((tree));
354 static inline void bit_size_attribute PROTO((tree));
355 static inline void element_list_attribute PROTO((tree));
356 static inline void stmt_list_attribute PROTO((char *));
357 static inline void low_pc_attribute PROTO((char *));
358 static inline void high_pc_attribute PROTO((char *));
359 static inline void body_begin_attribute PROTO((char *));
360 static inline void body_end_attribute PROTO((char *));
361 static inline void language_attribute PROTO((unsigned));
362 static inline void member_attribute PROTO((tree));
363 static inline void string_length_attribute PROTO((tree));
364 static inline void comp_dir_attribute PROTO((char *));
365 static inline void sf_names_attribute PROTO((char *));
366 static inline void src_info_attribute PROTO((char *));
367 static inline void mac_info_attribute PROTO((char *));
368 static inline void prototyped_attribute PROTO((tree));
369 static inline void producer_attribute PROTO((char *));
370 static inline void inline_attribute PROTO((tree));
371 static inline void containing_type_attribute PROTO((tree));
372 static inline void abstract_origin_attribute PROTO((tree));
373 #ifdef DWARF_DECL_COORDINATES
374 static inline void src_coords_attribute PROTO((unsigned, unsigned));
375 #endif /* defined(DWARF_DECL_COORDINATES) */
376 static inline void pure_or_virtual_attribute PROTO((tree));
377 static void name_and_src_coords_attributes PROTO((tree));
378 static void type_attribute PROTO((tree, int, int));
379 static char *type_tag PROTO((tree));
380 static inline void dienum_push PROTO((void));
381 static inline void dienum_pop PROTO((void));
382 static inline tree member_declared_type PROTO((tree));
383 static char *function_start_label PROTO((tree));
384 static void output_array_type_die PROTO((void *));
385 static void output_set_type_die PROTO((void *));
387 static void output_entry_point_die PROTO((void *));
389 static void output_inlined_enumeration_type_die PROTO((void *));
390 static void output_inlined_structure_type_die PROTO((void *));
391 static void output_inlined_union_type_die PROTO((void *));
392 static void output_enumeration_type_die PROTO((void *));
393 static void output_formal_parameter_die PROTO((void *));
394 static void output_global_subroutine_die PROTO((void *));
395 static void output_global_variable_die PROTO((void *));
396 static void output_label_die PROTO((void *));
397 static void output_lexical_block_die PROTO((void *));
398 static void output_inlined_subroutine_die PROTO((void *));
399 static void output_local_variable_die PROTO((void *));
400 static void output_member_die PROTO((void *));
402 static void output_pointer_type_die PROTO((void *));
403 static void output_reference_type_die PROTO((void *));
405 static void output_ptr_to_mbr_type_die PROTO((void *));
406 static void output_compile_unit_die PROTO((void *));
407 static void output_string_type_die PROTO((void *));
408 static void output_inheritance_die PROTO((void *));
409 static void output_structure_type_die PROTO((void *));
410 static void output_local_subroutine_die PROTO((void *));
411 static void output_subroutine_type_die PROTO((void *));
412 static void output_typedef_die PROTO((void *));
413 static void output_union_type_die PROTO((void *));
414 static void output_unspecified_parameters_die PROTO((void *));
415 static void output_padded_null_die PROTO((void *));
416 static void output_die PROTO((void (*) (), void *));
417 static void end_sibling_chain PROTO((void));
418 static void output_formal_types PROTO((tree));
419 static void pend_type PROTO((tree));
420 static int type_ok_for_scope PROTO((tree, tree));
421 static void output_pending_types_for_scope PROTO((tree));
422 static void output_type PROTO((tree, tree));
423 static void output_tagged_type_instantiation PROTO((tree));
424 static void output_block PROTO((tree, int));
425 static void output_decls_for_scope PROTO((tree, int));
426 static void output_decl PROTO((tree, tree));
427 static void shuffle_filename_entry PROTO((filename_entry *));
428 static void generate_new_sfname_entry PROTO((void));
429 static unsigned lookup_filename PROTO((char *));
430 static void generate_srcinfo_entry PROTO((unsigned, unsigned));
431 static void generate_macinfo_entry PROTO((char *, char *));
433 /* Definitions of defaults for assembler-dependent names of various
434 pseudo-ops and section names.
436 Theses may be overridden in your tm.h file (if necessary) for your
437 particular assembler. The default values provided here correspond to
438 what is expected by "standard" AT&T System V.4 assemblers. */
441 #define FILE_ASM_OP ".file"
443 #ifndef VERSION_ASM_OP
444 #define VERSION_ASM_OP ".version"
446 #ifndef UNALIGNED_SHORT_ASM_OP
447 #define UNALIGNED_SHORT_ASM_OP ".2byte"
449 #ifndef UNALIGNED_INT_ASM_OP
450 #define UNALIGNED_INT_ASM_OP ".4byte"
453 #define ASM_BYTE_OP ".byte"
456 #define SET_ASM_OP ".set"
459 /* Pseudo-ops for pushing the current section onto the section stack (and
460 simultaneously changing to a new section) and for poping back to the
461 section we were in immediately before this one. Note that most svr4
462 assemblers only maintain a one level stack... you can push all the
463 sections you want, but you can only pop out one level. (The sparc
464 svr4 assembler is an exception to this general rule.) That's
465 OK because we only use at most one level of the section stack herein. */
467 #ifndef PUSHSECTION_ASM_OP
468 #define PUSHSECTION_ASM_OP ".section"
470 #ifndef POPSECTION_ASM_OP
471 #define POPSECTION_ASM_OP ".previous"
474 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
475 to print the PUSHSECTION_ASM_OP and the section name. The default here
476 works for almost all svr4 assemblers, except for the sparc, where the
477 section name must be enclosed in double quotes. (See sparcv4.h.) */
479 #ifndef PUSHSECTION_FORMAT
480 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
483 #ifndef DEBUG_SECTION
484 #define DEBUG_SECTION ".debug"
487 #define LINE_SECTION ".line"
489 #ifndef SFNAMES_SECTION
490 #define SFNAMES_SECTION ".debug_sfnames"
492 #ifndef SRCINFO_SECTION
493 #define SRCINFO_SECTION ".debug_srcinfo"
495 #ifndef MACINFO_SECTION
496 #define MACINFO_SECTION ".debug_macinfo"
498 #ifndef PUBNAMES_SECTION
499 #define PUBNAMES_SECTION ".debug_pubnames"
501 #ifndef ARANGES_SECTION
502 #define ARANGES_SECTION ".debug_aranges"
505 #define TEXT_SECTION ".text"
508 #define DATA_SECTION ".data"
510 #ifndef DATA1_SECTION
511 #define DATA1_SECTION ".data1"
513 #ifndef RODATA_SECTION
514 #define RODATA_SECTION ".rodata"
516 #ifndef RODATA1_SECTION
517 #define RODATA1_SECTION ".rodata1"
520 #define BSS_SECTION ".bss"
523 /* Definitions of defaults for formats and names of various special
524 (artificial) labels which may be generated within this file (when
525 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
527 If necessary, these may be overridden from within your tm.h file,
528 but typically, you should never need to override these.
530 These labels have been hacked (temporarily) so that they all begin with
531 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
532 stock m88k/svr4 assembler, both of which need to see .L at the start of
533 a label in order to prevent that label from going into the linker symbol
534 table). When I get time, I'll have to fix this the right way so that we
535 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
536 but that will require a rather massive set of changes. For the moment,
537 the following definitions out to produce the right results for all svr4
538 and svr3 assemblers. -- rfg
541 #ifndef TEXT_BEGIN_LABEL
542 #define TEXT_BEGIN_LABEL "*.L_text_b"
544 #ifndef TEXT_END_LABEL
545 #define TEXT_END_LABEL "*.L_text_e"
548 #ifndef DATA_BEGIN_LABEL
549 #define DATA_BEGIN_LABEL "*.L_data_b"
551 #ifndef DATA_END_LABEL
552 #define DATA_END_LABEL "*.L_data_e"
555 #ifndef DATA1_BEGIN_LABEL
556 #define DATA1_BEGIN_LABEL "*.L_data1_b"
558 #ifndef DATA1_END_LABEL
559 #define DATA1_END_LABEL "*.L_data1_e"
562 #ifndef RODATA_BEGIN_LABEL
563 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
565 #ifndef RODATA_END_LABEL
566 #define RODATA_END_LABEL "*.L_rodata_e"
569 #ifndef RODATA1_BEGIN_LABEL
570 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
572 #ifndef RODATA1_END_LABEL
573 #define RODATA1_END_LABEL "*.L_rodata1_e"
576 #ifndef BSS_BEGIN_LABEL
577 #define BSS_BEGIN_LABEL "*.L_bss_b"
579 #ifndef BSS_END_LABEL
580 #define BSS_END_LABEL "*.L_bss_e"
583 #ifndef LINE_BEGIN_LABEL
584 #define LINE_BEGIN_LABEL "*.L_line_b"
586 #ifndef LINE_LAST_ENTRY_LABEL
587 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
589 #ifndef LINE_END_LABEL
590 #define LINE_END_LABEL "*.L_line_e"
593 #ifndef DEBUG_BEGIN_LABEL
594 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
596 #ifndef SFNAMES_BEGIN_LABEL
597 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
599 #ifndef SRCINFO_BEGIN_LABEL
600 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
602 #ifndef MACINFO_BEGIN_LABEL
603 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
606 #ifndef DIE_BEGIN_LABEL_FMT
607 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
609 #ifndef DIE_END_LABEL_FMT
610 #define DIE_END_LABEL_FMT "*.L_D%u_e"
612 #ifndef PUB_DIE_LABEL_FMT
613 #define PUB_DIE_LABEL_FMT "*.L_P%u"
615 #ifndef INSN_LABEL_FMT
616 #define INSN_LABEL_FMT "*.L_I%u_%u"
618 #ifndef BLOCK_BEGIN_LABEL_FMT
619 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
621 #ifndef BLOCK_END_LABEL_FMT
622 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
624 #ifndef SS_BEGIN_LABEL_FMT
625 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
627 #ifndef SS_END_LABEL_FMT
628 #define SS_END_LABEL_FMT "*.L_s%u_e"
630 #ifndef EE_BEGIN_LABEL_FMT
631 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
633 #ifndef EE_END_LABEL_FMT
634 #define EE_END_LABEL_FMT "*.L_e%u_e"
636 #ifndef MT_BEGIN_LABEL_FMT
637 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
639 #ifndef MT_END_LABEL_FMT
640 #define MT_END_LABEL_FMT "*.L_t%u_e"
642 #ifndef LOC_BEGIN_LABEL_FMT
643 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
645 #ifndef LOC_END_LABEL_FMT
646 #define LOC_END_LABEL_FMT "*.L_l%u_e"
648 #ifndef BOUND_BEGIN_LABEL_FMT
649 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
651 #ifndef BOUND_END_LABEL_FMT
652 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
654 #ifndef DERIV_BEGIN_LABEL_FMT
655 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
657 #ifndef DERIV_END_LABEL_FMT
658 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
660 #ifndef SL_BEGIN_LABEL_FMT
661 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
663 #ifndef SL_END_LABEL_FMT
664 #define SL_END_LABEL_FMT "*.L_sl%u_e"
666 #ifndef BODY_BEGIN_LABEL_FMT
667 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
669 #ifndef BODY_END_LABEL_FMT
670 #define BODY_END_LABEL_FMT "*.L_b%u_e"
672 #ifndef FUNC_END_LABEL_FMT
673 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
675 #ifndef TYPE_NAME_FMT
676 #define TYPE_NAME_FMT "*.L_T%u"
678 #ifndef DECL_NAME_FMT
679 #define DECL_NAME_FMT "*.L_E%u"
681 #ifndef LINE_CODE_LABEL_FMT
682 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
684 #ifndef SFNAMES_ENTRY_LABEL_FMT
685 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
687 #ifndef LINE_ENTRY_LABEL_FMT
688 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
691 /* Definitions of defaults for various types of primitive assembly language
694 If necessary, these may be overridden from within your tm.h file,
695 but typically, you shouldn't need to override these. */
697 #ifndef ASM_OUTPUT_PUSH_SECTION
698 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
699 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
702 #ifndef ASM_OUTPUT_POP_SECTION
703 #define ASM_OUTPUT_POP_SECTION(FILE) \
704 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
707 #ifndef ASM_OUTPUT_DWARF_DELTA2
708 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
709 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
710 assemble_name (FILE, LABEL1); \
711 fprintf (FILE, "-"); \
712 assemble_name (FILE, LABEL2); \
713 fprintf (FILE, "\n"); \
717 #ifndef ASM_OUTPUT_DWARF_DELTA4
718 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
719 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
720 assemble_name (FILE, LABEL1); \
721 fprintf (FILE, "-"); \
722 assemble_name (FILE, LABEL2); \
723 fprintf (FILE, "\n"); \
727 #ifndef ASM_OUTPUT_DWARF_TAG
728 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
730 fprintf ((FILE), "\t%s\t0x%x", \
731 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
732 if (flag_debug_asm) \
733 fprintf ((FILE), "\t%s %s", \
734 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
735 fputc ('\n', (FILE)); \
739 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
740 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
742 fprintf ((FILE), "\t%s\t0x%x", \
743 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
744 if (flag_debug_asm) \
745 fprintf ((FILE), "\t%s %s", \
746 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
747 fputc ('\n', (FILE)); \
751 #ifndef ASM_OUTPUT_DWARF_STACK_OP
752 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
754 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
755 if (flag_debug_asm) \
756 fprintf ((FILE), "\t%s %s", \
757 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
758 fputc ('\n', (FILE)); \
762 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
763 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
765 fprintf ((FILE), "\t%s\t0x%x", \
766 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
767 if (flag_debug_asm) \
768 fprintf ((FILE), "\t%s %s", \
769 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
770 fputc ('\n', (FILE)); \
774 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
775 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
777 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
778 if (flag_debug_asm) \
779 fprintf ((FILE), "\t%s %s", \
780 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
781 fputc ('\n', (FILE)); \
785 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
786 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
788 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
789 if (flag_debug_asm) \
790 fprintf ((FILE), "\t%s %s", \
791 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
792 fputc ('\n', (FILE)); \
796 #ifndef ASM_OUTPUT_DWARF_ADDR
797 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
798 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
799 assemble_name (FILE, LABEL); \
800 fprintf (FILE, "\n"); \
804 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
805 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
807 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
808 output_addr_const ((FILE), (RTX)); \
809 fputc ('\n', (FILE)); \
813 #ifndef ASM_OUTPUT_DWARF_REF
814 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
815 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
816 assemble_name (FILE, LABEL); \
817 fprintf (FILE, "\n"); \
821 #ifndef ASM_OUTPUT_DWARF_DATA1
822 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
823 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
826 #ifndef ASM_OUTPUT_DWARF_DATA2
827 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
828 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
831 #ifndef ASM_OUTPUT_DWARF_DATA4
832 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
833 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
836 #ifndef ASM_OUTPUT_DWARF_DATA8
837 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
839 if (WORDS_BIG_ENDIAN) \
841 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
842 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
846 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
847 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
852 #ifndef ASM_OUTPUT_DWARF_STRING
853 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
854 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
857 /************************ general utility functions **************************/
863 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
864 || ((GET_CODE (rtl) == SUBREG)
865 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
869 type_main_variant (type)
872 type = TYPE_MAIN_VARIANT (type);
874 /* There really should be only one main variant among any group of variants
875 of a given type (and all of the MAIN_VARIANT values for all members of
876 the group should point to that one type) but sometimes the C front-end
877 messes this up for array types, so we work around that bug here. */
879 if (TREE_CODE (type) == ARRAY_TYPE)
881 while (type != TYPE_MAIN_VARIANT (type))
882 type = TYPE_MAIN_VARIANT (type);
888 /* Return non-zero if the given type node represents a tagged type. */
891 is_tagged_type (type)
894 register enum tree_code code = TREE_CODE (type);
896 return (code == RECORD_TYPE || code == UNION_TYPE
897 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
902 register unsigned tag;
906 case TAG_padding: return "TAG_padding";
907 case TAG_array_type: return "TAG_array_type";
908 case TAG_class_type: return "TAG_class_type";
909 case TAG_entry_point: return "TAG_entry_point";
910 case TAG_enumeration_type: return "TAG_enumeration_type";
911 case TAG_formal_parameter: return "TAG_formal_parameter";
912 case TAG_global_subroutine: return "TAG_global_subroutine";
913 case TAG_global_variable: return "TAG_global_variable";
914 case TAG_label: return "TAG_label";
915 case TAG_lexical_block: return "TAG_lexical_block";
916 case TAG_local_variable: return "TAG_local_variable";
917 case TAG_member: return "TAG_member";
918 case TAG_pointer_type: return "TAG_pointer_type";
919 case TAG_reference_type: return "TAG_reference_type";
920 case TAG_compile_unit: return "TAG_compile_unit";
921 case TAG_string_type: return "TAG_string_type";
922 case TAG_structure_type: return "TAG_structure_type";
923 case TAG_subroutine: return "TAG_subroutine";
924 case TAG_subroutine_type: return "TAG_subroutine_type";
925 case TAG_typedef: return "TAG_typedef";
926 case TAG_union_type: return "TAG_union_type";
927 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
928 case TAG_variant: return "TAG_variant";
929 case TAG_common_block: return "TAG_common_block";
930 case TAG_common_inclusion: return "TAG_common_inclusion";
931 case TAG_inheritance: return "TAG_inheritance";
932 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
933 case TAG_module: return "TAG_module";
934 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
935 case TAG_set_type: return "TAG_set_type";
936 case TAG_subrange_type: return "TAG_subrange_type";
937 case TAG_with_stmt: return "TAG_with_stmt";
939 /* GNU extensions. */
941 case TAG_format_label: return "TAG_format_label";
942 case TAG_namelist: return "TAG_namelist";
943 case TAG_function_template: return "TAG_function_template";
944 case TAG_class_template: return "TAG_class_template";
946 default: return "TAG_<unknown>";
951 dwarf_attr_name (attr)
952 register unsigned attr;
956 case AT_sibling: return "AT_sibling";
957 case AT_location: return "AT_location";
958 case AT_name: return "AT_name";
959 case AT_fund_type: return "AT_fund_type";
960 case AT_mod_fund_type: return "AT_mod_fund_type";
961 case AT_user_def_type: return "AT_user_def_type";
962 case AT_mod_u_d_type: return "AT_mod_u_d_type";
963 case AT_ordering: return "AT_ordering";
964 case AT_subscr_data: return "AT_subscr_data";
965 case AT_byte_size: return "AT_byte_size";
966 case AT_bit_offset: return "AT_bit_offset";
967 case AT_bit_size: return "AT_bit_size";
968 case AT_element_list: return "AT_element_list";
969 case AT_stmt_list: return "AT_stmt_list";
970 case AT_low_pc: return "AT_low_pc";
971 case AT_high_pc: return "AT_high_pc";
972 case AT_language: return "AT_language";
973 case AT_member: return "AT_member";
974 case AT_discr: return "AT_discr";
975 case AT_discr_value: return "AT_discr_value";
976 case AT_string_length: return "AT_string_length";
977 case AT_common_reference: return "AT_common_reference";
978 case AT_comp_dir: return "AT_comp_dir";
979 case AT_const_value_string: return "AT_const_value_string";
980 case AT_const_value_data2: return "AT_const_value_data2";
981 case AT_const_value_data4: return "AT_const_value_data4";
982 case AT_const_value_data8: return "AT_const_value_data8";
983 case AT_const_value_block2: return "AT_const_value_block2";
984 case AT_const_value_block4: return "AT_const_value_block4";
985 case AT_containing_type: return "AT_containing_type";
986 case AT_default_value_addr: return "AT_default_value_addr";
987 case AT_default_value_data2: return "AT_default_value_data2";
988 case AT_default_value_data4: return "AT_default_value_data4";
989 case AT_default_value_data8: return "AT_default_value_data8";
990 case AT_default_value_string: return "AT_default_value_string";
991 case AT_friends: return "AT_friends";
992 case AT_inline: return "AT_inline";
993 case AT_is_optional: return "AT_is_optional";
994 case AT_lower_bound_ref: return "AT_lower_bound_ref";
995 case AT_lower_bound_data2: return "AT_lower_bound_data2";
996 case AT_lower_bound_data4: return "AT_lower_bound_data4";
997 case AT_lower_bound_data8: return "AT_lower_bound_data8";
998 case AT_private: return "AT_private";
999 case AT_producer: return "AT_producer";
1000 case AT_program: return "AT_program";
1001 case AT_protected: return "AT_protected";
1002 case AT_prototyped: return "AT_prototyped";
1003 case AT_public: return "AT_public";
1004 case AT_pure_virtual: return "AT_pure_virtual";
1005 case AT_return_addr: return "AT_return_addr";
1006 case AT_abstract_origin: return "AT_abstract_origin";
1007 case AT_start_scope: return "AT_start_scope";
1008 case AT_stride_size: return "AT_stride_size";
1009 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1010 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1011 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1012 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1013 case AT_virtual: return "AT_virtual";
1015 /* GNU extensions */
1017 case AT_sf_names: return "AT_sf_names";
1018 case AT_src_info: return "AT_src_info";
1019 case AT_mac_info: return "AT_mac_info";
1020 case AT_src_coords: return "AT_src_coords";
1021 case AT_body_begin: return "AT_body_begin";
1022 case AT_body_end: return "AT_body_end";
1024 default: return "AT_<unknown>";
1029 dwarf_stack_op_name (op)
1030 register unsigned op;
1034 case OP_REG: return "OP_REG";
1035 case OP_BASEREG: return "OP_BASEREG";
1036 case OP_ADDR: return "OP_ADDR";
1037 case OP_CONST: return "OP_CONST";
1038 case OP_DEREF2: return "OP_DEREF2";
1039 case OP_DEREF4: return "OP_DEREF4";
1040 case OP_ADD: return "OP_ADD";
1041 default: return "OP_<unknown>";
1046 dwarf_typemod_name (mod)
1047 register unsigned mod;
1051 case MOD_pointer_to: return "MOD_pointer_to";
1052 case MOD_reference_to: return "MOD_reference_to";
1053 case MOD_const: return "MOD_const";
1054 case MOD_volatile: return "MOD_volatile";
1055 default: return "MOD_<unknown>";
1060 dwarf_fmt_byte_name (fmt)
1061 register unsigned fmt;
1065 case FMT_FT_C_C: return "FMT_FT_C_C";
1066 case FMT_FT_C_X: return "FMT_FT_C_X";
1067 case FMT_FT_X_C: return "FMT_FT_X_C";
1068 case FMT_FT_X_X: return "FMT_FT_X_X";
1069 case FMT_UT_C_C: return "FMT_UT_C_C";
1070 case FMT_UT_C_X: return "FMT_UT_C_X";
1071 case FMT_UT_X_C: return "FMT_UT_X_C";
1072 case FMT_UT_X_X: return "FMT_UT_X_X";
1073 case FMT_ET: return "FMT_ET";
1074 default: return "FMT_<unknown>";
1079 dwarf_fund_type_name (ft)
1080 register unsigned ft;
1084 case FT_char: return "FT_char";
1085 case FT_signed_char: return "FT_signed_char";
1086 case FT_unsigned_char: return "FT_unsigned_char";
1087 case FT_short: return "FT_short";
1088 case FT_signed_short: return "FT_signed_short";
1089 case FT_unsigned_short: return "FT_unsigned_short";
1090 case FT_integer: return "FT_integer";
1091 case FT_signed_integer: return "FT_signed_integer";
1092 case FT_unsigned_integer: return "FT_unsigned_integer";
1093 case FT_long: return "FT_long";
1094 case FT_signed_long: return "FT_signed_long";
1095 case FT_unsigned_long: return "FT_unsigned_long";
1096 case FT_pointer: return "FT_pointer";
1097 case FT_float: return "FT_float";
1098 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1099 case FT_ext_prec_float: return "FT_ext_prec_float";
1100 case FT_complex: return "FT_complex";
1101 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1102 case FT_void: return "FT_void";
1103 case FT_boolean: return "FT_boolean";
1104 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1105 case FT_label: return "FT_label";
1107 /* GNU extensions. */
1109 case FT_long_long: return "FT_long_long";
1110 case FT_signed_long_long: return "FT_signed_long_long";
1111 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1113 case FT_int8: return "FT_int8";
1114 case FT_signed_int8: return "FT_signed_int8";
1115 case FT_unsigned_int8: return "FT_unsigned_int8";
1116 case FT_int16: return "FT_int16";
1117 case FT_signed_int16: return "FT_signed_int16";
1118 case FT_unsigned_int16: return "FT_unsigned_int16";
1119 case FT_int32: return "FT_int32";
1120 case FT_signed_int32: return "FT_signed_int32";
1121 case FT_unsigned_int32: return "FT_unsigned_int32";
1122 case FT_int64: return "FT_int64";
1123 case FT_signed_int64: return "FT_signed_int64";
1124 case FT_unsigned_int64: return "FT_unsigned_int64";
1126 case FT_real32: return "FT_real32";
1127 case FT_real64: return "FT_real64";
1128 case FT_real96: return "FT_real96";
1129 case FT_real128: return "FT_real128";
1131 default: return "FT_<unknown>";
1135 /* Determine the "ultimate origin" of a decl. The decl may be an
1136 inlined instance of an inlined instance of a decl which is local
1137 to an inline function, so we have to trace all of the way back
1138 through the origin chain to find out what sort of node actually
1139 served as the original seed for the given block. */
1142 decl_ultimate_origin (decl)
1145 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1147 if (immediate_origin == NULL)
1151 register tree ret_val;
1152 register tree lookahead = immediate_origin;
1156 ret_val = lookahead;
1157 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1159 while (lookahead != NULL && lookahead != ret_val);
1164 /* Determine the "ultimate origin" of a block. The block may be an
1165 inlined instance of an inlined instance of a block which is local
1166 to an inline function, so we have to trace all of the way back
1167 through the origin chain to find out what sort of node actually
1168 served as the original seed for the given block. */
1171 block_ultimate_origin (block)
1172 register tree block;
1174 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1176 if (immediate_origin == NULL)
1180 register tree ret_val;
1181 register tree lookahead = immediate_origin;
1185 ret_val = lookahead;
1186 lookahead = (TREE_CODE (ret_val) == BLOCK)
1187 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1190 while (lookahead != NULL && lookahead != ret_val);
1195 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1196 of a virtual function may refer to a base class, so we check the 'this'
1200 decl_class_context (decl)
1203 tree context = NULL_TREE;
1204 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1205 context = DECL_CONTEXT (decl);
1207 context = TYPE_MAIN_VARIANT
1208 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1210 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1211 context = NULL_TREE;
1217 output_unsigned_leb128 (value)
1218 register unsigned long value;
1220 register unsigned long orig_value = value;
1224 register unsigned byte = (value & 0x7f);
1227 if (value != 0) /* more bytes to follow */
1229 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1230 if (flag_debug_asm && value == 0)
1231 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1232 ASM_COMMENT_START, orig_value);
1233 fputc ('\n', asm_out_file);
1239 output_signed_leb128 (value)
1240 register long value;
1242 register long orig_value = value;
1243 register int negative = (value < 0);
1248 register unsigned byte = (value & 0x7f);
1252 value |= 0xfe000000; /* manually sign extend */
1253 if (((value == 0) && ((byte & 0x40) == 0))
1254 || ((value == -1) && ((byte & 0x40) == 1)))
1261 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1262 if (flag_debug_asm && more == 0)
1263 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1264 ASM_COMMENT_START, orig_value);
1265 fputc ('\n', asm_out_file);
1270 /**************** utility functions for attribute functions ******************/
1272 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1273 node in question represents the outermost pair of curly braces (i.e.
1274 the "body block") of a function or method.
1276 For any BLOCK node representing a "body block" of a function or method,
1277 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1278 which represents the outermost (function) scope for the function or
1279 method (i.e. the one which includes the formal parameters). The
1280 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1285 is_body_block (stmt)
1288 if (TREE_CODE (stmt) == BLOCK)
1290 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1292 if (TREE_CODE (parent) == BLOCK)
1294 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1296 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1303 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1304 type code for the given type.
1306 This routine must only be called for GCC type nodes that correspond to
1307 Dwarf fundamental types.
1309 The current Dwarf draft specification calls for Dwarf fundamental types
1310 to accurately reflect the fact that a given type was either a "plain"
1311 integral type or an explicitly "signed" integral type. Unfortunately,
1312 we can't always do this, because GCC may already have thrown away the
1313 information about the precise way in which the type was originally
1316 typedef signed int my_type;
1318 struct s { my_type f; };
1320 Since we may be stuck here without enought information to do exactly
1321 what is called for in the Dwarf draft specification, we do the best
1322 that we can under the circumstances and always use the "plain" integral
1323 fundamental type codes for int, short, and long types. That's probably
1324 good enough. The additional accuracy called for in the current DWARF
1325 draft specification is probably never even useful in practice. */
1328 fundamental_type_code (type)
1331 if (TREE_CODE (type) == ERROR_MARK)
1334 switch (TREE_CODE (type))
1343 /* Carefully distinguish all the standard types of C,
1344 without messing up if the language is not C.
1345 Note that we check only for the names that contain spaces;
1346 other names might occur by coincidence in other languages. */
1347 if (TYPE_NAME (type) != 0
1348 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1349 && DECL_NAME (TYPE_NAME (type)) != 0
1350 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1352 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1354 if (!strcmp (name, "unsigned char"))
1355 return FT_unsigned_char;
1356 if (!strcmp (name, "signed char"))
1357 return FT_signed_char;
1358 if (!strcmp (name, "unsigned int"))
1359 return FT_unsigned_integer;
1360 if (!strcmp (name, "short int"))
1362 if (!strcmp (name, "short unsigned int"))
1363 return FT_unsigned_short;
1364 if (!strcmp (name, "long int"))
1366 if (!strcmp (name, "long unsigned int"))
1367 return FT_unsigned_long;
1368 if (!strcmp (name, "long long int"))
1369 return FT_long_long; /* Not grok'ed by svr4 SDB */
1370 if (!strcmp (name, "long long unsigned int"))
1371 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1374 /* Most integer types will be sorted out above, however, for the
1375 sake of special `array index' integer types, the following code
1376 is also provided. */
1378 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1379 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1381 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1382 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1384 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1385 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1387 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1388 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1390 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1391 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1396 /* Carefully distinguish all the standard types of C,
1397 without messing up if the language is not C. */
1398 if (TYPE_NAME (type) != 0
1399 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1400 && DECL_NAME (TYPE_NAME (type)) != 0
1401 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1403 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1405 /* Note that here we can run afowl of a serious bug in "classic"
1406 svr4 SDB debuggers. They don't seem to understand the
1407 FT_ext_prec_float type (even though they should). */
1409 if (!strcmp (name, "long double"))
1410 return FT_ext_prec_float;
1413 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1414 return FT_dbl_prec_float;
1415 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1418 /* Note that here we can run afowl of a serious bug in "classic"
1419 svr4 SDB debuggers. They don't seem to understand the
1420 FT_ext_prec_float type (even though they should). */
1422 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1423 return FT_ext_prec_float;
1427 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1430 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1433 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1436 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1441 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1442 the Dwarf "root" type for the given input type. The Dwarf "root" type
1443 of a given type is generally the same as the given type, except that if
1444 the given type is a pointer or reference type, then the root type of
1445 the given type is the root type of the "basis" type for the pointer or
1446 reference type. (This definition of the "root" type is recursive.)
1447 Also, the root type of a `const' qualified type or a `volatile'
1448 qualified type is the root type of the given type without the
1452 root_type_1 (type, count)
1456 /* Give up after searching 1000 levels, in case this is a recursive
1457 pointer type. Such types are possible in Ada, but it is not possible
1458 to represent them in DWARF1 debug info. */
1460 return error_mark_node;
1462 switch (TREE_CODE (type))
1465 return error_mark_node;
1468 case REFERENCE_TYPE:
1469 return root_type_1 (TREE_TYPE (type), count+1);
1480 type = root_type_1 (type, 0);
1481 if (type != error_mark_node)
1482 type = type_main_variant (type);
1486 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1487 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1490 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1492 register int decl_const;
1493 register int decl_volatile;
1496 if (TREE_CODE (type) == ERROR_MARK)
1499 /* Give up after searching 1000 levels, in case this is a recursive
1500 pointer type. Such types are possible in Ada, but it is not possible
1501 to represent them in DWARF1 debug info. */
1505 if (TYPE_READONLY (type) || decl_const)
1506 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1507 if (TYPE_VOLATILE (type) || decl_volatile)
1508 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1509 switch (TREE_CODE (type))
1512 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1513 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1516 case REFERENCE_TYPE:
1517 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1518 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1528 write_modifier_bytes (type, decl_const, decl_volatile)
1530 register int decl_const;
1531 register int decl_volatile;
1533 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1536 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1537 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1540 type_is_fundamental (type)
1543 switch (TREE_CODE (type))
1558 case QUAL_UNION_TYPE:
1563 case REFERENCE_TYPE:
1575 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1576 equate directive which will associate a symbolic name with the current DIE.
1578 The name used is an artificial label generated from the DECL_UID number
1579 associated with the given decl node. The name it gets equated to is the
1580 symbolic label that we (previously) output at the start of the DIE that
1581 we are currently generating.
1583 Calling this function while generating some "decl related" form of DIE
1584 makes it possible to later refer to the DIE which represents the given
1585 decl simply by re-generating the symbolic name from the ..._DECL node's
1589 equate_decl_number_to_die_number (decl)
1592 /* In the case where we are generating a DIE for some ..._DECL node
1593 which represents either some inline function declaration or some
1594 entity declared within an inline function declaration/definition,
1595 setup a symbolic name for the current DIE so that we have a name
1596 for this DIE that we can easily refer to later on within
1597 AT_abstract_origin attributes. */
1599 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1600 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1602 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1603 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1604 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1607 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1608 equate directive which will associate a symbolic name with the current DIE.
1610 The name used is an artificial label generated from the TYPE_UID number
1611 associated with the given type node. The name it gets equated to is the
1612 symbolic label that we (previously) output at the start of the DIE that
1613 we are currently generating.
1615 Calling this function while generating some "type related" form of DIE
1616 makes it easy to later refer to the DIE which represents the given type
1617 simply by re-generating the alternative name from the ..._TYPE node's
1621 equate_type_number_to_die_number (type)
1624 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1625 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1627 /* We are generating a DIE to represent the main variant of this type
1628 (i.e the type without any const or volatile qualifiers) so in order
1629 to get the equate to come out right, we need to get the main variant
1632 type = type_main_variant (type);
1634 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1635 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1636 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1640 output_reg_number (rtl)
1643 register unsigned regno = REGNO (rtl);
1645 if (regno >= FIRST_PSEUDO_REGISTER)
1647 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1651 fprintf (asm_out_file, "\t%s\t0x%x",
1652 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1655 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1656 PRINT_REG (rtl, 0, asm_out_file);
1658 fputc ('\n', asm_out_file);
1661 /* The following routine is a nice and simple transducer. It converts the
1662 RTL for a variable or parameter (resident in memory) into an equivalent
1663 Dwarf representation of a mechanism for getting the address of that same
1664 variable onto the top of a hypothetical "address evaluation" stack.
1666 When creating memory location descriptors, we are effectively trans-
1667 forming the RTL for a memory-resident object into its Dwarf postfix
1668 expression equivalent. This routine just recursively descends an
1669 RTL tree, turning it into Dwarf postfix code as it goes. */
1672 output_mem_loc_descriptor (rtl)
1675 /* Note that for a dynamically sized array, the location we will
1676 generate a description of here will be the lowest numbered location
1677 which is actually within the array. That's *not* necessarily the
1678 same as the zeroth element of the array. */
1680 switch (GET_CODE (rtl))
1684 /* The case of a subreg may arise when we have a local (register)
1685 variable or a formal (register) parameter which doesn't quite
1686 fill up an entire register. For now, just assume that it is
1687 legitimate to make the Dwarf info refer to the whole register
1688 which contains the given subreg. */
1690 rtl = XEXP (rtl, 0);
1695 /* Whenever a register number forms a part of the description of
1696 the method for calculating the (dynamic) address of a memory
1697 resident object, DWARF rules require the register number to
1698 be referred to as a "base register". This distinction is not
1699 based in any way upon what category of register the hardware
1700 believes the given register belongs to. This is strictly
1701 DWARF terminology we're dealing with here.
1703 Note that in cases where the location of a memory-resident data
1704 object could be expressed as:
1706 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1708 the actual DWARF location descriptor that we generate may just
1709 be OP_BASEREG (basereg). This may look deceptively like the
1710 object in question was allocated to a register (rather than
1711 in memory) so DWARF consumers need to be aware of the subtle
1712 distinction between OP_REG and OP_BASEREG. */
1714 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1715 output_reg_number (rtl);
1719 output_mem_loc_descriptor (XEXP (rtl, 0));
1720 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1725 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1726 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1730 output_mem_loc_descriptor (XEXP (rtl, 0));
1731 output_mem_loc_descriptor (XEXP (rtl, 1));
1732 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1736 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1737 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1741 /* If a pseudo-reg is optimized away, it is possible for it to
1742 be replaced with a MEM containing a multiply. Use a GNU extension
1744 output_mem_loc_descriptor (XEXP (rtl, 0));
1745 output_mem_loc_descriptor (XEXP (rtl, 1));
1746 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1754 /* Output a proper Dwarf location descriptor for a variable or parameter
1755 which is either allocated in a register or in a memory location. For
1756 a register, we just generate an OP_REG and the register number. For a
1757 memory location we provide a Dwarf postfix expression describing how to
1758 generate the (dynamic) address of the object onto the address stack. */
1761 output_loc_descriptor (rtl)
1764 switch (GET_CODE (rtl))
1768 /* The case of a subreg may arise when we have a local (register)
1769 variable or a formal (register) parameter which doesn't quite
1770 fill up an entire register. For now, just assume that it is
1771 legitimate to make the Dwarf info refer to the whole register
1772 which contains the given subreg. */
1774 rtl = XEXP (rtl, 0);
1778 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1779 output_reg_number (rtl);
1783 output_mem_loc_descriptor (XEXP (rtl, 0));
1787 abort (); /* Should never happen */
1791 /* Given a tree node describing an array bound (either lower or upper)
1792 output a representation for that bound. */
1795 output_bound_representation (bound, dim_num, u_or_l)
1796 register tree bound;
1797 register unsigned dim_num; /* For multi-dimensional arrays. */
1798 register char u_or_l; /* Designates upper or lower bound. */
1800 switch (TREE_CODE (bound))
1806 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1809 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1810 (unsigned) TREE_INT_CST_LOW (bound));
1815 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1816 SAVE_EXPR nodes, in which case we can do something, or as
1817 an expression, which we cannot represent. */
1819 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1820 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1822 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1823 current_dienum, dim_num, u_or_l);
1825 sprintf (end_label, BOUND_END_LABEL_FMT,
1826 current_dienum, dim_num, u_or_l);
1828 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1829 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1831 /* If optimization is turned on, the SAVE_EXPRs that describe
1832 how to access the upper bound values are essentially bogus.
1833 They only describe (at best) how to get at these values at
1834 the points in the generated code right after they have just
1835 been computed. Worse yet, in the typical case, the upper
1836 bound values will not even *be* computed in the optimized
1837 code, so these SAVE_EXPRs are entirely bogus.
1839 In order to compensate for this fact, we check here to see
1840 if optimization is enabled, and if so, we effectively create
1841 an empty location description for the (unknown and unknowable)
1844 This should not cause too much trouble for existing (stupid?)
1845 debuggers because they have to deal with empty upper bounds
1846 location descriptions anyway in order to be able to deal with
1847 incomplete array types.
1849 Of course an intelligent debugger (GDB?) should be able to
1850 comprehend that a missing upper bound specification in a
1851 array type used for a storage class `auto' local array variable
1852 indicates that the upper bound is both unknown (at compile-
1853 time) and unknowable (at run-time) due to optimization. */
1857 while (TREE_CODE (bound) == NOP_EXPR
1858 || TREE_CODE (bound) == CONVERT_EXPR)
1859 bound = TREE_OPERAND (bound, 0);
1861 if (TREE_CODE (bound) == SAVE_EXPR)
1862 output_loc_descriptor
1863 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1866 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1873 /* Recursive function to output a sequence of value/name pairs for
1874 enumeration constants in reversed order. This is called from
1875 enumeration_type_die. */
1878 output_enumeral_list (link)
1883 output_enumeral_list (TREE_CHAIN (link));
1884 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1885 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1886 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1887 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1891 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1892 which is not less than the value itself. */
1894 static inline unsigned
1895 ceiling (value, boundary)
1896 register unsigned value;
1897 register unsigned boundary;
1899 return (((value + boundary - 1) / boundary) * boundary);
1902 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1903 pointer to the declared type for the relevant field variable, or return
1904 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1912 if (TREE_CODE (decl) == ERROR_MARK)
1913 return integer_type_node;
1915 type = DECL_BIT_FIELD_TYPE (decl);
1917 type = TREE_TYPE (decl);
1921 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1922 node, return the alignment in bits for the type, or else return
1923 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1925 static inline unsigned
1926 simple_type_align_in_bits (type)
1929 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1932 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1933 node, return the size in bits for the type if it is a constant, or
1934 else return the alignment for the type if the type's size is not
1935 constant, or else return BITS_PER_WORD if the type actually turns out
1936 to be an ERROR_MARK node. */
1938 static inline unsigned
1939 simple_type_size_in_bits (type)
1942 if (TREE_CODE (type) == ERROR_MARK)
1943 return BITS_PER_WORD;
1946 register tree type_size_tree = TYPE_SIZE (type);
1948 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1949 return TYPE_ALIGN (type);
1951 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1955 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1956 return the byte offset of the lowest addressed byte of the "containing
1957 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1958 mine what that offset is, either because the argument turns out to be a
1959 pointer to an ERROR_MARK node, or because the offset is actually variable.
1960 (We can't handle the latter case just yet.) */
1963 field_byte_offset (decl)
1966 register unsigned type_align_in_bytes;
1967 register unsigned type_align_in_bits;
1968 register unsigned type_size_in_bits;
1969 register unsigned object_offset_in_align_units;
1970 register unsigned object_offset_in_bits;
1971 register unsigned object_offset_in_bytes;
1973 register tree bitpos_tree;
1974 register tree field_size_tree;
1975 register unsigned bitpos_int;
1976 register unsigned deepest_bitpos;
1977 register unsigned field_size_in_bits;
1979 if (TREE_CODE (decl) == ERROR_MARK)
1982 if (TREE_CODE (decl) != FIELD_DECL)
1985 type = field_type (decl);
1987 bitpos_tree = DECL_FIELD_BITPOS (decl);
1988 field_size_tree = DECL_SIZE (decl);
1990 /* We cannot yet cope with fields whose positions or sizes are variable,
1991 so for now, when we see such things, we simply return 0. Someday,
1992 we may be able to handle such cases, but it will be damn difficult. */
1994 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1996 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1998 if (TREE_CODE (field_size_tree) != INTEGER_CST)
2000 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
2002 type_size_in_bits = simple_type_size_in_bits (type);
2004 type_align_in_bits = simple_type_align_in_bits (type);
2005 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2007 /* Note that the GCC front-end doesn't make any attempt to keep track
2008 of the starting bit offset (relative to the start of the containing
2009 structure type) of the hypothetical "containing object" for a bit-
2010 field. Thus, when computing the byte offset value for the start of
2011 the "containing object" of a bit-field, we must deduce this infor-
2014 This can be rather tricky to do in some cases. For example, handling
2015 the following structure type definition when compiling for an i386/i486
2016 target (which only aligns long long's to 32-bit boundaries) can be very
2021 long long field2:31;
2024 Fortunately, there is a simple rule-of-thumb which can be used in such
2025 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2026 the structure shown above. It decides to do this based upon one simple
2027 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2028 taining object" for each bit-field at the first (i.e. lowest addressed)
2029 legitimate alignment boundary (based upon the required minimum alignment
2030 for the declared type of the field) which it can possibly use, subject
2031 to the condition that there is still enough available space remaining
2032 in the containing object (when allocated at the selected point) to
2033 fully accommodate all of the bits of the bit-field itself.
2035 This simple rule makes it obvious why GCC allocates 8 bytes for each
2036 object of the structure type shown above. When looking for a place to
2037 allocate the "containing object" for `field2', the compiler simply tries
2038 to allocate a 64-bit "containing object" at each successive 32-bit
2039 boundary (starting at zero) until it finds a place to allocate that 64-
2040 bit field such that at least 31 contiguous (and previously unallocated)
2041 bits remain within that selected 64 bit field. (As it turns out, for
2042 the example above, the compiler finds that it is OK to allocate the
2043 "containing object" 64-bit field at bit-offset zero within the
2046 Here we attempt to work backwards from the limited set of facts we're
2047 given, and we try to deduce from those facts, where GCC must have
2048 believed that the containing object started (within the structure type).
2050 The value we deduce is then used (by the callers of this routine) to
2051 generate AT_location and AT_bit_offset attributes for fields (both
2052 bit-fields and, in the case of AT_location, regular fields as well).
2055 /* Figure out the bit-distance from the start of the structure to the
2056 "deepest" bit of the bit-field. */
2057 deepest_bitpos = bitpos_int + field_size_in_bits;
2059 /* This is the tricky part. Use some fancy footwork to deduce where the
2060 lowest addressed bit of the containing object must be. */
2061 object_offset_in_bits
2062 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2064 /* Compute the offset of the containing object in "alignment units". */
2065 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2067 /* Compute the offset of the containing object in bytes. */
2068 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2070 /* The above code assumes that the field does not cross an alignment
2071 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2072 or if the structure is packed. If this happens, then we get an object
2073 which starts after the bitfield, which means that the bit offset is
2074 negative. Gdb fails when given negative bit offsets. We avoid this
2075 by recomputing using the first bit of the bitfield. This will give
2076 us an object which does not completely contain the bitfield, but it
2077 will be aligned, and it will contain the first bit of the bitfield. */
2078 if (object_offset_in_bits > bitpos_int)
2080 deepest_bitpos = bitpos_int + 1;
2081 object_offset_in_bits
2082 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2083 object_offset_in_align_units = (object_offset_in_bits
2084 / type_align_in_bits);
2085 object_offset_in_bytes = (object_offset_in_align_units
2086 * type_align_in_bytes);
2089 return object_offset_in_bytes;
2092 /****************************** attributes *********************************/
2094 /* The following routines are responsible for writing out the various types
2095 of Dwarf attributes (and any following data bytes associated with them).
2096 These routines are listed in order based on the numerical codes of their
2097 associated attributes. */
2099 /* Generate an AT_sibling attribute. */
2102 sibling_attribute ()
2104 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2106 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2107 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2108 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2111 /* Output the form of location attributes suitable for whole variables and
2112 whole parameters. Note that the location attributes for struct fields
2113 are generated by the routine `data_member_location_attribute' below. */
2116 location_attribute (rtl)
2119 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2120 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2122 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2123 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2124 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2125 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2126 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2128 /* Handle a special case. If we are about to output a location descriptor
2129 for a variable or parameter which has been optimized out of existence,
2130 don't do that. Instead we output a zero-length location descriptor
2131 value as part of the location attribute.
2133 A variable which has been optimized out of existence will have a
2134 DECL_RTL value which denotes a pseudo-reg.
2136 Currently, in some rare cases, variables can have DECL_RTL values
2137 which look like (MEM (REG pseudo-reg#)). These cases are due to
2138 bugs elsewhere in the compiler. We treat such cases
2139 as if the variable(s) in question had been optimized out of existence.
2141 Note that in all cases where we wish to express the fact that a
2142 variable has been optimized out of existence, we do not simply
2143 suppress the generation of the entire location attribute because
2144 the absence of a location attribute in certain kinds of DIEs is
2145 used to indicate something else entirely... i.e. that the DIE
2146 represents an object declaration, but not a definition. So saith
2150 if (! is_pseudo_reg (rtl)
2151 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2152 output_loc_descriptor (rtl);
2154 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2157 /* Output the specialized form of location attribute used for data members
2158 of struct and union types.
2160 In the special case of a FIELD_DECL node which represents a bit-field,
2161 the "offset" part of this special location descriptor must indicate the
2162 distance in bytes from the lowest-addressed byte of the containing
2163 struct or union type to the lowest-addressed byte of the "containing
2164 object" for the bit-field. (See the `field_byte_offset' function above.)
2166 For any given bit-field, the "containing object" is a hypothetical
2167 object (of some integral or enum type) within which the given bit-field
2168 lives. The type of this hypothetical "containing object" is always the
2169 same as the declared type of the individual bit-field itself (for GCC
2170 anyway... the DWARF spec doesn't actually mandate this).
2172 Note that it is the size (in bytes) of the hypothetical "containing
2173 object" which will be given in the AT_byte_size attribute for this
2174 bit-field. (See the `byte_size_attribute' function below.) It is
2175 also used when calculating the value of the AT_bit_offset attribute.
2176 (See the `bit_offset_attribute' function below.) */
2179 data_member_location_attribute (t)
2182 register unsigned object_offset_in_bytes;
2183 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2184 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2186 if (TREE_CODE (t) == TREE_VEC)
2187 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2189 object_offset_in_bytes = field_byte_offset (t);
2191 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2192 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2193 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2194 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2195 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2196 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2197 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2198 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2199 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2202 /* Output an AT_const_value attribute for a variable or a parameter which
2203 does not have a "location" either in memory or in a register. These
2204 things can arise in GNU C when a constant is passed as an actual
2205 parameter to an inlined function. They can also arise in C++ where
2206 declared constants do not necessarily get memory "homes". */
2209 const_value_attribute (rtl)
2212 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2213 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2215 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2216 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2217 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2218 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2219 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2221 switch (GET_CODE (rtl))
2224 /* Note that a CONST_INT rtx could represent either an integer or
2225 a floating-point constant. A CONST_INT is used whenever the
2226 constant will fit into a single word. In all such cases, the
2227 original mode of the constant value is wiped out, and the
2228 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2229 precise mode information for these constants, we always just
2230 output them using 4 bytes. */
2232 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2236 /* Note that a CONST_DOUBLE rtx could represent either an integer
2237 or a floating-point constant. A CONST_DOUBLE is used whenever
2238 the constant requires more than one word in order to be adequately
2239 represented. In all such cases, the original mode of the constant
2240 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2241 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2243 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2244 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2245 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2249 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2255 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2259 /* In cases where an inlined instance of an inline function is passed
2260 the address of an `auto' variable (which is local to the caller)
2261 we can get a situation where the DECL_RTL of the artificial
2262 local variable (for the inlining) which acts as a stand-in for
2263 the corresponding formal parameter (of the inline function)
2264 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2265 This is not exactly a compile-time constant expression, but it
2266 isn't the address of the (artificial) local variable either.
2267 Rather, it represents the *value* which the artificial local
2268 variable always has during its lifetime. We currently have no
2269 way to represent such quasi-constant values in Dwarf, so for now
2270 we just punt and generate an AT_const_value attribute with form
2271 FORM_BLOCK4 and a length of zero. */
2275 abort (); /* No other kinds of rtx should be possible here. */
2278 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2281 /* Generate *either* an AT_location attribute or else an AT_const_value
2282 data attribute for a variable or a parameter. We generate the
2283 AT_const_value attribute only in those cases where the given
2284 variable or parameter does not have a true "location" either in
2285 memory or in a register. This can happen (for example) when a
2286 constant is passed as an actual argument in a call to an inline
2287 function. (It's possible that these things can crop up in other
2288 ways also.) Note that one type of constant value which can be
2289 passed into an inlined function is a constant pointer. This can
2290 happen for example if an actual argument in an inlined function
2291 call evaluates to a compile-time constant address. */
2294 location_or_const_value_attribute (decl)
2299 if (TREE_CODE (decl) == ERROR_MARK)
2302 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2304 /* Should never happen. */
2309 /* Here we have to decide where we are going to say the parameter "lives"
2310 (as far as the debugger is concerned). We only have a couple of choices.
2311 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2312 normally indicates where the parameter lives during most of the activa-
2313 tion of the function. If optimization is enabled however, this could
2314 be either NULL or else a pseudo-reg. Both of those cases indicate that
2315 the parameter doesn't really live anywhere (as far as the code generation
2316 parts of GCC are concerned) during most of the function's activation.
2317 That will happen (for example) if the parameter is never referenced
2318 within the function.
2320 We could just generate a location descriptor here for all non-NULL
2321 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2322 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2323 cases where DECL_RTL is NULL or is a pseudo-reg.
2325 Note however that we can only get away with using DECL_INCOMING_RTL as
2326 a backup substitute for DECL_RTL in certain limited cases. In cases
2327 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2328 we can be sure that the parameter was passed using the same type as it
2329 is declared to have within the function, and that its DECL_INCOMING_RTL
2330 points us to a place where a value of that type is passed. In cases
2331 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2332 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2333 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2334 points us to a value of some type which is *different* from the type
2335 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2336 to generate a location attribute in such cases, the debugger would
2337 end up (for example) trying to fetch a `float' from a place which
2338 actually contains the first part of a `double'. That would lead to
2339 really incorrect and confusing output at debug-time, and we don't
2340 want that now do we?
2342 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2343 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2344 couple of cute exceptions however. On little-endian machines we can
2345 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2346 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2347 an integral type which is smaller than TREE_TYPE(decl). These cases
2348 arise when (on a little-endian machine) a non-prototyped function has
2349 a parameter declared to be of type `short' or `char'. In such cases,
2350 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2351 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2352 passed `int' value. If the debugger then uses that address to fetch a
2353 `short' or a `char' (on a little-endian machine) the result will be the
2354 correct data, so we allow for such exceptional cases below.
2356 Note that our goal here is to describe the place where the given formal
2357 parameter lives during most of the function's activation (i.e. between
2358 the end of the prologue and the start of the epilogue). We'll do that
2359 as best as we can. Note however that if the given formal parameter is
2360 modified sometime during the execution of the function, then a stack
2361 backtrace (at debug-time) will show the function as having been called
2362 with the *new* value rather than the value which was originally passed
2363 in. This happens rarely enough that it is not a major problem, but it
2364 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2365 may generate two additional attributes for any given TAG_formal_parameter
2366 DIE which will describe the "passed type" and the "passed location" for
2367 the given formal parameter in addition to the attributes we now generate
2368 to indicate the "declared type" and the "active location" for each
2369 parameter. This additional set of attributes could be used by debuggers
2370 for stack backtraces.
2372 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2373 can be NULL also. This happens (for example) for inlined-instances of
2374 inline function formal parameters which are never referenced. This really
2375 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2376 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2377 these values for inlined instances of inline function parameters, so
2378 when we see such cases, we are just out-of-luck for the time
2379 being (until integrate.c gets fixed).
2382 /* Use DECL_RTL as the "location" unless we find something better. */
2383 rtl = DECL_RTL (decl);
2385 if (TREE_CODE (decl) == PARM_DECL)
2386 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2388 /* This decl represents a formal parameter which was optimized out. */
2389 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2390 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2392 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2393 *all* cases where (rtl == NULL_RTX) just below. */
2395 if (declared_type == passed_type)
2396 rtl = DECL_INCOMING_RTL (decl);
2397 else if (! BYTES_BIG_ENDIAN)
2398 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2399 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2400 rtl = DECL_INCOMING_RTL (decl);
2403 if (rtl == NULL_RTX)
2406 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2407 #ifdef LEAF_REG_REMAP
2409 leaf_renumber_regs_insn (rtl);
2412 switch (GET_CODE (rtl))
2415 /* The address of a variable that was optimized away; don't emit
2425 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2426 const_value_attribute (rtl);
2432 location_attribute (rtl);
2436 /* ??? CONCAT is used for complex variables, which may have the real
2437 part stored in one place and the imag part stored somewhere else.
2438 DWARF1 has no way to describe a variable that lives in two different
2439 places, so we just describe where the first part lives, and hope that
2440 the second part is stored after it. */
2441 location_attribute (XEXP (rtl, 0));
2445 abort (); /* Should never happen. */
2449 /* Generate an AT_name attribute given some string value to be included as
2450 the value of the attribute. */
2453 name_attribute (name_string)
2454 register char *name_string;
2456 if (name_string && *name_string)
2458 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2459 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2464 fund_type_attribute (ft_code)
2465 register unsigned ft_code;
2467 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2468 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2472 mod_fund_type_attribute (type, decl_const, decl_volatile)
2474 register int decl_const;
2475 register int decl_volatile;
2477 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2478 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2480 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2481 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2482 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2483 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2484 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2485 write_modifier_bytes (type, decl_const, decl_volatile);
2486 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2487 fundamental_type_code (root_type (type)));
2488 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2492 user_def_type_attribute (type)
2495 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2497 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2498 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2499 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2503 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2505 register int decl_const;
2506 register int decl_volatile;
2508 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2509 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2510 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2512 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2513 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2514 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2515 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2516 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2517 write_modifier_bytes (type, decl_const, decl_volatile);
2518 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2519 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2520 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2523 #ifdef USE_ORDERING_ATTRIBUTE
2525 ordering_attribute (ordering)
2526 register unsigned ordering;
2528 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2529 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2531 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2533 /* Note that the block of subscript information for an array type also
2534 includes information about the element type of type given array type. */
2537 subscript_data_attribute (type)
2540 register unsigned dimension_number;
2541 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2542 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2544 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2545 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2546 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2547 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2548 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2550 /* The GNU compilers represent multidimensional array types as sequences
2551 of one dimensional array types whose element types are themselves array
2552 types. Here we squish that down, so that each multidimensional array
2553 type gets only one array_type DIE in the Dwarf debugging info. The
2554 draft Dwarf specification say that we are allowed to do this kind
2555 of compression in C (because there is no difference between an
2556 array or arrays and a multidimensional array in C) but for other
2557 source languages (e.g. Ada) we probably shouldn't do this. */
2559 for (dimension_number = 0;
2560 TREE_CODE (type) == ARRAY_TYPE;
2561 type = TREE_TYPE (type), dimension_number++)
2563 register tree domain = TYPE_DOMAIN (type);
2565 /* Arrays come in three flavors. Unspecified bounds, fixed
2566 bounds, and (in GNU C only) variable bounds. Handle all
2567 three forms here. */
2571 /* We have an array type with specified bounds. */
2573 register tree lower = TYPE_MIN_VALUE (domain);
2574 register tree upper = TYPE_MAX_VALUE (domain);
2576 /* Handle only fundamental types as index types for now. */
2578 if (! type_is_fundamental (domain))
2581 /* Output the representation format byte for this dimension. */
2583 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2584 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2585 (upper && TREE_CODE (upper) == INTEGER_CST)));
2587 /* Output the index type for this dimension. */
2589 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2590 fundamental_type_code (domain));
2592 /* Output the representation for the lower bound. */
2594 output_bound_representation (lower, dimension_number, 'l');
2596 /* Output the representation for the upper bound. */
2598 output_bound_representation (upper, dimension_number, 'u');
2602 /* We have an array type with an unspecified length. For C and
2603 C++ we can assume that this really means that (a) the index
2604 type is an integral type, and (b) the lower bound is zero.
2605 Note that Dwarf defines the representation of an unspecified
2606 (upper) bound as being a zero-length location description. */
2608 /* Output the array-bounds format byte. */
2610 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2612 /* Output the (assumed) index type. */
2614 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2616 /* Output the (assumed) lower bound (constant) value. */
2618 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2620 /* Output the (empty) location description for the upper bound. */
2622 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2626 /* Output the prefix byte that says that the element type is coming up. */
2628 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2630 /* Output a representation of the type of the elements of this array type. */
2632 type_attribute (type, 0, 0);
2634 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2638 byte_size_attribute (tree_node)
2639 register tree tree_node;
2641 register unsigned size;
2643 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2644 switch (TREE_CODE (tree_node))
2653 case QUAL_UNION_TYPE:
2655 size = int_size_in_bytes (tree_node);
2659 /* For a data member of a struct or union, the AT_byte_size is
2660 generally given as the number of bytes normally allocated for
2661 an object of the *declared* type of the member itself. This
2662 is true even for bit-fields. */
2663 size = simple_type_size_in_bits (field_type (tree_node))
2671 /* Note that `size' might be -1 when we get to this point. If it
2672 is, that indicates that the byte size of the entity in question
2673 is variable. We have no good way of expressing this fact in Dwarf
2674 at the present time, so just let the -1 pass on through. */
2676 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2679 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2680 which specifies the distance in bits from the highest order bit of the
2681 "containing object" for the bit-field to the highest order bit of the
2684 For any given bit-field, the "containing object" is a hypothetical
2685 object (of some integral or enum type) within which the given bit-field
2686 lives. The type of this hypothetical "containing object" is always the
2687 same as the declared type of the individual bit-field itself.
2689 The determination of the exact location of the "containing object" for
2690 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2693 Note that it is the size (in bytes) of the hypothetical "containing
2694 object" which will be given in the AT_byte_size attribute for this
2695 bit-field. (See `byte_size_attribute' above.) */
2698 bit_offset_attribute (decl)
2701 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2702 register tree type = DECL_BIT_FIELD_TYPE (decl);
2703 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2704 register unsigned bitpos_int;
2705 register unsigned highest_order_object_bit_offset;
2706 register unsigned highest_order_field_bit_offset;
2707 register unsigned bit_offset;
2709 /* Must be a bit field. */
2711 || TREE_CODE (decl) != FIELD_DECL)
2714 /* We can't yet handle bit-fields whose offsets are variable, so if we
2715 encounter such things, just return without generating any attribute
2718 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2720 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2722 /* Note that the bit offset is always the distance (in bits) from the
2723 highest-order bit of the "containing object" to the highest-order
2724 bit of the bit-field itself. Since the "high-order end" of any
2725 object or field is different on big-endian and little-endian machines,
2726 the computation below must take account of these differences. */
2728 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2729 highest_order_field_bit_offset = bitpos_int;
2731 if (! BYTES_BIG_ENDIAN)
2733 highest_order_field_bit_offset
2734 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2736 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2741 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2742 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2744 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2745 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2748 /* For a FIELD_DECL node which represents a bit field, output an attribute
2749 which specifies the length in bits of the given field. */
2752 bit_size_attribute (decl)
2755 /* Must be a field and a bit field. */
2756 if (TREE_CODE (decl) != FIELD_DECL
2757 || ! DECL_BIT_FIELD_TYPE (decl))
2760 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2761 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2762 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2765 /* The following routine outputs the `element_list' attribute for enumeration
2766 type DIEs. The element_lits attribute includes the names and values of
2767 all of the enumeration constants associated with the given enumeration
2771 element_list_attribute (element)
2772 register tree element;
2774 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2775 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2777 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2778 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2779 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2780 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2781 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2783 /* Here we output a list of value/name pairs for each enumeration constant
2784 defined for this enumeration type (as required), but we do it in REVERSE
2785 order. The order is the one required by the draft #5 Dwarf specification
2786 published by the UI/PLSIG. */
2788 output_enumeral_list (element); /* Recursively output the whole list. */
2790 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2793 /* Generate an AT_stmt_list attribute. These are normally present only in
2794 DIEs with a TAG_compile_unit tag. */
2797 stmt_list_attribute (label)
2798 register char *label;
2800 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2801 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2802 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2805 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2806 for a subroutine DIE. */
2809 low_pc_attribute (asm_low_label)
2810 register char *asm_low_label;
2812 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2813 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2816 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2820 high_pc_attribute (asm_high_label)
2821 register char *asm_high_label;
2823 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2824 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2827 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2830 body_begin_attribute (asm_begin_label)
2831 register char *asm_begin_label;
2833 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2834 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2837 /* Generate an AT_body_end attribute for a subroutine DIE. */
2840 body_end_attribute (asm_end_label)
2841 register char *asm_end_label;
2843 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2844 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2847 /* Generate an AT_language attribute given a LANG value. These attributes
2848 are used only within TAG_compile_unit DIEs. */
2851 language_attribute (language_code)
2852 register unsigned language_code;
2854 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2855 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2859 member_attribute (context)
2860 register tree context;
2862 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2864 /* Generate this attribute only for members in C++. */
2866 if (context != NULL && is_tagged_type (context))
2868 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2869 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2870 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2875 string_length_attribute (upper_bound)
2876 register tree upper_bound;
2878 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2879 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2881 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2882 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2883 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2884 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2885 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2886 output_bound_representation (upper_bound, 0, 'u');
2887 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2891 comp_dir_attribute (dirname)
2892 register char *dirname;
2894 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2895 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2899 sf_names_attribute (sf_names_start_label)
2900 register char *sf_names_start_label;
2902 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2903 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2904 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2908 src_info_attribute (src_info_start_label)
2909 register char *src_info_start_label;
2911 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2912 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2913 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2917 mac_info_attribute (mac_info_start_label)
2918 register char *mac_info_start_label;
2920 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2921 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2922 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2926 prototyped_attribute (func_type)
2927 register tree func_type;
2929 if ((strcmp (language_string, "GNU C") == 0)
2930 && (TYPE_ARG_TYPES (func_type) != NULL))
2932 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2933 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2938 producer_attribute (producer)
2939 register char *producer;
2941 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2942 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2946 inline_attribute (decl)
2949 if (DECL_INLINE (decl))
2951 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2952 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2957 containing_type_attribute (containing_type)
2958 register tree containing_type;
2960 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2962 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2963 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2964 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2968 abstract_origin_attribute (origin)
2969 register tree origin;
2971 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2973 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2974 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2977 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2981 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2985 abort (); /* Should never happen. */
2988 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2991 #ifdef DWARF_DECL_COORDINATES
2993 src_coords_attribute (src_fileno, src_lineno)
2994 register unsigned src_fileno;
2995 register unsigned src_lineno;
2997 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2998 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2999 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3001 #endif /* defined(DWARF_DECL_COORDINATES) */
3004 pure_or_virtual_attribute (func_decl)
3005 register tree func_decl;
3007 if (DECL_VIRTUAL_P (func_decl))
3009 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3010 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3011 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3014 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3015 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3019 /************************* end of attributes *****************************/
3021 /********************* utility routines for DIEs *************************/
3023 /* Output an AT_name attribute and an AT_src_coords attribute for the
3024 given decl, but only if it actually has a name. */
3027 name_and_src_coords_attributes (decl)
3030 register tree decl_name = DECL_NAME (decl);
3032 if (decl_name && IDENTIFIER_POINTER (decl_name))
3034 name_attribute (IDENTIFIER_POINTER (decl_name));
3035 #ifdef DWARF_DECL_COORDINATES
3037 register unsigned file_index;
3039 /* This is annoying, but we have to pop out of the .debug section
3040 for a moment while we call `lookup_filename' because calling it
3041 may cause a temporary switch into the .debug_sfnames section and
3042 most svr4 assemblers are not smart enough to be able to nest
3043 section switches to any depth greater than one. Note that we
3044 also can't skirt this issue by delaying all output to the
3045 .debug_sfnames section unit the end of compilation because that
3046 would cause us to have inter-section forward references and
3047 Fred Fish sez that m68k/svr4 assemblers botch those. */
3049 ASM_OUTPUT_POP_SECTION (asm_out_file);
3050 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3051 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3053 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3055 #endif /* defined(DWARF_DECL_COORDINATES) */
3059 /* Many forms of DIEs contain a "type description" part. The following
3060 routine writes out these "type descriptor" parts. */
3063 type_attribute (type, decl_const, decl_volatile)
3065 register int decl_const;
3066 register int decl_volatile;
3068 register enum tree_code code = TREE_CODE (type);
3069 register int root_type_modified;
3071 if (code == ERROR_MARK)
3074 /* Handle a special case. For functions whose return type is void,
3075 we generate *no* type attribute. (Note that no object may have
3076 type `void', so this only applies to function return types. */
3078 if (code == VOID_TYPE)
3081 /* If this is a subtype, find the underlying type. Eventually,
3082 this should write out the appropriate subtype info. */
3083 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3084 && TREE_TYPE (type) != 0)
3085 type = TREE_TYPE (type), code = TREE_CODE (type);
3087 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3088 || decl_const || decl_volatile
3089 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3091 if (type_is_fundamental (root_type (type)))
3093 if (root_type_modified)
3094 mod_fund_type_attribute (type, decl_const, decl_volatile);
3096 fund_type_attribute (fundamental_type_code (type));
3100 if (root_type_modified)
3101 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3103 /* We have to get the type_main_variant here (and pass that to the
3104 `user_def_type_attribute' routine) because the ..._TYPE node we
3105 have might simply be a *copy* of some original type node (where
3106 the copy was created to help us keep track of typedef names)
3107 and that copy might have a different TYPE_UID from the original
3108 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3109 is labeling a given type DIE for future reference, it always and
3110 only creates labels for DIEs representing *main variants*, and it
3111 never even knows about non-main-variants.) */
3112 user_def_type_attribute (type_main_variant (type));
3116 /* Given a tree pointer to a struct, class, union, or enum type node, return
3117 a pointer to the (string) tag name for the given type, or zero if the
3118 type was declared without a tag. */
3124 register char *name = 0;
3126 if (TYPE_NAME (type) != 0)
3128 register tree t = 0;
3130 /* Find the IDENTIFIER_NODE for the type name. */
3131 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3132 t = TYPE_NAME (type);
3134 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3135 a TYPE_DECL node, regardless of whether or not a `typedef' was
3137 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3138 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3139 t = DECL_NAME (TYPE_NAME (type));
3141 /* Now get the name as a string, or invent one. */
3143 name = IDENTIFIER_POINTER (t);
3146 return (name == 0 || *name == '\0') ? 0 : name;
3152 /* Start by checking if the pending_sibling_stack needs to be expanded.
3153 If necessary, expand it. */
3155 if (pending_siblings == pending_siblings_allocated)
3157 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3158 pending_sibling_stack
3159 = (unsigned *) xrealloc (pending_sibling_stack,
3160 pending_siblings_allocated * sizeof(unsigned));
3164 NEXT_DIE_NUM = next_unused_dienum++;
3167 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3177 member_declared_type (member)
3178 register tree member;
3180 return (DECL_BIT_FIELD_TYPE (member))
3181 ? DECL_BIT_FIELD_TYPE (member)
3182 : TREE_TYPE (member);
3185 /* Get the function's label, as described by its RTL.
3186 This may be different from the DECL_NAME name used
3187 in the source file. */
3190 function_start_label (decl)
3196 x = DECL_RTL (decl);
3197 if (GET_CODE (x) != MEM)
3200 if (GET_CODE (x) != SYMBOL_REF)
3202 fnname = XSTR (x, 0);
3207 /******************************* DIEs ************************************/
3209 /* Output routines for individual types of DIEs. */
3211 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3214 output_array_type_die (arg)
3217 register tree type = arg;
3219 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3220 sibling_attribute ();
3221 equate_type_number_to_die_number (type);
3222 member_attribute (TYPE_CONTEXT (type));
3224 /* I believe that we can default the array ordering. SDB will probably
3225 do the right things even if AT_ordering is not present. It's not
3226 even an issue until we start to get into multidimensional arrays
3227 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3228 dimensional arrays, then we'll have to put the AT_ordering attribute
3229 back in. (But if and when we find out that we need to put these in,
3230 we will only do so for multidimensional arrays. After all, we don't
3231 want to waste space in the .debug section now do we?) */
3233 #ifdef USE_ORDERING_ATTRIBUTE
3234 ordering_attribute (ORD_row_major);
3235 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3237 subscript_data_attribute (type);
3241 output_set_type_die (arg)
3244 register tree type = arg;
3246 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3247 sibling_attribute ();
3248 equate_type_number_to_die_number (type);
3249 member_attribute (TYPE_CONTEXT (type));
3250 type_attribute (TREE_TYPE (type), 0, 0);
3254 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3257 output_entry_point_die (arg)
3260 register tree decl = arg;
3261 register tree origin = decl_ultimate_origin (decl);
3263 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3264 sibling_attribute ();
3267 abstract_origin_attribute (origin);
3270 name_and_src_coords_attributes (decl);
3271 member_attribute (DECL_CONTEXT (decl));
3272 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3274 if (DECL_ABSTRACT (decl))
3275 equate_decl_number_to_die_number (decl);
3277 low_pc_attribute (function_start_label (decl));
3281 /* Output a DIE to represent an inlined instance of an enumeration type. */
3284 output_inlined_enumeration_type_die (arg)
3287 register tree type = arg;
3289 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3290 sibling_attribute ();
3291 if (!TREE_ASM_WRITTEN (type))
3293 abstract_origin_attribute (type);
3296 /* Output a DIE to represent an inlined instance of a structure type. */
3299 output_inlined_structure_type_die (arg)
3302 register tree type = arg;
3304 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3305 sibling_attribute ();
3306 if (!TREE_ASM_WRITTEN (type))
3308 abstract_origin_attribute (type);
3311 /* Output a DIE to represent an inlined instance of a union type. */
3314 output_inlined_union_type_die (arg)
3317 register tree type = arg;
3319 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3320 sibling_attribute ();
3321 if (!TREE_ASM_WRITTEN (type))
3323 abstract_origin_attribute (type);
3326 /* Output a DIE to represent an enumeration type. Note that these DIEs
3327 include all of the information about the enumeration values also.
3328 This information is encoded into the element_list attribute. */
3331 output_enumeration_type_die (arg)
3334 register tree type = arg;
3336 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3337 sibling_attribute ();
3338 equate_type_number_to_die_number (type);
3339 name_attribute (type_tag (type));
3340 member_attribute (TYPE_CONTEXT (type));
3342 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3343 given enum type is incomplete, do not generate the AT_byte_size
3344 attribute or the AT_element_list attribute. */
3346 if (TYPE_SIZE (type))
3348 byte_size_attribute (type);
3349 element_list_attribute (TYPE_FIELDS (type));
3353 /* Output a DIE to represent either a real live formal parameter decl or
3354 to represent just the type of some formal parameter position in some
3357 Note that this routine is a bit unusual because its argument may be
3358 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3359 represents an inlining of some PARM_DECL) or else some sort of a
3360 ..._TYPE node. If it's the former then this function is being called
3361 to output a DIE to represent a formal parameter object (or some inlining
3362 thereof). If it's the latter, then this function is only being called
3363 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3364 formal argument type of some subprogram type. */
3367 output_formal_parameter_die (arg)
3370 register tree node = arg;
3372 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3373 sibling_attribute ();
3375 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3377 case 'd': /* We were called with some kind of a ..._DECL node. */
3379 register tree origin = decl_ultimate_origin (node);
3382 abstract_origin_attribute (origin);
3385 name_and_src_coords_attributes (node);
3386 type_attribute (TREE_TYPE (node),
3387 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3389 if (DECL_ABSTRACT (node))
3390 equate_decl_number_to_die_number (node);
3392 location_or_const_value_attribute (node);
3396 case 't': /* We were called with some kind of a ..._TYPE node. */
3397 type_attribute (node, 0, 0);
3401 abort (); /* Should never happen. */
3405 /* Output a DIE to represent a declared function (either file-scope
3406 or block-local) which has "external linkage" (according to ANSI-C). */
3409 output_global_subroutine_die (arg)
3412 register tree decl = arg;
3413 register tree origin = decl_ultimate_origin (decl);
3415 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3416 sibling_attribute ();
3419 abstract_origin_attribute (origin);
3422 register tree type = TREE_TYPE (decl);
3424 name_and_src_coords_attributes (decl);
3425 inline_attribute (decl);
3426 prototyped_attribute (type);
3427 member_attribute (DECL_CONTEXT (decl));
3428 type_attribute (TREE_TYPE (type), 0, 0);
3429 pure_or_virtual_attribute (decl);
3431 if (DECL_ABSTRACT (decl))
3432 equate_decl_number_to_die_number (decl);
3435 if (! DECL_EXTERNAL (decl) && ! in_class
3436 && decl == current_function_decl)
3438 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3440 low_pc_attribute (function_start_label (decl));
3441 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3442 high_pc_attribute (label);
3443 if (use_gnu_debug_info_extensions)
3445 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3446 body_begin_attribute (label);
3447 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3448 body_end_attribute (label);
3454 /* Output a DIE to represent a declared data object (either file-scope
3455 or block-local) which has "external linkage" (according to ANSI-C). */
3458 output_global_variable_die (arg)
3461 register tree decl = arg;
3462 register tree origin = decl_ultimate_origin (decl);
3464 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3465 sibling_attribute ();
3467 abstract_origin_attribute (origin);
3470 name_and_src_coords_attributes (decl);
3471 member_attribute (DECL_CONTEXT (decl));
3472 type_attribute (TREE_TYPE (decl),
3473 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3475 if (DECL_ABSTRACT (decl))
3476 equate_decl_number_to_die_number (decl);
3479 if (! DECL_EXTERNAL (decl) && ! in_class
3480 && current_function_decl == decl_function_context (decl))
3481 location_or_const_value_attribute (decl);
3486 output_label_die (arg)
3489 register tree decl = arg;
3490 register tree origin = decl_ultimate_origin (decl);
3492 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3493 sibling_attribute ();
3495 abstract_origin_attribute (origin);
3497 name_and_src_coords_attributes (decl);
3498 if (DECL_ABSTRACT (decl))
3499 equate_decl_number_to_die_number (decl);
3502 register rtx insn = DECL_RTL (decl);
3504 if (GET_CODE (insn) == CODE_LABEL)
3506 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3508 /* When optimization is enabled (via -O) some parts of the compiler
3509 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3510 represent source-level labels which were explicitly declared by
3511 the user. This really shouldn't be happening though, so catch
3512 it if it ever does happen. */
3514 if (INSN_DELETED_P (insn))
3515 abort (); /* Should never happen. */
3517 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3518 (unsigned) INSN_UID (insn));
3519 low_pc_attribute (label);
3525 output_lexical_block_die (arg)
3528 register tree stmt = arg;
3530 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3531 sibling_attribute ();
3533 if (! BLOCK_ABSTRACT (stmt))
3535 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3536 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3538 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3539 low_pc_attribute (begin_label);
3540 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3541 high_pc_attribute (end_label);
3546 output_inlined_subroutine_die (arg)
3549 register tree stmt = arg;
3551 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3552 sibling_attribute ();
3554 abstract_origin_attribute (block_ultimate_origin (stmt));
3555 if (! BLOCK_ABSTRACT (stmt))
3557 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3558 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3560 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3561 low_pc_attribute (begin_label);
3562 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3563 high_pc_attribute (end_label);
3567 /* Output a DIE to represent a declared data object (either file-scope
3568 or block-local) which has "internal linkage" (according to ANSI-C). */
3571 output_local_variable_die (arg)
3574 register tree decl = arg;
3575 register tree origin = decl_ultimate_origin (decl);
3577 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3578 sibling_attribute ();
3580 abstract_origin_attribute (origin);
3583 name_and_src_coords_attributes (decl);
3584 member_attribute (DECL_CONTEXT (decl));
3585 type_attribute (TREE_TYPE (decl),
3586 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3588 if (DECL_ABSTRACT (decl))
3589 equate_decl_number_to_die_number (decl);
3591 location_or_const_value_attribute (decl);
3595 output_member_die (arg)
3598 register tree decl = arg;
3600 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3601 sibling_attribute ();
3602 name_and_src_coords_attributes (decl);
3603 member_attribute (DECL_CONTEXT (decl));
3604 type_attribute (member_declared_type (decl),
3605 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3606 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3608 byte_size_attribute (decl);
3609 bit_size_attribute (decl);
3610 bit_offset_attribute (decl);
3612 data_member_location_attribute (decl);
3616 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3617 modified types instead.
3619 We keep this code here just in case these types of DIEs may be
3620 needed to represent certain things in other languages (e.g. Pascal)
3624 output_pointer_type_die (arg)
3627 register tree type = arg;
3629 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3630 sibling_attribute ();
3631 equate_type_number_to_die_number (type);
3632 member_attribute (TYPE_CONTEXT (type));
3633 type_attribute (TREE_TYPE (type), 0, 0);
3637 output_reference_type_die (arg)
3640 register tree type = arg;
3642 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_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);
3651 output_ptr_to_mbr_type_die (arg)
3654 register tree type = arg;
3656 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3657 sibling_attribute ();
3658 equate_type_number_to_die_number (type);
3659 member_attribute (TYPE_CONTEXT (type));
3660 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3661 type_attribute (TREE_TYPE (type), 0, 0);
3665 output_compile_unit_die (arg)
3668 register char *main_input_filename = arg;
3670 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3671 sibling_attribute ();
3673 name_attribute (main_input_filename);
3678 sprintf (producer, "%s %s", language_string, version_string);
3679 producer_attribute (producer);
3682 if (strcmp (language_string, "GNU C++") == 0)
3683 language_attribute (LANG_C_PLUS_PLUS);
3684 else if (strcmp (language_string, "GNU Ada") == 0)
3685 language_attribute (LANG_ADA83);
3686 else if (strcmp (language_string, "GNU F77") == 0)
3687 language_attribute (LANG_FORTRAN77);
3688 else if (strcmp (language_string, "GNU Pascal") == 0)
3689 language_attribute (LANG_PASCAL83);
3690 else if (flag_traditional)
3691 language_attribute (LANG_C);
3693 language_attribute (LANG_C89);
3694 low_pc_attribute (TEXT_BEGIN_LABEL);
3695 high_pc_attribute (TEXT_END_LABEL);
3696 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3697 stmt_list_attribute (LINE_BEGIN_LABEL);
3698 last_filename = xstrdup (main_input_filename);
3701 char *wd = getpwd ();
3703 comp_dir_attribute (wd);
3706 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3708 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3709 src_info_attribute (SRCINFO_BEGIN_LABEL);
3710 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3711 mac_info_attribute (MACINFO_BEGIN_LABEL);
3716 output_string_type_die (arg)
3719 register tree type = arg;
3721 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3722 sibling_attribute ();
3723 equate_type_number_to_die_number (type);
3724 member_attribute (TYPE_CONTEXT (type));
3725 /* this is a fixed length string */
3726 byte_size_attribute (type);
3730 output_inheritance_die (arg)
3733 register tree binfo = arg;
3735 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3736 sibling_attribute ();
3737 type_attribute (BINFO_TYPE (binfo), 0, 0);
3738 data_member_location_attribute (binfo);
3739 if (TREE_VIA_VIRTUAL (binfo))
3741 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3742 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3744 if (TREE_VIA_PUBLIC (binfo))
3746 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3747 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3749 else if (TREE_VIA_PROTECTED (binfo))
3751 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3752 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3757 output_structure_type_die (arg)
3760 register tree type = arg;
3762 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3763 sibling_attribute ();
3764 equate_type_number_to_die_number (type);
3765 name_attribute (type_tag (type));
3766 member_attribute (TYPE_CONTEXT (type));
3768 /* If this type has been completed, then give it a byte_size attribute
3769 and prepare to give a list of members. Otherwise, don't do either of
3770 these things. In the latter case, we will not be generating a list
3771 of members (since we don't have any idea what they might be for an
3772 incomplete type). */
3774 if (TYPE_SIZE (type))
3777 byte_size_attribute (type);
3781 /* Output a DIE to represent a declared function (either file-scope
3782 or block-local) which has "internal linkage" (according to ANSI-C). */
3785 output_local_subroutine_die (arg)
3788 register tree decl = arg;
3789 register tree origin = decl_ultimate_origin (decl);
3791 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3792 sibling_attribute ();
3795 abstract_origin_attribute (origin);
3798 register tree type = TREE_TYPE (decl);
3800 name_and_src_coords_attributes (decl);
3801 inline_attribute (decl);
3802 prototyped_attribute (type);
3803 member_attribute (DECL_CONTEXT (decl));
3804 type_attribute (TREE_TYPE (type), 0, 0);
3805 pure_or_virtual_attribute (decl);
3807 if (DECL_ABSTRACT (decl))
3808 equate_decl_number_to_die_number (decl);
3811 /* Avoid getting screwed up in cases where a function was declared
3812 static but where no definition was ever given for it. */
3814 if (TREE_ASM_WRITTEN (decl))
3816 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3817 low_pc_attribute (function_start_label (decl));
3818 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3819 high_pc_attribute (label);
3820 if (use_gnu_debug_info_extensions)
3822 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3823 body_begin_attribute (label);
3824 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3825 body_end_attribute (label);
3832 output_subroutine_type_die (arg)
3835 register tree type = arg;
3836 register tree return_type = TREE_TYPE (type);
3838 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3839 sibling_attribute ();
3841 equate_type_number_to_die_number (type);
3842 prototyped_attribute (type);
3843 member_attribute (TYPE_CONTEXT (type));
3844 type_attribute (return_type, 0, 0);
3848 output_typedef_die (arg)
3851 register tree decl = arg;
3852 register tree origin = decl_ultimate_origin (decl);
3854 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3855 sibling_attribute ();
3857 abstract_origin_attribute (origin);
3860 name_and_src_coords_attributes (decl);
3861 member_attribute (DECL_CONTEXT (decl));
3862 type_attribute (TREE_TYPE (decl),
3863 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3865 if (DECL_ABSTRACT (decl))
3866 equate_decl_number_to_die_number (decl);
3870 output_union_type_die (arg)
3873 register tree type = arg;
3875 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3876 sibling_attribute ();
3877 equate_type_number_to_die_number (type);
3878 name_attribute (type_tag (type));
3879 member_attribute (TYPE_CONTEXT (type));
3881 /* If this type has been completed, then give it a byte_size attribute
3882 and prepare to give a list of members. Otherwise, don't do either of
3883 these things. In the latter case, we will not be generating a list
3884 of members (since we don't have any idea what they might be for an
3885 incomplete type). */
3887 if (TYPE_SIZE (type))
3890 byte_size_attribute (type);
3894 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3895 at the end of an (ANSI prototyped) formal parameters list. */
3898 output_unspecified_parameters_die (arg)
3901 register tree decl_or_type = arg;
3903 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3904 sibling_attribute ();
3906 /* This kludge is here only for the sake of being compatible with what
3907 the USL CI5 C compiler does. The specification of Dwarf Version 1
3908 doesn't say that TAG_unspecified_parameters DIEs should contain any
3909 attributes other than the AT_sibling attribute, but they are certainly
3910 allowed to contain additional attributes, and the CI5 compiler
3911 generates AT_name, AT_fund_type, and AT_location attributes within
3912 TAG_unspecified_parameters DIEs which appear in the child lists for
3913 DIEs representing function definitions, so we do likewise here. */
3915 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3917 name_attribute ("...");
3918 fund_type_attribute (FT_pointer);
3919 /* location_attribute (?); */
3924 output_padded_null_die (arg)
3927 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3930 /*************************** end of DIEs *********************************/
3932 /* Generate some type of DIE. This routine generates the generic outer
3933 wrapper stuff which goes around all types of DIE's (regardless of their
3934 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3935 DIE-length word, followed by the guts of the DIE itself. After the guts
3936 of the DIE, there must always be a terminator label for the DIE. */
3939 output_die (die_specific_output_function, param)
3940 register void (*die_specific_output_function)();
3941 register void *param;
3943 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3944 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3946 current_dienum = NEXT_DIE_NUM;
3947 NEXT_DIE_NUM = next_unused_dienum;
3949 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3950 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3952 /* Write a label which will act as the name for the start of this DIE. */
3954 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3956 /* Write the DIE-length word. */
3958 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3960 /* Fill in the guts of the DIE. */
3962 next_unused_dienum++;
3963 die_specific_output_function (param);
3965 /* Write a label which will act as the name for the end of this DIE. */
3967 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3971 end_sibling_chain ()
3973 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3975 current_dienum = NEXT_DIE_NUM;
3976 NEXT_DIE_NUM = next_unused_dienum;
3978 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3980 /* Write a label which will act as the name for the start of this DIE. */
3982 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3984 /* Write the DIE-length word. */
3986 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3991 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3992 TAG_unspecified_parameters DIE) to represent the types of the formal
3993 parameters as specified in some function type specification (except
3994 for those which appear as part of a function *definition*).
3996 Note that we must be careful here to output all of the parameter
3997 DIEs *before* we output any DIEs needed to represent the types of
3998 the formal parameters. This keeps svr4 SDB happy because it
3999 (incorrectly) thinks that the first non-parameter DIE it sees ends
4000 the formal parameter list. */
4003 output_formal_types (function_or_method_type)
4004 register tree function_or_method_type;
4007 register tree formal_type = NULL;
4008 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4010 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4011 get bogus recursion when outputting tagged types local to a
4012 function declaration. */
4013 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4014 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4016 /* In the case where we are generating a formal types list for a C++
4017 non-static member function type, skip over the first thing on the
4018 TYPE_ARG_TYPES list because it only represents the type of the
4019 hidden `this pointer'. The debugger should be able to figure
4020 out (without being explicitly told) that this non-static member
4021 function type takes a `this pointer' and should be able to figure
4022 what the type of that hidden parameter is from the AT_member
4023 attribute of the parent TAG_subroutine_type DIE. */
4025 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4026 first_parm_type = TREE_CHAIN (first_parm_type);
4028 /* Make our first pass over the list of formal parameter types and output
4029 a TAG_formal_parameter DIE for each one. */
4031 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4033 formal_type = TREE_VALUE (link);
4034 if (formal_type == void_type_node)
4037 /* Output a (nameless) DIE to represent the formal parameter itself. */
4039 output_die (output_formal_parameter_die, formal_type);
4042 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4043 DIE to the end of the parameter list. */
4045 if (formal_type != void_type_node)
4046 output_die (output_unspecified_parameters_die, function_or_method_type);
4048 /* Make our second (and final) pass over the list of formal parameter types
4049 and output DIEs to represent those types (as necessary). */
4051 for (link = TYPE_ARG_TYPES (function_or_method_type);
4053 link = TREE_CHAIN (link))
4055 formal_type = TREE_VALUE (link);
4056 if (formal_type == void_type_node)
4059 output_type (formal_type, function_or_method_type);
4062 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4065 /* Remember a type in the pending_types_list. */
4071 if (pending_types == pending_types_allocated)
4073 pending_types_allocated += PENDING_TYPES_INCREMENT;
4075 = (tree *) xrealloc (pending_types_list,
4076 sizeof (tree) * pending_types_allocated);
4078 pending_types_list[pending_types++] = type;
4080 /* Mark the pending type as having been output already (even though
4081 it hasn't been). This prevents the type from being added to the
4082 pending_types_list more than once. */
4084 TREE_ASM_WRITTEN (type) = 1;
4087 /* Return non-zero if it is legitimate to output DIEs to represent a
4088 given type while we are generating the list of child DIEs for some
4089 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4091 See the comments within the function for a description of when it is
4092 considered legitimate to output DIEs for various kinds of types.
4094 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4095 or it may point to a BLOCK node (for types local to a block), or to a
4096 FUNCTION_DECL node (for types local to the heading of some function
4097 definition), or to a FUNCTION_TYPE node (for types local to the
4098 prototyped parameter list of a function type specification), or to a
4099 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4100 (in the case of C++ nested types).
4102 The `scope' parameter should likewise be NULL or should point to a
4103 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4104 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4106 This function is used only for deciding when to "pend" and when to
4107 "un-pend" types to/from the pending_types_list.
4109 Note that we sometimes make use of this "type pending" feature in a
4110 rather twisted way to temporarily delay the production of DIEs for the
4111 types of formal parameters. (We do this just to make svr4 SDB happy.)
4112 It order to delay the production of DIEs representing types of formal
4113 parameters, callers of this function supply `fake_containing_scope' as
4114 the `scope' parameter to this function. Given that fake_containing_scope
4115 is a tagged type which is *not* the containing scope for *any* other type,
4116 the desired effect is achieved, i.e. output of DIEs representing types
4117 is temporarily suspended, and any type DIEs which would have otherwise
4118 been output are instead placed onto the pending_types_list. Later on,
4119 we force these (temporarily pended) types to be output simply by calling
4120 `output_pending_types_for_scope' with an actual argument equal to the
4121 true scope of the types we temporarily pended. */
4124 type_ok_for_scope (type, scope)
4126 register tree scope;
4128 /* Tagged types (i.e. struct, union, and enum types) must always be
4129 output only in the scopes where they actually belong (or else the
4130 scoping of their own tag names and the scoping of their member
4131 names will be incorrect). Non-tagged-types on the other hand can
4132 generally be output anywhere, except that svr4 SDB really doesn't
4133 want to see them nested within struct or union types, so here we
4134 say it is always OK to immediately output any such a (non-tagged)
4135 type, so long as we are not within such a context. Note that the
4136 only kinds of non-tagged types which we will be dealing with here
4137 (for C and C++ anyway) will be array types and function types. */
4139 return is_tagged_type (type)
4140 ? (TYPE_CONTEXT (type) == scope
4141 /* Ignore namespaces for the moment. */
4142 || (scope == NULL_TREE
4143 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4144 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4145 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4146 : (scope == NULL_TREE || ! is_tagged_type (scope));
4149 /* Output any pending types (from the pending_types list) which we can output
4150 now (taking into account the scope that we are working on now).
4152 For each type output, remove the given type from the pending_types_list
4153 *before* we try to output it.
4155 Note that we have to process the list in beginning-to-end order,
4156 because the call made here to output_type may cause yet more types
4157 to be added to the end of the list, and we may have to output some
4161 output_pending_types_for_scope (containing_scope)
4162 register tree containing_scope;
4164 register unsigned i;
4166 for (i = 0; i < pending_types; )
4168 register tree type = pending_types_list[i];
4170 if (type_ok_for_scope (type, containing_scope))
4172 register tree *mover;
4173 register tree *limit;
4176 limit = &pending_types_list[pending_types];
4177 for (mover = &pending_types_list[i]; mover < limit; mover++)
4178 *mover = *(mover+1);
4180 /* Un-mark the type as having been output already (because it
4181 hasn't been, really). Then call output_type to generate a
4182 Dwarf representation of it. */
4184 TREE_ASM_WRITTEN (type) = 0;
4185 output_type (type, containing_scope);
4187 /* Don't increment the loop counter in this case because we
4188 have shifted all of the subsequent pending types down one
4189 element in the pending_types_list array. */
4197 output_type (type, containing_scope)
4199 register tree containing_scope;
4201 if (type == 0 || type == error_mark_node)
4204 /* We are going to output a DIE to represent the unqualified version of
4205 this type (i.e. without any const or volatile qualifiers) so get
4206 the main variant (i.e. the unqualified version) of this type now. */
4208 type = type_main_variant (type);
4210 if (TREE_ASM_WRITTEN (type))
4212 if (finalizing && AGGREGATE_TYPE_P (type))
4214 register tree member;
4216 /* Some of our nested types might not have been defined when we
4217 were written out before; force them out now. */
4219 for (member = TYPE_FIELDS (type); member;
4220 member = TREE_CHAIN (member))
4221 if (TREE_CODE (member) == TYPE_DECL
4222 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4223 output_type (TREE_TYPE (member), containing_scope);
4228 /* If this is a nested type whose containing class hasn't been
4229 written out yet, writing it out will cover this one, too. */
4231 if (TYPE_CONTEXT (type)
4232 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4233 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4235 output_type (TYPE_CONTEXT (type), containing_scope);
4239 /* Don't generate any DIEs for this type now unless it is OK to do so
4240 (based upon what `type_ok_for_scope' tells us). */
4242 if (! type_ok_for_scope (type, containing_scope))
4248 switch (TREE_CODE (type))
4254 case REFERENCE_TYPE:
4255 /* Prevent infinite recursion in cases where this is a recursive
4256 type. Recursive types are possible in Ada. */
4257 TREE_ASM_WRITTEN (type) = 1;
4258 /* For these types, all that is required is that we output a DIE
4259 (or a set of DIEs) to represent the "basis" type. */
4260 output_type (TREE_TYPE (type), containing_scope);
4264 /* This code is used for C++ pointer-to-data-member types. */
4265 /* Output a description of the relevant class type. */
4266 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4267 /* Output a description of the type of the object pointed to. */
4268 output_type (TREE_TYPE (type), containing_scope);
4269 /* Now output a DIE to represent this pointer-to-data-member type
4271 output_die (output_ptr_to_mbr_type_die, type);
4275 output_type (TYPE_DOMAIN (type), containing_scope);
4276 output_die (output_set_type_die, type);
4280 output_type (TREE_TYPE (type), containing_scope);
4281 abort (); /* No way to represent these in Dwarf yet! */
4285 /* Force out return type (in case it wasn't forced out already). */
4286 output_type (TREE_TYPE (type), containing_scope);
4287 output_die (output_subroutine_type_die, type);
4288 output_formal_types (type);
4289 end_sibling_chain ();
4293 /* Force out return type (in case it wasn't forced out already). */
4294 output_type (TREE_TYPE (type), containing_scope);
4295 output_die (output_subroutine_type_die, type);
4296 output_formal_types (type);
4297 end_sibling_chain ();
4301 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4303 output_type (TREE_TYPE (type), containing_scope);
4304 output_die (output_string_type_die, type);
4308 register tree element_type;
4310 element_type = TREE_TYPE (type);
4311 while (TREE_CODE (element_type) == ARRAY_TYPE)
4312 element_type = TREE_TYPE (element_type);
4314 output_type (element_type, containing_scope);
4315 output_die (output_array_type_die, type);
4322 case QUAL_UNION_TYPE:
4324 /* For a non-file-scope tagged type, we can always go ahead and
4325 output a Dwarf description of this type right now, even if
4326 the type in question is still incomplete, because if this
4327 local type *was* ever completed anywhere within its scope,
4328 that complete definition would already have been attached to
4329 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4330 node by the time we reach this point. That's true because of the
4331 way the front-end does its processing of file-scope declarations (of
4332 functions and class types) within which other types might be
4333 nested. The C and C++ front-ends always gobble up such "local
4334 scope" things en-mass before they try to output *any* debugging
4335 information for any of the stuff contained inside them and thus,
4336 we get the benefit here of what is (in effect) a pre-resolution
4337 of forward references to tagged types in local scopes.
4339 Note however that for file-scope tagged types we cannot assume
4340 that such pre-resolution of forward references has taken place.
4341 A given file-scope tagged type may appear to be incomplete when
4342 we reach this point, but it may yet be given a full definition
4343 (at file-scope) later on during compilation. In order to avoid
4344 generating a premature (and possibly incorrect) set of Dwarf
4345 DIEs for such (as yet incomplete) file-scope tagged types, we
4346 generate nothing at all for as-yet incomplete file-scope tagged
4347 types here unless we are making our special "finalization" pass
4348 for file-scope things at the very end of compilation. At that
4349 time, we will certainly know as much about each file-scope tagged
4350 type as we are ever going to know, so at that point in time, we
4351 can safely generate correct Dwarf descriptions for these file-
4352 scope tagged types. */
4354 if (TYPE_SIZE (type) == 0
4355 && (TYPE_CONTEXT (type) == NULL
4356 || (TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4357 && TREE_CODE (TYPE_CONTEXT (type)) != FUNCTION_TYPE
4358 && TREE_CODE (TYPE_CONTEXT (type)) != METHOD_TYPE))
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 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 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 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 */