(sne): Modified to use negc instead of xor.
[official-gcc.git] / gcc / dwarfout.c
blobf91cccb3420788b8a32448fe23e84e064bb03fa6
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 /* #define NDEBUG 1 */
37 #include "assert.h"
39 #if defined(DWARF_TIMESTAMPS)
40 #if defined(POSIX)
41 #include <time.h>
42 #else /* !defined(POSIX) */
43 #include <sys/types.h>
44 #if defined(__STDC__)
45 extern time_t time (time_t *);
46 #else /* !defined(__STDC__) */
47 extern time_t time ();
48 #endif /* !defined(__STDC__) */
49 #endif /* !defined(POSIX) */
50 #endif /* defined(DWARF_TIMESTAMPS) */
52 extern char *getpwd ();
54 extern char *index ();
55 extern char *rindex ();
57 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
58 regarding the GNU implementation of Dwarf. */
60 /* NOTE: In the comments in this file, many references are made to
61 so called "Debugging Information Entries". For the sake of brevity,
62 this term is abbreviated to `DIE' throughout the remainder of this
63 file. */
65 /* Note that the implementation of C++ support herein is (as yet) unfinished.
66 If you want to try to complete it, more power to you. */
68 #if !defined(__GNUC__) || (NDEBUG != 1)
69 #define inline
70 #endif
72 /* How to start an assembler comment. */
73 #ifndef ASM_COMMENT_START
74 #define ASM_COMMENT_START ";#"
75 #endif
77 /* How to print out a register name. */
78 #ifndef PRINT_REG
79 #define PRINT_REG(RTX, CODE, FILE) \
80 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
81 #endif
83 /* Define a macro which returns non-zero for any tagged type which is
84 used (directly or indirectly) in the specification of either some
85 function's return type or some formal parameter of some function.
86 We use this macro when we are operating in "terse" mode to help us
87 know what tagged types have to be represented in Dwarf (even in
88 terse mode) and which ones don't.
90 A flag bit with this meaning really should be a part of the normal
91 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
92 for these nodes. For now, we have to just fake it. It it safe for
93 us to simply return zero for all complete tagged types (which will
94 get forced out anyway if they were used in the specification of some
95 formal or return type) and non-zero for all incomplete tagged types.
98 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
100 /* Define a macro which returns non-zero for a TYPE_DECL which was
101 implicitly generated for a tagged type.
103 Note that unlike the gcc front end (which generates a NULL named
104 TYPE_DECL node for each complete tagged type, each array type, and
105 each function type node created) the g++ front end generates a
106 _named_ TYPE_DECL node for each tagged type node created.
107 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
108 generate a DW_TAG_typedef DIE for them. */
109 #define TYPE_DECL_IS_STUB(decl) \
110 (DECL_NAME (decl) == NULL \
111 || (DECL_ARTIFICIAL (decl) \
112 && is_tagged_type (TREE_TYPE (decl)) \
113 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
115 extern int flag_traditional;
116 extern char *version_string;
117 extern char *language_string;
119 /* Maximum size (in bytes) of an artificially generated label. */
121 #define MAX_ARTIFICIAL_LABEL_BYTES 30
123 /* Make sure we know the sizes of the various types dwarf can describe.
124 These are only defaults. If the sizes are different for your target,
125 you should override these values by defining the appropriate symbols
126 in your tm.h file. */
128 #ifndef CHAR_TYPE_SIZE
129 #define CHAR_TYPE_SIZE BITS_PER_UNIT
130 #endif
132 #ifndef SHORT_TYPE_SIZE
133 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
134 #endif
136 #ifndef INT_TYPE_SIZE
137 #define INT_TYPE_SIZE BITS_PER_WORD
138 #endif
140 #ifndef LONG_TYPE_SIZE
141 #define LONG_TYPE_SIZE BITS_PER_WORD
142 #endif
144 #ifndef LONG_LONG_TYPE_SIZE
145 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
146 #endif
148 #ifndef WCHAR_TYPE_SIZE
149 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
150 #endif
152 #ifndef WCHAR_UNSIGNED
153 #define WCHAR_UNSIGNED 0
154 #endif
156 #ifndef FLOAT_TYPE_SIZE
157 #define FLOAT_TYPE_SIZE BITS_PER_WORD
158 #endif
160 #ifndef DOUBLE_TYPE_SIZE
161 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
162 #endif
164 #ifndef LONG_DOUBLE_TYPE_SIZE
165 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
166 #endif
168 /* Structure to keep track of source filenames. */
170 struct filename_entry {
171 unsigned number;
172 char * name;
175 typedef struct filename_entry filename_entry;
177 /* Pointer to an array of elements, each one having the structure above. */
179 static filename_entry *filename_table;
181 /* Total number of entries in the table (i.e. array) pointed to by
182 `filename_table'. This is the *total* and includes both used and
183 unused slots. */
185 static unsigned ft_entries_allocated;
187 /* Number of entries in the filename_table which are actually in use. */
189 static unsigned ft_entries;
191 /* Size (in elements) of increments by which we may expand the filename
192 table. Actually, a single hunk of space of this size should be enough
193 for most typical programs. */
195 #define FT_ENTRIES_INCREMENT 64
197 /* Local pointer to the name of the main input file. Initialized in
198 dwarfout_init. */
200 static char *primary_filename;
202 /* Pointer to the most recent filename for which we produced some line info. */
204 static char *last_filename;
206 /* For Dwarf output, we must assign lexical-blocks id numbers
207 in the order in which their beginnings are encountered.
208 We output Dwarf debugging info that refers to the beginnings
209 and ends of the ranges of code for each lexical block with
210 assembler labels ..Bn and ..Bn.e, where n is the block number.
211 The labels themselves are generated in final.c, which assigns
212 numbers to the blocks in the same way. */
214 static unsigned next_block_number = 2;
216 /* Counter to generate unique names for DIEs. */
218 static unsigned next_unused_dienum = 1;
220 /* Number of the DIE which is currently being generated. */
222 static unsigned current_dienum;
224 /* Number to use for the special "pubname" label on the next DIE which
225 represents a function or data object defined in this compilation
226 unit which has "extern" linkage. */
228 static next_pubname_number = 0;
230 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
232 /* Pointer to a dynamically allocated list of pre-reserved and still
233 pending sibling DIE numbers. Note that this list will grow as needed. */
235 static unsigned *pending_sibling_stack;
237 /* Counter to keep track of the number of pre-reserved and still pending
238 sibling DIE numbers. */
240 static unsigned pending_siblings;
242 /* The currently allocated size of the above list (expressed in number of
243 list elements). */
245 static unsigned pending_siblings_allocated;
247 /* Size (in elements) of increments by which we may expand the pending
248 sibling stack. Actually, a single hunk of space of this size should
249 be enough for most typical programs. */
251 #define PENDING_SIBLINGS_INCREMENT 64
253 /* Non-zero if we are performing our file-scope finalization pass and if
254 we should force out Dwarf descriptions of any and all file-scope
255 tagged types which are still incomplete types. */
257 static int finalizing = 0;
259 /* A pointer to the base of a list of pending types which we haven't
260 generated DIEs for yet, but which we will have to come back to
261 later on. */
263 static tree *pending_types_list;
265 /* Number of elements currently allocated for the pending_types_list. */
267 static unsigned pending_types_allocated;
269 /* Number of elements of pending_types_list currently in use. */
271 static unsigned pending_types;
273 /* Size (in elements) of increments by which we may expand the pending
274 types list. Actually, a single hunk of space of this size should
275 be enough for most typical programs. */
277 #define PENDING_TYPES_INCREMENT 64
279 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
280 This is used in a hack to help us get the DIEs describing types of
281 formal parameters to come *after* all of the DIEs describing the formal
282 parameters themselves. That's necessary in order to be compatible
283 with what the brain-damaged svr4 SDB debugger requires. */
285 static tree fake_containing_scope;
287 /* The number of the current function definition that we are generating
288 debugging information for. These numbers range from 1 up to the maximum
289 number of function definitions contained within the current compilation
290 unit. These numbers are used to create unique labels for various things
291 contained within various function definitions. */
293 static unsigned current_funcdef_number = 1;
295 /* A pointer to the ..._DECL node which we have most recently been working
296 on. We keep this around just in case something about it looks screwy
297 and we want to tell the user what the source coordinates for the actual
298 declaration are. */
300 static tree dwarf_last_decl;
302 /* A flag indicating that we are emitting the member declarations of a
303 class, so member functions and variables should not be entirely emitted.
304 This is a kludge to avoid passing a second argument to output_*_die. */
306 static int in_class;
308 /* Forward declarations for functions defined in this file. */
310 static char *dwarf_tag_name PROTO((unsigned));
311 static char *dwarf_attr_name PROTO((unsigned));
312 static char *dwarf_stack_op_name PROTO((unsigned));
313 static char *dwarf_typemod_name PROTO((unsigned));
314 static char *dwarf_fmt_byte_name PROTO((unsigned));
315 static char *dwarf_fund_type_name PROTO((unsigned));
316 static tree decl_ultimate_origin PROTO((tree));
317 static tree block_ultimate_origin PROTO((tree));
318 static void output_unsigned_leb128 PROTO((unsigned long));
319 static void output_signed_leb128 PROTO((long));
320 static inline int is_body_block PROTO((tree));
321 static int fundamental_type_code PROTO((tree));
322 static tree root_type_1 PROTO((tree, int));
323 static tree root_type PROTO((tree));
324 static void write_modifier_bytes_1 PROTO((tree, int, int, int));
325 static void write_modifier_bytes PROTO((tree, int, int));
326 static inline int type_is_fundamental PROTO((tree));
327 static void equate_decl_number_to_die_number PROTO((tree));
328 static inline void equate_type_number_to_die_number PROTO((tree));
329 static void output_reg_number PROTO((rtx));
330 static void output_mem_loc_descriptor PROTO((rtx));
331 static void output_loc_descriptor PROTO((rtx));
332 static void output_bound_representation PROTO((tree, unsigned, int));
333 static void output_enumeral_list PROTO((tree));
334 static inline unsigned ceiling PROTO((unsigned, unsigned));
335 static inline tree field_type PROTO((tree));
336 static inline unsigned simple_type_align_in_bits PROTO((tree));
337 static inline unsigned simple_type_size_in_bits PROTO((tree));
338 static unsigned field_byte_offset PROTO((tree));
339 static inline void sibling_attribute PROTO((void));
340 static void location_attribute PROTO((rtx));
341 static void data_member_location_attribute PROTO((tree));
342 static void const_value_attribute PROTO((rtx));
343 static void location_or_const_value_attribute PROTO((tree));
344 static inline void name_attribute PROTO((char *));
345 static inline void fund_type_attribute PROTO((unsigned));
346 static void mod_fund_type_attribute PROTO((tree, int, int));
347 static inline void user_def_type_attribute PROTO((tree));
348 static void mod_u_d_type_attribute PROTO((tree, int, int));
349 static inline void ordering_attribute PROTO((unsigned));
350 static void subscript_data_attribute PROTO((tree));
351 static void byte_size_attribute PROTO((tree));
352 static inline void bit_offset_attribute PROTO((tree));
353 static inline void bit_size_attribute PROTO((tree));
354 static inline void element_list_attribute PROTO((tree));
355 static inline void stmt_list_attribute PROTO((char *));
356 static inline void low_pc_attribute PROTO((char *));
357 static inline void high_pc_attribute PROTO((char *));
358 static inline void body_begin_attribute PROTO((char *));
359 static inline void body_end_attribute PROTO((char *));
360 static inline void langauge_attribute PROTO((unsigned));
361 static inline void member_attribute PROTO((tree));
362 static inline void string_length_attribute PROTO((tree));
363 static inline void comp_dir_attribute PROTO((char *));
364 static inline void sf_names_attribute PROTO((char *));
365 static inline void src_info_attribute PROTO((char *));
366 static inline void mac_info_attribute PROTO((char *));
367 static inline void prototyped_attribute PROTO((tree));
368 static inline void producer_attribute PROTO((char *));
369 static inline void inline_attribute PROTO((tree));
370 static inline void containing_type_attribute PROTO((tree));
371 static inline void abstract_origin_attribute PROTO((tree));
372 static inline void src_coords_attribute PROTO((unsigned, unsigned));
373 static inline void pure_or_virtual_attribute PROTO((tree));
374 static void name_and_src_coords_attributes PROTO((tree));
375 static void type_attribute PROTO((tree, int, int));
376 static char *type_tag PROTO((tree));
377 static inline void dienum_push PROTO((void));
378 static inline void dienum_pop PROTO((void));
379 static inline tree member_declared_type PROTO((tree));
380 static char *function_start_label PROTO((tree));
381 static void output_array_type_die PROTO((void *));
382 static void output_set_type_die PROTO((void *));
383 static void output_entry_point_die PROTO((void *));
384 static void output_inlined_enumeration_type_die PROTO((void *));
385 static void output_inlined_structure_type_die PROTO((void *));
386 static void output_inlined_union_type_die PROTO((void *));
387 static void output_enumeration_type_die PROTO((void *));
388 static void output_formal_parameter_die PROTO((void *));
389 static void output_global_subroutine_die PROTO((void *));
390 static void output_global_variable_die PROTO((void *));
391 static void output_label_die PROTO((void *));
392 static void output_lexical_block_die PROTO((void *));
393 static void output_inlined_subroutine_die PROTO((void *));
394 static void output_local_variable_die PROTO((void *));
395 static void output_member_die PROTO((void *));
396 static void output_pointer_type_die PROTO((void *));
397 static void output_reference_type_die PROTO((void *));
398 static void output_ptr_to_mbr_type_die PROTO((void *));
399 static void output_compile_unit_die PROTO((void *));
400 static void output_string_type_die PROTO((void *));
401 static void output_structure_type_die PROTO((void *));
402 static void output_local_subroutine_die PROTO((void *));
403 static void output_subroutine_type_die PROTO((void *));
404 static void output_typedef_die PROTO((void *));
405 static void output_union_type_die PROTO((void *));
406 static void output_unspecified_parameters_die PROTO((void *));
407 static void output_padded_null_die PROTO((void *));
408 static void output_die PROTO((void (*) (), void *));
409 static void end_sibling_chain PROTO((void));
410 static void output_formal_types PROTO((tree));
411 static void pend_type PROTO((tree));
412 static inline int type_of_for_scope PROTO((tree, tree));
413 static void output_pending_types_for_scope PROTO((tree));
414 static void output_type PROTO((tree, tree));
415 static void output_tagged_type_instantiation PROTO((tree));
416 static void output_block PROTO((tree, int));
417 static void output_decls_for_scope PROTO((tree, int));
418 static void output_decl PROTO((tree, tree));
419 static void shuffle_filename_entry PROTO((filename_entry *));
420 static void geneate_new_sfname_entry PROTO((void));
421 static unsigned lookup_filename PROTO((char *));
422 static void generate_srcinfo_entry PROTO((unsigned, unsigned));
423 static void generate_macinfo_entry PROTO((char *, char *));
425 /* Definitions of defaults for assembler-dependent names of various
426 pseudo-ops and section names.
428 Theses may be overridden in your tm.h file (if necessary) for your
429 particular assembler. The default values provided here correspond to
430 what is expected by "standard" AT&T System V.4 assemblers. */
432 #ifndef FILE_ASM_OP
433 #define FILE_ASM_OP ".file"
434 #endif
435 #ifndef VERSION_ASM_OP
436 #define VERSION_ASM_OP ".version"
437 #endif
438 #ifndef UNALIGNED_SHORT_ASM_OP
439 #define UNALIGNED_SHORT_ASM_OP ".2byte"
440 #endif
441 #ifndef UNALIGNED_INT_ASM_OP
442 #define UNALIGNED_INT_ASM_OP ".4byte"
443 #endif
444 #ifndef ASM_BYTE_OP
445 #define ASM_BYTE_OP ".byte"
446 #endif
447 #ifndef SET_ASM_OP
448 #define SET_ASM_OP ".set"
449 #endif
451 /* Pseudo-ops for pushing the current section onto the section stack (and
452 simultaneously changing to a new section) and for poping back to the
453 section we were in immediately before this one. Note that most svr4
454 assemblers only maintain a one level stack... you can push all the
455 sections you want, but you can only pop out one level. (The sparc
456 svr4 assembler is an exception to this general rule.) That's
457 OK because we only use at most one level of the section stack herein. */
459 #ifndef PUSHSECTION_ASM_OP
460 #define PUSHSECTION_ASM_OP ".section"
461 #endif
462 #ifndef POPSECTION_ASM_OP
463 #define POPSECTION_ASM_OP ".previous"
464 #endif
466 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
467 to print the PUSHSECTION_ASM_OP and the section name. The default here
468 works for almost all svr4 assemblers, except for the sparc, where the
469 section name must be enclosed in double quotes. (See sparcv4.h.) */
471 #ifndef PUSHSECTION_FORMAT
472 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
473 #endif
475 #ifndef DEBUG_SECTION
476 #define DEBUG_SECTION ".debug"
477 #endif
478 #ifndef LINE_SECTION
479 #define LINE_SECTION ".line"
480 #endif
481 #ifndef SFNAMES_SECTION
482 #define SFNAMES_SECTION ".debug_sfnames"
483 #endif
484 #ifndef SRCINFO_SECTION
485 #define SRCINFO_SECTION ".debug_srcinfo"
486 #endif
487 #ifndef MACINFO_SECTION
488 #define MACINFO_SECTION ".debug_macinfo"
489 #endif
490 #ifndef PUBNAMES_SECTION
491 #define PUBNAMES_SECTION ".debug_pubnames"
492 #endif
493 #ifndef ARANGES_SECTION
494 #define ARANGES_SECTION ".debug_aranges"
495 #endif
496 #ifndef TEXT_SECTION
497 #define TEXT_SECTION ".text"
498 #endif
499 #ifndef DATA_SECTION
500 #define DATA_SECTION ".data"
501 #endif
502 #ifndef DATA1_SECTION
503 #define DATA1_SECTION ".data1"
504 #endif
505 #ifndef RODATA_SECTION
506 #define RODATA_SECTION ".rodata"
507 #endif
508 #ifndef RODATA1_SECTION
509 #define RODATA1_SECTION ".rodata1"
510 #endif
511 #ifndef BSS_SECTION
512 #define BSS_SECTION ".bss"
513 #endif
515 /* Definitions of defaults for formats and names of various special
516 (artificial) labels which may be generated within this file (when
517 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
519 If necessary, these may be overridden from within your tm.h file,
520 but typically, you should never need to override these.
522 These labels have been hacked (temporarily) so that they all begin with
523 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
524 stock m88k/svr4 assembler, both of which need to see .L at the start of
525 a label in order to prevent that label from going into the linker symbol
526 table). When I get time, I'll have to fix this the right way so that we
527 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
528 but that will require a rather massive set of changes. For the moment,
529 the following definitions out to produce the right results for all svr4
530 and svr3 assemblers. -- rfg
533 #ifndef TEXT_BEGIN_LABEL
534 #define TEXT_BEGIN_LABEL ".L_text_b"
535 #endif
536 #ifndef TEXT_END_LABEL
537 #define TEXT_END_LABEL ".L_text_e"
538 #endif
540 #ifndef DATA_BEGIN_LABEL
541 #define DATA_BEGIN_LABEL ".L_data_b"
542 #endif
543 #ifndef DATA_END_LABEL
544 #define DATA_END_LABEL ".L_data_e"
545 #endif
547 #ifndef DATA1_BEGIN_LABEL
548 #define DATA1_BEGIN_LABEL ".L_data1_b"
549 #endif
550 #ifndef DATA1_END_LABEL
551 #define DATA1_END_LABEL ".L_data1_e"
552 #endif
554 #ifndef RODATA_BEGIN_LABEL
555 #define RODATA_BEGIN_LABEL ".L_rodata_b"
556 #endif
557 #ifndef RODATA_END_LABEL
558 #define RODATA_END_LABEL ".L_rodata_e"
559 #endif
561 #ifndef RODATA1_BEGIN_LABEL
562 #define RODATA1_BEGIN_LABEL ".L_rodata1_b"
563 #endif
564 #ifndef RODATA1_END_LABEL
565 #define RODATA1_END_LABEL ".L_rodata1_e"
566 #endif
568 #ifndef BSS_BEGIN_LABEL
569 #define BSS_BEGIN_LABEL ".L_bss_b"
570 #endif
571 #ifndef BSS_END_LABEL
572 #define BSS_END_LABEL ".L_bss_e"
573 #endif
575 #ifndef LINE_BEGIN_LABEL
576 #define LINE_BEGIN_LABEL ".L_line_b"
577 #endif
578 #ifndef LINE_LAST_ENTRY_LABEL
579 #define LINE_LAST_ENTRY_LABEL ".L_line_last"
580 #endif
581 #ifndef LINE_END_LABEL
582 #define LINE_END_LABEL ".L_line_e"
583 #endif
585 #ifndef DEBUG_BEGIN_LABEL
586 #define DEBUG_BEGIN_LABEL ".L_debug_b"
587 #endif
588 #ifndef SFNAMES_BEGIN_LABEL
589 #define SFNAMES_BEGIN_LABEL ".L_sfnames_b"
590 #endif
591 #ifndef SRCINFO_BEGIN_LABEL
592 #define SRCINFO_BEGIN_LABEL ".L_srcinfo_b"
593 #endif
594 #ifndef MACINFO_BEGIN_LABEL
595 #define MACINFO_BEGIN_LABEL ".L_macinfo_b"
596 #endif
598 #ifndef DIE_BEGIN_LABEL_FMT
599 #define DIE_BEGIN_LABEL_FMT ".L_D%u"
600 #endif
601 #ifndef DIE_END_LABEL_FMT
602 #define DIE_END_LABEL_FMT ".L_D%u_e"
603 #endif
604 #ifndef PUB_DIE_LABEL_FMT
605 #define PUB_DIE_LABEL_FMT ".L_P%u"
606 #endif
607 #ifndef INSN_LABEL_FMT
608 #define INSN_LABEL_FMT ".L_I%u_%u"
609 #endif
610 #ifndef BLOCK_BEGIN_LABEL_FMT
611 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
612 #endif
613 #ifndef BLOCK_END_LABEL_FMT
614 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
615 #endif
616 #ifndef SS_BEGIN_LABEL_FMT
617 #define SS_BEGIN_LABEL_FMT ".L_s%u"
618 #endif
619 #ifndef SS_END_LABEL_FMT
620 #define SS_END_LABEL_FMT ".L_s%u_e"
621 #endif
622 #ifndef EE_BEGIN_LABEL_FMT
623 #define EE_BEGIN_LABEL_FMT ".L_e%u"
624 #endif
625 #ifndef EE_END_LABEL_FMT
626 #define EE_END_LABEL_FMT ".L_e%u_e"
627 #endif
628 #ifndef MT_BEGIN_LABEL_FMT
629 #define MT_BEGIN_LABEL_FMT ".L_t%u"
630 #endif
631 #ifndef MT_END_LABEL_FMT
632 #define MT_END_LABEL_FMT ".L_t%u_e"
633 #endif
634 #ifndef LOC_BEGIN_LABEL_FMT
635 #define LOC_BEGIN_LABEL_FMT ".L_l%u"
636 #endif
637 #ifndef LOC_END_LABEL_FMT
638 #define LOC_END_LABEL_FMT ".L_l%u_e"
639 #endif
640 #ifndef BOUND_BEGIN_LABEL_FMT
641 #define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c"
642 #endif
643 #ifndef BOUND_END_LABEL_FMT
644 #define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e"
645 #endif
646 #ifndef DERIV_BEGIN_LABEL_FMT
647 #define DERIV_BEGIN_LABEL_FMT ".L_d%u"
648 #endif
649 #ifndef DERIV_END_LABEL_FMT
650 #define DERIV_END_LABEL_FMT ".L_d%u_e"
651 #endif
652 #ifndef SL_BEGIN_LABEL_FMT
653 #define SL_BEGIN_LABEL_FMT ".L_sl%u"
654 #endif
655 #ifndef SL_END_LABEL_FMT
656 #define SL_END_LABEL_FMT ".L_sl%u_e"
657 #endif
658 #ifndef BODY_BEGIN_LABEL_FMT
659 #define BODY_BEGIN_LABEL_FMT ".L_b%u"
660 #endif
661 #ifndef BODY_END_LABEL_FMT
662 #define BODY_END_LABEL_FMT ".L_b%u_e"
663 #endif
664 #ifndef FUNC_END_LABEL_FMT
665 #define FUNC_END_LABEL_FMT ".L_f%u_e"
666 #endif
667 #ifndef TYPE_NAME_FMT
668 #define TYPE_NAME_FMT ".L_T%u"
669 #endif
670 #ifndef DECL_NAME_FMT
671 #define DECL_NAME_FMT ".L_E%u"
672 #endif
673 #ifndef LINE_CODE_LABEL_FMT
674 #define LINE_CODE_LABEL_FMT ".L_LC%u"
675 #endif
676 #ifndef SFNAMES_ENTRY_LABEL_FMT
677 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
678 #endif
679 #ifndef LINE_ENTRY_LABEL_FMT
680 #define LINE_ENTRY_LABEL_FMT ".L_LE%u"
681 #endif
683 /* Definitions of defaults for various types of primitive assembly language
684 output operations.
686 If necessary, these may be overridden from within your tm.h file,
687 but typically, you shouldn't need to override these. */
689 #ifndef ASM_OUTPUT_PUSH_SECTION
690 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
691 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
692 #endif
694 #ifndef ASM_OUTPUT_POP_SECTION
695 #define ASM_OUTPUT_POP_SECTION(FILE) \
696 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
697 #endif
699 #ifndef ASM_OUTPUT_SOURCE_FILENAME
700 #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
701 do { fprintf (FILE, "\t%s\t", FILE_ASM_OP); \
702 output_quoted_string (FILE, NAME); \
703 fputc ('\n', FILE); \
704 } while (0)
705 #endif
707 #ifndef ASM_OUTPUT_DWARF_DELTA2
708 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
709 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
710 assemble_name (FILE, LABEL1); \
711 fprintf (FILE, "-"); \
712 assemble_name (FILE, LABEL2); \
713 fprintf (FILE, "\n"); \
714 } while (0)
715 #endif
717 #ifndef ASM_OUTPUT_DWARF_DELTA4
718 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
719 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
720 assemble_name (FILE, LABEL1); \
721 fprintf (FILE, "-"); \
722 assemble_name (FILE, LABEL2); \
723 fprintf (FILE, "\n"); \
724 } while (0)
725 #endif
727 #ifndef ASM_OUTPUT_DWARF_TAG
728 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
729 do { \
730 fprintf ((FILE), "\t%s\t0x%x", \
731 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
732 if (flag_debug_asm) \
733 fprintf ((FILE), "\t%s %s", \
734 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
735 fputc ('\n', (FILE)); \
736 } while (0)
737 #endif
739 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
740 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
741 do { \
742 fprintf ((FILE), "\t%s\t0x%x", \
743 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
744 if (flag_debug_asm) \
745 fprintf ((FILE), "\t%s %s", \
746 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
747 fputc ('\n', (FILE)); \
748 } while (0)
749 #endif
751 #ifndef ASM_OUTPUT_DWARF_STACK_OP
752 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
753 do { \
754 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
755 if (flag_debug_asm) \
756 fprintf ((FILE), "\t%s %s", \
757 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
758 fputc ('\n', (FILE)); \
759 } while (0)
760 #endif
762 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
763 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
764 do { \
765 fprintf ((FILE), "\t%s\t0x%x", \
766 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
767 if (flag_debug_asm) \
768 fprintf ((FILE), "\t%s %s", \
769 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
770 fputc ('\n', (FILE)); \
771 } while (0)
772 #endif
774 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
775 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
776 do { \
777 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
778 if (flag_debug_asm) \
779 fprintf ((FILE), "\t%s %s", \
780 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
781 fputc ('\n', (FILE)); \
782 } while (0)
783 #endif
785 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
786 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
787 do { \
788 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
789 if (flag_debug_asm) \
790 fprintf ((FILE), "\t%s %s", \
791 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
792 fputc ('\n', (FILE)); \
793 } while (0)
794 #endif
796 #ifndef ASM_OUTPUT_DWARF_ADDR
797 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
798 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
799 assemble_name (FILE, LABEL); \
800 fprintf (FILE, "\n"); \
801 } while (0)
802 #endif
804 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
805 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
806 do { \
807 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
808 output_addr_const ((FILE), (RTX)); \
809 fputc ('\n', (FILE)); \
810 } while (0)
811 #endif
813 #ifndef ASM_OUTPUT_DWARF_REF
814 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
815 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
816 assemble_name (FILE, LABEL); \
817 fprintf (FILE, "\n"); \
818 } while (0)
819 #endif
821 #ifndef ASM_OUTPUT_DWARF_DATA1
822 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
823 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
824 #endif
826 #ifndef ASM_OUTPUT_DWARF_DATA2
827 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
828 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
829 #endif
831 #ifndef ASM_OUTPUT_DWARF_DATA4
832 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
833 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
834 #endif
836 #ifndef ASM_OUTPUT_DWARF_DATA8
837 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
838 do { \
839 if (WORDS_BIG_ENDIAN) \
841 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
842 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
844 else \
846 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
847 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
849 } while (0)
850 #endif
852 #ifndef ASM_OUTPUT_DWARF_STRING
853 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
854 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
855 #endif
857 /************************ general utility functions **************************/
859 inline int
860 is_pseudo_reg (rtl)
861 register rtx rtl;
863 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
864 || ((GET_CODE (rtl) == SUBREG)
865 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
868 inline tree
869 type_main_variant (type)
870 register tree type;
872 type = TYPE_MAIN_VARIANT (type);
874 /* There really should be only one main variant among any group of variants
875 of a given type (and all of the MAIN_VARIANT values for all members of
876 the group should point to that one type) but sometimes the C front-end
877 messes this up for array types, so we work around that bug here. */
879 if (TREE_CODE (type) == ARRAY_TYPE)
881 while (type != TYPE_MAIN_VARIANT (type))
882 type = TYPE_MAIN_VARIANT (type);
885 return type;
888 /* Return non-zero if the given type node represents a tagged type. */
890 inline int
891 is_tagged_type (type)
892 register tree type;
894 register enum tree_code code = TREE_CODE (type);
896 return (code == RECORD_TYPE || code == UNION_TYPE
897 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
900 static char *
901 dwarf_tag_name (tag)
902 register unsigned tag;
904 switch (tag)
906 case TAG_padding: return "TAG_padding";
907 case TAG_array_type: return "TAG_array_type";
908 case TAG_class_type: return "TAG_class_type";
909 case TAG_entry_point: return "TAG_entry_point";
910 case TAG_enumeration_type: return "TAG_enumeration_type";
911 case TAG_formal_parameter: return "TAG_formal_parameter";
912 case TAG_global_subroutine: return "TAG_global_subroutine";
913 case TAG_global_variable: return "TAG_global_variable";
914 case TAG_label: return "TAG_label";
915 case TAG_lexical_block: return "TAG_lexical_block";
916 case TAG_local_variable: return "TAG_local_variable";
917 case TAG_member: return "TAG_member";
918 case TAG_pointer_type: return "TAG_pointer_type";
919 case TAG_reference_type: return "TAG_reference_type";
920 case TAG_compile_unit: return "TAG_compile_unit";
921 case TAG_string_type: return "TAG_string_type";
922 case TAG_structure_type: return "TAG_structure_type";
923 case TAG_subroutine: return "TAG_subroutine";
924 case TAG_subroutine_type: return "TAG_subroutine_type";
925 case TAG_typedef: return "TAG_typedef";
926 case TAG_union_type: return "TAG_union_type";
927 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
928 case TAG_variant: return "TAG_variant";
929 case TAG_common_block: return "TAG_common_block";
930 case TAG_common_inclusion: return "TAG_common_inclusion";
931 case TAG_inheritance: return "TAG_inheritance";
932 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
933 case TAG_module: return "TAG_module";
934 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
935 case TAG_set_type: return "TAG_set_type";
936 case TAG_subrange_type: return "TAG_subrange_type";
937 case TAG_with_stmt: return "TAG_with_stmt";
939 /* GNU extensions. */
941 case TAG_format_label: return "TAG_format_label";
942 case TAG_namelist: return "TAG_namelist";
943 case TAG_function_template: return "TAG_function_template";
944 case TAG_class_template: return "TAG_class_template";
946 default: return "TAG_<unknown>";
950 static char *
951 dwarf_attr_name (attr)
952 register unsigned attr;
954 switch (attr)
956 case AT_sibling: return "AT_sibling";
957 case AT_location: return "AT_location";
958 case AT_name: return "AT_name";
959 case AT_fund_type: return "AT_fund_type";
960 case AT_mod_fund_type: return "AT_mod_fund_type";
961 case AT_user_def_type: return "AT_user_def_type";
962 case AT_mod_u_d_type: return "AT_mod_u_d_type";
963 case AT_ordering: return "AT_ordering";
964 case AT_subscr_data: return "AT_subscr_data";
965 case AT_byte_size: return "AT_byte_size";
966 case AT_bit_offset: return "AT_bit_offset";
967 case AT_bit_size: return "AT_bit_size";
968 case AT_element_list: return "AT_element_list";
969 case AT_stmt_list: return "AT_stmt_list";
970 case AT_low_pc: return "AT_low_pc";
971 case AT_high_pc: return "AT_high_pc";
972 case AT_language: return "AT_language";
973 case AT_member: return "AT_member";
974 case AT_discr: return "AT_discr";
975 case AT_discr_value: return "AT_discr_value";
976 case AT_string_length: return "AT_string_length";
977 case AT_common_reference: return "AT_common_reference";
978 case AT_comp_dir: return "AT_comp_dir";
979 case AT_const_value_string: return "AT_const_value_string";
980 case AT_const_value_data2: return "AT_const_value_data2";
981 case AT_const_value_data4: return "AT_const_value_data4";
982 case AT_const_value_data8: return "AT_const_value_data8";
983 case AT_const_value_block2: return "AT_const_value_block2";
984 case AT_const_value_block4: return "AT_const_value_block4";
985 case AT_containing_type: return "AT_containing_type";
986 case AT_default_value_addr: return "AT_default_value_addr";
987 case AT_default_value_data2: return "AT_default_value_data2";
988 case AT_default_value_data4: return "AT_default_value_data4";
989 case AT_default_value_data8: return "AT_default_value_data8";
990 case AT_default_value_string: return "AT_default_value_string";
991 case AT_friends: return "AT_friends";
992 case AT_inline: return "AT_inline";
993 case AT_is_optional: return "AT_is_optional";
994 case AT_lower_bound_ref: return "AT_lower_bound_ref";
995 case AT_lower_bound_data2: return "AT_lower_bound_data2";
996 case AT_lower_bound_data4: return "AT_lower_bound_data4";
997 case AT_lower_bound_data8: return "AT_lower_bound_data8";
998 case AT_private: return "AT_private";
999 case AT_producer: return "AT_producer";
1000 case AT_program: return "AT_program";
1001 case AT_protected: return "AT_protected";
1002 case AT_prototyped: return "AT_prototyped";
1003 case AT_public: return "AT_public";
1004 case AT_pure_virtual: return "AT_pure_virtual";
1005 case AT_return_addr: return "AT_return_addr";
1006 case AT_abstract_origin: return "AT_abstract_origin";
1007 case AT_start_scope: return "AT_start_scope";
1008 case AT_stride_size: return "AT_stride_size";
1009 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1010 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1011 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1012 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1013 case AT_virtual: return "AT_virtual";
1015 /* GNU extensions */
1017 case AT_sf_names: return "AT_sf_names";
1018 case AT_src_info: return "AT_src_info";
1019 case AT_mac_info: return "AT_mac_info";
1020 case AT_src_coords: return "AT_src_coords";
1021 case AT_body_begin: return "AT_body_begin";
1022 case AT_body_end: return "AT_body_end";
1024 default: return "AT_<unknown>";
1028 static char *
1029 dwarf_stack_op_name (op)
1030 register unsigned op;
1032 switch (op)
1034 case OP_REG: return "OP_REG";
1035 case OP_BASEREG: return "OP_BASEREG";
1036 case OP_ADDR: return "OP_ADDR";
1037 case OP_CONST: return "OP_CONST";
1038 case OP_DEREF2: return "OP_DEREF2";
1039 case OP_DEREF4: return "OP_DEREF4";
1040 case OP_ADD: return "OP_ADD";
1041 default: return "OP_<unknown>";
1045 static char *
1046 dwarf_typemod_name (mod)
1047 register unsigned mod;
1049 switch (mod)
1051 case MOD_pointer_to: return "MOD_pointer_to";
1052 case MOD_reference_to: return "MOD_reference_to";
1053 case MOD_const: return "MOD_const";
1054 case MOD_volatile: return "MOD_volatile";
1055 default: return "MOD_<unknown>";
1059 static char *
1060 dwarf_fmt_byte_name (fmt)
1061 register unsigned fmt;
1063 switch (fmt)
1065 case FMT_FT_C_C: return "FMT_FT_C_C";
1066 case FMT_FT_C_X: return "FMT_FT_C_X";
1067 case FMT_FT_X_C: return "FMT_FT_X_C";
1068 case FMT_FT_X_X: return "FMT_FT_X_X";
1069 case FMT_UT_C_C: return "FMT_UT_C_C";
1070 case FMT_UT_C_X: return "FMT_UT_C_X";
1071 case FMT_UT_X_C: return "FMT_UT_X_C";
1072 case FMT_UT_X_X: return "FMT_UT_X_X";
1073 case FMT_ET: return "FMT_ET";
1074 default: return "FMT_<unknown>";
1078 static char *
1079 dwarf_fund_type_name (ft)
1080 register unsigned ft;
1082 switch (ft)
1084 case FT_char: return "FT_char";
1085 case FT_signed_char: return "FT_signed_char";
1086 case FT_unsigned_char: return "FT_unsigned_char";
1087 case FT_short: return "FT_short";
1088 case FT_signed_short: return "FT_signed_short";
1089 case FT_unsigned_short: return "FT_unsigned_short";
1090 case FT_integer: return "FT_integer";
1091 case FT_signed_integer: return "FT_signed_integer";
1092 case FT_unsigned_integer: return "FT_unsigned_integer";
1093 case FT_long: return "FT_long";
1094 case FT_signed_long: return "FT_signed_long";
1095 case FT_unsigned_long: return "FT_unsigned_long";
1096 case FT_pointer: return "FT_pointer";
1097 case FT_float: return "FT_float";
1098 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1099 case FT_ext_prec_float: return "FT_ext_prec_float";
1100 case FT_complex: return "FT_complex";
1101 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1102 case FT_void: return "FT_void";
1103 case FT_boolean: return "FT_boolean";
1104 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1105 case FT_label: return "FT_label";
1107 /* GNU extensions. */
1109 case FT_long_long: return "FT_long_long";
1110 case FT_signed_long_long: return "FT_signed_long_long";
1111 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1113 case FT_int8: return "FT_int8";
1114 case FT_signed_int8: return "FT_signed_int8";
1115 case FT_unsigned_int8: return "FT_unsigned_int8";
1116 case FT_int16: return "FT_int16";
1117 case FT_signed_int16: return "FT_signed_int16";
1118 case FT_unsigned_int16: return "FT_unsigned_int16";
1119 case FT_int32: return "FT_int32";
1120 case FT_signed_int32: return "FT_signed_int32";
1121 case FT_unsigned_int32: return "FT_unsigned_int32";
1122 case FT_int64: return "FT_int64";
1123 case FT_signed_int64: return "FT_signed_int64";
1124 case FT_unsigned_int64: return "FT_unsigned_int64";
1126 case FT_real32: return "FT_real32";
1127 case FT_real64: return "FT_real64";
1128 case FT_real96: return "FT_real96";
1129 case FT_real128: return "FT_real128";
1131 default: return "FT_<unknown>";
1135 /* Determine the "ultimate origin" of a decl. The decl may be an
1136 inlined instance of an inlined instance of a decl which is local
1137 to an inline function, so we have to trace all of the way back
1138 through the origin chain to find out what sort of node actually
1139 served as the original seed for the given block. */
1141 static tree
1142 decl_ultimate_origin (decl)
1143 register tree decl;
1145 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1147 if (immediate_origin == NULL)
1148 return NULL;
1149 else
1151 register tree ret_val;
1152 register tree lookahead = immediate_origin;
1156 ret_val = lookahead;
1157 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1159 while (lookahead != NULL && lookahead != ret_val);
1160 return ret_val;
1164 /* Determine the "ultimate origin" of a block. The block may be an
1165 inlined instance of an inlined instance of a block which is local
1166 to an inline function, so we have to trace all of the way back
1167 through the origin chain to find out what sort of node actually
1168 served as the original seed for the given block. */
1170 static tree
1171 block_ultimate_origin (block)
1172 register tree block;
1174 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1176 if (immediate_origin == NULL)
1177 return NULL;
1178 else
1180 register tree ret_val;
1181 register tree lookahead = immediate_origin;
1185 ret_val = lookahead;
1186 lookahead = (TREE_CODE (ret_val) == BLOCK)
1187 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1188 : NULL;
1190 while (lookahead != NULL && lookahead != ret_val);
1191 return ret_val;
1195 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1196 of a virtual function may refer to a base class, so we check the 'this'
1197 parameter. */
1199 static tree
1200 decl_class_context (decl)
1201 tree decl;
1203 tree context = NULL_TREE;
1204 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1205 context = DECL_CONTEXT (decl);
1206 else
1207 context = TYPE_MAIN_VARIANT
1208 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1210 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1211 context = NULL_TREE;
1213 return context;
1216 static void
1217 output_unsigned_leb128 (value)
1218 register unsigned long value;
1220 register unsigned long orig_value = value;
1224 register unsigned byte = (value & 0x7f);
1226 value >>= 7;
1227 if (value != 0) /* more bytes to follow */
1228 byte |= 0x80;
1229 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1230 if (flag_debug_asm && value == 0)
1231 fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1232 ASM_COMMENT_START, orig_value);
1233 fputc ('\n', asm_out_file);
1235 while (value != 0);
1238 static void
1239 output_signed_leb128 (value)
1240 register long value;
1242 register long orig_value = value;
1243 register int negative = (value < 0);
1244 register int more;
1248 register unsigned byte = (value & 0x7f);
1250 value >>= 7;
1251 if (negative)
1252 value |= 0xfe000000; /* manually sign extend */
1253 if (((value == 0) && ((byte & 0x40) == 0))
1254 || ((value == -1) && ((byte & 0x40) == 1)))
1255 more = 0;
1256 else
1258 byte |= 0x80;
1259 more = 1;
1261 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1262 if (flag_debug_asm && more == 0)
1263 fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1264 ASM_COMMENT_START, orig_value);
1265 fputc ('\n', asm_out_file);
1267 while (more);
1270 /**************** utility functions for attribute functions ******************/
1272 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1273 node in question represents the outermost pair of curly braces (i.e.
1274 the "body block") of a function or method.
1276 For any BLOCK node representing a "body block" of a function or method,
1277 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1278 which represents the outermost (function) scope for the function or
1279 method (i.e. the one which includes the formal parameters). The
1280 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1281 FUNCTION_DECL node.
1284 static inline int
1285 is_body_block (stmt)
1286 register tree stmt;
1288 if (TREE_CODE (stmt) == BLOCK)
1290 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1292 if (TREE_CODE (parent) == BLOCK)
1294 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1296 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1297 return 1;
1300 return 0;
1303 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1304 type code for the given type.
1306 This routine must only be called for GCC type nodes that correspond to
1307 Dwarf fundamental types.
1309 The current Dwarf draft specification calls for Dwarf fundamental types
1310 to accurately reflect the fact that a given type was either a "plain"
1311 integral type or an explicitly "signed" integral type. Unfortunately,
1312 we can't always do this, because GCC may already have thrown away the
1313 information about the precise way in which the type was originally
1314 specified, as in:
1316 typedef signed int my_type;
1318 struct s { my_type f; };
1320 Since we may be stuck here without enought information to do exactly
1321 what is called for in the Dwarf draft specification, we do the best
1322 that we can under the circumstances and always use the "plain" integral
1323 fundamental type codes for int, short, and long types. That's probably
1324 good enough. The additional accuracy called for in the current DWARF
1325 draft specification is probably never even useful in practice. */
1327 static int
1328 fundamental_type_code (type)
1329 register tree type;
1331 if (TREE_CODE (type) == ERROR_MARK)
1332 return 0;
1334 switch (TREE_CODE (type))
1336 case ERROR_MARK:
1337 return FT_void;
1339 case VOID_TYPE:
1340 return FT_void;
1342 case INTEGER_TYPE:
1343 /* Carefully distinguish all the standard types of C,
1344 without messing up if the language is not C.
1345 Note that we check only for the names that contain spaces;
1346 other names might occur by coincidence in other languages. */
1347 if (TYPE_NAME (type) != 0
1348 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1349 && DECL_NAME (TYPE_NAME (type)) != 0
1350 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1352 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1354 if (!strcmp (name, "unsigned char"))
1355 return FT_unsigned_char;
1356 if (!strcmp (name, "signed char"))
1357 return FT_signed_char;
1358 if (!strcmp (name, "unsigned int"))
1359 return FT_unsigned_integer;
1360 if (!strcmp (name, "short int"))
1361 return FT_short;
1362 if (!strcmp (name, "short unsigned int"))
1363 return FT_unsigned_short;
1364 if (!strcmp (name, "long int"))
1365 return FT_long;
1366 if (!strcmp (name, "long unsigned int"))
1367 return FT_unsigned_long;
1368 if (!strcmp (name, "long long int"))
1369 return FT_long_long; /* Not grok'ed by svr4 SDB */
1370 if (!strcmp (name, "long long unsigned int"))
1371 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1374 /* Most integer types will be sorted out above, however, for the
1375 sake of special `array index' integer types, the following code
1376 is also provided. */
1378 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1379 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1381 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1382 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1384 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1385 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1387 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1388 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1390 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1391 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1393 abort ();
1395 case REAL_TYPE:
1396 /* Carefully distinguish all the standard types of C,
1397 without messing up if the language is not C. */
1398 if (TYPE_NAME (type) != 0
1399 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1400 && DECL_NAME (TYPE_NAME (type)) != 0
1401 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1403 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1405 /* Note that here we can run afowl of a serious bug in "classic"
1406 svr4 SDB debuggers. They don't seem to understand the
1407 FT_ext_prec_float type (even though they should). */
1409 if (!strcmp (name, "long double"))
1410 return FT_ext_prec_float;
1413 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1414 return FT_dbl_prec_float;
1415 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1416 return FT_float;
1418 /* Note that here we can run afowl of a serious bug in "classic"
1419 svr4 SDB debuggers. They don't seem to understand the
1420 FT_ext_prec_float type (even though they should). */
1422 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1423 return FT_ext_prec_float;
1424 abort ();
1426 case COMPLEX_TYPE:
1427 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1429 case CHAR_TYPE:
1430 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1432 case BOOLEAN_TYPE:
1433 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1435 default:
1436 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1438 return 0;
1441 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1442 the Dwarf "root" type for the given input type. The Dwarf "root" type
1443 of a given type is generally the same as the given type, except that if
1444 the given type is a pointer or reference type, then the root type of
1445 the given type is the root type of the "basis" type for the pointer or
1446 reference type. (This definition of the "root" type is recursive.)
1447 Also, the root type of a `const' qualified type or a `volatile'
1448 qualified type is the root type of the given type without the
1449 qualifiers. */
1451 static tree
1452 root_type_1 (type, count)
1453 register tree type;
1454 register int count;
1456 /* Give up after searching 1000 levels, in case this is a recursive
1457 pointer type. Such types are possible in Ada, but it is not possible
1458 to represent them in DWARF1 debug info. */
1459 if (count > 1000)
1460 return error_mark_node;
1462 switch (TREE_CODE (type))
1464 case ERROR_MARK:
1465 return error_mark_node;
1467 case POINTER_TYPE:
1468 case REFERENCE_TYPE:
1469 return root_type_1 (TREE_TYPE (type), count+1);
1471 default:
1472 return type;
1476 static tree
1477 root_type (type)
1478 register tree type;
1480 type = root_type_1 (type, 0);
1481 if (type != error_mark_node)
1482 type = type_main_variant (type);
1483 return type;
1486 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1487 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1489 static void
1490 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1491 register tree type;
1492 register int decl_const;
1493 register int decl_volatile;
1494 register int count;
1496 if (TREE_CODE (type) == ERROR_MARK)
1497 return;
1499 /* Give up after searching 1000 levels, in case this is a recursive
1500 pointer type. Such types are possible in Ada, but it is not possible
1501 to represent them in DWARF1 debug info. */
1502 if (count > 1000)
1503 return;
1505 if (TYPE_READONLY (type) || decl_const)
1506 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1507 if (TYPE_VOLATILE (type) || decl_volatile)
1508 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1509 switch (TREE_CODE (type))
1511 case POINTER_TYPE:
1512 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1513 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1514 return;
1516 case REFERENCE_TYPE:
1517 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1518 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1519 return;
1521 case ERROR_MARK:
1522 default:
1523 return;
1527 static void
1528 write_modifier_bytes (type, decl_const, decl_volatile)
1529 register tree type;
1530 register int decl_const;
1531 register int decl_volatile;
1533 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1536 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1537 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1539 static inline int
1540 type_is_fundamental (type)
1541 register tree type;
1543 switch (TREE_CODE (type))
1545 case ERROR_MARK:
1546 case VOID_TYPE:
1547 case INTEGER_TYPE:
1548 case REAL_TYPE:
1549 case COMPLEX_TYPE:
1550 case BOOLEAN_TYPE:
1551 case CHAR_TYPE:
1552 return 1;
1554 case SET_TYPE:
1555 case ARRAY_TYPE:
1556 case RECORD_TYPE:
1557 case UNION_TYPE:
1558 case QUAL_UNION_TYPE:
1559 case ENUMERAL_TYPE:
1560 case FUNCTION_TYPE:
1561 case METHOD_TYPE:
1562 case POINTER_TYPE:
1563 case REFERENCE_TYPE:
1564 case FILE_TYPE:
1565 case OFFSET_TYPE:
1566 case LANG_TYPE:
1567 return 0;
1569 default:
1570 abort ();
1572 return 0;
1575 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1576 equate directive which will associate a symbolic name with the current DIE.
1578 The name used is an artificial label generated from the DECL_UID number
1579 associated with the given decl node. The name it gets equated to is the
1580 symbolic label that we (previously) output at the start of the DIE that
1581 we are currently generating.
1583 Calling this function while generating some "decl related" form of DIE
1584 makes it possible to later refer to the DIE which represents the given
1585 decl simply by re-generating the symbolic name from the ..._DECL node's
1586 UID number. */
1588 static void
1589 equate_decl_number_to_die_number (decl)
1590 register tree decl;
1592 /* In the case where we are generating a DIE for some ..._DECL node
1593 which represents either some inline function declaration or some
1594 entity declared within an inline function declaration/definition,
1595 setup a symbolic name for the current DIE so that we have a name
1596 for this DIE that we can easily refer to later on within
1597 AT_abstract_origin attributes. */
1599 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1600 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1602 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1603 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1604 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1607 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1608 equate directive which will associate a symbolic name with the current DIE.
1610 The name used is an artificial label generated from the TYPE_UID number
1611 associated with the given type node. The name it gets equated to is the
1612 symbolic label that we (previously) output at the start of the DIE that
1613 we are currently generating.
1615 Calling this function while generating some "type related" form of DIE
1616 makes it easy to later refer to the DIE which represents the given type
1617 simply by re-generating the alternative name from the ..._TYPE node's
1618 UID number. */
1620 static inline void
1621 equate_type_number_to_die_number (type)
1622 register tree type;
1624 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1625 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1627 /* We are generating a DIE to represent the main variant of this type
1628 (i.e the type without any const or volatile qualifiers) so in order
1629 to get the equate to come out right, we need to get the main variant
1630 itself here. */
1632 type = type_main_variant (type);
1634 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1635 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1636 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1639 static void
1640 output_reg_number (rtl)
1641 register rtx rtl;
1643 register unsigned regno = REGNO (rtl);
1645 if (regno >= FIRST_PSEUDO_REGISTER)
1647 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1648 regno);
1649 regno = 0;
1651 fprintf (asm_out_file, "\t%s\t0x%x",
1652 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1653 if (flag_debug_asm)
1655 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1656 PRINT_REG (rtl, 0, asm_out_file);
1658 fputc ('\n', asm_out_file);
1661 /* The following routine is a nice and simple transducer. It converts the
1662 RTL for a variable or parameter (resident in memory) into an equivalent
1663 Dwarf representation of a mechanism for getting the address of that same
1664 variable onto the top of a hypothetical "address evaluation" stack.
1666 When creating memory location descriptors, we are effectively trans-
1667 forming the RTL for a memory-resident object into its Dwarf postfix
1668 expression equivalent. This routine just recursively descends an
1669 RTL tree, turning it into Dwarf postfix code as it goes. */
1671 static void
1672 output_mem_loc_descriptor (rtl)
1673 register rtx rtl;
1675 /* Note that for a dynamically sized array, the location we will
1676 generate a description of here will be the lowest numbered location
1677 which is actually within the array. That's *not* necessarily the
1678 same as the zeroth element of the array. */
1680 switch (GET_CODE (rtl))
1682 case SUBREG:
1684 /* The case of a subreg may arise when we have a local (register)
1685 variable or a formal (register) parameter which doesn't quite
1686 fill up an entire register. For now, just assume that it is
1687 legitimate to make the Dwarf info refer to the whole register
1688 which contains the given subreg. */
1690 rtl = XEXP (rtl, 0);
1691 /* Drop thru. */
1693 case REG:
1695 /* Whenever a register number forms a part of the description of
1696 the method for calculating the (dynamic) address of a memory
1697 resident object, DWARF rules require the register number to
1698 be referred to as a "base register". This distinction is not
1699 based in any way upon what category of register the hardware
1700 believes the given register belongs to. This is strictly
1701 DWARF terminology we're dealing with here.
1703 Note that in cases where the location of a memory-resident data
1704 object could be expressed as:
1706 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1708 the actual DWARF location descriptor that we generate may just
1709 be OP_BASEREG (basereg). This may look deceptively like the
1710 object in question was allocated to a register (rather than
1711 in memory) so DWARF consumers need to be aware of the subtle
1712 distinction between OP_REG and OP_BASEREG. */
1714 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1715 output_reg_number (rtl);
1716 break;
1718 case MEM:
1719 output_mem_loc_descriptor (XEXP (rtl, 0));
1720 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1721 break;
1723 case CONST:
1724 case SYMBOL_REF:
1725 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1726 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1727 break;
1729 case PLUS:
1730 output_mem_loc_descriptor (XEXP (rtl, 0));
1731 output_mem_loc_descriptor (XEXP (rtl, 1));
1732 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1733 break;
1735 case CONST_INT:
1736 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1737 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1738 break;
1740 case MULT:
1741 /* If a pseudo-reg is optimized away, it is possible for it to
1742 be replaced with a MEM containing a multiply. Use a GNU extension
1743 to describe it. */
1744 output_mem_loc_descriptor (XEXP (rtl, 0));
1745 output_mem_loc_descriptor (XEXP (rtl, 1));
1746 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1747 break;
1749 default:
1750 abort ();
1754 /* Output a proper Dwarf location descriptor for a variable or parameter
1755 which is either allocated in a register or in a memory location. For
1756 a register, we just generate an OP_REG and the register number. For a
1757 memory location we provide a Dwarf postfix expression describing how to
1758 generate the (dynamic) address of the object onto the address stack. */
1760 static void
1761 output_loc_descriptor (rtl)
1762 register rtx rtl;
1764 switch (GET_CODE (rtl))
1766 case SUBREG:
1768 /* The case of a subreg may arise when we have a local (register)
1769 variable or a formal (register) parameter which doesn't quite
1770 fill up an entire register. For now, just assume that it is
1771 legitimate to make the Dwarf info refer to the whole register
1772 which contains the given subreg. */
1774 rtl = XEXP (rtl, 0);
1775 /* Drop thru. */
1777 case REG:
1778 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1779 output_reg_number (rtl);
1780 break;
1782 case MEM:
1783 output_mem_loc_descriptor (XEXP (rtl, 0));
1784 break;
1786 default:
1787 abort (); /* Should never happen */
1791 /* Given a tree node describing an array bound (either lower or upper)
1792 output a representation for that bound. */
1794 static void
1795 output_bound_representation (bound, dim_num, u_or_l)
1796 register tree bound;
1797 register unsigned dim_num; /* For multi-dimensional arrays. */
1798 register char u_or_l; /* Designates upper or lower bound. */
1800 switch (TREE_CODE (bound))
1803 case ERROR_MARK:
1804 return;
1806 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1808 case INTEGER_CST:
1809 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1810 (unsigned) TREE_INT_CST_LOW (bound));
1811 break;
1813 default:
1815 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1816 SAVE_EXPR nodes, in which case we can do something, or as
1817 an expression, which we cannot represent. */
1819 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1820 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1822 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1823 current_dienum, dim_num, u_or_l);
1825 sprintf (end_label, BOUND_END_LABEL_FMT,
1826 current_dienum, dim_num, u_or_l);
1828 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1829 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1831 /* If optimization is turned on, the SAVE_EXPRs that describe
1832 how to access the upper bound values are essentially bogus.
1833 They only describe (at best) how to get at these values at
1834 the points in the generated code right after they have just
1835 been computed. Worse yet, in the typical case, the upper
1836 bound values will not even *be* computed in the optimized
1837 code, so these SAVE_EXPRs are entirely bogus.
1839 In order to compensate for this fact, we check here to see
1840 if optimization is enabled, and if so, we effectively create
1841 an empty location description for the (unknown and unknowable)
1842 upper bound.
1844 This should not cause too much trouble for existing (stupid?)
1845 debuggers because they have to deal with empty upper bounds
1846 location descriptions anyway in order to be able to deal with
1847 incomplete array types.
1849 Of course an intelligent debugger (GDB?) should be able to
1850 comprehend that a missing upper bound specification in a
1851 array type used for a storage class `auto' local array variable
1852 indicates that the upper bound is both unknown (at compile-
1853 time) and unknowable (at run-time) due to optimization. */
1855 if (! optimize)
1857 while (TREE_CODE (bound) == NOP_EXPR
1858 || TREE_CODE (bound) == CONVERT_EXPR)
1859 bound = TREE_OPERAND (bound, 0);
1861 if (TREE_CODE (bound) == SAVE_EXPR)
1862 output_loc_descriptor
1863 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX, 0));
1866 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1868 break;
1873 /* Recursive function to output a sequence of value/name pairs for
1874 enumeration constants in reversed order. This is called from
1875 enumeration_type_die. */
1877 static void
1878 output_enumeral_list (link)
1879 register tree link;
1881 if (link)
1883 output_enumeral_list (TREE_CHAIN (link));
1884 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1885 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1886 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1887 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1891 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1892 which is not less than the value itself. */
1894 static inline unsigned
1895 ceiling (value, boundary)
1896 register unsigned value;
1897 register unsigned boundary;
1899 return (((value + boundary - 1) / boundary) * boundary);
1902 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1903 pointer to the declared type for the relevant field variable, or return
1904 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1906 static inline tree
1907 field_type (decl)
1908 register tree decl;
1910 register tree type;
1912 if (TREE_CODE (decl) == ERROR_MARK)
1913 return integer_type_node;
1915 type = DECL_BIT_FIELD_TYPE (decl);
1916 if (type == NULL)
1917 type = TREE_TYPE (decl);
1918 return type;
1921 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1922 node, return the alignment in bits for the type, or else return
1923 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1925 static inline unsigned
1926 simple_type_align_in_bits (type)
1927 register tree type;
1929 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1932 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1933 node, return the size in bits for the type if it is a constant, or
1934 else return the alignment for the type if the type's size is not
1935 constant, or else return BITS_PER_WORD if the type actually turns out
1936 to be an ERROR_MARK node. */
1938 static inline unsigned
1939 simple_type_size_in_bits (type)
1940 register tree type;
1942 if (TREE_CODE (type) == ERROR_MARK)
1943 return BITS_PER_WORD;
1944 else
1946 register tree type_size_tree = TYPE_SIZE (type);
1948 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1949 return TYPE_ALIGN (type);
1951 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1955 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1956 return the byte offset of the lowest addressed byte of the "containing
1957 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1958 mine what that offset is, either because the argument turns out to be a
1959 pointer to an ERROR_MARK node, or because the offset is actually variable.
1960 (We can't handle the latter case just yet.) */
1962 static unsigned
1963 field_byte_offset (decl)
1964 register tree decl;
1966 register unsigned type_align_in_bytes;
1967 register unsigned type_align_in_bits;
1968 register unsigned type_size_in_bits;
1969 register unsigned object_offset_in_align_units;
1970 register unsigned object_offset_in_bits;
1971 register unsigned object_offset_in_bytes;
1972 register tree type;
1973 register tree bitpos_tree;
1974 register tree field_size_tree;
1975 register unsigned bitpos_int;
1976 register unsigned deepest_bitpos;
1977 register unsigned field_size_in_bits;
1979 if (TREE_CODE (decl) == ERROR_MARK)
1980 return 0;
1982 if (TREE_CODE (decl) != FIELD_DECL)
1983 abort ();
1985 type = field_type (decl);
1987 bitpos_tree = DECL_FIELD_BITPOS (decl);
1988 field_size_tree = DECL_SIZE (decl);
1990 /* We cannot yet cope with fields whose positions or sizes are variable,
1991 so for now, when we see such things, we simply return 0. Someday,
1992 we may be able to handle such cases, but it will be damn difficult. */
1994 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1995 return 0;
1996 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1998 if (TREE_CODE (field_size_tree) != INTEGER_CST)
1999 return 0;
2000 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
2002 type_size_in_bits = simple_type_size_in_bits (type);
2004 type_align_in_bits = simple_type_align_in_bits (type);
2005 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2007 /* Note that the GCC front-end doesn't make any attempt to keep track
2008 of the starting bit offset (relative to the start of the containing
2009 structure type) of the hypothetical "containing object" for a bit-
2010 field. Thus, when computing the byte offset value for the start of
2011 the "containing object" of a bit-field, we must deduce this infor-
2012 mation on our own.
2014 This can be rather tricky to do in some cases. For example, handling
2015 the following structure type definition when compiling for an i386/i486
2016 target (which only aligns long long's to 32-bit boundaries) can be very
2017 tricky:
2019 struct S {
2020 int field1;
2021 long long field2:31;
2024 Fortunately, there is a simple rule-of-thumb which can be used in such
2025 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2026 the structure shown above. It decides to do this based upon one simple
2027 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2028 taining object" for each bit-field at the first (i.e. lowest addressed)
2029 legitimate alignment boundary (based upon the required minimum alignment
2030 for the declared type of the field) which it can possibly use, subject
2031 to the condition that there is still enough available space remaining
2032 in the containing object (when allocated at the selected point) to
2033 fully accommodate all of the bits of the bit-field itself.
2035 This simple rule makes it obvious why GCC allocates 8 bytes for each
2036 object of the structure type shown above. When looking for a place to
2037 allocate the "containing object" for `field2', the compiler simply tries
2038 to allocate a 64-bit "containing object" at each successive 32-bit
2039 boundary (starting at zero) until it finds a place to allocate that 64-
2040 bit field such that at least 31 contiguous (and previously unallocated)
2041 bits remain within that selected 64 bit field. (As it turns out, for
2042 the example above, the compiler finds that it is OK to allocate the
2043 "containing object" 64-bit field at bit-offset zero within the
2044 structure type.)
2046 Here we attempt to work backwards from the limited set of facts we're
2047 given, and we try to deduce from those facts, where GCC must have
2048 believed that the containing object started (within the structure type).
2050 The value we deduce is then used (by the callers of this routine) to
2051 generate AT_location and AT_bit_offset attributes for fields (both
2052 bit-fields and, in the case of AT_location, regular fields as well).
2055 /* Figure out the bit-distance from the start of the structure to the
2056 "deepest" bit of the bit-field. */
2057 deepest_bitpos = bitpos_int + field_size_in_bits;
2059 /* This is the tricky part. Use some fancy footwork to deduce where the
2060 lowest addressed bit of the containing object must be. */
2061 object_offset_in_bits
2062 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2064 /* Compute the offset of the containing object in "alignment units". */
2065 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2067 /* Compute the offset of the containing object in bytes. */
2068 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2070 return object_offset_in_bytes;
2073 /****************************** attributes *********************************/
2075 /* The following routines are responsible for writing out the various types
2076 of Dwarf attributes (and any following data bytes associated with them).
2077 These routines are listed in order based on the numerical codes of their
2078 associated attributes. */
2080 /* Generate an AT_sibling attribute. */
2082 static inline void
2083 sibling_attribute ()
2085 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2087 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2088 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2089 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2092 /* Output the form of location attributes suitable for whole variables and
2093 whole parameters. Note that the location attributes for struct fields
2094 are generated by the routine `data_member_location_attribute' below. */
2096 static void
2097 location_attribute (rtl)
2098 register rtx rtl;
2100 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2101 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2103 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2104 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2105 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2106 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2107 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2109 /* Handle a special case. If we are about to output a location descriptor
2110 for a variable or parameter which has been optimized out of existence,
2111 don't do that. Instead we output a zero-length location descriptor
2112 value as part of the location attribute.
2114 A variable which has been optimized out of existence will have a
2115 DECL_RTL value which denotes a pseudo-reg.
2117 Currently, in some rare cases, variables can have DECL_RTL values
2118 which look like (MEM (REG pseudo-reg#)). These cases are due to
2119 bugs elsewhere in the compiler. We treat such cases
2120 as if the variable(s) in question had been optimized out of existence.
2122 Note that in all cases where we wish to express the fact that a
2123 variable has been optimized out of existence, we do not simply
2124 suppress the generation of the entire location attribute because
2125 the absence of a location attribute in certain kinds of DIEs is
2126 used to indicate something else entirely... i.e. that the DIE
2127 represents an object declaration, but not a definition. So saith
2128 the PLSIG.
2131 if (! is_pseudo_reg (rtl)
2132 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2133 output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX, 0));
2135 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2138 /* Output the specialized form of location attribute used for data members
2139 of struct and union types.
2141 In the special case of a FIELD_DECL node which represents a bit-field,
2142 the "offset" part of this special location descriptor must indicate the
2143 distance in bytes from the lowest-addressed byte of the containing
2144 struct or union type to the lowest-addressed byte of the "containing
2145 object" for the bit-field. (See the `field_byte_offset' function above.)
2147 For any given bit-field, the "containing object" is a hypothetical
2148 object (of some integral or enum type) within which the given bit-field
2149 lives. The type of this hypothetical "containing object" is always the
2150 same as the declared type of the individual bit-field itself (for GCC
2151 anyway... the DWARF spec doesn't actually mandate this).
2153 Note that it is the size (in bytes) of the hypothetical "containing
2154 object" which will be given in the AT_byte_size attribute for this
2155 bit-field. (See the `byte_size_attribute' function below.) It is
2156 also used when calculating the value of the AT_bit_offset attribute.
2157 (See the `bit_offset_attribute' function below.) */
2159 static void
2160 data_member_location_attribute (t)
2161 register tree t;
2163 register unsigned object_offset_in_bytes;
2164 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2165 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2167 if (TREE_CODE (t) == TREE_VEC)
2168 object_offset_in_bytes = TREE_INT_CST_LOW (BINFO_OFFSET (t));
2169 else
2170 object_offset_in_bytes = field_byte_offset (t);
2172 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2173 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2174 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2175 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2176 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2177 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2178 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2179 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2180 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2183 /* Output an AT_const_value attribute for a variable or a parameter which
2184 does not have a "location" either in memory or in a register. These
2185 things can arise in GNU C when a constant is passed as an actual
2186 parameter to an inlined function. They can also arise in C++ where
2187 declared constants do not necessarily get memory "homes". */
2189 static void
2190 const_value_attribute (rtl)
2191 register rtx rtl;
2193 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2194 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2196 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2197 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2198 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2199 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2200 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2202 switch (GET_CODE (rtl))
2204 case CONST_INT:
2205 /* Note that a CONST_INT rtx could represent either an integer or
2206 a floating-point constant. A CONST_INT is used whenever the
2207 constant will fit into a single word. In all such cases, the
2208 original mode of the constant value is wiped out, and the
2209 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2210 precise mode information for these constants, we always just
2211 output them using 4 bytes. */
2213 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2214 break;
2216 case CONST_DOUBLE:
2217 /* Note that a CONST_DOUBLE rtx could represent either an integer
2218 or a floating-point constant. A CONST_DOUBLE is used whenever
2219 the constant requires more than one word in order to be adequately
2220 represented. In all such cases, the original mode of the constant
2221 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2222 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2224 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2225 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2226 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2227 break;
2229 case CONST_STRING:
2230 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2231 break;
2233 case SYMBOL_REF:
2234 case LABEL_REF:
2235 case CONST:
2236 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2237 break;
2239 case PLUS:
2240 /* In cases where an inlined instance of an inline function is passed
2241 the address of an `auto' variable (which is local to the caller)
2242 we can get a situation where the DECL_RTL of the artificial
2243 local variable (for the inlining) which acts as a stand-in for
2244 the corresponding formal parameter (of the inline function)
2245 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2246 This is not exactly a compile-time constant expression, but it
2247 isn't the address of the (artificial) local variable either.
2248 Rather, it represents the *value* which the artificial local
2249 variable always has during its lifetime. We currently have no
2250 way to represent such quasi-constant values in Dwarf, so for now
2251 we just punt and generate an AT_const_value attribute with form
2252 FORM_BLOCK4 and a length of zero. */
2253 break;
2255 default:
2256 abort (); /* No other kinds of rtx should be possible here. */
2259 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2262 /* Generate *either* an AT_location attribute or else an AT_const_value
2263 data attribute for a variable or a parameter. We generate the
2264 AT_const_value attribute only in those cases where the given
2265 variable or parameter does not have a true "location" either in
2266 memory or in a register. This can happen (for example) when a
2267 constant is passed as an actual argument in a call to an inline
2268 function. (It's possible that these things can crop up in other
2269 ways also.) Note that one type of constant value which can be
2270 passed into an inlined function is a constant pointer. This can
2271 happen for example if an actual argument in an inlined function
2272 call evaluates to a compile-time constant address. */
2274 static void
2275 location_or_const_value_attribute (decl)
2276 register tree decl;
2278 register rtx rtl;
2280 if (TREE_CODE (decl) == ERROR_MARK)
2281 return;
2283 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2285 /* Should never happen. */
2286 abort ();
2287 return;
2290 /* Here we have to decide where we are going to say the parameter "lives"
2291 (as far as the debugger is concerned). We only have a couple of choices.
2292 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2293 normally indicates where the parameter lives during most of the activa-
2294 tion of the function. If optimization is enabled however, this could
2295 be either NULL or else a pseudo-reg. Both of those cases indicate that
2296 the parameter doesn't really live anywhere (as far as the code generation
2297 parts of GCC are concerned) during most of the function's activation.
2298 That will happen (for example) if the parameter is never referenced
2299 within the function.
2301 We could just generate a location descriptor here for all non-NULL
2302 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2303 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2304 cases where DECL_RTL is NULL or is a pseudo-reg.
2306 Note however that we can only get away with using DECL_INCOMING_RTL as
2307 a backup substitute for DECL_RTL in certain limited cases. In cases
2308 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2309 we can be sure that the parameter was passed using the same type as it
2310 is declared to have within the function, and that its DECL_INCOMING_RTL
2311 points us to a place where a value of that type is passed. In cases
2312 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2313 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2314 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2315 points us to a value of some type which is *different* from the type
2316 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2317 to generate a location attribute in such cases, the debugger would
2318 end up (for example) trying to fetch a `float' from a place which
2319 actually contains the first part of a `double'. That would lead to
2320 really incorrect and confusing output at debug-time, and we don't
2321 want that now do we?
2323 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2324 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2325 couple of cute exceptions however. On little-endian machines we can
2326 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2327 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2328 an integral type which is smaller than TREE_TYPE(decl). These cases
2329 arise when (on a little-endian machine) a non-prototyped function has
2330 a parameter declared to be of type `short' or `char'. In such cases,
2331 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2332 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2333 passed `int' value. If the debugger then uses that address to fetch a
2334 `short' or a `char' (on a little-endian machine) the result will be the
2335 correct data, so we allow for such exceptional cases below.
2337 Note that our goal here is to describe the place where the given formal
2338 parameter lives during most of the function's activation (i.e. between
2339 the end of the prologue and the start of the epilogue). We'll do that
2340 as best as we can. Note however that if the given formal parameter is
2341 modified sometime during the execution of the function, then a stack
2342 backtrace (at debug-time) will show the function as having been called
2343 with the *new* value rather than the value which was originally passed
2344 in. This happens rarely enough that it is not a major problem, but it
2345 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2346 may generate two additional attributes for any given TAG_formal_parameter
2347 DIE which will describe the "passed type" and the "passed location" for
2348 the given formal parameter in addition to the attributes we now generate
2349 to indicate the "declared type" and the "active location" for each
2350 parameter. This additional set of attributes could be used by debuggers
2351 for stack backtraces.
2353 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2354 can be NULL also. This happens (for example) for inlined-instances of
2355 inline function formal parameters which are never referenced. This really
2356 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2357 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2358 these values for inlined instances of inline function parameters, so
2359 when we see such cases, we are just SOL (shit-out-of-luck) for the time
2360 being (until integrate.c gets fixed).
2363 /* Use DECL_RTL as the "location" unless we find something better. */
2364 rtl = DECL_RTL (decl);
2366 if (TREE_CODE (decl) == PARM_DECL)
2367 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2369 /* This decl represents a formal parameter which was optimized out. */
2370 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2371 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2373 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2374 *all* cases where (rtl == NULL_RTX) just below. */
2376 if (declared_type == passed_type)
2377 rtl = DECL_INCOMING_RTL (decl);
2378 else if (! BYTES_BIG_ENDIAN)
2379 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2380 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2381 rtl = DECL_INCOMING_RTL (decl);
2384 if (rtl == NULL_RTX)
2385 return;
2387 switch (GET_CODE (rtl))
2389 case CONST_INT:
2390 case CONST_DOUBLE:
2391 case CONST_STRING:
2392 case SYMBOL_REF:
2393 case LABEL_REF:
2394 case CONST:
2395 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2396 const_value_attribute (rtl);
2397 break;
2399 case MEM:
2400 case REG:
2401 case SUBREG:
2402 location_attribute (rtl);
2403 break;
2405 case CONCAT:
2406 /* ??? CONCAT is used for complex variables, which may have the real
2407 part stored in one place and the imag part stored somewhere else.
2408 DWARF1 has no way to describe a variable that lives in two different
2409 places, so we just describe where the first part lives, and hope that
2410 the second part is stored after it. */
2411 location_attribute (XEXP (rtl, 0));
2412 break;
2414 default:
2415 abort (); /* Should never happen. */
2419 /* Generate an AT_name attribute given some string value to be included as
2420 the value of the attribute. */
2422 static inline void
2423 name_attribute (name_string)
2424 register char *name_string;
2426 if (name_string && *name_string)
2428 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2429 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2433 static inline void
2434 fund_type_attribute (ft_code)
2435 register unsigned ft_code;
2437 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2438 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2441 static void
2442 mod_fund_type_attribute (type, decl_const, decl_volatile)
2443 register tree type;
2444 register int decl_const;
2445 register int decl_volatile;
2447 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2448 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2450 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2451 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2452 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2453 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2454 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2455 write_modifier_bytes (type, decl_const, decl_volatile);
2456 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2457 fundamental_type_code (root_type (type)));
2458 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2461 static inline void
2462 user_def_type_attribute (type)
2463 register tree type;
2465 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2467 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2468 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2469 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2472 static void
2473 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2474 register tree type;
2475 register int decl_const;
2476 register int decl_volatile;
2478 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2479 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2480 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2482 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2483 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2484 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2485 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2486 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2487 write_modifier_bytes (type, decl_const, decl_volatile);
2488 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2489 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2490 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2493 #ifdef USE_ORDERING_ATTRIBUTE
2494 static inline void
2495 ordering_attribute (ordering)
2496 register unsigned ordering;
2498 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2499 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2501 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2503 /* Note that the block of subscript information for an array type also
2504 includes information about the element type of type given array type. */
2506 static void
2507 subscript_data_attribute (type)
2508 register tree type;
2510 register unsigned dimension_number;
2511 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2512 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2514 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2515 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2516 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2517 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2518 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2520 /* The GNU compilers represent multidimensional array types as sequences
2521 of one dimensional array types whose element types are themselves array
2522 types. Here we squish that down, so that each multidimensional array
2523 type gets only one array_type DIE in the Dwarf debugging info. The
2524 draft Dwarf specification say that we are allowed to do this kind
2525 of compression in C (because there is no difference between an
2526 array or arrays and a multidimensional array in C) but for other
2527 source languages (e.g. Ada) we probably shouldn't do this. */
2529 for (dimension_number = 0;
2530 TREE_CODE (type) == ARRAY_TYPE;
2531 type = TREE_TYPE (type), dimension_number++)
2533 register tree domain = TYPE_DOMAIN (type);
2535 /* Arrays come in three flavors. Unspecified bounds, fixed
2536 bounds, and (in GNU C only) variable bounds. Handle all
2537 three forms here. */
2539 if (domain)
2541 /* We have an array type with specified bounds. */
2543 register tree lower = TYPE_MIN_VALUE (domain);
2544 register tree upper = TYPE_MAX_VALUE (domain);
2546 /* Handle only fundamental types as index types for now. */
2548 if (! type_is_fundamental (domain))
2549 abort ();
2551 /* Output the representation format byte for this dimension. */
2553 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2554 FMT_CODE (1,
2555 TREE_CODE (lower) == INTEGER_CST,
2556 TREE_CODE (upper) == INTEGER_CST));
2558 /* Output the index type for this dimension. */
2560 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2561 fundamental_type_code (domain));
2563 /* Output the representation for the lower bound. */
2565 output_bound_representation (lower, dimension_number, 'l');
2567 /* Output the representation for the upper bound. */
2569 output_bound_representation (upper, dimension_number, 'u');
2571 else
2573 /* We have an array type with an unspecified length. For C and
2574 C++ we can assume that this really means that (a) the index
2575 type is an integral type, and (b) the lower bound is zero.
2576 Note that Dwarf defines the representation of an unspecified
2577 (upper) bound as being a zero-length location description. */
2579 /* Output the array-bounds format byte. */
2581 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2583 /* Output the (assumed) index type. */
2585 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2587 /* Output the (assumed) lower bound (constant) value. */
2589 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2591 /* Output the (empty) location description for the upper bound. */
2593 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2597 /* Output the prefix byte that says that the element type is coming up. */
2599 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2601 /* Output a representation of the type of the elements of this array type. */
2603 type_attribute (type, 0, 0);
2605 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2608 static void
2609 byte_size_attribute (tree_node)
2610 register tree tree_node;
2612 register unsigned size;
2614 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2615 switch (TREE_CODE (tree_node))
2617 case ERROR_MARK:
2618 size = 0;
2619 break;
2621 case ENUMERAL_TYPE:
2622 case RECORD_TYPE:
2623 case UNION_TYPE:
2624 case QUAL_UNION_TYPE:
2625 size = int_size_in_bytes (tree_node);
2626 break;
2628 case FIELD_DECL:
2629 /* For a data member of a struct or union, the AT_byte_size is
2630 generally given as the number of bytes normally allocated for
2631 an object of the *declared* type of the member itself. This
2632 is true even for bit-fields. */
2633 size = simple_type_size_in_bits (field_type (tree_node))
2634 / BITS_PER_UNIT;
2635 break;
2637 default:
2638 abort ();
2641 /* Note that `size' might be -1 when we get to this point. If it
2642 is, that indicates that the byte size of the entity in question
2643 is variable. We have no good way of expressing this fact in Dwarf
2644 at the present time, so just let the -1 pass on through. */
2646 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2649 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2650 which specifies the distance in bits from the highest order bit of the
2651 "containing object" for the bit-field to the highest order bit of the
2652 bit-field itself.
2654 For any given bit-field, the "containing object" is a hypothetical
2655 object (of some integral or enum type) within which the given bit-field
2656 lives. The type of this hypothetical "containing object" is always the
2657 same as the declared type of the individual bit-field itself.
2659 The determination of the exact location of the "containing object" for
2660 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2661 function (above).
2663 Note that it is the size (in bytes) of the hypothetical "containing
2664 object" which will be given in the AT_byte_size attribute for this
2665 bit-field. (See `byte_size_attribute' above.) */
2667 static inline void
2668 bit_offset_attribute (decl)
2669 register tree decl;
2671 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2672 register tree type = DECL_BIT_FIELD_TYPE (decl);
2673 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2674 register unsigned bitpos_int;
2675 register unsigned highest_order_object_bit_offset;
2676 register unsigned highest_order_field_bit_offset;
2677 register unsigned bit_offset;
2679 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2680 assert (type); /* Must be a bit field. */
2682 /* We can't yet handle bit-fields whose offsets are variable, so if we
2683 encounter such things, just return without generating any attribute
2684 whatsoever. */
2686 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2687 return;
2688 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2690 /* Note that the bit offset is always the distance (in bits) from the
2691 highest-order bit of the "containing object" to the highest-order
2692 bit of the bit-field itself. Since the "high-order end" of any
2693 object or field is different on big-endian and little-endian machines,
2694 the computation below must take account of these differences. */
2696 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2697 highest_order_field_bit_offset = bitpos_int;
2699 if (! BYTES_BIG_ENDIAN)
2701 highest_order_field_bit_offset
2702 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2704 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2707 bit_offset =
2708 (! BYTES_BIG_ENDIAN
2709 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2710 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2712 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2713 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2716 /* For a FIELD_DECL node which represents a bit field, output an attribute
2717 which specifies the length in bits of the given field. */
2719 static inline void
2720 bit_size_attribute (decl)
2721 register tree decl;
2723 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2724 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
2726 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2727 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2728 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2731 /* The following routine outputs the `element_list' attribute for enumeration
2732 type DIEs. The element_lits attribute includes the names and values of
2733 all of the enumeration constants associated with the given enumeration
2734 type. */
2736 static inline void
2737 element_list_attribute (element)
2738 register tree element;
2740 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2741 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2743 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2744 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2745 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2746 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2747 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2749 /* Here we output a list of value/name pairs for each enumeration constant
2750 defined for this enumeration type (as required), but we do it in REVERSE
2751 order. The order is the one required by the draft #5 Dwarf specification
2752 published by the UI/PLSIG. */
2754 output_enumeral_list (element); /* Recursively output the whole list. */
2756 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2759 /* Generate an AT_stmt_list attribute. These are normally present only in
2760 DIEs with a TAG_compile_unit tag. */
2762 static inline void
2763 stmt_list_attribute (label)
2764 register char *label;
2766 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2767 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2768 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2771 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2772 for a subroutine DIE. */
2774 static inline void
2775 low_pc_attribute (asm_low_label)
2776 register char *asm_low_label;
2778 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2779 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2782 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2783 subroutine DIE. */
2785 static inline void
2786 high_pc_attribute (asm_high_label)
2787 register char *asm_high_label;
2789 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2790 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2793 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2795 static inline void
2796 body_begin_attribute (asm_begin_label)
2797 register char *asm_begin_label;
2799 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2800 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2803 /* Generate an AT_body_end attribute for a subroutine DIE. */
2805 static inline void
2806 body_end_attribute (asm_end_label)
2807 register char *asm_end_label;
2809 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2810 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2813 /* Generate an AT_language attribute given a LANG value. These attributes
2814 are used only within TAG_compile_unit DIEs. */
2816 static inline void
2817 language_attribute (language_code)
2818 register unsigned language_code;
2820 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2821 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2824 static inline void
2825 member_attribute (context)
2826 register tree context;
2828 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2830 /* Generate this attribute only for members in C++. */
2832 if (context != NULL && is_tagged_type (context))
2834 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2835 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2836 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2840 static inline void
2841 string_length_attribute (upper_bound)
2842 register tree upper_bound;
2844 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2845 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2847 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2848 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2849 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2850 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2851 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2852 output_bound_representation (upper_bound, 0, 'u');
2853 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2856 static inline void
2857 comp_dir_attribute (dirname)
2858 register char *dirname;
2860 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2861 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2864 static inline void
2865 sf_names_attribute (sf_names_start_label)
2866 register char *sf_names_start_label;
2868 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2869 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2870 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2873 static inline void
2874 src_info_attribute (src_info_start_label)
2875 register char *src_info_start_label;
2877 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2878 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2879 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2882 static inline void
2883 mac_info_attribute (mac_info_start_label)
2884 register char *mac_info_start_label;
2886 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2887 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2888 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2891 static inline void
2892 prototyped_attribute (func_type)
2893 register tree func_type;
2895 if ((strcmp (language_string, "GNU C") == 0)
2896 && (TYPE_ARG_TYPES (func_type) != NULL))
2898 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2899 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2903 static inline void
2904 producer_attribute (producer)
2905 register char *producer;
2907 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2908 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2911 static inline void
2912 inline_attribute (decl)
2913 register tree decl;
2915 if (DECL_INLINE (decl))
2917 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2918 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2922 static inline void
2923 containing_type_attribute (containing_type)
2924 register tree containing_type;
2926 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2928 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2929 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2930 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2933 static inline void
2934 abstract_origin_attribute (origin)
2935 register tree origin;
2937 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2939 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2940 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2942 case 'd':
2943 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2944 break;
2946 case 't':
2947 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2948 break;
2950 default:
2951 abort (); /* Should never happen. */
2954 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2957 #ifdef DWARF_DECL_COORDINATES
2958 static inline void
2959 src_coords_attribute (src_fileno, src_lineno)
2960 register unsigned src_fileno;
2961 register unsigned src_lineno;
2963 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2964 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2965 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2967 #endif /* defined(DWARF_DECL_COORDINATES) */
2969 static inline void
2970 pure_or_virtual_attribute (func_decl)
2971 register tree func_decl;
2973 if (DECL_VIRTUAL_P (func_decl))
2975 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
2976 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2977 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2978 else
2979 #endif
2980 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2981 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2985 /************************* end of attributes *****************************/
2987 /********************* utility routines for DIEs *************************/
2989 /* Output an AT_name attribute and an AT_src_coords attribute for the
2990 given decl, but only if it actually has a name. */
2992 static void
2993 name_and_src_coords_attributes (decl)
2994 register tree decl;
2996 register tree decl_name = DECL_NAME (decl);
2998 if (decl_name && IDENTIFIER_POINTER (decl_name))
3000 name_attribute (IDENTIFIER_POINTER (decl_name));
3001 #ifdef DWARF_DECL_COORDINATES
3003 register unsigned file_index;
3005 /* This is annoying, but we have to pop out of the .debug section
3006 for a moment while we call `lookup_filename' because calling it
3007 may cause a temporary switch into the .debug_sfnames section and
3008 most svr4 assemblers are not smart enough be be able to nest
3009 section switches to any depth greater than one. Note that we
3010 also can't skirt this issue by delaying all output to the
3011 .debug_sfnames section unit the end of compilation because that
3012 would cause us to have inter-section forward references and
3013 Fred Fish sez that m68k/svr4 assemblers botch those. */
3015 ASM_OUTPUT_POP_SECTION (asm_out_file);
3016 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3017 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3019 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3021 #endif /* defined(DWARF_DECL_COORDINATES) */
3025 /* Many forms of DIEs contain a "type description" part. The following
3026 routine writes out these "type descriptor" parts. */
3028 static void
3029 type_attribute (type, decl_const, decl_volatile)
3030 register tree type;
3031 register int decl_const;
3032 register int decl_volatile;
3034 register enum tree_code code = TREE_CODE (type);
3035 register int root_type_modified;
3037 if (code == ERROR_MARK)
3038 return;
3040 /* Handle a special case. For functions whose return type is void,
3041 we generate *no* type attribute. (Note that no object may have
3042 type `void', so this only applies to function return types. */
3044 if (code == VOID_TYPE)
3045 return;
3047 /* If this is a subtype, find the underlying type. Eventually,
3048 this should write out the appropriate subtype info. */
3049 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3050 && TREE_TYPE (type) != 0)
3051 type = TREE_TYPE (type), code = TREE_CODE (type);
3053 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3054 || decl_const || decl_volatile
3055 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3057 if (type_is_fundamental (root_type (type)))
3058 if (root_type_modified)
3059 mod_fund_type_attribute (type, decl_const, decl_volatile);
3060 else
3061 fund_type_attribute (fundamental_type_code (type));
3062 else
3063 if (root_type_modified)
3064 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3065 else
3066 /* We have to get the type_main_variant here (and pass that to the
3067 `user_def_type_attribute' routine) because the ..._TYPE node we
3068 have might simply be a *copy* of some original type node (where
3069 the copy was created to help us keep track of typedef names)
3070 and that copy might have a different TYPE_UID from the original
3071 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3072 is labeling a given type DIE for future reference, it always and
3073 only creates labels for DIEs representing *main variants*, and it
3074 never even knows about non-main-variants.) */
3075 user_def_type_attribute (type_main_variant (type));
3078 /* Given a tree pointer to a struct, class, union, or enum type node, return
3079 a pointer to the (string) tag name for the given type, or zero if the
3080 type was declared without a tag. */
3082 static char *
3083 type_tag (type)
3084 register tree type;
3086 register char *name = 0;
3088 if (TYPE_NAME (type) != 0)
3090 register tree t = 0;
3092 /* Find the IDENTIFIER_NODE for the type name. */
3093 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3094 t = TYPE_NAME (type);
3096 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3097 a TYPE_DECL node, regardless of whether or not a `typedef' was
3098 involved. */
3099 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3100 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3101 t = DECL_NAME (TYPE_NAME (type));
3103 /* Now get the name as a string, or invent one. */
3104 if (t != 0)
3105 name = IDENTIFIER_POINTER (t);
3108 return (name == 0 || *name == '\0') ? 0 : name;
3111 static inline void
3112 dienum_push ()
3114 /* Start by checking if the pending_sibling_stack needs to be expanded.
3115 If necessary, expand it. */
3117 if (pending_siblings == pending_siblings_allocated)
3119 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3120 pending_sibling_stack
3121 = (unsigned *) xrealloc (pending_sibling_stack,
3122 pending_siblings_allocated * sizeof(unsigned));
3125 pending_siblings++;
3126 NEXT_DIE_NUM = next_unused_dienum++;
3129 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3130 NEXT_DIE_NUM. */
3132 static inline void
3133 dienum_pop ()
3135 pending_siblings--;
3138 static inline tree
3139 member_declared_type (member)
3140 register tree member;
3142 return (DECL_BIT_FIELD_TYPE (member))
3143 ? DECL_BIT_FIELD_TYPE (member)
3144 : TREE_TYPE (member);
3147 /* Get the function's label, as described by its RTL.
3148 This may be different from the DECL_NAME name used
3149 in the source file. */
3151 static char *
3152 function_start_label (decl)
3153 register tree decl;
3155 rtx x;
3156 char *fnname;
3158 x = DECL_RTL (decl);
3159 if (GET_CODE (x) != MEM)
3160 abort ();
3161 x = XEXP (x, 0);
3162 if (GET_CODE (x) != SYMBOL_REF)
3163 abort ();
3164 fnname = XSTR (x, 0);
3165 return fnname;
3169 /******************************* DIEs ************************************/
3171 /* Output routines for individual types of DIEs. */
3173 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3175 static void
3176 output_array_type_die (arg)
3177 register void *arg;
3179 register tree type = arg;
3181 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3182 sibling_attribute ();
3183 equate_type_number_to_die_number (type);
3184 member_attribute (TYPE_CONTEXT (type));
3186 /* I believe that we can default the array ordering. SDB will probably
3187 do the right things even if AT_ordering is not present. It's not
3188 even an issue until we start to get into multidimensional arrays
3189 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3190 dimensional arrays, then we'll have to put the AT_ordering attribute
3191 back in. (But if and when we find out that we need to put these in,
3192 we will only do so for multidimensional arrays. After all, we don't
3193 want to waste space in the .debug section now do we?) */
3195 #ifdef USE_ORDERING_ATTRIBUTE
3196 ordering_attribute (ORD_row_major);
3197 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3199 subscript_data_attribute (type);
3202 static void
3203 output_set_type_die (arg)
3204 register void *arg;
3206 register tree type = arg;
3208 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3209 sibling_attribute ();
3210 equate_type_number_to_die_number (type);
3211 member_attribute (TYPE_CONTEXT (type));
3212 type_attribute (TREE_TYPE (type), 0, 0);
3215 #if 0
3216 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3218 static void
3219 output_entry_point_die (arg)
3220 register void *arg;
3222 register tree decl = arg;
3223 register tree origin = decl_ultimate_origin (decl);
3225 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3226 sibling_attribute ();
3227 dienum_push ();
3228 if (origin != NULL)
3229 abstract_origin_attribute (origin);
3230 else
3232 name_and_src_coords_attributes (decl);
3233 member_attribute (DECL_CONTEXT (decl));
3234 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3236 if (DECL_ABSTRACT (decl))
3237 equate_decl_number_to_die_number (decl);
3238 else
3239 low_pc_attribute (function_start_label (decl));
3241 #endif
3243 /* Output a DIE to represent an inlined instance of an enumeration type. */
3245 static void
3246 output_inlined_enumeration_type_die (arg)
3247 register void *arg;
3249 register tree type = arg;
3251 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3252 sibling_attribute ();
3253 assert (TREE_ASM_WRITTEN (type));
3254 abstract_origin_attribute (type);
3257 /* Output a DIE to represent an inlined instance of a structure type. */
3259 static void
3260 output_inlined_structure_type_die (arg)
3261 register void *arg;
3263 register tree type = arg;
3265 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3266 sibling_attribute ();
3267 assert (TREE_ASM_WRITTEN (type));
3268 abstract_origin_attribute (type);
3271 /* Output a DIE to represent an inlined instance of a union type. */
3273 static void
3274 output_inlined_union_type_die (arg)
3275 register void *arg;
3277 register tree type = arg;
3279 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3280 sibling_attribute ();
3281 assert (TREE_ASM_WRITTEN (type));
3282 abstract_origin_attribute (type);
3285 /* Output a DIE to represent an enumeration type. Note that these DIEs
3286 include all of the information about the enumeration values also.
3287 This information is encoded into the element_list attribute. */
3289 static void
3290 output_enumeration_type_die (arg)
3291 register void *arg;
3293 register tree type = arg;
3295 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3296 sibling_attribute ();
3297 equate_type_number_to_die_number (type);
3298 name_attribute (type_tag (type));
3299 member_attribute (TYPE_CONTEXT (type));
3301 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3302 given enum type is incomplete, do not generate the AT_byte_size
3303 attribute or the AT_element_list attribute. */
3305 if (TYPE_SIZE (type))
3307 byte_size_attribute (type);
3308 element_list_attribute (TYPE_FIELDS (type));
3312 /* Output a DIE to represent either a real live formal parameter decl or
3313 to represent just the type of some formal parameter position in some
3314 function type.
3316 Note that this routine is a bit unusual because its argument may be
3317 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3318 represents an inlining of some PARM_DECL) or else some sort of a
3319 ..._TYPE node. If it's the former then this function is being called
3320 to output a DIE to represent a formal parameter object (or some inlining
3321 thereof). If it's the latter, then this function is only being called
3322 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3323 formal argument type of some subprogram type. */
3325 static void
3326 output_formal_parameter_die (arg)
3327 register void *arg;
3329 register tree node = arg;
3331 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3332 sibling_attribute ();
3334 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3336 case 'd': /* We were called with some kind of a ..._DECL node. */
3338 register tree origin = decl_ultimate_origin (node);
3340 if (origin != NULL)
3341 abstract_origin_attribute (origin);
3342 else
3344 name_and_src_coords_attributes (node);
3345 type_attribute (TREE_TYPE (node),
3346 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3348 if (DECL_ABSTRACT (node))
3349 equate_decl_number_to_die_number (node);
3350 else
3351 location_or_const_value_attribute (node);
3353 break;
3355 case 't': /* We were called with some kind of a ..._TYPE node. */
3356 type_attribute (node, 0, 0);
3357 break;
3359 default:
3360 abort (); /* Should never happen. */
3364 /* Output a DIE to represent a declared function (either file-scope
3365 or block-local) which has "external linkage" (according to ANSI-C). */
3367 static void
3368 output_global_subroutine_die (arg)
3369 register void *arg;
3371 register tree decl = arg;
3372 register tree origin = decl_ultimate_origin (decl);
3374 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3375 sibling_attribute ();
3376 dienum_push ();
3377 if (origin != NULL)
3378 abstract_origin_attribute (origin);
3379 else
3381 register tree type = TREE_TYPE (decl);
3383 name_and_src_coords_attributes (decl);
3384 inline_attribute (decl);
3385 prototyped_attribute (type);
3386 member_attribute (DECL_CONTEXT (decl));
3387 type_attribute (TREE_TYPE (type), 0, 0);
3388 pure_or_virtual_attribute (decl);
3390 if (DECL_ABSTRACT (decl))
3391 equate_decl_number_to_die_number (decl);
3392 else
3394 if (! DECL_EXTERNAL (decl) && ! in_class
3395 && decl == current_function_decl)
3397 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3399 low_pc_attribute (function_start_label (decl));
3400 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3401 high_pc_attribute (label);
3402 if (use_gnu_debug_info_extensions)
3404 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3405 body_begin_attribute (label);
3406 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3407 body_end_attribute (label);
3413 /* Output a DIE to represent a declared data object (either file-scope
3414 or block-local) which has "external linkage" (according to ANSI-C). */
3416 static void
3417 output_global_variable_die (arg)
3418 register void *arg;
3420 register tree decl = arg;
3421 register tree origin = decl_ultimate_origin (decl);
3423 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3424 sibling_attribute ();
3425 if (origin != NULL)
3426 abstract_origin_attribute (origin);
3427 else
3429 name_and_src_coords_attributes (decl);
3430 member_attribute (DECL_CONTEXT (decl));
3431 type_attribute (TREE_TYPE (decl),
3432 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3434 if (DECL_ABSTRACT (decl))
3435 equate_decl_number_to_die_number (decl);
3436 else
3438 if (! DECL_EXTERNAL (decl) && ! in_class
3439 && current_function_decl == decl_function_context (decl))
3440 location_or_const_value_attribute (decl);
3444 static void
3445 output_label_die (arg)
3446 register void *arg;
3448 register tree decl = arg;
3449 register tree origin = decl_ultimate_origin (decl);
3451 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3452 sibling_attribute ();
3453 if (origin != NULL)
3454 abstract_origin_attribute (origin);
3455 else
3456 name_and_src_coords_attributes (decl);
3457 if (DECL_ABSTRACT (decl))
3458 equate_decl_number_to_die_number (decl);
3459 else
3461 register rtx insn = DECL_RTL (decl);
3463 if (GET_CODE (insn) == CODE_LABEL)
3465 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3467 /* When optimization is enabled (via -O) some parts of the compiler
3468 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3469 represent source-level labels which were explicitly declared by
3470 the user. This really shouldn't be happening though, so catch
3471 it if it ever does happen. */
3473 if (INSN_DELETED_P (insn))
3474 abort (); /* Should never happen. */
3476 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3477 (unsigned) INSN_UID (insn));
3478 low_pc_attribute (label);
3483 static void
3484 output_lexical_block_die (arg)
3485 register void *arg;
3487 register tree stmt = arg;
3489 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3490 sibling_attribute ();
3491 dienum_push ();
3492 if (! BLOCK_ABSTRACT (stmt))
3494 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3495 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3497 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3498 low_pc_attribute (begin_label);
3499 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3500 high_pc_attribute (end_label);
3504 static void
3505 output_inlined_subroutine_die (arg)
3506 register void *arg;
3508 register tree stmt = arg;
3510 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3511 sibling_attribute ();
3512 dienum_push ();
3513 abstract_origin_attribute (block_ultimate_origin (stmt));
3514 if (! BLOCK_ABSTRACT (stmt))
3516 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3517 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3519 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3520 low_pc_attribute (begin_label);
3521 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3522 high_pc_attribute (end_label);
3526 /* Output a DIE to represent a declared data object (either file-scope
3527 or block-local) which has "internal linkage" (according to ANSI-C). */
3529 static void
3530 output_local_variable_die (arg)
3531 register void *arg;
3533 register tree decl = arg;
3534 register tree origin = decl_ultimate_origin (decl);
3536 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3537 sibling_attribute ();
3538 if (origin != NULL)
3539 abstract_origin_attribute (origin);
3540 else
3542 name_and_src_coords_attributes (decl);
3543 member_attribute (DECL_CONTEXT (decl));
3544 type_attribute (TREE_TYPE (decl),
3545 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3547 if (DECL_ABSTRACT (decl))
3548 equate_decl_number_to_die_number (decl);
3549 else
3550 location_or_const_value_attribute (decl);
3553 static void
3554 output_member_die (arg)
3555 register void *arg;
3557 register tree decl = arg;
3559 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3560 sibling_attribute ();
3561 name_and_src_coords_attributes (decl);
3562 member_attribute (DECL_CONTEXT (decl));
3563 type_attribute (member_declared_type (decl),
3564 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3565 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3567 byte_size_attribute (decl);
3568 bit_size_attribute (decl);
3569 bit_offset_attribute (decl);
3571 data_member_location_attribute (decl);
3574 #if 0
3575 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3576 modified types instead.
3578 We keep this code here just in case these types of DIEs may be
3579 needed to represent certain things in other languages (e.g. Pascal)
3580 someday. */
3582 static void
3583 output_pointer_type_die (arg)
3584 register void *arg;
3586 register tree type = arg;
3588 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3589 sibling_attribute ();
3590 equate_type_number_to_die_number (type);
3591 member_attribute (TYPE_CONTEXT (type));
3592 type_attribute (TREE_TYPE (type), 0, 0);
3595 static void
3596 output_reference_type_die (arg)
3597 register void *arg;
3599 register tree type = arg;
3601 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3602 sibling_attribute ();
3603 equate_type_number_to_die_number (type);
3604 member_attribute (TYPE_CONTEXT (type));
3605 type_attribute (TREE_TYPE (type), 0, 0);
3607 #endif
3609 static void
3610 output_ptr_to_mbr_type_die (arg)
3611 register void *arg;
3613 register tree type = arg;
3615 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3616 sibling_attribute ();
3617 equate_type_number_to_die_number (type);
3618 member_attribute (TYPE_CONTEXT (type));
3619 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3620 type_attribute (TREE_TYPE (type), 0, 0);
3623 static void
3624 output_compile_unit_die (arg)
3625 register void *arg;
3627 register char *main_input_filename = arg;
3629 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3630 sibling_attribute ();
3631 dienum_push ();
3632 name_attribute (main_input_filename);
3635 char producer[250];
3637 sprintf (producer, "%s %s", language_string, version_string);
3638 producer_attribute (producer);
3641 if (strcmp (language_string, "GNU C++") == 0)
3642 language_attribute (LANG_C_PLUS_PLUS);
3643 else if (strcmp (language_string, "GNU Ada") == 0)
3644 language_attribute (LANG_ADA83);
3645 else if (strcmp (language_string, "GNU F77") == 0)
3646 language_attribute (LANG_FORTRAN77);
3647 else if (flag_traditional)
3648 language_attribute (LANG_C);
3649 else
3650 language_attribute (LANG_C89);
3651 low_pc_attribute (TEXT_BEGIN_LABEL);
3652 high_pc_attribute (TEXT_END_LABEL);
3653 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3654 stmt_list_attribute (LINE_BEGIN_LABEL);
3655 last_filename = xstrdup (main_input_filename);
3658 char *wd = getpwd ();
3659 if (wd)
3660 comp_dir_attribute (wd);
3663 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3665 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3666 src_info_attribute (SRCINFO_BEGIN_LABEL);
3667 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3668 mac_info_attribute (MACINFO_BEGIN_LABEL);
3672 static void
3673 output_string_type_die (arg)
3674 register void *arg;
3676 register tree type = arg;
3678 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3679 sibling_attribute ();
3680 member_attribute (TYPE_CONTEXT (type));
3682 /* Fudge the string length attribute for now. */
3684 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
3687 static void
3688 output_inheritance_die (arg)
3689 register void *arg;
3691 register tree binfo = arg;
3693 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3694 sibling_attribute ();
3695 type_attribute (BINFO_TYPE (binfo), 0, 0);
3696 data_member_location_attribute (binfo);
3697 if (TREE_VIA_VIRTUAL (binfo))
3699 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3700 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3702 if (TREE_VIA_PUBLIC (binfo))
3704 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3705 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3707 else if (TREE_VIA_PROTECTED (binfo))
3709 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3710 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
3714 static void
3715 output_structure_type_die (arg)
3716 register void *arg;
3718 register tree type = arg;
3720 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3721 sibling_attribute ();
3722 equate_type_number_to_die_number (type);
3723 name_attribute (type_tag (type));
3724 member_attribute (TYPE_CONTEXT (type));
3726 /* If this type has been completed, then give it a byte_size attribute
3727 and prepare to give a list of members. Otherwise, don't do either of
3728 these things. In the latter case, we will not be generating a list
3729 of members (since we don't have any idea what they might be for an
3730 incomplete type). */
3732 if (TYPE_SIZE (type))
3734 dienum_push ();
3735 byte_size_attribute (type);
3739 /* Output a DIE to represent a declared function (either file-scope
3740 or block-local) which has "internal linkage" (according to ANSI-C). */
3742 static void
3743 output_local_subroutine_die (arg)
3744 register void *arg;
3746 register tree decl = arg;
3747 register tree origin = decl_ultimate_origin (decl);
3749 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3750 sibling_attribute ();
3751 dienum_push ();
3752 if (origin != NULL)
3753 abstract_origin_attribute (origin);
3754 else
3756 register tree type = TREE_TYPE (decl);
3758 name_and_src_coords_attributes (decl);
3759 inline_attribute (decl);
3760 prototyped_attribute (type);
3761 member_attribute (DECL_CONTEXT (decl));
3762 type_attribute (TREE_TYPE (type), 0, 0);
3763 pure_or_virtual_attribute (decl);
3765 if (DECL_ABSTRACT (decl))
3766 equate_decl_number_to_die_number (decl);
3767 else
3769 /* Avoid getting screwed up in cases where a function was declared
3770 static but where no definition was ever given for it. */
3772 if (TREE_ASM_WRITTEN (decl))
3774 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3775 low_pc_attribute (function_start_label (decl));
3776 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3777 high_pc_attribute (label);
3778 if (use_gnu_debug_info_extensions)
3780 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3781 body_begin_attribute (label);
3782 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3783 body_end_attribute (label);
3789 static void
3790 output_subroutine_type_die (arg)
3791 register void *arg;
3793 register tree type = arg;
3794 register tree return_type = TREE_TYPE (type);
3796 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3797 sibling_attribute ();
3798 dienum_push ();
3799 equate_type_number_to_die_number (type);
3800 prototyped_attribute (type);
3801 member_attribute (TYPE_CONTEXT (type));
3802 type_attribute (return_type, 0, 0);
3805 static void
3806 output_typedef_die (arg)
3807 register void *arg;
3809 register tree decl = arg;
3810 register tree origin = decl_ultimate_origin (decl);
3812 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3813 sibling_attribute ();
3814 if (origin != NULL)
3815 abstract_origin_attribute (origin);
3816 else
3818 name_and_src_coords_attributes (decl);
3819 member_attribute (DECL_CONTEXT (decl));
3820 type_attribute (TREE_TYPE (decl),
3821 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3823 if (DECL_ABSTRACT (decl))
3824 equate_decl_number_to_die_number (decl);
3827 static void
3828 output_union_type_die (arg)
3829 register void *arg;
3831 register tree type = arg;
3833 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3834 sibling_attribute ();
3835 equate_type_number_to_die_number (type);
3836 name_attribute (type_tag (type));
3837 member_attribute (TYPE_CONTEXT (type));
3839 /* If this type has been completed, then give it a byte_size attribute
3840 and prepare to give a list of members. Otherwise, don't do either of
3841 these things. In the latter case, we will not be generating a list
3842 of members (since we don't have any idea what they might be for an
3843 incomplete type). */
3845 if (TYPE_SIZE (type))
3847 dienum_push ();
3848 byte_size_attribute (type);
3852 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3853 at the end of an (ANSI prototyped) formal parameters list. */
3855 static void
3856 output_unspecified_parameters_die (arg)
3857 register void *arg;
3859 register tree decl_or_type = arg;
3861 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3862 sibling_attribute ();
3864 /* This kludge is here only for the sake of being compatible with what
3865 the USL CI5 C compiler does. The specification of Dwarf Version 1
3866 doesn't say that TAG_unspecified_parameters DIEs should contain any
3867 attributes other than the AT_sibling attribute, but they are certainly
3868 allowed to contain additional attributes, and the CI5 compiler
3869 generates AT_name, AT_fund_type, and AT_location attributes within
3870 TAG_unspecified_parameters DIEs which appear in the child lists for
3871 DIEs representing function definitions, so we do likewise here. */
3873 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3875 name_attribute ("...");
3876 fund_type_attribute (FT_pointer);
3877 /* location_attribute (?); */
3881 static void
3882 output_padded_null_die (arg)
3883 register void *arg;
3885 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3888 /*************************** end of DIEs *********************************/
3890 /* Generate some type of DIE. This routine generates the generic outer
3891 wrapper stuff which goes around all types of DIE's (regardless of their
3892 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3893 DIE-length word, followed by the guts of the DIE itself. After the guts
3894 of the DIE, there must always be a terminator label for the DIE. */
3896 static void
3897 output_die (die_specific_output_function, param)
3898 register void (*die_specific_output_function)();
3899 register void *param;
3901 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3902 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3904 current_dienum = NEXT_DIE_NUM;
3905 NEXT_DIE_NUM = next_unused_dienum;
3907 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3908 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3910 /* Write a label which will act as the name for the start of this DIE. */
3912 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3914 /* Write the DIE-length word. */
3916 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3918 /* Fill in the guts of the DIE. */
3920 next_unused_dienum++;
3921 die_specific_output_function (param);
3923 /* Write a label which will act as the name for the end of this DIE. */
3925 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3928 static void
3929 end_sibling_chain ()
3931 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3933 current_dienum = NEXT_DIE_NUM;
3934 NEXT_DIE_NUM = next_unused_dienum;
3936 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3938 /* Write a label which will act as the name for the start of this DIE. */
3940 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3942 /* Write the DIE-length word. */
3944 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3946 dienum_pop ();
3949 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3950 TAG_unspecified_parameters DIE) to represent the types of the formal
3951 parameters as specified in some function type specification (except
3952 for those which appear as part of a function *definition*).
3954 Note that we must be careful here to output all of the parameter
3955 DIEs *before* we output any DIEs needed to represent the types of
3956 the formal parameters. This keeps svr4 SDB happy because it
3957 (incorrectly) thinks that the first non-parameter DIE it sees ends
3958 the formal parameter list. */
3960 static void
3961 output_formal_types (function_or_method_type)
3962 register tree function_or_method_type;
3964 register tree link;
3965 register tree formal_type = NULL;
3966 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3968 /* In the case where we are generating a formal types list for a C++
3969 non-static member function type, skip over the first thing on the
3970 TYPE_ARG_TYPES list because it only represents the type of the
3971 hidden `this pointer'. The debugger should be able to figure
3972 out (without being explicitly told) that this non-static member
3973 function type takes a `this pointer' and should be able to figure
3974 what the type of that hidden parameter is from the AT_member
3975 attribute of the parent TAG_subroutine_type DIE. */
3977 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3978 first_parm_type = TREE_CHAIN (first_parm_type);
3980 /* Make our first pass over the list of formal parameter types and output
3981 a TAG_formal_parameter DIE for each one. */
3983 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3985 formal_type = TREE_VALUE (link);
3986 if (formal_type == void_type_node)
3987 break;
3989 /* Output a (nameless) DIE to represent the formal parameter itself. */
3991 output_die (output_formal_parameter_die, formal_type);
3994 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
3995 DIE to the end of the parameter list. */
3997 if (formal_type != void_type_node)
3998 output_die (output_unspecified_parameters_die, function_or_method_type);
4000 /* Make our second (and final) pass over the list of formal parameter types
4001 and output DIEs to represent those types (as necessary). */
4003 for (link = TYPE_ARG_TYPES (function_or_method_type);
4004 link;
4005 link = TREE_CHAIN (link))
4007 formal_type = TREE_VALUE (link);
4008 if (formal_type == void_type_node)
4009 break;
4011 output_type (formal_type, function_or_method_type);
4015 /* Remember a type in the pending_types_list. */
4017 static void
4018 pend_type (type)
4019 register tree type;
4021 if (pending_types == pending_types_allocated)
4023 pending_types_allocated += PENDING_TYPES_INCREMENT;
4024 pending_types_list
4025 = (tree *) xrealloc (pending_types_list,
4026 sizeof (tree) * pending_types_allocated);
4028 pending_types_list[pending_types++] = type;
4030 /* Mark the pending type as having been output already (even though
4031 it hasn't been). This prevents the type from being added to the
4032 pending_types_list more than once. */
4034 TREE_ASM_WRITTEN (type) = 1;
4037 /* Return non-zero if it is legitimate to output DIEs to represent a
4038 given type while we are generating the list of child DIEs for some
4039 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4041 See the comments within the function for a description of when it is
4042 considered legitimate to output DIEs for various kinds of types.
4044 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4045 or it may point to a BLOCK node (for types local to a block), or to a
4046 FUNCTION_DECL node (for types local to the heading of some function
4047 definition), or to a FUNCTION_TYPE node (for types local to the
4048 prototyped parameter list of a function type specification), or to a
4049 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4050 (in the case of C++ nested types).
4052 The `scope' parameter should likewise be NULL or should point to a
4053 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4054 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4056 This function is used only for deciding when to "pend" and when to
4057 "un-pend" types to/from the pending_types_list.
4059 Note that we sometimes make use of this "type pending" feature in a
4060 rather twisted way to temporarily delay the production of DIEs for the
4061 types of formal parameters. (We do this just to make svr4 SDB happy.)
4062 It order to delay the production of DIEs representing types of formal
4063 parameters, callers of this function supply `fake_containing_scope' as
4064 the `scope' parameter to this function. Given that fake_containing_scope
4065 is a tagged type which is *not* the containing scope for *any* other type,
4066 the desired effect is achieved, i.e. output of DIEs representing types
4067 is temporarily suspended, and any type DIEs which would have otherwise
4068 been output are instead placed onto the pending_types_list. Later on,
4069 we force these (temporarily pended) types to be output simply by calling
4070 `output_pending_types_for_scope' with an actual argument equal to the
4071 true scope of the types we temporarily pended. */
4073 static inline int
4074 type_ok_for_scope (type, scope)
4075 register tree type;
4076 register tree scope;
4078 /* Tagged types (i.e. struct, union, and enum types) must always be
4079 output only in the scopes where they actually belong (or else the
4080 scoping of their own tag names and the scoping of their member
4081 names will be incorrect). Non-tagged-types on the other hand can
4082 generally be output anywhere, except that svr4 SDB really doesn't
4083 want to see them nested within struct or union types, so here we
4084 say it is always OK to immediately output any such a (non-tagged)
4085 type, so long as we are not within such a context. Note that the
4086 only kinds of non-tagged types which we will be dealing with here
4087 (for C and C++ anyway) will be array types and function types. */
4089 return is_tagged_type (type)
4090 ? (TYPE_CONTEXT (type) == scope
4091 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4092 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4093 : (scope == NULL_TREE || ! is_tagged_type (scope));
4096 /* Output any pending types (from the pending_types list) which we can output
4097 now (taking into account the scope that we are working on now).
4099 For each type output, remove the given type from the pending_types_list
4100 *before* we try to output it.
4102 Note that we have to process the list in beginning-to-end order,
4103 because the call made here to output_type may cause yet more types
4104 to be added to the end of the list, and we may have to output some
4105 of them too. */
4107 static void
4108 output_pending_types_for_scope (containing_scope)
4109 register tree containing_scope;
4111 register unsigned i;
4113 for (i = 0; i < pending_types; )
4115 register tree type = pending_types_list[i];
4117 if (type_ok_for_scope (type, containing_scope))
4119 register tree *mover;
4120 register tree *limit;
4122 pending_types--;
4123 limit = &pending_types_list[pending_types];
4124 for (mover = &pending_types_list[i]; mover < limit; mover++)
4125 *mover = *(mover+1);
4127 /* Un-mark the type as having been output already (because it
4128 hasn't been, really). Then call output_type to generate a
4129 Dwarf representation of it. */
4131 TREE_ASM_WRITTEN (type) = 0;
4132 output_type (type, containing_scope);
4134 /* Don't increment the loop counter in this case because we
4135 have shifted all of the subsequent pending types down one
4136 element in the pending_types_list array. */
4138 else
4139 i++;
4143 static void
4144 output_type (type, containing_scope)
4145 register tree type;
4146 register tree containing_scope;
4148 if (type == 0 || type == error_mark_node)
4149 return;
4151 /* We are going to output a DIE to represent the unqualified version of
4152 of this type (i.e. without any const or volatile qualifiers) so get
4153 the main variant (i.e. the unqualified version) of this type now. */
4155 type = type_main_variant (type);
4157 if (TREE_ASM_WRITTEN (type))
4158 return;
4160 /* If this is a nested type whose containing class hasn't been
4161 written out yet, writing it out will cover this one, too. */
4163 if (TYPE_CONTEXT (type)
4164 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
4165 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4167 output_type (TYPE_CONTEXT (type), containing_scope);
4168 return;
4171 /* Don't generate any DIEs for this type now unless it is OK to do so
4172 (based upon what `type_ok_for_scope' tells us). */
4174 if (! type_ok_for_scope (type, containing_scope))
4176 pend_type (type);
4177 return;
4180 switch (TREE_CODE (type))
4182 case ERROR_MARK:
4183 break;
4185 case POINTER_TYPE:
4186 case REFERENCE_TYPE:
4187 /* Prevent infinite recursion in cases where this is a recursive
4188 type. Recursive types are possible in Ada. */
4189 TREE_ASM_WRITTEN (type) = 1;
4190 /* For these types, all that is required is that we output a DIE
4191 (or a set of DIEs) to represent the "basis" type. */
4192 output_type (TREE_TYPE (type), containing_scope);
4193 break;
4195 case OFFSET_TYPE:
4196 /* This code is used for C++ pointer-to-data-member types. */
4197 /* Output a description of the relevant class type. */
4198 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4199 /* Output a description of the type of the object pointed to. */
4200 output_type (TREE_TYPE (type), containing_scope);
4201 /* Now output a DIE to represent this pointer-to-data-member type
4202 itself. */
4203 output_die (output_ptr_to_mbr_type_die, type);
4204 break;
4206 case SET_TYPE:
4207 output_type (TYPE_DOMAIN (type), containing_scope);
4208 output_die (output_set_type_die, type);
4209 break;
4211 case FILE_TYPE:
4212 output_type (TREE_TYPE (type), containing_scope);
4213 abort (); /* No way to represent these in Dwarf yet! */
4214 break;
4216 case FUNCTION_TYPE:
4217 /* Force out return type (in case it wasn't forced out already). */
4218 output_type (TREE_TYPE (type), containing_scope);
4219 output_die (output_subroutine_type_die, type);
4220 output_formal_types (type);
4221 end_sibling_chain ();
4222 break;
4224 case METHOD_TYPE:
4225 /* Force out return type (in case it wasn't forced out already). */
4226 output_type (TREE_TYPE (type), containing_scope);
4227 output_die (output_subroutine_type_die, type);
4228 output_formal_types (type);
4229 end_sibling_chain ();
4230 break;
4232 case ARRAY_TYPE:
4233 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4235 output_type (TREE_TYPE (type), containing_scope);
4236 output_die (output_string_type_die, type);
4238 else
4240 register tree element_type;
4242 element_type = TREE_TYPE (type);
4243 while (TREE_CODE (element_type) == ARRAY_TYPE)
4244 element_type = TREE_TYPE (element_type);
4246 output_type (element_type, containing_scope);
4247 output_die (output_array_type_die, type);
4249 break;
4251 case ENUMERAL_TYPE:
4252 case RECORD_TYPE:
4253 case UNION_TYPE:
4254 case QUAL_UNION_TYPE:
4256 /* For a non-file-scope tagged type, we can always go ahead and
4257 output a Dwarf description of this type right now, even if
4258 the type in question is still incomplete, because if this
4259 local type *was* ever completed anywhere within its scope,
4260 that complete definition would already have been attached to
4261 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4262 node by the time we reach this point. That's true because of the
4263 way the front-end does its processing of file-scope declarations (of
4264 functions and class types) within which other types might be
4265 nested. The C and C++ front-ends always gobble up such "local
4266 scope" things en-mass before they try to output *any* debugging
4267 information for any of the stuff contained inside them and thus,
4268 we get the benefit here of what is (in effect) a pre-resolution
4269 of forward references to tagged types in local scopes.
4271 Note however that for file-scope tagged types we cannot assume
4272 that such pre-resolution of forward references has taken place.
4273 A given file-scope tagged type may appear to be incomplete when
4274 we reach this point, but it may yet be given a full definition
4275 (at file-scope) later on during compilation. In order to avoid
4276 generating a premature (and possibly incorrect) set of Dwarf
4277 DIEs for such (as yet incomplete) file-scope tagged types, we
4278 generate nothing at all for as-yet incomplete file-scope tagged
4279 types here unless we are making our special "finalization" pass
4280 for file-scope things at the very end of compilation. At that
4281 time, we will certainly know as much about each file-scope tagged
4282 type as we are ever going to know, so at that point in time, we
4283 can safely generate correct Dwarf descriptions for these file-
4284 scope tagged types. */
4286 if (TYPE_SIZE (type) == 0
4287 && (TYPE_CONTEXT (type) == NULL
4288 || TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
4289 && !finalizing)
4290 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4292 /* Prevent infinite recursion in cases where the type of some
4293 member of this type is expressed in terms of this type itself. */
4295 TREE_ASM_WRITTEN (type) = 1;
4297 /* Output a DIE to represent the tagged type itself. */
4299 switch (TREE_CODE (type))
4301 case ENUMERAL_TYPE:
4302 output_die (output_enumeration_type_die, type);
4303 return; /* a special case -- nothing left to do so just return */
4305 case RECORD_TYPE:
4306 output_die (output_structure_type_die, type);
4307 break;
4309 case UNION_TYPE:
4310 case QUAL_UNION_TYPE:
4311 output_die (output_union_type_die, type);
4312 break;
4314 default:
4315 abort (); /* Should never happen. */
4318 /* If this is not an incomplete type, output descriptions of
4319 each of its members.
4321 Note that as we output the DIEs necessary to represent the
4322 members of this record or union type, we will also be trying
4323 to output DIEs to represent the *types* of those members.
4324 However the `output_type' function (above) will specifically
4325 avoid generating type DIEs for member types *within* the list
4326 of member DIEs for this (containing) type execpt for those
4327 types (of members) which are explicitly marked as also being
4328 members of this (containing) type themselves. The g++ front-
4329 end can force any given type to be treated as a member of some
4330 other (containing) type by setting the TYPE_CONTEXT of the
4331 given (member) type to point to the TREE node representing the
4332 appropriate (containing) type.
4335 if (TYPE_SIZE (type))
4337 /* First output info about the base classes. */
4338 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4340 register tree bases = TYPE_BINFO_BASETYPES (type);
4341 register int n_bases = TREE_VEC_LENGTH (bases);
4342 register int i;
4344 for (i = 0; i < n_bases; i++)
4345 output_die (output_inheritance_die, TREE_VEC_ELT (bases, i));
4348 ++in_class;
4351 register tree normal_member;
4353 /* Now output info about the data members and type members. */
4355 for (normal_member = TYPE_FIELDS (type);
4356 normal_member;
4357 normal_member = TREE_CHAIN (normal_member))
4358 output_decl (normal_member, type);
4362 register tree func_member;
4364 /* Now output info about the function members (if any). */
4366 for (func_member = TYPE_METHODS (type);
4367 func_member;
4368 func_member = TREE_CHAIN (func_member))
4369 output_decl (func_member, type);
4372 --in_class;
4374 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4375 scopes (at least in C++) so we must now output any nested
4376 pending types which are local just to this type. */
4378 output_pending_types_for_scope (type);
4380 end_sibling_chain (); /* Terminate member chain. */
4383 break;
4385 case VOID_TYPE:
4386 case INTEGER_TYPE:
4387 case REAL_TYPE:
4388 case COMPLEX_TYPE:
4389 case BOOLEAN_TYPE:
4390 case CHAR_TYPE:
4391 break; /* No DIEs needed for fundamental types. */
4393 case LANG_TYPE: /* No Dwarf representation currently defined. */
4394 break;
4396 default:
4397 abort ();
4400 TREE_ASM_WRITTEN (type) = 1;
4403 static void
4404 output_tagged_type_instantiation (type)
4405 register tree type;
4407 if (type == 0 || type == error_mark_node)
4408 return;
4410 /* We are going to output a DIE to represent the unqualified version of
4411 of this type (i.e. without any const or volatile qualifiers) so make
4412 sure that we have the main variant (i.e. the unqualified version) of
4413 this type now. */
4415 assert (type == type_main_variant (type));
4417 assert (TREE_ASM_WRITTEN (type));
4419 switch (TREE_CODE (type))
4421 case ERROR_MARK:
4422 break;
4424 case ENUMERAL_TYPE:
4425 output_die (output_inlined_enumeration_type_die, type);
4426 break;
4428 case RECORD_TYPE:
4429 output_die (output_inlined_structure_type_die, type);
4430 break;
4432 case UNION_TYPE:
4433 case QUAL_UNION_TYPE:
4434 output_die (output_inlined_union_type_die, type);
4435 break;
4437 default:
4438 abort (); /* Should never happen. */
4442 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4443 the things which are local to the given block. */
4445 static void
4446 output_block (stmt, depth)
4447 register tree stmt;
4448 int depth;
4450 register int must_output_die = 0;
4451 register tree origin;
4452 register enum tree_code origin_code;
4454 /* Ignore blocks never really used to make RTL. */
4456 if (! stmt || ! TREE_USED (stmt))
4457 return;
4459 /* Determine the "ultimate origin" of this block. This block may be an
4460 inlined instance of an inlined instance of inline function, so we
4461 have to trace all of the way back through the origin chain to find
4462 out what sort of node actually served as the original seed for the
4463 creation of the current block. */
4465 origin = block_ultimate_origin (stmt);
4466 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4468 /* Determine if we need to output any Dwarf DIEs at all to represent this
4469 block. */
4471 if (origin_code == FUNCTION_DECL)
4472 /* The outer scopes for inlinings *must* always be represented. We
4473 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4474 must_output_die = 1;
4475 else
4477 /* In the case where the current block represents an inlining of the
4478 "body block" of an inline function, we must *NOT* output any DIE
4479 for this block because we have already output a DIE to represent
4480 the whole inlined function scope and the "body block" of any
4481 function doesn't really represent a different scope according to
4482 ANSI C rules. So we check here to make sure that this block does
4483 not represent a "body block inlining" before trying to set the
4484 `must_output_die' flag. */
4486 if (! is_body_block (origin ? origin : stmt))
4488 /* Determine if this block directly contains any "significant"
4489 local declarations which we will need to output DIEs for. */
4491 if (debug_info_level > DINFO_LEVEL_TERSE)
4492 /* We are not in terse mode so *any* local declaration counts
4493 as being a "significant" one. */
4494 must_output_die = (BLOCK_VARS (stmt) != NULL);
4495 else
4497 register tree decl;
4499 /* We are in terse mode, so only local (nested) function
4500 definitions count as "significant" local declarations. */
4502 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4503 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4505 must_output_die = 1;
4506 break;
4512 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4513 DIE for any block which contains no significant local declarations
4514 at all. Rather, in such cases we just call `output_decls_for_scope'
4515 so that any needed Dwarf info for any sub-blocks will get properly
4516 generated. Note that in terse mode, our definition of what constitutes
4517 a "significant" local declaration gets restricted to include only
4518 inlined function instances and local (nested) function definitions. */
4520 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4521 /* We don't care about an abstract inlined subroutine. */;
4522 else if (must_output_die)
4524 output_die ((origin_code == FUNCTION_DECL)
4525 ? output_inlined_subroutine_die
4526 : output_lexical_block_die,
4527 stmt);
4528 output_decls_for_scope (stmt, depth);
4529 end_sibling_chain ();
4531 else
4532 output_decls_for_scope (stmt, depth);
4535 /* Output all of the decls declared within a given scope (also called
4536 a `binding contour') and (recursively) all of it's sub-blocks. */
4538 static void
4539 output_decls_for_scope (stmt, depth)
4540 register tree stmt;
4541 int depth;
4543 /* Ignore blocks never really used to make RTL. */
4545 if (! stmt || ! TREE_USED (stmt))
4546 return;
4548 if (! BLOCK_ABSTRACT (stmt) && depth > 0)
4549 next_block_number++;
4551 /* Output the DIEs to represent all of the data objects, functions,
4552 typedefs, and tagged types declared directly within this block
4553 but not within any nested sub-blocks. */
4556 register tree decl;
4558 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4559 output_decl (decl, stmt);
4562 output_pending_types_for_scope (stmt);
4564 /* Output the DIEs to represent all sub-blocks (and the items declared
4565 therein) of this block. */
4568 register tree subblocks;
4570 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4571 subblocks;
4572 subblocks = BLOCK_CHAIN (subblocks))
4573 output_block (subblocks, depth + 1);
4577 /* Is this a typedef we can avoid emitting? */
4579 inline int
4580 is_redundant_typedef (decl)
4581 register tree decl;
4583 if (TYPE_DECL_IS_STUB (decl))
4584 return 1;
4585 if (DECL_ARTIFICIAL (decl)
4586 && DECL_CONTEXT (decl)
4587 && is_tagged_type (DECL_CONTEXT (decl))
4588 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4589 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4590 /* Also ignore the artificial member typedef for the class name. */
4591 return 1;
4592 return 0;
4595 /* Output Dwarf .debug information for a decl described by DECL. */
4597 static void
4598 output_decl (decl, containing_scope)
4599 register tree decl;
4600 register tree containing_scope;
4602 /* Make a note of the decl node we are going to be working on. We may
4603 need to give the user the source coordinates of where it appeared in
4604 case we notice (later on) that something about it looks screwy. */
4606 dwarf_last_decl = decl;
4608 if (TREE_CODE (decl) == ERROR_MARK)
4609 return;
4611 /* If a structure is declared within an initialization, e.g. as the
4612 operand of a sizeof, then it will not have a name. We don't want
4613 to output a DIE for it, as the tree nodes are in the temporary obstack */
4615 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4616 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4617 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4618 || (TYPE_FIELDS (TREE_TYPE (decl))
4619 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4620 return;
4622 /* If this ..._DECL node is marked to be ignored, then ignore it.
4623 But don't ignore a function definition, since that would screw
4624 up our count of blocks, and that it turn will completely screw up the
4625 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4626 attributes (for subsequent blocks). */
4628 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4629 return;
4631 switch (TREE_CODE (decl))
4633 case CONST_DECL:
4634 /* The individual enumerators of an enum type get output when we
4635 output the Dwarf representation of the relevant enum type itself. */
4636 break;
4638 case FUNCTION_DECL:
4639 /* If we are in terse mode, don't output any DIEs to represent
4640 mere function declarations. Also, if we are conforming
4641 to the DWARF version 1 specification, don't output DIEs for
4642 mere function declarations. */
4644 if (DECL_INITIAL (decl) == NULL_TREE)
4645 #if (DWARF_VERSION > 1)
4646 if (debug_info_level <= DINFO_LEVEL_TERSE)
4647 #endif
4648 break;
4650 /* Before we describe the FUNCTION_DECL itself, make sure that we
4651 have described its return type. */
4653 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4656 /* And its containing type. */
4657 register tree origin = decl_class_context (decl);
4658 if (origin)
4659 output_type (origin, containing_scope);
4662 /* If the following DIE will represent a function definition for a
4663 function with "extern" linkage, output a special "pubnames" DIE
4664 label just ahead of the actual DIE. A reference to this label
4665 was already generated in the .debug_pubnames section sub-entry
4666 for this function definition. */
4668 if (TREE_PUBLIC (decl))
4670 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4672 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4673 ASM_OUTPUT_LABEL (asm_out_file, label);
4676 /* Now output a DIE to represent the function itself. */
4678 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4679 ? output_global_subroutine_die
4680 : output_local_subroutine_die,
4681 decl);
4683 /* Now output descriptions of the arguments for this function.
4684 This gets (unnecessarily?) complex because of the fact that
4685 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4686 cases where there was a trailing `...' at the end of the formal
4687 parameter list. In order to find out if there was a trailing
4688 ellipsis or not, we must instead look at the type associated
4689 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4690 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4691 ends with a void_type_node then there should *not* be an ellipsis
4692 at the end. */
4694 /* In the case where we are describing a mere function declaration, all
4695 we need to do here (and all we *can* do here) is to describe
4696 the *types* of its formal parameters. */
4698 if (decl != current_function_decl || in_class)
4699 output_formal_types (TREE_TYPE (decl));
4700 else
4702 /* Generate DIEs to represent all known formal parameters */
4704 register tree arg_decls = DECL_ARGUMENTS (decl);
4705 register tree parm;
4707 /* WARNING! Kludge zone ahead! Here we have a special
4708 hack for svr4 SDB compatibility. Instead of passing the
4709 current FUNCTION_DECL node as the second parameter (i.e.
4710 the `containing_scope' parameter) to `output_decl' (as
4711 we ought to) we instead pass a pointer to our own private
4712 fake_containing_scope node. That node is a RECORD_TYPE
4713 node which NO OTHER TYPE may ever actually be a member of.
4715 This pointer will ultimately get passed into `output_type'
4716 as its `containing_scope' parameter. `Output_type' will
4717 then perform its part in the hack... i.e. it will pend
4718 the type of the formal parameter onto the pending_types
4719 list. Later on, when we are done generating the whole
4720 sequence of formal parameter DIEs for this function
4721 definition, we will un-pend all previously pended types
4722 of formal parameters for this function definition.
4724 This whole kludge prevents any type DIEs from being
4725 mixed in with the formal parameter DIEs. That's good
4726 because svr4 SDB believes that the list of formal
4727 parameter DIEs for a function ends wherever the first
4728 non-formal-parameter DIE appears. Thus, we have to
4729 keep the formal parameter DIEs segregated. They must
4730 all appear (consecutively) at the start of the list of
4731 children for the DIE representing the function definition.
4732 Then (and only then) may we output any additional DIEs
4733 needed to represent the types of these formal parameters.
4737 When generating DIEs, generate the unspecified_parameters
4738 DIE instead if we come across the arg "__builtin_va_alist"
4741 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4742 if (TREE_CODE (parm) == PARM_DECL)
4744 if (DECL_NAME(parm) &&
4745 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4746 "__builtin_va_alist") )
4747 output_die (output_unspecified_parameters_die, decl);
4748 else
4749 output_decl (parm, fake_containing_scope);
4753 Now that we have finished generating all of the DIEs to
4754 represent the formal parameters themselves, force out
4755 any DIEs needed to represent their types. We do this
4756 simply by un-pending all previously pended types which
4757 can legitimately go into the chain of children DIEs for
4758 the current FUNCTION_DECL.
4761 output_pending_types_for_scope (decl);
4764 Decide whether we need a unspecified_parameters DIE at the end.
4765 There are 2 more cases to do this for:
4766 1) the ansi ... declaration - this is detectable when the end
4767 of the arg list is not a void_type_node
4768 2) an unprototyped function declaration (not a definition). This
4769 just means that we have no info about the parameters at all.
4773 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4775 if (fn_arg_types)
4777 /* this is the prototyped case, check for ... */
4778 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4779 output_die (output_unspecified_parameters_die, decl);
4781 else
4783 /* this is unprototyped, check for undefined (just declaration) */
4784 if (!DECL_INITIAL (decl))
4785 output_die (output_unspecified_parameters_die, decl);
4789 /* Output Dwarf info for all of the stuff within the body of the
4790 function (if it has one - it may be just a declaration). */
4793 register tree outer_scope = DECL_INITIAL (decl);
4795 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4797 /* Note that here, `outer_scope' is a pointer to the outermost
4798 BLOCK node created to represent a function.
4799 This outermost BLOCK actually represents the outermost
4800 binding contour for the function, i.e. the contour in which
4801 the function's formal parameters and labels get declared.
4803 Curiously, it appears that the front end doesn't actually
4804 put the PARM_DECL nodes for the current function onto the
4805 BLOCK_VARS list for this outer scope. (They are strung
4806 off of the DECL_ARGUMENTS list for the function instead.)
4807 The BLOCK_VARS list for the `outer_scope' does provide us
4808 with a list of the LABEL_DECL nodes for the function however,
4809 and we output DWARF info for those here.
4811 Just within the `outer_scope' there will be a BLOCK node
4812 representing the function's outermost pair of curly braces,
4813 and any blocks used for the base and member initializers of
4814 a C++ constructor function. */
4816 output_decls_for_scope (outer_scope, 0);
4818 /* Finally, force out any pending types which are local to the
4819 outermost block of this function definition. These will
4820 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4821 node itself. */
4823 output_pending_types_for_scope (decl);
4828 /* Generate a terminator for the list of stuff `owned' by this
4829 function. */
4831 end_sibling_chain ();
4833 break;
4835 case TYPE_DECL:
4836 /* If we are in terse mode, don't generate any DIEs to represent
4837 any actual typedefs. Note that even when we are in terse mode,
4838 we must still output DIEs to represent those tagged types which
4839 are used (directly or indirectly) in the specification of either
4840 a return type or a formal parameter type of some function. */
4842 if (debug_info_level <= DINFO_LEVEL_TERSE)
4843 if (! TYPE_DECL_IS_STUB (decl)
4844 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4845 return;
4847 /* In the special case of a TYPE_DECL node representing
4848 the declaration of some type tag, if the given TYPE_DECL is
4849 marked as having been instantiated from some other (original)
4850 TYPE_DECL node (e.g. one which was generated within the original
4851 definition of an inline function) we have to generate a special
4852 (abbreviated) TAG_structure_type, TAG_union_type, or
4853 TAG_enumeration-type DIE here. */
4855 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4857 output_tagged_type_instantiation (TREE_TYPE (decl));
4858 return;
4861 output_type (TREE_TYPE (decl), containing_scope);
4863 if (! is_redundant_typedef (decl))
4864 /* Output a DIE to represent the typedef itself. */
4865 output_die (output_typedef_die, decl);
4866 break;
4868 case LABEL_DECL:
4869 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4870 output_die (output_label_die, decl);
4871 break;
4873 case VAR_DECL:
4874 /* If we are conforming to the DWARF version 1 specification, don't
4875 generated any DIEs to represent mere external object declarations. */
4877 #if (DWARF_VERSION <= 1)
4878 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4879 break;
4880 #endif
4882 /* If we are in terse mode, don't generate any DIEs to represent
4883 any variable declarations or definitions. */
4885 if (debug_info_level <= DINFO_LEVEL_TERSE)
4886 break;
4888 /* Output any DIEs that are needed to specify the type of this data
4889 object. */
4891 output_type (TREE_TYPE (decl), containing_scope);
4894 /* And its containing type. */
4895 register tree origin = decl_class_context (decl);
4896 if (origin)
4897 output_type (origin, containing_scope);
4900 /* If the following DIE will represent a data object definition for a
4901 data object with "extern" linkage, output a special "pubnames" DIE
4902 label just ahead of the actual DIE. A reference to this label
4903 was already generated in the .debug_pubnames section sub-entry
4904 for this data object definition. */
4906 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4908 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4910 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4911 ASM_OUTPUT_LABEL (asm_out_file, label);
4914 /* Now output the DIE to represent the data object itself. This gets
4915 complicated because of the possibility that the VAR_DECL really
4916 represents an inlined instance of a formal parameter for an inline
4917 function. */
4920 register void (*func) ();
4921 register tree origin = decl_ultimate_origin (decl);
4923 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
4924 func = output_formal_parameter_die;
4925 else
4927 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
4928 func = output_global_variable_die;
4929 else
4930 func = output_local_variable_die;
4932 output_die (func, decl);
4934 break;
4936 case FIELD_DECL:
4937 /* Ignore the nameless fields that are used to skip bits. */
4938 if (DECL_NAME (decl) != 0)
4940 output_type (member_declared_type (decl), containing_scope);
4941 output_die (output_member_die, decl);
4943 break;
4945 case PARM_DECL:
4946 /* Force out the type of this formal, if it was not forced out yet.
4947 Note that here we can run afowl of a bug in "classic" svr4 SDB.
4948 It should be able to grok the presence of type DIEs within a list
4949 of TAG_formal_parameter DIEs, but it doesn't. */
4951 output_type (TREE_TYPE (decl), containing_scope);
4952 output_die (output_formal_parameter_die, decl);
4953 break;
4955 default:
4956 abort ();
4960 void
4961 dwarfout_file_scope_decl (decl, set_finalizing)
4962 register tree decl;
4963 register int set_finalizing;
4965 if (TREE_CODE (decl) == ERROR_MARK)
4966 return;
4968 /* If this ..._DECL node is marked to be ignored, then ignore it. We
4969 gotta hope that the node in question doesn't represent a function
4970 definition. If it does, then totally ignoring it is bound to screw
4971 up our count of blocks, and that it turn will completely screw up the
4972 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4973 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
4974 don't carry their own sequence numbers with them!) */
4976 if (DECL_IGNORED_P (decl))
4978 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4979 abort ();
4980 return;
4983 switch (TREE_CODE (decl))
4985 case FUNCTION_DECL:
4987 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
4988 a builtin function. Explicit programmer-supplied declarations of
4989 these same functions should NOT be ignored however. */
4991 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
4992 return;
4994 /* What we would really like to do here is to filter out all mere
4995 file-scope declarations of file-scope functions which are never
4996 referenced later within this translation unit (and keep all of
4997 ones that *are* referenced later on) but we aren't clairvoyant,
4998 so we have no idea which functions will be referenced in the
4999 future (i.e. later on within the current translation unit).
5000 So here we just ignore all file-scope function declarations
5001 which are not also definitions. If and when the debugger needs
5002 to know something about these functions, it wil have to hunt
5003 around and find the DWARF information associated with the
5004 *definition* of the function.
5006 Note that we can't just check `DECL_EXTERNAL' to find out which
5007 FUNCTION_DECL nodes represent definitions and which ones represent
5008 mere declarations. We have to check `DECL_INITIAL' instead. That's
5009 because the C front-end supports some weird semantics for "extern
5010 inline" function definitions. These can get inlined within the
5011 current translation unit (an thus, we need to generate DWARF info
5012 for their abstract instances so that the DWARF info for the
5013 concrete inlined instances can have something to refer to) but
5014 the compiler never generates any out-of-lines instances of such
5015 things (despite the fact that they *are* definitions). The
5016 important point is that the C front-end marks these "extern inline"
5017 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5018 anyway.
5020 Note that the C++ front-end also plays some similar games for inline
5021 function definitions appearing within include files which also
5022 contain `#pragma interface' pragmas. */
5024 if (DECL_INITIAL (decl) == NULL_TREE)
5025 return;
5027 if (TREE_PUBLIC (decl)
5028 && ! DECL_EXTERNAL (decl)
5029 && ! DECL_ABSTRACT (decl))
5031 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5033 /* Output a .debug_pubnames entry for a public function
5034 defined in this compilation unit. */
5036 fputc ('\n', asm_out_file);
5037 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5038 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5039 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5040 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5041 IDENTIFIER_POINTER (DECL_NAME (decl)));
5042 ASM_OUTPUT_POP_SECTION (asm_out_file);
5045 break;
5047 case VAR_DECL:
5049 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5050 object declaration and if the declaration was never even
5051 referenced from within this entire compilation unit. We
5052 suppress these DIEs in order to save space in the .debug section
5053 (by eliminating entries which are probably useless). Note that
5054 we must not suppress block-local extern declarations (whether
5055 used or not) because that would screw-up the debugger's name
5056 lookup mechanism and cause it to miss things which really ought
5057 to be in scope at a given point. */
5059 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5060 return;
5062 if (TREE_PUBLIC (decl)
5063 && ! DECL_EXTERNAL (decl)
5064 && GET_CODE (DECL_RTL (decl)) == MEM
5065 && ! DECL_ABSTRACT (decl))
5067 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5069 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5071 /* Output a .debug_pubnames entry for a public variable
5072 defined in this compilation unit. */
5074 fputc ('\n', asm_out_file);
5075 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5076 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5077 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5078 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5079 IDENTIFIER_POINTER (DECL_NAME (decl)));
5080 ASM_OUTPUT_POP_SECTION (asm_out_file);
5083 if (DECL_INITIAL (decl) == NULL)
5085 /* Output a .debug_aranges entry for a public variable
5086 which is tentatively defined in this compilation unit. */
5088 fputc ('\n', asm_out_file);
5089 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5090 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5091 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5092 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5093 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5094 ASM_OUTPUT_POP_SECTION (asm_out_file);
5098 /* If we are in terse mode, don't generate any DIEs to represent
5099 any variable declarations or definitions. */
5101 if (debug_info_level <= DINFO_LEVEL_TERSE)
5102 return;
5104 break;
5106 case TYPE_DECL:
5107 /* Don't bother trying to generate any DIEs to represent any of the
5108 normal built-in types for the language we are compiling, except
5109 in cases where the types in question are *not* DWARF fundamental
5110 types. We make an exception in the case of non-fundamental types
5111 for the sake of objective C (and perhaps C++) because the GNU
5112 front-ends for these languages may in fact create certain "built-in"
5113 types which are (for example) RECORD_TYPEs. In such cases, we
5114 really need to output these (non-fundamental) types because other
5115 DIEs may contain references to them. */
5117 if (DECL_SOURCE_LINE (decl) == 0
5118 && type_is_fundamental (TREE_TYPE (decl)))
5119 return;
5121 /* If we are in terse mode, don't generate any DIEs to represent
5122 any actual typedefs. Note that even when we are in terse mode,
5123 we must still output DIEs to represent those tagged types which
5124 are used (directly or indirectly) in the specification of either
5125 a return type or a formal parameter type of some function. */
5127 if (debug_info_level <= DINFO_LEVEL_TERSE)
5128 if (DECL_NAME (decl) != NULL
5129 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5130 return;
5132 break;
5134 default:
5135 return;
5138 fputc ('\n', asm_out_file);
5139 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5140 finalizing = set_finalizing;
5141 output_decl (decl, NULL_TREE);
5143 /* NOTE: The call above to `output_decl' may have caused one or more
5144 file-scope named types (i.e. tagged types) to be placed onto the
5145 pending_types_list. We have to get those types off of that list
5146 at some point, and this is the perfect time to do it. If we didn't
5147 take them off now, they might still be on the list when cc1 finally
5148 exits. That might be OK if it weren't for the fact that when we put
5149 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5150 for these types, and that causes them never to be output unless
5151 `output_pending_types_for_scope' takes them off of the list and un-sets
5152 their TREE_ASM_WRITTEN flags. */
5154 output_pending_types_for_scope (NULL_TREE);
5156 /* The above call should have totally emptied the pending_types_list. */
5158 assert (pending_types == 0);
5160 ASM_OUTPUT_POP_SECTION (asm_out_file);
5162 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5163 current_funcdef_number++;
5166 /* Output a marker (i.e. a label) for the beginning of the generated code
5167 for a lexical block. */
5169 void
5170 dwarfout_begin_block (blocknum)
5171 register unsigned blocknum;
5173 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5175 function_section (current_function_decl);
5176 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5177 ASM_OUTPUT_LABEL (asm_out_file, label);
5180 /* Output a marker (i.e. a label) for the end of the generated code
5181 for a lexical block. */
5183 void
5184 dwarfout_end_block (blocknum)
5185 register unsigned blocknum;
5187 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5189 function_section (current_function_decl);
5190 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5191 ASM_OUTPUT_LABEL (asm_out_file, label);
5194 /* Output a marker (i.e. a label) at a point in the assembly code which
5195 corresponds to a given source level label. */
5197 void
5198 dwarfout_label (insn)
5199 register rtx insn;
5201 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5203 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5205 function_section (current_function_decl);
5206 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5207 (unsigned) INSN_UID (insn));
5208 ASM_OUTPUT_LABEL (asm_out_file, label);
5212 /* Output a marker (i.e. a label) for the point in the generated code where
5213 the real body of the function begins (after parameters have been moved
5214 to their home locations). */
5216 void
5217 dwarfout_begin_function ()
5219 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5221 if (! use_gnu_debug_info_extensions)
5222 return;
5223 function_section (current_function_decl);
5224 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5225 ASM_OUTPUT_LABEL (asm_out_file, label);
5228 /* Output a marker (i.e. a label) for the point in the generated code where
5229 the real body of the function ends (just before the epilogue code). */
5231 void
5232 dwarfout_end_function ()
5234 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5236 if (! use_gnu_debug_info_extensions)
5237 return;
5238 function_section (current_function_decl);
5239 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5240 ASM_OUTPUT_LABEL (asm_out_file, label);
5243 /* Output a marker (i.e. a label) for the absolute end of the generated code
5244 for a function definition. This gets called *after* the epilogue code
5245 has been generated. */
5247 void
5248 dwarfout_end_epilogue ()
5250 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5252 /* Output a label to mark the endpoint of the code generated for this
5253 function. */
5255 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5256 ASM_OUTPUT_LABEL (asm_out_file, label);
5259 static void
5260 shuffle_filename_entry (new_zeroth)
5261 register filename_entry *new_zeroth;
5263 filename_entry temp_entry;
5264 register filename_entry *limit_p;
5265 register filename_entry *move_p;
5267 if (new_zeroth == &filename_table[0])
5268 return;
5270 temp_entry = *new_zeroth;
5272 /* Shift entries up in the table to make room at [0]. */
5274 limit_p = &filename_table[0];
5275 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5276 *move_p = *(move_p-1);
5278 /* Install the found entry at [0]. */
5280 filename_table[0] = temp_entry;
5283 /* Create a new (string) entry for the .debug_sfnames section. */
5285 static void
5286 generate_new_sfname_entry ()
5288 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5290 fputc ('\n', asm_out_file);
5291 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5292 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5293 ASM_OUTPUT_LABEL (asm_out_file, label);
5294 ASM_OUTPUT_DWARF_STRING (asm_out_file,
5295 filename_table[0].name
5296 ? filename_table[0].name
5297 : "");
5298 ASM_OUTPUT_POP_SECTION (asm_out_file);
5301 /* Lookup a filename (in the list of filenames that we know about here in
5302 dwarfout.c) and return its "index". The index of each (known) filename
5303 is just a unique number which is associated with only that one filename.
5304 We need such numbers for the sake of generating labels (in the
5305 .debug_sfnames section) and references to those unique labels (in the
5306 .debug_srcinfo and .debug_macinfo sections).
5308 If the filename given as an argument is not found in our current list,
5309 add it to the list and assign it the next available unique index number.
5311 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5312 one), we shuffle the filename found (or added) up to the zeroth entry of
5313 our list of filenames (which is always searched linearly). We do this so
5314 as to optimize the most common case for these filename lookups within
5315 dwarfout.c. The most common case by far is the case where we call
5316 lookup_filename to lookup the very same filename that we did a lookup
5317 on the last time we called lookup_filename. We make sure that this
5318 common case is fast because such cases will constitute 99.9% of the
5319 lookups we ever do (in practice).
5321 If we add a new filename entry to our table, we go ahead and generate
5322 the corresponding entry in the .debug_sfnames section right away.
5323 Doing so allows us to avoid tickling an assembler bug (present in some
5324 m68k assemblers) which yields assembly-time errors in cases where the
5325 difference of two label addresses is taken and where the two labels
5326 are in a section *other* than the one where the difference is being
5327 calculated, and where at least one of the two symbol references is a
5328 forward reference. (This bug could be tickled by our .debug_srcinfo
5329 entries if we don't output their corresponding .debug_sfnames entries
5330 before them.) */
5332 static unsigned
5333 lookup_filename (file_name)
5334 char *file_name;
5336 register filename_entry *search_p;
5337 register filename_entry *limit_p = &filename_table[ft_entries];
5339 for (search_p = filename_table; search_p < limit_p; search_p++)
5340 if (!strcmp (file_name, search_p->name))
5342 /* When we get here, we have found the filename that we were
5343 looking for in the filename_table. Now we want to make sure
5344 that it gets moved to the zero'th entry in the table (if it
5345 is not already there) so that subsequent attempts to find the
5346 same filename will find it as quickly as possible. */
5348 shuffle_filename_entry (search_p);
5349 return filename_table[0].number;
5352 /* We come here whenever we have a new filename which is not registered
5353 in the current table. Here we add it to the table. */
5355 /* Prepare to add a new table entry by making sure there is enough space
5356 in the table to do so. If not, expand the current table. */
5358 if (ft_entries == ft_entries_allocated)
5360 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5361 filename_table
5362 = (filename_entry *)
5363 xrealloc (filename_table,
5364 ft_entries_allocated * sizeof (filename_entry));
5367 /* Initially, add the new entry at the end of the filename table. */
5369 filename_table[ft_entries].number = ft_entries;
5370 filename_table[ft_entries].name = xstrdup (file_name);
5372 /* Shuffle the new entry into filename_table[0]. */
5374 shuffle_filename_entry (&filename_table[ft_entries]);
5376 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5377 generate_new_sfname_entry ();
5379 ft_entries++;
5380 return filename_table[0].number;
5383 static void
5384 generate_srcinfo_entry (line_entry_num, files_entry_num)
5385 unsigned line_entry_num;
5386 unsigned files_entry_num;
5388 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5390 fputc ('\n', asm_out_file);
5391 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5392 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5393 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5394 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5395 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5396 ASM_OUTPUT_POP_SECTION (asm_out_file);
5399 void
5400 dwarfout_line (filename, line)
5401 register char *filename;
5402 register unsigned line;
5404 if (debug_info_level >= DINFO_LEVEL_NORMAL
5405 /* We can't emit line number info for functions in separate sections,
5406 because the assembler can't subtract labels in different sections. */
5407 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5409 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5410 static unsigned last_line_entry_num = 0;
5411 static unsigned prev_file_entry_num = (unsigned) -1;
5412 register unsigned this_file_entry_num;
5414 function_section (current_function_decl);
5415 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5416 ASM_OUTPUT_LABEL (asm_out_file, label);
5418 fputc ('\n', asm_out_file);
5420 if (use_gnu_debug_info_extensions)
5421 this_file_entry_num = lookup_filename (filename);
5422 else
5423 this_file_entry_num = (unsigned) -1;
5425 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5426 if (this_file_entry_num != prev_file_entry_num)
5428 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5430 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5431 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5435 register char *tail = rindex (filename, '/');
5437 if (tail != NULL)
5438 filename = tail;
5441 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5442 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5443 filename, line);
5444 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5445 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5446 ASM_OUTPUT_POP_SECTION (asm_out_file);
5448 if (this_file_entry_num != prev_file_entry_num)
5449 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5450 prev_file_entry_num = this_file_entry_num;
5454 /* Generate an entry in the .debug_macinfo section. */
5456 static void
5457 generate_macinfo_entry (type_and_offset, string)
5458 register char *type_and_offset;
5459 register char *string;
5461 if (! use_gnu_debug_info_extensions)
5462 return;
5464 fputc ('\n', asm_out_file);
5465 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5466 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5467 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
5468 ASM_OUTPUT_POP_SECTION (asm_out_file);
5471 void
5472 dwarfout_start_new_source_file (filename)
5473 register char *filename;
5475 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5476 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5478 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5479 sprintf (type_and_offset, "0x%08x+%s-%s",
5480 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
5481 generate_macinfo_entry (type_and_offset, "");
5484 void
5485 dwarfout_resume_previous_source_file (lineno)
5486 register unsigned lineno;
5488 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5490 sprintf (type_and_offset, "0x%08x+%u",
5491 ((unsigned) MACINFO_resume << 24), lineno);
5492 generate_macinfo_entry (type_and_offset, "");
5495 /* Called from check_newline in c-parse.y. The `buffer' parameter
5496 contains the tail part of the directive line, i.e. the part which
5497 is past the initial whitespace, #, whitespace, directive-name,
5498 whitespace part. */
5500 void
5501 dwarfout_define (lineno, buffer)
5502 register unsigned lineno;
5503 register char *buffer;
5505 static int initialized = 0;
5506 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5508 if (!initialized)
5510 dwarfout_start_new_source_file (primary_filename);
5511 initialized = 1;
5513 sprintf (type_and_offset, "0x%08x+%u",
5514 ((unsigned) MACINFO_define << 24), lineno);
5515 generate_macinfo_entry (type_and_offset, buffer);
5518 /* Called from check_newline in c-parse.y. The `buffer' parameter
5519 contains the tail part of the directive line, i.e. the part which
5520 is past the initial whitespace, #, whitespace, directive-name,
5521 whitespace part. */
5523 void
5524 dwarfout_undef (lineno, buffer)
5525 register unsigned lineno;
5526 register char *buffer;
5528 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5530 sprintf (type_and_offset, "0x%08x+%u",
5531 ((unsigned) MACINFO_undef << 24), lineno);
5532 generate_macinfo_entry (type_and_offset, buffer);
5535 /* Set up for Dwarf output at the start of compilation. */
5537 void
5538 dwarfout_init (asm_out_file, main_input_filename)
5539 register FILE *asm_out_file;
5540 register char *main_input_filename;
5542 /* Remember the name of the primary input file. */
5544 primary_filename = main_input_filename;
5546 /* Allocate the initial hunk of the pending_sibling_stack. */
5548 pending_sibling_stack
5549 = (unsigned *)
5550 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5551 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5552 pending_siblings = 1;
5554 /* Allocate the initial hunk of the filename_table. */
5556 filename_table
5557 = (filename_entry *)
5558 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5559 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5560 ft_entries = 0;
5562 /* Allocate the initial hunk of the pending_types_list. */
5564 pending_types_list
5565 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5566 pending_types_allocated = PENDING_TYPES_INCREMENT;
5567 pending_types = 0;
5569 /* Create an artificial RECORD_TYPE node which we can use in our hack
5570 to get the DIEs representing types of formal parameters to come out
5571 only *after* the DIEs for the formal parameters themselves. */
5573 fake_containing_scope = make_node (RECORD_TYPE);
5575 /* Output a starting label for the .text section. */
5577 fputc ('\n', asm_out_file);
5578 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5579 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5580 ASM_OUTPUT_POP_SECTION (asm_out_file);
5582 /* Output a starting label for the .data section. */
5584 fputc ('\n', asm_out_file);
5585 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5586 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5587 ASM_OUTPUT_POP_SECTION (asm_out_file);
5589 #if 0 /* GNU C doesn't currently use .data1. */
5590 /* Output a starting label for the .data1 section. */
5592 fputc ('\n', asm_out_file);
5593 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5594 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5595 ASM_OUTPUT_POP_SECTION (asm_out_file);
5596 #endif
5598 /* Output a starting label for the .rodata section. */
5600 fputc ('\n', asm_out_file);
5601 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5602 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5603 ASM_OUTPUT_POP_SECTION (asm_out_file);
5605 #if 0 /* GNU C doesn't currently use .rodata1. */
5606 /* Output a starting label for the .rodata1 section. */
5608 fputc ('\n', asm_out_file);
5609 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5610 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5611 ASM_OUTPUT_POP_SECTION (asm_out_file);
5612 #endif
5614 /* Output a starting label for the .bss section. */
5616 fputc ('\n', asm_out_file);
5617 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5618 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5619 ASM_OUTPUT_POP_SECTION (asm_out_file);
5621 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5623 if (use_gnu_debug_info_extensions)
5625 /* Output a starting label and an initial (compilation directory)
5626 entry for the .debug_sfnames section. The starting label will be
5627 referenced by the initial entry in the .debug_srcinfo section. */
5629 fputc ('\n', asm_out_file);
5630 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5631 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5633 register char *pwd;
5634 register unsigned len;
5635 register char *dirname;
5637 pwd = getpwd ();
5638 if (!pwd)
5639 pfatal_with_name ("getpwd");
5640 len = strlen (pwd);
5641 dirname = (char *) xmalloc (len + 2);
5643 strcpy (dirname, pwd);
5644 strcpy (dirname + len, "/");
5645 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5646 free (dirname);
5648 ASM_OUTPUT_POP_SECTION (asm_out_file);
5651 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5652 && use_gnu_debug_info_extensions)
5654 /* Output a starting label for the .debug_macinfo section. This
5655 label will be referenced by the AT_mac_info attribute in the
5656 TAG_compile_unit DIE. */
5658 fputc ('\n', asm_out_file);
5659 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5660 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5661 ASM_OUTPUT_POP_SECTION (asm_out_file);
5664 /* Generate the initial entry for the .line section. */
5666 fputc ('\n', asm_out_file);
5667 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5668 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5669 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5670 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5671 ASM_OUTPUT_POP_SECTION (asm_out_file);
5673 if (use_gnu_debug_info_extensions)
5675 /* Generate the initial entry for the .debug_srcinfo section. */
5677 fputc ('\n', asm_out_file);
5678 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5679 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5680 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5681 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5682 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5683 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5684 #ifdef DWARF_TIMESTAMPS
5685 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5686 #else
5687 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5688 #endif
5689 ASM_OUTPUT_POP_SECTION (asm_out_file);
5692 /* Generate the initial entry for the .debug_pubnames section. */
5694 fputc ('\n', asm_out_file);
5695 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5696 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5697 ASM_OUTPUT_POP_SECTION (asm_out_file);
5699 /* Generate the initial entry for the .debug_aranges section. */
5701 fputc ('\n', asm_out_file);
5702 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5703 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5704 ASM_OUTPUT_POP_SECTION (asm_out_file);
5707 /* Setup first DIE number == 1. */
5708 NEXT_DIE_NUM = next_unused_dienum++;
5710 /* Generate the initial DIE for the .debug section. Note that the
5711 (string) value given in the AT_name attribute of the TAG_compile_unit
5712 DIE will (typically) be a relative pathname and that this pathname
5713 should be taken as being relative to the directory from which the
5714 compiler was invoked when the given (base) source file was compiled. */
5716 fputc ('\n', asm_out_file);
5717 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5718 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5719 output_die (output_compile_unit_die, main_input_filename);
5720 ASM_OUTPUT_POP_SECTION (asm_out_file);
5722 fputc ('\n', asm_out_file);
5725 /* Output stuff that dwarf requires at the end of every file. */
5727 void
5728 dwarfout_finish ()
5730 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5732 fputc ('\n', asm_out_file);
5733 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5735 /* Mark the end of the chain of siblings which represent all file-scope
5736 declarations in this compilation unit. */
5738 /* The (null) DIE which represents the terminator for the (sibling linked)
5739 list of file-scope items is *special*. Normally, we would just call
5740 end_sibling_chain at this point in order to output a word with the
5741 value `4' and that word would act as the terminator for the list of
5742 DIEs describing file-scope items. Unfortunately, if we were to simply
5743 do that, the label that would follow this DIE in the .debug section
5744 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5745 machines) to a 4 byte boundary.
5747 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5748 the trick used is to insert extra (otherwise useless) padding bytes
5749 into the (null) DIE that we know must precede the ..D2 label in the
5750 .debug section. The amount of padding required can be anywhere between
5751 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5752 with the padding) would normally contain the value 4, but now it will
5753 also have to include the padding bytes, so it will instead have some
5754 value in the range 4..7.
5756 Fortunately, the rules of Dwarf say that any DIE whose length word
5757 contains *any* value less than 8 should be treated as a null DIE, so
5758 this trick works out nicely. Clever, eh? Don't give me any credit
5759 (or blame). I didn't think of this scheme. I just conformed to it.
5762 output_die (output_padded_null_die, (void *) 0);
5763 dienum_pop ();
5765 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5766 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5767 ASM_OUTPUT_POP_SECTION (asm_out_file);
5769 /* Output a terminator label for the .text section. */
5771 fputc ('\n', asm_out_file);
5772 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5773 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5774 ASM_OUTPUT_POP_SECTION (asm_out_file);
5776 /* Output a terminator label for the .data section. */
5778 fputc ('\n', asm_out_file);
5779 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5780 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5781 ASM_OUTPUT_POP_SECTION (asm_out_file);
5783 #if 0 /* GNU C doesn't currently use .data1. */
5784 /* Output a terminator label for the .data1 section. */
5786 fputc ('\n', asm_out_file);
5787 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5788 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5789 ASM_OUTPUT_POP_SECTION (asm_out_file);
5790 #endif
5792 /* Output a terminator label for the .rodata section. */
5794 fputc ('\n', asm_out_file);
5795 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5796 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5797 ASM_OUTPUT_POP_SECTION (asm_out_file);
5799 #if 0 /* GNU C doesn't currently use .rodata1. */
5800 /* Output a terminator label for the .rodata1 section. */
5802 fputc ('\n', asm_out_file);
5803 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5804 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5805 ASM_OUTPUT_POP_SECTION (asm_out_file);
5806 #endif
5808 /* Output a terminator label for the .bss section. */
5810 fputc ('\n', asm_out_file);
5811 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5812 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5813 ASM_OUTPUT_POP_SECTION (asm_out_file);
5815 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5817 /* Output a terminating entry for the .line section. */
5819 fputc ('\n', asm_out_file);
5820 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5821 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5822 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5823 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5824 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5825 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5826 ASM_OUTPUT_POP_SECTION (asm_out_file);
5828 if (use_gnu_debug_info_extensions)
5830 /* Output a terminating entry for the .debug_srcinfo section. */
5832 fputc ('\n', asm_out_file);
5833 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5834 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5835 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5836 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5837 ASM_OUTPUT_POP_SECTION (asm_out_file);
5840 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5842 /* Output terminating entries for the .debug_macinfo section. */
5844 dwarfout_resume_previous_source_file (0);
5846 fputc ('\n', asm_out_file);
5847 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5848 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5849 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5850 ASM_OUTPUT_POP_SECTION (asm_out_file);
5853 /* Generate the terminating entry for the .debug_pubnames section. */
5855 fputc ('\n', asm_out_file);
5856 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5857 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5858 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5859 ASM_OUTPUT_POP_SECTION (asm_out_file);
5861 /* Generate the terminating entries for the .debug_aranges section.
5863 Note that we want to do this only *after* we have output the end
5864 labels (for the various program sections) which we are going to
5865 refer to here. This allows us to work around a bug in the m68k
5866 svr4 assembler. That assembler gives bogus assembly-time errors
5867 if (within any given section) you try to take the difference of
5868 two relocatable symbols, both of which are located within some
5869 other section, and if one (or both?) of the symbols involved is
5870 being forward-referenced. By generating the .debug_aranges
5871 entries at this late point in the assembly output, we skirt the
5872 issue simply by avoiding forward-references.
5875 fputc ('\n', asm_out_file);
5876 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5878 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5879 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5881 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5882 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5884 #if 0 /* GNU C doesn't currently use .data1. */
5885 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5886 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5887 DATA1_BEGIN_LABEL);
5888 #endif
5890 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5891 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5892 RODATA_BEGIN_LABEL);
5894 #if 0 /* GNU C doesn't currently use .rodata1. */
5895 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5896 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5897 RODATA1_BEGIN_LABEL);
5898 #endif
5900 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5901 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5903 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5904 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5906 ASM_OUTPUT_POP_SECTION (asm_out_file);
5910 #endif /* DWARF_DEBUGGING_INFO */