1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #ifdef DWARF_DEBUGGING_INFO
30 #include "hard-reg-set.h"
31 #include "insn-config.h"
36 /* #define NDEBUG 1 */
39 #if defined(DWARF_TIMESTAMPS)
42 #else /* !defined(POSIX) */
43 #include <sys/types.h>
45 extern time_t time (time_t *);
46 #else /* !defined(__STDC__) */
47 extern time_t time ();
48 #endif /* !defined(__STDC__) */
49 #endif /* !defined(POSIX) */
50 #endif /* defined(DWARF_TIMESTAMPS) */
52 extern char *getpwd ();
54 extern char *index ();
55 extern char *rindex ();
57 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
58 regarding the GNU implementation of Dwarf. */
60 /* NOTE: In the comments in this file, many references are made to
61 so called "Debugging Information Entries". For the sake of brevity,
62 this term is abbreviated to `DIE' throughout the remainder of this
65 /* Note that the implementation of C++ support herein is (as yet) unfinished.
66 If you want to try to complete it, more power to you. */
68 #if !defined(__GNUC__) || (NDEBUG != 1)
72 /* How to start an assembler comment. */
73 #ifndef ASM_COMMENT_START
74 #define ASM_COMMENT_START ";#"
77 /* How to print out a register name. */
79 #define PRINT_REG(RTX, CODE, FILE) \
80 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
83 /* Define a macro which returns non-zero for any tagged type which is
84 used (directly or indirectly) in the specification of either some
85 function's return type or some formal parameter of some function.
86 We use this macro when we are operating in "terse" mode to help us
87 know what tagged types have to be represented in Dwarf (even in
88 terse mode) and which ones don't.
90 A flag bit with this meaning really should be a part of the normal
91 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
92 for these nodes. For now, we have to just fake it. It it safe for
93 us to simply return zero for all complete tagged types (which will
94 get forced out anyway if they were used in the specification of some
95 formal or return type) and non-zero for all incomplete tagged types.
98 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
100 /* Define a macro which returns non-zero for a TYPE_DECL which was
101 implicitly generated for a tagged type.
103 Note that unlike the gcc front end (which generates a NULL named
104 TYPE_DECL node for each complete tagged type, each array type, and
105 each function type node created) the g++ front end generates a
106 _named_ TYPE_DECL node for each tagged type node created.
107 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
108 generate a DW_TAG_typedef DIE for them. */
109 #define TYPE_DECL_IS_STUB(decl) \
110 (DECL_NAME (decl) == NULL \
111 || (DECL_ARTIFICIAL (decl) \
112 && is_tagged_type (TREE_TYPE (decl)) \
113 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
115 extern int flag_traditional;
116 extern char *version_string;
117 extern char *language_string;
119 /* Maximum size (in bytes) of an artificially generated label. */
121 #define MAX_ARTIFICIAL_LABEL_BYTES 30
123 /* Make sure we know the sizes of the various types dwarf can describe.
124 These are only defaults. If the sizes are different for your target,
125 you should override these values by defining the appropriate symbols
126 in your tm.h file. */
128 #ifndef CHAR_TYPE_SIZE
129 #define CHAR_TYPE_SIZE BITS_PER_UNIT
132 #ifndef SHORT_TYPE_SIZE
133 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
136 #ifndef INT_TYPE_SIZE
137 #define INT_TYPE_SIZE BITS_PER_WORD
140 #ifndef LONG_TYPE_SIZE
141 #define LONG_TYPE_SIZE BITS_PER_WORD
144 #ifndef LONG_LONG_TYPE_SIZE
145 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
148 #ifndef WCHAR_TYPE_SIZE
149 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
152 #ifndef WCHAR_UNSIGNED
153 #define WCHAR_UNSIGNED 0
156 #ifndef FLOAT_TYPE_SIZE
157 #define FLOAT_TYPE_SIZE BITS_PER_WORD
160 #ifndef DOUBLE_TYPE_SIZE
161 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
164 #ifndef LONG_DOUBLE_TYPE_SIZE
165 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
168 /* Structure to keep track of source filenames. */
170 struct filename_entry {
175 typedef struct filename_entry filename_entry;
177 /* Pointer to an array of elements, each one having the structure above. */
179 static filename_entry *filename_table;
181 /* Total number of entries in the table (i.e. array) pointed to by
182 `filename_table'. This is the *total* and includes both used and
185 static unsigned ft_entries_allocated;
187 /* Number of entries in the filename_table which are actually in use. */
189 static unsigned ft_entries;
191 /* Size (in elements) of increments by which we may expand the filename
192 table. Actually, a single hunk of space of this size should be enough
193 for most typical programs. */
195 #define FT_ENTRIES_INCREMENT 64
197 /* Local pointer to the name of the main input file. Initialized in
200 static char *primary_filename;
202 /* Pointer to the most recent filename for which we produced some line info. */
204 static char *last_filename;
206 /* For Dwarf output, we must assign lexical-blocks id numbers
207 in the order in which their beginnings are encountered.
208 We output Dwarf debugging info that refers to the beginnings
209 and ends of the ranges of code for each lexical block with
210 assembler labels ..Bn and ..Bn.e, where n is the block number.
211 The labels themselves are generated in final.c, which assigns
212 numbers to the blocks in the same way. */
214 static unsigned next_block_number = 2;
216 /* Counter to generate unique names for DIEs. */
218 static unsigned next_unused_dienum = 1;
220 /* Number of the DIE which is currently being generated. */
222 static unsigned current_dienum;
224 /* Number to use for the special "pubname" label on the next DIE which
225 represents a function or data object defined in this compilation
226 unit which has "extern" linkage. */
228 static next_pubname_number = 0;
230 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
232 /* Pointer to a dynamically allocated list of pre-reserved and still
233 pending sibling DIE numbers. Note that this list will grow as needed. */
235 static unsigned *pending_sibling_stack;
237 /* Counter to keep track of the number of pre-reserved and still pending
238 sibling DIE numbers. */
240 static unsigned pending_siblings;
242 /* The currently allocated size of the above list (expressed in number of
245 static unsigned pending_siblings_allocated;
247 /* Size (in elements) of increments by which we may expand the pending
248 sibling stack. Actually, a single hunk of space of this size should
249 be enough for most typical programs. */
251 #define PENDING_SIBLINGS_INCREMENT 64
253 /* Non-zero if we are performing our file-scope finalization pass and if
254 we should force out Dwarf descriptions of any and all file-scope
255 tagged types which are still incomplete types. */
257 static int finalizing = 0;
259 /* A pointer to the base of a list of pending types which we haven't
260 generated DIEs for yet, but which we will have to come back to
263 static tree *pending_types_list;
265 /* Number of elements currently allocated for the pending_types_list. */
267 static unsigned pending_types_allocated;
269 /* Number of elements of pending_types_list currently in use. */
271 static unsigned pending_types;
273 /* Size (in elements) of increments by which we may expand the pending
274 types list. Actually, a single hunk of space of this size should
275 be enough for most typical programs. */
277 #define PENDING_TYPES_INCREMENT 64
279 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
280 This is used in a hack to help us get the DIEs describing types of
281 formal parameters to come *after* all of the DIEs describing the formal
282 parameters themselves. That's necessary in order to be compatible
283 with what the brain-damaged svr4 SDB debugger requires. */
285 static tree fake_containing_scope;
287 /* The number of the current function definition that we are generating
288 debugging information for. These numbers range from 1 up to the maximum
289 number of function definitions contained within the current compilation
290 unit. These numbers are used to create unique labels for various things
291 contained within various function definitions. */
293 static unsigned current_funcdef_number = 1;
295 /* A pointer to the ..._DECL node which we have most recently been working
296 on. We keep this around just in case something about it looks screwy
297 and we want to tell the user what the source coordinates for the actual
300 static tree dwarf_last_decl;
302 /* A flag indicating that we are emitting the member declarations of a
303 class, so member functions and variables should not be entirely emitted.
304 This is a kludge to avoid passing a second argument to output_*_die. */
308 /* Forward declarations for functions defined in this file. */
310 static char *dwarf_tag_name PROTO((unsigned));
311 static char *dwarf_attr_name PROTO((unsigned));
312 static char *dwarf_stack_op_name PROTO((unsigned));
313 static char *dwarf_typemod_name PROTO((unsigned));
314 static char *dwarf_fmt_byte_name PROTO((unsigned));
315 static char *dwarf_fund_type_name PROTO((unsigned));
316 static tree decl_ultimate_origin PROTO((tree));
317 static tree block_ultimate_origin PROTO((tree));
318 static void output_unsigned_leb128 PROTO((unsigned long));
319 static void output_signed_leb128 PROTO((long));
320 static inline int is_body_block PROTO((tree));
321 static int fundamental_type_code PROTO((tree));
322 static tree root_type_1 PROTO((tree, int));
323 static tree root_type PROTO((tree));
324 static void write_modifier_bytes_1 PROTO((tree, int, int, int));
325 static void write_modifier_bytes PROTO((tree, int, int));
326 static inline int type_is_fundamental PROTO((tree));
327 static void equate_decl_number_to_die_number PROTO((tree));
328 static inline void equate_type_number_to_die_number PROTO((tree));
329 static void output_reg_number PROTO((rtx));
330 static void output_mem_loc_descriptor PROTO((rtx));
331 static void output_loc_descriptor PROTO((rtx));
332 static void output_bound_representation PROTO((tree, unsigned, int));
333 static void output_enumeral_list PROTO((tree));
334 static inline unsigned ceiling PROTO((unsigned, unsigned));
335 static inline tree field_type PROTO((tree));
336 static inline unsigned simple_type_align_in_bits PROTO((tree));
337 static inline unsigned simple_type_size_in_bits PROTO((tree));
338 static unsigned field_byte_offset PROTO((tree));
339 static inline void sibling_attribute PROTO((void));
340 static void location_attribute PROTO((rtx));
341 static void data_member_location_attribute PROTO((tree));
342 static void const_value_attribute PROTO((rtx));
343 static void location_or_const_value_attribute PROTO((tree));
344 static inline void name_attribute PROTO((char *));
345 static inline void fund_type_attribute PROTO((unsigned));
346 static void mod_fund_type_attribute PROTO((tree, int, int));
347 static inline void user_def_type_attribute PROTO((tree));
348 static void mod_u_d_type_attribute PROTO((tree, int, int));
349 static inline void ordering_attribute PROTO((unsigned));
350 static void subscript_data_attribute PROTO((tree));
351 static void byte_size_attribute PROTO((tree));
352 static inline void bit_offset_attribute PROTO((tree));
353 static inline void bit_size_attribute PROTO((tree));
354 static inline void element_list_attribute PROTO((tree));
355 static inline void stmt_list_attribute PROTO((char *));
356 static inline void low_pc_attribute PROTO((char *));
357 static inline void high_pc_attribute PROTO((char *));
358 static inline void body_begin_attribute PROTO((char *));
359 static inline void body_end_attribute PROTO((char *));
360 static inline void langauge_attribute PROTO((unsigned));
361 static inline void member_attribute PROTO((tree));
362 static inline void string_length_attribute PROTO((tree));
363 static inline void comp_dir_attribute PROTO((char *));
364 static inline void sf_names_attribute PROTO((char *));
365 static inline void src_info_attribute PROTO((char *));
366 static inline void mac_info_attribute PROTO((char *));
367 static inline void prototyped_attribute PROTO((tree));
368 static inline void producer_attribute PROTO((char *));
369 static inline void inline_attribute PROTO((tree));
370 static inline void containing_type_attribute PROTO((tree));
371 static inline void abstract_origin_attribute PROTO((tree));
372 static inline void src_coords_attribute PROTO((unsigned, unsigned));
373 static inline void pure_or_virtual_attribute PROTO((tree));
374 static void name_and_src_coords_attributes PROTO((tree));
375 static void type_attribute PROTO((tree, int, int));
376 static char *type_tag PROTO((tree));
377 static inline void dienum_push PROTO((void));
378 static inline void dienum_pop PROTO((void));
379 static inline tree member_declared_type PROTO((tree));
380 static char *function_start_label PROTO((tree));
381 static void output_array_type_die PROTO((void *));
382 static void output_set_type_die PROTO((void *));
383 static void output_entry_point_die PROTO((void *));
384 static void output_inlined_enumeration_type_die PROTO((void *));
385 static void output_inlined_structure_type_die PROTO((void *));
386 static void output_inlined_union_type_die PROTO((void *));
387 static void output_enumeration_type_die PROTO((void *));
388 static void output_formal_parameter_die PROTO((void *));
389 static void output_global_subroutine_die PROTO((void *));
390 static void output_global_variable_die PROTO((void *));
391 static void output_label_die PROTO((void *));
392 static void output_lexical_block_die PROTO((void *));
393 static void output_inlined_subroutine_die PROTO((void *));
394 static void output_local_variable_die PROTO((void *));
395 static void output_member_die PROTO((void *));
396 static void output_pointer_type_die PROTO((void *));
397 static void output_reference_type_die PROTO((void *));
398 static void output_ptr_to_mbr_type_die PROTO((void *));
399 static void output_compile_unit_die PROTO((void *));
400 static void output_string_type_die PROTO((void *));
401 static void output_structure_type_die PROTO((void *));
402 static void output_local_subroutine_die PROTO((void *));
403 static void output_subroutine_type_die PROTO((void *));
404 static void output_typedef_die PROTO((void *));
405 static void output_union_type_die PROTO((void *));
406 static void output_unspecified_parameters_die PROTO((void *));
407 static void output_padded_null_die PROTO((void *));
408 static void output_die PROTO((void (*) (), void *));
409 static void end_sibling_chain PROTO((void));
410 static void output_formal_types PROTO((tree));
411 static void pend_type PROTO((tree));
412 static inline int type_of_for_scope PROTO((tree, tree));
413 static void output_pending_types_for_scope PROTO((tree));
414 static void output_type PROTO((tree, tree));
415 static void output_tagged_type_instantiation PROTO((tree));
416 static void output_block PROTO((tree, int));
417 static void output_decls_for_scope PROTO((tree, int));
418 static void output_decl PROTO((tree, tree));
419 static void shuffle_filename_entry PROTO((filename_entry *));
420 static void geneate_new_sfname_entry PROTO((void));
421 static unsigned lookup_filename PROTO((char *));
422 static void generate_srcinfo_entry PROTO((unsigned, unsigned));
423 static void generate_macinfo_entry PROTO((char *, char *));
425 /* Definitions of defaults for assembler-dependent names of various
426 pseudo-ops and section names.
428 Theses may be overridden in your tm.h file (if necessary) for your
429 particular assembler. The default values provided here correspond to
430 what is expected by "standard" AT&T System V.4 assemblers. */
433 #define FILE_ASM_OP ".file"
435 #ifndef VERSION_ASM_OP
436 #define VERSION_ASM_OP ".version"
438 #ifndef UNALIGNED_SHORT_ASM_OP
439 #define UNALIGNED_SHORT_ASM_OP ".2byte"
441 #ifndef UNALIGNED_INT_ASM_OP
442 #define UNALIGNED_INT_ASM_OP ".4byte"
445 #define ASM_BYTE_OP ".byte"
448 #define SET_ASM_OP ".set"
451 /* Pseudo-ops for pushing the current section onto the section stack (and
452 simultaneously changing to a new section) and for poping back to the
453 section we were in immediately before this one. Note that most svr4
454 assemblers only maintain a one level stack... you can push all the
455 sections you want, but you can only pop out one level. (The sparc
456 svr4 assembler is an exception to this general rule.) That's
457 OK because we only use at most one level of the section stack herein. */
459 #ifndef PUSHSECTION_ASM_OP
460 #define PUSHSECTION_ASM_OP ".section"
462 #ifndef POPSECTION_ASM_OP
463 #define POPSECTION_ASM_OP ".previous"
466 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
467 to print the PUSHSECTION_ASM_OP and the section name. The default here
468 works for almost all svr4 assemblers, except for the sparc, where the
469 section name must be enclosed in double quotes. (See sparcv4.h.) */
471 #ifndef PUSHSECTION_FORMAT
472 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
475 #ifndef DEBUG_SECTION
476 #define DEBUG_SECTION ".debug"
479 #define LINE_SECTION ".line"
481 #ifndef SFNAMES_SECTION
482 #define SFNAMES_SECTION ".debug_sfnames"
484 #ifndef SRCINFO_SECTION
485 #define SRCINFO_SECTION ".debug_srcinfo"
487 #ifndef MACINFO_SECTION
488 #define MACINFO_SECTION ".debug_macinfo"
490 #ifndef PUBNAMES_SECTION
491 #define PUBNAMES_SECTION ".debug_pubnames"
493 #ifndef ARANGES_SECTION
494 #define ARANGES_SECTION ".debug_aranges"
497 #define TEXT_SECTION ".text"
500 #define DATA_SECTION ".data"
502 #ifndef DATA1_SECTION
503 #define DATA1_SECTION ".data1"
505 #ifndef RODATA_SECTION
506 #define RODATA_SECTION ".rodata"
508 #ifndef RODATA1_SECTION
509 #define RODATA1_SECTION ".rodata1"
512 #define BSS_SECTION ".bss"
515 /* Definitions of defaults for formats and names of various special
516 (artificial) labels which may be generated within this file (when
517 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
519 If necessary, these may be overridden from within your tm.h file,
520 but typically, you should never need to override these.
522 These labels have been hacked (temporarily) so that they all begin with
523 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
524 stock m88k/svr4 assembler, both of which need to see .L at the start of
525 a label in order to prevent that label from going into the linker symbol
526 table). When I get time, I'll have to fix this the right way so that we
527 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
528 but that will require a rather massive set of changes. For the moment,
529 the following definitions out to produce the right results for all svr4
530 and svr3 assemblers. -- rfg
533 #ifndef TEXT_BEGIN_LABEL
534 #define TEXT_BEGIN_LABEL ".L_text_b"
536 #ifndef TEXT_END_LABEL
537 #define TEXT_END_LABEL ".L_text_e"
540 #ifndef DATA_BEGIN_LABEL
541 #define DATA_BEGIN_LABEL ".L_data_b"
543 #ifndef DATA_END_LABEL
544 #define DATA_END_LABEL ".L_data_e"
547 #ifndef DATA1_BEGIN_LABEL
548 #define DATA1_BEGIN_LABEL ".L_data1_b"
550 #ifndef DATA1_END_LABEL
551 #define DATA1_END_LABEL ".L_data1_e"
554 #ifndef RODATA_BEGIN_LABEL
555 #define RODATA_BEGIN_LABEL ".L_rodata_b"
557 #ifndef RODATA_END_LABEL
558 #define RODATA_END_LABEL ".L_rodata_e"
561 #ifndef RODATA1_BEGIN_LABEL
562 #define RODATA1_BEGIN_LABEL ".L_rodata1_b"
564 #ifndef RODATA1_END_LABEL
565 #define RODATA1_END_LABEL ".L_rodata1_e"
568 #ifndef BSS_BEGIN_LABEL
569 #define BSS_BEGIN_LABEL ".L_bss_b"
571 #ifndef BSS_END_LABEL
572 #define BSS_END_LABEL ".L_bss_e"
575 #ifndef LINE_BEGIN_LABEL
576 #define LINE_BEGIN_LABEL ".L_line_b"
578 #ifndef LINE_LAST_ENTRY_LABEL
579 #define LINE_LAST_ENTRY_LABEL ".L_line_last"
581 #ifndef LINE_END_LABEL
582 #define LINE_END_LABEL ".L_line_e"
585 #ifndef DEBUG_BEGIN_LABEL
586 #define DEBUG_BEGIN_LABEL ".L_debug_b"
588 #ifndef SFNAMES_BEGIN_LABEL
589 #define SFNAMES_BEGIN_LABEL ".L_sfnames_b"
591 #ifndef SRCINFO_BEGIN_LABEL
592 #define SRCINFO_BEGIN_LABEL ".L_srcinfo_b"
594 #ifndef MACINFO_BEGIN_LABEL
595 #define MACINFO_BEGIN_LABEL ".L_macinfo_b"
598 #ifndef DIE_BEGIN_LABEL_FMT
599 #define DIE_BEGIN_LABEL_FMT ".L_D%u"
601 #ifndef DIE_END_LABEL_FMT
602 #define DIE_END_LABEL_FMT ".L_D%u_e"
604 #ifndef PUB_DIE_LABEL_FMT
605 #define PUB_DIE_LABEL_FMT ".L_P%u"
607 #ifndef INSN_LABEL_FMT
608 #define INSN_LABEL_FMT ".L_I%u_%u"
610 #ifndef BLOCK_BEGIN_LABEL_FMT
611 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
613 #ifndef BLOCK_END_LABEL_FMT
614 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
616 #ifndef SS_BEGIN_LABEL_FMT
617 #define SS_BEGIN_LABEL_FMT ".L_s%u"
619 #ifndef SS_END_LABEL_FMT
620 #define SS_END_LABEL_FMT ".L_s%u_e"
622 #ifndef EE_BEGIN_LABEL_FMT
623 #define EE_BEGIN_LABEL_FMT ".L_e%u"
625 #ifndef EE_END_LABEL_FMT
626 #define EE_END_LABEL_FMT ".L_e%u_e"
628 #ifndef MT_BEGIN_LABEL_FMT
629 #define MT_BEGIN_LABEL_FMT ".L_t%u"
631 #ifndef MT_END_LABEL_FMT
632 #define MT_END_LABEL_FMT ".L_t%u_e"
634 #ifndef LOC_BEGIN_LABEL_FMT
635 #define LOC_BEGIN_LABEL_FMT ".L_l%u"
637 #ifndef LOC_END_LABEL_FMT
638 #define LOC_END_LABEL_FMT ".L_l%u_e"
640 #ifndef BOUND_BEGIN_LABEL_FMT
641 #define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c"
643 #ifndef BOUND_END_LABEL_FMT
644 #define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e"
646 #ifndef DERIV_BEGIN_LABEL_FMT
647 #define DERIV_BEGIN_LABEL_FMT ".L_d%u"
649 #ifndef DERIV_END_LABEL_FMT
650 #define DERIV_END_LABEL_FMT ".L_d%u_e"
652 #ifndef SL_BEGIN_LABEL_FMT
653 #define SL_BEGIN_LABEL_FMT ".L_sl%u"
655 #ifndef SL_END_LABEL_FMT
656 #define SL_END_LABEL_FMT ".L_sl%u_e"
658 #ifndef BODY_BEGIN_LABEL_FMT
659 #define BODY_BEGIN_LABEL_FMT ".L_b%u"
661 #ifndef BODY_END_LABEL_FMT
662 #define BODY_END_LABEL_FMT ".L_b%u_e"
664 #ifndef FUNC_END_LABEL_FMT
665 #define FUNC_END_LABEL_FMT ".L_f%u_e"
667 #ifndef TYPE_NAME_FMT
668 #define TYPE_NAME_FMT ".L_T%u"
670 #ifndef DECL_NAME_FMT
671 #define DECL_NAME_FMT ".L_E%u"
673 #ifndef LINE_CODE_LABEL_FMT
674 #define LINE_CODE_LABEL_FMT ".L_LC%u"
676 #ifndef SFNAMES_ENTRY_LABEL_FMT
677 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
679 #ifndef LINE_ENTRY_LABEL_FMT
680 #define LINE_ENTRY_LABEL_FMT ".L_LE%u"
683 /* Definitions of defaults for various types of primitive assembly language
686 If necessary, these may be overridden from within your tm.h file,
687 but typically, you shouldn't need to override these. */
689 #ifndef ASM_OUTPUT_PUSH_SECTION
690 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
691 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
694 #ifndef ASM_OUTPUT_POP_SECTION
695 #define ASM_OUTPUT_POP_SECTION(FILE) \
696 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
699 #ifndef ASM_OUTPUT_DWARF_DELTA2
700 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
701 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
702 assemble_name (FILE, LABEL1); \
703 fprintf (FILE, "-"); \
704 assemble_name (FILE, LABEL2); \
705 fprintf (FILE, "\n"); \
709 #ifndef ASM_OUTPUT_DWARF_DELTA4
710 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
711 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
712 assemble_name (FILE, LABEL1); \
713 fprintf (FILE, "-"); \
714 assemble_name (FILE, LABEL2); \
715 fprintf (FILE, "\n"); \
719 #ifndef ASM_OUTPUT_DWARF_TAG
720 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
722 fprintf ((FILE), "\t%s\t0x%x", \
723 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
724 if (flag_debug_asm) \
725 fprintf ((FILE), "\t%s %s", \
726 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
727 fputc ('\n', (FILE)); \
731 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
732 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
734 fprintf ((FILE), "\t%s\t0x%x", \
735 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
736 if (flag_debug_asm) \
737 fprintf ((FILE), "\t%s %s", \
738 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
739 fputc ('\n', (FILE)); \
743 #ifndef ASM_OUTPUT_DWARF_STACK_OP
744 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
746 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
747 if (flag_debug_asm) \
748 fprintf ((FILE), "\t%s %s", \
749 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
750 fputc ('\n', (FILE)); \
754 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
755 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
757 fprintf ((FILE), "\t%s\t0x%x", \
758 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
759 if (flag_debug_asm) \
760 fprintf ((FILE), "\t%s %s", \
761 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
762 fputc ('\n', (FILE)); \
766 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
767 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
769 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
770 if (flag_debug_asm) \
771 fprintf ((FILE), "\t%s %s", \
772 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
773 fputc ('\n', (FILE)); \
777 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
778 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
780 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
781 if (flag_debug_asm) \
782 fprintf ((FILE), "\t%s %s", \
783 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
784 fputc ('\n', (FILE)); \
788 #ifndef ASM_OUTPUT_DWARF_ADDR
789 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
790 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
791 assemble_name (FILE, LABEL); \
792 fprintf (FILE, "\n"); \
796 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
797 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
799 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
800 output_addr_const ((FILE), (RTX)); \
801 fputc ('\n', (FILE)); \
805 #ifndef ASM_OUTPUT_DWARF_REF
806 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
807 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
808 assemble_name (FILE, LABEL); \
809 fprintf (FILE, "\n"); \
813 #ifndef ASM_OUTPUT_DWARF_DATA1
814 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
815 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
818 #ifndef ASM_OUTPUT_DWARF_DATA2
819 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
820 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
823 #ifndef ASM_OUTPUT_DWARF_DATA4
824 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
825 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
828 #ifndef ASM_OUTPUT_DWARF_DATA8
829 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
831 if (WORDS_BIG_ENDIAN) \
833 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
834 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
838 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
839 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
844 #ifndef ASM_OUTPUT_DWARF_STRING
845 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
846 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
849 /************************ general utility functions **************************/
855 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
856 || ((GET_CODE (rtl) == SUBREG)
857 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
861 type_main_variant (type)
864 type = TYPE_MAIN_VARIANT (type);
866 /* There really should be only one main variant among any group of variants
867 of a given type (and all of the MAIN_VARIANT values for all members of
868 the group should point to that one type) but sometimes the C front-end
869 messes this up for array types, so we work around that bug here. */
871 if (TREE_CODE (type) == ARRAY_TYPE)
873 while (type != TYPE_MAIN_VARIANT (type))
874 type = TYPE_MAIN_VARIANT (type);
880 /* Return non-zero if the given type node represents a tagged type. */
883 is_tagged_type (type)
886 register enum tree_code code = TREE_CODE (type);
888 return (code == RECORD_TYPE || code == UNION_TYPE
889 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
894 register unsigned tag;
898 case TAG_padding: return "TAG_padding";
899 case TAG_array_type: return "TAG_array_type";
900 case TAG_class_type: return "TAG_class_type";
901 case TAG_entry_point: return "TAG_entry_point";
902 case TAG_enumeration_type: return "TAG_enumeration_type";
903 case TAG_formal_parameter: return "TAG_formal_parameter";
904 case TAG_global_subroutine: return "TAG_global_subroutine";
905 case TAG_global_variable: return "TAG_global_variable";
906 case TAG_label: return "TAG_label";
907 case TAG_lexical_block: return "TAG_lexical_block";
908 case TAG_local_variable: return "TAG_local_variable";
909 case TAG_member: return "TAG_member";
910 case TAG_pointer_type: return "TAG_pointer_type";
911 case TAG_reference_type: return "TAG_reference_type";
912 case TAG_compile_unit: return "TAG_compile_unit";
913 case TAG_string_type: return "TAG_string_type";
914 case TAG_structure_type: return "TAG_structure_type";
915 case TAG_subroutine: return "TAG_subroutine";
916 case TAG_subroutine_type: return "TAG_subroutine_type";
917 case TAG_typedef: return "TAG_typedef";
918 case TAG_union_type: return "TAG_union_type";
919 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
920 case TAG_variant: return "TAG_variant";
921 case TAG_common_block: return "TAG_common_block";
922 case TAG_common_inclusion: return "TAG_common_inclusion";
923 case TAG_inheritance: return "TAG_inheritance";
924 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
925 case TAG_module: return "TAG_module";
926 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
927 case TAG_set_type: return "TAG_set_type";
928 case TAG_subrange_type: return "TAG_subrange_type";
929 case TAG_with_stmt: return "TAG_with_stmt";
931 /* GNU extensions. */
933 case TAG_format_label: return "TAG_format_label";
934 case TAG_namelist: return "TAG_namelist";
935 case TAG_function_template: return "TAG_function_template";
936 case TAG_class_template: return "TAG_class_template";
938 default: return "TAG_<unknown>";
943 dwarf_attr_name (attr)
944 register unsigned attr;
948 case AT_sibling: return "AT_sibling";
949 case AT_location: return "AT_location";
950 case AT_name: return "AT_name";
951 case AT_fund_type: return "AT_fund_type";
952 case AT_mod_fund_type: return "AT_mod_fund_type";
953 case AT_user_def_type: return "AT_user_def_type";
954 case AT_mod_u_d_type: return "AT_mod_u_d_type";
955 case AT_ordering: return "AT_ordering";
956 case AT_subscr_data: return "AT_subscr_data";
957 case AT_byte_size: return "AT_byte_size";
958 case AT_bit_offset: return "AT_bit_offset";
959 case AT_bit_size: return "AT_bit_size";
960 case AT_element_list: return "AT_element_list";
961 case AT_stmt_list: return "AT_stmt_list";
962 case AT_low_pc: return "AT_low_pc";
963 case AT_high_pc: return "AT_high_pc";
964 case AT_language: return "AT_language";
965 case AT_member: return "AT_member";
966 case AT_discr: return "AT_discr";
967 case AT_discr_value: return "AT_discr_value";
968 case AT_string_length: return "AT_string_length";
969 case AT_common_reference: return "AT_common_reference";
970 case AT_comp_dir: return "AT_comp_dir";
971 case AT_const_value_string: return "AT_const_value_string";
972 case AT_const_value_data2: return "AT_const_value_data2";
973 case AT_const_value_data4: return "AT_const_value_data4";
974 case AT_const_value_data8: return "AT_const_value_data8";
975 case AT_const_value_block2: return "AT_const_value_block2";
976 case AT_const_value_block4: return "AT_const_value_block4";
977 case AT_containing_type: return "AT_containing_type";
978 case AT_default_value_addr: return "AT_default_value_addr";
979 case AT_default_value_data2: return "AT_default_value_data2";
980 case AT_default_value_data4: return "AT_default_value_data4";
981 case AT_default_value_data8: return "AT_default_value_data8";
982 case AT_default_value_string: return "AT_default_value_string";
983 case AT_friends: return "AT_friends";
984 case AT_inline: return "AT_inline";
985 case AT_is_optional: return "AT_is_optional";
986 case AT_lower_bound_ref: return "AT_lower_bound_ref";
987 case AT_lower_bound_data2: return "AT_lower_bound_data2";
988 case AT_lower_bound_data4: return "AT_lower_bound_data4";
989 case AT_lower_bound_data8: return "AT_lower_bound_data8";
990 case AT_private: return "AT_private";
991 case AT_producer: return "AT_producer";
992 case AT_program: return "AT_program";
993 case AT_protected: return "AT_protected";
994 case AT_prototyped: return "AT_prototyped";
995 case AT_public: return "AT_public";
996 case AT_pure_virtual: return "AT_pure_virtual";
997 case AT_return_addr: return "AT_return_addr";
998 case AT_abstract_origin: return "AT_abstract_origin";
999 case AT_start_scope: return "AT_start_scope";
1000 case AT_stride_size: return "AT_stride_size";
1001 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1002 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1003 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1004 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1005 case AT_virtual: return "AT_virtual";
1007 /* GNU extensions */
1009 case AT_sf_names: return "AT_sf_names";
1010 case AT_src_info: return "AT_src_info";
1011 case AT_mac_info: return "AT_mac_info";
1012 case AT_src_coords: return "AT_src_coords";
1013 case AT_body_begin: return "AT_body_begin";
1014 case AT_body_end: return "AT_body_end";
1016 default: return "AT_<unknown>";
1021 dwarf_stack_op_name (op)
1022 register unsigned op;
1026 case OP_REG: return "OP_REG";
1027 case OP_BASEREG: return "OP_BASEREG";
1028 case OP_ADDR: return "OP_ADDR";
1029 case OP_CONST: return "OP_CONST";
1030 case OP_DEREF2: return "OP_DEREF2";
1031 case OP_DEREF4: return "OP_DEREF4";
1032 case OP_ADD: return "OP_ADD";
1033 default: return "OP_<unknown>";
1038 dwarf_typemod_name (mod)
1039 register unsigned mod;
1043 case MOD_pointer_to: return "MOD_pointer_to";
1044 case MOD_reference_to: return "MOD_reference_to";
1045 case MOD_const: return "MOD_const";
1046 case MOD_volatile: return "MOD_volatile";
1047 default: return "MOD_<unknown>";
1052 dwarf_fmt_byte_name (fmt)
1053 register unsigned fmt;
1057 case FMT_FT_C_C: return "FMT_FT_C_C";
1058 case FMT_FT_C_X: return "FMT_FT_C_X";
1059 case FMT_FT_X_C: return "FMT_FT_X_C";
1060 case FMT_FT_X_X: return "FMT_FT_X_X";
1061 case FMT_UT_C_C: return "FMT_UT_C_C";
1062 case FMT_UT_C_X: return "FMT_UT_C_X";
1063 case FMT_UT_X_C: return "FMT_UT_X_C";
1064 case FMT_UT_X_X: return "FMT_UT_X_X";
1065 case FMT_ET: return "FMT_ET";
1066 default: return "FMT_<unknown>";
1071 dwarf_fund_type_name (ft)
1072 register unsigned ft;
1076 case FT_char: return "FT_char";
1077 case FT_signed_char: return "FT_signed_char";
1078 case FT_unsigned_char: return "FT_unsigned_char";
1079 case FT_short: return "FT_short";
1080 case FT_signed_short: return "FT_signed_short";
1081 case FT_unsigned_short: return "FT_unsigned_short";
1082 case FT_integer: return "FT_integer";
1083 case FT_signed_integer: return "FT_signed_integer";
1084 case FT_unsigned_integer: return "FT_unsigned_integer";
1085 case FT_long: return "FT_long";
1086 case FT_signed_long: return "FT_signed_long";
1087 case FT_unsigned_long: return "FT_unsigned_long";
1088 case FT_pointer: return "FT_pointer";
1089 case FT_float: return "FT_float";
1090 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1091 case FT_ext_prec_float: return "FT_ext_prec_float";
1092 case FT_complex: return "FT_complex";
1093 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1094 case FT_void: return "FT_void";
1095 case FT_boolean: return "FT_boolean";
1096 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1097 case FT_label: return "FT_label";
1099 /* GNU extensions. */
1101 case FT_long_long: return "FT_long_long";
1102 case FT_signed_long_long: return "FT_signed_long_long";
1103 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1105 case FT_int8: return "FT_int8";
1106 case FT_signed_int8: return "FT_signed_int8";
1107 case FT_unsigned_int8: return "FT_unsigned_int8";
1108 case FT_int16: return "FT_int16";
1109 case FT_signed_int16: return "FT_signed_int16";
1110 case FT_unsigned_int16: return "FT_unsigned_int16";
1111 case FT_int32: return "FT_int32";
1112 case FT_signed_int32: return "FT_signed_int32";
1113 case FT_unsigned_int32: return "FT_unsigned_int32";
1114 case FT_int64: return "FT_int64";
1115 case FT_signed_int64: return "FT_signed_int64";
1116 case FT_unsigned_int64: return "FT_unsigned_int64";
1118 case FT_real32: return "FT_real32";
1119 case FT_real64: return "FT_real64";
1120 case FT_real96: return "FT_real96";
1121 case FT_real128: return "FT_real128";
1123 default: return "FT_<unknown>";
1127 /* Determine the "ultimate origin" of a decl. The decl may be an
1128 inlined instance of an inlined instance of a decl which is local
1129 to an inline function, so we have to trace all of the way back
1130 through the origin chain to find out what sort of node actually
1131 served as the original seed for the given block. */
1134 decl_ultimate_origin (decl)
1137 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1139 if (immediate_origin == NULL)
1143 register tree ret_val;
1144 register tree lookahead = immediate_origin;
1148 ret_val = lookahead;
1149 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1151 while (lookahead != NULL && lookahead != ret_val);
1156 /* Determine the "ultimate origin" of a block. The block may be an
1157 inlined instance of an inlined instance of a block which is local
1158 to an inline function, so we have to trace all of the way back
1159 through the origin chain to find out what sort of node actually
1160 served as the original seed for the given block. */
1163 block_ultimate_origin (block)
1164 register tree block;
1166 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1168 if (immediate_origin == NULL)
1172 register tree ret_val;
1173 register tree lookahead = immediate_origin;
1177 ret_val = lookahead;
1178 lookahead = (TREE_CODE (ret_val) == BLOCK)
1179 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1182 while (lookahead != NULL && lookahead != ret_val);
1187 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1188 of a virtual function may refer to a base class, so we check the 'this'
1192 decl_class_context (decl)
1195 tree context = NULL_TREE;
1196 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1197 context = DECL_CONTEXT (decl);
1199 context = TYPE_MAIN_VARIANT
1200 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1202 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1203 context = NULL_TREE;
1209 output_unsigned_leb128 (value)
1210 register unsigned long value;
1212 register unsigned long orig_value = value;
1216 register unsigned byte = (value & 0x7f);
1219 if (value != 0) /* more bytes to follow */
1221 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1222 if (flag_debug_asm && value == 0)
1223 fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1224 ASM_COMMENT_START, orig_value);
1225 fputc ('\n', asm_out_file);
1231 output_signed_leb128 (value)
1232 register long value;
1234 register long orig_value = value;
1235 register int negative = (value < 0);
1240 register unsigned byte = (value & 0x7f);
1244 value |= 0xfe000000; /* manually sign extend */
1245 if (((value == 0) && ((byte & 0x40) == 0))
1246 || ((value == -1) && ((byte & 0x40) == 1)))
1253 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1254 if (flag_debug_asm && more == 0)
1255 fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1256 ASM_COMMENT_START, orig_value);
1257 fputc ('\n', asm_out_file);
1262 /**************** utility functions for attribute functions ******************/
1264 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1265 node in question represents the outermost pair of curly braces (i.e.
1266 the "body block") of a function or method.
1268 For any BLOCK node representing a "body block" of a function or method,
1269 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1270 which represents the outermost (function) scope for the function or
1271 method (i.e. the one which includes the formal parameters). The
1272 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1277 is_body_block (stmt)
1280 if (TREE_CODE (stmt) == BLOCK)
1282 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1284 if (TREE_CODE (parent) == BLOCK)
1286 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1288 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1295 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1296 type code for the given type.
1298 This routine must only be called for GCC type nodes that correspond to
1299 Dwarf fundamental types.
1301 The current Dwarf draft specification calls for Dwarf fundamental types
1302 to accurately reflect the fact that a given type was either a "plain"
1303 integral type or an explicitly "signed" integral type. Unfortunately,
1304 we can't always do this, because GCC may already have thrown away the
1305 information about the precise way in which the type was originally
1308 typedef signed int my_type;
1310 struct s { my_type f; };
1312 Since we may be stuck here without enought information to do exactly
1313 what is called for in the Dwarf draft specification, we do the best
1314 that we can under the circumstances and always use the "plain" integral
1315 fundamental type codes for int, short, and long types. That's probably
1316 good enough. The additional accuracy called for in the current DWARF
1317 draft specification is probably never even useful in practice. */
1320 fundamental_type_code (type)
1323 if (TREE_CODE (type) == ERROR_MARK)
1326 switch (TREE_CODE (type))
1335 /* Carefully distinguish all the standard types of C,
1336 without messing up if the language is not C.
1337 Note that we check only for the names that contain spaces;
1338 other names might occur by coincidence in other languages. */
1339 if (TYPE_NAME (type) != 0
1340 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1341 && DECL_NAME (TYPE_NAME (type)) != 0
1342 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1344 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1346 if (!strcmp (name, "unsigned char"))
1347 return FT_unsigned_char;
1348 if (!strcmp (name, "signed char"))
1349 return FT_signed_char;
1350 if (!strcmp (name, "unsigned int"))
1351 return FT_unsigned_integer;
1352 if (!strcmp (name, "short int"))
1354 if (!strcmp (name, "short unsigned int"))
1355 return FT_unsigned_short;
1356 if (!strcmp (name, "long int"))
1358 if (!strcmp (name, "long unsigned int"))
1359 return FT_unsigned_long;
1360 if (!strcmp (name, "long long int"))
1361 return FT_long_long; /* Not grok'ed by svr4 SDB */
1362 if (!strcmp (name, "long long unsigned int"))
1363 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1366 /* Most integer types will be sorted out above, however, for the
1367 sake of special `array index' integer types, the following code
1368 is also provided. */
1370 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1371 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1373 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1374 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1376 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1377 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1379 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1380 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1382 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1383 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1388 /* Carefully distinguish all the standard types of C,
1389 without messing up if the language is not C. */
1390 if (TYPE_NAME (type) != 0
1391 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1392 && DECL_NAME (TYPE_NAME (type)) != 0
1393 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1395 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1397 /* Note that here we can run afowl of a serious bug in "classic"
1398 svr4 SDB debuggers. They don't seem to understand the
1399 FT_ext_prec_float type (even though they should). */
1401 if (!strcmp (name, "long double"))
1402 return FT_ext_prec_float;
1405 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1406 return FT_dbl_prec_float;
1407 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1410 /* Note that here we can run afowl of a serious bug in "classic"
1411 svr4 SDB debuggers. They don't seem to understand the
1412 FT_ext_prec_float type (even though they should). */
1414 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1415 return FT_ext_prec_float;
1419 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1422 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1425 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1428 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1433 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1434 the Dwarf "root" type for the given input type. The Dwarf "root" type
1435 of a given type is generally the same as the given type, except that if
1436 the given type is a pointer or reference type, then the root type of
1437 the given type is the root type of the "basis" type for the pointer or
1438 reference type. (This definition of the "root" type is recursive.)
1439 Also, the root type of a `const' qualified type or a `volatile'
1440 qualified type is the root type of the given type without the
1444 root_type_1 (type, count)
1448 /* Give up after searching 1000 levels, in case this is a recursive
1449 pointer type. Such types are possible in Ada, but it is not possible
1450 to represent them in DWARF1 debug info. */
1452 return error_mark_node;
1454 switch (TREE_CODE (type))
1457 return error_mark_node;
1460 case REFERENCE_TYPE:
1461 return root_type_1 (TREE_TYPE (type), count+1);
1472 type = root_type_1 (type, 0);
1473 if (type != error_mark_node)
1474 type = type_main_variant (type);
1478 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1479 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1482 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1484 register int decl_const;
1485 register int decl_volatile;
1488 if (TREE_CODE (type) == ERROR_MARK)
1491 /* Give up after searching 1000 levels, in case this is a recursive
1492 pointer type. Such types are possible in Ada, but it is not possible
1493 to represent them in DWARF1 debug info. */
1497 if (TYPE_READONLY (type) || decl_const)
1498 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1499 if (TYPE_VOLATILE (type) || decl_volatile)
1500 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1501 switch (TREE_CODE (type))
1504 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1505 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1508 case REFERENCE_TYPE:
1509 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1510 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1520 write_modifier_bytes (type, decl_const, decl_volatile)
1522 register int decl_const;
1523 register int decl_volatile;
1525 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1528 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1529 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1532 type_is_fundamental (type)
1535 switch (TREE_CODE (type))
1550 case QUAL_UNION_TYPE:
1555 case REFERENCE_TYPE:
1567 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1568 equate directive which will associate a symbolic name with the current DIE.
1570 The name used is an artificial label generated from the DECL_UID number
1571 associated with the given decl node. The name it gets equated to is the
1572 symbolic label that we (previously) output at the start of the DIE that
1573 we are currently generating.
1575 Calling this function while generating some "decl related" form of DIE
1576 makes it possible to later refer to the DIE which represents the given
1577 decl simply by re-generating the symbolic name from the ..._DECL node's
1581 equate_decl_number_to_die_number (decl)
1584 /* In the case where we are generating a DIE for some ..._DECL node
1585 which represents either some inline function declaration or some
1586 entity declared within an inline function declaration/definition,
1587 setup a symbolic name for the current DIE so that we have a name
1588 for this DIE that we can easily refer to later on within
1589 AT_abstract_origin attributes. */
1591 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1592 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1594 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1595 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1596 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1599 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1600 equate directive which will associate a symbolic name with the current DIE.
1602 The name used is an artificial label generated from the TYPE_UID number
1603 associated with the given type node. The name it gets equated to is the
1604 symbolic label that we (previously) output at the start of the DIE that
1605 we are currently generating.
1607 Calling this function while generating some "type related" form of DIE
1608 makes it easy to later refer to the DIE which represents the given type
1609 simply by re-generating the alternative name from the ..._TYPE node's
1613 equate_type_number_to_die_number (type)
1616 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1617 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1619 /* We are generating a DIE to represent the main variant of this type
1620 (i.e the type without any const or volatile qualifiers) so in order
1621 to get the equate to come out right, we need to get the main variant
1624 type = type_main_variant (type);
1626 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1627 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1628 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1632 output_reg_number (rtl)
1635 register unsigned regno = REGNO (rtl);
1637 if (regno >= FIRST_PSEUDO_REGISTER)
1639 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1643 fprintf (asm_out_file, "\t%s\t0x%x",
1644 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1647 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1648 PRINT_REG (rtl, 0, asm_out_file);
1650 fputc ('\n', asm_out_file);
1653 /* The following routine is a nice and simple transducer. It converts the
1654 RTL for a variable or parameter (resident in memory) into an equivalent
1655 Dwarf representation of a mechanism for getting the address of that same
1656 variable onto the top of a hypothetical "address evaluation" stack.
1658 When creating memory location descriptors, we are effectively trans-
1659 forming the RTL for a memory-resident object into its Dwarf postfix
1660 expression equivalent. This routine just recursively descends an
1661 RTL tree, turning it into Dwarf postfix code as it goes. */
1664 output_mem_loc_descriptor (rtl)
1667 /* Note that for a dynamically sized array, the location we will
1668 generate a description of here will be the lowest numbered location
1669 which is actually within the array. That's *not* necessarily the
1670 same as the zeroth element of the array. */
1672 switch (GET_CODE (rtl))
1676 /* The case of a subreg may arise when we have a local (register)
1677 variable or a formal (register) parameter which doesn't quite
1678 fill up an entire register. For now, just assume that it is
1679 legitimate to make the Dwarf info refer to the whole register
1680 which contains the given subreg. */
1682 rtl = XEXP (rtl, 0);
1687 /* Whenever a register number forms a part of the description of
1688 the method for calculating the (dynamic) address of a memory
1689 resident object, DWARF rules require the register number to
1690 be referred to as a "base register". This distinction is not
1691 based in any way upon what category of register the hardware
1692 believes the given register belongs to. This is strictly
1693 DWARF terminology we're dealing with here.
1695 Note that in cases where the location of a memory-resident data
1696 object could be expressed as:
1698 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1700 the actual DWARF location descriptor that we generate may just
1701 be OP_BASEREG (basereg). This may look deceptively like the
1702 object in question was allocated to a register (rather than
1703 in memory) so DWARF consumers need to be aware of the subtle
1704 distinction between OP_REG and OP_BASEREG. */
1706 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1707 output_reg_number (rtl);
1711 output_mem_loc_descriptor (XEXP (rtl, 0));
1712 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1717 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1718 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1722 output_mem_loc_descriptor (XEXP (rtl, 0));
1723 output_mem_loc_descriptor (XEXP (rtl, 1));
1724 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1728 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1729 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1733 /* If a pseudo-reg is optimized away, it is possible for it to
1734 be replaced with a MEM containing a multiply. Use a GNU extension
1736 output_mem_loc_descriptor (XEXP (rtl, 0));
1737 output_mem_loc_descriptor (XEXP (rtl, 1));
1738 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1746 /* Output a proper Dwarf location descriptor for a variable or parameter
1747 which is either allocated in a register or in a memory location. For
1748 a register, we just generate an OP_REG and the register number. For a
1749 memory location we provide a Dwarf postfix expression describing how to
1750 generate the (dynamic) address of the object onto the address stack. */
1753 output_loc_descriptor (rtl)
1756 switch (GET_CODE (rtl))
1760 /* The case of a subreg may arise when we have a local (register)
1761 variable or a formal (register) parameter which doesn't quite
1762 fill up an entire register. For now, just assume that it is
1763 legitimate to make the Dwarf info refer to the whole register
1764 which contains the given subreg. */
1766 rtl = XEXP (rtl, 0);
1770 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1771 output_reg_number (rtl);
1775 output_mem_loc_descriptor (XEXP (rtl, 0));
1779 abort (); /* Should never happen */
1783 /* Given a tree node describing an array bound (either lower or upper)
1784 output a representation for that bound. */
1787 output_bound_representation (bound, dim_num, u_or_l)
1788 register tree bound;
1789 register unsigned dim_num; /* For multi-dimensional arrays. */
1790 register char u_or_l; /* Designates upper or lower bound. */
1792 switch (TREE_CODE (bound))
1798 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1801 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1802 (unsigned) TREE_INT_CST_LOW (bound));
1807 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1808 SAVE_EXPR nodes, in which case we can do something, or as
1809 an expression, which we cannot represent. */
1811 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1812 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1814 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1815 current_dienum, dim_num, u_or_l);
1817 sprintf (end_label, BOUND_END_LABEL_FMT,
1818 current_dienum, dim_num, u_or_l);
1820 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1821 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1823 /* If optimization is turned on, the SAVE_EXPRs that describe
1824 how to access the upper bound values are essentially bogus.
1825 They only describe (at best) how to get at these values at
1826 the points in the generated code right after they have just
1827 been computed. Worse yet, in the typical case, the upper
1828 bound values will not even *be* computed in the optimized
1829 code, so these SAVE_EXPRs are entirely bogus.
1831 In order to compensate for this fact, we check here to see
1832 if optimization is enabled, and if so, we effectively create
1833 an empty location description for the (unknown and unknowable)
1836 This should not cause too much trouble for existing (stupid?)
1837 debuggers because they have to deal with empty upper bounds
1838 location descriptions anyway in order to be able to deal with
1839 incomplete array types.
1841 Of course an intelligent debugger (GDB?) should be able to
1842 comprehend that a missing upper bound specification in a
1843 array type used for a storage class `auto' local array variable
1844 indicates that the upper bound is both unknown (at compile-
1845 time) and unknowable (at run-time) due to optimization. */
1849 while (TREE_CODE (bound) == NOP_EXPR
1850 || TREE_CODE (bound) == CONVERT_EXPR)
1851 bound = TREE_OPERAND (bound, 0);
1853 if (TREE_CODE (bound) == SAVE_EXPR)
1854 output_loc_descriptor
1855 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX, 0));
1858 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1865 /* Recursive function to output a sequence of value/name pairs for
1866 enumeration constants in reversed order. This is called from
1867 enumeration_type_die. */
1870 output_enumeral_list (link)
1875 output_enumeral_list (TREE_CHAIN (link));
1876 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1877 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1878 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1879 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1883 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1884 which is not less than the value itself. */
1886 static inline unsigned
1887 ceiling (value, boundary)
1888 register unsigned value;
1889 register unsigned boundary;
1891 return (((value + boundary - 1) / boundary) * boundary);
1894 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1895 pointer to the declared type for the relevant field variable, or return
1896 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1904 if (TREE_CODE (decl) == ERROR_MARK)
1905 return integer_type_node;
1907 type = DECL_BIT_FIELD_TYPE (decl);
1909 type = TREE_TYPE (decl);
1913 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1914 node, return the alignment in bits for the type, or else return
1915 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1917 static inline unsigned
1918 simple_type_align_in_bits (type)
1921 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1924 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1925 node, return the size in bits for the type if it is a constant, or
1926 else return the alignment for the type if the type's size is not
1927 constant, or else return BITS_PER_WORD if the type actually turns out
1928 to be an ERROR_MARK node. */
1930 static inline unsigned
1931 simple_type_size_in_bits (type)
1934 if (TREE_CODE (type) == ERROR_MARK)
1935 return BITS_PER_WORD;
1938 register tree type_size_tree = TYPE_SIZE (type);
1940 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1941 return TYPE_ALIGN (type);
1943 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1947 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1948 return the byte offset of the lowest addressed byte of the "containing
1949 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1950 mine what that offset is, either because the argument turns out to be a
1951 pointer to an ERROR_MARK node, or because the offset is actually variable.
1952 (We can't handle the latter case just yet.) */
1955 field_byte_offset (decl)
1958 register unsigned type_align_in_bytes;
1959 register unsigned type_align_in_bits;
1960 register unsigned type_size_in_bits;
1961 register unsigned object_offset_in_align_units;
1962 register unsigned object_offset_in_bits;
1963 register unsigned object_offset_in_bytes;
1965 register tree bitpos_tree;
1966 register tree field_size_tree;
1967 register unsigned bitpos_int;
1968 register unsigned deepest_bitpos;
1969 register unsigned field_size_in_bits;
1971 if (TREE_CODE (decl) == ERROR_MARK)
1974 if (TREE_CODE (decl) != FIELD_DECL)
1977 type = field_type (decl);
1979 bitpos_tree = DECL_FIELD_BITPOS (decl);
1980 field_size_tree = DECL_SIZE (decl);
1982 /* We cannot yet cope with fields whose positions or sizes are variable,
1983 so for now, when we see such things, we simply return 0. Someday,
1984 we may be able to handle such cases, but it will be damn difficult. */
1986 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1988 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1990 if (TREE_CODE (field_size_tree) != INTEGER_CST)
1992 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
1994 type_size_in_bits = simple_type_size_in_bits (type);
1996 type_align_in_bits = simple_type_align_in_bits (type);
1997 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1999 /* Note that the GCC front-end doesn't make any attempt to keep track
2000 of the starting bit offset (relative to the start of the containing
2001 structure type) of the hypothetical "containing object" for a bit-
2002 field. Thus, when computing the byte offset value for the start of
2003 the "containing object" of a bit-field, we must deduce this infor-
2006 This can be rather tricky to do in some cases. For example, handling
2007 the following structure type definition when compiling for an i386/i486
2008 target (which only aligns long long's to 32-bit boundaries) can be very
2013 long long field2:31;
2016 Fortunately, there is a simple rule-of-thumb which can be used in such
2017 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2018 the structure shown above. It decides to do this based upon one simple
2019 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2020 taining object" for each bit-field at the first (i.e. lowest addressed)
2021 legitimate alignment boundary (based upon the required minimum alignment
2022 for the declared type of the field) which it can possibly use, subject
2023 to the condition that there is still enough available space remaining
2024 in the containing object (when allocated at the selected point) to
2025 fully accommodate all of the bits of the bit-field itself.
2027 This simple rule makes it obvious why GCC allocates 8 bytes for each
2028 object of the structure type shown above. When looking for a place to
2029 allocate the "containing object" for `field2', the compiler simply tries
2030 to allocate a 64-bit "containing object" at each successive 32-bit
2031 boundary (starting at zero) until it finds a place to allocate that 64-
2032 bit field such that at least 31 contiguous (and previously unallocated)
2033 bits remain within that selected 64 bit field. (As it turns out, for
2034 the example above, the compiler finds that it is OK to allocate the
2035 "containing object" 64-bit field at bit-offset zero within the
2038 Here we attempt to work backwards from the limited set of facts we're
2039 given, and we try to deduce from those facts, where GCC must have
2040 believed that the containing object started (within the structure type).
2042 The value we deduce is then used (by the callers of this routine) to
2043 generate AT_location and AT_bit_offset attributes for fields (both
2044 bit-fields and, in the case of AT_location, regular fields as well).
2047 /* Figure out the bit-distance from the start of the structure to the
2048 "deepest" bit of the bit-field. */
2049 deepest_bitpos = bitpos_int + field_size_in_bits;
2051 /* This is the tricky part. Use some fancy footwork to deduce where the
2052 lowest addressed bit of the containing object must be. */
2053 object_offset_in_bits
2054 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2056 /* Compute the offset of the containing object in "alignment units". */
2057 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2059 /* Compute the offset of the containing object in bytes. */
2060 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2062 /* The above code assumes that the field does not cross an alignment
2063 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2064 or if the structure is packed. If this happens, then we get an object
2065 which starts after the bitfield, which means that the bit offset is
2066 negative. Gdb fails when given negative bit offsets. We avoid this
2067 by recomputing using the first bit of the bitfield. This will give
2068 us an object which does not completely contain the bitfield, but it
2069 will be aligned, and it will contain the first bit of the bitfield. */
2070 if (object_offset_in_bits > bitpos_int)
2072 deepest_bitpos = bitpos_int + 1;
2073 object_offset_in_bits
2074 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2075 object_offset_in_align_units = (object_offset_in_bits
2076 / type_align_in_bits);
2077 object_offset_in_bytes = (object_offset_in_align_units
2078 * type_align_in_bytes);
2081 return object_offset_in_bytes;
2084 /****************************** attributes *********************************/
2086 /* The following routines are responsible for writing out the various types
2087 of Dwarf attributes (and any following data bytes associated with them).
2088 These routines are listed in order based on the numerical codes of their
2089 associated attributes. */
2091 /* Generate an AT_sibling attribute. */
2094 sibling_attribute ()
2096 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2098 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2099 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2100 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2103 /* Output the form of location attributes suitable for whole variables and
2104 whole parameters. Note that the location attributes for struct fields
2105 are generated by the routine `data_member_location_attribute' below. */
2108 location_attribute (rtl)
2111 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2112 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2114 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2115 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2116 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2117 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2118 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2120 /* Handle a special case. If we are about to output a location descriptor
2121 for a variable or parameter which has been optimized out of existence,
2122 don't do that. Instead we output a zero-length location descriptor
2123 value as part of the location attribute.
2125 A variable which has been optimized out of existence will have a
2126 DECL_RTL value which denotes a pseudo-reg.
2128 Currently, in some rare cases, variables can have DECL_RTL values
2129 which look like (MEM (REG pseudo-reg#)). These cases are due to
2130 bugs elsewhere in the compiler. We treat such cases
2131 as if the variable(s) in question had been optimized out of existence.
2133 Note that in all cases where we wish to express the fact that a
2134 variable has been optimized out of existence, we do not simply
2135 suppress the generation of the entire location attribute because
2136 the absence of a location attribute in certain kinds of DIEs is
2137 used to indicate something else entirely... i.e. that the DIE
2138 represents an object declaration, but not a definition. So saith
2142 if (! is_pseudo_reg (rtl)
2143 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2144 output_loc_descriptor (rtl);
2146 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2149 /* Output the specialized form of location attribute used for data members
2150 of struct and union types.
2152 In the special case of a FIELD_DECL node which represents a bit-field,
2153 the "offset" part of this special location descriptor must indicate the
2154 distance in bytes from the lowest-addressed byte of the containing
2155 struct or union type to the lowest-addressed byte of the "containing
2156 object" for the bit-field. (See the `field_byte_offset' function above.)
2158 For any given bit-field, the "containing object" is a hypothetical
2159 object (of some integral or enum type) within which the given bit-field
2160 lives. The type of this hypothetical "containing object" is always the
2161 same as the declared type of the individual bit-field itself (for GCC
2162 anyway... the DWARF spec doesn't actually mandate this).
2164 Note that it is the size (in bytes) of the hypothetical "containing
2165 object" which will be given in the AT_byte_size attribute for this
2166 bit-field. (See the `byte_size_attribute' function below.) It is
2167 also used when calculating the value of the AT_bit_offset attribute.
2168 (See the `bit_offset_attribute' function below.) */
2171 data_member_location_attribute (t)
2174 register unsigned object_offset_in_bytes;
2175 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2176 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2178 if (TREE_CODE (t) == TREE_VEC)
2179 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2181 object_offset_in_bytes = field_byte_offset (t);
2183 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2184 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2185 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2186 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2187 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2188 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2189 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2190 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2191 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2194 /* Output an AT_const_value attribute for a variable or a parameter which
2195 does not have a "location" either in memory or in a register. These
2196 things can arise in GNU C when a constant is passed as an actual
2197 parameter to an inlined function. They can also arise in C++ where
2198 declared constants do not necessarily get memory "homes". */
2201 const_value_attribute (rtl)
2204 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2205 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2207 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2208 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2209 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2210 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2211 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2213 switch (GET_CODE (rtl))
2216 /* Note that a CONST_INT rtx could represent either an integer or
2217 a floating-point constant. A CONST_INT is used whenever the
2218 constant will fit into a single word. In all such cases, the
2219 original mode of the constant value is wiped out, and the
2220 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2221 precise mode information for these constants, we always just
2222 output them using 4 bytes. */
2224 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2228 /* Note that a CONST_DOUBLE rtx could represent either an integer
2229 or a floating-point constant. A CONST_DOUBLE is used whenever
2230 the constant requires more than one word in order to be adequately
2231 represented. In all such cases, the original mode of the constant
2232 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2233 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2235 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2236 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2237 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2241 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2247 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2251 /* In cases where an inlined instance of an inline function is passed
2252 the address of an `auto' variable (which is local to the caller)
2253 we can get a situation where the DECL_RTL of the artificial
2254 local variable (for the inlining) which acts as a stand-in for
2255 the corresponding formal parameter (of the inline function)
2256 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2257 This is not exactly a compile-time constant expression, but it
2258 isn't the address of the (artificial) local variable either.
2259 Rather, it represents the *value* which the artificial local
2260 variable always has during its lifetime. We currently have no
2261 way to represent such quasi-constant values in Dwarf, so for now
2262 we just punt and generate an AT_const_value attribute with form
2263 FORM_BLOCK4 and a length of zero. */
2267 abort (); /* No other kinds of rtx should be possible here. */
2270 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2273 /* Generate *either* an AT_location attribute or else an AT_const_value
2274 data attribute for a variable or a parameter. We generate the
2275 AT_const_value attribute only in those cases where the given
2276 variable or parameter does not have a true "location" either in
2277 memory or in a register. This can happen (for example) when a
2278 constant is passed as an actual argument in a call to an inline
2279 function. (It's possible that these things can crop up in other
2280 ways also.) Note that one type of constant value which can be
2281 passed into an inlined function is a constant pointer. This can
2282 happen for example if an actual argument in an inlined function
2283 call evaluates to a compile-time constant address. */
2286 location_or_const_value_attribute (decl)
2291 if (TREE_CODE (decl) == ERROR_MARK)
2294 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2296 /* Should never happen. */
2301 /* Here we have to decide where we are going to say the parameter "lives"
2302 (as far as the debugger is concerned). We only have a couple of choices.
2303 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2304 normally indicates where the parameter lives during most of the activa-
2305 tion of the function. If optimization is enabled however, this could
2306 be either NULL or else a pseudo-reg. Both of those cases indicate that
2307 the parameter doesn't really live anywhere (as far as the code generation
2308 parts of GCC are concerned) during most of the function's activation.
2309 That will happen (for example) if the parameter is never referenced
2310 within the function.
2312 We could just generate a location descriptor here for all non-NULL
2313 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2314 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2315 cases where DECL_RTL is NULL or is a pseudo-reg.
2317 Note however that we can only get away with using DECL_INCOMING_RTL as
2318 a backup substitute for DECL_RTL in certain limited cases. In cases
2319 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2320 we can be sure that the parameter was passed using the same type as it
2321 is declared to have within the function, and that its DECL_INCOMING_RTL
2322 points us to a place where a value of that type is passed. In cases
2323 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2324 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2325 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2326 points us to a value of some type which is *different* from the type
2327 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2328 to generate a location attribute in such cases, the debugger would
2329 end up (for example) trying to fetch a `float' from a place which
2330 actually contains the first part of a `double'. That would lead to
2331 really incorrect and confusing output at debug-time, and we don't
2332 want that now do we?
2334 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2335 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2336 couple of cute exceptions however. On little-endian machines we can
2337 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2338 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2339 an integral type which is smaller than TREE_TYPE(decl). These cases
2340 arise when (on a little-endian machine) a non-prototyped function has
2341 a parameter declared to be of type `short' or `char'. In such cases,
2342 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2343 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2344 passed `int' value. If the debugger then uses that address to fetch a
2345 `short' or a `char' (on a little-endian machine) the result will be the
2346 correct data, so we allow for such exceptional cases below.
2348 Note that our goal here is to describe the place where the given formal
2349 parameter lives during most of the function's activation (i.e. between
2350 the end of the prologue and the start of the epilogue). We'll do that
2351 as best as we can. Note however that if the given formal parameter is
2352 modified sometime during the execution of the function, then a stack
2353 backtrace (at debug-time) will show the function as having been called
2354 with the *new* value rather than the value which was originally passed
2355 in. This happens rarely enough that it is not a major problem, but it
2356 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2357 may generate two additional attributes for any given TAG_formal_parameter
2358 DIE which will describe the "passed type" and the "passed location" for
2359 the given formal parameter in addition to the attributes we now generate
2360 to indicate the "declared type" and the "active location" for each
2361 parameter. This additional set of attributes could be used by debuggers
2362 for stack backtraces.
2364 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2365 can be NULL also. This happens (for example) for inlined-instances of
2366 inline function formal parameters which are never referenced. This really
2367 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2368 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2369 these values for inlined instances of inline function parameters, so
2370 when we see such cases, we are just SOL (shit-out-of-luck) for the time
2371 being (until integrate.c gets fixed).
2374 /* Use DECL_RTL as the "location" unless we find something better. */
2375 rtl = DECL_RTL (decl);
2377 if (TREE_CODE (decl) == PARM_DECL)
2378 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2380 /* This decl represents a formal parameter which was optimized out. */
2381 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2382 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2384 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2385 *all* cases where (rtl == NULL_RTX) just below. */
2387 if (declared_type == passed_type)
2388 rtl = DECL_INCOMING_RTL (decl);
2389 else if (! BYTES_BIG_ENDIAN)
2390 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2391 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2392 rtl = DECL_INCOMING_RTL (decl);
2395 if (rtl == NULL_RTX)
2398 rtl = eliminate_regs (rtl, 0, NULL_RTX, 0);
2399 #ifdef LEAF_REG_REMAP
2401 leaf_renumber_regs_insn (rtl);
2404 switch (GET_CODE (rtl))
2412 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2413 const_value_attribute (rtl);
2419 location_attribute (rtl);
2423 /* ??? CONCAT is used for complex variables, which may have the real
2424 part stored in one place and the imag part stored somewhere else.
2425 DWARF1 has no way to describe a variable that lives in two different
2426 places, so we just describe where the first part lives, and hope that
2427 the second part is stored after it. */
2428 location_attribute (XEXP (rtl, 0));
2432 abort (); /* Should never happen. */
2436 /* Generate an AT_name attribute given some string value to be included as
2437 the value of the attribute. */
2440 name_attribute (name_string)
2441 register char *name_string;
2443 if (name_string && *name_string)
2445 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2446 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2451 fund_type_attribute (ft_code)
2452 register unsigned ft_code;
2454 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2455 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2459 mod_fund_type_attribute (type, decl_const, decl_volatile)
2461 register int decl_const;
2462 register int decl_volatile;
2464 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2465 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2467 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2468 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2469 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2470 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2471 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2472 write_modifier_bytes (type, decl_const, decl_volatile);
2473 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2474 fundamental_type_code (root_type (type)));
2475 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2479 user_def_type_attribute (type)
2482 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2484 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2485 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2486 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2490 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2492 register int decl_const;
2493 register int decl_volatile;
2495 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2496 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2497 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2499 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2500 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2501 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2502 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2503 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2504 write_modifier_bytes (type, decl_const, decl_volatile);
2505 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2506 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2507 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2510 #ifdef USE_ORDERING_ATTRIBUTE
2512 ordering_attribute (ordering)
2513 register unsigned ordering;
2515 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2516 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2518 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2520 /* Note that the block of subscript information for an array type also
2521 includes information about the element type of type given array type. */
2524 subscript_data_attribute (type)
2527 register unsigned dimension_number;
2528 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2529 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2531 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2532 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2533 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2534 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2535 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2537 /* The GNU compilers represent multidimensional array types as sequences
2538 of one dimensional array types whose element types are themselves array
2539 types. Here we squish that down, so that each multidimensional array
2540 type gets only one array_type DIE in the Dwarf debugging info. The
2541 draft Dwarf specification say that we are allowed to do this kind
2542 of compression in C (because there is no difference between an
2543 array or arrays and a multidimensional array in C) but for other
2544 source languages (e.g. Ada) we probably shouldn't do this. */
2546 for (dimension_number = 0;
2547 TREE_CODE (type) == ARRAY_TYPE;
2548 type = TREE_TYPE (type), dimension_number++)
2550 register tree domain = TYPE_DOMAIN (type);
2552 /* Arrays come in three flavors. Unspecified bounds, fixed
2553 bounds, and (in GNU C only) variable bounds. Handle all
2554 three forms here. */
2558 /* We have an array type with specified bounds. */
2560 register tree lower = TYPE_MIN_VALUE (domain);
2561 register tree upper = TYPE_MAX_VALUE (domain);
2563 /* Handle only fundamental types as index types for now. */
2565 if (! type_is_fundamental (domain))
2568 /* Output the representation format byte for this dimension. */
2570 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2572 TREE_CODE (lower) == INTEGER_CST,
2573 TREE_CODE (upper) == INTEGER_CST));
2575 /* Output the index type for this dimension. */
2577 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2578 fundamental_type_code (domain));
2580 /* Output the representation for the lower bound. */
2582 output_bound_representation (lower, dimension_number, 'l');
2584 /* Output the representation for the upper bound. */
2586 output_bound_representation (upper, dimension_number, 'u');
2590 /* We have an array type with an unspecified length. For C and
2591 C++ we can assume that this really means that (a) the index
2592 type is an integral type, and (b) the lower bound is zero.
2593 Note that Dwarf defines the representation of an unspecified
2594 (upper) bound as being a zero-length location description. */
2596 /* Output the array-bounds format byte. */
2598 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2600 /* Output the (assumed) index type. */
2602 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2604 /* Output the (assumed) lower bound (constant) value. */
2606 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2608 /* Output the (empty) location description for the upper bound. */
2610 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2614 /* Output the prefix byte that says that the element type is coming up. */
2616 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2618 /* Output a representation of the type of the elements of this array type. */
2620 type_attribute (type, 0, 0);
2622 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2626 byte_size_attribute (tree_node)
2627 register tree tree_node;
2629 register unsigned size;
2631 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2632 switch (TREE_CODE (tree_node))
2641 case QUAL_UNION_TYPE:
2642 size = int_size_in_bytes (tree_node);
2646 /* For a data member of a struct or union, the AT_byte_size is
2647 generally given as the number of bytes normally allocated for
2648 an object of the *declared* type of the member itself. This
2649 is true even for bit-fields. */
2650 size = simple_type_size_in_bits (field_type (tree_node))
2658 /* Note that `size' might be -1 when we get to this point. If it
2659 is, that indicates that the byte size of the entity in question
2660 is variable. We have no good way of expressing this fact in Dwarf
2661 at the present time, so just let the -1 pass on through. */
2663 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2666 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2667 which specifies the distance in bits from the highest order bit of the
2668 "containing object" for the bit-field to the highest order bit of the
2671 For any given bit-field, the "containing object" is a hypothetical
2672 object (of some integral or enum type) within which the given bit-field
2673 lives. The type of this hypothetical "containing object" is always the
2674 same as the declared type of the individual bit-field itself.
2676 The determination of the exact location of the "containing object" for
2677 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2680 Note that it is the size (in bytes) of the hypothetical "containing
2681 object" which will be given in the AT_byte_size attribute for this
2682 bit-field. (See `byte_size_attribute' above.) */
2685 bit_offset_attribute (decl)
2688 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2689 register tree type = DECL_BIT_FIELD_TYPE (decl);
2690 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2691 register unsigned bitpos_int;
2692 register unsigned highest_order_object_bit_offset;
2693 register unsigned highest_order_field_bit_offset;
2694 register unsigned bit_offset;
2696 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2697 assert (type); /* Must be a bit field. */
2699 /* We can't yet handle bit-fields whose offsets are variable, so if we
2700 encounter such things, just return without generating any attribute
2703 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2705 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2707 /* Note that the bit offset is always the distance (in bits) from the
2708 highest-order bit of the "containing object" to the highest-order
2709 bit of the bit-field itself. Since the "high-order end" of any
2710 object or field is different on big-endian and little-endian machines,
2711 the computation below must take account of these differences. */
2713 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2714 highest_order_field_bit_offset = bitpos_int;
2716 if (! BYTES_BIG_ENDIAN)
2718 highest_order_field_bit_offset
2719 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2721 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2726 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2727 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2729 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2730 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2733 /* For a FIELD_DECL node which represents a bit field, output an attribute
2734 which specifies the length in bits of the given field. */
2737 bit_size_attribute (decl)
2740 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2741 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
2743 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2744 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2745 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2748 /* The following routine outputs the `element_list' attribute for enumeration
2749 type DIEs. The element_lits attribute includes the names and values of
2750 all of the enumeration constants associated with the given enumeration
2754 element_list_attribute (element)
2755 register tree element;
2757 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2758 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2760 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2761 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2762 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2763 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2764 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2766 /* Here we output a list of value/name pairs for each enumeration constant
2767 defined for this enumeration type (as required), but we do it in REVERSE
2768 order. The order is the one required by the draft #5 Dwarf specification
2769 published by the UI/PLSIG. */
2771 output_enumeral_list (element); /* Recursively output the whole list. */
2773 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2776 /* Generate an AT_stmt_list attribute. These are normally present only in
2777 DIEs with a TAG_compile_unit tag. */
2780 stmt_list_attribute (label)
2781 register char *label;
2783 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2784 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2785 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2788 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2789 for a subroutine DIE. */
2792 low_pc_attribute (asm_low_label)
2793 register char *asm_low_label;
2795 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2796 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2799 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2803 high_pc_attribute (asm_high_label)
2804 register char *asm_high_label;
2806 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2807 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2810 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2813 body_begin_attribute (asm_begin_label)
2814 register char *asm_begin_label;
2816 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2817 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2820 /* Generate an AT_body_end attribute for a subroutine DIE. */
2823 body_end_attribute (asm_end_label)
2824 register char *asm_end_label;
2826 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2827 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2830 /* Generate an AT_language attribute given a LANG value. These attributes
2831 are used only within TAG_compile_unit DIEs. */
2834 language_attribute (language_code)
2835 register unsigned language_code;
2837 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2838 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2842 member_attribute (context)
2843 register tree context;
2845 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2847 /* Generate this attribute only for members in C++. */
2849 if (context != NULL && is_tagged_type (context))
2851 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2852 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2853 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2858 string_length_attribute (upper_bound)
2859 register tree upper_bound;
2861 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2862 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2864 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2865 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2866 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2867 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2868 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2869 output_bound_representation (upper_bound, 0, 'u');
2870 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2874 comp_dir_attribute (dirname)
2875 register char *dirname;
2877 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2878 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2882 sf_names_attribute (sf_names_start_label)
2883 register char *sf_names_start_label;
2885 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2886 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2887 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2891 src_info_attribute (src_info_start_label)
2892 register char *src_info_start_label;
2894 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2895 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2896 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2900 mac_info_attribute (mac_info_start_label)
2901 register char *mac_info_start_label;
2903 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2904 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2905 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2909 prototyped_attribute (func_type)
2910 register tree func_type;
2912 if ((strcmp (language_string, "GNU C") == 0)
2913 && (TYPE_ARG_TYPES (func_type) != NULL))
2915 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2916 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2921 producer_attribute (producer)
2922 register char *producer;
2924 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2925 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2929 inline_attribute (decl)
2932 if (DECL_INLINE (decl))
2934 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2935 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2940 containing_type_attribute (containing_type)
2941 register tree containing_type;
2943 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2945 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2946 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2947 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2951 abstract_origin_attribute (origin)
2952 register tree origin;
2954 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2956 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2957 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2960 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2964 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2968 abort (); /* Should never happen. */
2971 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2974 #ifdef DWARF_DECL_COORDINATES
2976 src_coords_attribute (src_fileno, src_lineno)
2977 register unsigned src_fileno;
2978 register unsigned src_lineno;
2980 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2981 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2982 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2984 #endif /* defined(DWARF_DECL_COORDINATES) */
2987 pure_or_virtual_attribute (func_decl)
2988 register tree func_decl;
2990 if (DECL_VIRTUAL_P (func_decl))
2992 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
2993 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2994 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2997 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2998 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3002 /************************* end of attributes *****************************/
3004 /********************* utility routines for DIEs *************************/
3006 /* Output an AT_name attribute and an AT_src_coords attribute for the
3007 given decl, but only if it actually has a name. */
3010 name_and_src_coords_attributes (decl)
3013 register tree decl_name = DECL_NAME (decl);
3015 if (decl_name && IDENTIFIER_POINTER (decl_name))
3017 name_attribute (IDENTIFIER_POINTER (decl_name));
3018 #ifdef DWARF_DECL_COORDINATES
3020 register unsigned file_index;
3022 /* This is annoying, but we have to pop out of the .debug section
3023 for a moment while we call `lookup_filename' because calling it
3024 may cause a temporary switch into the .debug_sfnames section and
3025 most svr4 assemblers are not smart enough be be able to nest
3026 section switches to any depth greater than one. Note that we
3027 also can't skirt this issue by delaying all output to the
3028 .debug_sfnames section unit the end of compilation because that
3029 would cause us to have inter-section forward references and
3030 Fred Fish sez that m68k/svr4 assemblers botch those. */
3032 ASM_OUTPUT_POP_SECTION (asm_out_file);
3033 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3034 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3036 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3038 #endif /* defined(DWARF_DECL_COORDINATES) */
3042 /* Many forms of DIEs contain a "type description" part. The following
3043 routine writes out these "type descriptor" parts. */
3046 type_attribute (type, decl_const, decl_volatile)
3048 register int decl_const;
3049 register int decl_volatile;
3051 register enum tree_code code = TREE_CODE (type);
3052 register int root_type_modified;
3054 if (code == ERROR_MARK)
3057 /* Handle a special case. For functions whose return type is void,
3058 we generate *no* type attribute. (Note that no object may have
3059 type `void', so this only applies to function return types. */
3061 if (code == VOID_TYPE)
3064 /* If this is a subtype, find the underlying type. Eventually,
3065 this should write out the appropriate subtype info. */
3066 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3067 && TREE_TYPE (type) != 0)
3068 type = TREE_TYPE (type), code = TREE_CODE (type);
3070 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3071 || decl_const || decl_volatile
3072 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3074 if (type_is_fundamental (root_type (type)))
3075 if (root_type_modified)
3076 mod_fund_type_attribute (type, decl_const, decl_volatile);
3078 fund_type_attribute (fundamental_type_code (type));
3080 if (root_type_modified)
3081 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3083 /* We have to get the type_main_variant here (and pass that to the
3084 `user_def_type_attribute' routine) because the ..._TYPE node we
3085 have might simply be a *copy* of some original type node (where
3086 the copy was created to help us keep track of typedef names)
3087 and that copy might have a different TYPE_UID from the original
3088 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3089 is labeling a given type DIE for future reference, it always and
3090 only creates labels for DIEs representing *main variants*, and it
3091 never even knows about non-main-variants.) */
3092 user_def_type_attribute (type_main_variant (type));
3095 /* Given a tree pointer to a struct, class, union, or enum type node, return
3096 a pointer to the (string) tag name for the given type, or zero if the
3097 type was declared without a tag. */
3103 register char *name = 0;
3105 if (TYPE_NAME (type) != 0)
3107 register tree t = 0;
3109 /* Find the IDENTIFIER_NODE for the type name. */
3110 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3111 t = TYPE_NAME (type);
3113 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3114 a TYPE_DECL node, regardless of whether or not a `typedef' was
3116 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3117 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3118 t = DECL_NAME (TYPE_NAME (type));
3120 /* Now get the name as a string, or invent one. */
3122 name = IDENTIFIER_POINTER (t);
3125 return (name == 0 || *name == '\0') ? 0 : name;
3131 /* Start by checking if the pending_sibling_stack needs to be expanded.
3132 If necessary, expand it. */
3134 if (pending_siblings == pending_siblings_allocated)
3136 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3137 pending_sibling_stack
3138 = (unsigned *) xrealloc (pending_sibling_stack,
3139 pending_siblings_allocated * sizeof(unsigned));
3143 NEXT_DIE_NUM = next_unused_dienum++;
3146 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3156 member_declared_type (member)
3157 register tree member;
3159 return (DECL_BIT_FIELD_TYPE (member))
3160 ? DECL_BIT_FIELD_TYPE (member)
3161 : TREE_TYPE (member);
3164 /* Get the function's label, as described by its RTL.
3165 This may be different from the DECL_NAME name used
3166 in the source file. */
3169 function_start_label (decl)
3175 x = DECL_RTL (decl);
3176 if (GET_CODE (x) != MEM)
3179 if (GET_CODE (x) != SYMBOL_REF)
3181 fnname = XSTR (x, 0);
3186 /******************************* DIEs ************************************/
3188 /* Output routines for individual types of DIEs. */
3190 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3193 output_array_type_die (arg)
3196 register tree type = arg;
3198 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3199 sibling_attribute ();
3200 equate_type_number_to_die_number (type);
3201 member_attribute (TYPE_CONTEXT (type));
3203 /* I believe that we can default the array ordering. SDB will probably
3204 do the right things even if AT_ordering is not present. It's not
3205 even an issue until we start to get into multidimensional arrays
3206 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3207 dimensional arrays, then we'll have to put the AT_ordering attribute
3208 back in. (But if and when we find out that we need to put these in,
3209 we will only do so for multidimensional arrays. After all, we don't
3210 want to waste space in the .debug section now do we?) */
3212 #ifdef USE_ORDERING_ATTRIBUTE
3213 ordering_attribute (ORD_row_major);
3214 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3216 subscript_data_attribute (type);
3220 output_set_type_die (arg)
3223 register tree type = arg;
3225 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3226 sibling_attribute ();
3227 equate_type_number_to_die_number (type);
3228 member_attribute (TYPE_CONTEXT (type));
3229 type_attribute (TREE_TYPE (type), 0, 0);
3233 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3236 output_entry_point_die (arg)
3239 register tree decl = arg;
3240 register tree origin = decl_ultimate_origin (decl);
3242 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3243 sibling_attribute ();
3246 abstract_origin_attribute (origin);
3249 name_and_src_coords_attributes (decl);
3250 member_attribute (DECL_CONTEXT (decl));
3251 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3253 if (DECL_ABSTRACT (decl))
3254 equate_decl_number_to_die_number (decl);
3256 low_pc_attribute (function_start_label (decl));
3260 /* Output a DIE to represent an inlined instance of an enumeration type. */
3263 output_inlined_enumeration_type_die (arg)
3266 register tree type = arg;
3268 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3269 sibling_attribute ();
3270 assert (TREE_ASM_WRITTEN (type));
3271 abstract_origin_attribute (type);
3274 /* Output a DIE to represent an inlined instance of a structure type. */
3277 output_inlined_structure_type_die (arg)
3280 register tree type = arg;
3282 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3283 sibling_attribute ();
3284 assert (TREE_ASM_WRITTEN (type));
3285 abstract_origin_attribute (type);
3288 /* Output a DIE to represent an inlined instance of a union type. */
3291 output_inlined_union_type_die (arg)
3294 register tree type = arg;
3296 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3297 sibling_attribute ();
3298 assert (TREE_ASM_WRITTEN (type));
3299 abstract_origin_attribute (type);
3302 /* Output a DIE to represent an enumeration type. Note that these DIEs
3303 include all of the information about the enumeration values also.
3304 This information is encoded into the element_list attribute. */
3307 output_enumeration_type_die (arg)
3310 register tree type = arg;
3312 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3313 sibling_attribute ();
3314 equate_type_number_to_die_number (type);
3315 name_attribute (type_tag (type));
3316 member_attribute (TYPE_CONTEXT (type));
3318 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3319 given enum type is incomplete, do not generate the AT_byte_size
3320 attribute or the AT_element_list attribute. */
3322 if (TYPE_SIZE (type))
3324 byte_size_attribute (type);
3325 element_list_attribute (TYPE_FIELDS (type));
3329 /* Output a DIE to represent either a real live formal parameter decl or
3330 to represent just the type of some formal parameter position in some
3333 Note that this routine is a bit unusual because its argument may be
3334 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3335 represents an inlining of some PARM_DECL) or else some sort of a
3336 ..._TYPE node. If it's the former then this function is being called
3337 to output a DIE to represent a formal parameter object (or some inlining
3338 thereof). If it's the latter, then this function is only being called
3339 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3340 formal argument type of some subprogram type. */
3343 output_formal_parameter_die (arg)
3346 register tree node = arg;
3348 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3349 sibling_attribute ();
3351 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3353 case 'd': /* We were called with some kind of a ..._DECL node. */
3355 register tree origin = decl_ultimate_origin (node);
3358 abstract_origin_attribute (origin);
3361 name_and_src_coords_attributes (node);
3362 type_attribute (TREE_TYPE (node),
3363 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3365 if (DECL_ABSTRACT (node))
3366 equate_decl_number_to_die_number (node);
3368 location_or_const_value_attribute (node);
3372 case 't': /* We were called with some kind of a ..._TYPE node. */
3373 type_attribute (node, 0, 0);
3377 abort (); /* Should never happen. */
3381 /* Output a DIE to represent a declared function (either file-scope
3382 or block-local) which has "external linkage" (according to ANSI-C). */
3385 output_global_subroutine_die (arg)
3388 register tree decl = arg;
3389 register tree origin = decl_ultimate_origin (decl);
3391 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3392 sibling_attribute ();
3395 abstract_origin_attribute (origin);
3398 register tree type = TREE_TYPE (decl);
3400 name_and_src_coords_attributes (decl);
3401 inline_attribute (decl);
3402 prototyped_attribute (type);
3403 member_attribute (DECL_CONTEXT (decl));
3404 type_attribute (TREE_TYPE (type), 0, 0);
3405 pure_or_virtual_attribute (decl);
3407 if (DECL_ABSTRACT (decl))
3408 equate_decl_number_to_die_number (decl);
3411 if (! DECL_EXTERNAL (decl) && ! in_class
3412 && decl == current_function_decl)
3414 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3416 low_pc_attribute (function_start_label (decl));
3417 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3418 high_pc_attribute (label);
3419 if (use_gnu_debug_info_extensions)
3421 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3422 body_begin_attribute (label);
3423 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3424 body_end_attribute (label);
3430 /* Output a DIE to represent a declared data object (either file-scope
3431 or block-local) which has "external linkage" (according to ANSI-C). */
3434 output_global_variable_die (arg)
3437 register tree decl = arg;
3438 register tree origin = decl_ultimate_origin (decl);
3440 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3441 sibling_attribute ();
3443 abstract_origin_attribute (origin);
3446 name_and_src_coords_attributes (decl);
3447 member_attribute (DECL_CONTEXT (decl));
3448 type_attribute (TREE_TYPE (decl),
3449 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3451 if (DECL_ABSTRACT (decl))
3452 equate_decl_number_to_die_number (decl);
3455 if (! DECL_EXTERNAL (decl) && ! in_class
3456 && current_function_decl == decl_function_context (decl))
3457 location_or_const_value_attribute (decl);
3462 output_label_die (arg)
3465 register tree decl = arg;
3466 register tree origin = decl_ultimate_origin (decl);
3468 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3469 sibling_attribute ();
3471 abstract_origin_attribute (origin);
3473 name_and_src_coords_attributes (decl);
3474 if (DECL_ABSTRACT (decl))
3475 equate_decl_number_to_die_number (decl);
3478 register rtx insn = DECL_RTL (decl);
3480 if (GET_CODE (insn) == CODE_LABEL)
3482 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3484 /* When optimization is enabled (via -O) some parts of the compiler
3485 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3486 represent source-level labels which were explicitly declared by
3487 the user. This really shouldn't be happening though, so catch
3488 it if it ever does happen. */
3490 if (INSN_DELETED_P (insn))
3491 abort (); /* Should never happen. */
3493 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3494 (unsigned) INSN_UID (insn));
3495 low_pc_attribute (label);
3501 output_lexical_block_die (arg)
3504 register tree stmt = arg;
3506 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3507 sibling_attribute ();
3509 if (! BLOCK_ABSTRACT (stmt))
3511 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3512 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3514 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3515 low_pc_attribute (begin_label);
3516 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3517 high_pc_attribute (end_label);
3522 output_inlined_subroutine_die (arg)
3525 register tree stmt = arg;
3527 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3528 sibling_attribute ();
3530 abstract_origin_attribute (block_ultimate_origin (stmt));
3531 if (! BLOCK_ABSTRACT (stmt))
3533 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3534 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3536 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3537 low_pc_attribute (begin_label);
3538 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3539 high_pc_attribute (end_label);
3543 /* Output a DIE to represent a declared data object (either file-scope
3544 or block-local) which has "internal linkage" (according to ANSI-C). */
3547 output_local_variable_die (arg)
3550 register tree decl = arg;
3551 register tree origin = decl_ultimate_origin (decl);
3553 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3554 sibling_attribute ();
3556 abstract_origin_attribute (origin);
3559 name_and_src_coords_attributes (decl);
3560 member_attribute (DECL_CONTEXT (decl));
3561 type_attribute (TREE_TYPE (decl),
3562 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3564 if (DECL_ABSTRACT (decl))
3565 equate_decl_number_to_die_number (decl);
3567 location_or_const_value_attribute (decl);
3571 output_member_die (arg)
3574 register tree decl = arg;
3576 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3577 sibling_attribute ();
3578 name_and_src_coords_attributes (decl);
3579 member_attribute (DECL_CONTEXT (decl));
3580 type_attribute (member_declared_type (decl),
3581 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3582 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3584 byte_size_attribute (decl);
3585 bit_size_attribute (decl);
3586 bit_offset_attribute (decl);
3588 data_member_location_attribute (decl);
3592 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3593 modified types instead.
3595 We keep this code here just in case these types of DIEs may be
3596 needed to represent certain things in other languages (e.g. Pascal)
3600 output_pointer_type_die (arg)
3603 register tree type = arg;
3605 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3606 sibling_attribute ();
3607 equate_type_number_to_die_number (type);
3608 member_attribute (TYPE_CONTEXT (type));
3609 type_attribute (TREE_TYPE (type), 0, 0);
3613 output_reference_type_die (arg)
3616 register tree type = arg;
3618 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3619 sibling_attribute ();
3620 equate_type_number_to_die_number (type);
3621 member_attribute (TYPE_CONTEXT (type));
3622 type_attribute (TREE_TYPE (type), 0, 0);
3627 output_ptr_to_mbr_type_die (arg)
3630 register tree type = arg;
3632 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3633 sibling_attribute ();
3634 equate_type_number_to_die_number (type);
3635 member_attribute (TYPE_CONTEXT (type));
3636 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3637 type_attribute (TREE_TYPE (type), 0, 0);
3641 output_compile_unit_die (arg)
3644 register char *main_input_filename = arg;
3646 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3647 sibling_attribute ();
3649 name_attribute (main_input_filename);
3654 sprintf (producer, "%s %s", language_string, version_string);
3655 producer_attribute (producer);
3658 if (strcmp (language_string, "GNU C++") == 0)
3659 language_attribute (LANG_C_PLUS_PLUS);
3660 else if (strcmp (language_string, "GNU Ada") == 0)
3661 language_attribute (LANG_ADA83);
3662 else if (strcmp (language_string, "GNU F77") == 0)
3663 language_attribute (LANG_FORTRAN77);
3664 else if (strcmp (language_string, "GNU Pascal") == 0)
3665 language_attribute (LANG_PASCAL83);
3666 else if (flag_traditional)
3667 language_attribute (LANG_C);
3669 language_attribute (LANG_C89);
3670 low_pc_attribute (TEXT_BEGIN_LABEL);
3671 high_pc_attribute (TEXT_END_LABEL);
3672 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3673 stmt_list_attribute (LINE_BEGIN_LABEL);
3674 last_filename = xstrdup (main_input_filename);
3677 char *wd = getpwd ();
3679 comp_dir_attribute (wd);
3682 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3684 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3685 src_info_attribute (SRCINFO_BEGIN_LABEL);
3686 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3687 mac_info_attribute (MACINFO_BEGIN_LABEL);
3692 output_string_type_die (arg)
3695 register tree type = arg;
3697 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3698 sibling_attribute ();
3699 member_attribute (TYPE_CONTEXT (type));
3701 /* Fudge the string length attribute for now. */
3703 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
3707 output_inheritance_die (arg)
3710 register tree binfo = arg;
3712 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3713 sibling_attribute ();
3714 type_attribute (BINFO_TYPE (binfo), 0, 0);
3715 data_member_location_attribute (binfo);
3716 if (TREE_VIA_VIRTUAL (binfo))
3718 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3719 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3721 if (TREE_VIA_PUBLIC (binfo))
3723 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3724 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3726 else if (TREE_VIA_PROTECTED (binfo))
3728 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3729 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3734 output_structure_type_die (arg)
3737 register tree type = arg;
3739 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3740 sibling_attribute ();
3741 equate_type_number_to_die_number (type);
3742 name_attribute (type_tag (type));
3743 member_attribute (TYPE_CONTEXT (type));
3745 /* If this type has been completed, then give it a byte_size attribute
3746 and prepare to give a list of members. Otherwise, don't do either of
3747 these things. In the latter case, we will not be generating a list
3748 of members (since we don't have any idea what they might be for an
3749 incomplete type). */
3751 if (TYPE_SIZE (type))
3754 byte_size_attribute (type);
3758 /* Output a DIE to represent a declared function (either file-scope
3759 or block-local) which has "internal linkage" (according to ANSI-C). */
3762 output_local_subroutine_die (arg)
3765 register tree decl = arg;
3766 register tree origin = decl_ultimate_origin (decl);
3768 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3769 sibling_attribute ();
3772 abstract_origin_attribute (origin);
3775 register tree type = TREE_TYPE (decl);
3777 name_and_src_coords_attributes (decl);
3778 inline_attribute (decl);
3779 prototyped_attribute (type);
3780 member_attribute (DECL_CONTEXT (decl));
3781 type_attribute (TREE_TYPE (type), 0, 0);
3782 pure_or_virtual_attribute (decl);
3784 if (DECL_ABSTRACT (decl))
3785 equate_decl_number_to_die_number (decl);
3788 /* Avoid getting screwed up in cases where a function was declared
3789 static but where no definition was ever given for it. */
3791 if (TREE_ASM_WRITTEN (decl))
3793 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3794 low_pc_attribute (function_start_label (decl));
3795 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3796 high_pc_attribute (label);
3797 if (use_gnu_debug_info_extensions)
3799 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3800 body_begin_attribute (label);
3801 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3802 body_end_attribute (label);
3809 output_subroutine_type_die (arg)
3812 register tree type = arg;
3813 register tree return_type = TREE_TYPE (type);
3815 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3816 sibling_attribute ();
3818 equate_type_number_to_die_number (type);
3819 prototyped_attribute (type);
3820 member_attribute (TYPE_CONTEXT (type));
3821 type_attribute (return_type, 0, 0);
3825 output_typedef_die (arg)
3828 register tree decl = arg;
3829 register tree origin = decl_ultimate_origin (decl);
3831 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3832 sibling_attribute ();
3834 abstract_origin_attribute (origin);
3837 name_and_src_coords_attributes (decl);
3838 member_attribute (DECL_CONTEXT (decl));
3839 type_attribute (TREE_TYPE (decl),
3840 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3842 if (DECL_ABSTRACT (decl))
3843 equate_decl_number_to_die_number (decl);
3847 output_union_type_die (arg)
3850 register tree type = arg;
3852 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3853 sibling_attribute ();
3854 equate_type_number_to_die_number (type);
3855 name_attribute (type_tag (type));
3856 member_attribute (TYPE_CONTEXT (type));
3858 /* If this type has been completed, then give it a byte_size attribute
3859 and prepare to give a list of members. Otherwise, don't do either of
3860 these things. In the latter case, we will not be generating a list
3861 of members (since we don't have any idea what they might be for an
3862 incomplete type). */
3864 if (TYPE_SIZE (type))
3867 byte_size_attribute (type);
3871 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3872 at the end of an (ANSI prototyped) formal parameters list. */
3875 output_unspecified_parameters_die (arg)
3878 register tree decl_or_type = arg;
3880 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3881 sibling_attribute ();
3883 /* This kludge is here only for the sake of being compatible with what
3884 the USL CI5 C compiler does. The specification of Dwarf Version 1
3885 doesn't say that TAG_unspecified_parameters DIEs should contain any
3886 attributes other than the AT_sibling attribute, but they are certainly
3887 allowed to contain additional attributes, and the CI5 compiler
3888 generates AT_name, AT_fund_type, and AT_location attributes within
3889 TAG_unspecified_parameters DIEs which appear in the child lists for
3890 DIEs representing function definitions, so we do likewise here. */
3892 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3894 name_attribute ("...");
3895 fund_type_attribute (FT_pointer);
3896 /* location_attribute (?); */
3901 output_padded_null_die (arg)
3904 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3907 /*************************** end of DIEs *********************************/
3909 /* Generate some type of DIE. This routine generates the generic outer
3910 wrapper stuff which goes around all types of DIE's (regardless of their
3911 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3912 DIE-length word, followed by the guts of the DIE itself. After the guts
3913 of the DIE, there must always be a terminator label for the DIE. */
3916 output_die (die_specific_output_function, param)
3917 register void (*die_specific_output_function)();
3918 register void *param;
3920 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3921 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3923 current_dienum = NEXT_DIE_NUM;
3924 NEXT_DIE_NUM = next_unused_dienum;
3926 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3927 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3929 /* Write a label which will act as the name for the start of this DIE. */
3931 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3933 /* Write the DIE-length word. */
3935 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3937 /* Fill in the guts of the DIE. */
3939 next_unused_dienum++;
3940 die_specific_output_function (param);
3942 /* Write a label which will act as the name for the end of this DIE. */
3944 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3948 end_sibling_chain ()
3950 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3952 current_dienum = NEXT_DIE_NUM;
3953 NEXT_DIE_NUM = next_unused_dienum;
3955 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3957 /* Write a label which will act as the name for the start of this DIE. */
3959 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3961 /* Write the DIE-length word. */
3963 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3968 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3969 TAG_unspecified_parameters DIE) to represent the types of the formal
3970 parameters as specified in some function type specification (except
3971 for those which appear as part of a function *definition*).
3973 Note that we must be careful here to output all of the parameter
3974 DIEs *before* we output any DIEs needed to represent the types of
3975 the formal parameters. This keeps svr4 SDB happy because it
3976 (incorrectly) thinks that the first non-parameter DIE it sees ends
3977 the formal parameter list. */
3980 output_formal_types (function_or_method_type)
3981 register tree function_or_method_type;
3984 register tree formal_type = NULL;
3985 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3987 /* In the case where we are generating a formal types list for a C++
3988 non-static member function type, skip over the first thing on the
3989 TYPE_ARG_TYPES list because it only represents the type of the
3990 hidden `this pointer'. The debugger should be able to figure
3991 out (without being explicitly told) that this non-static member
3992 function type takes a `this pointer' and should be able to figure
3993 what the type of that hidden parameter is from the AT_member
3994 attribute of the parent TAG_subroutine_type DIE. */
3996 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3997 first_parm_type = TREE_CHAIN (first_parm_type);
3999 /* Make our first pass over the list of formal parameter types and output
4000 a TAG_formal_parameter DIE for each one. */
4002 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4004 formal_type = TREE_VALUE (link);
4005 if (formal_type == void_type_node)
4008 /* Output a (nameless) DIE to represent the formal parameter itself. */
4010 output_die (output_formal_parameter_die, formal_type);
4013 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4014 DIE to the end of the parameter list. */
4016 if (formal_type != void_type_node)
4017 output_die (output_unspecified_parameters_die, function_or_method_type);
4019 /* Make our second (and final) pass over the list of formal parameter types
4020 and output DIEs to represent those types (as necessary). */
4022 for (link = TYPE_ARG_TYPES (function_or_method_type);
4024 link = TREE_CHAIN (link))
4026 formal_type = TREE_VALUE (link);
4027 if (formal_type == void_type_node)
4030 output_type (formal_type, function_or_method_type);
4034 /* Remember a type in the pending_types_list. */
4040 if (pending_types == pending_types_allocated)
4042 pending_types_allocated += PENDING_TYPES_INCREMENT;
4044 = (tree *) xrealloc (pending_types_list,
4045 sizeof (tree) * pending_types_allocated);
4047 pending_types_list[pending_types++] = type;
4049 /* Mark the pending type as having been output already (even though
4050 it hasn't been). This prevents the type from being added to the
4051 pending_types_list more than once. */
4053 TREE_ASM_WRITTEN (type) = 1;
4056 /* Return non-zero if it is legitimate to output DIEs to represent a
4057 given type while we are generating the list of child DIEs for some
4058 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4060 See the comments within the function for a description of when it is
4061 considered legitimate to output DIEs for various kinds of types.
4063 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4064 or it may point to a BLOCK node (for types local to a block), or to a
4065 FUNCTION_DECL node (for types local to the heading of some function
4066 definition), or to a FUNCTION_TYPE node (for types local to the
4067 prototyped parameter list of a function type specification), or to a
4068 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4069 (in the case of C++ nested types).
4071 The `scope' parameter should likewise be NULL or should point to a
4072 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4073 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4075 This function is used only for deciding when to "pend" and when to
4076 "un-pend" types to/from the pending_types_list.
4078 Note that we sometimes make use of this "type pending" feature in a
4079 rather twisted way to temporarily delay the production of DIEs for the
4080 types of formal parameters. (We do this just to make svr4 SDB happy.)
4081 It order to delay the production of DIEs representing types of formal
4082 parameters, callers of this function supply `fake_containing_scope' as
4083 the `scope' parameter to this function. Given that fake_containing_scope
4084 is a tagged type which is *not* the containing scope for *any* other type,
4085 the desired effect is achieved, i.e. output of DIEs representing types
4086 is temporarily suspended, and any type DIEs which would have otherwise
4087 been output are instead placed onto the pending_types_list. Later on,
4088 we force these (temporarily pended) types to be output simply by calling
4089 `output_pending_types_for_scope' with an actual argument equal to the
4090 true scope of the types we temporarily pended. */
4093 type_ok_for_scope (type, scope)
4095 register tree scope;
4097 /* Tagged types (i.e. struct, union, and enum types) must always be
4098 output only in the scopes where they actually belong (or else the
4099 scoping of their own tag names and the scoping of their member
4100 names will be incorrect). Non-tagged-types on the other hand can
4101 generally be output anywhere, except that svr4 SDB really doesn't
4102 want to see them nested within struct or union types, so here we
4103 say it is always OK to immediately output any such a (non-tagged)
4104 type, so long as we are not within such a context. Note that the
4105 only kinds of non-tagged types which we will be dealing with here
4106 (for C and C++ anyway) will be array types and function types. */
4108 return is_tagged_type (type)
4109 ? (TYPE_CONTEXT (type) == scope
4110 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4111 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4112 : (scope == NULL_TREE || ! is_tagged_type (scope));
4115 /* Output any pending types (from the pending_types list) which we can output
4116 now (taking into account the scope that we are working on now).
4118 For each type output, remove the given type from the pending_types_list
4119 *before* we try to output it.
4121 Note that we have to process the list in beginning-to-end order,
4122 because the call made here to output_type may cause yet more types
4123 to be added to the end of the list, and we may have to output some
4127 output_pending_types_for_scope (containing_scope)
4128 register tree containing_scope;
4130 register unsigned i;
4132 for (i = 0; i < pending_types; )
4134 register tree type = pending_types_list[i];
4136 if (type_ok_for_scope (type, containing_scope))
4138 register tree *mover;
4139 register tree *limit;
4142 limit = &pending_types_list[pending_types];
4143 for (mover = &pending_types_list[i]; mover < limit; mover++)
4144 *mover = *(mover+1);
4146 /* Un-mark the type as having been output already (because it
4147 hasn't been, really). Then call output_type to generate a
4148 Dwarf representation of it. */
4150 TREE_ASM_WRITTEN (type) = 0;
4151 output_type (type, containing_scope);
4153 /* Don't increment the loop counter in this case because we
4154 have shifted all of the subsequent pending types down one
4155 element in the pending_types_list array. */
4163 output_type (type, containing_scope)
4165 register tree containing_scope;
4167 if (type == 0 || type == error_mark_node)
4170 /* We are going to output a DIE to represent the unqualified version of
4171 of this type (i.e. without any const or volatile qualifiers) so get
4172 the main variant (i.e. the unqualified version) of this type now. */
4174 type = type_main_variant (type);
4176 if (TREE_ASM_WRITTEN (type))
4179 /* If this is a nested type whose containing class hasn't been
4180 written out yet, writing it out will cover this one, too. */
4182 if (TYPE_CONTEXT (type)
4183 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4184 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4186 output_type (TYPE_CONTEXT (type), containing_scope);
4190 /* Don't generate any DIEs for this type now unless it is OK to do so
4191 (based upon what `type_ok_for_scope' tells us). */
4193 if (! type_ok_for_scope (type, containing_scope))
4199 switch (TREE_CODE (type))
4205 case REFERENCE_TYPE:
4206 /* Prevent infinite recursion in cases where this is a recursive
4207 type. Recursive types are possible in Ada. */
4208 TREE_ASM_WRITTEN (type) = 1;
4209 /* For these types, all that is required is that we output a DIE
4210 (or a set of DIEs) to represent the "basis" type. */
4211 output_type (TREE_TYPE (type), containing_scope);
4215 /* This code is used for C++ pointer-to-data-member types. */
4216 /* Output a description of the relevant class type. */
4217 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4218 /* Output a description of the type of the object pointed to. */
4219 output_type (TREE_TYPE (type), containing_scope);
4220 /* Now output a DIE to represent this pointer-to-data-member type
4222 output_die (output_ptr_to_mbr_type_die, type);
4226 output_type (TYPE_DOMAIN (type), containing_scope);
4227 output_die (output_set_type_die, type);
4231 output_type (TREE_TYPE (type), containing_scope);
4232 abort (); /* No way to represent these in Dwarf yet! */
4236 /* Force out return type (in case it wasn't forced out already). */
4237 output_type (TREE_TYPE (type), containing_scope);
4238 output_die (output_subroutine_type_die, type);
4239 output_formal_types (type);
4240 end_sibling_chain ();
4244 /* Force out return type (in case it wasn't forced out already). */
4245 output_type (TREE_TYPE (type), containing_scope);
4246 output_die (output_subroutine_type_die, type);
4247 output_formal_types (type);
4248 end_sibling_chain ();
4252 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4254 output_type (TREE_TYPE (type), containing_scope);
4255 output_die (output_string_type_die, type);
4259 register tree element_type;
4261 element_type = TREE_TYPE (type);
4262 while (TREE_CODE (element_type) == ARRAY_TYPE)
4263 element_type = TREE_TYPE (element_type);
4265 output_type (element_type, containing_scope);
4266 output_die (output_array_type_die, type);
4273 case QUAL_UNION_TYPE:
4275 /* For a non-file-scope tagged type, we can always go ahead and
4276 output a Dwarf description of this type right now, even if
4277 the type in question is still incomplete, because if this
4278 local type *was* ever completed anywhere within its scope,
4279 that complete definition would already have been attached to
4280 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4281 node by the time we reach this point. That's true because of the
4282 way the front-end does its processing of file-scope declarations (of
4283 functions and class types) within which other types might be
4284 nested. The C and C++ front-ends always gobble up such "local
4285 scope" things en-mass before they try to output *any* debugging
4286 information for any of the stuff contained inside them and thus,
4287 we get the benefit here of what is (in effect) a pre-resolution
4288 of forward references to tagged types in local scopes.
4290 Note however that for file-scope tagged types we cannot assume
4291 that such pre-resolution of forward references has taken place.
4292 A given file-scope tagged type may appear to be incomplete when
4293 we reach this point, but it may yet be given a full definition
4294 (at file-scope) later on during compilation. In order to avoid
4295 generating a premature (and possibly incorrect) set of Dwarf
4296 DIEs for such (as yet incomplete) file-scope tagged types, we
4297 generate nothing at all for as-yet incomplete file-scope tagged
4298 types here unless we are making our special "finalization" pass
4299 for file-scope things at the very end of compilation. At that
4300 time, we will certainly know as much about each file-scope tagged
4301 type as we are ever going to know, so at that point in time, we
4302 can safely generate correct Dwarf descriptions for these file-
4303 scope tagged types. */
4305 if (TYPE_SIZE (type) == 0
4306 && (TYPE_CONTEXT (type) == NULL
4307 || TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
4309 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4311 /* Prevent infinite recursion in cases where the type of some
4312 member of this type is expressed in terms of this type itself. */
4314 TREE_ASM_WRITTEN (type) = 1;
4316 /* Output a DIE to represent the tagged type itself. */
4318 switch (TREE_CODE (type))
4321 output_die (output_enumeration_type_die, type);
4322 return; /* a special case -- nothing left to do so just return */
4325 output_die (output_structure_type_die, type);
4329 case QUAL_UNION_TYPE:
4330 output_die (output_union_type_die, type);
4334 abort (); /* Should never happen. */
4337 /* If this is not an incomplete type, output descriptions of
4338 each of its members.
4340 Note that as we output the DIEs necessary to represent the
4341 members of this record or union type, we will also be trying
4342 to output DIEs to represent the *types* of those members.
4343 However the `output_type' function (above) will specifically
4344 avoid generating type DIEs for member types *within* the list
4345 of member DIEs for this (containing) type execpt for those
4346 types (of members) which are explicitly marked as also being
4347 members of this (containing) type themselves. The g++ front-
4348 end can force any given type to be treated as a member of some
4349 other (containing) type by setting the TYPE_CONTEXT of the
4350 given (member) type to point to the TREE node representing the
4351 appropriate (containing) type.
4354 if (TYPE_SIZE (type))
4356 /* First output info about the base classes. */
4357 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4359 register tree bases = TYPE_BINFO_BASETYPES (type);
4360 register int n_bases = TREE_VEC_LENGTH (bases);
4363 for (i = 0; i < n_bases; i++)
4364 output_die (output_inheritance_die, TREE_VEC_ELT (bases, i));
4370 register tree normal_member;
4372 /* Now output info about the data members and type members. */
4374 for (normal_member = TYPE_FIELDS (type);
4376 normal_member = TREE_CHAIN (normal_member))
4377 output_decl (normal_member, type);
4381 register tree func_member;
4383 /* Now output info about the function members (if any). */
4385 for (func_member = TYPE_METHODS (type);
4387 func_member = TREE_CHAIN (func_member))
4388 output_decl (func_member, type);
4393 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4394 scopes (at least in C++) so we must now output any nested
4395 pending types which are local just to this type. */
4397 output_pending_types_for_scope (type);
4399 end_sibling_chain (); /* Terminate member chain. */
4410 break; /* No DIEs needed for fundamental types. */
4412 case LANG_TYPE: /* No Dwarf representation currently defined. */
4419 TREE_ASM_WRITTEN (type) = 1;
4423 output_tagged_type_instantiation (type)
4426 if (type == 0 || type == error_mark_node)
4429 /* We are going to output a DIE to represent the unqualified version of
4430 of this type (i.e. without any const or volatile qualifiers) so make
4431 sure that we have the main variant (i.e. the unqualified version) of
4434 assert (type == type_main_variant (type));
4436 assert (TREE_ASM_WRITTEN (type));
4438 switch (TREE_CODE (type))
4444 output_die (output_inlined_enumeration_type_die, type);
4448 output_die (output_inlined_structure_type_die, type);
4452 case QUAL_UNION_TYPE:
4453 output_die (output_inlined_union_type_die, type);
4457 abort (); /* Should never happen. */
4461 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4462 the things which are local to the given block. */
4465 output_block (stmt, depth)
4469 register int must_output_die = 0;
4470 register tree origin;
4471 register enum tree_code origin_code;
4473 /* Ignore blocks never really used to make RTL. */
4475 if (! stmt || ! TREE_USED (stmt))
4478 /* Determine the "ultimate origin" of this block. This block may be an
4479 inlined instance of an inlined instance of inline function, so we
4480 have to trace all of the way back through the origin chain to find
4481 out what sort of node actually served as the original seed for the
4482 creation of the current block. */
4484 origin = block_ultimate_origin (stmt);
4485 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4487 /* Determine if we need to output any Dwarf DIEs at all to represent this
4490 if (origin_code == FUNCTION_DECL)
4491 /* The outer scopes for inlinings *must* always be represented. We
4492 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4493 must_output_die = 1;
4496 /* In the case where the current block represents an inlining of the
4497 "body block" of an inline function, we must *NOT* output any DIE
4498 for this block because we have already output a DIE to represent
4499 the whole inlined function scope and the "body block" of any
4500 function doesn't really represent a different scope according to
4501 ANSI C rules. So we check here to make sure that this block does
4502 not represent a "body block inlining" before trying to set the
4503 `must_output_die' flag. */
4505 if (! is_body_block (origin ? origin : stmt))
4507 /* Determine if this block directly contains any "significant"
4508 local declarations which we will need to output DIEs for. */
4510 if (debug_info_level > DINFO_LEVEL_TERSE)
4511 /* We are not in terse mode so *any* local declaration counts
4512 as being a "significant" one. */
4513 must_output_die = (BLOCK_VARS (stmt) != NULL);
4518 /* We are in terse mode, so only local (nested) function
4519 definitions count as "significant" local declarations. */
4521 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4522 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4524 must_output_die = 1;
4531 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4532 DIE for any block which contains no significant local declarations
4533 at all. Rather, in such cases we just call `output_decls_for_scope'
4534 so that any needed Dwarf info for any sub-blocks will get properly
4535 generated. Note that in terse mode, our definition of what constitutes
4536 a "significant" local declaration gets restricted to include only
4537 inlined function instances and local (nested) function definitions. */
4539 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4540 /* We don't care about an abstract inlined subroutine. */;
4541 else if (must_output_die)
4543 output_die ((origin_code == FUNCTION_DECL)
4544 ? output_inlined_subroutine_die
4545 : output_lexical_block_die,
4547 output_decls_for_scope (stmt, depth);
4548 end_sibling_chain ();
4551 output_decls_for_scope (stmt, depth);
4554 /* Output all of the decls declared within a given scope (also called
4555 a `binding contour') and (recursively) all of it's sub-blocks. */
4558 output_decls_for_scope (stmt, depth)
4562 /* Ignore blocks never really used to make RTL. */
4564 if (! stmt || ! TREE_USED (stmt))
4567 if (! BLOCK_ABSTRACT (stmt) && depth > 0)
4568 next_block_number++;
4570 /* Output the DIEs to represent all of the data objects, functions,
4571 typedefs, and tagged types declared directly within this block
4572 but not within any nested sub-blocks. */
4577 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4578 output_decl (decl, stmt);
4581 output_pending_types_for_scope (stmt);
4583 /* Output the DIEs to represent all sub-blocks (and the items declared
4584 therein) of this block. */
4587 register tree subblocks;
4589 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4591 subblocks = BLOCK_CHAIN (subblocks))
4592 output_block (subblocks, depth + 1);
4596 /* Is this a typedef we can avoid emitting? */
4599 is_redundant_typedef (decl)
4602 if (TYPE_DECL_IS_STUB (decl))
4604 if (DECL_ARTIFICIAL (decl)
4605 && DECL_CONTEXT (decl)
4606 && is_tagged_type (DECL_CONTEXT (decl))
4607 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4608 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4609 /* Also ignore the artificial member typedef for the class name. */
4614 /* Output Dwarf .debug information for a decl described by DECL. */
4617 output_decl (decl, containing_scope)
4619 register tree containing_scope;
4621 /* Make a note of the decl node we are going to be working on. We may
4622 need to give the user the source coordinates of where it appeared in
4623 case we notice (later on) that something about it looks screwy. */
4625 dwarf_last_decl = decl;
4627 if (TREE_CODE (decl) == ERROR_MARK)
4630 /* If a structure is declared within an initialization, e.g. as the
4631 operand of a sizeof, then it will not have a name. We don't want
4632 to output a DIE for it, as the tree nodes are in the temporary obstack */
4634 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4635 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4636 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4637 || (TYPE_FIELDS (TREE_TYPE (decl))
4638 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4641 /* If this ..._DECL node is marked to be ignored, then ignore it.
4642 But don't ignore a function definition, since that would screw
4643 up our count of blocks, and that it turn will completely screw up the
4644 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4645 attributes (for subsequent blocks). */
4647 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4650 switch (TREE_CODE (decl))
4653 /* The individual enumerators of an enum type get output when we
4654 output the Dwarf representation of the relevant enum type itself. */
4658 /* If we are in terse mode, don't output any DIEs to represent
4659 mere function declarations. Also, if we are conforming
4660 to the DWARF version 1 specification, don't output DIEs for
4661 mere function declarations. */
4663 if (DECL_INITIAL (decl) == NULL_TREE)
4664 #if (DWARF_VERSION > 1)
4665 if (debug_info_level <= DINFO_LEVEL_TERSE)
4669 /* Before we describe the FUNCTION_DECL itself, make sure that we
4670 have described its return type. */
4672 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4675 /* And its containing type. */
4676 register tree origin = decl_class_context (decl);
4678 output_type (origin, containing_scope);
4681 /* If the following DIE will represent a function definition for a
4682 function with "extern" linkage, output a special "pubnames" DIE
4683 label just ahead of the actual DIE. A reference to this label
4684 was already generated in the .debug_pubnames section sub-entry
4685 for this function definition. */
4687 if (TREE_PUBLIC (decl))
4689 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4691 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4692 ASM_OUTPUT_LABEL (asm_out_file, label);
4695 /* Now output a DIE to represent the function itself. */
4697 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4698 ? output_global_subroutine_die
4699 : output_local_subroutine_die,
4702 /* Now output descriptions of the arguments for this function.
4703 This gets (unnecessarily?) complex because of the fact that
4704 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4705 cases where there was a trailing `...' at the end of the formal
4706 parameter list. In order to find out if there was a trailing
4707 ellipsis or not, we must instead look at the type associated
4708 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4709 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4710 ends with a void_type_node then there should *not* be an ellipsis
4713 /* In the case where we are describing a mere function declaration, all
4714 we need to do here (and all we *can* do here) is to describe
4715 the *types* of its formal parameters. */
4717 if (decl != current_function_decl || in_class)
4718 output_formal_types (TREE_TYPE (decl));
4721 /* Generate DIEs to represent all known formal parameters */
4723 register tree arg_decls = DECL_ARGUMENTS (decl);
4726 /* WARNING! Kludge zone ahead! Here we have a special
4727 hack for svr4 SDB compatibility. Instead of passing the
4728 current FUNCTION_DECL node as the second parameter (i.e.
4729 the `containing_scope' parameter) to `output_decl' (as
4730 we ought to) we instead pass a pointer to our own private
4731 fake_containing_scope node. That node is a RECORD_TYPE
4732 node which NO OTHER TYPE may ever actually be a member of.
4734 This pointer will ultimately get passed into `output_type'
4735 as its `containing_scope' parameter. `Output_type' will
4736 then perform its part in the hack... i.e. it will pend
4737 the type of the formal parameter onto the pending_types
4738 list. Later on, when we are done generating the whole
4739 sequence of formal parameter DIEs for this function
4740 definition, we will un-pend all previously pended types
4741 of formal parameters for this function definition.
4743 This whole kludge prevents any type DIEs from being
4744 mixed in with the formal parameter DIEs. That's good
4745 because svr4 SDB believes that the list of formal
4746 parameter DIEs for a function ends wherever the first
4747 non-formal-parameter DIE appears. Thus, we have to
4748 keep the formal parameter DIEs segregated. They must
4749 all appear (consecutively) at the start of the list of
4750 children for the DIE representing the function definition.
4751 Then (and only then) may we output any additional DIEs
4752 needed to represent the types of these formal parameters.
4756 When generating DIEs, generate the unspecified_parameters
4757 DIE instead if we come across the arg "__builtin_va_alist"
4760 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4761 if (TREE_CODE (parm) == PARM_DECL)
4763 if (DECL_NAME(parm) &&
4764 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4765 "__builtin_va_alist") )
4766 output_die (output_unspecified_parameters_die, decl);
4768 output_decl (parm, fake_containing_scope);
4772 Now that we have finished generating all of the DIEs to
4773 represent the formal parameters themselves, force out
4774 any DIEs needed to represent their types. We do this
4775 simply by un-pending all previously pended types which
4776 can legitimately go into the chain of children DIEs for
4777 the current FUNCTION_DECL.
4780 output_pending_types_for_scope (decl);
4783 Decide whether we need a unspecified_parameters DIE at the end.
4784 There are 2 more cases to do this for:
4785 1) the ansi ... declaration - this is detectable when the end
4786 of the arg list is not a void_type_node
4787 2) an unprototyped function declaration (not a definition). This
4788 just means that we have no info about the parameters at all.
4792 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4796 /* this is the prototyped case, check for ... */
4797 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4798 output_die (output_unspecified_parameters_die, decl);
4802 /* this is unprototyped, check for undefined (just declaration) */
4803 if (!DECL_INITIAL (decl))
4804 output_die (output_unspecified_parameters_die, decl);
4808 /* Output Dwarf info for all of the stuff within the body of the
4809 function (if it has one - it may be just a declaration). */
4812 register tree outer_scope = DECL_INITIAL (decl);
4814 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4816 /* Note that here, `outer_scope' is a pointer to the outermost
4817 BLOCK node created to represent a function.
4818 This outermost BLOCK actually represents the outermost
4819 binding contour for the function, i.e. the contour in which
4820 the function's formal parameters and labels get declared.
4822 Curiously, it appears that the front end doesn't actually
4823 put the PARM_DECL nodes for the current function onto the
4824 BLOCK_VARS list for this outer scope. (They are strung
4825 off of the DECL_ARGUMENTS list for the function instead.)
4826 The BLOCK_VARS list for the `outer_scope' does provide us
4827 with a list of the LABEL_DECL nodes for the function however,
4828 and we output DWARF info for those here.
4830 Just within the `outer_scope' there will be a BLOCK node
4831 representing the function's outermost pair of curly braces,
4832 and any blocks used for the base and member initializers of
4833 a C++ constructor function. */
4835 output_decls_for_scope (outer_scope, 0);
4837 /* Finally, force out any pending types which are local to the
4838 outermost block of this function definition. These will
4839 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4842 output_pending_types_for_scope (decl);
4847 /* Generate a terminator for the list of stuff `owned' by this
4850 end_sibling_chain ();
4855 /* If we are in terse mode, don't generate any DIEs to represent
4856 any actual typedefs. Note that even when we are in terse mode,
4857 we must still output DIEs to represent those tagged types which
4858 are used (directly or indirectly) in the specification of either
4859 a return type or a formal parameter type of some function. */
4861 if (debug_info_level <= DINFO_LEVEL_TERSE)
4862 if (! TYPE_DECL_IS_STUB (decl)
4863 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4866 /* In the special case of a TYPE_DECL node representing
4867 the declaration of some type tag, if the given TYPE_DECL is
4868 marked as having been instantiated from some other (original)
4869 TYPE_DECL node (e.g. one which was generated within the original
4870 definition of an inline function) we have to generate a special
4871 (abbreviated) TAG_structure_type, TAG_union_type, or
4872 TAG_enumeration-type DIE here. */
4874 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4876 output_tagged_type_instantiation (TREE_TYPE (decl));
4880 output_type (TREE_TYPE (decl), containing_scope);
4882 if (! is_redundant_typedef (decl))
4883 /* Output a DIE to represent the typedef itself. */
4884 output_die (output_typedef_die, decl);
4888 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4889 output_die (output_label_die, decl);
4893 /* If we are conforming to the DWARF version 1 specification, don't
4894 generated any DIEs to represent mere external object declarations. */
4896 #if (DWARF_VERSION <= 1)
4897 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4901 /* If we are in terse mode, don't generate any DIEs to represent
4902 any variable declarations or definitions. */
4904 if (debug_info_level <= DINFO_LEVEL_TERSE)
4907 /* Output any DIEs that are needed to specify the type of this data
4910 output_type (TREE_TYPE (decl), containing_scope);
4913 /* And its containing type. */
4914 register tree origin = decl_class_context (decl);
4916 output_type (origin, containing_scope);
4919 /* If the following DIE will represent a data object definition for a
4920 data object with "extern" linkage, output a special "pubnames" DIE
4921 label just ahead of the actual DIE. A reference to this label
4922 was already generated in the .debug_pubnames section sub-entry
4923 for this data object definition. */
4925 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4927 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4929 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4930 ASM_OUTPUT_LABEL (asm_out_file, label);
4933 /* Now output the DIE to represent the data object itself. This gets
4934 complicated because of the possibility that the VAR_DECL really
4935 represents an inlined instance of a formal parameter for an inline
4939 register void (*func) ();
4940 register tree origin = decl_ultimate_origin (decl);
4942 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
4943 func = output_formal_parameter_die;
4946 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
4947 func = output_global_variable_die;
4949 func = output_local_variable_die;
4951 output_die (func, decl);
4956 /* Ignore the nameless fields that are used to skip bits. */
4957 if (DECL_NAME (decl) != 0)
4959 output_type (member_declared_type (decl), containing_scope);
4960 output_die (output_member_die, decl);
4965 /* Force out the type of this formal, if it was not forced out yet.
4966 Note that here we can run afowl of a bug in "classic" svr4 SDB.
4967 It should be able to grok the presence of type DIEs within a list
4968 of TAG_formal_parameter DIEs, but it doesn't. */
4970 output_type (TREE_TYPE (decl), containing_scope);
4971 output_die (output_formal_parameter_die, decl);
4980 dwarfout_file_scope_decl (decl, set_finalizing)
4982 register int set_finalizing;
4984 if (TREE_CODE (decl) == ERROR_MARK)
4987 /* If this ..._DECL node is marked to be ignored, then ignore it. We
4988 gotta hope that the node in question doesn't represent a function
4989 definition. If it does, then totally ignoring it is bound to screw
4990 up our count of blocks, and that it turn will completely screw up the
4991 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4992 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
4993 don't carry their own sequence numbers with them!) */
4995 if (DECL_IGNORED_P (decl))
4997 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5002 switch (TREE_CODE (decl))
5006 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5007 a builtin function. Explicit programmer-supplied declarations of
5008 these same functions should NOT be ignored however. */
5010 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5013 /* What we would really like to do here is to filter out all mere
5014 file-scope declarations of file-scope functions which are never
5015 referenced later within this translation unit (and keep all of
5016 ones that *are* referenced later on) but we aren't clairvoyant,
5017 so we have no idea which functions will be referenced in the
5018 future (i.e. later on within the current translation unit).
5019 So here we just ignore all file-scope function declarations
5020 which are not also definitions. If and when the debugger needs
5021 to know something about these functions, it wil have to hunt
5022 around and find the DWARF information associated with the
5023 *definition* of the function.
5025 Note that we can't just check `DECL_EXTERNAL' to find out which
5026 FUNCTION_DECL nodes represent definitions and which ones represent
5027 mere declarations. We have to check `DECL_INITIAL' instead. That's
5028 because the C front-end supports some weird semantics for "extern
5029 inline" function definitions. These can get inlined within the
5030 current translation unit (an thus, we need to generate DWARF info
5031 for their abstract instances so that the DWARF info for the
5032 concrete inlined instances can have something to refer to) but
5033 the compiler never generates any out-of-lines instances of such
5034 things (despite the fact that they *are* definitions). The
5035 important point is that the C front-end marks these "extern inline"
5036 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5039 Note that the C++ front-end also plays some similar games for inline
5040 function definitions appearing within include files which also
5041 contain `#pragma interface' pragmas. */
5043 if (DECL_INITIAL (decl) == NULL_TREE)
5046 if (TREE_PUBLIC (decl)
5047 && ! DECL_EXTERNAL (decl)
5048 && ! DECL_ABSTRACT (decl))
5050 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5052 /* Output a .debug_pubnames entry for a public function
5053 defined in this compilation unit. */
5055 fputc ('\n', asm_out_file);
5056 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5057 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5058 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5059 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5060 IDENTIFIER_POINTER (DECL_NAME (decl)));
5061 ASM_OUTPUT_POP_SECTION (asm_out_file);
5068 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5069 object declaration and if the declaration was never even
5070 referenced from within this entire compilation unit. We
5071 suppress these DIEs in order to save space in the .debug section
5072 (by eliminating entries which are probably useless). Note that
5073 we must not suppress block-local extern declarations (whether
5074 used or not) because that would screw-up the debugger's name
5075 lookup mechanism and cause it to miss things which really ought
5076 to be in scope at a given point. */
5078 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5081 if (TREE_PUBLIC (decl)
5082 && ! DECL_EXTERNAL (decl)
5083 && GET_CODE (DECL_RTL (decl)) == MEM
5084 && ! DECL_ABSTRACT (decl))
5086 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5088 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5090 /* Output a .debug_pubnames entry for a public variable
5091 defined in this compilation unit. */
5093 fputc ('\n', asm_out_file);
5094 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5095 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5096 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5097 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5098 IDENTIFIER_POINTER (DECL_NAME (decl)));
5099 ASM_OUTPUT_POP_SECTION (asm_out_file);
5102 if (DECL_INITIAL (decl) == NULL)
5104 /* Output a .debug_aranges entry for a public variable
5105 which is tentatively defined in this compilation unit. */
5107 fputc ('\n', asm_out_file);
5108 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5109 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5110 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5111 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5112 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5113 ASM_OUTPUT_POP_SECTION (asm_out_file);
5117 /* If we are in terse mode, don't generate any DIEs to represent
5118 any variable declarations or definitions. */
5120 if (debug_info_level <= DINFO_LEVEL_TERSE)
5126 /* Don't bother trying to generate any DIEs to represent any of the
5127 normal built-in types for the language we are compiling, except
5128 in cases where the types in question are *not* DWARF fundamental
5129 types. We make an exception in the case of non-fundamental types
5130 for the sake of objective C (and perhaps C++) because the GNU
5131 front-ends for these languages may in fact create certain "built-in"
5132 types which are (for example) RECORD_TYPEs. In such cases, we
5133 really need to output these (non-fundamental) types because other
5134 DIEs may contain references to them. */
5136 if (DECL_SOURCE_LINE (decl) == 0
5137 && type_is_fundamental (TREE_TYPE (decl)))
5140 /* If we are in terse mode, don't generate any DIEs to represent
5141 any actual typedefs. Note that even when we are in terse mode,
5142 we must still output DIEs to represent those tagged types which
5143 are used (directly or indirectly) in the specification of either
5144 a return type or a formal parameter type of some function. */
5146 if (debug_info_level <= DINFO_LEVEL_TERSE)
5147 if (! TYPE_DECL_IS_STUB (decl)
5148 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5157 fputc ('\n', asm_out_file);
5158 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5159 finalizing = set_finalizing;
5160 output_decl (decl, NULL_TREE);
5162 /* NOTE: The call above to `output_decl' may have caused one or more
5163 file-scope named types (i.e. tagged types) to be placed onto the
5164 pending_types_list. We have to get those types off of that list
5165 at some point, and this is the perfect time to do it. If we didn't
5166 take them off now, they might still be on the list when cc1 finally
5167 exits. That might be OK if it weren't for the fact that when we put
5168 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5169 for these types, and that causes them never to be output unless
5170 `output_pending_types_for_scope' takes them off of the list and un-sets
5171 their TREE_ASM_WRITTEN flags. */
5173 output_pending_types_for_scope (NULL_TREE);
5175 /* The above call should have totally emptied the pending_types_list. */
5177 assert (pending_types == 0);
5179 ASM_OUTPUT_POP_SECTION (asm_out_file);
5181 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5182 current_funcdef_number++;
5185 /* Output a marker (i.e. a label) for the beginning of the generated code
5186 for a lexical block. */
5189 dwarfout_begin_block (blocknum)
5190 register unsigned blocknum;
5192 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5194 function_section (current_function_decl);
5195 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5196 ASM_OUTPUT_LABEL (asm_out_file, label);
5199 /* Output a marker (i.e. a label) for the end of the generated code
5200 for a lexical block. */
5203 dwarfout_end_block (blocknum)
5204 register unsigned blocknum;
5206 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5208 function_section (current_function_decl);
5209 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5210 ASM_OUTPUT_LABEL (asm_out_file, label);
5213 /* Output a marker (i.e. a label) at a point in the assembly code which
5214 corresponds to a given source level label. */
5217 dwarfout_label (insn)
5220 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5222 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5224 function_section (current_function_decl);
5225 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5226 (unsigned) INSN_UID (insn));
5227 ASM_OUTPUT_LABEL (asm_out_file, label);
5231 /* Output a marker (i.e. a label) for the point in the generated code where
5232 the real body of the function begins (after parameters have been moved
5233 to their home locations). */
5236 dwarfout_begin_function ()
5238 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5240 if (! use_gnu_debug_info_extensions)
5242 function_section (current_function_decl);
5243 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5244 ASM_OUTPUT_LABEL (asm_out_file, label);
5247 /* Output a marker (i.e. a label) for the point in the generated code where
5248 the real body of the function ends (just before the epilogue code). */
5251 dwarfout_end_function ()
5253 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5255 if (! use_gnu_debug_info_extensions)
5257 function_section (current_function_decl);
5258 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5259 ASM_OUTPUT_LABEL (asm_out_file, label);
5262 /* Output a marker (i.e. a label) for the absolute end of the generated code
5263 for a function definition. This gets called *after* the epilogue code
5264 has been generated. */
5267 dwarfout_end_epilogue ()
5269 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5271 /* Output a label to mark the endpoint of the code generated for this
5274 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5275 ASM_OUTPUT_LABEL (asm_out_file, label);
5279 shuffle_filename_entry (new_zeroth)
5280 register filename_entry *new_zeroth;
5282 filename_entry temp_entry;
5283 register filename_entry *limit_p;
5284 register filename_entry *move_p;
5286 if (new_zeroth == &filename_table[0])
5289 temp_entry = *new_zeroth;
5291 /* Shift entries up in the table to make room at [0]. */
5293 limit_p = &filename_table[0];
5294 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5295 *move_p = *(move_p-1);
5297 /* Install the found entry at [0]. */
5299 filename_table[0] = temp_entry;
5302 /* Create a new (string) entry for the .debug_sfnames section. */
5305 generate_new_sfname_entry ()
5307 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5309 fputc ('\n', asm_out_file);
5310 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5311 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5312 ASM_OUTPUT_LABEL (asm_out_file, label);
5313 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5314 filename_table[0].name
5315 ? filename_table[0].name
5317 ASM_OUTPUT_POP_SECTION (asm_out_file);
5320 /* Lookup a filename (in the list of filenames that we know about here in
5321 dwarfout.c) and return its "index". The index of each (known) filename
5322 is just a unique number which is associated with only that one filename.
5323 We need such numbers for the sake of generating labels (in the
5324 .debug_sfnames section) and references to those unique labels (in the
5325 .debug_srcinfo and .debug_macinfo sections).
5327 If the filename given as an argument is not found in our current list,
5328 add it to the list and assign it the next available unique index number.
5330 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5331 one), we shuffle the filename found (or added) up to the zeroth entry of
5332 our list of filenames (which is always searched linearly). We do this so
5333 as to optimize the most common case for these filename lookups within
5334 dwarfout.c. The most common case by far is the case where we call
5335 lookup_filename to lookup the very same filename that we did a lookup
5336 on the last time we called lookup_filename. We make sure that this
5337 common case is fast because such cases will constitute 99.9% of the
5338 lookups we ever do (in practice).
5340 If we add a new filename entry to our table, we go ahead and generate
5341 the corresponding entry in the .debug_sfnames section right away.
5342 Doing so allows us to avoid tickling an assembler bug (present in some
5343 m68k assemblers) which yields assembly-time errors in cases where the
5344 difference of two label addresses is taken and where the two labels
5345 are in a section *other* than the one where the difference is being
5346 calculated, and where at least one of the two symbol references is a
5347 forward reference. (This bug could be tickled by our .debug_srcinfo
5348 entries if we don't output their corresponding .debug_sfnames entries
5352 lookup_filename (file_name)
5355 register filename_entry *search_p;
5356 register filename_entry *limit_p = &filename_table[ft_entries];
5358 for (search_p = filename_table; search_p < limit_p; search_p++)
5359 if (!strcmp (file_name, search_p->name))
5361 /* When we get here, we have found the filename that we were
5362 looking for in the filename_table. Now we want to make sure
5363 that it gets moved to the zero'th entry in the table (if it
5364 is not already there) so that subsequent attempts to find the
5365 same filename will find it as quickly as possible. */
5367 shuffle_filename_entry (search_p);
5368 return filename_table[0].number;
5371 /* We come here whenever we have a new filename which is not registered
5372 in the current table. Here we add it to the table. */
5374 /* Prepare to add a new table entry by making sure there is enough space
5375 in the table to do so. If not, expand the current table. */
5377 if (ft_entries == ft_entries_allocated)
5379 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5381 = (filename_entry *)
5382 xrealloc (filename_table,
5383 ft_entries_allocated * sizeof (filename_entry));
5386 /* Initially, add the new entry at the end of the filename table. */
5388 filename_table[ft_entries].number = ft_entries;
5389 filename_table[ft_entries].name = xstrdup (file_name);
5391 /* Shuffle the new entry into filename_table[0]. */
5393 shuffle_filename_entry (&filename_table[ft_entries]);
5395 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5396 generate_new_sfname_entry ();
5399 return filename_table[0].number;
5403 generate_srcinfo_entry (line_entry_num, files_entry_num)
5404 unsigned line_entry_num;
5405 unsigned files_entry_num;
5407 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5409 fputc ('\n', asm_out_file);
5410 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5411 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5412 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5413 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5414 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5415 ASM_OUTPUT_POP_SECTION (asm_out_file);
5419 dwarfout_line (filename, line)
5420 register char *filename;
5421 register unsigned line;
5423 if (debug_info_level >= DINFO_LEVEL_NORMAL
5424 /* We can't emit line number info for functions in separate sections,
5425 because the assembler can't subtract labels in different sections. */
5426 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5428 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5429 static unsigned last_line_entry_num = 0;
5430 static unsigned prev_file_entry_num = (unsigned) -1;
5431 register unsigned this_file_entry_num;
5433 function_section (current_function_decl);
5434 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5435 ASM_OUTPUT_LABEL (asm_out_file, label);
5437 fputc ('\n', asm_out_file);
5439 if (use_gnu_debug_info_extensions)
5440 this_file_entry_num = lookup_filename (filename);
5442 this_file_entry_num = (unsigned) -1;
5444 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5445 if (this_file_entry_num != prev_file_entry_num)
5447 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5449 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5450 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5454 register char *tail = rindex (filename, '/');
5460 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5461 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5463 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5464 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5465 ASM_OUTPUT_POP_SECTION (asm_out_file);
5467 if (this_file_entry_num != prev_file_entry_num)
5468 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5469 prev_file_entry_num = this_file_entry_num;
5473 /* Generate an entry in the .debug_macinfo section. */
5476 generate_macinfo_entry (type_and_offset, string)
5477 register char *type_and_offset;
5478 register char *string;
5480 if (! use_gnu_debug_info_extensions)
5483 fputc ('\n', asm_out_file);
5484 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5485 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5486 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
5487 ASM_OUTPUT_POP_SECTION (asm_out_file);
5491 dwarfout_start_new_source_file (filename)
5492 register char *filename;
5494 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5495 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5497 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5498 sprintf (type_and_offset, "0x%08x+%s-%s",
5499 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
5500 generate_macinfo_entry (type_and_offset, "");
5504 dwarfout_resume_previous_source_file (lineno)
5505 register unsigned lineno;
5507 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5509 sprintf (type_and_offset, "0x%08x+%u",
5510 ((unsigned) MACINFO_resume << 24), lineno);
5511 generate_macinfo_entry (type_and_offset, "");
5514 /* Called from check_newline in c-parse.y. The `buffer' parameter
5515 contains the tail part of the directive line, i.e. the part which
5516 is past the initial whitespace, #, whitespace, directive-name,
5520 dwarfout_define (lineno, buffer)
5521 register unsigned lineno;
5522 register char *buffer;
5524 static int initialized = 0;
5525 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5529 dwarfout_start_new_source_file (primary_filename);
5532 sprintf (type_and_offset, "0x%08x+%u",
5533 ((unsigned) MACINFO_define << 24), lineno);
5534 generate_macinfo_entry (type_and_offset, buffer);
5537 /* Called from check_newline in c-parse.y. The `buffer' parameter
5538 contains the tail part of the directive line, i.e. the part which
5539 is past the initial whitespace, #, whitespace, directive-name,
5543 dwarfout_undef (lineno, buffer)
5544 register unsigned lineno;
5545 register char *buffer;
5547 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5549 sprintf (type_and_offset, "0x%08x+%u",
5550 ((unsigned) MACINFO_undef << 24), lineno);
5551 generate_macinfo_entry (type_and_offset, buffer);
5554 /* Set up for Dwarf output at the start of compilation. */
5557 dwarfout_init (asm_out_file, main_input_filename)
5558 register FILE *asm_out_file;
5559 register char *main_input_filename;
5561 /* Remember the name of the primary input file. */
5563 primary_filename = main_input_filename;
5565 /* Allocate the initial hunk of the pending_sibling_stack. */
5567 pending_sibling_stack
5569 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5570 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5571 pending_siblings = 1;
5573 /* Allocate the initial hunk of the filename_table. */
5576 = (filename_entry *)
5577 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5578 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5581 /* Allocate the initial hunk of the pending_types_list. */
5584 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5585 pending_types_allocated = PENDING_TYPES_INCREMENT;
5588 /* Create an artificial RECORD_TYPE node which we can use in our hack
5589 to get the DIEs representing types of formal parameters to come out
5590 only *after* the DIEs for the formal parameters themselves. */
5592 fake_containing_scope = make_node (RECORD_TYPE);
5594 /* Output a starting label for the .text section. */
5596 fputc ('\n', asm_out_file);
5597 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5598 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5599 ASM_OUTPUT_POP_SECTION (asm_out_file);
5601 /* Output a starting label for the .data section. */
5603 fputc ('\n', asm_out_file);
5604 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5605 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5606 ASM_OUTPUT_POP_SECTION (asm_out_file);
5608 #if 0 /* GNU C doesn't currently use .data1. */
5609 /* Output a starting label for the .data1 section. */
5611 fputc ('\n', asm_out_file);
5612 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5613 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5614 ASM_OUTPUT_POP_SECTION (asm_out_file);
5617 /* Output a starting label for the .rodata section. */
5619 fputc ('\n', asm_out_file);
5620 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5621 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5622 ASM_OUTPUT_POP_SECTION (asm_out_file);
5624 #if 0 /* GNU C doesn't currently use .rodata1. */
5625 /* Output a starting label for the .rodata1 section. */
5627 fputc ('\n', asm_out_file);
5628 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5629 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5630 ASM_OUTPUT_POP_SECTION (asm_out_file);
5633 /* Output a starting label for the .bss section. */
5635 fputc ('\n', asm_out_file);
5636 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5637 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5638 ASM_OUTPUT_POP_SECTION (asm_out_file);
5640 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5642 if (use_gnu_debug_info_extensions)
5644 /* Output a starting label and an initial (compilation directory)
5645 entry for the .debug_sfnames section. The starting label will be
5646 referenced by the initial entry in the .debug_srcinfo section. */
5648 fputc ('\n', asm_out_file);
5649 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5650 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5653 register unsigned len;
5654 register char *dirname;
5658 pfatal_with_name ("getpwd");
5660 dirname = (char *) xmalloc (len + 2);
5662 strcpy (dirname, pwd);
5663 strcpy (dirname + len, "/");
5664 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5667 ASM_OUTPUT_POP_SECTION (asm_out_file);
5670 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5671 && use_gnu_debug_info_extensions)
5673 /* Output a starting label for the .debug_macinfo section. This
5674 label will be referenced by the AT_mac_info attribute in the
5675 TAG_compile_unit DIE. */
5677 fputc ('\n', asm_out_file);
5678 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5679 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5680 ASM_OUTPUT_POP_SECTION (asm_out_file);
5683 /* Generate the initial entry for the .line section. */
5685 fputc ('\n', asm_out_file);
5686 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5687 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5688 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5689 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5690 ASM_OUTPUT_POP_SECTION (asm_out_file);
5692 if (use_gnu_debug_info_extensions)
5694 /* Generate the initial entry for the .debug_srcinfo section. */
5696 fputc ('\n', asm_out_file);
5697 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5698 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5699 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5700 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5701 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5702 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5703 #ifdef DWARF_TIMESTAMPS
5704 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5706 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5708 ASM_OUTPUT_POP_SECTION (asm_out_file);
5711 /* Generate the initial entry for the .debug_pubnames section. */
5713 fputc ('\n', asm_out_file);
5714 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5715 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5716 ASM_OUTPUT_POP_SECTION (asm_out_file);
5718 /* Generate the initial entry for the .debug_aranges section. */
5720 fputc ('\n', asm_out_file);
5721 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5722 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5723 ASM_OUTPUT_POP_SECTION (asm_out_file);
5726 /* Setup first DIE number == 1. */
5727 NEXT_DIE_NUM = next_unused_dienum++;
5729 /* Generate the initial DIE for the .debug section. Note that the
5730 (string) value given in the AT_name attribute of the TAG_compile_unit
5731 DIE will (typically) be a relative pathname and that this pathname
5732 should be taken as being relative to the directory from which the
5733 compiler was invoked when the given (base) source file was compiled. */
5735 fputc ('\n', asm_out_file);
5736 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5737 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5738 output_die (output_compile_unit_die, main_input_filename);
5739 ASM_OUTPUT_POP_SECTION (asm_out_file);
5741 fputc ('\n', asm_out_file);
5744 /* Output stuff that dwarf requires at the end of every file. */
5749 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5751 fputc ('\n', asm_out_file);
5752 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5754 /* Mark the end of the chain of siblings which represent all file-scope
5755 declarations in this compilation unit. */
5757 /* The (null) DIE which represents the terminator for the (sibling linked)
5758 list of file-scope items is *special*. Normally, we would just call
5759 end_sibling_chain at this point in order to output a word with the
5760 value `4' and that word would act as the terminator for the list of
5761 DIEs describing file-scope items. Unfortunately, if we were to simply
5762 do that, the label that would follow this DIE in the .debug section
5763 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5764 machines) to a 4 byte boundary.
5766 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5767 the trick used is to insert extra (otherwise useless) padding bytes
5768 into the (null) DIE that we know must precede the ..D2 label in the
5769 .debug section. The amount of padding required can be anywhere between
5770 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5771 with the padding) would normally contain the value 4, but now it will
5772 also have to include the padding bytes, so it will instead have some
5773 value in the range 4..7.
5775 Fortunately, the rules of Dwarf say that any DIE whose length word
5776 contains *any* value less than 8 should be treated as a null DIE, so
5777 this trick works out nicely. Clever, eh? Don't give me any credit
5778 (or blame). I didn't think of this scheme. I just conformed to it.
5781 output_die (output_padded_null_die, (void *) 0);
5784 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5785 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5786 ASM_OUTPUT_POP_SECTION (asm_out_file);
5788 /* Output a terminator label for the .text section. */
5790 fputc ('\n', asm_out_file);
5791 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5792 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5793 ASM_OUTPUT_POP_SECTION (asm_out_file);
5795 /* Output a terminator label for the .data section. */
5797 fputc ('\n', asm_out_file);
5798 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5799 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5800 ASM_OUTPUT_POP_SECTION (asm_out_file);
5802 #if 0 /* GNU C doesn't currently use .data1. */
5803 /* Output a terminator label for the .data1 section. */
5805 fputc ('\n', asm_out_file);
5806 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5807 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5808 ASM_OUTPUT_POP_SECTION (asm_out_file);
5811 /* Output a terminator label for the .rodata section. */
5813 fputc ('\n', asm_out_file);
5814 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5815 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5816 ASM_OUTPUT_POP_SECTION (asm_out_file);
5818 #if 0 /* GNU C doesn't currently use .rodata1. */
5819 /* Output a terminator label for the .rodata1 section. */
5821 fputc ('\n', asm_out_file);
5822 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5823 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5824 ASM_OUTPUT_POP_SECTION (asm_out_file);
5827 /* Output a terminator label for the .bss section. */
5829 fputc ('\n', asm_out_file);
5830 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5831 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5832 ASM_OUTPUT_POP_SECTION (asm_out_file);
5834 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5836 /* Output a terminating entry for the .line section. */
5838 fputc ('\n', asm_out_file);
5839 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5840 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5841 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5842 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5843 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5844 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5845 ASM_OUTPUT_POP_SECTION (asm_out_file);
5847 if (use_gnu_debug_info_extensions)
5849 /* Output a terminating entry for the .debug_srcinfo section. */
5851 fputc ('\n', asm_out_file);
5852 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5853 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5854 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5855 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5856 ASM_OUTPUT_POP_SECTION (asm_out_file);
5859 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5861 /* Output terminating entries for the .debug_macinfo section. */
5863 dwarfout_resume_previous_source_file (0);
5865 fputc ('\n', asm_out_file);
5866 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5867 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5868 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5869 ASM_OUTPUT_POP_SECTION (asm_out_file);
5872 /* Generate the terminating entry for the .debug_pubnames section. */
5874 fputc ('\n', asm_out_file);
5875 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5876 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5877 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5878 ASM_OUTPUT_POP_SECTION (asm_out_file);
5880 /* Generate the terminating entries for the .debug_aranges section.
5882 Note that we want to do this only *after* we have output the end
5883 labels (for the various program sections) which we are going to
5884 refer to here. This allows us to work around a bug in the m68k
5885 svr4 assembler. That assembler gives bogus assembly-time errors
5886 if (within any given section) you try to take the difference of
5887 two relocatable symbols, both of which are located within some
5888 other section, and if one (or both?) of the symbols involved is
5889 being forward-referenced. By generating the .debug_aranges
5890 entries at this late point in the assembly output, we skirt the
5891 issue simply by avoiding forward-references.
5894 fputc ('\n', asm_out_file);
5895 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5897 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5898 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5900 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5901 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5903 #if 0 /* GNU C doesn't currently use .data1. */
5904 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5905 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5909 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5910 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5911 RODATA_BEGIN_LABEL);
5913 #if 0 /* GNU C doesn't currently use .rodata1. */
5914 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5915 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5916 RODATA1_BEGIN_LABEL);
5919 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5920 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5922 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5923 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5925 ASM_OUTPUT_POP_SECTION (asm_out_file);
5929 #endif /* DWARF_DEBUGGING_INFO */