* arm.c (arm_split_constant): Don't try to force a constant to
[official-gcc.git] / gcc / dwarfout.c
blob691348aa3eaecad2c976cd00c64c360facc4d0a6
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 95-98, 1999 Free Software Foundation, Inc.
3 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
24 #ifdef DWARF_DEBUGGING_INFO
25 #include "system.h"
26 #include "dwarf.h"
27 #include "tree.h"
28 #include "flags.h"
29 #include "rtl.h"
30 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "reload.h"
33 #include "output.h"
34 #include "defaults.h"
35 #include "dwarfout.h"
36 #include "toplev.h"
38 #if defined(DWARF_TIMESTAMPS)
39 #if !defined(POSIX)
40 extern time_t time PROTO ((time_t *)); /* FIXME: use NEED_DECLARATION_TIME */
41 #endif /* !defined(POSIX) */
42 #endif /* defined(DWARF_TIMESTAMPS) */
44 /* We cannot use <assert.h> in GCC source, since that would include
45 GCC's assert.h, which may not be compatible with the host compiler. */
46 #undef assert
47 #ifdef NDEBUG
48 # define assert(e)
49 #else
50 # define assert(e) do { if (! (e)) abort (); } while (0)
51 #endif
53 extern char *getpwd PROTO((void));
55 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
56 regarding the GNU implementation of Dwarf. */
58 /* NOTE: In the comments in this file, many references are made to
59 so called "Debugging Information Entries". For the sake of brevity,
60 this term is abbreviated to `DIE' throughout the remainder of this
61 file. */
63 /* Note that the implementation of C++ support herein is (as yet) unfinished.
64 If you want to try to complete it, more power to you. */
66 /* How to start an assembler comment. */
67 #ifndef ASM_COMMENT_START
68 #define ASM_COMMENT_START ";#"
69 #endif
71 /* How to print out a register name. */
72 #ifndef PRINT_REG
73 #define PRINT_REG(RTX, CODE, FILE) \
74 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
75 #endif
77 /* Define a macro which returns non-zero for any tagged type which is
78 used (directly or indirectly) in the specification of either some
79 function's return type or some formal parameter of some function.
80 We use this macro when we are operating in "terse" mode to help us
81 know what tagged types have to be represented in Dwarf (even in
82 terse mode) and which ones don't.
84 A flag bit with this meaning really should be a part of the normal
85 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
86 for these nodes. For now, we have to just fake it. It it safe for
87 us to simply return zero for all complete tagged types (which will
88 get forced out anyway if they were used in the specification of some
89 formal or return type) and non-zero for all incomplete tagged types.
92 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
94 /* Define a macro which returns non-zero for a TYPE_DECL which was
95 implicitly generated for a tagged type.
97 Note that unlike the gcc front end (which generates a NULL named
98 TYPE_DECL node for each complete tagged type, each array type, and
99 each function type node created) the g++ front end generates a
100 _named_ TYPE_DECL node for each tagged type node created.
101 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
102 generate a DW_TAG_typedef DIE for them. */
103 #define TYPE_DECL_IS_STUB(decl) \
104 (DECL_NAME (decl) == NULL \
105 || (DECL_ARTIFICIAL (decl) \
106 && is_tagged_type (TREE_TYPE (decl)) \
107 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
109 extern int flag_traditional;
110 extern char *version_string;
111 extern char *language_string;
113 /* Maximum size (in bytes) of an artificially generated label. */
115 #define MAX_ARTIFICIAL_LABEL_BYTES 30
117 /* Make sure we know the sizes of the various types dwarf can describe.
118 These are only defaults. If the sizes are different for your target,
119 you should override these values by defining the appropriate symbols
120 in your tm.h file. */
122 #ifndef CHAR_TYPE_SIZE
123 #define CHAR_TYPE_SIZE BITS_PER_UNIT
124 #endif
126 #ifndef SHORT_TYPE_SIZE
127 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
128 #endif
130 #ifndef INT_TYPE_SIZE
131 #define INT_TYPE_SIZE BITS_PER_WORD
132 #endif
134 #ifndef LONG_TYPE_SIZE
135 #define LONG_TYPE_SIZE BITS_PER_WORD
136 #endif
138 #ifndef LONG_LONG_TYPE_SIZE
139 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
140 #endif
142 #ifndef WCHAR_TYPE_SIZE
143 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
144 #endif
146 #ifndef WCHAR_UNSIGNED
147 #define WCHAR_UNSIGNED 0
148 #endif
150 #ifndef FLOAT_TYPE_SIZE
151 #define FLOAT_TYPE_SIZE BITS_PER_WORD
152 #endif
154 #ifndef DOUBLE_TYPE_SIZE
155 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
156 #endif
158 #ifndef LONG_DOUBLE_TYPE_SIZE
159 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
160 #endif
162 /* Structure to keep track of source filenames. */
164 struct filename_entry {
165 unsigned number;
166 char * name;
169 typedef struct filename_entry filename_entry;
171 /* Pointer to an array of elements, each one having the structure above. */
173 static filename_entry *filename_table;
175 /* Total number of entries in the table (i.e. array) pointed to by
176 `filename_table'. This is the *total* and includes both used and
177 unused slots. */
179 static unsigned ft_entries_allocated;
181 /* Number of entries in the filename_table which are actually in use. */
183 static unsigned ft_entries;
185 /* Size (in elements) of increments by which we may expand the filename
186 table. Actually, a single hunk of space of this size should be enough
187 for most typical programs. */
189 #define FT_ENTRIES_INCREMENT 64
191 /* Local pointer to the name of the main input file. Initialized in
192 dwarfout_init. */
194 static char *primary_filename;
196 /* Pointer to the most recent filename for which we produced some line info. */
198 static char *last_filename;
200 /* For Dwarf output, we must assign lexical-blocks id numbers
201 in the order in which their beginnings are encountered.
202 We output Dwarf debugging info that refers to the beginnings
203 and ends of the ranges of code for each lexical block with
204 assembler labels ..Bn and ..Bn.e, where n is the block number.
205 The labels themselves are generated in final.c, which assigns
206 numbers to the blocks in the same way. */
208 static unsigned next_block_number = 2;
210 /* Counter to generate unique names for DIEs. */
212 static unsigned next_unused_dienum = 1;
214 /* Number of the DIE which is currently being generated. */
216 static unsigned current_dienum;
218 /* Number to use for the special "pubname" label on the next DIE which
219 represents a function or data object defined in this compilation
220 unit which has "extern" linkage. */
222 static int next_pubname_number = 0;
224 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
226 /* Pointer to a dynamically allocated list of pre-reserved and still
227 pending sibling DIE numbers. Note that this list will grow as needed. */
229 static unsigned *pending_sibling_stack;
231 /* Counter to keep track of the number of pre-reserved and still pending
232 sibling DIE numbers. */
234 static unsigned pending_siblings;
236 /* The currently allocated size of the above list (expressed in number of
237 list elements). */
239 static unsigned pending_siblings_allocated;
241 /* Size (in elements) of increments by which we may expand the pending
242 sibling stack. Actually, a single hunk of space of this size should
243 be enough for most typical programs. */
245 #define PENDING_SIBLINGS_INCREMENT 64
247 /* Non-zero if we are performing our file-scope finalization pass and if
248 we should force out Dwarf descriptions of any and all file-scope
249 tagged types which are still incomplete types. */
251 static int finalizing = 0;
253 /* A pointer to the base of a list of pending types which we haven't
254 generated DIEs for yet, but which we will have to come back to
255 later on. */
257 static tree *pending_types_list;
259 /* Number of elements currently allocated for the pending_types_list. */
261 static unsigned pending_types_allocated;
263 /* Number of elements of pending_types_list currently in use. */
265 static unsigned pending_types;
267 /* Size (in elements) of increments by which we may expand the pending
268 types list. Actually, a single hunk of space of this size should
269 be enough for most typical programs. */
271 #define PENDING_TYPES_INCREMENT 64
273 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
274 This is used in a hack to help us get the DIEs describing types of
275 formal parameters to come *after* all of the DIEs describing the formal
276 parameters themselves. That's necessary in order to be compatible
277 with what the brain-damaged svr4 SDB debugger requires. */
279 static tree fake_containing_scope;
281 /* The number of the current function definition that we are generating
282 debugging information for. These numbers range from 1 up to the maximum
283 number of function definitions contained within the current compilation
284 unit. These numbers are used to create unique labels for various things
285 contained within various function definitions. */
287 static unsigned current_funcdef_number = 1;
289 /* A pointer to the ..._DECL node which we have most recently been working
290 on. We keep this around just in case something about it looks screwy
291 and we want to tell the user what the source coordinates for the actual
292 declaration are. */
294 static tree dwarf_last_decl;
296 /* A flag indicating that we are emitting the member declarations of a
297 class, so member functions and variables should not be entirely emitted.
298 This is a kludge to avoid passing a second argument to output_*_die. */
300 static int in_class;
302 /* Forward declarations for functions defined in this file. */
304 static char *dwarf_tag_name PROTO((unsigned));
305 static char *dwarf_attr_name PROTO((unsigned));
306 static char *dwarf_stack_op_name PROTO((unsigned));
307 static char *dwarf_typemod_name PROTO((unsigned));
308 static char *dwarf_fmt_byte_name PROTO((unsigned));
309 static char *dwarf_fund_type_name PROTO((unsigned));
310 static tree decl_ultimate_origin PROTO((tree));
311 static tree block_ultimate_origin PROTO((tree));
312 static tree decl_class_context PROTO((tree));
313 #if 0
314 static void output_unsigned_leb128 PROTO((unsigned long));
315 static void output_signed_leb128 PROTO((long));
316 #endif
317 static inline int is_body_block PROTO((tree));
318 static int fundamental_type_code PROTO((tree));
319 static tree root_type_1 PROTO((tree, int));
320 static tree root_type PROTO((tree));
321 static void write_modifier_bytes_1 PROTO((tree, int, int, int));
322 static void write_modifier_bytes PROTO((tree, int, int));
323 static inline int type_is_fundamental PROTO((tree));
324 static void equate_decl_number_to_die_number PROTO((tree));
325 static inline void equate_type_number_to_die_number PROTO((tree));
326 static void output_reg_number PROTO((rtx));
327 static void output_mem_loc_descriptor PROTO((rtx));
328 static void output_loc_descriptor PROTO((rtx));
329 static void output_bound_representation PROTO((tree, unsigned, int));
330 static void output_enumeral_list PROTO((tree));
331 static inline unsigned ceiling PROTO((unsigned, unsigned));
332 static inline tree field_type PROTO((tree));
333 static inline unsigned simple_type_align_in_bits PROTO((tree));
334 static inline unsigned simple_type_size_in_bits PROTO((tree));
335 static unsigned field_byte_offset PROTO((tree));
336 static inline void sibling_attribute PROTO((void));
337 static void location_attribute PROTO((rtx));
338 static void data_member_location_attribute PROTO((tree));
339 static void const_value_attribute PROTO((rtx));
340 static void location_or_const_value_attribute PROTO((tree));
341 static inline void name_attribute PROTO((char *));
342 static inline void fund_type_attribute PROTO((unsigned));
343 static void mod_fund_type_attribute PROTO((tree, int, int));
344 static inline void user_def_type_attribute PROTO((tree));
345 static void mod_u_d_type_attribute PROTO((tree, int, int));
346 #ifdef USE_ORDERING_ATTRIBUTE
347 static inline void ordering_attribute PROTO((unsigned));
348 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
349 static void subscript_data_attribute PROTO((tree));
350 static void byte_size_attribute PROTO((tree));
351 static inline void bit_offset_attribute PROTO((tree));
352 static inline void bit_size_attribute PROTO((tree));
353 static inline void element_list_attribute PROTO((tree));
354 static inline void stmt_list_attribute PROTO((char *));
355 static inline void low_pc_attribute PROTO((char *));
356 static inline void high_pc_attribute PROTO((char *));
357 static inline void body_begin_attribute PROTO((char *));
358 static inline void body_end_attribute PROTO((char *));
359 static inline void language_attribute PROTO((unsigned));
360 static inline void member_attribute PROTO((tree));
361 #if 0
362 static inline void string_length_attribute PROTO((tree));
363 #endif
364 static inline void comp_dir_attribute PROTO((char *));
365 static inline void sf_names_attribute PROTO((char *));
366 static inline void src_info_attribute PROTO((char *));
367 static inline void mac_info_attribute PROTO((char *));
368 static inline void prototyped_attribute PROTO((tree));
369 static inline void producer_attribute PROTO((char *));
370 static inline void inline_attribute PROTO((tree));
371 static inline void containing_type_attribute PROTO((tree));
372 static inline void abstract_origin_attribute PROTO((tree));
373 #ifdef DWARF_DECL_COORDINATES
374 static inline void src_coords_attribute PROTO((unsigned, unsigned));
375 #endif /* defined(DWARF_DECL_COORDINATES) */
376 static inline void pure_or_virtual_attribute PROTO((tree));
377 static void name_and_src_coords_attributes PROTO((tree));
378 static void type_attribute PROTO((tree, int, int));
379 static char *type_tag PROTO((tree));
380 static inline void dienum_push PROTO((void));
381 static inline void dienum_pop PROTO((void));
382 static inline tree member_declared_type PROTO((tree));
383 static char *function_start_label PROTO((tree));
384 static void output_array_type_die PROTO((void *));
385 static void output_set_type_die PROTO((void *));
386 #if 0
387 static void output_entry_point_die PROTO((void *));
388 #endif
389 static void output_inlined_enumeration_type_die PROTO((void *));
390 static void output_inlined_structure_type_die PROTO((void *));
391 static void output_inlined_union_type_die PROTO((void *));
392 static void output_enumeration_type_die PROTO((void *));
393 static void output_formal_parameter_die PROTO((void *));
394 static void output_global_subroutine_die PROTO((void *));
395 static void output_global_variable_die PROTO((void *));
396 static void output_label_die PROTO((void *));
397 static void output_lexical_block_die PROTO((void *));
398 static void output_inlined_subroutine_die PROTO((void *));
399 static void output_local_variable_die PROTO((void *));
400 static void output_member_die PROTO((void *));
401 #if 0
402 static void output_pointer_type_die PROTO((void *));
403 static void output_reference_type_die PROTO((void *));
404 #endif
405 static void output_ptr_to_mbr_type_die PROTO((void *));
406 static void output_compile_unit_die PROTO((void *));
407 static void output_string_type_die PROTO((void *));
408 static void output_inheritance_die PROTO((void *));
409 static void output_structure_type_die PROTO((void *));
410 static void output_local_subroutine_die PROTO((void *));
411 static void output_subroutine_type_die PROTO((void *));
412 static void output_typedef_die PROTO((void *));
413 static void output_union_type_die PROTO((void *));
414 static void output_unspecified_parameters_die PROTO((void *));
415 static void output_padded_null_die PROTO((void *));
416 static void output_die PROTO((void (*) PROTO((void *)), void *));
417 static void end_sibling_chain PROTO((void));
418 static void output_formal_types PROTO((tree));
419 static void pend_type PROTO((tree));
420 static int type_ok_for_scope PROTO((tree, tree));
421 static void output_pending_types_for_scope PROTO((tree));
422 static void output_type PROTO((tree, tree));
423 static void output_tagged_type_instantiation PROTO((tree));
424 static void output_block PROTO((tree, int));
425 static void output_decls_for_scope PROTO((tree, int));
426 static void output_decl PROTO((tree, tree));
427 static void shuffle_filename_entry PROTO((filename_entry *));
428 static void generate_new_sfname_entry PROTO((void));
429 static unsigned lookup_filename PROTO((char *));
430 static void generate_srcinfo_entry PROTO((unsigned, unsigned));
431 static void generate_macinfo_entry PROTO((char *, char *));
432 static int is_pseudo_reg PROTO((rtx));
433 static tree type_main_variant PROTO((tree));
434 static int is_tagged_type PROTO((tree));
435 static int is_redundant_typedef PROTO((tree));
437 /* Definitions of defaults for assembler-dependent names of various
438 pseudo-ops and section names.
440 Theses may be overridden in your tm.h file (if necessary) for your
441 particular assembler. The default values provided here correspond to
442 what is expected by "standard" AT&T System V.4 assemblers. */
444 #ifndef FILE_ASM_OP
445 #define FILE_ASM_OP ".file"
446 #endif
447 #ifndef VERSION_ASM_OP
448 #define VERSION_ASM_OP ".version"
449 #endif
450 #ifndef UNALIGNED_SHORT_ASM_OP
451 #define UNALIGNED_SHORT_ASM_OP ".2byte"
452 #endif
453 #ifndef UNALIGNED_INT_ASM_OP
454 #define UNALIGNED_INT_ASM_OP ".4byte"
455 #endif
456 #ifndef ASM_BYTE_OP
457 #define ASM_BYTE_OP ".byte"
458 #endif
459 #ifndef SET_ASM_OP
460 #define SET_ASM_OP ".set"
461 #endif
463 /* Pseudo-ops for pushing the current section onto the section stack (and
464 simultaneously changing to a new section) and for poping back to the
465 section we were in immediately before this one. Note that most svr4
466 assemblers only maintain a one level stack... you can push all the
467 sections you want, but you can only pop out one level. (The sparc
468 svr4 assembler is an exception to this general rule.) That's
469 OK because we only use at most one level of the section stack herein. */
471 #ifndef PUSHSECTION_ASM_OP
472 #define PUSHSECTION_ASM_OP ".section"
473 #endif
474 #ifndef POPSECTION_ASM_OP
475 #define POPSECTION_ASM_OP ".previous"
476 #endif
478 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
479 to print the PUSHSECTION_ASM_OP and the section name. The default here
480 works for almost all svr4 assemblers, except for the sparc, where the
481 section name must be enclosed in double quotes. (See sparcv4.h.) */
483 #ifndef PUSHSECTION_FORMAT
484 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
485 #endif
487 #ifndef DEBUG_SECTION
488 #define DEBUG_SECTION ".debug"
489 #endif
490 #ifndef LINE_SECTION
491 #define LINE_SECTION ".line"
492 #endif
493 #ifndef SFNAMES_SECTION
494 #define SFNAMES_SECTION ".debug_sfnames"
495 #endif
496 #ifndef SRCINFO_SECTION
497 #define SRCINFO_SECTION ".debug_srcinfo"
498 #endif
499 #ifndef MACINFO_SECTION
500 #define MACINFO_SECTION ".debug_macinfo"
501 #endif
502 #ifndef PUBNAMES_SECTION
503 #define PUBNAMES_SECTION ".debug_pubnames"
504 #endif
505 #ifndef ARANGES_SECTION
506 #define ARANGES_SECTION ".debug_aranges"
507 #endif
508 #ifndef TEXT_SECTION
509 #define TEXT_SECTION ".text"
510 #endif
511 #ifndef DATA_SECTION
512 #define DATA_SECTION ".data"
513 #endif
514 #ifndef DATA1_SECTION
515 #define DATA1_SECTION ".data1"
516 #endif
517 #ifndef RODATA_SECTION
518 #define RODATA_SECTION ".rodata"
519 #endif
520 #ifndef RODATA1_SECTION
521 #define RODATA1_SECTION ".rodata1"
522 #endif
523 #ifndef BSS_SECTION
524 #define BSS_SECTION ".bss"
525 #endif
527 /* Definitions of defaults for formats and names of various special
528 (artificial) labels which may be generated within this file (when
529 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
531 If necessary, these may be overridden from within your tm.h file,
532 but typically, you should never need to override these.
534 These labels have been hacked (temporarily) so that they all begin with
535 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
536 stock m88k/svr4 assembler, both of which need to see .L at the start of
537 a label in order to prevent that label from going into the linker symbol
538 table). When I get time, I'll have to fix this the right way so that we
539 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
540 but that will require a rather massive set of changes. For the moment,
541 the following definitions out to produce the right results for all svr4
542 and svr3 assemblers. -- rfg
545 #ifndef TEXT_BEGIN_LABEL
546 #define TEXT_BEGIN_LABEL "*.L_text_b"
547 #endif
548 #ifndef TEXT_END_LABEL
549 #define TEXT_END_LABEL "*.L_text_e"
550 #endif
552 #ifndef DATA_BEGIN_LABEL
553 #define DATA_BEGIN_LABEL "*.L_data_b"
554 #endif
555 #ifndef DATA_END_LABEL
556 #define DATA_END_LABEL "*.L_data_e"
557 #endif
559 #ifndef DATA1_BEGIN_LABEL
560 #define DATA1_BEGIN_LABEL "*.L_data1_b"
561 #endif
562 #ifndef DATA1_END_LABEL
563 #define DATA1_END_LABEL "*.L_data1_e"
564 #endif
566 #ifndef RODATA_BEGIN_LABEL
567 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
568 #endif
569 #ifndef RODATA_END_LABEL
570 #define RODATA_END_LABEL "*.L_rodata_e"
571 #endif
573 #ifndef RODATA1_BEGIN_LABEL
574 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
575 #endif
576 #ifndef RODATA1_END_LABEL
577 #define RODATA1_END_LABEL "*.L_rodata1_e"
578 #endif
580 #ifndef BSS_BEGIN_LABEL
581 #define BSS_BEGIN_LABEL "*.L_bss_b"
582 #endif
583 #ifndef BSS_END_LABEL
584 #define BSS_END_LABEL "*.L_bss_e"
585 #endif
587 #ifndef LINE_BEGIN_LABEL
588 #define LINE_BEGIN_LABEL "*.L_line_b"
589 #endif
590 #ifndef LINE_LAST_ENTRY_LABEL
591 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
592 #endif
593 #ifndef LINE_END_LABEL
594 #define LINE_END_LABEL "*.L_line_e"
595 #endif
597 #ifndef DEBUG_BEGIN_LABEL
598 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
599 #endif
600 #ifndef SFNAMES_BEGIN_LABEL
601 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
602 #endif
603 #ifndef SRCINFO_BEGIN_LABEL
604 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
605 #endif
606 #ifndef MACINFO_BEGIN_LABEL
607 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
608 #endif
610 #ifndef DIE_BEGIN_LABEL_FMT
611 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
612 #endif
613 #ifndef DIE_END_LABEL_FMT
614 #define DIE_END_LABEL_FMT "*.L_D%u_e"
615 #endif
616 #ifndef PUB_DIE_LABEL_FMT
617 #define PUB_DIE_LABEL_FMT "*.L_P%u"
618 #endif
619 #ifndef INSN_LABEL_FMT
620 #define INSN_LABEL_FMT "*.L_I%u_%u"
621 #endif
622 #ifndef BLOCK_BEGIN_LABEL_FMT
623 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
624 #endif
625 #ifndef BLOCK_END_LABEL_FMT
626 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
627 #endif
628 #ifndef SS_BEGIN_LABEL_FMT
629 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
630 #endif
631 #ifndef SS_END_LABEL_FMT
632 #define SS_END_LABEL_FMT "*.L_s%u_e"
633 #endif
634 #ifndef EE_BEGIN_LABEL_FMT
635 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
636 #endif
637 #ifndef EE_END_LABEL_FMT
638 #define EE_END_LABEL_FMT "*.L_e%u_e"
639 #endif
640 #ifndef MT_BEGIN_LABEL_FMT
641 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
642 #endif
643 #ifndef MT_END_LABEL_FMT
644 #define MT_END_LABEL_FMT "*.L_t%u_e"
645 #endif
646 #ifndef LOC_BEGIN_LABEL_FMT
647 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
648 #endif
649 #ifndef LOC_END_LABEL_FMT
650 #define LOC_END_LABEL_FMT "*.L_l%u_e"
651 #endif
652 #ifndef BOUND_BEGIN_LABEL_FMT
653 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
654 #endif
655 #ifndef BOUND_END_LABEL_FMT
656 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
657 #endif
658 #ifndef DERIV_BEGIN_LABEL_FMT
659 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
660 #endif
661 #ifndef DERIV_END_LABEL_FMT
662 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
663 #endif
664 #ifndef SL_BEGIN_LABEL_FMT
665 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
666 #endif
667 #ifndef SL_END_LABEL_FMT
668 #define SL_END_LABEL_FMT "*.L_sl%u_e"
669 #endif
670 #ifndef BODY_BEGIN_LABEL_FMT
671 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
672 #endif
673 #ifndef BODY_END_LABEL_FMT
674 #define BODY_END_LABEL_FMT "*.L_b%u_e"
675 #endif
676 #ifndef FUNC_END_LABEL_FMT
677 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
678 #endif
679 #ifndef TYPE_NAME_FMT
680 #define TYPE_NAME_FMT "*.L_T%u"
681 #endif
682 #ifndef DECL_NAME_FMT
683 #define DECL_NAME_FMT "*.L_E%u"
684 #endif
685 #ifndef LINE_CODE_LABEL_FMT
686 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
687 #endif
688 #ifndef SFNAMES_ENTRY_LABEL_FMT
689 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
690 #endif
691 #ifndef LINE_ENTRY_LABEL_FMT
692 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
693 #endif
695 /* Definitions of defaults for various types of primitive assembly language
696 output operations.
698 If necessary, these may be overridden from within your tm.h file,
699 but typically, you shouldn't need to override these. */
701 #ifndef ASM_OUTPUT_PUSH_SECTION
702 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
703 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
704 #endif
706 #ifndef ASM_OUTPUT_POP_SECTION
707 #define ASM_OUTPUT_POP_SECTION(FILE) \
708 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
709 #endif
711 #ifndef ASM_OUTPUT_DWARF_DELTA2
712 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
713 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
714 assemble_name (FILE, LABEL1); \
715 fprintf (FILE, "-"); \
716 assemble_name (FILE, LABEL2); \
717 fprintf (FILE, "\n"); \
718 } while (0)
719 #endif
721 #ifndef ASM_OUTPUT_DWARF_DELTA4
722 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
723 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
724 assemble_name (FILE, LABEL1); \
725 fprintf (FILE, "-"); \
726 assemble_name (FILE, LABEL2); \
727 fprintf (FILE, "\n"); \
728 } while (0)
729 #endif
731 #ifndef ASM_OUTPUT_DWARF_TAG
732 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
733 do { \
734 fprintf ((FILE), "\t%s\t0x%x", \
735 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
736 if (flag_debug_asm) \
737 fprintf ((FILE), "\t%s %s", \
738 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
739 fputc ('\n', (FILE)); \
740 } while (0)
741 #endif
743 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
744 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
745 do { \
746 fprintf ((FILE), "\t%s\t0x%x", \
747 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
748 if (flag_debug_asm) \
749 fprintf ((FILE), "\t%s %s", \
750 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
751 fputc ('\n', (FILE)); \
752 } while (0)
753 #endif
755 #ifndef ASM_OUTPUT_DWARF_STACK_OP
756 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
757 do { \
758 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
759 if (flag_debug_asm) \
760 fprintf ((FILE), "\t%s %s", \
761 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
762 fputc ('\n', (FILE)); \
763 } while (0)
764 #endif
766 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
767 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
768 do { \
769 fprintf ((FILE), "\t%s\t0x%x", \
770 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
771 if (flag_debug_asm) \
772 fprintf ((FILE), "\t%s %s", \
773 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
774 fputc ('\n', (FILE)); \
775 } while (0)
776 #endif
778 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
779 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
780 do { \
781 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
782 if (flag_debug_asm) \
783 fprintf ((FILE), "\t%s %s", \
784 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
785 fputc ('\n', (FILE)); \
786 } while (0)
787 #endif
789 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
790 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
791 do { \
792 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
793 if (flag_debug_asm) \
794 fprintf ((FILE), "\t%s %s", \
795 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
796 fputc ('\n', (FILE)); \
797 } while (0)
798 #endif
800 #ifndef ASM_OUTPUT_DWARF_ADDR
801 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
802 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
803 assemble_name (FILE, LABEL); \
804 fprintf (FILE, "\n"); \
805 } while (0)
806 #endif
808 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
809 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
810 do { \
811 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
812 output_addr_const ((FILE), (RTX)); \
813 fputc ('\n', (FILE)); \
814 } while (0)
815 #endif
817 #ifndef ASM_OUTPUT_DWARF_REF
818 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
819 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
820 assemble_name (FILE, LABEL); \
821 fprintf (FILE, "\n"); \
822 } while (0)
823 #endif
825 #ifndef ASM_OUTPUT_DWARF_DATA1
826 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
827 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
828 #endif
830 #ifndef ASM_OUTPUT_DWARF_DATA2
831 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
832 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
833 #endif
835 #ifndef ASM_OUTPUT_DWARF_DATA4
836 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
837 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
838 #endif
840 #ifndef ASM_OUTPUT_DWARF_DATA8
841 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
842 do { \
843 if (WORDS_BIG_ENDIAN) \
845 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
846 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
848 else \
850 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
851 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
853 } while (0)
854 #endif
856 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
857 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
858 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
859 defined, we call it, then issue the line feed. If not, we supply a
860 default defintion of calling ASM_OUTPUT_ASCII */
862 #ifndef ASM_OUTPUT_DWARF_STRING
863 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
864 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
865 #else
866 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
867 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
868 #endif
871 /************************ general utility functions **************************/
873 inline static int
874 is_pseudo_reg (rtl)
875 register rtx rtl;
877 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
878 || ((GET_CODE (rtl) == SUBREG)
879 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
882 inline static tree
883 type_main_variant (type)
884 register tree type;
886 type = TYPE_MAIN_VARIANT (type);
888 /* There really should be only one main variant among any group of variants
889 of a given type (and all of the MAIN_VARIANT values for all members of
890 the group should point to that one type) but sometimes the C front-end
891 messes this up for array types, so we work around that bug here. */
893 if (TREE_CODE (type) == ARRAY_TYPE)
895 while (type != TYPE_MAIN_VARIANT (type))
896 type = TYPE_MAIN_VARIANT (type);
899 return type;
902 /* Return non-zero if the given type node represents a tagged type. */
904 inline static int
905 is_tagged_type (type)
906 register tree type;
908 register enum tree_code code = TREE_CODE (type);
910 return (code == RECORD_TYPE || code == UNION_TYPE
911 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
914 static char *
915 dwarf_tag_name (tag)
916 register unsigned tag;
918 switch (tag)
920 case TAG_padding: return "TAG_padding";
921 case TAG_array_type: return "TAG_array_type";
922 case TAG_class_type: return "TAG_class_type";
923 case TAG_entry_point: return "TAG_entry_point";
924 case TAG_enumeration_type: return "TAG_enumeration_type";
925 case TAG_formal_parameter: return "TAG_formal_parameter";
926 case TAG_global_subroutine: return "TAG_global_subroutine";
927 case TAG_global_variable: return "TAG_global_variable";
928 case TAG_label: return "TAG_label";
929 case TAG_lexical_block: return "TAG_lexical_block";
930 case TAG_local_variable: return "TAG_local_variable";
931 case TAG_member: return "TAG_member";
932 case TAG_pointer_type: return "TAG_pointer_type";
933 case TAG_reference_type: return "TAG_reference_type";
934 case TAG_compile_unit: return "TAG_compile_unit";
935 case TAG_string_type: return "TAG_string_type";
936 case TAG_structure_type: return "TAG_structure_type";
937 case TAG_subroutine: return "TAG_subroutine";
938 case TAG_subroutine_type: return "TAG_subroutine_type";
939 case TAG_typedef: return "TAG_typedef";
940 case TAG_union_type: return "TAG_union_type";
941 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
942 case TAG_variant: return "TAG_variant";
943 case TAG_common_block: return "TAG_common_block";
944 case TAG_common_inclusion: return "TAG_common_inclusion";
945 case TAG_inheritance: return "TAG_inheritance";
946 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
947 case TAG_module: return "TAG_module";
948 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
949 case TAG_set_type: return "TAG_set_type";
950 case TAG_subrange_type: return "TAG_subrange_type";
951 case TAG_with_stmt: return "TAG_with_stmt";
953 /* GNU extensions. */
955 case TAG_format_label: return "TAG_format_label";
956 case TAG_namelist: return "TAG_namelist";
957 case TAG_function_template: return "TAG_function_template";
958 case TAG_class_template: return "TAG_class_template";
960 default: return "TAG_<unknown>";
964 static char *
965 dwarf_attr_name (attr)
966 register unsigned attr;
968 switch (attr)
970 case AT_sibling: return "AT_sibling";
971 case AT_location: return "AT_location";
972 case AT_name: return "AT_name";
973 case AT_fund_type: return "AT_fund_type";
974 case AT_mod_fund_type: return "AT_mod_fund_type";
975 case AT_user_def_type: return "AT_user_def_type";
976 case AT_mod_u_d_type: return "AT_mod_u_d_type";
977 case AT_ordering: return "AT_ordering";
978 case AT_subscr_data: return "AT_subscr_data";
979 case AT_byte_size: return "AT_byte_size";
980 case AT_bit_offset: return "AT_bit_offset";
981 case AT_bit_size: return "AT_bit_size";
982 case AT_element_list: return "AT_element_list";
983 case AT_stmt_list: return "AT_stmt_list";
984 case AT_low_pc: return "AT_low_pc";
985 case AT_high_pc: return "AT_high_pc";
986 case AT_language: return "AT_language";
987 case AT_member: return "AT_member";
988 case AT_discr: return "AT_discr";
989 case AT_discr_value: return "AT_discr_value";
990 case AT_string_length: return "AT_string_length";
991 case AT_common_reference: return "AT_common_reference";
992 case AT_comp_dir: return "AT_comp_dir";
993 case AT_const_value_string: return "AT_const_value_string";
994 case AT_const_value_data2: return "AT_const_value_data2";
995 case AT_const_value_data4: return "AT_const_value_data4";
996 case AT_const_value_data8: return "AT_const_value_data8";
997 case AT_const_value_block2: return "AT_const_value_block2";
998 case AT_const_value_block4: return "AT_const_value_block4";
999 case AT_containing_type: return "AT_containing_type";
1000 case AT_default_value_addr: return "AT_default_value_addr";
1001 case AT_default_value_data2: return "AT_default_value_data2";
1002 case AT_default_value_data4: return "AT_default_value_data4";
1003 case AT_default_value_data8: return "AT_default_value_data8";
1004 case AT_default_value_string: return "AT_default_value_string";
1005 case AT_friends: return "AT_friends";
1006 case AT_inline: return "AT_inline";
1007 case AT_is_optional: return "AT_is_optional";
1008 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1009 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1010 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1011 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1012 case AT_private: return "AT_private";
1013 case AT_producer: return "AT_producer";
1014 case AT_program: return "AT_program";
1015 case AT_protected: return "AT_protected";
1016 case AT_prototyped: return "AT_prototyped";
1017 case AT_public: return "AT_public";
1018 case AT_pure_virtual: return "AT_pure_virtual";
1019 case AT_return_addr: return "AT_return_addr";
1020 case AT_abstract_origin: return "AT_abstract_origin";
1021 case AT_start_scope: return "AT_start_scope";
1022 case AT_stride_size: return "AT_stride_size";
1023 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1024 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1025 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1026 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1027 case AT_virtual: return "AT_virtual";
1029 /* GNU extensions */
1031 case AT_sf_names: return "AT_sf_names";
1032 case AT_src_info: return "AT_src_info";
1033 case AT_mac_info: return "AT_mac_info";
1034 case AT_src_coords: return "AT_src_coords";
1035 case AT_body_begin: return "AT_body_begin";
1036 case AT_body_end: return "AT_body_end";
1038 default: return "AT_<unknown>";
1042 static char *
1043 dwarf_stack_op_name (op)
1044 register unsigned op;
1046 switch (op)
1048 case OP_REG: return "OP_REG";
1049 case OP_BASEREG: return "OP_BASEREG";
1050 case OP_ADDR: return "OP_ADDR";
1051 case OP_CONST: return "OP_CONST";
1052 case OP_DEREF2: return "OP_DEREF2";
1053 case OP_DEREF4: return "OP_DEREF4";
1054 case OP_ADD: return "OP_ADD";
1055 default: return "OP_<unknown>";
1059 static char *
1060 dwarf_typemod_name (mod)
1061 register unsigned mod;
1063 switch (mod)
1065 case MOD_pointer_to: return "MOD_pointer_to";
1066 case MOD_reference_to: return "MOD_reference_to";
1067 case MOD_const: return "MOD_const";
1068 case MOD_volatile: return "MOD_volatile";
1069 default: return "MOD_<unknown>";
1073 static char *
1074 dwarf_fmt_byte_name (fmt)
1075 register unsigned fmt;
1077 switch (fmt)
1079 case FMT_FT_C_C: return "FMT_FT_C_C";
1080 case FMT_FT_C_X: return "FMT_FT_C_X";
1081 case FMT_FT_X_C: return "FMT_FT_X_C";
1082 case FMT_FT_X_X: return "FMT_FT_X_X";
1083 case FMT_UT_C_C: return "FMT_UT_C_C";
1084 case FMT_UT_C_X: return "FMT_UT_C_X";
1085 case FMT_UT_X_C: return "FMT_UT_X_C";
1086 case FMT_UT_X_X: return "FMT_UT_X_X";
1087 case FMT_ET: return "FMT_ET";
1088 default: return "FMT_<unknown>";
1092 static char *
1093 dwarf_fund_type_name (ft)
1094 register unsigned ft;
1096 switch (ft)
1098 case FT_char: return "FT_char";
1099 case FT_signed_char: return "FT_signed_char";
1100 case FT_unsigned_char: return "FT_unsigned_char";
1101 case FT_short: return "FT_short";
1102 case FT_signed_short: return "FT_signed_short";
1103 case FT_unsigned_short: return "FT_unsigned_short";
1104 case FT_integer: return "FT_integer";
1105 case FT_signed_integer: return "FT_signed_integer";
1106 case FT_unsigned_integer: return "FT_unsigned_integer";
1107 case FT_long: return "FT_long";
1108 case FT_signed_long: return "FT_signed_long";
1109 case FT_unsigned_long: return "FT_unsigned_long";
1110 case FT_pointer: return "FT_pointer";
1111 case FT_float: return "FT_float";
1112 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1113 case FT_ext_prec_float: return "FT_ext_prec_float";
1114 case FT_complex: return "FT_complex";
1115 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1116 case FT_void: return "FT_void";
1117 case FT_boolean: return "FT_boolean";
1118 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1119 case FT_label: return "FT_label";
1121 /* GNU extensions. */
1123 case FT_long_long: return "FT_long_long";
1124 case FT_signed_long_long: return "FT_signed_long_long";
1125 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1127 case FT_int8: return "FT_int8";
1128 case FT_signed_int8: return "FT_signed_int8";
1129 case FT_unsigned_int8: return "FT_unsigned_int8";
1130 case FT_int16: return "FT_int16";
1131 case FT_signed_int16: return "FT_signed_int16";
1132 case FT_unsigned_int16: return "FT_unsigned_int16";
1133 case FT_int32: return "FT_int32";
1134 case FT_signed_int32: return "FT_signed_int32";
1135 case FT_unsigned_int32: return "FT_unsigned_int32";
1136 case FT_int64: return "FT_int64";
1137 case FT_signed_int64: return "FT_signed_int64";
1138 case FT_unsigned_int64: return "FT_unsigned_int64";
1140 case FT_real32: return "FT_real32";
1141 case FT_real64: return "FT_real64";
1142 case FT_real96: return "FT_real96";
1143 case FT_real128: return "FT_real128";
1145 default: return "FT_<unknown>";
1149 /* Determine the "ultimate origin" of a decl. The decl may be an
1150 inlined instance of an inlined instance of a decl which is local
1151 to an inline function, so we have to trace all of the way back
1152 through the origin chain to find out what sort of node actually
1153 served as the original seed for the given block. */
1155 static tree
1156 decl_ultimate_origin (decl)
1157 register tree decl;
1159 #ifdef ENABLE_CHECKING
1160 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1161 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1162 most distant ancestor, this should never happen. */
1163 abort ();
1164 #endif
1166 return DECL_ABSTRACT_ORIGIN (decl);
1169 /* Determine the "ultimate origin" of a block. The block may be an
1170 inlined instance of an inlined instance of a block which is local
1171 to an inline function, so we have to trace all of the way back
1172 through the origin chain to find out what sort of node actually
1173 served as the original seed for the given block. */
1175 static tree
1176 block_ultimate_origin (block)
1177 register tree block;
1179 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1181 if (immediate_origin == NULL)
1182 return NULL;
1183 else
1185 register tree ret_val;
1186 register tree lookahead = immediate_origin;
1190 ret_val = lookahead;
1191 lookahead = (TREE_CODE (ret_val) == BLOCK)
1192 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1193 : NULL;
1195 while (lookahead != NULL && lookahead != ret_val);
1196 return ret_val;
1200 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1201 of a virtual function may refer to a base class, so we check the 'this'
1202 parameter. */
1204 static tree
1205 decl_class_context (decl)
1206 tree decl;
1208 tree context = NULL_TREE;
1209 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1210 context = DECL_CONTEXT (decl);
1211 else
1212 context = TYPE_MAIN_VARIANT
1213 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1215 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1216 context = NULL_TREE;
1218 return context;
1221 #if 0
1222 static void
1223 output_unsigned_leb128 (value)
1224 register unsigned long value;
1226 register unsigned long orig_value = value;
1230 register unsigned byte = (value & 0x7f);
1232 value >>= 7;
1233 if (value != 0) /* more bytes to follow */
1234 byte |= 0x80;
1235 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1236 if (flag_debug_asm && value == 0)
1237 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1238 ASM_COMMENT_START, orig_value);
1239 fputc ('\n', asm_out_file);
1241 while (value != 0);
1244 static void
1245 output_signed_leb128 (value)
1246 register long value;
1248 register long orig_value = value;
1249 register int negative = (value < 0);
1250 register int more;
1254 register unsigned byte = (value & 0x7f);
1256 value >>= 7;
1257 if (negative)
1258 value |= 0xfe000000; /* manually sign extend */
1259 if (((value == 0) && ((byte & 0x40) == 0))
1260 || ((value == -1) && ((byte & 0x40) == 1)))
1261 more = 0;
1262 else
1264 byte |= 0x80;
1265 more = 1;
1267 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1268 if (flag_debug_asm && more == 0)
1269 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1270 ASM_COMMENT_START, orig_value);
1271 fputc ('\n', asm_out_file);
1273 while (more);
1275 #endif
1277 /**************** utility functions for attribute functions ******************/
1279 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1280 node in question represents the outermost pair of curly braces (i.e.
1281 the "body block") of a function or method.
1283 For any BLOCK node representing a "body block" of a function or method,
1284 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1285 which represents the outermost (function) scope for the function or
1286 method (i.e. the one which includes the formal parameters). The
1287 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1288 FUNCTION_DECL node.
1291 static inline int
1292 is_body_block (stmt)
1293 register tree stmt;
1295 if (TREE_CODE (stmt) == BLOCK)
1297 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1299 if (TREE_CODE (parent) == BLOCK)
1301 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1303 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1304 return 1;
1307 return 0;
1310 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1311 type code for the given type.
1313 This routine must only be called for GCC type nodes that correspond to
1314 Dwarf fundamental types.
1316 The current Dwarf draft specification calls for Dwarf fundamental types
1317 to accurately reflect the fact that a given type was either a "plain"
1318 integral type or an explicitly "signed" integral type. Unfortunately,
1319 we can't always do this, because GCC may already have thrown away the
1320 information about the precise way in which the type was originally
1321 specified, as in:
1323 typedef signed int my_type;
1325 struct s { my_type f; };
1327 Since we may be stuck here without enought information to do exactly
1328 what is called for in the Dwarf draft specification, we do the best
1329 that we can under the circumstances and always use the "plain" integral
1330 fundamental type codes for int, short, and long types. That's probably
1331 good enough. The additional accuracy called for in the current DWARF
1332 draft specification is probably never even useful in practice. */
1334 static int
1335 fundamental_type_code (type)
1336 register tree type;
1338 if (TREE_CODE (type) == ERROR_MARK)
1339 return 0;
1341 switch (TREE_CODE (type))
1343 case ERROR_MARK:
1344 return FT_void;
1346 case VOID_TYPE:
1347 return FT_void;
1349 case INTEGER_TYPE:
1350 /* Carefully distinguish all the standard types of C,
1351 without messing up if the language is not C.
1352 Note that we check only for the names that contain spaces;
1353 other names might occur by coincidence in other languages. */
1354 if (TYPE_NAME (type) != 0
1355 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1356 && DECL_NAME (TYPE_NAME (type)) != 0
1357 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1359 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1361 if (!strcmp (name, "unsigned char"))
1362 return FT_unsigned_char;
1363 if (!strcmp (name, "signed char"))
1364 return FT_signed_char;
1365 if (!strcmp (name, "unsigned int"))
1366 return FT_unsigned_integer;
1367 if (!strcmp (name, "short int"))
1368 return FT_short;
1369 if (!strcmp (name, "short unsigned int"))
1370 return FT_unsigned_short;
1371 if (!strcmp (name, "long int"))
1372 return FT_long;
1373 if (!strcmp (name, "long unsigned int"))
1374 return FT_unsigned_long;
1375 if (!strcmp (name, "long long int"))
1376 return FT_long_long; /* Not grok'ed by svr4 SDB */
1377 if (!strcmp (name, "long long unsigned int"))
1378 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1381 /* Most integer types will be sorted out above, however, for the
1382 sake of special `array index' integer types, the following code
1383 is also provided. */
1385 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1386 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1388 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1389 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1391 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1392 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1394 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1395 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1397 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1398 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1400 abort ();
1402 case REAL_TYPE:
1403 /* Carefully distinguish all the standard types of C,
1404 without messing up if the language is not C. */
1405 if (TYPE_NAME (type) != 0
1406 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1407 && DECL_NAME (TYPE_NAME (type)) != 0
1408 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1410 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1412 /* Note that here we can run afowl of a serious bug in "classic"
1413 svr4 SDB debuggers. They don't seem to understand the
1414 FT_ext_prec_float type (even though they should). */
1416 if (!strcmp (name, "long double"))
1417 return FT_ext_prec_float;
1420 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1422 /* On the SH, when compiling with -m3e or -m4-single-only, both
1423 float and double are 32 bits. But since the debugger doesn't
1424 know about the subtarget, it always thinks double is 64 bits.
1425 So we have to tell the debugger that the type is float to
1426 make the output of the 'print' command etc. readable. */
1427 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1428 return FT_float;
1429 return FT_dbl_prec_float;
1431 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1432 return FT_float;
1434 /* Note that here we can run afowl of a serious bug in "classic"
1435 svr4 SDB debuggers. They don't seem to understand the
1436 FT_ext_prec_float type (even though they should). */
1438 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1439 return FT_ext_prec_float;
1440 abort ();
1442 case COMPLEX_TYPE:
1443 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1445 case CHAR_TYPE:
1446 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1448 case BOOLEAN_TYPE:
1449 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1451 default:
1452 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1454 return 0;
1457 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1458 the Dwarf "root" type for the given input type. The Dwarf "root" type
1459 of a given type is generally the same as the given type, except that if
1460 the given type is a pointer or reference type, then the root type of
1461 the given type is the root type of the "basis" type for the pointer or
1462 reference type. (This definition of the "root" type is recursive.)
1463 Also, the root type of a `const' qualified type or a `volatile'
1464 qualified type is the root type of the given type without the
1465 qualifiers. */
1467 static tree
1468 root_type_1 (type, count)
1469 register tree type;
1470 register int count;
1472 /* Give up after searching 1000 levels, in case this is a recursive
1473 pointer type. Such types are possible in Ada, but it is not possible
1474 to represent them in DWARF1 debug info. */
1475 if (count > 1000)
1476 return error_mark_node;
1478 switch (TREE_CODE (type))
1480 case ERROR_MARK:
1481 return error_mark_node;
1483 case POINTER_TYPE:
1484 case REFERENCE_TYPE:
1485 return root_type_1 (TREE_TYPE (type), count+1);
1487 default:
1488 return type;
1492 static tree
1493 root_type (type)
1494 register tree type;
1496 type = root_type_1 (type, 0);
1497 if (type != error_mark_node)
1498 type = type_main_variant (type);
1499 return type;
1502 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1503 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1505 static void
1506 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1507 register tree type;
1508 register int decl_const;
1509 register int decl_volatile;
1510 register int count;
1512 if (TREE_CODE (type) == ERROR_MARK)
1513 return;
1515 /* Give up after searching 1000 levels, in case this is a recursive
1516 pointer type. Such types are possible in Ada, but it is not possible
1517 to represent them in DWARF1 debug info. */
1518 if (count > 1000)
1519 return;
1521 if (TYPE_READONLY (type) || decl_const)
1522 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1523 if (TYPE_VOLATILE (type) || decl_volatile)
1524 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1525 switch (TREE_CODE (type))
1527 case POINTER_TYPE:
1528 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1529 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1530 return;
1532 case REFERENCE_TYPE:
1533 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1534 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1535 return;
1537 case ERROR_MARK:
1538 default:
1539 return;
1543 static void
1544 write_modifier_bytes (type, decl_const, decl_volatile)
1545 register tree type;
1546 register int decl_const;
1547 register int decl_volatile;
1549 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1552 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1553 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1555 static inline int
1556 type_is_fundamental (type)
1557 register tree type;
1559 switch (TREE_CODE (type))
1561 case ERROR_MARK:
1562 case VOID_TYPE:
1563 case INTEGER_TYPE:
1564 case REAL_TYPE:
1565 case COMPLEX_TYPE:
1566 case BOOLEAN_TYPE:
1567 case CHAR_TYPE:
1568 return 1;
1570 case SET_TYPE:
1571 case ARRAY_TYPE:
1572 case RECORD_TYPE:
1573 case UNION_TYPE:
1574 case QUAL_UNION_TYPE:
1575 case ENUMERAL_TYPE:
1576 case FUNCTION_TYPE:
1577 case METHOD_TYPE:
1578 case POINTER_TYPE:
1579 case REFERENCE_TYPE:
1580 case FILE_TYPE:
1581 case OFFSET_TYPE:
1582 case LANG_TYPE:
1583 return 0;
1585 default:
1586 abort ();
1588 return 0;
1591 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1592 equate directive which will associate a symbolic name with the current DIE.
1594 The name used is an artificial label generated from the DECL_UID number
1595 associated with the given decl node. The name it gets equated to is the
1596 symbolic label that we (previously) output at the start of the DIE that
1597 we are currently generating.
1599 Calling this function while generating some "decl related" form of DIE
1600 makes it possible to later refer to the DIE which represents the given
1601 decl simply by re-generating the symbolic name from the ..._DECL node's
1602 UID number. */
1604 static void
1605 equate_decl_number_to_die_number (decl)
1606 register tree decl;
1608 /* In the case where we are generating a DIE for some ..._DECL node
1609 which represents either some inline function declaration or some
1610 entity declared within an inline function declaration/definition,
1611 setup a symbolic name for the current DIE so that we have a name
1612 for this DIE that we can easily refer to later on within
1613 AT_abstract_origin attributes. */
1615 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1616 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1618 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1619 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1620 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1623 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1624 equate directive which will associate a symbolic name with the current DIE.
1626 The name used is an artificial label generated from the TYPE_UID number
1627 associated with the given type node. The name it gets equated to is the
1628 symbolic label that we (previously) output at the start of the DIE that
1629 we are currently generating.
1631 Calling this function while generating some "type related" form of DIE
1632 makes it easy to later refer to the DIE which represents the given type
1633 simply by re-generating the alternative name from the ..._TYPE node's
1634 UID number. */
1636 static inline void
1637 equate_type_number_to_die_number (type)
1638 register tree type;
1640 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1641 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1643 /* We are generating a DIE to represent the main variant of this type
1644 (i.e the type without any const or volatile qualifiers) so in order
1645 to get the equate to come out right, we need to get the main variant
1646 itself here. */
1648 type = type_main_variant (type);
1650 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1651 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1652 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1655 static void
1656 output_reg_number (rtl)
1657 register rtx rtl;
1659 register unsigned regno = REGNO (rtl);
1661 if (regno >= FIRST_PSEUDO_REGISTER)
1663 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1664 regno);
1665 regno = 0;
1667 fprintf (asm_out_file, "\t%s\t0x%x",
1668 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1669 if (flag_debug_asm)
1671 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1672 PRINT_REG (rtl, 0, asm_out_file);
1674 fputc ('\n', asm_out_file);
1677 /* The following routine is a nice and simple transducer. It converts the
1678 RTL for a variable or parameter (resident in memory) into an equivalent
1679 Dwarf representation of a mechanism for getting the address of that same
1680 variable onto the top of a hypothetical "address evaluation" stack.
1682 When creating memory location descriptors, we are effectively trans-
1683 forming the RTL for a memory-resident object into its Dwarf postfix
1684 expression equivalent. This routine just recursively descends an
1685 RTL tree, turning it into Dwarf postfix code as it goes. */
1687 static void
1688 output_mem_loc_descriptor (rtl)
1689 register rtx rtl;
1691 /* Note that for a dynamically sized array, the location we will
1692 generate a description of here will be the lowest numbered location
1693 which is actually within the array. That's *not* necessarily the
1694 same as the zeroth element of the array. */
1696 switch (GET_CODE (rtl))
1698 case SUBREG:
1700 /* The case of a subreg may arise when we have a local (register)
1701 variable or a formal (register) parameter which doesn't quite
1702 fill up an entire register. For now, just assume that it is
1703 legitimate to make the Dwarf info refer to the whole register
1704 which contains the given subreg. */
1706 rtl = XEXP (rtl, 0);
1707 /* Drop thru. */
1709 case REG:
1711 /* Whenever a register number forms a part of the description of
1712 the method for calculating the (dynamic) address of a memory
1713 resident object, DWARF rules require the register number to
1714 be referred to as a "base register". This distinction is not
1715 based in any way upon what category of register the hardware
1716 believes the given register belongs to. This is strictly
1717 DWARF terminology we're dealing with here.
1719 Note that in cases where the location of a memory-resident data
1720 object could be expressed as:
1722 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1724 the actual DWARF location descriptor that we generate may just
1725 be OP_BASEREG (basereg). This may look deceptively like the
1726 object in question was allocated to a register (rather than
1727 in memory) so DWARF consumers need to be aware of the subtle
1728 distinction between OP_REG and OP_BASEREG. */
1730 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1731 output_reg_number (rtl);
1732 break;
1734 case MEM:
1735 output_mem_loc_descriptor (XEXP (rtl, 0));
1736 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1737 break;
1739 case CONST:
1740 case SYMBOL_REF:
1741 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1742 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1743 break;
1745 case PLUS:
1746 output_mem_loc_descriptor (XEXP (rtl, 0));
1747 output_mem_loc_descriptor (XEXP (rtl, 1));
1748 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1749 break;
1751 case CONST_INT:
1752 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1753 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1754 break;
1756 case MULT:
1757 /* If a pseudo-reg is optimized away, it is possible for it to
1758 be replaced with a MEM containing a multiply. Use a GNU extension
1759 to describe it. */
1760 output_mem_loc_descriptor (XEXP (rtl, 0));
1761 output_mem_loc_descriptor (XEXP (rtl, 1));
1762 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1763 break;
1765 default:
1766 abort ();
1770 /* Output a proper Dwarf location descriptor for a variable or parameter
1771 which is either allocated in a register or in a memory location. For
1772 a register, we just generate an OP_REG and the register number. For a
1773 memory location we provide a Dwarf postfix expression describing how to
1774 generate the (dynamic) address of the object onto the address stack. */
1776 static void
1777 output_loc_descriptor (rtl)
1778 register rtx rtl;
1780 switch (GET_CODE (rtl))
1782 case SUBREG:
1784 /* The case of a subreg may arise when we have a local (register)
1785 variable or a formal (register) parameter which doesn't quite
1786 fill up an entire register. For now, just assume that it is
1787 legitimate to make the Dwarf info refer to the whole register
1788 which contains the given subreg. */
1790 rtl = XEXP (rtl, 0);
1791 /* Drop thru. */
1793 case REG:
1794 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1795 output_reg_number (rtl);
1796 break;
1798 case MEM:
1799 output_mem_loc_descriptor (XEXP (rtl, 0));
1800 break;
1802 default:
1803 abort (); /* Should never happen */
1807 /* Given a tree node describing an array bound (either lower or upper)
1808 output a representation for that bound. */
1810 static void
1811 output_bound_representation (bound, dim_num, u_or_l)
1812 register tree bound;
1813 register unsigned dim_num; /* For multi-dimensional arrays. */
1814 register char u_or_l; /* Designates upper or lower bound. */
1816 switch (TREE_CODE (bound))
1819 case ERROR_MARK:
1820 return;
1822 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1824 case INTEGER_CST:
1825 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1826 (unsigned) TREE_INT_CST_LOW (bound));
1827 break;
1829 default:
1831 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1832 SAVE_EXPR nodes, in which case we can do something, or as
1833 an expression, which we cannot represent. */
1835 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1836 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1838 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1839 current_dienum, dim_num, u_or_l);
1841 sprintf (end_label, BOUND_END_LABEL_FMT,
1842 current_dienum, dim_num, u_or_l);
1844 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1845 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1847 /* If optimization is turned on, the SAVE_EXPRs that describe
1848 how to access the upper bound values are essentially bogus.
1849 They only describe (at best) how to get at these values at
1850 the points in the generated code right after they have just
1851 been computed. Worse yet, in the typical case, the upper
1852 bound values will not even *be* computed in the optimized
1853 code, so these SAVE_EXPRs are entirely bogus.
1855 In order to compensate for this fact, we check here to see
1856 if optimization is enabled, and if so, we effectively create
1857 an empty location description for the (unknown and unknowable)
1858 upper bound.
1860 This should not cause too much trouble for existing (stupid?)
1861 debuggers because they have to deal with empty upper bounds
1862 location descriptions anyway in order to be able to deal with
1863 incomplete array types.
1865 Of course an intelligent debugger (GDB?) should be able to
1866 comprehend that a missing upper bound specification in a
1867 array type used for a storage class `auto' local array variable
1868 indicates that the upper bound is both unknown (at compile-
1869 time) and unknowable (at run-time) due to optimization. */
1871 if (! optimize)
1873 while (TREE_CODE (bound) == NOP_EXPR
1874 || TREE_CODE (bound) == CONVERT_EXPR)
1875 bound = TREE_OPERAND (bound, 0);
1877 if (TREE_CODE (bound) == SAVE_EXPR)
1878 output_loc_descriptor
1879 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1882 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1884 break;
1889 /* Recursive function to output a sequence of value/name pairs for
1890 enumeration constants in reversed order. This is called from
1891 enumeration_type_die. */
1893 static void
1894 output_enumeral_list (link)
1895 register tree link;
1897 if (link)
1899 output_enumeral_list (TREE_CHAIN (link));
1900 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1901 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1902 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
1903 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1907 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1908 which is not less than the value itself. */
1910 static inline unsigned
1911 ceiling (value, boundary)
1912 register unsigned value;
1913 register unsigned boundary;
1915 return (((value + boundary - 1) / boundary) * boundary);
1918 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1919 pointer to the declared type for the relevant field variable, or return
1920 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1922 static inline tree
1923 field_type (decl)
1924 register tree decl;
1926 register tree type;
1928 if (TREE_CODE (decl) == ERROR_MARK)
1929 return integer_type_node;
1931 type = DECL_BIT_FIELD_TYPE (decl);
1932 if (type == NULL)
1933 type = TREE_TYPE (decl);
1934 return type;
1937 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1938 node, return the alignment in bits for the type, or else return
1939 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1941 static inline unsigned
1942 simple_type_align_in_bits (type)
1943 register tree type;
1945 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1948 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1949 node, return the size in bits for the type if it is a constant, or
1950 else return the alignment for the type if the type's size is not
1951 constant, or else return BITS_PER_WORD if the type actually turns out
1952 to be an ERROR_MARK node. */
1954 static inline unsigned
1955 simple_type_size_in_bits (type)
1956 register tree type;
1958 if (TREE_CODE (type) == ERROR_MARK)
1959 return BITS_PER_WORD;
1960 else
1962 register tree type_size_tree = TYPE_SIZE (type);
1964 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1965 return TYPE_ALIGN (type);
1967 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1971 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1972 return the byte offset of the lowest addressed byte of the "containing
1973 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1974 mine what that offset is, either because the argument turns out to be a
1975 pointer to an ERROR_MARK node, or because the offset is actually variable.
1976 (We can't handle the latter case just yet.) */
1978 static unsigned
1979 field_byte_offset (decl)
1980 register tree decl;
1982 register unsigned type_align_in_bytes;
1983 register unsigned type_align_in_bits;
1984 register unsigned type_size_in_bits;
1985 register unsigned object_offset_in_align_units;
1986 register unsigned object_offset_in_bits;
1987 register unsigned object_offset_in_bytes;
1988 register tree type;
1989 register tree bitpos_tree;
1990 register tree field_size_tree;
1991 register unsigned bitpos_int;
1992 register unsigned deepest_bitpos;
1993 register unsigned field_size_in_bits;
1995 if (TREE_CODE (decl) == ERROR_MARK)
1996 return 0;
1998 if (TREE_CODE (decl) != FIELD_DECL)
1999 abort ();
2001 type = field_type (decl);
2003 bitpos_tree = DECL_FIELD_BITPOS (decl);
2004 field_size_tree = DECL_SIZE (decl);
2006 /* We cannot yet cope with fields whose positions or sizes are variable,
2007 so for now, when we see such things, we simply return 0. Someday,
2008 we may be able to handle such cases, but it will be damn difficult. */
2010 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2011 return 0;
2012 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2014 if (TREE_CODE (field_size_tree) != INTEGER_CST)
2015 return 0;
2016 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
2018 type_size_in_bits = simple_type_size_in_bits (type);
2020 type_align_in_bits = simple_type_align_in_bits (type);
2021 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2023 /* Note that the GCC front-end doesn't make any attempt to keep track
2024 of the starting bit offset (relative to the start of the containing
2025 structure type) of the hypothetical "containing object" for a bit-
2026 field. Thus, when computing the byte offset value for the start of
2027 the "containing object" of a bit-field, we must deduce this infor-
2028 mation on our own.
2030 This can be rather tricky to do in some cases. For example, handling
2031 the following structure type definition when compiling for an i386/i486
2032 target (which only aligns long long's to 32-bit boundaries) can be very
2033 tricky:
2035 struct S {
2036 int field1;
2037 long long field2:31;
2040 Fortunately, there is a simple rule-of-thumb which can be used in such
2041 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2042 the structure shown above. It decides to do this based upon one simple
2043 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2044 taining object" for each bit-field at the first (i.e. lowest addressed)
2045 legitimate alignment boundary (based upon the required minimum alignment
2046 for the declared type of the field) which it can possibly use, subject
2047 to the condition that there is still enough available space remaining
2048 in the containing object (when allocated at the selected point) to
2049 fully accommodate all of the bits of the bit-field itself.
2051 This simple rule makes it obvious why GCC allocates 8 bytes for each
2052 object of the structure type shown above. When looking for a place to
2053 allocate the "containing object" for `field2', the compiler simply tries
2054 to allocate a 64-bit "containing object" at each successive 32-bit
2055 boundary (starting at zero) until it finds a place to allocate that 64-
2056 bit field such that at least 31 contiguous (and previously unallocated)
2057 bits remain within that selected 64 bit field. (As it turns out, for
2058 the example above, the compiler finds that it is OK to allocate the
2059 "containing object" 64-bit field at bit-offset zero within the
2060 structure type.)
2062 Here we attempt to work backwards from the limited set of facts we're
2063 given, and we try to deduce from those facts, where GCC must have
2064 believed that the containing object started (within the structure type).
2066 The value we deduce is then used (by the callers of this routine) to
2067 generate AT_location and AT_bit_offset attributes for fields (both
2068 bit-fields and, in the case of AT_location, regular fields as well).
2071 /* Figure out the bit-distance from the start of the structure to the
2072 "deepest" bit of the bit-field. */
2073 deepest_bitpos = bitpos_int + field_size_in_bits;
2075 /* This is the tricky part. Use some fancy footwork to deduce where the
2076 lowest addressed bit of the containing object must be. */
2077 object_offset_in_bits
2078 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2080 /* Compute the offset of the containing object in "alignment units". */
2081 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2083 /* Compute the offset of the containing object in bytes. */
2084 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2086 /* The above code assumes that the field does not cross an alignment
2087 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2088 or if the structure is packed. If this happens, then we get an object
2089 which starts after the bitfield, which means that the bit offset is
2090 negative. Gdb fails when given negative bit offsets. We avoid this
2091 by recomputing using the first bit of the bitfield. This will give
2092 us an object which does not completely contain the bitfield, but it
2093 will be aligned, and it will contain the first bit of the bitfield. */
2094 if (object_offset_in_bits > bitpos_int)
2096 deepest_bitpos = bitpos_int + 1;
2097 object_offset_in_bits
2098 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2099 object_offset_in_align_units = (object_offset_in_bits
2100 / type_align_in_bits);
2101 object_offset_in_bytes = (object_offset_in_align_units
2102 * type_align_in_bytes);
2105 return object_offset_in_bytes;
2108 /****************************** attributes *********************************/
2110 /* The following routines are responsible for writing out the various types
2111 of Dwarf attributes (and any following data bytes associated with them).
2112 These routines are listed in order based on the numerical codes of their
2113 associated attributes. */
2115 /* Generate an AT_sibling attribute. */
2117 static inline void
2118 sibling_attribute ()
2120 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2122 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2123 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2124 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2127 /* Output the form of location attributes suitable for whole variables and
2128 whole parameters. Note that the location attributes for struct fields
2129 are generated by the routine `data_member_location_attribute' below. */
2131 static void
2132 location_attribute (rtl)
2133 register rtx rtl;
2135 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2136 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2138 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2139 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2140 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2141 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2142 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2144 /* Handle a special case. If we are about to output a location descriptor
2145 for a variable or parameter which has been optimized out of existence,
2146 don't do that. Instead we output a zero-length location descriptor
2147 value as part of the location attribute.
2149 A variable which has been optimized out of existence will have a
2150 DECL_RTL value which denotes a pseudo-reg.
2152 Currently, in some rare cases, variables can have DECL_RTL values
2153 which look like (MEM (REG pseudo-reg#)). These cases are due to
2154 bugs elsewhere in the compiler. We treat such cases
2155 as if the variable(s) in question had been optimized out of existence.
2157 Note that in all cases where we wish to express the fact that a
2158 variable has been optimized out of existence, we do not simply
2159 suppress the generation of the entire location attribute because
2160 the absence of a location attribute in certain kinds of DIEs is
2161 used to indicate something else entirely... i.e. that the DIE
2162 represents an object declaration, but not a definition. So saith
2163 the PLSIG.
2166 if (! is_pseudo_reg (rtl)
2167 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2168 output_loc_descriptor (rtl);
2170 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2173 /* Output the specialized form of location attribute used for data members
2174 of struct and union types.
2176 In the special case of a FIELD_DECL node which represents a bit-field,
2177 the "offset" part of this special location descriptor must indicate the
2178 distance in bytes from the lowest-addressed byte of the containing
2179 struct or union type to the lowest-addressed byte of the "containing
2180 object" for the bit-field. (See the `field_byte_offset' function above.)
2182 For any given bit-field, the "containing object" is a hypothetical
2183 object (of some integral or enum type) within which the given bit-field
2184 lives. The type of this hypothetical "containing object" is always the
2185 same as the declared type of the individual bit-field itself (for GCC
2186 anyway... the DWARF spec doesn't actually mandate this).
2188 Note that it is the size (in bytes) of the hypothetical "containing
2189 object" which will be given in the AT_byte_size attribute for this
2190 bit-field. (See the `byte_size_attribute' function below.) It is
2191 also used when calculating the value of the AT_bit_offset attribute.
2192 (See the `bit_offset_attribute' function below.) */
2194 static void
2195 data_member_location_attribute (t)
2196 register tree t;
2198 register unsigned object_offset_in_bytes;
2199 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2200 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2202 if (TREE_CODE (t) == TREE_VEC)
2203 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2204 else
2205 object_offset_in_bytes = field_byte_offset (t);
2207 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2208 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2209 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2210 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2211 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2212 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2213 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2214 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2215 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2218 /* Output an AT_const_value attribute for a variable or a parameter which
2219 does not have a "location" either in memory or in a register. These
2220 things can arise in GNU C when a constant is passed as an actual
2221 parameter to an inlined function. They can also arise in C++ where
2222 declared constants do not necessarily get memory "homes". */
2224 static void
2225 const_value_attribute (rtl)
2226 register rtx rtl;
2228 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2229 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2231 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2232 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2233 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2234 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2235 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2237 switch (GET_CODE (rtl))
2239 case CONST_INT:
2240 /* Note that a CONST_INT rtx could represent either an integer or
2241 a floating-point constant. A CONST_INT is used whenever the
2242 constant will fit into a single word. In all such cases, the
2243 original mode of the constant value is wiped out, and the
2244 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2245 precise mode information for these constants, we always just
2246 output them using 4 bytes. */
2248 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2249 break;
2251 case CONST_DOUBLE:
2252 /* Note that a CONST_DOUBLE rtx could represent either an integer
2253 or a floating-point constant. A CONST_DOUBLE is used whenever
2254 the constant requires more than one word in order to be adequately
2255 represented. In all such cases, the original mode of the constant
2256 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2257 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2259 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2260 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2261 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2262 break;
2264 case CONST_STRING:
2265 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2266 break;
2268 case SYMBOL_REF:
2269 case LABEL_REF:
2270 case CONST:
2271 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2272 break;
2274 case PLUS:
2275 /* In cases where an inlined instance of an inline function is passed
2276 the address of an `auto' variable (which is local to the caller)
2277 we can get a situation where the DECL_RTL of the artificial
2278 local variable (for the inlining) which acts as a stand-in for
2279 the corresponding formal parameter (of the inline function)
2280 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2281 This is not exactly a compile-time constant expression, but it
2282 isn't the address of the (artificial) local variable either.
2283 Rather, it represents the *value* which the artificial local
2284 variable always has during its lifetime. We currently have no
2285 way to represent such quasi-constant values in Dwarf, so for now
2286 we just punt and generate an AT_const_value attribute with form
2287 FORM_BLOCK4 and a length of zero. */
2288 break;
2290 default:
2291 abort (); /* No other kinds of rtx should be possible here. */
2294 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2297 /* Generate *either* an AT_location attribute or else an AT_const_value
2298 data attribute for a variable or a parameter. We generate the
2299 AT_const_value attribute only in those cases where the given
2300 variable or parameter does not have a true "location" either in
2301 memory or in a register. This can happen (for example) when a
2302 constant is passed as an actual argument in a call to an inline
2303 function. (It's possible that these things can crop up in other
2304 ways also.) Note that one type of constant value which can be
2305 passed into an inlined function is a constant pointer. This can
2306 happen for example if an actual argument in an inlined function
2307 call evaluates to a compile-time constant address. */
2309 static void
2310 location_or_const_value_attribute (decl)
2311 register tree decl;
2313 register rtx rtl;
2315 if (TREE_CODE (decl) == ERROR_MARK)
2316 return;
2318 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2320 /* Should never happen. */
2321 abort ();
2322 return;
2325 /* Here we have to decide where we are going to say the parameter "lives"
2326 (as far as the debugger is concerned). We only have a couple of choices.
2327 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2328 normally indicates where the parameter lives during most of the activa-
2329 tion of the function. If optimization is enabled however, this could
2330 be either NULL or else a pseudo-reg. Both of those cases indicate that
2331 the parameter doesn't really live anywhere (as far as the code generation
2332 parts of GCC are concerned) during most of the function's activation.
2333 That will happen (for example) if the parameter is never referenced
2334 within the function.
2336 We could just generate a location descriptor here for all non-NULL
2337 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2338 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2339 cases where DECL_RTL is NULL or is a pseudo-reg.
2341 Note however that we can only get away with using DECL_INCOMING_RTL as
2342 a backup substitute for DECL_RTL in certain limited cases. In cases
2343 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2344 we can be sure that the parameter was passed using the same type as it
2345 is declared to have within the function, and that its DECL_INCOMING_RTL
2346 points us to a place where a value of that type is passed. In cases
2347 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2348 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2349 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2350 points us to a value of some type which is *different* from the type
2351 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2352 to generate a location attribute in such cases, the debugger would
2353 end up (for example) trying to fetch a `float' from a place which
2354 actually contains the first part of a `double'. That would lead to
2355 really incorrect and confusing output at debug-time, and we don't
2356 want that now do we?
2358 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2359 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2360 couple of cute exceptions however. On little-endian machines we can
2361 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2362 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2363 an integral type which is smaller than TREE_TYPE(decl). These cases
2364 arise when (on a little-endian machine) a non-prototyped function has
2365 a parameter declared to be of type `short' or `char'. In such cases,
2366 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2367 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2368 passed `int' value. If the debugger then uses that address to fetch a
2369 `short' or a `char' (on a little-endian machine) the result will be the
2370 correct data, so we allow for such exceptional cases below.
2372 Note that our goal here is to describe the place where the given formal
2373 parameter lives during most of the function's activation (i.e. between
2374 the end of the prologue and the start of the epilogue). We'll do that
2375 as best as we can. Note however that if the given formal parameter is
2376 modified sometime during the execution of the function, then a stack
2377 backtrace (at debug-time) will show the function as having been called
2378 with the *new* value rather than the value which was originally passed
2379 in. This happens rarely enough that it is not a major problem, but it
2380 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2381 may generate two additional attributes for any given TAG_formal_parameter
2382 DIE which will describe the "passed type" and the "passed location" for
2383 the given formal parameter in addition to the attributes we now generate
2384 to indicate the "declared type" and the "active location" for each
2385 parameter. This additional set of attributes could be used by debuggers
2386 for stack backtraces.
2388 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2389 can be NULL also. This happens (for example) for inlined-instances of
2390 inline function formal parameters which are never referenced. This really
2391 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2392 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2393 these values for inlined instances of inline function parameters, so
2394 when we see such cases, we are just out-of-luck for the time
2395 being (until integrate.c gets fixed).
2398 /* Use DECL_RTL as the "location" unless we find something better. */
2399 rtl = DECL_RTL (decl);
2401 if (TREE_CODE (decl) == PARM_DECL)
2402 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2404 /* This decl represents a formal parameter which was optimized out. */
2405 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2406 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2408 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2409 *all* cases where (rtl == NULL_RTX) just below. */
2411 if (declared_type == passed_type)
2412 rtl = DECL_INCOMING_RTL (decl);
2413 else if (! BYTES_BIG_ENDIAN)
2414 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2415 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2416 rtl = DECL_INCOMING_RTL (decl);
2419 if (rtl == NULL_RTX)
2420 return;
2422 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2423 #ifdef LEAF_REG_REMAP
2424 if (leaf_function)
2425 leaf_renumber_regs_insn (rtl);
2426 #endif
2428 switch (GET_CODE (rtl))
2430 case ADDRESSOF:
2431 /* The address of a variable that was optimized away; don't emit
2432 anything. */
2433 break;
2435 case CONST_INT:
2436 case CONST_DOUBLE:
2437 case CONST_STRING:
2438 case SYMBOL_REF:
2439 case LABEL_REF:
2440 case CONST:
2441 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2442 const_value_attribute (rtl);
2443 break;
2445 case MEM:
2446 case REG:
2447 case SUBREG:
2448 location_attribute (rtl);
2449 break;
2451 case CONCAT:
2452 /* ??? CONCAT is used for complex variables, which may have the real
2453 part stored in one place and the imag part stored somewhere else.
2454 DWARF1 has no way to describe a variable that lives in two different
2455 places, so we just describe where the first part lives, and hope that
2456 the second part is stored after it. */
2457 location_attribute (XEXP (rtl, 0));
2458 break;
2460 default:
2461 abort (); /* Should never happen. */
2465 /* Generate an AT_name attribute given some string value to be included as
2466 the value of the attribute. */
2468 static inline void
2469 name_attribute (name_string)
2470 register char *name_string;
2472 if (name_string && *name_string)
2474 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2475 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2479 static inline void
2480 fund_type_attribute (ft_code)
2481 register unsigned ft_code;
2483 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2484 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2487 static void
2488 mod_fund_type_attribute (type, decl_const, decl_volatile)
2489 register tree type;
2490 register int decl_const;
2491 register int decl_volatile;
2493 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2494 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2496 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2497 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2498 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2499 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2500 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2501 write_modifier_bytes (type, decl_const, decl_volatile);
2502 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2503 fundamental_type_code (root_type (type)));
2504 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2507 static inline void
2508 user_def_type_attribute (type)
2509 register tree type;
2511 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2513 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2514 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2515 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2518 static void
2519 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2520 register tree type;
2521 register int decl_const;
2522 register int decl_volatile;
2524 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2525 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2526 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2528 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2529 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2530 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2531 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2532 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2533 write_modifier_bytes (type, decl_const, decl_volatile);
2534 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2535 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2536 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2539 #ifdef USE_ORDERING_ATTRIBUTE
2540 static inline void
2541 ordering_attribute (ordering)
2542 register unsigned ordering;
2544 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2545 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2547 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2549 /* Note that the block of subscript information for an array type also
2550 includes information about the element type of type given array type. */
2552 static void
2553 subscript_data_attribute (type)
2554 register tree type;
2556 register unsigned dimension_number;
2557 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2558 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2560 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2561 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2562 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2563 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2564 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2566 /* The GNU compilers represent multidimensional array types as sequences
2567 of one dimensional array types whose element types are themselves array
2568 types. Here we squish that down, so that each multidimensional array
2569 type gets only one array_type DIE in the Dwarf debugging info. The
2570 draft Dwarf specification say that we are allowed to do this kind
2571 of compression in C (because there is no difference between an
2572 array or arrays and a multidimensional array in C) but for other
2573 source languages (e.g. Ada) we probably shouldn't do this. */
2575 for (dimension_number = 0;
2576 TREE_CODE (type) == ARRAY_TYPE;
2577 type = TREE_TYPE (type), dimension_number++)
2579 register tree domain = TYPE_DOMAIN (type);
2581 /* Arrays come in three flavors. Unspecified bounds, fixed
2582 bounds, and (in GNU C only) variable bounds. Handle all
2583 three forms here. */
2585 if (domain)
2587 /* We have an array type with specified bounds. */
2589 register tree lower = TYPE_MIN_VALUE (domain);
2590 register tree upper = TYPE_MAX_VALUE (domain);
2592 /* Handle only fundamental types as index types for now. */
2594 if (! type_is_fundamental (domain))
2595 abort ();
2597 /* Output the representation format byte for this dimension. */
2599 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2600 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2601 (upper && TREE_CODE (upper) == INTEGER_CST)));
2603 /* Output the index type for this dimension. */
2605 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2606 fundamental_type_code (domain));
2608 /* Output the representation for the lower bound. */
2610 output_bound_representation (lower, dimension_number, 'l');
2612 /* Output the representation for the upper bound. */
2614 output_bound_representation (upper, dimension_number, 'u');
2616 else
2618 /* We have an array type with an unspecified length. For C and
2619 C++ we can assume that this really means that (a) the index
2620 type is an integral type, and (b) the lower bound is zero.
2621 Note that Dwarf defines the representation of an unspecified
2622 (upper) bound as being a zero-length location description. */
2624 /* Output the array-bounds format byte. */
2626 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2628 /* Output the (assumed) index type. */
2630 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2632 /* Output the (assumed) lower bound (constant) value. */
2634 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2636 /* Output the (empty) location description for the upper bound. */
2638 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2642 /* Output the prefix byte that says that the element type is coming up. */
2644 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2646 /* Output a representation of the type of the elements of this array type. */
2648 type_attribute (type, 0, 0);
2650 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2653 static void
2654 byte_size_attribute (tree_node)
2655 register tree tree_node;
2657 register unsigned size;
2659 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2660 switch (TREE_CODE (tree_node))
2662 case ERROR_MARK:
2663 size = 0;
2664 break;
2666 case ENUMERAL_TYPE:
2667 case RECORD_TYPE:
2668 case UNION_TYPE:
2669 case QUAL_UNION_TYPE:
2670 case ARRAY_TYPE:
2671 size = int_size_in_bytes (tree_node);
2672 break;
2674 case FIELD_DECL:
2675 /* For a data member of a struct or union, the AT_byte_size is
2676 generally given as the number of bytes normally allocated for
2677 an object of the *declared* type of the member itself. This
2678 is true even for bit-fields. */
2679 size = simple_type_size_in_bits (field_type (tree_node))
2680 / BITS_PER_UNIT;
2681 break;
2683 default:
2684 abort ();
2687 /* Note that `size' might be -1 when we get to this point. If it
2688 is, that indicates that the byte size of the entity in question
2689 is variable. We have no good way of expressing this fact in Dwarf
2690 at the present time, so just let the -1 pass on through. */
2692 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2695 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2696 which specifies the distance in bits from the highest order bit of the
2697 "containing object" for the bit-field to the highest order bit of the
2698 bit-field itself.
2700 For any given bit-field, the "containing object" is a hypothetical
2701 object (of some integral or enum type) within which the given bit-field
2702 lives. The type of this hypothetical "containing object" is always the
2703 same as the declared type of the individual bit-field itself.
2705 The determination of the exact location of the "containing object" for
2706 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2707 function (above).
2709 Note that it is the size (in bytes) of the hypothetical "containing
2710 object" which will be given in the AT_byte_size attribute for this
2711 bit-field. (See `byte_size_attribute' above.) */
2713 static inline void
2714 bit_offset_attribute (decl)
2715 register tree decl;
2717 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2718 register tree type = DECL_BIT_FIELD_TYPE (decl);
2719 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2720 register unsigned bitpos_int;
2721 register unsigned highest_order_object_bit_offset;
2722 register unsigned highest_order_field_bit_offset;
2723 register unsigned bit_offset;
2725 /* Must be a bit field. */
2726 if (!type
2727 || TREE_CODE (decl) != FIELD_DECL)
2728 abort ();
2730 /* We can't yet handle bit-fields whose offsets are variable, so if we
2731 encounter such things, just return without generating any attribute
2732 whatsoever. */
2734 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2735 return;
2736 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2738 /* Note that the bit offset is always the distance (in bits) from the
2739 highest-order bit of the "containing object" to the highest-order
2740 bit of the bit-field itself. Since the "high-order end" of any
2741 object or field is different on big-endian and little-endian machines,
2742 the computation below must take account of these differences. */
2744 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2745 highest_order_field_bit_offset = bitpos_int;
2747 if (! BYTES_BIG_ENDIAN)
2749 highest_order_field_bit_offset
2750 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2752 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2755 bit_offset =
2756 (! BYTES_BIG_ENDIAN
2757 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2758 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2760 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2761 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2764 /* For a FIELD_DECL node which represents a bit field, output an attribute
2765 which specifies the length in bits of the given field. */
2767 static inline void
2768 bit_size_attribute (decl)
2769 register tree decl;
2771 /* Must be a field and a bit field. */
2772 if (TREE_CODE (decl) != FIELD_DECL
2773 || ! DECL_BIT_FIELD_TYPE (decl))
2774 abort ();
2776 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2777 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2778 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2781 /* The following routine outputs the `element_list' attribute for enumeration
2782 type DIEs. The element_lits attribute includes the names and values of
2783 all of the enumeration constants associated with the given enumeration
2784 type. */
2786 static inline void
2787 element_list_attribute (element)
2788 register tree element;
2790 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2791 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2793 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2794 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2795 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2796 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2797 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2799 /* Here we output a list of value/name pairs for each enumeration constant
2800 defined for this enumeration type (as required), but we do it in REVERSE
2801 order. The order is the one required by the draft #5 Dwarf specification
2802 published by the UI/PLSIG. */
2804 output_enumeral_list (element); /* Recursively output the whole list. */
2806 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2809 /* Generate an AT_stmt_list attribute. These are normally present only in
2810 DIEs with a TAG_compile_unit tag. */
2812 static inline void
2813 stmt_list_attribute (label)
2814 register char *label;
2816 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2817 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2818 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2821 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2822 for a subroutine DIE. */
2824 static inline void
2825 low_pc_attribute (asm_low_label)
2826 register char *asm_low_label;
2828 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2829 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2832 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2833 subroutine DIE. */
2835 static inline void
2836 high_pc_attribute (asm_high_label)
2837 register char *asm_high_label;
2839 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2840 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2843 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2845 static inline void
2846 body_begin_attribute (asm_begin_label)
2847 register char *asm_begin_label;
2849 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2850 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2853 /* Generate an AT_body_end attribute for a subroutine DIE. */
2855 static inline void
2856 body_end_attribute (asm_end_label)
2857 register char *asm_end_label;
2859 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2860 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2863 /* Generate an AT_language attribute given a LANG value. These attributes
2864 are used only within TAG_compile_unit DIEs. */
2866 static inline void
2867 language_attribute (language_code)
2868 register unsigned language_code;
2870 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2871 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2874 static inline void
2875 member_attribute (context)
2876 register tree context;
2878 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2880 /* Generate this attribute only for members in C++. */
2882 if (context != NULL && is_tagged_type (context))
2884 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2885 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2886 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2890 #if 0
2891 static inline void
2892 string_length_attribute (upper_bound)
2893 register tree upper_bound;
2895 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2896 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2898 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2899 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2900 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2901 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2902 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2903 output_bound_representation (upper_bound, 0, 'u');
2904 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2906 #endif
2908 static inline void
2909 comp_dir_attribute (dirname)
2910 register char *dirname;
2912 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2913 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
2916 static inline void
2917 sf_names_attribute (sf_names_start_label)
2918 register char *sf_names_start_label;
2920 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2921 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2922 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2925 static inline void
2926 src_info_attribute (src_info_start_label)
2927 register char *src_info_start_label;
2929 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2930 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2931 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2934 static inline void
2935 mac_info_attribute (mac_info_start_label)
2936 register char *mac_info_start_label;
2938 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2939 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2940 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2943 static inline void
2944 prototyped_attribute (func_type)
2945 register tree func_type;
2947 if ((strcmp (language_string, "GNU C") == 0)
2948 && (TYPE_ARG_TYPES (func_type) != NULL))
2950 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2951 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2955 static inline void
2956 producer_attribute (producer)
2957 register char *producer;
2959 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2960 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
2963 static inline void
2964 inline_attribute (decl)
2965 register tree decl;
2967 if (DECL_INLINE (decl))
2969 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2970 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2974 static inline void
2975 containing_type_attribute (containing_type)
2976 register tree containing_type;
2978 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2980 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2981 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2982 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2985 static inline void
2986 abstract_origin_attribute (origin)
2987 register tree origin;
2989 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2991 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2992 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2994 case 'd':
2995 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2996 break;
2998 case 't':
2999 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3000 break;
3002 default:
3003 abort (); /* Should never happen. */
3006 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3009 #ifdef DWARF_DECL_COORDINATES
3010 static inline void
3011 src_coords_attribute (src_fileno, src_lineno)
3012 register unsigned src_fileno;
3013 register unsigned src_lineno;
3015 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3016 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3017 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3019 #endif /* defined(DWARF_DECL_COORDINATES) */
3021 static inline void
3022 pure_or_virtual_attribute (func_decl)
3023 register tree func_decl;
3025 if (DECL_VIRTUAL_P (func_decl))
3027 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3028 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3029 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3030 else
3031 #endif
3032 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3033 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3037 /************************* end of attributes *****************************/
3039 /********************* utility routines for DIEs *************************/
3041 /* Output an AT_name attribute and an AT_src_coords attribute for the
3042 given decl, but only if it actually has a name. */
3044 static void
3045 name_and_src_coords_attributes (decl)
3046 register tree decl;
3048 register tree decl_name = DECL_NAME (decl);
3050 if (decl_name && IDENTIFIER_POINTER (decl_name))
3052 name_attribute (IDENTIFIER_POINTER (decl_name));
3053 #ifdef DWARF_DECL_COORDINATES
3055 register unsigned file_index;
3057 /* This is annoying, but we have to pop out of the .debug section
3058 for a moment while we call `lookup_filename' because calling it
3059 may cause a temporary switch into the .debug_sfnames section and
3060 most svr4 assemblers are not smart enough to be able to nest
3061 section switches to any depth greater than one. Note that we
3062 also can't skirt this issue by delaying all output to the
3063 .debug_sfnames section unit the end of compilation because that
3064 would cause us to have inter-section forward references and
3065 Fred Fish sez that m68k/svr4 assemblers botch those. */
3067 ASM_OUTPUT_POP_SECTION (asm_out_file);
3068 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3069 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3071 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3073 #endif /* defined(DWARF_DECL_COORDINATES) */
3077 /* Many forms of DIEs contain a "type description" part. The following
3078 routine writes out these "type descriptor" parts. */
3080 static void
3081 type_attribute (type, decl_const, decl_volatile)
3082 register tree type;
3083 register int decl_const;
3084 register int decl_volatile;
3086 register enum tree_code code = TREE_CODE (type);
3087 register int root_type_modified;
3089 if (code == ERROR_MARK)
3090 return;
3092 /* Handle a special case. For functions whose return type is void,
3093 we generate *no* type attribute. (Note that no object may have
3094 type `void', so this only applies to function return types. */
3096 if (code == VOID_TYPE)
3097 return;
3099 /* If this is a subtype, find the underlying type. Eventually,
3100 this should write out the appropriate subtype info. */
3101 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3102 && TREE_TYPE (type) != 0)
3103 type = TREE_TYPE (type), code = TREE_CODE (type);
3105 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3106 || decl_const || decl_volatile
3107 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3109 if (type_is_fundamental (root_type (type)))
3111 if (root_type_modified)
3112 mod_fund_type_attribute (type, decl_const, decl_volatile);
3113 else
3114 fund_type_attribute (fundamental_type_code (type));
3116 else
3118 if (root_type_modified)
3119 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3120 else
3121 /* We have to get the type_main_variant here (and pass that to the
3122 `user_def_type_attribute' routine) because the ..._TYPE node we
3123 have might simply be a *copy* of some original type node (where
3124 the copy was created to help us keep track of typedef names)
3125 and that copy might have a different TYPE_UID from the original
3126 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3127 is labeling a given type DIE for future reference, it always and
3128 only creates labels for DIEs representing *main variants*, and it
3129 never even knows about non-main-variants.) */
3130 user_def_type_attribute (type_main_variant (type));
3134 /* Given a tree pointer to a struct, class, union, or enum type node, return
3135 a pointer to the (string) tag name for the given type, or zero if the
3136 type was declared without a tag. */
3138 static char *
3139 type_tag (type)
3140 register tree type;
3142 register char *name = 0;
3144 if (TYPE_NAME (type) != 0)
3146 register tree t = 0;
3148 /* Find the IDENTIFIER_NODE for the type name. */
3149 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3150 t = TYPE_NAME (type);
3152 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3153 a TYPE_DECL node, regardless of whether or not a `typedef' was
3154 involved. */
3155 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3156 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3157 t = DECL_NAME (TYPE_NAME (type));
3159 /* Now get the name as a string, or invent one. */
3160 if (t != 0)
3161 name = IDENTIFIER_POINTER (t);
3164 return (name == 0 || *name == '\0') ? 0 : name;
3167 static inline void
3168 dienum_push ()
3170 /* Start by checking if the pending_sibling_stack needs to be expanded.
3171 If necessary, expand it. */
3173 if (pending_siblings == pending_siblings_allocated)
3175 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3176 pending_sibling_stack
3177 = (unsigned *) xrealloc (pending_sibling_stack,
3178 pending_siblings_allocated * sizeof(unsigned));
3181 pending_siblings++;
3182 NEXT_DIE_NUM = next_unused_dienum++;
3185 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3186 NEXT_DIE_NUM. */
3188 static inline void
3189 dienum_pop ()
3191 pending_siblings--;
3194 static inline tree
3195 member_declared_type (member)
3196 register tree member;
3198 return (DECL_BIT_FIELD_TYPE (member))
3199 ? DECL_BIT_FIELD_TYPE (member)
3200 : TREE_TYPE (member);
3203 /* Get the function's label, as described by its RTL.
3204 This may be different from the DECL_NAME name used
3205 in the source file. */
3207 static char *
3208 function_start_label (decl)
3209 register tree decl;
3211 rtx x;
3212 char *fnname;
3214 x = DECL_RTL (decl);
3215 if (GET_CODE (x) != MEM)
3216 abort ();
3217 x = XEXP (x, 0);
3218 if (GET_CODE (x) != SYMBOL_REF)
3219 abort ();
3220 fnname = XSTR (x, 0);
3221 return fnname;
3225 /******************************* DIEs ************************************/
3227 /* Output routines for individual types of DIEs. */
3229 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3231 static void
3232 output_array_type_die (arg)
3233 register void *arg;
3235 register tree type = arg;
3237 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3238 sibling_attribute ();
3239 equate_type_number_to_die_number (type);
3240 member_attribute (TYPE_CONTEXT (type));
3242 /* I believe that we can default the array ordering. SDB will probably
3243 do the right things even if AT_ordering is not present. It's not
3244 even an issue until we start to get into multidimensional arrays
3245 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3246 dimensional arrays, then we'll have to put the AT_ordering attribute
3247 back in. (But if and when we find out that we need to put these in,
3248 we will only do so for multidimensional arrays. After all, we don't
3249 want to waste space in the .debug section now do we?) */
3251 #ifdef USE_ORDERING_ATTRIBUTE
3252 ordering_attribute (ORD_row_major);
3253 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3255 subscript_data_attribute (type);
3258 static void
3259 output_set_type_die (arg)
3260 register void *arg;
3262 register tree type = arg;
3264 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3265 sibling_attribute ();
3266 equate_type_number_to_die_number (type);
3267 member_attribute (TYPE_CONTEXT (type));
3268 type_attribute (TREE_TYPE (type), 0, 0);
3271 #if 0
3272 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3274 static void
3275 output_entry_point_die (arg)
3276 register void *arg;
3278 register tree decl = arg;
3279 register tree origin = decl_ultimate_origin (decl);
3281 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3282 sibling_attribute ();
3283 dienum_push ();
3284 if (origin != NULL)
3285 abstract_origin_attribute (origin);
3286 else
3288 name_and_src_coords_attributes (decl);
3289 member_attribute (DECL_CONTEXT (decl));
3290 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3292 if (DECL_ABSTRACT (decl))
3293 equate_decl_number_to_die_number (decl);
3294 else
3295 low_pc_attribute (function_start_label (decl));
3297 #endif
3299 /* Output a DIE to represent an inlined instance of an enumeration type. */
3301 static void
3302 output_inlined_enumeration_type_die (arg)
3303 register void *arg;
3305 register tree type = arg;
3307 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3308 sibling_attribute ();
3309 if (!TREE_ASM_WRITTEN (type))
3310 abort ();
3311 abstract_origin_attribute (type);
3314 /* Output a DIE to represent an inlined instance of a structure type. */
3316 static void
3317 output_inlined_structure_type_die (arg)
3318 register void *arg;
3320 register tree type = arg;
3322 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3323 sibling_attribute ();
3324 if (!TREE_ASM_WRITTEN (type))
3325 abort ();
3326 abstract_origin_attribute (type);
3329 /* Output a DIE to represent an inlined instance of a union type. */
3331 static void
3332 output_inlined_union_type_die (arg)
3333 register void *arg;
3335 register tree type = arg;
3337 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3338 sibling_attribute ();
3339 if (!TREE_ASM_WRITTEN (type))
3340 abort ();
3341 abstract_origin_attribute (type);
3344 /* Output a DIE to represent an enumeration type. Note that these DIEs
3345 include all of the information about the enumeration values also.
3346 This information is encoded into the element_list attribute. */
3348 static void
3349 output_enumeration_type_die (arg)
3350 register void *arg;
3352 register tree type = arg;
3354 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3355 sibling_attribute ();
3356 equate_type_number_to_die_number (type);
3357 name_attribute (type_tag (type));
3358 member_attribute (TYPE_CONTEXT (type));
3360 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3361 given enum type is incomplete, do not generate the AT_byte_size
3362 attribute or the AT_element_list attribute. */
3364 if (TYPE_SIZE (type))
3366 byte_size_attribute (type);
3367 element_list_attribute (TYPE_FIELDS (type));
3371 /* Output a DIE to represent either a real live formal parameter decl or
3372 to represent just the type of some formal parameter position in some
3373 function type.
3375 Note that this routine is a bit unusual because its argument may be
3376 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3377 represents an inlining of some PARM_DECL) or else some sort of a
3378 ..._TYPE node. If it's the former then this function is being called
3379 to output a DIE to represent a formal parameter object (or some inlining
3380 thereof). If it's the latter, then this function is only being called
3381 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3382 formal argument type of some subprogram type. */
3384 static void
3385 output_formal_parameter_die (arg)
3386 register void *arg;
3388 register tree node = arg;
3390 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3391 sibling_attribute ();
3393 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3395 case 'd': /* We were called with some kind of a ..._DECL node. */
3397 register tree origin = decl_ultimate_origin (node);
3399 if (origin != NULL)
3400 abstract_origin_attribute (origin);
3401 else
3403 name_and_src_coords_attributes (node);
3404 type_attribute (TREE_TYPE (node),
3405 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3407 if (DECL_ABSTRACT (node))
3408 equate_decl_number_to_die_number (node);
3409 else
3410 location_or_const_value_attribute (node);
3412 break;
3414 case 't': /* We were called with some kind of a ..._TYPE node. */
3415 type_attribute (node, 0, 0);
3416 break;
3418 default:
3419 abort (); /* Should never happen. */
3423 /* Output a DIE to represent a declared function (either file-scope
3424 or block-local) which has "external linkage" (according to ANSI-C). */
3426 static void
3427 output_global_subroutine_die (arg)
3428 register void *arg;
3430 register tree decl = arg;
3431 register tree origin = decl_ultimate_origin (decl);
3433 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3434 sibling_attribute ();
3435 dienum_push ();
3436 if (origin != NULL)
3437 abstract_origin_attribute (origin);
3438 else
3440 register tree type = TREE_TYPE (decl);
3442 name_and_src_coords_attributes (decl);
3443 inline_attribute (decl);
3444 prototyped_attribute (type);
3445 member_attribute (DECL_CONTEXT (decl));
3446 type_attribute (TREE_TYPE (type), 0, 0);
3447 pure_or_virtual_attribute (decl);
3449 if (DECL_ABSTRACT (decl))
3450 equate_decl_number_to_die_number (decl);
3451 else
3453 if (! DECL_EXTERNAL (decl) && ! in_class
3454 && decl == current_function_decl)
3456 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3458 low_pc_attribute (function_start_label (decl));
3459 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3460 high_pc_attribute (label);
3461 if (use_gnu_debug_info_extensions)
3463 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3464 body_begin_attribute (label);
3465 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3466 body_end_attribute (label);
3472 /* Output a DIE to represent a declared data object (either file-scope
3473 or block-local) which has "external linkage" (according to ANSI-C). */
3475 static void
3476 output_global_variable_die (arg)
3477 register void *arg;
3479 register tree decl = arg;
3480 register tree origin = decl_ultimate_origin (decl);
3482 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3483 sibling_attribute ();
3484 if (origin != NULL)
3485 abstract_origin_attribute (origin);
3486 else
3488 name_and_src_coords_attributes (decl);
3489 member_attribute (DECL_CONTEXT (decl));
3490 type_attribute (TREE_TYPE (decl),
3491 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3493 if (DECL_ABSTRACT (decl))
3494 equate_decl_number_to_die_number (decl);
3495 else
3497 if (! DECL_EXTERNAL (decl) && ! in_class
3498 && current_function_decl == decl_function_context (decl))
3499 location_or_const_value_attribute (decl);
3503 static void
3504 output_label_die (arg)
3505 register void *arg;
3507 register tree decl = arg;
3508 register tree origin = decl_ultimate_origin (decl);
3510 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3511 sibling_attribute ();
3512 if (origin != NULL)
3513 abstract_origin_attribute (origin);
3514 else
3515 name_and_src_coords_attributes (decl);
3516 if (DECL_ABSTRACT (decl))
3517 equate_decl_number_to_die_number (decl);
3518 else
3520 register rtx insn = DECL_RTL (decl);
3522 if (GET_CODE (insn) == CODE_LABEL)
3524 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3526 /* When optimization is enabled (via -O) some parts of the compiler
3527 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3528 represent source-level labels which were explicitly declared by
3529 the user. This really shouldn't be happening though, so catch
3530 it if it ever does happen. */
3532 if (INSN_DELETED_P (insn))
3533 abort (); /* Should never happen. */
3535 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3536 (unsigned) INSN_UID (insn));
3537 low_pc_attribute (label);
3542 static void
3543 output_lexical_block_die (arg)
3544 register void *arg;
3546 register tree stmt = arg;
3548 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3549 sibling_attribute ();
3550 dienum_push ();
3551 if (! BLOCK_ABSTRACT (stmt))
3553 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3554 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3556 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3557 low_pc_attribute (begin_label);
3558 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3559 high_pc_attribute (end_label);
3563 static void
3564 output_inlined_subroutine_die (arg)
3565 register void *arg;
3567 register tree stmt = arg;
3569 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3570 sibling_attribute ();
3571 dienum_push ();
3572 abstract_origin_attribute (block_ultimate_origin (stmt));
3573 if (! BLOCK_ABSTRACT (stmt))
3575 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3576 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3578 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3579 low_pc_attribute (begin_label);
3580 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3581 high_pc_attribute (end_label);
3585 /* Output a DIE to represent a declared data object (either file-scope
3586 or block-local) which has "internal linkage" (according to ANSI-C). */
3588 static void
3589 output_local_variable_die (arg)
3590 register void *arg;
3592 register tree decl = arg;
3593 register tree origin = decl_ultimate_origin (decl);
3595 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3596 sibling_attribute ();
3597 if (origin != NULL)
3598 abstract_origin_attribute (origin);
3599 else
3601 name_and_src_coords_attributes (decl);
3602 member_attribute (DECL_CONTEXT (decl));
3603 type_attribute (TREE_TYPE (decl),
3604 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3606 if (DECL_ABSTRACT (decl))
3607 equate_decl_number_to_die_number (decl);
3608 else
3609 location_or_const_value_attribute (decl);
3612 static void
3613 output_member_die (arg)
3614 register void *arg;
3616 register tree decl = arg;
3618 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3619 sibling_attribute ();
3620 name_and_src_coords_attributes (decl);
3621 member_attribute (DECL_CONTEXT (decl));
3622 type_attribute (member_declared_type (decl),
3623 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3624 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3626 byte_size_attribute (decl);
3627 bit_size_attribute (decl);
3628 bit_offset_attribute (decl);
3630 data_member_location_attribute (decl);
3633 #if 0
3634 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3635 modified types instead.
3637 We keep this code here just in case these types of DIEs may be
3638 needed to represent certain things in other languages (e.g. Pascal)
3639 someday. */
3641 static void
3642 output_pointer_type_die (arg)
3643 register void *arg;
3645 register tree type = arg;
3647 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3648 sibling_attribute ();
3649 equate_type_number_to_die_number (type);
3650 member_attribute (TYPE_CONTEXT (type));
3651 type_attribute (TREE_TYPE (type), 0, 0);
3654 static void
3655 output_reference_type_die (arg)
3656 register void *arg;
3658 register tree type = arg;
3660 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3661 sibling_attribute ();
3662 equate_type_number_to_die_number (type);
3663 member_attribute (TYPE_CONTEXT (type));
3664 type_attribute (TREE_TYPE (type), 0, 0);
3666 #endif
3668 static void
3669 output_ptr_to_mbr_type_die (arg)
3670 register void *arg;
3672 register tree type = arg;
3674 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3675 sibling_attribute ();
3676 equate_type_number_to_die_number (type);
3677 member_attribute (TYPE_CONTEXT (type));
3678 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3679 type_attribute (TREE_TYPE (type), 0, 0);
3682 static void
3683 output_compile_unit_die (arg)
3684 register void *arg;
3686 register char *main_input_filename = arg;
3688 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3689 sibling_attribute ();
3690 dienum_push ();
3691 name_attribute (main_input_filename);
3694 char producer[250];
3696 sprintf (producer, "%s %s", language_string, version_string);
3697 producer_attribute (producer);
3700 if (strcmp (language_string, "GNU C++") == 0)
3701 language_attribute (LANG_C_PLUS_PLUS);
3702 else if (strcmp (language_string, "GNU Ada") == 0)
3703 language_attribute (LANG_ADA83);
3704 else if (strcmp (language_string, "GNU F77") == 0)
3705 language_attribute (LANG_FORTRAN77);
3706 else if (strcmp (language_string, "GNU Pascal") == 0)
3707 language_attribute (LANG_PASCAL83);
3708 else if (flag_traditional)
3709 language_attribute (LANG_C);
3710 else
3711 language_attribute (LANG_C89);
3712 low_pc_attribute (TEXT_BEGIN_LABEL);
3713 high_pc_attribute (TEXT_END_LABEL);
3714 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3715 stmt_list_attribute (LINE_BEGIN_LABEL);
3716 last_filename = xstrdup (main_input_filename);
3719 char *wd = getpwd ();
3720 if (wd)
3721 comp_dir_attribute (wd);
3724 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3726 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3727 src_info_attribute (SRCINFO_BEGIN_LABEL);
3728 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3729 mac_info_attribute (MACINFO_BEGIN_LABEL);
3733 static void
3734 output_string_type_die (arg)
3735 register void *arg;
3737 register tree type = arg;
3739 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3740 sibling_attribute ();
3741 equate_type_number_to_die_number (type);
3742 member_attribute (TYPE_CONTEXT (type));
3743 /* this is a fixed length string */
3744 byte_size_attribute (type);
3747 static void
3748 output_inheritance_die (arg)
3749 register void *arg;
3751 register tree binfo = arg;
3753 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3754 sibling_attribute ();
3755 type_attribute (BINFO_TYPE (binfo), 0, 0);
3756 data_member_location_attribute (binfo);
3757 if (TREE_VIA_VIRTUAL (binfo))
3759 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3760 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3762 if (TREE_VIA_PUBLIC (binfo))
3764 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3765 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3767 else if (TREE_VIA_PROTECTED (binfo))
3769 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3770 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3774 static void
3775 output_structure_type_die (arg)
3776 register void *arg;
3778 register tree type = arg;
3780 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3781 sibling_attribute ();
3782 equate_type_number_to_die_number (type);
3783 name_attribute (type_tag (type));
3784 member_attribute (TYPE_CONTEXT (type));
3786 /* If this type has been completed, then give it a byte_size attribute
3787 and prepare to give a list of members. Otherwise, don't do either of
3788 these things. In the latter case, we will not be generating a list
3789 of members (since we don't have any idea what they might be for an
3790 incomplete type). */
3792 if (TYPE_SIZE (type))
3794 dienum_push ();
3795 byte_size_attribute (type);
3799 /* Output a DIE to represent a declared function (either file-scope
3800 or block-local) which has "internal linkage" (according to ANSI-C). */
3802 static void
3803 output_local_subroutine_die (arg)
3804 register void *arg;
3806 register tree decl = arg;
3807 register tree origin = decl_ultimate_origin (decl);
3809 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3810 sibling_attribute ();
3811 dienum_push ();
3812 if (origin != NULL)
3813 abstract_origin_attribute (origin);
3814 else
3816 register tree type = TREE_TYPE (decl);
3818 name_and_src_coords_attributes (decl);
3819 inline_attribute (decl);
3820 prototyped_attribute (type);
3821 member_attribute (DECL_CONTEXT (decl));
3822 type_attribute (TREE_TYPE (type), 0, 0);
3823 pure_or_virtual_attribute (decl);
3825 if (DECL_ABSTRACT (decl))
3826 equate_decl_number_to_die_number (decl);
3827 else
3829 /* Avoid getting screwed up in cases where a function was declared
3830 static but where no definition was ever given for it. */
3832 if (TREE_ASM_WRITTEN (decl))
3834 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3835 low_pc_attribute (function_start_label (decl));
3836 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3837 high_pc_attribute (label);
3838 if (use_gnu_debug_info_extensions)
3840 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3841 body_begin_attribute (label);
3842 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3843 body_end_attribute (label);
3849 static void
3850 output_subroutine_type_die (arg)
3851 register void *arg;
3853 register tree type = arg;
3854 register tree return_type = TREE_TYPE (type);
3856 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3857 sibling_attribute ();
3858 dienum_push ();
3859 equate_type_number_to_die_number (type);
3860 prototyped_attribute (type);
3861 member_attribute (TYPE_CONTEXT (type));
3862 type_attribute (return_type, 0, 0);
3865 static void
3866 output_typedef_die (arg)
3867 register void *arg;
3869 register tree decl = arg;
3870 register tree origin = decl_ultimate_origin (decl);
3872 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3873 sibling_attribute ();
3874 if (origin != NULL)
3875 abstract_origin_attribute (origin);
3876 else
3878 name_and_src_coords_attributes (decl);
3879 member_attribute (DECL_CONTEXT (decl));
3880 type_attribute (TREE_TYPE (decl),
3881 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3883 if (DECL_ABSTRACT (decl))
3884 equate_decl_number_to_die_number (decl);
3887 static void
3888 output_union_type_die (arg)
3889 register void *arg;
3891 register tree type = arg;
3893 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3894 sibling_attribute ();
3895 equate_type_number_to_die_number (type);
3896 name_attribute (type_tag (type));
3897 member_attribute (TYPE_CONTEXT (type));
3899 /* If this type has been completed, then give it a byte_size attribute
3900 and prepare to give a list of members. Otherwise, don't do either of
3901 these things. In the latter case, we will not be generating a list
3902 of members (since we don't have any idea what they might be for an
3903 incomplete type). */
3905 if (TYPE_SIZE (type))
3907 dienum_push ();
3908 byte_size_attribute (type);
3912 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3913 at the end of an (ANSI prototyped) formal parameters list. */
3915 static void
3916 output_unspecified_parameters_die (arg)
3917 register void *arg;
3919 register tree decl_or_type = arg;
3921 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3922 sibling_attribute ();
3924 /* This kludge is here only for the sake of being compatible with what
3925 the USL CI5 C compiler does. The specification of Dwarf Version 1
3926 doesn't say that TAG_unspecified_parameters DIEs should contain any
3927 attributes other than the AT_sibling attribute, but they are certainly
3928 allowed to contain additional attributes, and the CI5 compiler
3929 generates AT_name, AT_fund_type, and AT_location attributes within
3930 TAG_unspecified_parameters DIEs which appear in the child lists for
3931 DIEs representing function definitions, so we do likewise here. */
3933 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3935 name_attribute ("...");
3936 fund_type_attribute (FT_pointer);
3937 /* location_attribute (?); */
3941 static void
3942 output_padded_null_die (arg)
3943 register void *arg ATTRIBUTE_UNUSED;
3945 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3948 /*************************** end of DIEs *********************************/
3950 /* Generate some type of DIE. This routine generates the generic outer
3951 wrapper stuff which goes around all types of DIE's (regardless of their
3952 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3953 DIE-length word, followed by the guts of the DIE itself. After the guts
3954 of the DIE, there must always be a terminator label for the DIE. */
3956 static void
3957 output_die (die_specific_output_function, param)
3958 register void (*die_specific_output_function) PROTO ((void *));
3959 register void *param;
3961 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3962 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3964 current_dienum = NEXT_DIE_NUM;
3965 NEXT_DIE_NUM = next_unused_dienum;
3967 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3968 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3970 /* Write a label which will act as the name for the start of this DIE. */
3972 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3974 /* Write the DIE-length word. */
3976 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3978 /* Fill in the guts of the DIE. */
3980 next_unused_dienum++;
3981 die_specific_output_function (param);
3983 /* Write a label which will act as the name for the end of this DIE. */
3985 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3988 static void
3989 end_sibling_chain ()
3991 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3993 current_dienum = NEXT_DIE_NUM;
3994 NEXT_DIE_NUM = next_unused_dienum;
3996 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3998 /* Write a label which will act as the name for the start of this DIE. */
4000 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4002 /* Write the DIE-length word. */
4004 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4006 dienum_pop ();
4009 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4010 TAG_unspecified_parameters DIE) to represent the types of the formal
4011 parameters as specified in some function type specification (except
4012 for those which appear as part of a function *definition*).
4014 Note that we must be careful here to output all of the parameter
4015 DIEs *before* we output any DIEs needed to represent the types of
4016 the formal parameters. This keeps svr4 SDB happy because it
4017 (incorrectly) thinks that the first non-parameter DIE it sees ends
4018 the formal parameter list. */
4020 static void
4021 output_formal_types (function_or_method_type)
4022 register tree function_or_method_type;
4024 register tree link;
4025 register tree formal_type = NULL;
4026 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4028 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4029 get bogus recursion when outputting tagged types local to a
4030 function declaration. */
4031 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4032 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4034 /* In the case where we are generating a formal types list for a C++
4035 non-static member function type, skip over the first thing on the
4036 TYPE_ARG_TYPES list because it only represents the type of the
4037 hidden `this pointer'. The debugger should be able to figure
4038 out (without being explicitly told) that this non-static member
4039 function type takes a `this pointer' and should be able to figure
4040 what the type of that hidden parameter is from the AT_member
4041 attribute of the parent TAG_subroutine_type DIE. */
4043 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4044 first_parm_type = TREE_CHAIN (first_parm_type);
4046 /* Make our first pass over the list of formal parameter types and output
4047 a TAG_formal_parameter DIE for each one. */
4049 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4051 formal_type = TREE_VALUE (link);
4052 if (formal_type == void_type_node)
4053 break;
4055 /* Output a (nameless) DIE to represent the formal parameter itself. */
4057 output_die (output_formal_parameter_die, formal_type);
4060 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4061 DIE to the end of the parameter list. */
4063 if (formal_type != void_type_node)
4064 output_die (output_unspecified_parameters_die, function_or_method_type);
4066 /* Make our second (and final) pass over the list of formal parameter types
4067 and output DIEs to represent those types (as necessary). */
4069 for (link = TYPE_ARG_TYPES (function_or_method_type);
4070 link;
4071 link = TREE_CHAIN (link))
4073 formal_type = TREE_VALUE (link);
4074 if (formal_type == void_type_node)
4075 break;
4077 output_type (formal_type, function_or_method_type);
4080 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4083 /* Remember a type in the pending_types_list. */
4085 static void
4086 pend_type (type)
4087 register tree type;
4089 if (pending_types == pending_types_allocated)
4091 pending_types_allocated += PENDING_TYPES_INCREMENT;
4092 pending_types_list
4093 = (tree *) xrealloc (pending_types_list,
4094 sizeof (tree) * pending_types_allocated);
4096 pending_types_list[pending_types++] = type;
4098 /* Mark the pending type as having been output already (even though
4099 it hasn't been). This prevents the type from being added to the
4100 pending_types_list more than once. */
4102 TREE_ASM_WRITTEN (type) = 1;
4105 /* Return non-zero if it is legitimate to output DIEs to represent a
4106 given type while we are generating the list of child DIEs for some
4107 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4109 See the comments within the function for a description of when it is
4110 considered legitimate to output DIEs for various kinds of types.
4112 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4113 or it may point to a BLOCK node (for types local to a block), or to a
4114 FUNCTION_DECL node (for types local to the heading of some function
4115 definition), or to a FUNCTION_TYPE node (for types local to the
4116 prototyped parameter list of a function type specification), or to a
4117 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4118 (in the case of C++ nested types).
4120 The `scope' parameter should likewise be NULL or should point to a
4121 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4122 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4124 This function is used only for deciding when to "pend" and when to
4125 "un-pend" types to/from the pending_types_list.
4127 Note that we sometimes make use of this "type pending" feature in a
4128 rather twisted way to temporarily delay the production of DIEs for the
4129 types of formal parameters. (We do this just to make svr4 SDB happy.)
4130 It order to delay the production of DIEs representing types of formal
4131 parameters, callers of this function supply `fake_containing_scope' as
4132 the `scope' parameter to this function. Given that fake_containing_scope
4133 is a tagged type which is *not* the containing scope for *any* other type,
4134 the desired effect is achieved, i.e. output of DIEs representing types
4135 is temporarily suspended, and any type DIEs which would have otherwise
4136 been output are instead placed onto the pending_types_list. Later on,
4137 we force these (temporarily pended) types to be output simply by calling
4138 `output_pending_types_for_scope' with an actual argument equal to the
4139 true scope of the types we temporarily pended. */
4141 static inline int
4142 type_ok_for_scope (type, scope)
4143 register tree type;
4144 register tree scope;
4146 /* Tagged types (i.e. struct, union, and enum types) must always be
4147 output only in the scopes where they actually belong (or else the
4148 scoping of their own tag names and the scoping of their member
4149 names will be incorrect). Non-tagged-types on the other hand can
4150 generally be output anywhere, except that svr4 SDB really doesn't
4151 want to see them nested within struct or union types, so here we
4152 say it is always OK to immediately output any such a (non-tagged)
4153 type, so long as we are not within such a context. Note that the
4154 only kinds of non-tagged types which we will be dealing with here
4155 (for C and C++ anyway) will be array types and function types. */
4157 return is_tagged_type (type)
4158 ? (TYPE_CONTEXT (type) == scope
4159 /* Ignore namespaces for the moment. */
4160 || (scope == NULL_TREE
4161 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4162 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4163 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4164 : (scope == NULL_TREE || ! is_tagged_type (scope));
4167 /* Output any pending types (from the pending_types list) which we can output
4168 now (taking into account the scope that we are working on now).
4170 For each type output, remove the given type from the pending_types_list
4171 *before* we try to output it.
4173 Note that we have to process the list in beginning-to-end order,
4174 because the call made here to output_type may cause yet more types
4175 to be added to the end of the list, and we may have to output some
4176 of them too. */
4178 static void
4179 output_pending_types_for_scope (containing_scope)
4180 register tree containing_scope;
4182 register unsigned i;
4184 for (i = 0; i < pending_types; )
4186 register tree type = pending_types_list[i];
4188 if (type_ok_for_scope (type, containing_scope))
4190 register tree *mover;
4191 register tree *limit;
4193 pending_types--;
4194 limit = &pending_types_list[pending_types];
4195 for (mover = &pending_types_list[i]; mover < limit; mover++)
4196 *mover = *(mover+1);
4198 /* Un-mark the type as having been output already (because it
4199 hasn't been, really). Then call output_type to generate a
4200 Dwarf representation of it. */
4202 TREE_ASM_WRITTEN (type) = 0;
4203 output_type (type, containing_scope);
4205 /* Don't increment the loop counter in this case because we
4206 have shifted all of the subsequent pending types down one
4207 element in the pending_types_list array. */
4209 else
4210 i++;
4214 static void
4215 output_type (type, containing_scope)
4216 register tree type;
4217 register tree containing_scope;
4219 if (type == 0 || type == error_mark_node)
4220 return;
4222 /* We are going to output a DIE to represent the unqualified version of
4223 this type (i.e. without any const or volatile qualifiers) so get
4224 the main variant (i.e. the unqualified version) of this type now. */
4226 type = type_main_variant (type);
4228 if (TREE_ASM_WRITTEN (type))
4230 if (finalizing && AGGREGATE_TYPE_P (type))
4232 register tree member;
4234 /* Some of our nested types might not have been defined when we
4235 were written out before; force them out now. */
4237 for (member = TYPE_FIELDS (type); member;
4238 member = TREE_CHAIN (member))
4239 if (TREE_CODE (member) == TYPE_DECL
4240 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4241 output_type (TREE_TYPE (member), containing_scope);
4243 return;
4246 /* If this is a nested type whose containing class hasn't been
4247 written out yet, writing it out will cover this one, too. */
4249 if (TYPE_CONTEXT (type)
4250 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4251 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4253 output_type (TYPE_CONTEXT (type), containing_scope);
4254 return;
4257 /* Don't generate any DIEs for this type now unless it is OK to do so
4258 (based upon what `type_ok_for_scope' tells us). */
4260 if (! type_ok_for_scope (type, containing_scope))
4262 pend_type (type);
4263 return;
4266 switch (TREE_CODE (type))
4268 case ERROR_MARK:
4269 break;
4271 case POINTER_TYPE:
4272 case REFERENCE_TYPE:
4273 /* Prevent infinite recursion in cases where this is a recursive
4274 type. Recursive types are possible in Ada. */
4275 TREE_ASM_WRITTEN (type) = 1;
4276 /* For these types, all that is required is that we output a DIE
4277 (or a set of DIEs) to represent the "basis" type. */
4278 output_type (TREE_TYPE (type), containing_scope);
4279 break;
4281 case OFFSET_TYPE:
4282 /* This code is used for C++ pointer-to-data-member types. */
4283 /* Output a description of the relevant class type. */
4284 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4285 /* Output a description of the type of the object pointed to. */
4286 output_type (TREE_TYPE (type), containing_scope);
4287 /* Now output a DIE to represent this pointer-to-data-member type
4288 itself. */
4289 output_die (output_ptr_to_mbr_type_die, type);
4290 break;
4292 case SET_TYPE:
4293 output_type (TYPE_DOMAIN (type), containing_scope);
4294 output_die (output_set_type_die, type);
4295 break;
4297 case FILE_TYPE:
4298 output_type (TREE_TYPE (type), containing_scope);
4299 abort (); /* No way to represent these in Dwarf yet! */
4300 break;
4302 case FUNCTION_TYPE:
4303 /* Force out return type (in case it wasn't forced out already). */
4304 output_type (TREE_TYPE (type), containing_scope);
4305 output_die (output_subroutine_type_die, type);
4306 output_formal_types (type);
4307 end_sibling_chain ();
4308 break;
4310 case METHOD_TYPE:
4311 /* Force out return type (in case it wasn't forced out already). */
4312 output_type (TREE_TYPE (type), containing_scope);
4313 output_die (output_subroutine_type_die, type);
4314 output_formal_types (type);
4315 end_sibling_chain ();
4316 break;
4318 case ARRAY_TYPE:
4319 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4321 output_type (TREE_TYPE (type), containing_scope);
4322 output_die (output_string_type_die, type);
4324 else
4326 register tree element_type;
4328 element_type = TREE_TYPE (type);
4329 while (TREE_CODE (element_type) == ARRAY_TYPE)
4330 element_type = TREE_TYPE (element_type);
4332 output_type (element_type, containing_scope);
4333 output_die (output_array_type_die, type);
4335 break;
4337 case ENUMERAL_TYPE:
4338 case RECORD_TYPE:
4339 case UNION_TYPE:
4340 case QUAL_UNION_TYPE:
4342 /* For a non-file-scope tagged type, we can always go ahead and
4343 output a Dwarf description of this type right now, even if
4344 the type in question is still incomplete, because if this
4345 local type *was* ever completed anywhere within its scope,
4346 that complete definition would already have been attached to
4347 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4348 node by the time we reach this point. That's true because of the
4349 way the front-end does its processing of file-scope declarations (of
4350 functions and class types) within which other types might be
4351 nested. The C and C++ front-ends always gobble up such "local
4352 scope" things en-mass before they try to output *any* debugging
4353 information for any of the stuff contained inside them and thus,
4354 we get the benefit here of what is (in effect) a pre-resolution
4355 of forward references to tagged types in local scopes.
4357 Note however that for file-scope tagged types we cannot assume
4358 that such pre-resolution of forward references has taken place.
4359 A given file-scope tagged type may appear to be incomplete when
4360 we reach this point, but it may yet be given a full definition
4361 (at file-scope) later on during compilation. In order to avoid
4362 generating a premature (and possibly incorrect) set of Dwarf
4363 DIEs for such (as yet incomplete) file-scope tagged types, we
4364 generate nothing at all for as-yet incomplete file-scope tagged
4365 types here unless we are making our special "finalization" pass
4366 for file-scope things at the very end of compilation. At that
4367 time, we will certainly know as much about each file-scope tagged
4368 type as we are ever going to know, so at that point in time, we
4369 can safely generate correct Dwarf descriptions for these file-
4370 scope tagged types. */
4372 if (TYPE_SIZE (type) == 0
4373 && (TYPE_CONTEXT (type) == NULL
4374 || (TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4375 && TREE_CODE (TYPE_CONTEXT (type)) != FUNCTION_TYPE
4376 && TREE_CODE (TYPE_CONTEXT (type)) != METHOD_TYPE))
4377 && !finalizing)
4378 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4380 /* Prevent infinite recursion in cases where the type of some
4381 member of this type is expressed in terms of this type itself. */
4383 TREE_ASM_WRITTEN (type) = 1;
4385 /* Output a DIE to represent the tagged type itself. */
4387 switch (TREE_CODE (type))
4389 case ENUMERAL_TYPE:
4390 output_die (output_enumeration_type_die, type);
4391 return; /* a special case -- nothing left to do so just return */
4393 case RECORD_TYPE:
4394 output_die (output_structure_type_die, type);
4395 break;
4397 case UNION_TYPE:
4398 case QUAL_UNION_TYPE:
4399 output_die (output_union_type_die, type);
4400 break;
4402 default:
4403 abort (); /* Should never happen. */
4406 /* If this is not an incomplete type, output descriptions of
4407 each of its members.
4409 Note that as we output the DIEs necessary to represent the
4410 members of this record or union type, we will also be trying
4411 to output DIEs to represent the *types* of those members.
4412 However the `output_type' function (above) will specifically
4413 avoid generating type DIEs for member types *within* the list
4414 of member DIEs for this (containing) type execpt for those
4415 types (of members) which are explicitly marked as also being
4416 members of this (containing) type themselves. The g++ front-
4417 end can force any given type to be treated as a member of some
4418 other (containing) type by setting the TYPE_CONTEXT of the
4419 given (member) type to point to the TREE node representing the
4420 appropriate (containing) type.
4423 if (TYPE_SIZE (type))
4425 /* First output info about the base classes. */
4426 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4428 register tree bases = TYPE_BINFO_BASETYPES (type);
4429 register int n_bases = TREE_VEC_LENGTH (bases);
4430 register int i;
4432 for (i = 0; i < n_bases; i++)
4433 output_die (output_inheritance_die, TREE_VEC_ELT (bases, i));
4436 ++in_class;
4439 register tree normal_member;
4441 /* Now output info about the data members and type members. */
4443 for (normal_member = TYPE_FIELDS (type);
4444 normal_member;
4445 normal_member = TREE_CHAIN (normal_member))
4446 output_decl (normal_member, type);
4450 register tree func_member;
4452 /* Now output info about the function members (if any). */
4454 for (func_member = TYPE_METHODS (type);
4455 func_member;
4456 func_member = TREE_CHAIN (func_member))
4457 output_decl (func_member, type);
4460 --in_class;
4462 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4463 scopes (at least in C++) so we must now output any nested
4464 pending types which are local just to this type. */
4466 output_pending_types_for_scope (type);
4468 end_sibling_chain (); /* Terminate member chain. */
4471 break;
4473 case VOID_TYPE:
4474 case INTEGER_TYPE:
4475 case REAL_TYPE:
4476 case COMPLEX_TYPE:
4477 case BOOLEAN_TYPE:
4478 case CHAR_TYPE:
4479 break; /* No DIEs needed for fundamental types. */
4481 case LANG_TYPE: /* No Dwarf representation currently defined. */
4482 break;
4484 default:
4485 abort ();
4488 TREE_ASM_WRITTEN (type) = 1;
4491 static void
4492 output_tagged_type_instantiation (type)
4493 register tree type;
4495 if (type == 0 || type == error_mark_node)
4496 return;
4498 /* We are going to output a DIE to represent the unqualified version of
4499 this type (i.e. without any const or volatile qualifiers) so make
4500 sure that we have the main variant (i.e. the unqualified version) of
4501 this type now. */
4503 if (type != type_main_variant (type))
4504 abort ();
4506 if (!TREE_ASM_WRITTEN (type))
4507 abort ();
4509 switch (TREE_CODE (type))
4511 case ERROR_MARK:
4512 break;
4514 case ENUMERAL_TYPE:
4515 output_die (output_inlined_enumeration_type_die, type);
4516 break;
4518 case RECORD_TYPE:
4519 output_die (output_inlined_structure_type_die, type);
4520 break;
4522 case UNION_TYPE:
4523 case QUAL_UNION_TYPE:
4524 output_die (output_inlined_union_type_die, type);
4525 break;
4527 default:
4528 abort (); /* Should never happen. */
4532 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4533 the things which are local to the given block. */
4535 static void
4536 output_block (stmt, depth)
4537 register tree stmt;
4538 int depth;
4540 register int must_output_die = 0;
4541 register tree origin;
4542 register enum tree_code origin_code;
4544 /* Ignore blocks never really used to make RTL. */
4546 if (! stmt || ! TREE_USED (stmt))
4547 return;
4549 /* Determine the "ultimate origin" of this block. This block may be an
4550 inlined instance of an inlined instance of inline function, so we
4551 have to trace all of the way back through the origin chain to find
4552 out what sort of node actually served as the original seed for the
4553 creation of the current block. */
4555 origin = block_ultimate_origin (stmt);
4556 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4558 /* Determine if we need to output any Dwarf DIEs at all to represent this
4559 block. */
4561 if (origin_code == FUNCTION_DECL)
4562 /* The outer scopes for inlinings *must* always be represented. We
4563 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4564 must_output_die = 1;
4565 else
4567 /* In the case where the current block represents an inlining of the
4568 "body block" of an inline function, we must *NOT* output any DIE
4569 for this block because we have already output a DIE to represent
4570 the whole inlined function scope and the "body block" of any
4571 function doesn't really represent a different scope according to
4572 ANSI C rules. So we check here to make sure that this block does
4573 not represent a "body block inlining" before trying to set the
4574 `must_output_die' flag. */
4576 if (! is_body_block (origin ? origin : stmt))
4578 /* Determine if this block directly contains any "significant"
4579 local declarations which we will need to output DIEs for. */
4581 if (debug_info_level > DINFO_LEVEL_TERSE)
4582 /* We are not in terse mode so *any* local declaration counts
4583 as being a "significant" one. */
4584 must_output_die = (BLOCK_VARS (stmt) != NULL);
4585 else
4587 register tree decl;
4589 /* We are in terse mode, so only local (nested) function
4590 definitions count as "significant" local declarations. */
4592 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4593 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4595 must_output_die = 1;
4596 break;
4602 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4603 DIE for any block which contains no significant local declarations
4604 at all. Rather, in such cases we just call `output_decls_for_scope'
4605 so that any needed Dwarf info for any sub-blocks will get properly
4606 generated. Note that in terse mode, our definition of what constitutes
4607 a "significant" local declaration gets restricted to include only
4608 inlined function instances and local (nested) function definitions. */
4610 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4611 /* We don't care about an abstract inlined subroutine. */;
4612 else if (must_output_die)
4614 output_die ((origin_code == FUNCTION_DECL)
4615 ? output_inlined_subroutine_die
4616 : output_lexical_block_die,
4617 stmt);
4618 output_decls_for_scope (stmt, depth);
4619 end_sibling_chain ();
4621 else
4622 output_decls_for_scope (stmt, depth);
4625 /* Output all of the decls declared within a given scope (also called
4626 a `binding contour') and (recursively) all of it's sub-blocks. */
4628 static void
4629 output_decls_for_scope (stmt, depth)
4630 register tree stmt;
4631 int depth;
4633 /* Ignore blocks never really used to make RTL. */
4635 if (! stmt || ! TREE_USED (stmt))
4636 return;
4638 if (! BLOCK_ABSTRACT (stmt) && depth > 0)
4639 next_block_number++;
4641 /* Output the DIEs to represent all of the data objects, functions,
4642 typedefs, and tagged types declared directly within this block
4643 but not within any nested sub-blocks. */
4646 register tree decl;
4648 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4649 output_decl (decl, stmt);
4652 output_pending_types_for_scope (stmt);
4654 /* Output the DIEs to represent all sub-blocks (and the items declared
4655 therein) of this block. */
4658 register tree subblocks;
4660 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4661 subblocks;
4662 subblocks = BLOCK_CHAIN (subblocks))
4663 output_block (subblocks, depth + 1);
4667 /* Is this a typedef we can avoid emitting? */
4669 inline static int
4670 is_redundant_typedef (decl)
4671 register tree decl;
4673 if (TYPE_DECL_IS_STUB (decl))
4674 return 1;
4675 if (DECL_ARTIFICIAL (decl)
4676 && DECL_CONTEXT (decl)
4677 && is_tagged_type (DECL_CONTEXT (decl))
4678 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4679 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4680 /* Also ignore the artificial member typedef for the class name. */
4681 return 1;
4682 return 0;
4685 /* Output Dwarf .debug information for a decl described by DECL. */
4687 static void
4688 output_decl (decl, containing_scope)
4689 register tree decl;
4690 register tree containing_scope;
4692 /* Make a note of the decl node we are going to be working on. We may
4693 need to give the user the source coordinates of where it appeared in
4694 case we notice (later on) that something about it looks screwy. */
4696 dwarf_last_decl = decl;
4698 if (TREE_CODE (decl) == ERROR_MARK)
4699 return;
4701 /* If a structure is declared within an initialization, e.g. as the
4702 operand of a sizeof, then it will not have a name. We don't want
4703 to output a DIE for it, as the tree nodes are in the temporary obstack */
4705 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4706 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4707 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4708 || (TYPE_FIELDS (TREE_TYPE (decl))
4709 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4710 return;
4712 /* If this ..._DECL node is marked to be ignored, then ignore it.
4713 But don't ignore a function definition, since that would screw
4714 up our count of blocks, and that it turn will completely screw up the
4715 labels we will reference in subsequent AT_low_pc and AT_high_pc
4716 attributes (for subsequent blocks). */
4718 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4719 return;
4721 switch (TREE_CODE (decl))
4723 case CONST_DECL:
4724 /* The individual enumerators of an enum type get output when we
4725 output the Dwarf representation of the relevant enum type itself. */
4726 break;
4728 case FUNCTION_DECL:
4729 /* If we are in terse mode, don't output any DIEs to represent
4730 mere function declarations. Also, if we are conforming
4731 to the DWARF version 1 specification, don't output DIEs for
4732 mere function declarations. */
4734 if (DECL_INITIAL (decl) == NULL_TREE)
4735 #if (DWARF_VERSION > 1)
4736 if (debug_info_level <= DINFO_LEVEL_TERSE)
4737 #endif
4738 break;
4740 /* Before we describe the FUNCTION_DECL itself, make sure that we
4741 have described its return type. */
4743 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4746 /* And its containing type. */
4747 register tree origin = decl_class_context (decl);
4748 if (origin)
4749 output_type (origin, containing_scope);
4752 /* If the following DIE will represent a function definition for a
4753 function with "extern" linkage, output a special "pubnames" DIE
4754 label just ahead of the actual DIE. A reference to this label
4755 was already generated in the .debug_pubnames section sub-entry
4756 for this function definition. */
4758 if (TREE_PUBLIC (decl))
4760 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4762 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4763 ASM_OUTPUT_LABEL (asm_out_file, label);
4766 /* Now output a DIE to represent the function itself. */
4768 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4769 ? output_global_subroutine_die
4770 : output_local_subroutine_die,
4771 decl);
4773 /* Now output descriptions of the arguments for this function.
4774 This gets (unnecessarily?) complex because of the fact that
4775 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4776 cases where there was a trailing `...' at the end of the formal
4777 parameter list. In order to find out if there was a trailing
4778 ellipsis or not, we must instead look at the type associated
4779 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4780 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4781 ends with a void_type_node then there should *not* be an ellipsis
4782 at the end. */
4784 /* In the case where we are describing a mere function declaration, all
4785 we need to do here (and all we *can* do here) is to describe
4786 the *types* of its formal parameters. */
4788 if (decl != current_function_decl || in_class)
4789 output_formal_types (TREE_TYPE (decl));
4790 else
4792 /* Generate DIEs to represent all known formal parameters */
4794 register tree arg_decls = DECL_ARGUMENTS (decl);
4795 register tree parm;
4797 /* WARNING! Kludge zone ahead! Here we have a special
4798 hack for svr4 SDB compatibility. Instead of passing the
4799 current FUNCTION_DECL node as the second parameter (i.e.
4800 the `containing_scope' parameter) to `output_decl' (as
4801 we ought to) we instead pass a pointer to our own private
4802 fake_containing_scope node. That node is a RECORD_TYPE
4803 node which NO OTHER TYPE may ever actually be a member of.
4805 This pointer will ultimately get passed into `output_type'
4806 as its `containing_scope' parameter. `Output_type' will
4807 then perform its part in the hack... i.e. it will pend
4808 the type of the formal parameter onto the pending_types
4809 list. Later on, when we are done generating the whole
4810 sequence of formal parameter DIEs for this function
4811 definition, we will un-pend all previously pended types
4812 of formal parameters for this function definition.
4814 This whole kludge prevents any type DIEs from being
4815 mixed in with the formal parameter DIEs. That's good
4816 because svr4 SDB believes that the list of formal
4817 parameter DIEs for a function ends wherever the first
4818 non-formal-parameter DIE appears. Thus, we have to
4819 keep the formal parameter DIEs segregated. They must
4820 all appear (consecutively) at the start of the list of
4821 children for the DIE representing the function definition.
4822 Then (and only then) may we output any additional DIEs
4823 needed to represent the types of these formal parameters.
4827 When generating DIEs, generate the unspecified_parameters
4828 DIE instead if we come across the arg "__builtin_va_alist"
4831 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4832 if (TREE_CODE (parm) == PARM_DECL)
4834 if (DECL_NAME(parm) &&
4835 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4836 "__builtin_va_alist") )
4837 output_die (output_unspecified_parameters_die, decl);
4838 else
4839 output_decl (parm, fake_containing_scope);
4843 Now that we have finished generating all of the DIEs to
4844 represent the formal parameters themselves, force out
4845 any DIEs needed to represent their types. We do this
4846 simply by un-pending all previously pended types which
4847 can legitimately go into the chain of children DIEs for
4848 the current FUNCTION_DECL.
4851 output_pending_types_for_scope (decl);
4854 Decide whether we need a unspecified_parameters DIE at the end.
4855 There are 2 more cases to do this for:
4856 1) the ansi ... declaration - this is detectable when the end
4857 of the arg list is not a void_type_node
4858 2) an unprototyped function declaration (not a definition). This
4859 just means that we have no info about the parameters at all.
4863 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4865 if (fn_arg_types)
4867 /* this is the prototyped case, check for ... */
4868 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4869 output_die (output_unspecified_parameters_die, decl);
4871 else
4873 /* this is unprototyped, check for undefined (just declaration) */
4874 if (!DECL_INITIAL (decl))
4875 output_die (output_unspecified_parameters_die, decl);
4879 /* Output Dwarf info for all of the stuff within the body of the
4880 function (if it has one - it may be just a declaration). */
4883 register tree outer_scope = DECL_INITIAL (decl);
4885 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4887 /* Note that here, `outer_scope' is a pointer to the outermost
4888 BLOCK node created to represent a function.
4889 This outermost BLOCK actually represents the outermost
4890 binding contour for the function, i.e. the contour in which
4891 the function's formal parameters and labels get declared.
4893 Curiously, it appears that the front end doesn't actually
4894 put the PARM_DECL nodes for the current function onto the
4895 BLOCK_VARS list for this outer scope. (They are strung
4896 off of the DECL_ARGUMENTS list for the function instead.)
4897 The BLOCK_VARS list for the `outer_scope' does provide us
4898 with a list of the LABEL_DECL nodes for the function however,
4899 and we output DWARF info for those here.
4901 Just within the `outer_scope' there will be a BLOCK node
4902 representing the function's outermost pair of curly braces,
4903 and any blocks used for the base and member initializers of
4904 a C++ constructor function. */
4906 output_decls_for_scope (outer_scope, 0);
4908 /* Finally, force out any pending types which are local to the
4909 outermost block of this function definition. These will
4910 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4911 node itself. */
4913 output_pending_types_for_scope (decl);
4918 /* Generate a terminator for the list of stuff `owned' by this
4919 function. */
4921 end_sibling_chain ();
4923 break;
4925 case TYPE_DECL:
4926 /* If we are in terse mode, don't generate any DIEs to represent
4927 any actual typedefs. Note that even when we are in terse mode,
4928 we must still output DIEs to represent those tagged types which
4929 are used (directly or indirectly) in the specification of either
4930 a return type or a formal parameter type of some function. */
4932 if (debug_info_level <= DINFO_LEVEL_TERSE)
4933 if (! TYPE_DECL_IS_STUB (decl)
4934 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4935 return;
4937 /* In the special case of a TYPE_DECL node representing
4938 the declaration of some type tag, if the given TYPE_DECL is
4939 marked as having been instantiated from some other (original)
4940 TYPE_DECL node (e.g. one which was generated within the original
4941 definition of an inline function) we have to generate a special
4942 (abbreviated) TAG_structure_type, TAG_union_type, or
4943 TAG_enumeration-type DIE here. */
4945 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4947 output_tagged_type_instantiation (TREE_TYPE (decl));
4948 return;
4951 output_type (TREE_TYPE (decl), containing_scope);
4953 if (! is_redundant_typedef (decl))
4954 /* Output a DIE to represent the typedef itself. */
4955 output_die (output_typedef_die, decl);
4956 break;
4958 case LABEL_DECL:
4959 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4960 output_die (output_label_die, decl);
4961 break;
4963 case VAR_DECL:
4964 /* If we are conforming to the DWARF version 1 specification, don't
4965 generated any DIEs to represent mere external object declarations. */
4967 #if (DWARF_VERSION <= 1)
4968 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4969 break;
4970 #endif
4972 /* If we are in terse mode, don't generate any DIEs to represent
4973 any variable declarations or definitions. */
4975 if (debug_info_level <= DINFO_LEVEL_TERSE)
4976 break;
4978 /* Output any DIEs that are needed to specify the type of this data
4979 object. */
4981 output_type (TREE_TYPE (decl), containing_scope);
4984 /* And its containing type. */
4985 register tree origin = decl_class_context (decl);
4986 if (origin)
4987 output_type (origin, containing_scope);
4990 /* If the following DIE will represent a data object definition for a
4991 data object with "extern" linkage, output a special "pubnames" DIE
4992 label just ahead of the actual DIE. A reference to this label
4993 was already generated in the .debug_pubnames section sub-entry
4994 for this data object definition. */
4996 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4998 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5000 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5001 ASM_OUTPUT_LABEL (asm_out_file, label);
5004 /* Now output the DIE to represent the data object itself. This gets
5005 complicated because of the possibility that the VAR_DECL really
5006 represents an inlined instance of a formal parameter for an inline
5007 function. */
5010 register void (*func) PROTO((void *));
5011 register tree origin = decl_ultimate_origin (decl);
5013 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5014 func = output_formal_parameter_die;
5015 else
5017 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5018 func = output_global_variable_die;
5019 else
5020 func = output_local_variable_die;
5022 output_die (func, decl);
5024 break;
5026 case FIELD_DECL:
5027 /* Ignore the nameless fields that are used to skip bits. */
5028 if (DECL_NAME (decl) != 0)
5030 output_type (member_declared_type (decl), containing_scope);
5031 output_die (output_member_die, decl);
5033 break;
5035 case PARM_DECL:
5036 /* Force out the type of this formal, if it was not forced out yet.
5037 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5038 It should be able to grok the presence of type DIEs within a list
5039 of TAG_formal_parameter DIEs, but it doesn't. */
5041 output_type (TREE_TYPE (decl), containing_scope);
5042 output_die (output_formal_parameter_die, decl);
5043 break;
5045 default:
5046 abort ();
5050 void
5051 dwarfout_file_scope_decl (decl, set_finalizing)
5052 register tree decl;
5053 register int set_finalizing;
5055 if (TREE_CODE (decl) == ERROR_MARK)
5056 return;
5058 /* If this ..._DECL node is marked to be ignored, then ignore it. We
5059 gotta hope that the node in question doesn't represent a function
5060 definition. If it does, then totally ignoring it is bound to screw
5061 up our count of blocks, and that it turn will completely screw up the
5062 labels we will reference in subsequent AT_low_pc and AT_high_pc
5063 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
5064 don't carry their own sequence numbers with them!) */
5066 if (DECL_IGNORED_P (decl))
5068 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5069 abort ();
5070 return;
5073 switch (TREE_CODE (decl))
5075 case FUNCTION_DECL:
5077 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5078 a builtin function. Explicit programmer-supplied declarations of
5079 these same functions should NOT be ignored however. */
5081 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5082 return;
5084 /* What we would really like to do here is to filter out all mere
5085 file-scope declarations of file-scope functions which are never
5086 referenced later within this translation unit (and keep all of
5087 ones that *are* referenced later on) but we aren't clairvoyant,
5088 so we have no idea which functions will be referenced in the
5089 future (i.e. later on within the current translation unit).
5090 So here we just ignore all file-scope function declarations
5091 which are not also definitions. If and when the debugger needs
5092 to know something about these functions, it wil have to hunt
5093 around and find the DWARF information associated with the
5094 *definition* of the function.
5096 Note that we can't just check `DECL_EXTERNAL' to find out which
5097 FUNCTION_DECL nodes represent definitions and which ones represent
5098 mere declarations. We have to check `DECL_INITIAL' instead. That's
5099 because the C front-end supports some weird semantics for "extern
5100 inline" function definitions. These can get inlined within the
5101 current translation unit (an thus, we need to generate DWARF info
5102 for their abstract instances so that the DWARF info for the
5103 concrete inlined instances can have something to refer to) but
5104 the compiler never generates any out-of-lines instances of such
5105 things (despite the fact that they *are* definitions). The
5106 important point is that the C front-end marks these "extern inline"
5107 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5108 anyway.
5110 Note that the C++ front-end also plays some similar games for inline
5111 function definitions appearing within include files which also
5112 contain `#pragma interface' pragmas. */
5114 if (DECL_INITIAL (decl) == NULL_TREE)
5115 return;
5117 if (TREE_PUBLIC (decl)
5118 && ! DECL_EXTERNAL (decl)
5119 && ! DECL_ABSTRACT (decl))
5121 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5123 /* Output a .debug_pubnames entry for a public function
5124 defined in this compilation unit. */
5126 fputc ('\n', asm_out_file);
5127 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5128 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5129 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5130 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5131 IDENTIFIER_POINTER (DECL_NAME (decl)));
5132 ASM_OUTPUT_POP_SECTION (asm_out_file);
5135 break;
5137 case VAR_DECL:
5139 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5140 object declaration and if the declaration was never even
5141 referenced from within this entire compilation unit. We
5142 suppress these DIEs in order to save space in the .debug section
5143 (by eliminating entries which are probably useless). Note that
5144 we must not suppress block-local extern declarations (whether
5145 used or not) because that would screw-up the debugger's name
5146 lookup mechanism and cause it to miss things which really ought
5147 to be in scope at a given point. */
5149 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5150 return;
5152 if (TREE_PUBLIC (decl)
5153 && ! DECL_EXTERNAL (decl)
5154 && GET_CODE (DECL_RTL (decl)) == MEM
5155 && ! DECL_ABSTRACT (decl))
5157 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5159 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5161 /* Output a .debug_pubnames entry for a public variable
5162 defined in this compilation unit. */
5164 fputc ('\n', asm_out_file);
5165 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5166 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5167 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5168 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5169 IDENTIFIER_POINTER (DECL_NAME (decl)));
5170 ASM_OUTPUT_POP_SECTION (asm_out_file);
5173 if (DECL_INITIAL (decl) == NULL)
5175 /* Output a .debug_aranges entry for a public variable
5176 which is tentatively defined in this compilation unit. */
5178 fputc ('\n', asm_out_file);
5179 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5180 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5181 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5182 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5183 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5184 ASM_OUTPUT_POP_SECTION (asm_out_file);
5188 /* If we are in terse mode, don't generate any DIEs to represent
5189 any variable declarations or definitions. */
5191 if (debug_info_level <= DINFO_LEVEL_TERSE)
5192 return;
5194 break;
5196 case TYPE_DECL:
5197 /* Don't bother trying to generate any DIEs to represent any of the
5198 normal built-in types for the language we are compiling, except
5199 in cases where the types in question are *not* DWARF fundamental
5200 types. We make an exception in the case of non-fundamental types
5201 for the sake of objective C (and perhaps C++) because the GNU
5202 front-ends for these languages may in fact create certain "built-in"
5203 types which are (for example) RECORD_TYPEs. In such cases, we
5204 really need to output these (non-fundamental) types because other
5205 DIEs may contain references to them. */
5207 /* Also ignore language dependent types here, because they are probably
5208 also built-in types. If we didn't ignore them, then we would get
5209 references to undefined labels because output_type doesn't support
5210 them. So, for now, we need to ignore them to avoid assembler
5211 errors. */
5213 /* ??? This code is different than the equivalent code in dwarf2out.c.
5214 The dwarf2out.c code is probably more correct. */
5216 if (DECL_SOURCE_LINE (decl) == 0
5217 && (type_is_fundamental (TREE_TYPE (decl))
5218 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5219 return;
5221 /* If we are in terse mode, don't generate any DIEs to represent
5222 any actual typedefs. Note that even when we are in terse mode,
5223 we must still output DIEs to represent those tagged types which
5224 are used (directly or indirectly) in the specification of either
5225 a return type or a formal parameter type of some function. */
5227 if (debug_info_level <= DINFO_LEVEL_TERSE)
5228 if (! TYPE_DECL_IS_STUB (decl)
5229 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5230 return;
5232 break;
5234 default:
5235 return;
5238 fputc ('\n', asm_out_file);
5239 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5240 finalizing = set_finalizing;
5241 output_decl (decl, NULL_TREE);
5243 /* NOTE: The call above to `output_decl' may have caused one or more
5244 file-scope named types (i.e. tagged types) to be placed onto the
5245 pending_types_list. We have to get those types off of that list
5246 at some point, and this is the perfect time to do it. If we didn't
5247 take them off now, they might still be on the list when cc1 finally
5248 exits. That might be OK if it weren't for the fact that when we put
5249 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5250 for these types, and that causes them never to be output unless
5251 `output_pending_types_for_scope' takes them off of the list and un-sets
5252 their TREE_ASM_WRITTEN flags. */
5254 output_pending_types_for_scope (NULL_TREE);
5256 /* The above call should have totally emptied the pending_types_list
5257 if this is not a nested function or class. If this is a nested type,
5258 then the remaining pending_types will be emitted when the containing type
5259 is handled. */
5261 if (! DECL_CONTEXT (decl))
5263 if (pending_types != 0)
5264 abort ();
5267 ASM_OUTPUT_POP_SECTION (asm_out_file);
5269 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5270 current_funcdef_number++;
5273 /* Output a marker (i.e. a label) for the beginning of the generated code
5274 for a lexical block. */
5276 void
5277 dwarfout_begin_block (blocknum)
5278 register unsigned blocknum;
5280 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5282 function_section (current_function_decl);
5283 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5284 ASM_OUTPUT_LABEL (asm_out_file, label);
5287 /* Output a marker (i.e. a label) for the end of the generated code
5288 for a lexical block. */
5290 void
5291 dwarfout_end_block (blocknum)
5292 register unsigned blocknum;
5294 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5296 function_section (current_function_decl);
5297 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5298 ASM_OUTPUT_LABEL (asm_out_file, label);
5301 /* Output a marker (i.e. a label) at a point in the assembly code which
5302 corresponds to a given source level label. */
5304 void
5305 dwarfout_label (insn)
5306 register rtx insn;
5308 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5310 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5312 function_section (current_function_decl);
5313 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5314 (unsigned) INSN_UID (insn));
5315 ASM_OUTPUT_LABEL (asm_out_file, label);
5319 /* Output a marker (i.e. a label) for the point in the generated code where
5320 the real body of the function begins (after parameters have been moved
5321 to their home locations). */
5323 void
5324 dwarfout_begin_function ()
5326 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5328 if (! use_gnu_debug_info_extensions)
5329 return;
5330 function_section (current_function_decl);
5331 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5332 ASM_OUTPUT_LABEL (asm_out_file, label);
5335 /* Output a marker (i.e. a label) for the point in the generated code where
5336 the real body of the function ends (just before the epilogue code). */
5338 void
5339 dwarfout_end_function ()
5341 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5343 if (! use_gnu_debug_info_extensions)
5344 return;
5345 function_section (current_function_decl);
5346 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5347 ASM_OUTPUT_LABEL (asm_out_file, label);
5350 /* Output a marker (i.e. a label) for the absolute end of the generated code
5351 for a function definition. This gets called *after* the epilogue code
5352 has been generated. */
5354 void
5355 dwarfout_end_epilogue ()
5357 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5359 /* Output a label to mark the endpoint of the code generated for this
5360 function. */
5362 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5363 ASM_OUTPUT_LABEL (asm_out_file, label);
5366 static void
5367 shuffle_filename_entry (new_zeroth)
5368 register filename_entry *new_zeroth;
5370 filename_entry temp_entry;
5371 register filename_entry *limit_p;
5372 register filename_entry *move_p;
5374 if (new_zeroth == &filename_table[0])
5375 return;
5377 temp_entry = *new_zeroth;
5379 /* Shift entries up in the table to make room at [0]. */
5381 limit_p = &filename_table[0];
5382 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5383 *move_p = *(move_p-1);
5385 /* Install the found entry at [0]. */
5387 filename_table[0] = temp_entry;
5390 /* Create a new (string) entry for the .debug_sfnames section. */
5392 static void
5393 generate_new_sfname_entry ()
5395 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5397 fputc ('\n', asm_out_file);
5398 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5399 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5400 ASM_OUTPUT_LABEL (asm_out_file, label);
5401 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5402 filename_table[0].name
5403 ? filename_table[0].name
5404 : "");
5405 ASM_OUTPUT_POP_SECTION (asm_out_file);
5408 /* Lookup a filename (in the list of filenames that we know about here in
5409 dwarfout.c) and return its "index". The index of each (known) filename
5410 is just a unique number which is associated with only that one filename.
5411 We need such numbers for the sake of generating labels (in the
5412 .debug_sfnames section) and references to those unique labels (in the
5413 .debug_srcinfo and .debug_macinfo sections).
5415 If the filename given as an argument is not found in our current list,
5416 add it to the list and assign it the next available unique index number.
5418 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5419 one), we shuffle the filename found (or added) up to the zeroth entry of
5420 our list of filenames (which is always searched linearly). We do this so
5421 as to optimize the most common case for these filename lookups within
5422 dwarfout.c. The most common case by far is the case where we call
5423 lookup_filename to lookup the very same filename that we did a lookup
5424 on the last time we called lookup_filename. We make sure that this
5425 common case is fast because such cases will constitute 99.9% of the
5426 lookups we ever do (in practice).
5428 If we add a new filename entry to our table, we go ahead and generate
5429 the corresponding entry in the .debug_sfnames section right away.
5430 Doing so allows us to avoid tickling an assembler bug (present in some
5431 m68k assemblers) which yields assembly-time errors in cases where the
5432 difference of two label addresses is taken and where the two labels
5433 are in a section *other* than the one where the difference is being
5434 calculated, and where at least one of the two symbol references is a
5435 forward reference. (This bug could be tickled by our .debug_srcinfo
5436 entries if we don't output their corresponding .debug_sfnames entries
5437 before them.) */
5439 static unsigned
5440 lookup_filename (file_name)
5441 char *file_name;
5443 register filename_entry *search_p;
5444 register filename_entry *limit_p = &filename_table[ft_entries];
5446 for (search_p = filename_table; search_p < limit_p; search_p++)
5447 if (!strcmp (file_name, search_p->name))
5449 /* When we get here, we have found the filename that we were
5450 looking for in the filename_table. Now we want to make sure
5451 that it gets moved to the zero'th entry in the table (if it
5452 is not already there) so that subsequent attempts to find the
5453 same filename will find it as quickly as possible. */
5455 shuffle_filename_entry (search_p);
5456 return filename_table[0].number;
5459 /* We come here whenever we have a new filename which is not registered
5460 in the current table. Here we add it to the table. */
5462 /* Prepare to add a new table entry by making sure there is enough space
5463 in the table to do so. If not, expand the current table. */
5465 if (ft_entries == ft_entries_allocated)
5467 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5468 filename_table
5469 = (filename_entry *)
5470 xrealloc (filename_table,
5471 ft_entries_allocated * sizeof (filename_entry));
5474 /* Initially, add the new entry at the end of the filename table. */
5476 filename_table[ft_entries].number = ft_entries;
5477 filename_table[ft_entries].name = xstrdup (file_name);
5479 /* Shuffle the new entry into filename_table[0]. */
5481 shuffle_filename_entry (&filename_table[ft_entries]);
5483 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5484 generate_new_sfname_entry ();
5486 ft_entries++;
5487 return filename_table[0].number;
5490 static void
5491 generate_srcinfo_entry (line_entry_num, files_entry_num)
5492 unsigned line_entry_num;
5493 unsigned files_entry_num;
5495 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5497 fputc ('\n', asm_out_file);
5498 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5499 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5500 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5501 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5502 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5503 ASM_OUTPUT_POP_SECTION (asm_out_file);
5506 void
5507 dwarfout_line (filename, line)
5508 register char *filename;
5509 register unsigned line;
5511 if (debug_info_level >= DINFO_LEVEL_NORMAL
5512 /* We can't emit line number info for functions in separate sections,
5513 because the assembler can't subtract labels in different sections. */
5514 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5516 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5517 static unsigned last_line_entry_num = 0;
5518 static unsigned prev_file_entry_num = (unsigned) -1;
5519 register unsigned this_file_entry_num;
5521 function_section (current_function_decl);
5522 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5523 ASM_OUTPUT_LABEL (asm_out_file, label);
5525 fputc ('\n', asm_out_file);
5527 if (use_gnu_debug_info_extensions)
5528 this_file_entry_num = lookup_filename (filename);
5529 else
5530 this_file_entry_num = (unsigned) -1;
5532 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5533 if (this_file_entry_num != prev_file_entry_num)
5535 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5537 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5538 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5542 register char *tail = rindex (filename, '/');
5544 if (tail != NULL)
5545 filename = tail;
5548 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5549 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5550 filename, line);
5551 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5552 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5553 ASM_OUTPUT_POP_SECTION (asm_out_file);
5555 if (this_file_entry_num != prev_file_entry_num)
5556 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5557 prev_file_entry_num = this_file_entry_num;
5561 /* Generate an entry in the .debug_macinfo section. */
5563 static void
5564 generate_macinfo_entry (type_and_offset, string)
5565 register char *type_and_offset;
5566 register char *string;
5568 if (! use_gnu_debug_info_extensions)
5569 return;
5571 fputc ('\n', asm_out_file);
5572 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5573 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5574 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
5575 ASM_OUTPUT_POP_SECTION (asm_out_file);
5578 void
5579 dwarfout_start_new_source_file (filename)
5580 register char *filename;
5582 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5583 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5585 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5586 sprintf (type_and_offset, "0x%08x+%s-%s",
5587 ((unsigned) MACINFO_start << 24),
5588 /* Hack: skip leading '*' . */
5589 (*label == '*') + label,
5590 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5591 generate_macinfo_entry (type_and_offset, "");
5594 void
5595 dwarfout_resume_previous_source_file (lineno)
5596 register unsigned lineno;
5598 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5600 sprintf (type_and_offset, "0x%08x+%u",
5601 ((unsigned) MACINFO_resume << 24), lineno);
5602 generate_macinfo_entry (type_and_offset, "");
5605 /* Called from check_newline in c-parse.y. The `buffer' parameter
5606 contains the tail part of the directive line, i.e. the part which
5607 is past the initial whitespace, #, whitespace, directive-name,
5608 whitespace part. */
5610 void
5611 dwarfout_define (lineno, buffer)
5612 register unsigned lineno;
5613 register char *buffer;
5615 static int initialized = 0;
5616 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5618 if (!initialized)
5620 dwarfout_start_new_source_file (primary_filename);
5621 initialized = 1;
5623 sprintf (type_and_offset, "0x%08x+%u",
5624 ((unsigned) MACINFO_define << 24), lineno);
5625 generate_macinfo_entry (type_and_offset, buffer);
5628 /* Called from check_newline in c-parse.y. The `buffer' parameter
5629 contains the tail part of the directive line, i.e. the part which
5630 is past the initial whitespace, #, whitespace, directive-name,
5631 whitespace part. */
5633 void
5634 dwarfout_undef (lineno, buffer)
5635 register unsigned lineno;
5636 register char *buffer;
5638 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5640 sprintf (type_and_offset, "0x%08x+%u",
5641 ((unsigned) MACINFO_undef << 24), lineno);
5642 generate_macinfo_entry (type_and_offset, buffer);
5645 /* Set up for Dwarf output at the start of compilation. */
5647 void
5648 dwarfout_init (asm_out_file, main_input_filename)
5649 register FILE *asm_out_file;
5650 register char *main_input_filename;
5652 /* Remember the name of the primary input file. */
5654 primary_filename = main_input_filename;
5656 /* Allocate the initial hunk of the pending_sibling_stack. */
5658 pending_sibling_stack
5659 = (unsigned *)
5660 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5661 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5662 pending_siblings = 1;
5664 /* Allocate the initial hunk of the filename_table. */
5666 filename_table
5667 = (filename_entry *)
5668 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5669 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5670 ft_entries = 0;
5672 /* Allocate the initial hunk of the pending_types_list. */
5674 pending_types_list
5675 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5676 pending_types_allocated = PENDING_TYPES_INCREMENT;
5677 pending_types = 0;
5679 /* Create an artificial RECORD_TYPE node which we can use in our hack
5680 to get the DIEs representing types of formal parameters to come out
5681 only *after* the DIEs for the formal parameters themselves. */
5683 fake_containing_scope = make_node (RECORD_TYPE);
5685 /* Output a starting label for the .text section. */
5687 fputc ('\n', asm_out_file);
5688 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5689 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5690 ASM_OUTPUT_POP_SECTION (asm_out_file);
5692 /* Output a starting label for the .data section. */
5694 fputc ('\n', asm_out_file);
5695 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5696 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5697 ASM_OUTPUT_POP_SECTION (asm_out_file);
5699 #if 0 /* GNU C doesn't currently use .data1. */
5700 /* Output a starting label for the .data1 section. */
5702 fputc ('\n', asm_out_file);
5703 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5704 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5705 ASM_OUTPUT_POP_SECTION (asm_out_file);
5706 #endif
5708 /* Output a starting label for the .rodata section. */
5710 fputc ('\n', asm_out_file);
5711 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5712 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5713 ASM_OUTPUT_POP_SECTION (asm_out_file);
5715 #if 0 /* GNU C doesn't currently use .rodata1. */
5716 /* Output a starting label for the .rodata1 section. */
5718 fputc ('\n', asm_out_file);
5719 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5720 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5721 ASM_OUTPUT_POP_SECTION (asm_out_file);
5722 #endif
5724 /* Output a starting label for the .bss section. */
5726 fputc ('\n', asm_out_file);
5727 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5728 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5729 ASM_OUTPUT_POP_SECTION (asm_out_file);
5731 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5733 if (use_gnu_debug_info_extensions)
5735 /* Output a starting label and an initial (compilation directory)
5736 entry for the .debug_sfnames section. The starting label will be
5737 referenced by the initial entry in the .debug_srcinfo section. */
5739 fputc ('\n', asm_out_file);
5740 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5741 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5743 register char *pwd;
5744 register unsigned len;
5745 register char *dirname;
5747 pwd = getpwd ();
5748 if (!pwd)
5749 pfatal_with_name ("getpwd");
5750 len = strlen (pwd);
5751 dirname = (char *) xmalloc (len + 2);
5753 strcpy (dirname, pwd);
5754 strcpy (dirname + len, "/");
5755 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
5756 free (dirname);
5758 ASM_OUTPUT_POP_SECTION (asm_out_file);
5761 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5762 && use_gnu_debug_info_extensions)
5764 /* Output a starting label for the .debug_macinfo section. This
5765 label will be referenced by the AT_mac_info attribute in the
5766 TAG_compile_unit DIE. */
5768 fputc ('\n', asm_out_file);
5769 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5770 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5771 ASM_OUTPUT_POP_SECTION (asm_out_file);
5774 /* Generate the initial entry for the .line section. */
5776 fputc ('\n', asm_out_file);
5777 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5778 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5779 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5780 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5781 ASM_OUTPUT_POP_SECTION (asm_out_file);
5783 if (use_gnu_debug_info_extensions)
5785 /* Generate the initial entry for the .debug_srcinfo section. */
5787 fputc ('\n', asm_out_file);
5788 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5789 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5790 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5791 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5792 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5793 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5794 #ifdef DWARF_TIMESTAMPS
5795 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5796 #else
5797 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5798 #endif
5799 ASM_OUTPUT_POP_SECTION (asm_out_file);
5802 /* Generate the initial entry for the .debug_pubnames section. */
5804 fputc ('\n', asm_out_file);
5805 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5806 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5807 ASM_OUTPUT_POP_SECTION (asm_out_file);
5809 /* Generate the initial entry for the .debug_aranges section. */
5811 fputc ('\n', asm_out_file);
5812 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5813 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5814 ASM_OUTPUT_POP_SECTION (asm_out_file);
5817 /* Setup first DIE number == 1. */
5818 NEXT_DIE_NUM = next_unused_dienum++;
5820 /* Generate the initial DIE for the .debug section. Note that the
5821 (string) value given in the AT_name attribute of the TAG_compile_unit
5822 DIE will (typically) be a relative pathname and that this pathname
5823 should be taken as being relative to the directory from which the
5824 compiler was invoked when the given (base) source file was compiled. */
5826 fputc ('\n', asm_out_file);
5827 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5828 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5829 output_die (output_compile_unit_die, main_input_filename);
5830 ASM_OUTPUT_POP_SECTION (asm_out_file);
5832 fputc ('\n', asm_out_file);
5835 /* Output stuff that dwarf requires at the end of every file. */
5837 void
5838 dwarfout_finish ()
5840 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5842 fputc ('\n', asm_out_file);
5843 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5845 /* Mark the end of the chain of siblings which represent all file-scope
5846 declarations in this compilation unit. */
5848 /* The (null) DIE which represents the terminator for the (sibling linked)
5849 list of file-scope items is *special*. Normally, we would just call
5850 end_sibling_chain at this point in order to output a word with the
5851 value `4' and that word would act as the terminator for the list of
5852 DIEs describing file-scope items. Unfortunately, if we were to simply
5853 do that, the label that would follow this DIE in the .debug section
5854 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5855 machines) to a 4 byte boundary.
5857 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5858 the trick used is to insert extra (otherwise useless) padding bytes
5859 into the (null) DIE that we know must precede the ..D2 label in the
5860 .debug section. The amount of padding required can be anywhere between
5861 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5862 with the padding) would normally contain the value 4, but now it will
5863 also have to include the padding bytes, so it will instead have some
5864 value in the range 4..7.
5866 Fortunately, the rules of Dwarf say that any DIE whose length word
5867 contains *any* value less than 8 should be treated as a null DIE, so
5868 this trick works out nicely. Clever, eh? Don't give me any credit
5869 (or blame). I didn't think of this scheme. I just conformed to it.
5872 output_die (output_padded_null_die, (void *) 0);
5873 dienum_pop ();
5875 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5876 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5877 ASM_OUTPUT_POP_SECTION (asm_out_file);
5879 /* Output a terminator label for the .text section. */
5881 fputc ('\n', asm_out_file);
5882 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5883 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5884 ASM_OUTPUT_POP_SECTION (asm_out_file);
5886 /* Output a terminator label for the .data section. */
5888 fputc ('\n', asm_out_file);
5889 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5890 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5891 ASM_OUTPUT_POP_SECTION (asm_out_file);
5893 #if 0 /* GNU C doesn't currently use .data1. */
5894 /* Output a terminator label for the .data1 section. */
5896 fputc ('\n', asm_out_file);
5897 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5898 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5899 ASM_OUTPUT_POP_SECTION (asm_out_file);
5900 #endif
5902 /* Output a terminator label for the .rodata section. */
5904 fputc ('\n', asm_out_file);
5905 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5906 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5907 ASM_OUTPUT_POP_SECTION (asm_out_file);
5909 #if 0 /* GNU C doesn't currently use .rodata1. */
5910 /* Output a terminator label for the .rodata1 section. */
5912 fputc ('\n', asm_out_file);
5913 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5914 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5915 ASM_OUTPUT_POP_SECTION (asm_out_file);
5916 #endif
5918 /* Output a terminator label for the .bss section. */
5920 fputc ('\n', asm_out_file);
5921 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5922 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5923 ASM_OUTPUT_POP_SECTION (asm_out_file);
5925 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5927 /* Output a terminating entry for the .line section. */
5929 fputc ('\n', asm_out_file);
5930 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5931 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5932 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5933 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5934 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5935 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5936 ASM_OUTPUT_POP_SECTION (asm_out_file);
5938 if (use_gnu_debug_info_extensions)
5940 /* Output a terminating entry for the .debug_srcinfo section. */
5942 fputc ('\n', asm_out_file);
5943 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5944 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5945 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5946 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5947 ASM_OUTPUT_POP_SECTION (asm_out_file);
5950 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5952 /* Output terminating entries for the .debug_macinfo section. */
5954 dwarfout_resume_previous_source_file (0);
5956 fputc ('\n', asm_out_file);
5957 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5958 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5959 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
5960 ASM_OUTPUT_POP_SECTION (asm_out_file);
5963 /* Generate the terminating entry for the .debug_pubnames section. */
5965 fputc ('\n', asm_out_file);
5966 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5967 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5968 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
5969 ASM_OUTPUT_POP_SECTION (asm_out_file);
5971 /* Generate the terminating entries for the .debug_aranges section.
5973 Note that we want to do this only *after* we have output the end
5974 labels (for the various program sections) which we are going to
5975 refer to here. This allows us to work around a bug in the m68k
5976 svr4 assembler. That assembler gives bogus assembly-time errors
5977 if (within any given section) you try to take the difference of
5978 two relocatable symbols, both of which are located within some
5979 other section, and if one (or both?) of the symbols involved is
5980 being forward-referenced. By generating the .debug_aranges
5981 entries at this late point in the assembly output, we skirt the
5982 issue simply by avoiding forward-references.
5985 fputc ('\n', asm_out_file);
5986 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5988 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5989 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5991 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5992 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5994 #if 0 /* GNU C doesn't currently use .data1. */
5995 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5996 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5997 DATA1_BEGIN_LABEL);
5998 #endif
6000 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6001 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6002 RODATA_BEGIN_LABEL);
6004 #if 0 /* GNU C doesn't currently use .rodata1. */
6005 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6006 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6007 RODATA1_BEGIN_LABEL);
6008 #endif
6010 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6011 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6013 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6014 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6016 ASM_OUTPUT_POP_SECTION (asm_out_file);
6019 /* There should not be any pending types left at the end. We need
6020 this now because it may not have been checked on the last call to
6021 dwarfout_file_scope_decl. */
6022 if (pending_types != 0)
6023 abort ();
6026 #endif /* DWARF_DEBUGGING_INFO */