* ropeimpl.h: Check __STL_PTHREADS instead of _PTHREADS.
[official-gcc.git] / gcc / dwarfout.c
blobc9fb09e95984dc1706421dc920043c13108dc363
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
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 <stdio.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"
36 #if defined(DWARF_TIMESTAMPS)
37 #if defined(POSIX)
38 #include <time.h>
39 #else /* !defined(POSIX) */
40 #include <sys/types.h>
41 #if defined(__STDC__)
42 extern time_t time (time_t *);
43 #else /* !defined(__STDC__) */
44 extern time_t time ();
45 #endif /* !defined(__STDC__) */
46 #endif /* !defined(POSIX) */
47 #endif /* defined(DWARF_TIMESTAMPS) */
49 #ifdef HAVE_STDLIB_H
50 #include <stdlib.h>
51 #endif
53 #ifdef HAVE_STRING_H
54 #include <string.h>
55 #else
56 #ifdef HAVE_STRINGS_H
57 #include <strings.h>
58 #endif
59 #endif
61 /* We cannot use <assert.h> in GCC source, since that would include
62 GCC's assert.h, which may not be compatible with the host compiler. */
63 #undef assert
64 #ifdef NDEBUG
65 # define assert(e)
66 #else
67 # define assert(e) do { if (! (e)) abort (); } while (0)
68 #endif
70 extern char *getpwd ();
72 #ifdef NEED_DECLARATION_INDEX
73 extern char *index ();
74 #endif
76 #ifdef NEED_DECLARATION_RINDEX
77 extern char *rindex ();
78 #endif
80 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
81 regarding the GNU implementation of Dwarf. */
83 /* NOTE: In the comments in this file, many references are made to
84 so called "Debugging Information Entries". For the sake of brevity,
85 this term is abbreviated to `DIE' throughout the remainder of this
86 file. */
88 /* Note that the implementation of C++ support herein is (as yet) unfinished.
89 If you want to try to complete it, more power to you. */
91 #if !defined(__GNUC__) || (NDEBUG != 1)
92 #define inline
93 #endif
95 /* How to start an assembler comment. */
96 #ifndef ASM_COMMENT_START
97 #define ASM_COMMENT_START ";#"
98 #endif
100 /* How to print out a register name. */
101 #ifndef PRINT_REG
102 #define PRINT_REG(RTX, CODE, FILE) \
103 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
104 #endif
106 /* Define a macro which returns non-zero for any tagged type which is
107 used (directly or indirectly) in the specification of either some
108 function's return type or some formal parameter of some function.
109 We use this macro when we are operating in "terse" mode to help us
110 know what tagged types have to be represented in Dwarf (even in
111 terse mode) and which ones don't.
113 A flag bit with this meaning really should be a part of the normal
114 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
115 for these nodes. For now, we have to just fake it. It it safe for
116 us to simply return zero for all complete tagged types (which will
117 get forced out anyway if they were used in the specification of some
118 formal or return type) and non-zero for all incomplete tagged types.
121 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
123 /* Define a macro which returns non-zero for a TYPE_DECL which was
124 implicitly generated for a tagged type.
126 Note that unlike the gcc front end (which generates a NULL named
127 TYPE_DECL node for each complete tagged type, each array type, and
128 each function type node created) the g++ front end generates a
129 _named_ TYPE_DECL node for each tagged type node created.
130 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
131 generate a DW_TAG_typedef DIE for them. */
132 #define TYPE_DECL_IS_STUB(decl) \
133 (DECL_NAME (decl) == NULL \
134 || (DECL_ARTIFICIAL (decl) \
135 && is_tagged_type (TREE_TYPE (decl)) \
136 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
138 extern int flag_traditional;
139 extern char *version_string;
140 extern char *language_string;
142 /* Maximum size (in bytes) of an artificially generated label. */
144 #define MAX_ARTIFICIAL_LABEL_BYTES 30
146 /* Make sure we know the sizes of the various types dwarf can describe.
147 These are only defaults. If the sizes are different for your target,
148 you should override these values by defining the appropriate symbols
149 in your tm.h file. */
151 #ifndef CHAR_TYPE_SIZE
152 #define CHAR_TYPE_SIZE BITS_PER_UNIT
153 #endif
155 #ifndef SHORT_TYPE_SIZE
156 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
157 #endif
159 #ifndef INT_TYPE_SIZE
160 #define INT_TYPE_SIZE BITS_PER_WORD
161 #endif
163 #ifndef LONG_TYPE_SIZE
164 #define LONG_TYPE_SIZE BITS_PER_WORD
165 #endif
167 #ifndef LONG_LONG_TYPE_SIZE
168 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
169 #endif
171 #ifndef WCHAR_TYPE_SIZE
172 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
173 #endif
175 #ifndef WCHAR_UNSIGNED
176 #define WCHAR_UNSIGNED 0
177 #endif
179 #ifndef FLOAT_TYPE_SIZE
180 #define FLOAT_TYPE_SIZE BITS_PER_WORD
181 #endif
183 #ifndef DOUBLE_TYPE_SIZE
184 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
185 #endif
187 #ifndef LONG_DOUBLE_TYPE_SIZE
188 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
189 #endif
191 /* Structure to keep track of source filenames. */
193 struct filename_entry {
194 unsigned number;
195 char * name;
198 typedef struct filename_entry filename_entry;
200 /* Pointer to an array of elements, each one having the structure above. */
202 static filename_entry *filename_table;
204 /* Total number of entries in the table (i.e. array) pointed to by
205 `filename_table'. This is the *total* and includes both used and
206 unused slots. */
208 static unsigned ft_entries_allocated;
210 /* Number of entries in the filename_table which are actually in use. */
212 static unsigned ft_entries;
214 /* Size (in elements) of increments by which we may expand the filename
215 table. Actually, a single hunk of space of this size should be enough
216 for most typical programs. */
218 #define FT_ENTRIES_INCREMENT 64
220 /* Local pointer to the name of the main input file. Initialized in
221 dwarfout_init. */
223 static char *primary_filename;
225 /* Pointer to the most recent filename for which we produced some line info. */
227 static char *last_filename;
229 /* For Dwarf output, we must assign lexical-blocks id numbers
230 in the order in which their beginnings are encountered.
231 We output Dwarf debugging info that refers to the beginnings
232 and ends of the ranges of code for each lexical block with
233 assembler labels ..Bn and ..Bn.e, where n is the block number.
234 The labels themselves are generated in final.c, which assigns
235 numbers to the blocks in the same way. */
237 static unsigned next_block_number = 2;
239 /* Counter to generate unique names for DIEs. */
241 static unsigned next_unused_dienum = 1;
243 /* Number of the DIE which is currently being generated. */
245 static unsigned current_dienum;
247 /* Number to use for the special "pubname" label on the next DIE which
248 represents a function or data object defined in this compilation
249 unit which has "extern" linkage. */
251 static int next_pubname_number = 0;
253 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
255 /* Pointer to a dynamically allocated list of pre-reserved and still
256 pending sibling DIE numbers. Note that this list will grow as needed. */
258 static unsigned *pending_sibling_stack;
260 /* Counter to keep track of the number of pre-reserved and still pending
261 sibling DIE numbers. */
263 static unsigned pending_siblings;
265 /* The currently allocated size of the above list (expressed in number of
266 list elements). */
268 static unsigned pending_siblings_allocated;
270 /* Size (in elements) of increments by which we may expand the pending
271 sibling stack. Actually, a single hunk of space of this size should
272 be enough for most typical programs. */
274 #define PENDING_SIBLINGS_INCREMENT 64
276 /* Non-zero if we are performing our file-scope finalization pass and if
277 we should force out Dwarf descriptions of any and all file-scope
278 tagged types which are still incomplete types. */
280 static int finalizing = 0;
282 /* A pointer to the base of a list of pending types which we haven't
283 generated DIEs for yet, but which we will have to come back to
284 later on. */
286 static tree *pending_types_list;
288 /* Number of elements currently allocated for the pending_types_list. */
290 static unsigned pending_types_allocated;
292 /* Number of elements of pending_types_list currently in use. */
294 static unsigned pending_types;
296 /* Size (in elements) of increments by which we may expand the pending
297 types list. Actually, a single hunk of space of this size should
298 be enough for most typical programs. */
300 #define PENDING_TYPES_INCREMENT 64
302 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
303 This is used in a hack to help us get the DIEs describing types of
304 formal parameters to come *after* all of the DIEs describing the formal
305 parameters themselves. That's necessary in order to be compatible
306 with what the brain-damaged svr4 SDB debugger requires. */
308 static tree fake_containing_scope;
310 /* The number of the current function definition that we are generating
311 debugging information for. These numbers range from 1 up to the maximum
312 number of function definitions contained within the current compilation
313 unit. These numbers are used to create unique labels for various things
314 contained within various function definitions. */
316 static unsigned current_funcdef_number = 1;
318 /* A pointer to the ..._DECL node which we have most recently been working
319 on. We keep this around just in case something about it looks screwy
320 and we want to tell the user what the source coordinates for the actual
321 declaration are. */
323 static tree dwarf_last_decl;
325 /* A flag indicating that we are emitting the member declarations of a
326 class, so member functions and variables should not be entirely emitted.
327 This is a kludge to avoid passing a second argument to output_*_die. */
329 static int in_class;
331 /* Forward declarations for functions defined in this file. */
333 static char *dwarf_tag_name PROTO((unsigned));
334 static char *dwarf_attr_name PROTO((unsigned));
335 static char *dwarf_stack_op_name PROTO((unsigned));
336 static char *dwarf_typemod_name PROTO((unsigned));
337 static char *dwarf_fmt_byte_name PROTO((unsigned));
338 static char *dwarf_fund_type_name PROTO((unsigned));
339 static tree decl_ultimate_origin PROTO((tree));
340 static tree block_ultimate_origin PROTO((tree));
341 static void output_unsigned_leb128 PROTO((unsigned long));
342 static void output_signed_leb128 PROTO((long));
343 static inline int is_body_block PROTO((tree));
344 static int fundamental_type_code PROTO((tree));
345 static tree root_type_1 PROTO((tree, int));
346 static tree root_type PROTO((tree));
347 static void write_modifier_bytes_1 PROTO((tree, int, int, int));
348 static void write_modifier_bytes PROTO((tree, int, int));
349 static inline int type_is_fundamental PROTO((tree));
350 static void equate_decl_number_to_die_number PROTO((tree));
351 static inline void equate_type_number_to_die_number PROTO((tree));
352 static void output_reg_number PROTO((rtx));
353 static void output_mem_loc_descriptor PROTO((rtx));
354 static void output_loc_descriptor PROTO((rtx));
355 static void output_bound_representation PROTO((tree, unsigned, int));
356 static void output_enumeral_list PROTO((tree));
357 static inline unsigned ceiling PROTO((unsigned, unsigned));
358 static inline tree field_type PROTO((tree));
359 static inline unsigned simple_type_align_in_bits PROTO((tree));
360 static inline unsigned simple_type_size_in_bits PROTO((tree));
361 static unsigned field_byte_offset PROTO((tree));
362 static inline void sibling_attribute PROTO((void));
363 static void location_attribute PROTO((rtx));
364 static void data_member_location_attribute PROTO((tree));
365 static void const_value_attribute PROTO((rtx));
366 static void location_or_const_value_attribute PROTO((tree));
367 static inline void name_attribute PROTO((char *));
368 static inline void fund_type_attribute PROTO((unsigned));
369 static void mod_fund_type_attribute PROTO((tree, int, int));
370 static inline void user_def_type_attribute PROTO((tree));
371 static void mod_u_d_type_attribute PROTO((tree, int, int));
372 #ifdef USE_ORDERING_ATTRIBUTE
373 static inline void ordering_attribute PROTO((unsigned));
374 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
375 static void subscript_data_attribute PROTO((tree));
376 static void byte_size_attribute PROTO((tree));
377 static inline void bit_offset_attribute PROTO((tree));
378 static inline void bit_size_attribute PROTO((tree));
379 static inline void element_list_attribute PROTO((tree));
380 static inline void stmt_list_attribute PROTO((char *));
381 static inline void low_pc_attribute PROTO((char *));
382 static inline void high_pc_attribute PROTO((char *));
383 static inline void body_begin_attribute PROTO((char *));
384 static inline void body_end_attribute PROTO((char *));
385 static inline void language_attribute PROTO((unsigned));
386 static inline void member_attribute PROTO((tree));
387 static inline void string_length_attribute PROTO((tree));
388 static inline void comp_dir_attribute PROTO((char *));
389 static inline void sf_names_attribute PROTO((char *));
390 static inline void src_info_attribute PROTO((char *));
391 static inline void mac_info_attribute PROTO((char *));
392 static inline void prototyped_attribute PROTO((tree));
393 static inline void producer_attribute PROTO((char *));
394 static inline void inline_attribute PROTO((tree));
395 static inline void containing_type_attribute PROTO((tree));
396 static inline void abstract_origin_attribute PROTO((tree));
397 #ifdef DWARF_DECL_COORDINATES
398 static inline void src_coords_attribute PROTO((unsigned, unsigned));
399 #endif /* defined(DWARF_DECL_COORDINATES) */
400 static inline void pure_or_virtual_attribute PROTO((tree));
401 static void name_and_src_coords_attributes PROTO((tree));
402 static void type_attribute PROTO((tree, int, int));
403 static char *type_tag PROTO((tree));
404 static inline void dienum_push PROTO((void));
405 static inline void dienum_pop PROTO((void));
406 static inline tree member_declared_type PROTO((tree));
407 static char *function_start_label PROTO((tree));
408 static void output_array_type_die PROTO((void *));
409 static void output_set_type_die PROTO((void *));
410 #if 0
411 static void output_entry_point_die PROTO((void *));
412 #endif
413 static void output_inlined_enumeration_type_die PROTO((void *));
414 static void output_inlined_structure_type_die PROTO((void *));
415 static void output_inlined_union_type_die PROTO((void *));
416 static void output_enumeration_type_die PROTO((void *));
417 static void output_formal_parameter_die PROTO((void *));
418 static void output_global_subroutine_die PROTO((void *));
419 static void output_global_variable_die PROTO((void *));
420 static void output_label_die PROTO((void *));
421 static void output_lexical_block_die PROTO((void *));
422 static void output_inlined_subroutine_die PROTO((void *));
423 static void output_local_variable_die PROTO((void *));
424 static void output_member_die PROTO((void *));
425 #if 0
426 static void output_pointer_type_die PROTO((void *));
427 static void output_reference_type_die PROTO((void *));
428 #endif
429 static void output_ptr_to_mbr_type_die PROTO((void *));
430 static void output_compile_unit_die PROTO((void *));
431 static void output_string_type_die PROTO((void *));
432 static void output_structure_type_die PROTO((void *));
433 static void output_local_subroutine_die PROTO((void *));
434 static void output_subroutine_type_die PROTO((void *));
435 static void output_typedef_die PROTO((void *));
436 static void output_union_type_die PROTO((void *));
437 static void output_unspecified_parameters_die PROTO((void *));
438 static void output_padded_null_die PROTO((void *));
439 static void output_die PROTO((void (*) (), void *));
440 static void end_sibling_chain PROTO((void));
441 static void output_formal_types PROTO((tree));
442 static void pend_type PROTO((tree));
443 static void output_pending_types_for_scope PROTO((tree));
444 static void output_type PROTO((tree, tree));
445 static void output_tagged_type_instantiation PROTO((tree));
446 static void output_block PROTO((tree, int));
447 static void output_decls_for_scope PROTO((tree, int));
448 static void output_decl PROTO((tree, tree));
449 static void shuffle_filename_entry PROTO((filename_entry *));
450 static void generate_new_sfname_entry PROTO((void));
451 static unsigned lookup_filename PROTO((char *));
452 static void generate_srcinfo_entry PROTO((unsigned, unsigned));
453 static void generate_macinfo_entry PROTO((char *, char *));
455 /* Definitions of defaults for assembler-dependent names of various
456 pseudo-ops and section names.
458 Theses may be overridden in your tm.h file (if necessary) for your
459 particular assembler. The default values provided here correspond to
460 what is expected by "standard" AT&T System V.4 assemblers. */
462 #ifndef FILE_ASM_OP
463 #define FILE_ASM_OP ".file"
464 #endif
465 #ifndef VERSION_ASM_OP
466 #define VERSION_ASM_OP ".version"
467 #endif
468 #ifndef UNALIGNED_SHORT_ASM_OP
469 #define UNALIGNED_SHORT_ASM_OP ".2byte"
470 #endif
471 #ifndef UNALIGNED_INT_ASM_OP
472 #define UNALIGNED_INT_ASM_OP ".4byte"
473 #endif
474 #ifndef ASM_BYTE_OP
475 #define ASM_BYTE_OP ".byte"
476 #endif
477 #ifndef SET_ASM_OP
478 #define SET_ASM_OP ".set"
479 #endif
481 /* Pseudo-ops for pushing the current section onto the section stack (and
482 simultaneously changing to a new section) and for poping back to the
483 section we were in immediately before this one. Note that most svr4
484 assemblers only maintain a one level stack... you can push all the
485 sections you want, but you can only pop out one level. (The sparc
486 svr4 assembler is an exception to this general rule.) That's
487 OK because we only use at most one level of the section stack herein. */
489 #ifndef PUSHSECTION_ASM_OP
490 #define PUSHSECTION_ASM_OP ".section"
491 #endif
492 #ifndef POPSECTION_ASM_OP
493 #define POPSECTION_ASM_OP ".previous"
494 #endif
496 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
497 to print the PUSHSECTION_ASM_OP and the section name. The default here
498 works for almost all svr4 assemblers, except for the sparc, where the
499 section name must be enclosed in double quotes. (See sparcv4.h.) */
501 #ifndef PUSHSECTION_FORMAT
502 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
503 #endif
505 #ifndef DEBUG_SECTION
506 #define DEBUG_SECTION ".debug"
507 #endif
508 #ifndef LINE_SECTION
509 #define LINE_SECTION ".line"
510 #endif
511 #ifndef SFNAMES_SECTION
512 #define SFNAMES_SECTION ".debug_sfnames"
513 #endif
514 #ifndef SRCINFO_SECTION
515 #define SRCINFO_SECTION ".debug_srcinfo"
516 #endif
517 #ifndef MACINFO_SECTION
518 #define MACINFO_SECTION ".debug_macinfo"
519 #endif
520 #ifndef PUBNAMES_SECTION
521 #define PUBNAMES_SECTION ".debug_pubnames"
522 #endif
523 #ifndef ARANGES_SECTION
524 #define ARANGES_SECTION ".debug_aranges"
525 #endif
526 #ifndef TEXT_SECTION
527 #define TEXT_SECTION ".text"
528 #endif
529 #ifndef DATA_SECTION
530 #define DATA_SECTION ".data"
531 #endif
532 #ifndef DATA1_SECTION
533 #define DATA1_SECTION ".data1"
534 #endif
535 #ifndef RODATA_SECTION
536 #define RODATA_SECTION ".rodata"
537 #endif
538 #ifndef RODATA1_SECTION
539 #define RODATA1_SECTION ".rodata1"
540 #endif
541 #ifndef BSS_SECTION
542 #define BSS_SECTION ".bss"
543 #endif
545 /* Definitions of defaults for formats and names of various special
546 (artificial) labels which may be generated within this file (when
547 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
549 If necessary, these may be overridden from within your tm.h file,
550 but typically, you should never need to override these.
552 These labels have been hacked (temporarily) so that they all begin with
553 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
554 stock m88k/svr4 assembler, both of which need to see .L at the start of
555 a label in order to prevent that label from going into the linker symbol
556 table). When I get time, I'll have to fix this the right way so that we
557 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
558 but that will require a rather massive set of changes. For the moment,
559 the following definitions out to produce the right results for all svr4
560 and svr3 assemblers. -- rfg
563 #ifndef TEXT_BEGIN_LABEL
564 #define TEXT_BEGIN_LABEL "*.L_text_b"
565 #endif
566 #ifndef TEXT_END_LABEL
567 #define TEXT_END_LABEL "*.L_text_e"
568 #endif
570 #ifndef DATA_BEGIN_LABEL
571 #define DATA_BEGIN_LABEL "*.L_data_b"
572 #endif
573 #ifndef DATA_END_LABEL
574 #define DATA_END_LABEL "*.L_data_e"
575 #endif
577 #ifndef DATA1_BEGIN_LABEL
578 #define DATA1_BEGIN_LABEL "*.L_data1_b"
579 #endif
580 #ifndef DATA1_END_LABEL
581 #define DATA1_END_LABEL "*.L_data1_e"
582 #endif
584 #ifndef RODATA_BEGIN_LABEL
585 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
586 #endif
587 #ifndef RODATA_END_LABEL
588 #define RODATA_END_LABEL "*.L_rodata_e"
589 #endif
591 #ifndef RODATA1_BEGIN_LABEL
592 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
593 #endif
594 #ifndef RODATA1_END_LABEL
595 #define RODATA1_END_LABEL "*.L_rodata1_e"
596 #endif
598 #ifndef BSS_BEGIN_LABEL
599 #define BSS_BEGIN_LABEL "*.L_bss_b"
600 #endif
601 #ifndef BSS_END_LABEL
602 #define BSS_END_LABEL "*.L_bss_e"
603 #endif
605 #ifndef LINE_BEGIN_LABEL
606 #define LINE_BEGIN_LABEL "*.L_line_b"
607 #endif
608 #ifndef LINE_LAST_ENTRY_LABEL
609 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
610 #endif
611 #ifndef LINE_END_LABEL
612 #define LINE_END_LABEL "*.L_line_e"
613 #endif
615 #ifndef DEBUG_BEGIN_LABEL
616 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
617 #endif
618 #ifndef SFNAMES_BEGIN_LABEL
619 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
620 #endif
621 #ifndef SRCINFO_BEGIN_LABEL
622 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
623 #endif
624 #ifndef MACINFO_BEGIN_LABEL
625 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
626 #endif
628 #ifndef DIE_BEGIN_LABEL_FMT
629 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
630 #endif
631 #ifndef DIE_END_LABEL_FMT
632 #define DIE_END_LABEL_FMT "*.L_D%u_e"
633 #endif
634 #ifndef PUB_DIE_LABEL_FMT
635 #define PUB_DIE_LABEL_FMT "*.L_P%u"
636 #endif
637 #ifndef INSN_LABEL_FMT
638 #define INSN_LABEL_FMT "*.L_I%u_%u"
639 #endif
640 #ifndef BLOCK_BEGIN_LABEL_FMT
641 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
642 #endif
643 #ifndef BLOCK_END_LABEL_FMT
644 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
645 #endif
646 #ifndef SS_BEGIN_LABEL_FMT
647 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
648 #endif
649 #ifndef SS_END_LABEL_FMT
650 #define SS_END_LABEL_FMT "*.L_s%u_e"
651 #endif
652 #ifndef EE_BEGIN_LABEL_FMT
653 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
654 #endif
655 #ifndef EE_END_LABEL_FMT
656 #define EE_END_LABEL_FMT "*.L_e%u_e"
657 #endif
658 #ifndef MT_BEGIN_LABEL_FMT
659 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
660 #endif
661 #ifndef MT_END_LABEL_FMT
662 #define MT_END_LABEL_FMT "*.L_t%u_e"
663 #endif
664 #ifndef LOC_BEGIN_LABEL_FMT
665 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
666 #endif
667 #ifndef LOC_END_LABEL_FMT
668 #define LOC_END_LABEL_FMT "*.L_l%u_e"
669 #endif
670 #ifndef BOUND_BEGIN_LABEL_FMT
671 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
672 #endif
673 #ifndef BOUND_END_LABEL_FMT
674 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
675 #endif
676 #ifndef DERIV_BEGIN_LABEL_FMT
677 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
678 #endif
679 #ifndef DERIV_END_LABEL_FMT
680 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
681 #endif
682 #ifndef SL_BEGIN_LABEL_FMT
683 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
684 #endif
685 #ifndef SL_END_LABEL_FMT
686 #define SL_END_LABEL_FMT "*.L_sl%u_e"
687 #endif
688 #ifndef BODY_BEGIN_LABEL_FMT
689 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
690 #endif
691 #ifndef BODY_END_LABEL_FMT
692 #define BODY_END_LABEL_FMT "*.L_b%u_e"
693 #endif
694 #ifndef FUNC_END_LABEL_FMT
695 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
696 #endif
697 #ifndef TYPE_NAME_FMT
698 #define TYPE_NAME_FMT "*.L_T%u"
699 #endif
700 #ifndef DECL_NAME_FMT
701 #define DECL_NAME_FMT "*.L_E%u"
702 #endif
703 #ifndef LINE_CODE_LABEL_FMT
704 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
705 #endif
706 #ifndef SFNAMES_ENTRY_LABEL_FMT
707 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
708 #endif
709 #ifndef LINE_ENTRY_LABEL_FMT
710 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
711 #endif
713 /* Definitions of defaults for various types of primitive assembly language
714 output operations.
716 If necessary, these may be overridden from within your tm.h file,
717 but typically, you shouldn't need to override these. */
719 #ifndef ASM_OUTPUT_PUSH_SECTION
720 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
721 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
722 #endif
724 #ifndef ASM_OUTPUT_POP_SECTION
725 #define ASM_OUTPUT_POP_SECTION(FILE) \
726 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
727 #endif
729 #ifndef ASM_OUTPUT_DWARF_DELTA2
730 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
731 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
732 assemble_name (FILE, LABEL1); \
733 fprintf (FILE, "-"); \
734 assemble_name (FILE, LABEL2); \
735 fprintf (FILE, "\n"); \
736 } while (0)
737 #endif
739 #ifndef ASM_OUTPUT_DWARF_DELTA4
740 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
741 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
742 assemble_name (FILE, LABEL1); \
743 fprintf (FILE, "-"); \
744 assemble_name (FILE, LABEL2); \
745 fprintf (FILE, "\n"); \
746 } while (0)
747 #endif
749 #ifndef ASM_OUTPUT_DWARF_TAG
750 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
751 do { \
752 fprintf ((FILE), "\t%s\t0x%x", \
753 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
754 if (flag_debug_asm) \
755 fprintf ((FILE), "\t%s %s", \
756 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
757 fputc ('\n', (FILE)); \
758 } while (0)
759 #endif
761 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
762 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
763 do { \
764 fprintf ((FILE), "\t%s\t0x%x", \
765 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
766 if (flag_debug_asm) \
767 fprintf ((FILE), "\t%s %s", \
768 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
769 fputc ('\n', (FILE)); \
770 } while (0)
771 #endif
773 #ifndef ASM_OUTPUT_DWARF_STACK_OP
774 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
775 do { \
776 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
777 if (flag_debug_asm) \
778 fprintf ((FILE), "\t%s %s", \
779 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
780 fputc ('\n', (FILE)); \
781 } while (0)
782 #endif
784 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
785 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
786 do { \
787 fprintf ((FILE), "\t%s\t0x%x", \
788 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
789 if (flag_debug_asm) \
790 fprintf ((FILE), "\t%s %s", \
791 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
792 fputc ('\n', (FILE)); \
793 } while (0)
794 #endif
796 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
797 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
798 do { \
799 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
800 if (flag_debug_asm) \
801 fprintf ((FILE), "\t%s %s", \
802 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
803 fputc ('\n', (FILE)); \
804 } while (0)
805 #endif
807 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
808 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
809 do { \
810 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
811 if (flag_debug_asm) \
812 fprintf ((FILE), "\t%s %s", \
813 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
814 fputc ('\n', (FILE)); \
815 } while (0)
816 #endif
818 #ifndef ASM_OUTPUT_DWARF_ADDR
819 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
820 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
821 assemble_name (FILE, LABEL); \
822 fprintf (FILE, "\n"); \
823 } while (0)
824 #endif
826 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
827 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
828 do { \
829 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
830 output_addr_const ((FILE), (RTX)); \
831 fputc ('\n', (FILE)); \
832 } while (0)
833 #endif
835 #ifndef ASM_OUTPUT_DWARF_REF
836 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
837 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
838 assemble_name (FILE, LABEL); \
839 fprintf (FILE, "\n"); \
840 } while (0)
841 #endif
843 #ifndef ASM_OUTPUT_DWARF_DATA1
844 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
845 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
846 #endif
848 #ifndef ASM_OUTPUT_DWARF_DATA2
849 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
850 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
851 #endif
853 #ifndef ASM_OUTPUT_DWARF_DATA4
854 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
855 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
856 #endif
858 #ifndef ASM_OUTPUT_DWARF_DATA8
859 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
860 do { \
861 if (WORDS_BIG_ENDIAN) \
863 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
864 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
866 else \
868 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
869 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
871 } while (0)
872 #endif
874 #ifndef ASM_OUTPUT_DWARF_STRING
875 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
876 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
877 #endif
879 /************************ general utility functions **************************/
881 inline int
882 is_pseudo_reg (rtl)
883 register rtx rtl;
885 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
886 || ((GET_CODE (rtl) == SUBREG)
887 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
890 inline tree
891 type_main_variant (type)
892 register tree type;
894 type = TYPE_MAIN_VARIANT (type);
896 /* There really should be only one main variant among any group of variants
897 of a given type (and all of the MAIN_VARIANT values for all members of
898 the group should point to that one type) but sometimes the C front-end
899 messes this up for array types, so we work around that bug here. */
901 if (TREE_CODE (type) == ARRAY_TYPE)
903 while (type != TYPE_MAIN_VARIANT (type))
904 type = TYPE_MAIN_VARIANT (type);
907 return type;
910 /* Return non-zero if the given type node represents a tagged type. */
912 inline int
913 is_tagged_type (type)
914 register tree type;
916 register enum tree_code code = TREE_CODE (type);
918 return (code == RECORD_TYPE || code == UNION_TYPE
919 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
922 static char *
923 dwarf_tag_name (tag)
924 register unsigned tag;
926 switch (tag)
928 case TAG_padding: return "TAG_padding";
929 case TAG_array_type: return "TAG_array_type";
930 case TAG_class_type: return "TAG_class_type";
931 case TAG_entry_point: return "TAG_entry_point";
932 case TAG_enumeration_type: return "TAG_enumeration_type";
933 case TAG_formal_parameter: return "TAG_formal_parameter";
934 case TAG_global_subroutine: return "TAG_global_subroutine";
935 case TAG_global_variable: return "TAG_global_variable";
936 case TAG_label: return "TAG_label";
937 case TAG_lexical_block: return "TAG_lexical_block";
938 case TAG_local_variable: return "TAG_local_variable";
939 case TAG_member: return "TAG_member";
940 case TAG_pointer_type: return "TAG_pointer_type";
941 case TAG_reference_type: return "TAG_reference_type";
942 case TAG_compile_unit: return "TAG_compile_unit";
943 case TAG_string_type: return "TAG_string_type";
944 case TAG_structure_type: return "TAG_structure_type";
945 case TAG_subroutine: return "TAG_subroutine";
946 case TAG_subroutine_type: return "TAG_subroutine_type";
947 case TAG_typedef: return "TAG_typedef";
948 case TAG_union_type: return "TAG_union_type";
949 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
950 case TAG_variant: return "TAG_variant";
951 case TAG_common_block: return "TAG_common_block";
952 case TAG_common_inclusion: return "TAG_common_inclusion";
953 case TAG_inheritance: return "TAG_inheritance";
954 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
955 case TAG_module: return "TAG_module";
956 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
957 case TAG_set_type: return "TAG_set_type";
958 case TAG_subrange_type: return "TAG_subrange_type";
959 case TAG_with_stmt: return "TAG_with_stmt";
961 /* GNU extensions. */
963 case TAG_format_label: return "TAG_format_label";
964 case TAG_namelist: return "TAG_namelist";
965 case TAG_function_template: return "TAG_function_template";
966 case TAG_class_template: return "TAG_class_template";
968 default: return "TAG_<unknown>";
972 static char *
973 dwarf_attr_name (attr)
974 register unsigned attr;
976 switch (attr)
978 case AT_sibling: return "AT_sibling";
979 case AT_location: return "AT_location";
980 case AT_name: return "AT_name";
981 case AT_fund_type: return "AT_fund_type";
982 case AT_mod_fund_type: return "AT_mod_fund_type";
983 case AT_user_def_type: return "AT_user_def_type";
984 case AT_mod_u_d_type: return "AT_mod_u_d_type";
985 case AT_ordering: return "AT_ordering";
986 case AT_subscr_data: return "AT_subscr_data";
987 case AT_byte_size: return "AT_byte_size";
988 case AT_bit_offset: return "AT_bit_offset";
989 case AT_bit_size: return "AT_bit_size";
990 case AT_element_list: return "AT_element_list";
991 case AT_stmt_list: return "AT_stmt_list";
992 case AT_low_pc: return "AT_low_pc";
993 case AT_high_pc: return "AT_high_pc";
994 case AT_language: return "AT_language";
995 case AT_member: return "AT_member";
996 case AT_discr: return "AT_discr";
997 case AT_discr_value: return "AT_discr_value";
998 case AT_string_length: return "AT_string_length";
999 case AT_common_reference: return "AT_common_reference";
1000 case AT_comp_dir: return "AT_comp_dir";
1001 case AT_const_value_string: return "AT_const_value_string";
1002 case AT_const_value_data2: return "AT_const_value_data2";
1003 case AT_const_value_data4: return "AT_const_value_data4";
1004 case AT_const_value_data8: return "AT_const_value_data8";
1005 case AT_const_value_block2: return "AT_const_value_block2";
1006 case AT_const_value_block4: return "AT_const_value_block4";
1007 case AT_containing_type: return "AT_containing_type";
1008 case AT_default_value_addr: return "AT_default_value_addr";
1009 case AT_default_value_data2: return "AT_default_value_data2";
1010 case AT_default_value_data4: return "AT_default_value_data4";
1011 case AT_default_value_data8: return "AT_default_value_data8";
1012 case AT_default_value_string: return "AT_default_value_string";
1013 case AT_friends: return "AT_friends";
1014 case AT_inline: return "AT_inline";
1015 case AT_is_optional: return "AT_is_optional";
1016 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1017 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1018 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1019 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1020 case AT_private: return "AT_private";
1021 case AT_producer: return "AT_producer";
1022 case AT_program: return "AT_program";
1023 case AT_protected: return "AT_protected";
1024 case AT_prototyped: return "AT_prototyped";
1025 case AT_public: return "AT_public";
1026 case AT_pure_virtual: return "AT_pure_virtual";
1027 case AT_return_addr: return "AT_return_addr";
1028 case AT_abstract_origin: return "AT_abstract_origin";
1029 case AT_start_scope: return "AT_start_scope";
1030 case AT_stride_size: return "AT_stride_size";
1031 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1032 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1033 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1034 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1035 case AT_virtual: return "AT_virtual";
1037 /* GNU extensions */
1039 case AT_sf_names: return "AT_sf_names";
1040 case AT_src_info: return "AT_src_info";
1041 case AT_mac_info: return "AT_mac_info";
1042 case AT_src_coords: return "AT_src_coords";
1043 case AT_body_begin: return "AT_body_begin";
1044 case AT_body_end: return "AT_body_end";
1046 default: return "AT_<unknown>";
1050 static char *
1051 dwarf_stack_op_name (op)
1052 register unsigned op;
1054 switch (op)
1056 case OP_REG: return "OP_REG";
1057 case OP_BASEREG: return "OP_BASEREG";
1058 case OP_ADDR: return "OP_ADDR";
1059 case OP_CONST: return "OP_CONST";
1060 case OP_DEREF2: return "OP_DEREF2";
1061 case OP_DEREF4: return "OP_DEREF4";
1062 case OP_ADD: return "OP_ADD";
1063 default: return "OP_<unknown>";
1067 static char *
1068 dwarf_typemod_name (mod)
1069 register unsigned mod;
1071 switch (mod)
1073 case MOD_pointer_to: return "MOD_pointer_to";
1074 case MOD_reference_to: return "MOD_reference_to";
1075 case MOD_const: return "MOD_const";
1076 case MOD_volatile: return "MOD_volatile";
1077 default: return "MOD_<unknown>";
1081 static char *
1082 dwarf_fmt_byte_name (fmt)
1083 register unsigned fmt;
1085 switch (fmt)
1087 case FMT_FT_C_C: return "FMT_FT_C_C";
1088 case FMT_FT_C_X: return "FMT_FT_C_X";
1089 case FMT_FT_X_C: return "FMT_FT_X_C";
1090 case FMT_FT_X_X: return "FMT_FT_X_X";
1091 case FMT_UT_C_C: return "FMT_UT_C_C";
1092 case FMT_UT_C_X: return "FMT_UT_C_X";
1093 case FMT_UT_X_C: return "FMT_UT_X_C";
1094 case FMT_UT_X_X: return "FMT_UT_X_X";
1095 case FMT_ET: return "FMT_ET";
1096 default: return "FMT_<unknown>";
1100 static char *
1101 dwarf_fund_type_name (ft)
1102 register unsigned ft;
1104 switch (ft)
1106 case FT_char: return "FT_char";
1107 case FT_signed_char: return "FT_signed_char";
1108 case FT_unsigned_char: return "FT_unsigned_char";
1109 case FT_short: return "FT_short";
1110 case FT_signed_short: return "FT_signed_short";
1111 case FT_unsigned_short: return "FT_unsigned_short";
1112 case FT_integer: return "FT_integer";
1113 case FT_signed_integer: return "FT_signed_integer";
1114 case FT_unsigned_integer: return "FT_unsigned_integer";
1115 case FT_long: return "FT_long";
1116 case FT_signed_long: return "FT_signed_long";
1117 case FT_unsigned_long: return "FT_unsigned_long";
1118 case FT_pointer: return "FT_pointer";
1119 case FT_float: return "FT_float";
1120 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1121 case FT_ext_prec_float: return "FT_ext_prec_float";
1122 case FT_complex: return "FT_complex";
1123 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1124 case FT_void: return "FT_void";
1125 case FT_boolean: return "FT_boolean";
1126 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1127 case FT_label: return "FT_label";
1129 /* GNU extensions. */
1131 case FT_long_long: return "FT_long_long";
1132 case FT_signed_long_long: return "FT_signed_long_long";
1133 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1135 case FT_int8: return "FT_int8";
1136 case FT_signed_int8: return "FT_signed_int8";
1137 case FT_unsigned_int8: return "FT_unsigned_int8";
1138 case FT_int16: return "FT_int16";
1139 case FT_signed_int16: return "FT_signed_int16";
1140 case FT_unsigned_int16: return "FT_unsigned_int16";
1141 case FT_int32: return "FT_int32";
1142 case FT_signed_int32: return "FT_signed_int32";
1143 case FT_unsigned_int32: return "FT_unsigned_int32";
1144 case FT_int64: return "FT_int64";
1145 case FT_signed_int64: return "FT_signed_int64";
1146 case FT_unsigned_int64: return "FT_unsigned_int64";
1148 case FT_real32: return "FT_real32";
1149 case FT_real64: return "FT_real64";
1150 case FT_real96: return "FT_real96";
1151 case FT_real128: return "FT_real128";
1153 default: return "FT_<unknown>";
1157 /* Determine the "ultimate origin" of a decl. The decl may be an
1158 inlined instance of an inlined instance of a decl which is local
1159 to an inline function, so we have to trace all of the way back
1160 through the origin chain to find out what sort of node actually
1161 served as the original seed for the given block. */
1163 static tree
1164 decl_ultimate_origin (decl)
1165 register tree decl;
1167 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1169 if (immediate_origin == NULL)
1170 return NULL;
1171 else
1173 register tree ret_val;
1174 register tree lookahead = immediate_origin;
1178 ret_val = lookahead;
1179 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1181 while (lookahead != NULL && lookahead != ret_val);
1182 return ret_val;
1186 /* Determine the "ultimate origin" of a block. The block may be an
1187 inlined instance of an inlined instance of a block which is local
1188 to an inline function, so we have to trace all of the way back
1189 through the origin chain to find out what sort of node actually
1190 served as the original seed for the given block. */
1192 static tree
1193 block_ultimate_origin (block)
1194 register tree block;
1196 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1198 if (immediate_origin == NULL)
1199 return NULL;
1200 else
1202 register tree ret_val;
1203 register tree lookahead = immediate_origin;
1207 ret_val = lookahead;
1208 lookahead = (TREE_CODE (ret_val) == BLOCK)
1209 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1210 : NULL;
1212 while (lookahead != NULL && lookahead != ret_val);
1213 return ret_val;
1217 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1218 of a virtual function may refer to a base class, so we check the 'this'
1219 parameter. */
1221 static tree
1222 decl_class_context (decl)
1223 tree decl;
1225 tree context = NULL_TREE;
1226 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1227 context = DECL_CONTEXT (decl);
1228 else
1229 context = TYPE_MAIN_VARIANT
1230 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1232 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1233 context = NULL_TREE;
1235 return context;
1238 static void
1239 output_unsigned_leb128 (value)
1240 register unsigned long value;
1242 register unsigned long orig_value = value;
1246 register unsigned byte = (value & 0x7f);
1248 value >>= 7;
1249 if (value != 0) /* more bytes to follow */
1250 byte |= 0x80;
1251 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1252 if (flag_debug_asm && value == 0)
1253 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1254 ASM_COMMENT_START, orig_value);
1255 fputc ('\n', asm_out_file);
1257 while (value != 0);
1260 static void
1261 output_signed_leb128 (value)
1262 register long value;
1264 register long orig_value = value;
1265 register int negative = (value < 0);
1266 register int more;
1270 register unsigned byte = (value & 0x7f);
1272 value >>= 7;
1273 if (negative)
1274 value |= 0xfe000000; /* manually sign extend */
1275 if (((value == 0) && ((byte & 0x40) == 0))
1276 || ((value == -1) && ((byte & 0x40) == 1)))
1277 more = 0;
1278 else
1280 byte |= 0x80;
1281 more = 1;
1283 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1284 if (flag_debug_asm && more == 0)
1285 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1286 ASM_COMMENT_START, orig_value);
1287 fputc ('\n', asm_out_file);
1289 while (more);
1292 /**************** utility functions for attribute functions ******************/
1294 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1295 node in question represents the outermost pair of curly braces (i.e.
1296 the "body block") of a function or method.
1298 For any BLOCK node representing a "body block" of a function or method,
1299 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1300 which represents the outermost (function) scope for the function or
1301 method (i.e. the one which includes the formal parameters). The
1302 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1303 FUNCTION_DECL node.
1306 static inline int
1307 is_body_block (stmt)
1308 register tree stmt;
1310 if (TREE_CODE (stmt) == BLOCK)
1312 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1314 if (TREE_CODE (parent) == BLOCK)
1316 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1318 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1319 return 1;
1322 return 0;
1325 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1326 type code for the given type.
1328 This routine must only be called for GCC type nodes that correspond to
1329 Dwarf fundamental types.
1331 The current Dwarf draft specification calls for Dwarf fundamental types
1332 to accurately reflect the fact that a given type was either a "plain"
1333 integral type or an explicitly "signed" integral type. Unfortunately,
1334 we can't always do this, because GCC may already have thrown away the
1335 information about the precise way in which the type was originally
1336 specified, as in:
1338 typedef signed int my_type;
1340 struct s { my_type f; };
1342 Since we may be stuck here without enought information to do exactly
1343 what is called for in the Dwarf draft specification, we do the best
1344 that we can under the circumstances and always use the "plain" integral
1345 fundamental type codes for int, short, and long types. That's probably
1346 good enough. The additional accuracy called for in the current DWARF
1347 draft specification is probably never even useful in practice. */
1349 static int
1350 fundamental_type_code (type)
1351 register tree type;
1353 if (TREE_CODE (type) == ERROR_MARK)
1354 return 0;
1356 switch (TREE_CODE (type))
1358 case ERROR_MARK:
1359 return FT_void;
1361 case VOID_TYPE:
1362 return FT_void;
1364 case INTEGER_TYPE:
1365 /* Carefully distinguish all the standard types of C,
1366 without messing up if the language is not C.
1367 Note that we check only for the names that contain spaces;
1368 other names might occur by coincidence in other languages. */
1369 if (TYPE_NAME (type) != 0
1370 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1371 && DECL_NAME (TYPE_NAME (type)) != 0
1372 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1374 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1376 if (!strcmp (name, "unsigned char"))
1377 return FT_unsigned_char;
1378 if (!strcmp (name, "signed char"))
1379 return FT_signed_char;
1380 if (!strcmp (name, "unsigned int"))
1381 return FT_unsigned_integer;
1382 if (!strcmp (name, "short int"))
1383 return FT_short;
1384 if (!strcmp (name, "short unsigned int"))
1385 return FT_unsigned_short;
1386 if (!strcmp (name, "long int"))
1387 return FT_long;
1388 if (!strcmp (name, "long unsigned int"))
1389 return FT_unsigned_long;
1390 if (!strcmp (name, "long long int"))
1391 return FT_long_long; /* Not grok'ed by svr4 SDB */
1392 if (!strcmp (name, "long long unsigned int"))
1393 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1396 /* Most integer types will be sorted out above, however, for the
1397 sake of special `array index' integer types, the following code
1398 is also provided. */
1400 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1401 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1403 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1404 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1406 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1407 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1409 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1410 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1412 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1413 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1415 abort ();
1417 case REAL_TYPE:
1418 /* Carefully distinguish all the standard types of C,
1419 without messing up if the language is not C. */
1420 if (TYPE_NAME (type) != 0
1421 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1422 && DECL_NAME (TYPE_NAME (type)) != 0
1423 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1425 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1427 /* Note that here we can run afowl of a serious bug in "classic"
1428 svr4 SDB debuggers. They don't seem to understand the
1429 FT_ext_prec_float type (even though they should). */
1431 if (!strcmp (name, "long double"))
1432 return FT_ext_prec_float;
1435 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1436 return FT_dbl_prec_float;
1437 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1438 return FT_float;
1440 /* Note that here we can run afowl of a serious bug in "classic"
1441 svr4 SDB debuggers. They don't seem to understand the
1442 FT_ext_prec_float type (even though they should). */
1444 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1445 return FT_ext_prec_float;
1446 abort ();
1448 case COMPLEX_TYPE:
1449 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1451 case CHAR_TYPE:
1452 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1454 case BOOLEAN_TYPE:
1455 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1457 default:
1458 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1460 return 0;
1463 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1464 the Dwarf "root" type for the given input type. The Dwarf "root" type
1465 of a given type is generally the same as the given type, except that if
1466 the given type is a pointer or reference type, then the root type of
1467 the given type is the root type of the "basis" type for the pointer or
1468 reference type. (This definition of the "root" type is recursive.)
1469 Also, the root type of a `const' qualified type or a `volatile'
1470 qualified type is the root type of the given type without the
1471 qualifiers. */
1473 static tree
1474 root_type_1 (type, count)
1475 register tree type;
1476 register int count;
1478 /* Give up after searching 1000 levels, in case this is a recursive
1479 pointer type. Such types are possible in Ada, but it is not possible
1480 to represent them in DWARF1 debug info. */
1481 if (count > 1000)
1482 return error_mark_node;
1484 switch (TREE_CODE (type))
1486 case ERROR_MARK:
1487 return error_mark_node;
1489 case POINTER_TYPE:
1490 case REFERENCE_TYPE:
1491 return root_type_1 (TREE_TYPE (type), count+1);
1493 default:
1494 return type;
1498 static tree
1499 root_type (type)
1500 register tree type;
1502 type = root_type_1 (type, 0);
1503 if (type != error_mark_node)
1504 type = type_main_variant (type);
1505 return type;
1508 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1509 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1511 static void
1512 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1513 register tree type;
1514 register int decl_const;
1515 register int decl_volatile;
1516 register int count;
1518 if (TREE_CODE (type) == ERROR_MARK)
1519 return;
1521 /* Give up after searching 1000 levels, in case this is a recursive
1522 pointer type. Such types are possible in Ada, but it is not possible
1523 to represent them in DWARF1 debug info. */
1524 if (count > 1000)
1525 return;
1527 if (TYPE_READONLY (type) || decl_const)
1528 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1529 if (TYPE_VOLATILE (type) || decl_volatile)
1530 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1531 switch (TREE_CODE (type))
1533 case POINTER_TYPE:
1534 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1535 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1536 return;
1538 case REFERENCE_TYPE:
1539 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1540 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1541 return;
1543 case ERROR_MARK:
1544 default:
1545 return;
1549 static void
1550 write_modifier_bytes (type, decl_const, decl_volatile)
1551 register tree type;
1552 register int decl_const;
1553 register int decl_volatile;
1555 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1558 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1559 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1561 static inline int
1562 type_is_fundamental (type)
1563 register tree type;
1565 switch (TREE_CODE (type))
1567 case ERROR_MARK:
1568 case VOID_TYPE:
1569 case INTEGER_TYPE:
1570 case REAL_TYPE:
1571 case COMPLEX_TYPE:
1572 case BOOLEAN_TYPE:
1573 case CHAR_TYPE:
1574 return 1;
1576 case SET_TYPE:
1577 case ARRAY_TYPE:
1578 case RECORD_TYPE:
1579 case UNION_TYPE:
1580 case QUAL_UNION_TYPE:
1581 case ENUMERAL_TYPE:
1582 case FUNCTION_TYPE:
1583 case METHOD_TYPE:
1584 case POINTER_TYPE:
1585 case REFERENCE_TYPE:
1586 case FILE_TYPE:
1587 case OFFSET_TYPE:
1588 case LANG_TYPE:
1589 return 0;
1591 default:
1592 abort ();
1594 return 0;
1597 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1598 equate directive which will associate a symbolic name with the current DIE.
1600 The name used is an artificial label generated from the DECL_UID number
1601 associated with the given decl node. The name it gets equated to is the
1602 symbolic label that we (previously) output at the start of the DIE that
1603 we are currently generating.
1605 Calling this function while generating some "decl related" form of DIE
1606 makes it possible to later refer to the DIE which represents the given
1607 decl simply by re-generating the symbolic name from the ..._DECL node's
1608 UID number. */
1610 static void
1611 equate_decl_number_to_die_number (decl)
1612 register tree decl;
1614 /* In the case where we are generating a DIE for some ..._DECL node
1615 which represents either some inline function declaration or some
1616 entity declared within an inline function declaration/definition,
1617 setup a symbolic name for the current DIE so that we have a name
1618 for this DIE that we can easily refer to later on within
1619 AT_abstract_origin attributes. */
1621 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1622 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1624 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1625 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1626 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1629 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1630 equate directive which will associate a symbolic name with the current DIE.
1632 The name used is an artificial label generated from the TYPE_UID number
1633 associated with the given type node. The name it gets equated to is the
1634 symbolic label that we (previously) output at the start of the DIE that
1635 we are currently generating.
1637 Calling this function while generating some "type related" form of DIE
1638 makes it easy to later refer to the DIE which represents the given type
1639 simply by re-generating the alternative name from the ..._TYPE node's
1640 UID number. */
1642 static inline void
1643 equate_type_number_to_die_number (type)
1644 register tree type;
1646 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1647 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1649 /* We are generating a DIE to represent the main variant of this type
1650 (i.e the type without any const or volatile qualifiers) so in order
1651 to get the equate to come out right, we need to get the main variant
1652 itself here. */
1654 type = type_main_variant (type);
1656 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1657 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1658 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1661 static void
1662 output_reg_number (rtl)
1663 register rtx rtl;
1665 register unsigned regno = REGNO (rtl);
1667 if (regno >= FIRST_PSEUDO_REGISTER)
1669 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1670 regno);
1671 regno = 0;
1673 fprintf (asm_out_file, "\t%s\t0x%x",
1674 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1675 if (flag_debug_asm)
1677 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1678 PRINT_REG (rtl, 0, asm_out_file);
1680 fputc ('\n', asm_out_file);
1683 /* The following routine is a nice and simple transducer. It converts the
1684 RTL for a variable or parameter (resident in memory) into an equivalent
1685 Dwarf representation of a mechanism for getting the address of that same
1686 variable onto the top of a hypothetical "address evaluation" stack.
1688 When creating memory location descriptors, we are effectively trans-
1689 forming the RTL for a memory-resident object into its Dwarf postfix
1690 expression equivalent. This routine just recursively descends an
1691 RTL tree, turning it into Dwarf postfix code as it goes. */
1693 static void
1694 output_mem_loc_descriptor (rtl)
1695 register rtx rtl;
1697 /* Note that for a dynamically sized array, the location we will
1698 generate a description of here will be the lowest numbered location
1699 which is actually within the array. That's *not* necessarily the
1700 same as the zeroth element of the array. */
1702 switch (GET_CODE (rtl))
1704 case SUBREG:
1706 /* The case of a subreg may arise when we have a local (register)
1707 variable or a formal (register) parameter which doesn't quite
1708 fill up an entire register. For now, just assume that it is
1709 legitimate to make the Dwarf info refer to the whole register
1710 which contains the given subreg. */
1712 rtl = XEXP (rtl, 0);
1713 /* Drop thru. */
1715 case REG:
1717 /* Whenever a register number forms a part of the description of
1718 the method for calculating the (dynamic) address of a memory
1719 resident object, DWARF rules require the register number to
1720 be referred to as a "base register". This distinction is not
1721 based in any way upon what category of register the hardware
1722 believes the given register belongs to. This is strictly
1723 DWARF terminology we're dealing with here.
1725 Note that in cases where the location of a memory-resident data
1726 object could be expressed as:
1728 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1730 the actual DWARF location descriptor that we generate may just
1731 be OP_BASEREG (basereg). This may look deceptively like the
1732 object in question was allocated to a register (rather than
1733 in memory) so DWARF consumers need to be aware of the subtle
1734 distinction between OP_REG and OP_BASEREG. */
1736 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1737 output_reg_number (rtl);
1738 break;
1740 case MEM:
1741 output_mem_loc_descriptor (XEXP (rtl, 0));
1742 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1743 break;
1745 case CONST:
1746 case SYMBOL_REF:
1747 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1748 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1749 break;
1751 case PLUS:
1752 output_mem_loc_descriptor (XEXP (rtl, 0));
1753 output_mem_loc_descriptor (XEXP (rtl, 1));
1754 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1755 break;
1757 case CONST_INT:
1758 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1759 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1760 break;
1762 case MULT:
1763 /* If a pseudo-reg is optimized away, it is possible for it to
1764 be replaced with a MEM containing a multiply. Use a GNU extension
1765 to describe it. */
1766 output_mem_loc_descriptor (XEXP (rtl, 0));
1767 output_mem_loc_descriptor (XEXP (rtl, 1));
1768 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1769 break;
1771 default:
1772 abort ();
1776 /* Output a proper Dwarf location descriptor for a variable or parameter
1777 which is either allocated in a register or in a memory location. For
1778 a register, we just generate an OP_REG and the register number. For a
1779 memory location we provide a Dwarf postfix expression describing how to
1780 generate the (dynamic) address of the object onto the address stack. */
1782 static void
1783 output_loc_descriptor (rtl)
1784 register rtx rtl;
1786 switch (GET_CODE (rtl))
1788 case SUBREG:
1790 /* The case of a subreg may arise when we have a local (register)
1791 variable or a formal (register) parameter which doesn't quite
1792 fill up an entire register. For now, just assume that it is
1793 legitimate to make the Dwarf info refer to the whole register
1794 which contains the given subreg. */
1796 rtl = XEXP (rtl, 0);
1797 /* Drop thru. */
1799 case REG:
1800 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1801 output_reg_number (rtl);
1802 break;
1804 case MEM:
1805 output_mem_loc_descriptor (XEXP (rtl, 0));
1806 break;
1808 default:
1809 abort (); /* Should never happen */
1813 /* Given a tree node describing an array bound (either lower or upper)
1814 output a representation for that bound. */
1816 static void
1817 output_bound_representation (bound, dim_num, u_or_l)
1818 register tree bound;
1819 register unsigned dim_num; /* For multi-dimensional arrays. */
1820 register char u_or_l; /* Designates upper or lower bound. */
1822 switch (TREE_CODE (bound))
1825 case ERROR_MARK:
1826 return;
1828 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1830 case INTEGER_CST:
1831 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1832 (unsigned) TREE_INT_CST_LOW (bound));
1833 break;
1835 default:
1837 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1838 SAVE_EXPR nodes, in which case we can do something, or as
1839 an expression, which we cannot represent. */
1841 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1842 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1844 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1845 current_dienum, dim_num, u_or_l);
1847 sprintf (end_label, BOUND_END_LABEL_FMT,
1848 current_dienum, dim_num, u_or_l);
1850 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1851 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1853 /* If optimization is turned on, the SAVE_EXPRs that describe
1854 how to access the upper bound values are essentially bogus.
1855 They only describe (at best) how to get at these values at
1856 the points in the generated code right after they have just
1857 been computed. Worse yet, in the typical case, the upper
1858 bound values will not even *be* computed in the optimized
1859 code, so these SAVE_EXPRs are entirely bogus.
1861 In order to compensate for this fact, we check here to see
1862 if optimization is enabled, and if so, we effectively create
1863 an empty location description for the (unknown and unknowable)
1864 upper bound.
1866 This should not cause too much trouble for existing (stupid?)
1867 debuggers because they have to deal with empty upper bounds
1868 location descriptions anyway in order to be able to deal with
1869 incomplete array types.
1871 Of course an intelligent debugger (GDB?) should be able to
1872 comprehend that a missing upper bound specification in a
1873 array type used for a storage class `auto' local array variable
1874 indicates that the upper bound is both unknown (at compile-
1875 time) and unknowable (at run-time) due to optimization. */
1877 if (! optimize)
1879 while (TREE_CODE (bound) == NOP_EXPR
1880 || TREE_CODE (bound) == CONVERT_EXPR)
1881 bound = TREE_OPERAND (bound, 0);
1883 if (TREE_CODE (bound) == SAVE_EXPR)
1884 output_loc_descriptor
1885 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1888 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1890 break;
1895 /* Recursive function to output a sequence of value/name pairs for
1896 enumeration constants in reversed order. This is called from
1897 enumeration_type_die. */
1899 static void
1900 output_enumeral_list (link)
1901 register tree link;
1903 if (link)
1905 output_enumeral_list (TREE_CHAIN (link));
1906 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1907 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1908 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1909 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1913 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1914 which is not less than the value itself. */
1916 static inline unsigned
1917 ceiling (value, boundary)
1918 register unsigned value;
1919 register unsigned boundary;
1921 return (((value + boundary - 1) / boundary) * boundary);
1924 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1925 pointer to the declared type for the relevant field variable, or return
1926 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1928 static inline tree
1929 field_type (decl)
1930 register tree decl;
1932 register tree type;
1934 if (TREE_CODE (decl) == ERROR_MARK)
1935 return integer_type_node;
1937 type = DECL_BIT_FIELD_TYPE (decl);
1938 if (type == NULL)
1939 type = TREE_TYPE (decl);
1940 return type;
1943 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1944 node, return the alignment in bits for the type, or else return
1945 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1947 static inline unsigned
1948 simple_type_align_in_bits (type)
1949 register tree type;
1951 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1954 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1955 node, return the size in bits for the type if it is a constant, or
1956 else return the alignment for the type if the type's size is not
1957 constant, or else return BITS_PER_WORD if the type actually turns out
1958 to be an ERROR_MARK node. */
1960 static inline unsigned
1961 simple_type_size_in_bits (type)
1962 register tree type;
1964 if (TREE_CODE (type) == ERROR_MARK)
1965 return BITS_PER_WORD;
1966 else
1968 register tree type_size_tree = TYPE_SIZE (type);
1970 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1971 return TYPE_ALIGN (type);
1973 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1977 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1978 return the byte offset of the lowest addressed byte of the "containing
1979 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1980 mine what that offset is, either because the argument turns out to be a
1981 pointer to an ERROR_MARK node, or because the offset is actually variable.
1982 (We can't handle the latter case just yet.) */
1984 static unsigned
1985 field_byte_offset (decl)
1986 register tree decl;
1988 register unsigned type_align_in_bytes;
1989 register unsigned type_align_in_bits;
1990 register unsigned type_size_in_bits;
1991 register unsigned object_offset_in_align_units;
1992 register unsigned object_offset_in_bits;
1993 register unsigned object_offset_in_bytes;
1994 register tree type;
1995 register tree bitpos_tree;
1996 register tree field_size_tree;
1997 register unsigned bitpos_int;
1998 register unsigned deepest_bitpos;
1999 register unsigned field_size_in_bits;
2001 if (TREE_CODE (decl) == ERROR_MARK)
2002 return 0;
2004 if (TREE_CODE (decl) != FIELD_DECL)
2005 abort ();
2007 type = field_type (decl);
2009 bitpos_tree = DECL_FIELD_BITPOS (decl);
2010 field_size_tree = DECL_SIZE (decl);
2012 /* We cannot yet cope with fields whose positions or sizes are variable,
2013 so for now, when we see such things, we simply return 0. Someday,
2014 we may be able to handle such cases, but it will be damn difficult. */
2016 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2017 return 0;
2018 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2020 if (TREE_CODE (field_size_tree) != INTEGER_CST)
2021 return 0;
2022 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
2024 type_size_in_bits = simple_type_size_in_bits (type);
2026 type_align_in_bits = simple_type_align_in_bits (type);
2027 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2029 /* Note that the GCC front-end doesn't make any attempt to keep track
2030 of the starting bit offset (relative to the start of the containing
2031 structure type) of the hypothetical "containing object" for a bit-
2032 field. Thus, when computing the byte offset value for the start of
2033 the "containing object" of a bit-field, we must deduce this infor-
2034 mation on our own.
2036 This can be rather tricky to do in some cases. For example, handling
2037 the following structure type definition when compiling for an i386/i486
2038 target (which only aligns long long's to 32-bit boundaries) can be very
2039 tricky:
2041 struct S {
2042 int field1;
2043 long long field2:31;
2046 Fortunately, there is a simple rule-of-thumb which can be used in such
2047 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2048 the structure shown above. It decides to do this based upon one simple
2049 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2050 taining object" for each bit-field at the first (i.e. lowest addressed)
2051 legitimate alignment boundary (based upon the required minimum alignment
2052 for the declared type of the field) which it can possibly use, subject
2053 to the condition that there is still enough available space remaining
2054 in the containing object (when allocated at the selected point) to
2055 fully accommodate all of the bits of the bit-field itself.
2057 This simple rule makes it obvious why GCC allocates 8 bytes for each
2058 object of the structure type shown above. When looking for a place to
2059 allocate the "containing object" for `field2', the compiler simply tries
2060 to allocate a 64-bit "containing object" at each successive 32-bit
2061 boundary (starting at zero) until it finds a place to allocate that 64-
2062 bit field such that at least 31 contiguous (and previously unallocated)
2063 bits remain within that selected 64 bit field. (As it turns out, for
2064 the example above, the compiler finds that it is OK to allocate the
2065 "containing object" 64-bit field at bit-offset zero within the
2066 structure type.)
2068 Here we attempt to work backwards from the limited set of facts we're
2069 given, and we try to deduce from those facts, where GCC must have
2070 believed that the containing object started (within the structure type).
2072 The value we deduce is then used (by the callers of this routine) to
2073 generate AT_location and AT_bit_offset attributes for fields (both
2074 bit-fields and, in the case of AT_location, regular fields as well).
2077 /* Figure out the bit-distance from the start of the structure to the
2078 "deepest" bit of the bit-field. */
2079 deepest_bitpos = bitpos_int + field_size_in_bits;
2081 /* This is the tricky part. Use some fancy footwork to deduce where the
2082 lowest addressed bit of the containing object must be. */
2083 object_offset_in_bits
2084 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2086 /* Compute the offset of the containing object in "alignment units". */
2087 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2089 /* Compute the offset of the containing object in bytes. */
2090 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2092 /* The above code assumes that the field does not cross an alignment
2093 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2094 or if the structure is packed. If this happens, then we get an object
2095 which starts after the bitfield, which means that the bit offset is
2096 negative. Gdb fails when given negative bit offsets. We avoid this
2097 by recomputing using the first bit of the bitfield. This will give
2098 us an object which does not completely contain the bitfield, but it
2099 will be aligned, and it will contain the first bit of the bitfield. */
2100 if (object_offset_in_bits > bitpos_int)
2102 deepest_bitpos = bitpos_int + 1;
2103 object_offset_in_bits
2104 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2105 object_offset_in_align_units = (object_offset_in_bits
2106 / type_align_in_bits);
2107 object_offset_in_bytes = (object_offset_in_align_units
2108 * type_align_in_bytes);
2111 return object_offset_in_bytes;
2114 /****************************** attributes *********************************/
2116 /* The following routines are responsible for writing out the various types
2117 of Dwarf attributes (and any following data bytes associated with them).
2118 These routines are listed in order based on the numerical codes of their
2119 associated attributes. */
2121 /* Generate an AT_sibling attribute. */
2123 static inline void
2124 sibling_attribute ()
2126 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2128 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2129 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2130 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2133 /* Output the form of location attributes suitable for whole variables and
2134 whole parameters. Note that the location attributes for struct fields
2135 are generated by the routine `data_member_location_attribute' below. */
2137 static void
2138 location_attribute (rtl)
2139 register rtx rtl;
2141 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2142 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2144 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2145 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2146 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2147 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2148 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2150 /* Handle a special case. If we are about to output a location descriptor
2151 for a variable or parameter which has been optimized out of existence,
2152 don't do that. Instead we output a zero-length location descriptor
2153 value as part of the location attribute.
2155 A variable which has been optimized out of existence will have a
2156 DECL_RTL value which denotes a pseudo-reg.
2158 Currently, in some rare cases, variables can have DECL_RTL values
2159 which look like (MEM (REG pseudo-reg#)). These cases are due to
2160 bugs elsewhere in the compiler. We treat such cases
2161 as if the variable(s) in question had been optimized out of existence.
2163 Note that in all cases where we wish to express the fact that a
2164 variable has been optimized out of existence, we do not simply
2165 suppress the generation of the entire location attribute because
2166 the absence of a location attribute in certain kinds of DIEs is
2167 used to indicate something else entirely... i.e. that the DIE
2168 represents an object declaration, but not a definition. So saith
2169 the PLSIG.
2172 if (! is_pseudo_reg (rtl)
2173 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2174 output_loc_descriptor (rtl);
2176 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2179 /* Output the specialized form of location attribute used for data members
2180 of struct and union types.
2182 In the special case of a FIELD_DECL node which represents a bit-field,
2183 the "offset" part of this special location descriptor must indicate the
2184 distance in bytes from the lowest-addressed byte of the containing
2185 struct or union type to the lowest-addressed byte of the "containing
2186 object" for the bit-field. (See the `field_byte_offset' function above.)
2188 For any given bit-field, the "containing object" is a hypothetical
2189 object (of some integral or enum type) within which the given bit-field
2190 lives. The type of this hypothetical "containing object" is always the
2191 same as the declared type of the individual bit-field itself (for GCC
2192 anyway... the DWARF spec doesn't actually mandate this).
2194 Note that it is the size (in bytes) of the hypothetical "containing
2195 object" which will be given in the AT_byte_size attribute for this
2196 bit-field. (See the `byte_size_attribute' function below.) It is
2197 also used when calculating the value of the AT_bit_offset attribute.
2198 (See the `bit_offset_attribute' function below.) */
2200 static void
2201 data_member_location_attribute (t)
2202 register tree t;
2204 register unsigned object_offset_in_bytes;
2205 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2206 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2208 if (TREE_CODE (t) == TREE_VEC)
2209 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2210 else
2211 object_offset_in_bytes = field_byte_offset (t);
2213 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2214 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2215 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2216 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2217 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2218 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2219 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2220 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2221 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2224 /* Output an AT_const_value attribute for a variable or a parameter which
2225 does not have a "location" either in memory or in a register. These
2226 things can arise in GNU C when a constant is passed as an actual
2227 parameter to an inlined function. They can also arise in C++ where
2228 declared constants do not necessarily get memory "homes". */
2230 static void
2231 const_value_attribute (rtl)
2232 register rtx rtl;
2234 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2235 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2237 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2238 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2239 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2240 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2241 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2243 switch (GET_CODE (rtl))
2245 case CONST_INT:
2246 /* Note that a CONST_INT rtx could represent either an integer or
2247 a floating-point constant. A CONST_INT is used whenever the
2248 constant will fit into a single word. In all such cases, the
2249 original mode of the constant value is wiped out, and the
2250 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2251 precise mode information for these constants, we always just
2252 output them using 4 bytes. */
2254 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2255 break;
2257 case CONST_DOUBLE:
2258 /* Note that a CONST_DOUBLE rtx could represent either an integer
2259 or a floating-point constant. A CONST_DOUBLE is used whenever
2260 the constant requires more than one word in order to be adequately
2261 represented. In all such cases, the original mode of the constant
2262 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2263 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2265 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2266 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2267 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2268 break;
2270 case CONST_STRING:
2271 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2272 break;
2274 case SYMBOL_REF:
2275 case LABEL_REF:
2276 case CONST:
2277 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2278 break;
2280 case PLUS:
2281 /* In cases where an inlined instance of an inline function is passed
2282 the address of an `auto' variable (which is local to the caller)
2283 we can get a situation where the DECL_RTL of the artificial
2284 local variable (for the inlining) which acts as a stand-in for
2285 the corresponding formal parameter (of the inline function)
2286 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2287 This is not exactly a compile-time constant expression, but it
2288 isn't the address of the (artificial) local variable either.
2289 Rather, it represents the *value* which the artificial local
2290 variable always has during its lifetime. We currently have no
2291 way to represent such quasi-constant values in Dwarf, so for now
2292 we just punt and generate an AT_const_value attribute with form
2293 FORM_BLOCK4 and a length of zero. */
2294 break;
2296 default:
2297 abort (); /* No other kinds of rtx should be possible here. */
2300 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2303 /* Generate *either* an AT_location attribute or else an AT_const_value
2304 data attribute for a variable or a parameter. We generate the
2305 AT_const_value attribute only in those cases where the given
2306 variable or parameter does not have a true "location" either in
2307 memory or in a register. This can happen (for example) when a
2308 constant is passed as an actual argument in a call to an inline
2309 function. (It's possible that these things can crop up in other
2310 ways also.) Note that one type of constant value which can be
2311 passed into an inlined function is a constant pointer. This can
2312 happen for example if an actual argument in an inlined function
2313 call evaluates to a compile-time constant address. */
2315 static void
2316 location_or_const_value_attribute (decl)
2317 register tree decl;
2319 register rtx rtl;
2321 if (TREE_CODE (decl) == ERROR_MARK)
2322 return;
2324 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2326 /* Should never happen. */
2327 abort ();
2328 return;
2331 /* Here we have to decide where we are going to say the parameter "lives"
2332 (as far as the debugger is concerned). We only have a couple of choices.
2333 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2334 normally indicates where the parameter lives during most of the activa-
2335 tion of the function. If optimization is enabled however, this could
2336 be either NULL or else a pseudo-reg. Both of those cases indicate that
2337 the parameter doesn't really live anywhere (as far as the code generation
2338 parts of GCC are concerned) during most of the function's activation.
2339 That will happen (for example) if the parameter is never referenced
2340 within the function.
2342 We could just generate a location descriptor here for all non-NULL
2343 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2344 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2345 cases where DECL_RTL is NULL or is a pseudo-reg.
2347 Note however that we can only get away with using DECL_INCOMING_RTL as
2348 a backup substitute for DECL_RTL in certain limited cases. In cases
2349 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2350 we can be sure that the parameter was passed using the same type as it
2351 is declared to have within the function, and that its DECL_INCOMING_RTL
2352 points us to a place where a value of that type is passed. In cases
2353 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2354 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2355 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2356 points us to a value of some type which is *different* from the type
2357 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2358 to generate a location attribute in such cases, the debugger would
2359 end up (for example) trying to fetch a `float' from a place which
2360 actually contains the first part of a `double'. That would lead to
2361 really incorrect and confusing output at debug-time, and we don't
2362 want that now do we?
2364 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2365 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2366 couple of cute exceptions however. On little-endian machines we can
2367 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2368 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2369 an integral type which is smaller than TREE_TYPE(decl). These cases
2370 arise when (on a little-endian machine) a non-prototyped function has
2371 a parameter declared to be of type `short' or `char'. In such cases,
2372 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2373 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2374 passed `int' value. If the debugger then uses that address to fetch a
2375 `short' or a `char' (on a little-endian machine) the result will be the
2376 correct data, so we allow for such exceptional cases below.
2378 Note that our goal here is to describe the place where the given formal
2379 parameter lives during most of the function's activation (i.e. between
2380 the end of the prologue and the start of the epilogue). We'll do that
2381 as best as we can. Note however that if the given formal parameter is
2382 modified sometime during the execution of the function, then a stack
2383 backtrace (at debug-time) will show the function as having been called
2384 with the *new* value rather than the value which was originally passed
2385 in. This happens rarely enough that it is not a major problem, but it
2386 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2387 may generate two additional attributes for any given TAG_formal_parameter
2388 DIE which will describe the "passed type" and the "passed location" for
2389 the given formal parameter in addition to the attributes we now generate
2390 to indicate the "declared type" and the "active location" for each
2391 parameter. This additional set of attributes could be used by debuggers
2392 for stack backtraces.
2394 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2395 can be NULL also. This happens (for example) for inlined-instances of
2396 inline function formal parameters which are never referenced. This really
2397 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2398 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2399 these values for inlined instances of inline function parameters, so
2400 when we see such cases, we are just out-of-luck for the time
2401 being (until integrate.c gets fixed).
2404 /* Use DECL_RTL as the "location" unless we find something better. */
2405 rtl = DECL_RTL (decl);
2407 if (TREE_CODE (decl) == PARM_DECL)
2408 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2410 /* This decl represents a formal parameter which was optimized out. */
2411 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2412 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2414 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2415 *all* cases where (rtl == NULL_RTX) just below. */
2417 if (declared_type == passed_type)
2418 rtl = DECL_INCOMING_RTL (decl);
2419 else if (! BYTES_BIG_ENDIAN)
2420 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2421 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2422 rtl = DECL_INCOMING_RTL (decl);
2425 if (rtl == NULL_RTX)
2426 return;
2428 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2429 #ifdef LEAF_REG_REMAP
2430 if (leaf_function)
2431 leaf_renumber_regs_insn (rtl);
2432 #endif
2434 switch (GET_CODE (rtl))
2436 case ADDRESSOF:
2437 /* The address of a variable that was optimized away; don't emit
2438 anything. */
2439 break;
2441 case CONST_INT:
2442 case CONST_DOUBLE:
2443 case CONST_STRING:
2444 case SYMBOL_REF:
2445 case LABEL_REF:
2446 case CONST:
2447 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2448 const_value_attribute (rtl);
2449 break;
2451 case MEM:
2452 case REG:
2453 case SUBREG:
2454 location_attribute (rtl);
2455 break;
2457 case CONCAT:
2458 /* ??? CONCAT is used for complex variables, which may have the real
2459 part stored in one place and the imag part stored somewhere else.
2460 DWARF1 has no way to describe a variable that lives in two different
2461 places, so we just describe where the first part lives, and hope that
2462 the second part is stored after it. */
2463 location_attribute (XEXP (rtl, 0));
2464 break;
2466 default:
2467 abort (); /* Should never happen. */
2471 /* Generate an AT_name attribute given some string value to be included as
2472 the value of the attribute. */
2474 static inline void
2475 name_attribute (name_string)
2476 register char *name_string;
2478 if (name_string && *name_string)
2480 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2481 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2485 static inline void
2486 fund_type_attribute (ft_code)
2487 register unsigned ft_code;
2489 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2490 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2493 static void
2494 mod_fund_type_attribute (type, decl_const, decl_volatile)
2495 register tree type;
2496 register int decl_const;
2497 register int decl_volatile;
2499 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2500 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2502 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2503 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2504 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2505 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2506 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2507 write_modifier_bytes (type, decl_const, decl_volatile);
2508 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2509 fundamental_type_code (root_type (type)));
2510 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2513 static inline void
2514 user_def_type_attribute (type)
2515 register tree type;
2517 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2519 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2520 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2521 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2524 static void
2525 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2526 register tree type;
2527 register int decl_const;
2528 register int decl_volatile;
2530 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2531 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2532 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2534 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2535 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2536 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2537 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2538 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2539 write_modifier_bytes (type, decl_const, decl_volatile);
2540 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2541 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2542 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2545 #ifdef USE_ORDERING_ATTRIBUTE
2546 static inline void
2547 ordering_attribute (ordering)
2548 register unsigned ordering;
2550 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2551 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2553 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2555 /* Note that the block of subscript information for an array type also
2556 includes information about the element type of type given array type. */
2558 static void
2559 subscript_data_attribute (type)
2560 register tree type;
2562 register unsigned dimension_number;
2563 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2564 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2566 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2567 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2568 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2569 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2570 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2572 /* The GNU compilers represent multidimensional array types as sequences
2573 of one dimensional array types whose element types are themselves array
2574 types. Here we squish that down, so that each multidimensional array
2575 type gets only one array_type DIE in the Dwarf debugging info. The
2576 draft Dwarf specification say that we are allowed to do this kind
2577 of compression in C (because there is no difference between an
2578 array or arrays and a multidimensional array in C) but for other
2579 source languages (e.g. Ada) we probably shouldn't do this. */
2581 for (dimension_number = 0;
2582 TREE_CODE (type) == ARRAY_TYPE;
2583 type = TREE_TYPE (type), dimension_number++)
2585 register tree domain = TYPE_DOMAIN (type);
2587 /* Arrays come in three flavors. Unspecified bounds, fixed
2588 bounds, and (in GNU C only) variable bounds. Handle all
2589 three forms here. */
2591 if (domain)
2593 /* We have an array type with specified bounds. */
2595 register tree lower = TYPE_MIN_VALUE (domain);
2596 register tree upper = TYPE_MAX_VALUE (domain);
2598 /* Handle only fundamental types as index types for now. */
2600 if (! type_is_fundamental (domain))
2601 abort ();
2603 /* Output the representation format byte for this dimension. */
2605 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2606 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2607 (upper && TREE_CODE (upper) == INTEGER_CST)));
2609 /* Output the index type for this dimension. */
2611 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2612 fundamental_type_code (domain));
2614 /* Output the representation for the lower bound. */
2616 output_bound_representation (lower, dimension_number, 'l');
2618 /* Output the representation for the upper bound. */
2620 output_bound_representation (upper, dimension_number, 'u');
2622 else
2624 /* We have an array type with an unspecified length. For C and
2625 C++ we can assume that this really means that (a) the index
2626 type is an integral type, and (b) the lower bound is zero.
2627 Note that Dwarf defines the representation of an unspecified
2628 (upper) bound as being a zero-length location description. */
2630 /* Output the array-bounds format byte. */
2632 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2634 /* Output the (assumed) index type. */
2636 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2638 /* Output the (assumed) lower bound (constant) value. */
2640 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2642 /* Output the (empty) location description for the upper bound. */
2644 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2648 /* Output the prefix byte that says that the element type is coming up. */
2650 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2652 /* Output a representation of the type of the elements of this array type. */
2654 type_attribute (type, 0, 0);
2656 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2659 static void
2660 byte_size_attribute (tree_node)
2661 register tree tree_node;
2663 register unsigned size;
2665 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2666 switch (TREE_CODE (tree_node))
2668 case ERROR_MARK:
2669 size = 0;
2670 break;
2672 case ENUMERAL_TYPE:
2673 case RECORD_TYPE:
2674 case UNION_TYPE:
2675 case QUAL_UNION_TYPE:
2676 case ARRAY_TYPE:
2677 size = int_size_in_bytes (tree_node);
2678 break;
2680 case FIELD_DECL:
2681 /* For a data member of a struct or union, the AT_byte_size is
2682 generally given as the number of bytes normally allocated for
2683 an object of the *declared* type of the member itself. This
2684 is true even for bit-fields. */
2685 size = simple_type_size_in_bits (field_type (tree_node))
2686 / BITS_PER_UNIT;
2687 break;
2689 default:
2690 abort ();
2693 /* Note that `size' might be -1 when we get to this point. If it
2694 is, that indicates that the byte size of the entity in question
2695 is variable. We have no good way of expressing this fact in Dwarf
2696 at the present time, so just let the -1 pass on through. */
2698 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2701 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2702 which specifies the distance in bits from the highest order bit of the
2703 "containing object" for the bit-field to the highest order bit of the
2704 bit-field itself.
2706 For any given bit-field, the "containing object" is a hypothetical
2707 object (of some integral or enum type) within which the given bit-field
2708 lives. The type of this hypothetical "containing object" is always the
2709 same as the declared type of the individual bit-field itself.
2711 The determination of the exact location of the "containing object" for
2712 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2713 function (above).
2715 Note that it is the size (in bytes) of the hypothetical "containing
2716 object" which will be given in the AT_byte_size attribute for this
2717 bit-field. (See `byte_size_attribute' above.) */
2719 static inline void
2720 bit_offset_attribute (decl)
2721 register tree decl;
2723 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2724 register tree type = DECL_BIT_FIELD_TYPE (decl);
2725 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2726 register unsigned bitpos_int;
2727 register unsigned highest_order_object_bit_offset;
2728 register unsigned highest_order_field_bit_offset;
2729 register unsigned bit_offset;
2731 /* Must be a bit field. */
2732 if (!type
2733 || TREE_CODE (decl) != FIELD_DECL)
2734 abort ();
2736 /* We can't yet handle bit-fields whose offsets are variable, so if we
2737 encounter such things, just return without generating any attribute
2738 whatsoever. */
2740 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2741 return;
2742 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2744 /* Note that the bit offset is always the distance (in bits) from the
2745 highest-order bit of the "containing object" to the highest-order
2746 bit of the bit-field itself. Since the "high-order end" of any
2747 object or field is different on big-endian and little-endian machines,
2748 the computation below must take account of these differences. */
2750 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2751 highest_order_field_bit_offset = bitpos_int;
2753 if (! BYTES_BIG_ENDIAN)
2755 highest_order_field_bit_offset
2756 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2758 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2761 bit_offset =
2762 (! BYTES_BIG_ENDIAN
2763 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2764 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2766 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2767 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2770 /* For a FIELD_DECL node which represents a bit field, output an attribute
2771 which specifies the length in bits of the given field. */
2773 static inline void
2774 bit_size_attribute (decl)
2775 register tree decl;
2777 /* Must be a field and a bit field. */
2778 if (TREE_CODE (decl) != FIELD_DECL
2779 || ! DECL_BIT_FIELD_TYPE (decl))
2780 abort ();
2782 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2783 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2784 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2787 /* The following routine outputs the `element_list' attribute for enumeration
2788 type DIEs. The element_lits attribute includes the names and values of
2789 all of the enumeration constants associated with the given enumeration
2790 type. */
2792 static inline void
2793 element_list_attribute (element)
2794 register tree element;
2796 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2797 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2799 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2800 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2801 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2802 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2803 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2805 /* Here we output a list of value/name pairs for each enumeration constant
2806 defined for this enumeration type (as required), but we do it in REVERSE
2807 order. The order is the one required by the draft #5 Dwarf specification
2808 published by the UI/PLSIG. */
2810 output_enumeral_list (element); /* Recursively output the whole list. */
2812 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2815 /* Generate an AT_stmt_list attribute. These are normally present only in
2816 DIEs with a TAG_compile_unit tag. */
2818 static inline void
2819 stmt_list_attribute (label)
2820 register char *label;
2822 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2823 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2824 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2827 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2828 for a subroutine DIE. */
2830 static inline void
2831 low_pc_attribute (asm_low_label)
2832 register char *asm_low_label;
2834 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2835 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2838 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2839 subroutine DIE. */
2841 static inline void
2842 high_pc_attribute (asm_high_label)
2843 register char *asm_high_label;
2845 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2846 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2849 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2851 static inline void
2852 body_begin_attribute (asm_begin_label)
2853 register char *asm_begin_label;
2855 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2856 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2859 /* Generate an AT_body_end attribute for a subroutine DIE. */
2861 static inline void
2862 body_end_attribute (asm_end_label)
2863 register char *asm_end_label;
2865 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2866 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2869 /* Generate an AT_language attribute given a LANG value. These attributes
2870 are used only within TAG_compile_unit DIEs. */
2872 static inline void
2873 language_attribute (language_code)
2874 register unsigned language_code;
2876 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2877 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2880 static inline void
2881 member_attribute (context)
2882 register tree context;
2884 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2886 /* Generate this attribute only for members in C++. */
2888 if (context != NULL && is_tagged_type (context))
2890 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2891 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2892 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2896 static inline void
2897 string_length_attribute (upper_bound)
2898 register tree upper_bound;
2900 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2901 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2903 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2904 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2905 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2906 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2907 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2908 output_bound_representation (upper_bound, 0, 'u');
2909 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2912 static inline void
2913 comp_dir_attribute (dirname)
2914 register char *dirname;
2916 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2917 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2920 static inline void
2921 sf_names_attribute (sf_names_start_label)
2922 register char *sf_names_start_label;
2924 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2925 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2926 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2929 static inline void
2930 src_info_attribute (src_info_start_label)
2931 register char *src_info_start_label;
2933 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2934 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2935 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2938 static inline void
2939 mac_info_attribute (mac_info_start_label)
2940 register char *mac_info_start_label;
2942 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2943 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2944 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2947 static inline void
2948 prototyped_attribute (func_type)
2949 register tree func_type;
2951 if ((strcmp (language_string, "GNU C") == 0)
2952 && (TYPE_ARG_TYPES (func_type) != NULL))
2954 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2955 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2959 static inline void
2960 producer_attribute (producer)
2961 register char *producer;
2963 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2964 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2967 static inline void
2968 inline_attribute (decl)
2969 register tree decl;
2971 if (DECL_INLINE (decl))
2973 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2974 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2978 static inline void
2979 containing_type_attribute (containing_type)
2980 register tree containing_type;
2982 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2984 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2985 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2986 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2989 static inline void
2990 abstract_origin_attribute (origin)
2991 register tree origin;
2993 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2995 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2996 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2998 case 'd':
2999 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
3000 break;
3002 case 't':
3003 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3004 break;
3006 default:
3007 abort (); /* Should never happen. */
3010 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3013 #ifdef DWARF_DECL_COORDINATES
3014 static inline void
3015 src_coords_attribute (src_fileno, src_lineno)
3016 register unsigned src_fileno;
3017 register unsigned src_lineno;
3019 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3020 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3021 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3023 #endif /* defined(DWARF_DECL_COORDINATES) */
3025 static inline void
3026 pure_or_virtual_attribute (func_decl)
3027 register tree func_decl;
3029 if (DECL_VIRTUAL_P (func_decl))
3031 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3032 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3033 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3034 else
3035 #endif
3036 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3037 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3041 /************************* end of attributes *****************************/
3043 /********************* utility routines for DIEs *************************/
3045 /* Output an AT_name attribute and an AT_src_coords attribute for the
3046 given decl, but only if it actually has a name. */
3048 static void
3049 name_and_src_coords_attributes (decl)
3050 register tree decl;
3052 register tree decl_name = DECL_NAME (decl);
3054 if (decl_name && IDENTIFIER_POINTER (decl_name))
3056 name_attribute (IDENTIFIER_POINTER (decl_name));
3057 #ifdef DWARF_DECL_COORDINATES
3059 register unsigned file_index;
3061 /* This is annoying, but we have to pop out of the .debug section
3062 for a moment while we call `lookup_filename' because calling it
3063 may cause a temporary switch into the .debug_sfnames section and
3064 most svr4 assemblers are not smart enough be be able to nest
3065 section switches to any depth greater than one. Note that we
3066 also can't skirt this issue by delaying all output to the
3067 .debug_sfnames section unit the end of compilation because that
3068 would cause us to have inter-section forward references and
3069 Fred Fish sez that m68k/svr4 assemblers botch those. */
3071 ASM_OUTPUT_POP_SECTION (asm_out_file);
3072 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3073 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3075 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3077 #endif /* defined(DWARF_DECL_COORDINATES) */
3081 /* Many forms of DIEs contain a "type description" part. The following
3082 routine writes out these "type descriptor" parts. */
3084 static void
3085 type_attribute (type, decl_const, decl_volatile)
3086 register tree type;
3087 register int decl_const;
3088 register int decl_volatile;
3090 register enum tree_code code = TREE_CODE (type);
3091 register int root_type_modified;
3093 if (code == ERROR_MARK)
3094 return;
3096 /* Handle a special case. For functions whose return type is void,
3097 we generate *no* type attribute. (Note that no object may have
3098 type `void', so this only applies to function return types. */
3100 if (code == VOID_TYPE)
3101 return;
3103 /* If this is a subtype, find the underlying type. Eventually,
3104 this should write out the appropriate subtype info. */
3105 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3106 && TREE_TYPE (type) != 0)
3107 type = TREE_TYPE (type), code = TREE_CODE (type);
3109 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3110 || decl_const || decl_volatile
3111 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3113 if (type_is_fundamental (root_type (type)))
3115 if (root_type_modified)
3116 mod_fund_type_attribute (type, decl_const, decl_volatile);
3117 else
3118 fund_type_attribute (fundamental_type_code (type));
3120 else
3122 if (root_type_modified)
3123 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3124 else
3125 /* We have to get the type_main_variant here (and pass that to the
3126 `user_def_type_attribute' routine) because the ..._TYPE node we
3127 have might simply be a *copy* of some original type node (where
3128 the copy was created to help us keep track of typedef names)
3129 and that copy might have a different TYPE_UID from the original
3130 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3131 is labeling a given type DIE for future reference, it always and
3132 only creates labels for DIEs representing *main variants*, and it
3133 never even knows about non-main-variants.) */
3134 user_def_type_attribute (type_main_variant (type));
3138 /* Given a tree pointer to a struct, class, union, or enum type node, return
3139 a pointer to the (string) tag name for the given type, or zero if the
3140 type was declared without a tag. */
3142 static char *
3143 type_tag (type)
3144 register tree type;
3146 register char *name = 0;
3148 if (TYPE_NAME (type) != 0)
3150 register tree t = 0;
3152 /* Find the IDENTIFIER_NODE for the type name. */
3153 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3154 t = TYPE_NAME (type);
3156 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3157 a TYPE_DECL node, regardless of whether or not a `typedef' was
3158 involved. */
3159 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3160 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3161 t = DECL_NAME (TYPE_NAME (type));
3163 /* Now get the name as a string, or invent one. */
3164 if (t != 0)
3165 name = IDENTIFIER_POINTER (t);
3168 return (name == 0 || *name == '\0') ? 0 : name;
3171 static inline void
3172 dienum_push ()
3174 /* Start by checking if the pending_sibling_stack needs to be expanded.
3175 If necessary, expand it. */
3177 if (pending_siblings == pending_siblings_allocated)
3179 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3180 pending_sibling_stack
3181 = (unsigned *) xrealloc (pending_sibling_stack,
3182 pending_siblings_allocated * sizeof(unsigned));
3185 pending_siblings++;
3186 NEXT_DIE_NUM = next_unused_dienum++;
3189 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3190 NEXT_DIE_NUM. */
3192 static inline void
3193 dienum_pop ()
3195 pending_siblings--;
3198 static inline tree
3199 member_declared_type (member)
3200 register tree member;
3202 return (DECL_BIT_FIELD_TYPE (member))
3203 ? DECL_BIT_FIELD_TYPE (member)
3204 : TREE_TYPE (member);
3207 /* Get the function's label, as described by its RTL.
3208 This may be different from the DECL_NAME name used
3209 in the source file. */
3211 static char *
3212 function_start_label (decl)
3213 register tree decl;
3215 rtx x;
3216 char *fnname;
3218 x = DECL_RTL (decl);
3219 if (GET_CODE (x) != MEM)
3220 abort ();
3221 x = XEXP (x, 0);
3222 if (GET_CODE (x) != SYMBOL_REF)
3223 abort ();
3224 fnname = XSTR (x, 0);
3225 return fnname;
3229 /******************************* DIEs ************************************/
3231 /* Output routines for individual types of DIEs. */
3233 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3235 static void
3236 output_array_type_die (arg)
3237 register void *arg;
3239 register tree type = arg;
3241 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3242 sibling_attribute ();
3243 equate_type_number_to_die_number (type);
3244 member_attribute (TYPE_CONTEXT (type));
3246 /* I believe that we can default the array ordering. SDB will probably
3247 do the right things even if AT_ordering is not present. It's not
3248 even an issue until we start to get into multidimensional arrays
3249 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3250 dimensional arrays, then we'll have to put the AT_ordering attribute
3251 back in. (But if and when we find out that we need to put these in,
3252 we will only do so for multidimensional arrays. After all, we don't
3253 want to waste space in the .debug section now do we?) */
3255 #ifdef USE_ORDERING_ATTRIBUTE
3256 ordering_attribute (ORD_row_major);
3257 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3259 subscript_data_attribute (type);
3262 static void
3263 output_set_type_die (arg)
3264 register void *arg;
3266 register tree type = arg;
3268 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3269 sibling_attribute ();
3270 equate_type_number_to_die_number (type);
3271 member_attribute (TYPE_CONTEXT (type));
3272 type_attribute (TREE_TYPE (type), 0, 0);
3275 #if 0
3276 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3278 static void
3279 output_entry_point_die (arg)
3280 register void *arg;
3282 register tree decl = arg;
3283 register tree origin = decl_ultimate_origin (decl);
3285 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3286 sibling_attribute ();
3287 dienum_push ();
3288 if (origin != NULL)
3289 abstract_origin_attribute (origin);
3290 else
3292 name_and_src_coords_attributes (decl);
3293 member_attribute (DECL_CONTEXT (decl));
3294 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3296 if (DECL_ABSTRACT (decl))
3297 equate_decl_number_to_die_number (decl);
3298 else
3299 low_pc_attribute (function_start_label (decl));
3301 #endif
3303 /* Output a DIE to represent an inlined instance of an enumeration type. */
3305 static void
3306 output_inlined_enumeration_type_die (arg)
3307 register void *arg;
3309 register tree type = arg;
3311 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3312 sibling_attribute ();
3313 if (!TREE_ASM_WRITTEN (type))
3314 abort ();
3315 abstract_origin_attribute (type);
3318 /* Output a DIE to represent an inlined instance of a structure type. */
3320 static void
3321 output_inlined_structure_type_die (arg)
3322 register void *arg;
3324 register tree type = arg;
3326 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3327 sibling_attribute ();
3328 if (!TREE_ASM_WRITTEN (type))
3329 abort ();
3330 abstract_origin_attribute (type);
3333 /* Output a DIE to represent an inlined instance of a union type. */
3335 static void
3336 output_inlined_union_type_die (arg)
3337 register void *arg;
3339 register tree type = arg;
3341 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3342 sibling_attribute ();
3343 if (!TREE_ASM_WRITTEN (type))
3344 abort ();
3345 abstract_origin_attribute (type);
3348 /* Output a DIE to represent an enumeration type. Note that these DIEs
3349 include all of the information about the enumeration values also.
3350 This information is encoded into the element_list attribute. */
3352 static void
3353 output_enumeration_type_die (arg)
3354 register void *arg;
3356 register tree type = arg;
3358 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3359 sibling_attribute ();
3360 equate_type_number_to_die_number (type);
3361 name_attribute (type_tag (type));
3362 member_attribute (TYPE_CONTEXT (type));
3364 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3365 given enum type is incomplete, do not generate the AT_byte_size
3366 attribute or the AT_element_list attribute. */
3368 if (TYPE_SIZE (type))
3370 byte_size_attribute (type);
3371 element_list_attribute (TYPE_FIELDS (type));
3375 /* Output a DIE to represent either a real live formal parameter decl or
3376 to represent just the type of some formal parameter position in some
3377 function type.
3379 Note that this routine is a bit unusual because its argument may be
3380 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3381 represents an inlining of some PARM_DECL) or else some sort of a
3382 ..._TYPE node. If it's the former then this function is being called
3383 to output a DIE to represent a formal parameter object (or some inlining
3384 thereof). If it's the latter, then this function is only being called
3385 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3386 formal argument type of some subprogram type. */
3388 static void
3389 output_formal_parameter_die (arg)
3390 register void *arg;
3392 register tree node = arg;
3394 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3395 sibling_attribute ();
3397 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3399 case 'd': /* We were called with some kind of a ..._DECL node. */
3401 register tree origin = decl_ultimate_origin (node);
3403 if (origin != NULL)
3404 abstract_origin_attribute (origin);
3405 else
3407 name_and_src_coords_attributes (node);
3408 type_attribute (TREE_TYPE (node),
3409 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3411 if (DECL_ABSTRACT (node))
3412 equate_decl_number_to_die_number (node);
3413 else
3414 location_or_const_value_attribute (node);
3416 break;
3418 case 't': /* We were called with some kind of a ..._TYPE node. */
3419 type_attribute (node, 0, 0);
3420 break;
3422 default:
3423 abort (); /* Should never happen. */
3427 /* Output a DIE to represent a declared function (either file-scope
3428 or block-local) which has "external linkage" (according to ANSI-C). */
3430 static void
3431 output_global_subroutine_die (arg)
3432 register void *arg;
3434 register tree decl = arg;
3435 register tree origin = decl_ultimate_origin (decl);
3437 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3438 sibling_attribute ();
3439 dienum_push ();
3440 if (origin != NULL)
3441 abstract_origin_attribute (origin);
3442 else
3444 register tree type = TREE_TYPE (decl);
3446 name_and_src_coords_attributes (decl);
3447 inline_attribute (decl);
3448 prototyped_attribute (type);
3449 member_attribute (DECL_CONTEXT (decl));
3450 type_attribute (TREE_TYPE (type), 0, 0);
3451 pure_or_virtual_attribute (decl);
3453 if (DECL_ABSTRACT (decl))
3454 equate_decl_number_to_die_number (decl);
3455 else
3457 if (! DECL_EXTERNAL (decl) && ! in_class
3458 && decl == current_function_decl)
3460 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3462 low_pc_attribute (function_start_label (decl));
3463 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3464 high_pc_attribute (label);
3465 if (use_gnu_debug_info_extensions)
3467 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3468 body_begin_attribute (label);
3469 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3470 body_end_attribute (label);
3476 /* Output a DIE to represent a declared data object (either file-scope
3477 or block-local) which has "external linkage" (according to ANSI-C). */
3479 static void
3480 output_global_variable_die (arg)
3481 register void *arg;
3483 register tree decl = arg;
3484 register tree origin = decl_ultimate_origin (decl);
3486 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3487 sibling_attribute ();
3488 if (origin != NULL)
3489 abstract_origin_attribute (origin);
3490 else
3492 name_and_src_coords_attributes (decl);
3493 member_attribute (DECL_CONTEXT (decl));
3494 type_attribute (TREE_TYPE (decl),
3495 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3497 if (DECL_ABSTRACT (decl))
3498 equate_decl_number_to_die_number (decl);
3499 else
3501 if (! DECL_EXTERNAL (decl) && ! in_class
3502 && current_function_decl == decl_function_context (decl))
3503 location_or_const_value_attribute (decl);
3507 static void
3508 output_label_die (arg)
3509 register void *arg;
3511 register tree decl = arg;
3512 register tree origin = decl_ultimate_origin (decl);
3514 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3515 sibling_attribute ();
3516 if (origin != NULL)
3517 abstract_origin_attribute (origin);
3518 else
3519 name_and_src_coords_attributes (decl);
3520 if (DECL_ABSTRACT (decl))
3521 equate_decl_number_to_die_number (decl);
3522 else
3524 register rtx insn = DECL_RTL (decl);
3526 if (GET_CODE (insn) == CODE_LABEL)
3528 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3530 /* When optimization is enabled (via -O) some parts of the compiler
3531 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3532 represent source-level labels which were explicitly declared by
3533 the user. This really shouldn't be happening though, so catch
3534 it if it ever does happen. */
3536 if (INSN_DELETED_P (insn))
3537 abort (); /* Should never happen. */
3539 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3540 (unsigned) INSN_UID (insn));
3541 low_pc_attribute (label);
3546 static void
3547 output_lexical_block_die (arg)
3548 register void *arg;
3550 register tree stmt = arg;
3552 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3553 sibling_attribute ();
3554 dienum_push ();
3555 if (! BLOCK_ABSTRACT (stmt))
3557 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3558 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3560 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3561 low_pc_attribute (begin_label);
3562 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3563 high_pc_attribute (end_label);
3567 static void
3568 output_inlined_subroutine_die (arg)
3569 register void *arg;
3571 register tree stmt = arg;
3573 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3574 sibling_attribute ();
3575 dienum_push ();
3576 abstract_origin_attribute (block_ultimate_origin (stmt));
3577 if (! BLOCK_ABSTRACT (stmt))
3579 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3580 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3582 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3583 low_pc_attribute (begin_label);
3584 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3585 high_pc_attribute (end_label);
3589 /* Output a DIE to represent a declared data object (either file-scope
3590 or block-local) which has "internal linkage" (according to ANSI-C). */
3592 static void
3593 output_local_variable_die (arg)
3594 register void *arg;
3596 register tree decl = arg;
3597 register tree origin = decl_ultimate_origin (decl);
3599 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3600 sibling_attribute ();
3601 if (origin != NULL)
3602 abstract_origin_attribute (origin);
3603 else
3605 name_and_src_coords_attributes (decl);
3606 member_attribute (DECL_CONTEXT (decl));
3607 type_attribute (TREE_TYPE (decl),
3608 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3610 if (DECL_ABSTRACT (decl))
3611 equate_decl_number_to_die_number (decl);
3612 else
3613 location_or_const_value_attribute (decl);
3616 static void
3617 output_member_die (arg)
3618 register void *arg;
3620 register tree decl = arg;
3622 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3623 sibling_attribute ();
3624 name_and_src_coords_attributes (decl);
3625 member_attribute (DECL_CONTEXT (decl));
3626 type_attribute (member_declared_type (decl),
3627 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3628 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3630 byte_size_attribute (decl);
3631 bit_size_attribute (decl);
3632 bit_offset_attribute (decl);
3634 data_member_location_attribute (decl);
3637 #if 0
3638 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3639 modified types instead.
3641 We keep this code here just in case these types of DIEs may be
3642 needed to represent certain things in other languages (e.g. Pascal)
3643 someday. */
3645 static void
3646 output_pointer_type_die (arg)
3647 register void *arg;
3649 register tree type = arg;
3651 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3652 sibling_attribute ();
3653 equate_type_number_to_die_number (type);
3654 member_attribute (TYPE_CONTEXT (type));
3655 type_attribute (TREE_TYPE (type), 0, 0);
3658 static void
3659 output_reference_type_die (arg)
3660 register void *arg;
3662 register tree type = arg;
3664 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3665 sibling_attribute ();
3666 equate_type_number_to_die_number (type);
3667 member_attribute (TYPE_CONTEXT (type));
3668 type_attribute (TREE_TYPE (type), 0, 0);
3670 #endif
3672 static void
3673 output_ptr_to_mbr_type_die (arg)
3674 register void *arg;
3676 register tree type = arg;
3678 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3679 sibling_attribute ();
3680 equate_type_number_to_die_number (type);
3681 member_attribute (TYPE_CONTEXT (type));
3682 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3683 type_attribute (TREE_TYPE (type), 0, 0);
3686 static void
3687 output_compile_unit_die (arg)
3688 register void *arg;
3690 register char *main_input_filename = arg;
3692 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3693 sibling_attribute ();
3694 dienum_push ();
3695 name_attribute (main_input_filename);
3698 char producer[250];
3700 sprintf (producer, "%s %s", language_string, version_string);
3701 producer_attribute (producer);
3704 if (strcmp (language_string, "GNU C++") == 0)
3705 language_attribute (LANG_C_PLUS_PLUS);
3706 else if (strcmp (language_string, "GNU Ada") == 0)
3707 language_attribute (LANG_ADA83);
3708 else if (strcmp (language_string, "GNU F77") == 0)
3709 language_attribute (LANG_FORTRAN77);
3710 else if (strcmp (language_string, "GNU Pascal") == 0)
3711 language_attribute (LANG_PASCAL83);
3712 else if (flag_traditional)
3713 language_attribute (LANG_C);
3714 else
3715 language_attribute (LANG_C89);
3716 low_pc_attribute (TEXT_BEGIN_LABEL);
3717 high_pc_attribute (TEXT_END_LABEL);
3718 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3719 stmt_list_attribute (LINE_BEGIN_LABEL);
3720 last_filename = xstrdup (main_input_filename);
3723 char *wd = getpwd ();
3724 if (wd)
3725 comp_dir_attribute (wd);
3728 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3730 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3731 src_info_attribute (SRCINFO_BEGIN_LABEL);
3732 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3733 mac_info_attribute (MACINFO_BEGIN_LABEL);
3737 static void
3738 output_string_type_die (arg)
3739 register void *arg;
3741 register tree type = arg;
3743 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3744 sibling_attribute ();
3745 equate_type_number_to_die_number (type);
3746 member_attribute (TYPE_CONTEXT (type));
3747 /* this is a fixed length string */
3748 byte_size_attribute (type);
3751 static void
3752 output_inheritance_die (arg)
3753 register void *arg;
3755 register tree binfo = arg;
3757 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3758 sibling_attribute ();
3759 type_attribute (BINFO_TYPE (binfo), 0, 0);
3760 data_member_location_attribute (binfo);
3761 if (TREE_VIA_VIRTUAL (binfo))
3763 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3764 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3766 if (TREE_VIA_PUBLIC (binfo))
3768 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3769 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3771 else if (TREE_VIA_PROTECTED (binfo))
3773 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3774 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3778 static void
3779 output_structure_type_die (arg)
3780 register void *arg;
3782 register tree type = arg;
3784 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3785 sibling_attribute ();
3786 equate_type_number_to_die_number (type);
3787 name_attribute (type_tag (type));
3788 member_attribute (TYPE_CONTEXT (type));
3790 /* If this type has been completed, then give it a byte_size attribute
3791 and prepare to give a list of members. Otherwise, don't do either of
3792 these things. In the latter case, we will not be generating a list
3793 of members (since we don't have any idea what they might be for an
3794 incomplete type). */
3796 if (TYPE_SIZE (type))
3798 dienum_push ();
3799 byte_size_attribute (type);
3803 /* Output a DIE to represent a declared function (either file-scope
3804 or block-local) which has "internal linkage" (according to ANSI-C). */
3806 static void
3807 output_local_subroutine_die (arg)
3808 register void *arg;
3810 register tree decl = arg;
3811 register tree origin = decl_ultimate_origin (decl);
3813 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3814 sibling_attribute ();
3815 dienum_push ();
3816 if (origin != NULL)
3817 abstract_origin_attribute (origin);
3818 else
3820 register tree type = TREE_TYPE (decl);
3822 name_and_src_coords_attributes (decl);
3823 inline_attribute (decl);
3824 prototyped_attribute (type);
3825 member_attribute (DECL_CONTEXT (decl));
3826 type_attribute (TREE_TYPE (type), 0, 0);
3827 pure_or_virtual_attribute (decl);
3829 if (DECL_ABSTRACT (decl))
3830 equate_decl_number_to_die_number (decl);
3831 else
3833 /* Avoid getting screwed up in cases where a function was declared
3834 static but where no definition was ever given for it. */
3836 if (TREE_ASM_WRITTEN (decl))
3838 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3839 low_pc_attribute (function_start_label (decl));
3840 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3841 high_pc_attribute (label);
3842 if (use_gnu_debug_info_extensions)
3844 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3845 body_begin_attribute (label);
3846 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3847 body_end_attribute (label);
3853 static void
3854 output_subroutine_type_die (arg)
3855 register void *arg;
3857 register tree type = arg;
3858 register tree return_type = TREE_TYPE (type);
3860 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3861 sibling_attribute ();
3862 dienum_push ();
3863 equate_type_number_to_die_number (type);
3864 prototyped_attribute (type);
3865 member_attribute (TYPE_CONTEXT (type));
3866 type_attribute (return_type, 0, 0);
3869 static void
3870 output_typedef_die (arg)
3871 register void *arg;
3873 register tree decl = arg;
3874 register tree origin = decl_ultimate_origin (decl);
3876 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3877 sibling_attribute ();
3878 if (origin != NULL)
3879 abstract_origin_attribute (origin);
3880 else
3882 name_and_src_coords_attributes (decl);
3883 member_attribute (DECL_CONTEXT (decl));
3884 type_attribute (TREE_TYPE (decl),
3885 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3887 if (DECL_ABSTRACT (decl))
3888 equate_decl_number_to_die_number (decl);
3891 static void
3892 output_union_type_die (arg)
3893 register void *arg;
3895 register tree type = arg;
3897 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3898 sibling_attribute ();
3899 equate_type_number_to_die_number (type);
3900 name_attribute (type_tag (type));
3901 member_attribute (TYPE_CONTEXT (type));
3903 /* If this type has been completed, then give it a byte_size attribute
3904 and prepare to give a list of members. Otherwise, don't do either of
3905 these things. In the latter case, we will not be generating a list
3906 of members (since we don't have any idea what they might be for an
3907 incomplete type). */
3909 if (TYPE_SIZE (type))
3911 dienum_push ();
3912 byte_size_attribute (type);
3916 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3917 at the end of an (ANSI prototyped) formal parameters list. */
3919 static void
3920 output_unspecified_parameters_die (arg)
3921 register void *arg;
3923 register tree decl_or_type = arg;
3925 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3926 sibling_attribute ();
3928 /* This kludge is here only for the sake of being compatible with what
3929 the USL CI5 C compiler does. The specification of Dwarf Version 1
3930 doesn't say that TAG_unspecified_parameters DIEs should contain any
3931 attributes other than the AT_sibling attribute, but they are certainly
3932 allowed to contain additional attributes, and the CI5 compiler
3933 generates AT_name, AT_fund_type, and AT_location attributes within
3934 TAG_unspecified_parameters DIEs which appear in the child lists for
3935 DIEs representing function definitions, so we do likewise here. */
3937 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3939 name_attribute ("...");
3940 fund_type_attribute (FT_pointer);
3941 /* location_attribute (?); */
3945 static void
3946 output_padded_null_die (arg)
3947 register void *arg;
3949 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3952 /*************************** end of DIEs *********************************/
3954 /* Generate some type of DIE. This routine generates the generic outer
3955 wrapper stuff which goes around all types of DIE's (regardless of their
3956 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3957 DIE-length word, followed by the guts of the DIE itself. After the guts
3958 of the DIE, there must always be a terminator label for the DIE. */
3960 static void
3961 output_die (die_specific_output_function, param)
3962 register void (*die_specific_output_function)();
3963 register void *param;
3965 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3966 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3968 current_dienum = NEXT_DIE_NUM;
3969 NEXT_DIE_NUM = next_unused_dienum;
3971 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3972 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3974 /* Write a label which will act as the name for the start of this DIE. */
3976 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3978 /* Write the DIE-length word. */
3980 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3982 /* Fill in the guts of the DIE. */
3984 next_unused_dienum++;
3985 die_specific_output_function (param);
3987 /* Write a label which will act as the name for the end of this DIE. */
3989 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3992 static void
3993 end_sibling_chain ()
3995 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3997 current_dienum = NEXT_DIE_NUM;
3998 NEXT_DIE_NUM = next_unused_dienum;
4000 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4002 /* Write a label which will act as the name for the start of this DIE. */
4004 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4006 /* Write the DIE-length word. */
4008 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4010 dienum_pop ();
4013 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4014 TAG_unspecified_parameters DIE) to represent the types of the formal
4015 parameters as specified in some function type specification (except
4016 for those which appear as part of a function *definition*).
4018 Note that we must be careful here to output all of the parameter
4019 DIEs *before* we output any DIEs needed to represent the types of
4020 the formal parameters. This keeps svr4 SDB happy because it
4021 (incorrectly) thinks that the first non-parameter DIE it sees ends
4022 the formal parameter list. */
4024 static void
4025 output_formal_types (function_or_method_type)
4026 register tree function_or_method_type;
4028 register tree link;
4029 register tree formal_type = NULL;
4030 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4032 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4033 get bogus recursion when outputting tagged types local to a
4034 function declaration. */
4035 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4036 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4038 /* In the case where we are generating a formal types list for a C++
4039 non-static member function type, skip over the first thing on the
4040 TYPE_ARG_TYPES list because it only represents the type of the
4041 hidden `this pointer'. The debugger should be able to figure
4042 out (without being explicitly told) that this non-static member
4043 function type takes a `this pointer' and should be able to figure
4044 what the type of that hidden parameter is from the AT_member
4045 attribute of the parent TAG_subroutine_type DIE. */
4047 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4048 first_parm_type = TREE_CHAIN (first_parm_type);
4050 /* Make our first pass over the list of formal parameter types and output
4051 a TAG_formal_parameter DIE for each one. */
4053 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4055 formal_type = TREE_VALUE (link);
4056 if (formal_type == void_type_node)
4057 break;
4059 /* Output a (nameless) DIE to represent the formal parameter itself. */
4061 output_die (output_formal_parameter_die, formal_type);
4064 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4065 DIE to the end of the parameter list. */
4067 if (formal_type != void_type_node)
4068 output_die (output_unspecified_parameters_die, function_or_method_type);
4070 /* Make our second (and final) pass over the list of formal parameter types
4071 and output DIEs to represent those types (as necessary). */
4073 for (link = TYPE_ARG_TYPES (function_or_method_type);
4074 link;
4075 link = TREE_CHAIN (link))
4077 formal_type = TREE_VALUE (link);
4078 if (formal_type == void_type_node)
4079 break;
4081 output_type (formal_type, function_or_method_type);
4084 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4087 /* Remember a type in the pending_types_list. */
4089 static void
4090 pend_type (type)
4091 register tree type;
4093 if (pending_types == pending_types_allocated)
4095 pending_types_allocated += PENDING_TYPES_INCREMENT;
4096 pending_types_list
4097 = (tree *) xrealloc (pending_types_list,
4098 sizeof (tree) * pending_types_allocated);
4100 pending_types_list[pending_types++] = type;
4102 /* Mark the pending type as having been output already (even though
4103 it hasn't been). This prevents the type from being added to the
4104 pending_types_list more than once. */
4106 TREE_ASM_WRITTEN (type) = 1;
4109 /* Return non-zero if it is legitimate to output DIEs to represent a
4110 given type while we are generating the list of child DIEs for some
4111 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4113 See the comments within the function for a description of when it is
4114 considered legitimate to output DIEs for various kinds of types.
4116 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4117 or it may point to a BLOCK node (for types local to a block), or to a
4118 FUNCTION_DECL node (for types local to the heading of some function
4119 definition), or to a FUNCTION_TYPE node (for types local to the
4120 prototyped parameter list of a function type specification), or to a
4121 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4122 (in the case of C++ nested types).
4124 The `scope' parameter should likewise be NULL or should point to a
4125 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4126 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4128 This function is used only for deciding when to "pend" and when to
4129 "un-pend" types to/from the pending_types_list.
4131 Note that we sometimes make use of this "type pending" feature in a
4132 rather twisted way to temporarily delay the production of DIEs for the
4133 types of formal parameters. (We do this just to make svr4 SDB happy.)
4134 It order to delay the production of DIEs representing types of formal
4135 parameters, callers of this function supply `fake_containing_scope' as
4136 the `scope' parameter to this function. Given that fake_containing_scope
4137 is a tagged type which is *not* the containing scope for *any* other type,
4138 the desired effect is achieved, i.e. output of DIEs representing types
4139 is temporarily suspended, and any type DIEs which would have otherwise
4140 been output are instead placed onto the pending_types_list. Later on,
4141 we force these (temporarily pended) types to be output simply by calling
4142 `output_pending_types_for_scope' with an actual argument equal to the
4143 true scope of the types we temporarily pended. */
4145 static inline int
4146 type_ok_for_scope (type, scope)
4147 register tree type;
4148 register tree scope;
4150 /* Tagged types (i.e. struct, union, and enum types) must always be
4151 output only in the scopes where they actually belong (or else the
4152 scoping of their own tag names and the scoping of their member
4153 names will be incorrect). Non-tagged-types on the other hand can
4154 generally be output anywhere, except that svr4 SDB really doesn't
4155 want to see them nested within struct or union types, so here we
4156 say it is always OK to immediately output any such a (non-tagged)
4157 type, so long as we are not within such a context. Note that the
4158 only kinds of non-tagged types which we will be dealing with here
4159 (for C and C++ anyway) will be array types and function types. */
4161 return is_tagged_type (type)
4162 ? (TYPE_CONTEXT (type) == scope
4163 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4164 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4165 : (scope == NULL_TREE || ! is_tagged_type (scope));
4168 /* Output any pending types (from the pending_types list) which we can output
4169 now (taking into account the scope that we are working on now).
4171 For each type output, remove the given type from the pending_types_list
4172 *before* we try to output it.
4174 Note that we have to process the list in beginning-to-end order,
4175 because the call made here to output_type may cause yet more types
4176 to be added to the end of the list, and we may have to output some
4177 of them too. */
4179 static void
4180 output_pending_types_for_scope (containing_scope)
4181 register tree containing_scope;
4183 register unsigned i;
4185 for (i = 0; i < pending_types; )
4187 register tree type = pending_types_list[i];
4189 if (type_ok_for_scope (type, containing_scope))
4191 register tree *mover;
4192 register tree *limit;
4194 pending_types--;
4195 limit = &pending_types_list[pending_types];
4196 for (mover = &pending_types_list[i]; mover < limit; mover++)
4197 *mover = *(mover+1);
4199 /* Un-mark the type as having been output already (because it
4200 hasn't been, really). Then call output_type to generate a
4201 Dwarf representation of it. */
4203 TREE_ASM_WRITTEN (type) = 0;
4204 output_type (type, containing_scope);
4206 /* Don't increment the loop counter in this case because we
4207 have shifted all of the subsequent pending types down one
4208 element in the pending_types_list array. */
4210 else
4211 i++;
4215 static void
4216 output_type (type, containing_scope)
4217 register tree type;
4218 register tree containing_scope;
4220 if (type == 0 || type == error_mark_node)
4221 return;
4223 /* We are going to output a DIE to represent the unqualified version of
4224 of this type (i.e. without any const or volatile qualifiers) so get
4225 the main variant (i.e. the unqualified version) of this type now. */
4227 type = type_main_variant (type);
4229 if (TREE_ASM_WRITTEN (type))
4231 if (finalizing && AGGREGATE_TYPE_P (type))
4233 register tree member;
4235 /* Some of our nested types might not have been defined when we
4236 were written out before; force them out now. */
4238 for (member = TYPE_FIELDS (type); member;
4239 member = TREE_CHAIN (member))
4240 if (TREE_CODE (member) == TYPE_DECL
4241 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4242 output_type (TREE_TYPE (member), containing_scope);
4244 return;
4247 /* If this is a nested type whose containing class hasn't been
4248 written out yet, writing it out will cover this one, too. */
4250 if (TYPE_CONTEXT (type)
4251 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4252 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4254 output_type (TYPE_CONTEXT (type), containing_scope);
4255 return;
4258 /* Don't generate any DIEs for this type now unless it is OK to do so
4259 (based upon what `type_ok_for_scope' tells us). */
4261 if (! type_ok_for_scope (type, containing_scope))
4263 pend_type (type);
4264 return;
4267 switch (TREE_CODE (type))
4269 case ERROR_MARK:
4270 break;
4272 case POINTER_TYPE:
4273 case REFERENCE_TYPE:
4274 /* Prevent infinite recursion in cases where this is a recursive
4275 type. Recursive types are possible in Ada. */
4276 TREE_ASM_WRITTEN (type) = 1;
4277 /* For these types, all that is required is that we output a DIE
4278 (or a set of DIEs) to represent the "basis" type. */
4279 output_type (TREE_TYPE (type), containing_scope);
4280 break;
4282 case OFFSET_TYPE:
4283 /* This code is used for C++ pointer-to-data-member types. */
4284 /* Output a description of the relevant class type. */
4285 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4286 /* Output a description of the type of the object pointed to. */
4287 output_type (TREE_TYPE (type), containing_scope);
4288 /* Now output a DIE to represent this pointer-to-data-member type
4289 itself. */
4290 output_die (output_ptr_to_mbr_type_die, type);
4291 break;
4293 case SET_TYPE:
4294 output_type (TYPE_DOMAIN (type), containing_scope);
4295 output_die (output_set_type_die, type);
4296 break;
4298 case FILE_TYPE:
4299 output_type (TREE_TYPE (type), containing_scope);
4300 abort (); /* No way to represent these in Dwarf yet! */
4301 break;
4303 case FUNCTION_TYPE:
4304 /* Force out return type (in case it wasn't forced out already). */
4305 output_type (TREE_TYPE (type), containing_scope);
4306 output_die (output_subroutine_type_die, type);
4307 output_formal_types (type);
4308 end_sibling_chain ();
4309 break;
4311 case METHOD_TYPE:
4312 /* Force out return type (in case it wasn't forced out already). */
4313 output_type (TREE_TYPE (type), containing_scope);
4314 output_die (output_subroutine_type_die, type);
4315 output_formal_types (type);
4316 end_sibling_chain ();
4317 break;
4319 case ARRAY_TYPE:
4320 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4322 output_type (TREE_TYPE (type), containing_scope);
4323 output_die (output_string_type_die, type);
4325 else
4327 register tree element_type;
4329 element_type = TREE_TYPE (type);
4330 while (TREE_CODE (element_type) == ARRAY_TYPE)
4331 element_type = TREE_TYPE (element_type);
4333 output_type (element_type, containing_scope);
4334 output_die (output_array_type_die, type);
4336 break;
4338 case ENUMERAL_TYPE:
4339 case RECORD_TYPE:
4340 case UNION_TYPE:
4341 case QUAL_UNION_TYPE:
4343 /* For a non-file-scope tagged type, we can always go ahead and
4344 output a Dwarf description of this type right now, even if
4345 the type in question is still incomplete, because if this
4346 local type *was* ever completed anywhere within its scope,
4347 that complete definition would already have been attached to
4348 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4349 node by the time we reach this point. That's true because of the
4350 way the front-end does its processing of file-scope declarations (of
4351 functions and class types) within which other types might be
4352 nested. The C and C++ front-ends always gobble up such "local
4353 scope" things en-mass before they try to output *any* debugging
4354 information for any of the stuff contained inside them and thus,
4355 we get the benefit here of what is (in effect) a pre-resolution
4356 of forward references to tagged types in local scopes.
4358 Note however that for file-scope tagged types we cannot assume
4359 that such pre-resolution of forward references has taken place.
4360 A given file-scope tagged type may appear to be incomplete when
4361 we reach this point, but it may yet be given a full definition
4362 (at file-scope) later on during compilation. In order to avoid
4363 generating a premature (and possibly incorrect) set of Dwarf
4364 DIEs for such (as yet incomplete) file-scope tagged types, we
4365 generate nothing at all for as-yet incomplete file-scope tagged
4366 types here unless we are making our special "finalization" pass
4367 for file-scope things at the very end of compilation. At that
4368 time, we will certainly know as much about each file-scope tagged
4369 type as we are ever going to know, so at that point in time, we
4370 can safely generate correct Dwarf descriptions for these file-
4371 scope tagged types. */
4373 if (TYPE_SIZE (type) == 0
4374 && (TYPE_CONTEXT (type) == NULL
4375 || (TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4376 && TREE_CODE (TYPE_CONTEXT (type)) != FUNCTION_TYPE
4377 && TREE_CODE (TYPE_CONTEXT (type)) != METHOD_TYPE))
4378 && !finalizing)
4379 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4381 /* Prevent infinite recursion in cases where the type of some
4382 member of this type is expressed in terms of this type itself. */
4384 TREE_ASM_WRITTEN (type) = 1;
4386 /* Output a DIE to represent the tagged type itself. */
4388 switch (TREE_CODE (type))
4390 case ENUMERAL_TYPE:
4391 output_die (output_enumeration_type_die, type);
4392 return; /* a special case -- nothing left to do so just return */
4394 case RECORD_TYPE:
4395 output_die (output_structure_type_die, type);
4396 break;
4398 case UNION_TYPE:
4399 case QUAL_UNION_TYPE:
4400 output_die (output_union_type_die, type);
4401 break;
4403 default:
4404 abort (); /* Should never happen. */
4407 /* If this is not an incomplete type, output descriptions of
4408 each of its members.
4410 Note that as we output the DIEs necessary to represent the
4411 members of this record or union type, we will also be trying
4412 to output DIEs to represent the *types* of those members.
4413 However the `output_type' function (above) will specifically
4414 avoid generating type DIEs for member types *within* the list
4415 of member DIEs for this (containing) type execpt for those
4416 types (of members) which are explicitly marked as also being
4417 members of this (containing) type themselves. The g++ front-
4418 end can force any given type to be treated as a member of some
4419 other (containing) type by setting the TYPE_CONTEXT of the
4420 given (member) type to point to the TREE node representing the
4421 appropriate (containing) type.
4424 if (TYPE_SIZE (type))
4426 /* First output info about the base classes. */
4427 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4429 register tree bases = TYPE_BINFO_BASETYPES (type);
4430 register int n_bases = TREE_VEC_LENGTH (bases);
4431 register int i;
4433 for (i = 0; i < n_bases; i++)
4434 output_die (output_inheritance_die, TREE_VEC_ELT (bases, i));
4437 ++in_class;
4440 register tree normal_member;
4442 /* Now output info about the data members and type members. */
4444 for (normal_member = TYPE_FIELDS (type);
4445 normal_member;
4446 normal_member = TREE_CHAIN (normal_member))
4447 output_decl (normal_member, type);
4451 register tree func_member;
4453 /* Now output info about the function members (if any). */
4455 for (func_member = TYPE_METHODS (type);
4456 func_member;
4457 func_member = TREE_CHAIN (func_member))
4458 output_decl (func_member, type);
4461 --in_class;
4463 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4464 scopes (at least in C++) so we must now output any nested
4465 pending types which are local just to this type. */
4467 output_pending_types_for_scope (type);
4469 end_sibling_chain (); /* Terminate member chain. */
4472 break;
4474 case VOID_TYPE:
4475 case INTEGER_TYPE:
4476 case REAL_TYPE:
4477 case COMPLEX_TYPE:
4478 case BOOLEAN_TYPE:
4479 case CHAR_TYPE:
4480 break; /* No DIEs needed for fundamental types. */
4482 case LANG_TYPE: /* No Dwarf representation currently defined. */
4483 break;
4485 default:
4486 abort ();
4489 TREE_ASM_WRITTEN (type) = 1;
4492 static void
4493 output_tagged_type_instantiation (type)
4494 register tree type;
4496 if (type == 0 || type == error_mark_node)
4497 return;
4499 /* We are going to output a DIE to represent the unqualified version of
4500 of this type (i.e. without any const or volatile qualifiers) so make
4501 sure that we have the main variant (i.e. the unqualified version) of
4502 this type now. */
4504 if (type != type_main_variant (type))
4505 abort ();
4507 if (!TREE_ASM_WRITTEN (type))
4508 abort ();
4510 switch (TREE_CODE (type))
4512 case ERROR_MARK:
4513 break;
4515 case ENUMERAL_TYPE:
4516 output_die (output_inlined_enumeration_type_die, type);
4517 break;
4519 case RECORD_TYPE:
4520 output_die (output_inlined_structure_type_die, type);
4521 break;
4523 case UNION_TYPE:
4524 case QUAL_UNION_TYPE:
4525 output_die (output_inlined_union_type_die, type);
4526 break;
4528 default:
4529 abort (); /* Should never happen. */
4533 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4534 the things which are local to the given block. */
4536 static void
4537 output_block (stmt, depth)
4538 register tree stmt;
4539 int depth;
4541 register int must_output_die = 0;
4542 register tree origin;
4543 register enum tree_code origin_code;
4545 /* Ignore blocks never really used to make RTL. */
4547 if (! stmt || ! TREE_USED (stmt))
4548 return;
4550 /* Determine the "ultimate origin" of this block. This block may be an
4551 inlined instance of an inlined instance of inline function, so we
4552 have to trace all of the way back through the origin chain to find
4553 out what sort of node actually served as the original seed for the
4554 creation of the current block. */
4556 origin = block_ultimate_origin (stmt);
4557 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4559 /* Determine if we need to output any Dwarf DIEs at all to represent this
4560 block. */
4562 if (origin_code == FUNCTION_DECL)
4563 /* The outer scopes for inlinings *must* always be represented. We
4564 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4565 must_output_die = 1;
4566 else
4568 /* In the case where the current block represents an inlining of the
4569 "body block" of an inline function, we must *NOT* output any DIE
4570 for this block because we have already output a DIE to represent
4571 the whole inlined function scope and the "body block" of any
4572 function doesn't really represent a different scope according to
4573 ANSI C rules. So we check here to make sure that this block does
4574 not represent a "body block inlining" before trying to set the
4575 `must_output_die' flag. */
4577 if (! is_body_block (origin ? origin : stmt))
4579 /* Determine if this block directly contains any "significant"
4580 local declarations which we will need to output DIEs for. */
4582 if (debug_info_level > DINFO_LEVEL_TERSE)
4583 /* We are not in terse mode so *any* local declaration counts
4584 as being a "significant" one. */
4585 must_output_die = (BLOCK_VARS (stmt) != NULL);
4586 else
4588 register tree decl;
4590 /* We are in terse mode, so only local (nested) function
4591 definitions count as "significant" local declarations. */
4593 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4594 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4596 must_output_die = 1;
4597 break;
4603 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4604 DIE for any block which contains no significant local declarations
4605 at all. Rather, in such cases we just call `output_decls_for_scope'
4606 so that any needed Dwarf info for any sub-blocks will get properly
4607 generated. Note that in terse mode, our definition of what constitutes
4608 a "significant" local declaration gets restricted to include only
4609 inlined function instances and local (nested) function definitions. */
4611 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4612 /* We don't care about an abstract inlined subroutine. */;
4613 else if (must_output_die)
4615 output_die ((origin_code == FUNCTION_DECL)
4616 ? output_inlined_subroutine_die
4617 : output_lexical_block_die,
4618 stmt);
4619 output_decls_for_scope (stmt, depth);
4620 end_sibling_chain ();
4622 else
4623 output_decls_for_scope (stmt, depth);
4626 /* Output all of the decls declared within a given scope (also called
4627 a `binding contour') and (recursively) all of it's sub-blocks. */
4629 static void
4630 output_decls_for_scope (stmt, depth)
4631 register tree stmt;
4632 int depth;
4634 /* Ignore blocks never really used to make RTL. */
4636 if (! stmt || ! TREE_USED (stmt))
4637 return;
4639 if (! BLOCK_ABSTRACT (stmt) && depth > 0)
4640 next_block_number++;
4642 /* Output the DIEs to represent all of the data objects, functions,
4643 typedefs, and tagged types declared directly within this block
4644 but not within any nested sub-blocks. */
4647 register tree decl;
4649 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4650 output_decl (decl, stmt);
4653 output_pending_types_for_scope (stmt);
4655 /* Output the DIEs to represent all sub-blocks (and the items declared
4656 therein) of this block. */
4659 register tree subblocks;
4661 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4662 subblocks;
4663 subblocks = BLOCK_CHAIN (subblocks))
4664 output_block (subblocks, depth + 1);
4668 /* Is this a typedef we can avoid emitting? */
4670 inline int
4671 is_redundant_typedef (decl)
4672 register tree decl;
4674 if (TYPE_DECL_IS_STUB (decl))
4675 return 1;
4676 if (DECL_ARTIFICIAL (decl)
4677 && DECL_CONTEXT (decl)
4678 && is_tagged_type (DECL_CONTEXT (decl))
4679 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4680 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4681 /* Also ignore the artificial member typedef for the class name. */
4682 return 1;
4683 return 0;
4686 /* Output Dwarf .debug information for a decl described by DECL. */
4688 static void
4689 output_decl (decl, containing_scope)
4690 register tree decl;
4691 register tree containing_scope;
4693 /* Make a note of the decl node we are going to be working on. We may
4694 need to give the user the source coordinates of where it appeared in
4695 case we notice (later on) that something about it looks screwy. */
4697 dwarf_last_decl = decl;
4699 if (TREE_CODE (decl) == ERROR_MARK)
4700 return;
4702 /* If a structure is declared within an initialization, e.g. as the
4703 operand of a sizeof, then it will not have a name. We don't want
4704 to output a DIE for it, as the tree nodes are in the temporary obstack */
4706 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4707 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4708 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4709 || (TYPE_FIELDS (TREE_TYPE (decl))
4710 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4711 return;
4713 /* If this ..._DECL node is marked to be ignored, then ignore it.
4714 But don't ignore a function definition, since that would screw
4715 up our count of blocks, and that it turn will completely screw up the
4716 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4717 attributes (for subsequent blocks). */
4719 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4720 return;
4722 switch (TREE_CODE (decl))
4724 case CONST_DECL:
4725 /* The individual enumerators of an enum type get output when we
4726 output the Dwarf representation of the relevant enum type itself. */
4727 break;
4729 case FUNCTION_DECL:
4730 /* If we are in terse mode, don't output any DIEs to represent
4731 mere function declarations. Also, if we are conforming
4732 to the DWARF version 1 specification, don't output DIEs for
4733 mere function declarations. */
4735 if (DECL_INITIAL (decl) == NULL_TREE)
4736 #if (DWARF_VERSION > 1)
4737 if (debug_info_level <= DINFO_LEVEL_TERSE)
4738 #endif
4739 break;
4741 /* Before we describe the FUNCTION_DECL itself, make sure that we
4742 have described its return type. */
4744 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4747 /* And its containing type. */
4748 register tree origin = decl_class_context (decl);
4749 if (origin)
4750 output_type (origin, containing_scope);
4753 /* If the following DIE will represent a function definition for a
4754 function with "extern" linkage, output a special "pubnames" DIE
4755 label just ahead of the actual DIE. A reference to this label
4756 was already generated in the .debug_pubnames section sub-entry
4757 for this function definition. */
4759 if (TREE_PUBLIC (decl))
4761 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4763 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4764 ASM_OUTPUT_LABEL (asm_out_file, label);
4767 /* Now output a DIE to represent the function itself. */
4769 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4770 ? output_global_subroutine_die
4771 : output_local_subroutine_die,
4772 decl);
4774 /* Now output descriptions of the arguments for this function.
4775 This gets (unnecessarily?) complex because of the fact that
4776 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4777 cases where there was a trailing `...' at the end of the formal
4778 parameter list. In order to find out if there was a trailing
4779 ellipsis or not, we must instead look at the type associated
4780 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4781 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4782 ends with a void_type_node then there should *not* be an ellipsis
4783 at the end. */
4785 /* In the case where we are describing a mere function declaration, all
4786 we need to do here (and all we *can* do here) is to describe
4787 the *types* of its formal parameters. */
4789 if (decl != current_function_decl || in_class)
4790 output_formal_types (TREE_TYPE (decl));
4791 else
4793 /* Generate DIEs to represent all known formal parameters */
4795 register tree arg_decls = DECL_ARGUMENTS (decl);
4796 register tree parm;
4798 /* WARNING! Kludge zone ahead! Here we have a special
4799 hack for svr4 SDB compatibility. Instead of passing the
4800 current FUNCTION_DECL node as the second parameter (i.e.
4801 the `containing_scope' parameter) to `output_decl' (as
4802 we ought to) we instead pass a pointer to our own private
4803 fake_containing_scope node. That node is a RECORD_TYPE
4804 node which NO OTHER TYPE may ever actually be a member of.
4806 This pointer will ultimately get passed into `output_type'
4807 as its `containing_scope' parameter. `Output_type' will
4808 then perform its part in the hack... i.e. it will pend
4809 the type of the formal parameter onto the pending_types
4810 list. Later on, when we are done generating the whole
4811 sequence of formal parameter DIEs for this function
4812 definition, we will un-pend all previously pended types
4813 of formal parameters for this function definition.
4815 This whole kludge prevents any type DIEs from being
4816 mixed in with the formal parameter DIEs. That's good
4817 because svr4 SDB believes that the list of formal
4818 parameter DIEs for a function ends wherever the first
4819 non-formal-parameter DIE appears. Thus, we have to
4820 keep the formal parameter DIEs segregated. They must
4821 all appear (consecutively) at the start of the list of
4822 children for the DIE representing the function definition.
4823 Then (and only then) may we output any additional DIEs
4824 needed to represent the types of these formal parameters.
4828 When generating DIEs, generate the unspecified_parameters
4829 DIE instead if we come across the arg "__builtin_va_alist"
4832 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4833 if (TREE_CODE (parm) == PARM_DECL)
4835 if (DECL_NAME(parm) &&
4836 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4837 "__builtin_va_alist") )
4838 output_die (output_unspecified_parameters_die, decl);
4839 else
4840 output_decl (parm, fake_containing_scope);
4844 Now that we have finished generating all of the DIEs to
4845 represent the formal parameters themselves, force out
4846 any DIEs needed to represent their types. We do this
4847 simply by un-pending all previously pended types which
4848 can legitimately go into the chain of children DIEs for
4849 the current FUNCTION_DECL.
4852 output_pending_types_for_scope (decl);
4855 Decide whether we need a unspecified_parameters DIE at the end.
4856 There are 2 more cases to do this for:
4857 1) the ansi ... declaration - this is detectable when the end
4858 of the arg list is not a void_type_node
4859 2) an unprototyped function declaration (not a definition). This
4860 just means that we have no info about the parameters at all.
4864 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4866 if (fn_arg_types)
4868 /* this is the prototyped case, check for ... */
4869 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4870 output_die (output_unspecified_parameters_die, decl);
4872 else
4874 /* this is unprototyped, check for undefined (just declaration) */
4875 if (!DECL_INITIAL (decl))
4876 output_die (output_unspecified_parameters_die, decl);
4880 /* Output Dwarf info for all of the stuff within the body of the
4881 function (if it has one - it may be just a declaration). */
4884 register tree outer_scope = DECL_INITIAL (decl);
4886 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4888 /* Note that here, `outer_scope' is a pointer to the outermost
4889 BLOCK node created to represent a function.
4890 This outermost BLOCK actually represents the outermost
4891 binding contour for the function, i.e. the contour in which
4892 the function's formal parameters and labels get declared.
4894 Curiously, it appears that the front end doesn't actually
4895 put the PARM_DECL nodes for the current function onto the
4896 BLOCK_VARS list for this outer scope. (They are strung
4897 off of the DECL_ARGUMENTS list for the function instead.)
4898 The BLOCK_VARS list for the `outer_scope' does provide us
4899 with a list of the LABEL_DECL nodes for the function however,
4900 and we output DWARF info for those here.
4902 Just within the `outer_scope' there will be a BLOCK node
4903 representing the function's outermost pair of curly braces,
4904 and any blocks used for the base and member initializers of
4905 a C++ constructor function. */
4907 output_decls_for_scope (outer_scope, 0);
4909 /* Finally, force out any pending types which are local to the
4910 outermost block of this function definition. These will
4911 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4912 node itself. */
4914 output_pending_types_for_scope (decl);
4919 /* Generate a terminator for the list of stuff `owned' by this
4920 function. */
4922 end_sibling_chain ();
4924 break;
4926 case TYPE_DECL:
4927 /* If we are in terse mode, don't generate any DIEs to represent
4928 any actual typedefs. Note that even when we are in terse mode,
4929 we must still output DIEs to represent those tagged types which
4930 are used (directly or indirectly) in the specification of either
4931 a return type or a formal parameter type of some function. */
4933 if (debug_info_level <= DINFO_LEVEL_TERSE)
4934 if (! TYPE_DECL_IS_STUB (decl)
4935 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4936 return;
4938 /* In the special case of a TYPE_DECL node representing
4939 the declaration of some type tag, if the given TYPE_DECL is
4940 marked as having been instantiated from some other (original)
4941 TYPE_DECL node (e.g. one which was generated within the original
4942 definition of an inline function) we have to generate a special
4943 (abbreviated) TAG_structure_type, TAG_union_type, or
4944 TAG_enumeration-type DIE here. */
4946 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4948 output_tagged_type_instantiation (TREE_TYPE (decl));
4949 return;
4952 output_type (TREE_TYPE (decl), containing_scope);
4954 if (! is_redundant_typedef (decl))
4955 /* Output a DIE to represent the typedef itself. */
4956 output_die (output_typedef_die, decl);
4957 break;
4959 case LABEL_DECL:
4960 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4961 output_die (output_label_die, decl);
4962 break;
4964 case VAR_DECL:
4965 /* If we are conforming to the DWARF version 1 specification, don't
4966 generated any DIEs to represent mere external object declarations. */
4968 #if (DWARF_VERSION <= 1)
4969 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4970 break;
4971 #endif
4973 /* If we are in terse mode, don't generate any DIEs to represent
4974 any variable declarations or definitions. */
4976 if (debug_info_level <= DINFO_LEVEL_TERSE)
4977 break;
4979 /* Output any DIEs that are needed to specify the type of this data
4980 object. */
4982 output_type (TREE_TYPE (decl), containing_scope);
4985 /* And its containing type. */
4986 register tree origin = decl_class_context (decl);
4987 if (origin)
4988 output_type (origin, containing_scope);
4991 /* If the following DIE will represent a data object definition for a
4992 data object with "extern" linkage, output a special "pubnames" DIE
4993 label just ahead of the actual DIE. A reference to this label
4994 was already generated in the .debug_pubnames section sub-entry
4995 for this data object definition. */
4997 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4999 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5001 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5002 ASM_OUTPUT_LABEL (asm_out_file, label);
5005 /* Now output the DIE to represent the data object itself. This gets
5006 complicated because of the possibility that the VAR_DECL really
5007 represents an inlined instance of a formal parameter for an inline
5008 function. */
5011 register void (*func) ();
5012 register tree origin = decl_ultimate_origin (decl);
5014 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5015 func = output_formal_parameter_die;
5016 else
5018 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5019 func = output_global_variable_die;
5020 else
5021 func = output_local_variable_die;
5023 output_die (func, decl);
5025 break;
5027 case FIELD_DECL:
5028 /* Ignore the nameless fields that are used to skip bits. */
5029 if (DECL_NAME (decl) != 0)
5031 output_type (member_declared_type (decl), containing_scope);
5032 output_die (output_member_die, decl);
5034 break;
5036 case PARM_DECL:
5037 /* Force out the type of this formal, if it was not forced out yet.
5038 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5039 It should be able to grok the presence of type DIEs within a list
5040 of TAG_formal_parameter DIEs, but it doesn't. */
5042 output_type (TREE_TYPE (decl), containing_scope);
5043 output_die (output_formal_parameter_die, decl);
5044 break;
5046 default:
5047 abort ();
5051 void
5052 dwarfout_file_scope_decl (decl, set_finalizing)
5053 register tree decl;
5054 register int set_finalizing;
5056 if (TREE_CODE (decl) == ERROR_MARK)
5057 return;
5059 /* If this ..._DECL node is marked to be ignored, then ignore it. We
5060 gotta hope that the node in question doesn't represent a function
5061 definition. If it does, then totally ignoring it is bound to screw
5062 up our count of blocks, and that it turn will completely screw up the
5063 the labels we will reference in subsequent AT_low_pc and AT_high_pc
5064 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
5065 don't carry their own sequence numbers with them!) */
5067 if (DECL_IGNORED_P (decl))
5069 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5070 abort ();
5071 return;
5074 switch (TREE_CODE (decl))
5076 case FUNCTION_DECL:
5078 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5079 a builtin function. Explicit programmer-supplied declarations of
5080 these same functions should NOT be ignored however. */
5082 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5083 return;
5085 /* What we would really like to do here is to filter out all mere
5086 file-scope declarations of file-scope functions which are never
5087 referenced later within this translation unit (and keep all of
5088 ones that *are* referenced later on) but we aren't clairvoyant,
5089 so we have no idea which functions will be referenced in the
5090 future (i.e. later on within the current translation unit).
5091 So here we just ignore all file-scope function declarations
5092 which are not also definitions. If and when the debugger needs
5093 to know something about these functions, it wil have to hunt
5094 around and find the DWARF information associated with the
5095 *definition* of the function.
5097 Note that we can't just check `DECL_EXTERNAL' to find out which
5098 FUNCTION_DECL nodes represent definitions and which ones represent
5099 mere declarations. We have to check `DECL_INITIAL' instead. That's
5100 because the C front-end supports some weird semantics for "extern
5101 inline" function definitions. These can get inlined within the
5102 current translation unit (an thus, we need to generate DWARF info
5103 for their abstract instances so that the DWARF info for the
5104 concrete inlined instances can have something to refer to) but
5105 the compiler never generates any out-of-lines instances of such
5106 things (despite the fact that they *are* definitions). The
5107 important point is that the C front-end marks these "extern inline"
5108 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5109 anyway.
5111 Note that the C++ front-end also plays some similar games for inline
5112 function definitions appearing within include files which also
5113 contain `#pragma interface' pragmas. */
5115 if (DECL_INITIAL (decl) == NULL_TREE)
5116 return;
5118 if (TREE_PUBLIC (decl)
5119 && ! DECL_EXTERNAL (decl)
5120 && ! DECL_ABSTRACT (decl))
5122 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5124 /* Output a .debug_pubnames entry for a public function
5125 defined in this compilation unit. */
5127 fputc ('\n', asm_out_file);
5128 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5129 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5130 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5131 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5132 IDENTIFIER_POINTER (DECL_NAME (decl)));
5133 ASM_OUTPUT_POP_SECTION (asm_out_file);
5136 break;
5138 case VAR_DECL:
5140 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5141 object declaration and if the declaration was never even
5142 referenced from within this entire compilation unit. We
5143 suppress these DIEs in order to save space in the .debug section
5144 (by eliminating entries which are probably useless). Note that
5145 we must not suppress block-local extern declarations (whether
5146 used or not) because that would screw-up the debugger's name
5147 lookup mechanism and cause it to miss things which really ought
5148 to be in scope at a given point. */
5150 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5151 return;
5153 if (TREE_PUBLIC (decl)
5154 && ! DECL_EXTERNAL (decl)
5155 && GET_CODE (DECL_RTL (decl)) == MEM
5156 && ! DECL_ABSTRACT (decl))
5158 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5160 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5162 /* Output a .debug_pubnames entry for a public variable
5163 defined in this compilation unit. */
5165 fputc ('\n', asm_out_file);
5166 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5167 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5168 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5169 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5170 IDENTIFIER_POINTER (DECL_NAME (decl)));
5171 ASM_OUTPUT_POP_SECTION (asm_out_file);
5174 if (DECL_INITIAL (decl) == NULL)
5176 /* Output a .debug_aranges entry for a public variable
5177 which is tentatively defined in this compilation unit. */
5179 fputc ('\n', asm_out_file);
5180 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5181 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5182 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5183 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5184 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5185 ASM_OUTPUT_POP_SECTION (asm_out_file);
5189 /* If we are in terse mode, don't generate any DIEs to represent
5190 any variable declarations or definitions. */
5192 if (debug_info_level <= DINFO_LEVEL_TERSE)
5193 return;
5195 break;
5197 case TYPE_DECL:
5198 /* Don't bother trying to generate any DIEs to represent any of the
5199 normal built-in types for the language we are compiling, except
5200 in cases where the types in question are *not* DWARF fundamental
5201 types. We make an exception in the case of non-fundamental types
5202 for the sake of objective C (and perhaps C++) because the GNU
5203 front-ends for these languages may in fact create certain "built-in"
5204 types which are (for example) RECORD_TYPEs. In such cases, we
5205 really need to output these (non-fundamental) types because other
5206 DIEs may contain references to them. */
5208 if (DECL_SOURCE_LINE (decl) == 0
5209 && type_is_fundamental (TREE_TYPE (decl)))
5210 return;
5212 /* If we are in terse mode, don't generate any DIEs to represent
5213 any actual typedefs. Note that even when we are in terse mode,
5214 we must still output DIEs to represent those tagged types which
5215 are used (directly or indirectly) in the specification of either
5216 a return type or a formal parameter type of some function. */
5218 if (debug_info_level <= DINFO_LEVEL_TERSE)
5219 if (! TYPE_DECL_IS_STUB (decl)
5220 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5221 return;
5223 break;
5225 default:
5226 return;
5229 fputc ('\n', asm_out_file);
5230 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5231 finalizing = set_finalizing;
5232 output_decl (decl, NULL_TREE);
5234 /* NOTE: The call above to `output_decl' may have caused one or more
5235 file-scope named types (i.e. tagged types) to be placed onto the
5236 pending_types_list. We have to get those types off of that list
5237 at some point, and this is the perfect time to do it. If we didn't
5238 take them off now, they might still be on the list when cc1 finally
5239 exits. That might be OK if it weren't for the fact that when we put
5240 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5241 for these types, and that causes them never to be output unless
5242 `output_pending_types_for_scope' takes them off of the list and un-sets
5243 their TREE_ASM_WRITTEN flags. */
5245 output_pending_types_for_scope (NULL_TREE);
5247 /* The above call should have totally emptied the pending_types_list. */
5249 if (pending_types != 0)
5250 abort ();
5252 ASM_OUTPUT_POP_SECTION (asm_out_file);
5254 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5255 current_funcdef_number++;
5258 /* Output a marker (i.e. a label) for the beginning of the generated code
5259 for a lexical block. */
5261 void
5262 dwarfout_begin_block (blocknum)
5263 register unsigned blocknum;
5265 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5267 function_section (current_function_decl);
5268 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5269 ASM_OUTPUT_LABEL (asm_out_file, label);
5272 /* Output a marker (i.e. a label) for the end of the generated code
5273 for a lexical block. */
5275 void
5276 dwarfout_end_block (blocknum)
5277 register unsigned blocknum;
5279 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5281 function_section (current_function_decl);
5282 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5283 ASM_OUTPUT_LABEL (asm_out_file, label);
5286 /* Output a marker (i.e. a label) at a point in the assembly code which
5287 corresponds to a given source level label. */
5289 void
5290 dwarfout_label (insn)
5291 register rtx insn;
5293 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5295 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5297 function_section (current_function_decl);
5298 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5299 (unsigned) INSN_UID (insn));
5300 ASM_OUTPUT_LABEL (asm_out_file, label);
5304 /* Output a marker (i.e. a label) for the point in the generated code where
5305 the real body of the function begins (after parameters have been moved
5306 to their home locations). */
5308 void
5309 dwarfout_begin_function ()
5311 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5313 if (! use_gnu_debug_info_extensions)
5314 return;
5315 function_section (current_function_decl);
5316 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5317 ASM_OUTPUT_LABEL (asm_out_file, label);
5320 /* Output a marker (i.e. a label) for the point in the generated code where
5321 the real body of the function ends (just before the epilogue code). */
5323 void
5324 dwarfout_end_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_END_LABEL_FMT, current_funcdef_number);
5332 ASM_OUTPUT_LABEL (asm_out_file, label);
5335 /* Output a marker (i.e. a label) for the absolute end of the generated code
5336 for a function definition. This gets called *after* the epilogue code
5337 has been generated. */
5339 void
5340 dwarfout_end_epilogue ()
5342 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5344 /* Output a label to mark the endpoint of the code generated for this
5345 function. */
5347 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5348 ASM_OUTPUT_LABEL (asm_out_file, label);
5351 static void
5352 shuffle_filename_entry (new_zeroth)
5353 register filename_entry *new_zeroth;
5355 filename_entry temp_entry;
5356 register filename_entry *limit_p;
5357 register filename_entry *move_p;
5359 if (new_zeroth == &filename_table[0])
5360 return;
5362 temp_entry = *new_zeroth;
5364 /* Shift entries up in the table to make room at [0]. */
5366 limit_p = &filename_table[0];
5367 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5368 *move_p = *(move_p-1);
5370 /* Install the found entry at [0]. */
5372 filename_table[0] = temp_entry;
5375 /* Create a new (string) entry for the .debug_sfnames section. */
5377 static void
5378 generate_new_sfname_entry ()
5380 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5382 fputc ('\n', asm_out_file);
5383 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5384 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5385 ASM_OUTPUT_LABEL (asm_out_file, label);
5386 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5387 filename_table[0].name
5388 ? filename_table[0].name
5389 : "");
5390 ASM_OUTPUT_POP_SECTION (asm_out_file);
5393 /* Lookup a filename (in the list of filenames that we know about here in
5394 dwarfout.c) and return its "index". The index of each (known) filename
5395 is just a unique number which is associated with only that one filename.
5396 We need such numbers for the sake of generating labels (in the
5397 .debug_sfnames section) and references to those unique labels (in the
5398 .debug_srcinfo and .debug_macinfo sections).
5400 If the filename given as an argument is not found in our current list,
5401 add it to the list and assign it the next available unique index number.
5403 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5404 one), we shuffle the filename found (or added) up to the zeroth entry of
5405 our list of filenames (which is always searched linearly). We do this so
5406 as to optimize the most common case for these filename lookups within
5407 dwarfout.c. The most common case by far is the case where we call
5408 lookup_filename to lookup the very same filename that we did a lookup
5409 on the last time we called lookup_filename. We make sure that this
5410 common case is fast because such cases will constitute 99.9% of the
5411 lookups we ever do (in practice).
5413 If we add a new filename entry to our table, we go ahead and generate
5414 the corresponding entry in the .debug_sfnames section right away.
5415 Doing so allows us to avoid tickling an assembler bug (present in some
5416 m68k assemblers) which yields assembly-time errors in cases where the
5417 difference of two label addresses is taken and where the two labels
5418 are in a section *other* than the one where the difference is being
5419 calculated, and where at least one of the two symbol references is a
5420 forward reference. (This bug could be tickled by our .debug_srcinfo
5421 entries if we don't output their corresponding .debug_sfnames entries
5422 before them.) */
5424 static unsigned
5425 lookup_filename (file_name)
5426 char *file_name;
5428 register filename_entry *search_p;
5429 register filename_entry *limit_p = &filename_table[ft_entries];
5431 for (search_p = filename_table; search_p < limit_p; search_p++)
5432 if (!strcmp (file_name, search_p->name))
5434 /* When we get here, we have found the filename that we were
5435 looking for in the filename_table. Now we want to make sure
5436 that it gets moved to the zero'th entry in the table (if it
5437 is not already there) so that subsequent attempts to find the
5438 same filename will find it as quickly as possible. */
5440 shuffle_filename_entry (search_p);
5441 return filename_table[0].number;
5444 /* We come here whenever we have a new filename which is not registered
5445 in the current table. Here we add it to the table. */
5447 /* Prepare to add a new table entry by making sure there is enough space
5448 in the table to do so. If not, expand the current table. */
5450 if (ft_entries == ft_entries_allocated)
5452 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5453 filename_table
5454 = (filename_entry *)
5455 xrealloc (filename_table,
5456 ft_entries_allocated * sizeof (filename_entry));
5459 /* Initially, add the new entry at the end of the filename table. */
5461 filename_table[ft_entries].number = ft_entries;
5462 filename_table[ft_entries].name = xstrdup (file_name);
5464 /* Shuffle the new entry into filename_table[0]. */
5466 shuffle_filename_entry (&filename_table[ft_entries]);
5468 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5469 generate_new_sfname_entry ();
5471 ft_entries++;
5472 return filename_table[0].number;
5475 static void
5476 generate_srcinfo_entry (line_entry_num, files_entry_num)
5477 unsigned line_entry_num;
5478 unsigned files_entry_num;
5480 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5482 fputc ('\n', asm_out_file);
5483 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5484 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5485 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5486 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5487 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5488 ASM_OUTPUT_POP_SECTION (asm_out_file);
5491 void
5492 dwarfout_line (filename, line)
5493 register char *filename;
5494 register unsigned line;
5496 if (debug_info_level >= DINFO_LEVEL_NORMAL
5497 /* We can't emit line number info for functions in separate sections,
5498 because the assembler can't subtract labels in different sections. */
5499 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5501 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5502 static unsigned last_line_entry_num = 0;
5503 static unsigned prev_file_entry_num = (unsigned) -1;
5504 register unsigned this_file_entry_num;
5506 function_section (current_function_decl);
5507 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5508 ASM_OUTPUT_LABEL (asm_out_file, label);
5510 fputc ('\n', asm_out_file);
5512 if (use_gnu_debug_info_extensions)
5513 this_file_entry_num = lookup_filename (filename);
5514 else
5515 this_file_entry_num = (unsigned) -1;
5517 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5518 if (this_file_entry_num != prev_file_entry_num)
5520 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5522 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5523 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5527 register char *tail = rindex (filename, '/');
5529 if (tail != NULL)
5530 filename = tail;
5533 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5534 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5535 filename, line);
5536 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5537 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5538 ASM_OUTPUT_POP_SECTION (asm_out_file);
5540 if (this_file_entry_num != prev_file_entry_num)
5541 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5542 prev_file_entry_num = this_file_entry_num;
5546 /* Generate an entry in the .debug_macinfo section. */
5548 static void
5549 generate_macinfo_entry (type_and_offset, string)
5550 register char *type_and_offset;
5551 register char *string;
5553 if (! use_gnu_debug_info_extensions)
5554 return;
5556 fputc ('\n', asm_out_file);
5557 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5558 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5559 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
5560 ASM_OUTPUT_POP_SECTION (asm_out_file);
5563 void
5564 dwarfout_start_new_source_file (filename)
5565 register char *filename;
5567 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5568 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5570 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5571 sprintf (type_and_offset, "0x%08x+%s-%s",
5572 ((unsigned) MACINFO_start << 24),
5573 /* Hack: skip leading '*' . */
5574 (*label == '*') + label,
5575 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5576 generate_macinfo_entry (type_and_offset, "");
5579 void
5580 dwarfout_resume_previous_source_file (lineno)
5581 register unsigned lineno;
5583 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5585 sprintf (type_and_offset, "0x%08x+%u",
5586 ((unsigned) MACINFO_resume << 24), lineno);
5587 generate_macinfo_entry (type_and_offset, "");
5590 /* Called from check_newline in c-parse.y. The `buffer' parameter
5591 contains the tail part of the directive line, i.e. the part which
5592 is past the initial whitespace, #, whitespace, directive-name,
5593 whitespace part. */
5595 void
5596 dwarfout_define (lineno, buffer)
5597 register unsigned lineno;
5598 register char *buffer;
5600 static int initialized = 0;
5601 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5603 if (!initialized)
5605 dwarfout_start_new_source_file (primary_filename);
5606 initialized = 1;
5608 sprintf (type_and_offset, "0x%08x+%u",
5609 ((unsigned) MACINFO_define << 24), lineno);
5610 generate_macinfo_entry (type_and_offset, buffer);
5613 /* Called from check_newline in c-parse.y. The `buffer' parameter
5614 contains the tail part of the directive line, i.e. the part which
5615 is past the initial whitespace, #, whitespace, directive-name,
5616 whitespace part. */
5618 void
5619 dwarfout_undef (lineno, buffer)
5620 register unsigned lineno;
5621 register char *buffer;
5623 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5625 sprintf (type_and_offset, "0x%08x+%u",
5626 ((unsigned) MACINFO_undef << 24), lineno);
5627 generate_macinfo_entry (type_and_offset, buffer);
5630 /* Set up for Dwarf output at the start of compilation. */
5632 void
5633 dwarfout_init (asm_out_file, main_input_filename)
5634 register FILE *asm_out_file;
5635 register char *main_input_filename;
5637 /* Remember the name of the primary input file. */
5639 primary_filename = main_input_filename;
5641 /* Allocate the initial hunk of the pending_sibling_stack. */
5643 pending_sibling_stack
5644 = (unsigned *)
5645 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5646 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5647 pending_siblings = 1;
5649 /* Allocate the initial hunk of the filename_table. */
5651 filename_table
5652 = (filename_entry *)
5653 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5654 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5655 ft_entries = 0;
5657 /* Allocate the initial hunk of the pending_types_list. */
5659 pending_types_list
5660 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5661 pending_types_allocated = PENDING_TYPES_INCREMENT;
5662 pending_types = 0;
5664 /* Create an artificial RECORD_TYPE node which we can use in our hack
5665 to get the DIEs representing types of formal parameters to come out
5666 only *after* the DIEs for the formal parameters themselves. */
5668 fake_containing_scope = make_node (RECORD_TYPE);
5670 /* Output a starting label for the .text section. */
5672 fputc ('\n', asm_out_file);
5673 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5674 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5675 ASM_OUTPUT_POP_SECTION (asm_out_file);
5677 /* Output a starting label for the .data section. */
5679 fputc ('\n', asm_out_file);
5680 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5681 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5682 ASM_OUTPUT_POP_SECTION (asm_out_file);
5684 #if 0 /* GNU C doesn't currently use .data1. */
5685 /* Output a starting label for the .data1 section. */
5687 fputc ('\n', asm_out_file);
5688 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5689 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5690 ASM_OUTPUT_POP_SECTION (asm_out_file);
5691 #endif
5693 /* Output a starting label for the .rodata section. */
5695 fputc ('\n', asm_out_file);
5696 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5697 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5698 ASM_OUTPUT_POP_SECTION (asm_out_file);
5700 #if 0 /* GNU C doesn't currently use .rodata1. */
5701 /* Output a starting label for the .rodata1 section. */
5703 fputc ('\n', asm_out_file);
5704 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5705 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5706 ASM_OUTPUT_POP_SECTION (asm_out_file);
5707 #endif
5709 /* Output a starting label for the .bss section. */
5711 fputc ('\n', asm_out_file);
5712 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5713 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5714 ASM_OUTPUT_POP_SECTION (asm_out_file);
5716 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5718 if (use_gnu_debug_info_extensions)
5720 /* Output a starting label and an initial (compilation directory)
5721 entry for the .debug_sfnames section. The starting label will be
5722 referenced by the initial entry in the .debug_srcinfo section. */
5724 fputc ('\n', asm_out_file);
5725 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5726 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5728 register char *pwd;
5729 register unsigned len;
5730 register char *dirname;
5732 pwd = getpwd ();
5733 if (!pwd)
5734 pfatal_with_name ("getpwd");
5735 len = strlen (pwd);
5736 dirname = (char *) xmalloc (len + 2);
5738 strcpy (dirname, pwd);
5739 strcpy (dirname + len, "/");
5740 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5741 free (dirname);
5743 ASM_OUTPUT_POP_SECTION (asm_out_file);
5746 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5747 && use_gnu_debug_info_extensions)
5749 /* Output a starting label for the .debug_macinfo section. This
5750 label will be referenced by the AT_mac_info attribute in the
5751 TAG_compile_unit DIE. */
5753 fputc ('\n', asm_out_file);
5754 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5755 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5756 ASM_OUTPUT_POP_SECTION (asm_out_file);
5759 /* Generate the initial entry for the .line section. */
5761 fputc ('\n', asm_out_file);
5762 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5763 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5764 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5765 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5766 ASM_OUTPUT_POP_SECTION (asm_out_file);
5768 if (use_gnu_debug_info_extensions)
5770 /* Generate the initial entry for the .debug_srcinfo section. */
5772 fputc ('\n', asm_out_file);
5773 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5774 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5775 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5776 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5777 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5778 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5779 #ifdef DWARF_TIMESTAMPS
5780 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5781 #else
5782 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5783 #endif
5784 ASM_OUTPUT_POP_SECTION (asm_out_file);
5787 /* Generate the initial entry for the .debug_pubnames section. */
5789 fputc ('\n', asm_out_file);
5790 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5791 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5792 ASM_OUTPUT_POP_SECTION (asm_out_file);
5794 /* Generate the initial entry for the .debug_aranges section. */
5796 fputc ('\n', asm_out_file);
5797 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5798 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5799 ASM_OUTPUT_POP_SECTION (asm_out_file);
5802 /* Setup first DIE number == 1. */
5803 NEXT_DIE_NUM = next_unused_dienum++;
5805 /* Generate the initial DIE for the .debug section. Note that the
5806 (string) value given in the AT_name attribute of the TAG_compile_unit
5807 DIE will (typically) be a relative pathname and that this pathname
5808 should be taken as being relative to the directory from which the
5809 compiler was invoked when the given (base) source file was compiled. */
5811 fputc ('\n', asm_out_file);
5812 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5813 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5814 output_die (output_compile_unit_die, main_input_filename);
5815 ASM_OUTPUT_POP_SECTION (asm_out_file);
5817 fputc ('\n', asm_out_file);
5820 /* Output stuff that dwarf requires at the end of every file. */
5822 void
5823 dwarfout_finish ()
5825 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5827 fputc ('\n', asm_out_file);
5828 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5830 /* Mark the end of the chain of siblings which represent all file-scope
5831 declarations in this compilation unit. */
5833 /* The (null) DIE which represents the terminator for the (sibling linked)
5834 list of file-scope items is *special*. Normally, we would just call
5835 end_sibling_chain at this point in order to output a word with the
5836 value `4' and that word would act as the terminator for the list of
5837 DIEs describing file-scope items. Unfortunately, if we were to simply
5838 do that, the label that would follow this DIE in the .debug section
5839 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5840 machines) to a 4 byte boundary.
5842 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5843 the trick used is to insert extra (otherwise useless) padding bytes
5844 into the (null) DIE that we know must precede the ..D2 label in the
5845 .debug section. The amount of padding required can be anywhere between
5846 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5847 with the padding) would normally contain the value 4, but now it will
5848 also have to include the padding bytes, so it will instead have some
5849 value in the range 4..7.
5851 Fortunately, the rules of Dwarf say that any DIE whose length word
5852 contains *any* value less than 8 should be treated as a null DIE, so
5853 this trick works out nicely. Clever, eh? Don't give me any credit
5854 (or blame). I didn't think of this scheme. I just conformed to it.
5857 output_die (output_padded_null_die, (void *) 0);
5858 dienum_pop ();
5860 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5861 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5862 ASM_OUTPUT_POP_SECTION (asm_out_file);
5864 /* Output a terminator label for the .text section. */
5866 fputc ('\n', asm_out_file);
5867 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5868 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5869 ASM_OUTPUT_POP_SECTION (asm_out_file);
5871 /* Output a terminator label for the .data section. */
5873 fputc ('\n', asm_out_file);
5874 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5875 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5876 ASM_OUTPUT_POP_SECTION (asm_out_file);
5878 #if 0 /* GNU C doesn't currently use .data1. */
5879 /* Output a terminator label for the .data1 section. */
5881 fputc ('\n', asm_out_file);
5882 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5883 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5884 ASM_OUTPUT_POP_SECTION (asm_out_file);
5885 #endif
5887 /* Output a terminator label for the .rodata section. */
5889 fputc ('\n', asm_out_file);
5890 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5891 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5892 ASM_OUTPUT_POP_SECTION (asm_out_file);
5894 #if 0 /* GNU C doesn't currently use .rodata1. */
5895 /* Output a terminator label for the .rodata1 section. */
5897 fputc ('\n', asm_out_file);
5898 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5899 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5900 ASM_OUTPUT_POP_SECTION (asm_out_file);
5901 #endif
5903 /* Output a terminator label for the .bss section. */
5905 fputc ('\n', asm_out_file);
5906 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5907 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5908 ASM_OUTPUT_POP_SECTION (asm_out_file);
5910 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5912 /* Output a terminating entry for the .line section. */
5914 fputc ('\n', asm_out_file);
5915 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5916 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5917 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5918 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5919 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5920 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5921 ASM_OUTPUT_POP_SECTION (asm_out_file);
5923 if (use_gnu_debug_info_extensions)
5925 /* Output a terminating entry for the .debug_srcinfo section. */
5927 fputc ('\n', asm_out_file);
5928 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5929 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5930 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5931 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5932 ASM_OUTPUT_POP_SECTION (asm_out_file);
5935 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5937 /* Output terminating entries for the .debug_macinfo section. */
5939 dwarfout_resume_previous_source_file (0);
5941 fputc ('\n', asm_out_file);
5942 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5943 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5944 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5945 ASM_OUTPUT_POP_SECTION (asm_out_file);
5948 /* Generate the terminating entry for the .debug_pubnames section. */
5950 fputc ('\n', asm_out_file);
5951 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5952 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5953 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5954 ASM_OUTPUT_POP_SECTION (asm_out_file);
5956 /* Generate the terminating entries for the .debug_aranges section.
5958 Note that we want to do this only *after* we have output the end
5959 labels (for the various program sections) which we are going to
5960 refer to here. This allows us to work around a bug in the m68k
5961 svr4 assembler. That assembler gives bogus assembly-time errors
5962 if (within any given section) you try to take the difference of
5963 two relocatable symbols, both of which are located within some
5964 other section, and if one (or both?) of the symbols involved is
5965 being forward-referenced. By generating the .debug_aranges
5966 entries at this late point in the assembly output, we skirt the
5967 issue simply by avoiding forward-references.
5970 fputc ('\n', asm_out_file);
5971 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5973 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5974 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5976 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5977 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5979 #if 0 /* GNU C doesn't currently use .data1. */
5980 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5981 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5982 DATA1_BEGIN_LABEL);
5983 #endif
5985 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5986 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5987 RODATA_BEGIN_LABEL);
5989 #if 0 /* GNU C doesn't currently use .rodata1. */
5990 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5991 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5992 RODATA1_BEGIN_LABEL);
5993 #endif
5995 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5996 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5998 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5999 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6001 ASM_OUTPUT_POP_SECTION (asm_out_file);
6005 #endif /* DWARF_DEBUGGING_INFO */