Fix typos in comment
[official-gcc.git] / gcc / dwarfout.c
blobaf1337f4ce83f364ed8ef44aaef3a68ad198030d
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 #include "config.h"
25 #ifdef DWARF_DEBUGGING_INFO
26 #include "system.h"
27 #include "dwarf.h"
28 #include "tree.h"
29 #include "flags.h"
30 #include "rtl.h"
31 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "reload.h"
34 #include "output.h"
35 #include "defaults.h"
36 #include "dwarfout.h"
37 #include "toplev.h"
38 #include "tm_p.h"
40 /* We cannot use <assert.h> in GCC source, since that would include
41 GCC's assert.h, which may not be compatible with the host compiler. */
42 #undef assert
43 #ifdef NDEBUG
44 # define assert(e)
45 #else
46 # define assert(e) do { if (! (e)) abort (); } while (0)
47 #endif
49 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
50 regarding the GNU implementation of Dwarf. */
52 /* NOTE: In the comments in this file, many references are made to
53 so called "Debugging Information Entries". For the sake of brevity,
54 this term is abbreviated to `DIE' throughout the remainder of this
55 file. */
57 /* Note that the implementation of C++ support herein is (as yet) unfinished.
58 If you want to try to complete it, more power to you. */
60 /* How to start an assembler comment. */
61 #ifndef ASM_COMMENT_START
62 #define ASM_COMMENT_START ";#"
63 #endif
65 /* How to print out a register name. */
66 #ifndef PRINT_REG
67 #define PRINT_REG(RTX, CODE, FILE) \
68 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
69 #endif
71 /* Define a macro which returns non-zero for any tagged type which is
72 used (directly or indirectly) in the specification of either some
73 function's return type or some formal parameter of some function.
74 We use this macro when we are operating in "terse" mode to help us
75 know what tagged types have to be represented in Dwarf (even in
76 terse mode) and which ones don't.
78 A flag bit with this meaning really should be a part of the normal
79 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
80 for these nodes. For now, we have to just fake it. It it safe for
81 us to simply return zero for all complete tagged types (which will
82 get forced out anyway if they were used in the specification of some
83 formal or return type) and non-zero for all incomplete tagged types.
86 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
88 /* Define a macro which returns non-zero for a TYPE_DECL which was
89 implicitly generated for a tagged type.
91 Note that unlike the gcc front end (which generates a NULL named
92 TYPE_DECL node for each complete tagged type, each array type, and
93 each function type node created) the g++ front end generates a
94 _named_ TYPE_DECL node for each tagged type node created.
95 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
96 generate a DW_TAG_typedef DIE for them. */
97 #define TYPE_DECL_IS_STUB(decl) \
98 (DECL_NAME (decl) == NULL \
99 || (DECL_ARTIFICIAL (decl) \
100 && is_tagged_type (TREE_TYPE (decl)) \
101 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
103 extern int flag_traditional;
105 /* Maximum size (in bytes) of an artificially generated label. */
107 #define MAX_ARTIFICIAL_LABEL_BYTES 30
109 /* Make sure we know the sizes of the various types dwarf can describe.
110 These are only defaults. If the sizes are different for your target,
111 you should override these values by defining the appropriate symbols
112 in your tm.h file. */
114 #ifndef CHAR_TYPE_SIZE
115 #define CHAR_TYPE_SIZE BITS_PER_UNIT
116 #endif
118 #ifndef SHORT_TYPE_SIZE
119 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
120 #endif
122 #ifndef INT_TYPE_SIZE
123 #define INT_TYPE_SIZE BITS_PER_WORD
124 #endif
126 #ifndef LONG_TYPE_SIZE
127 #define LONG_TYPE_SIZE BITS_PER_WORD
128 #endif
130 #ifndef LONG_LONG_TYPE_SIZE
131 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
132 #endif
134 #ifndef WCHAR_TYPE_SIZE
135 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
136 #endif
138 #ifndef WCHAR_UNSIGNED
139 #define WCHAR_UNSIGNED 0
140 #endif
142 #ifndef FLOAT_TYPE_SIZE
143 #define FLOAT_TYPE_SIZE BITS_PER_WORD
144 #endif
146 #ifndef DOUBLE_TYPE_SIZE
147 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
148 #endif
150 #ifndef LONG_DOUBLE_TYPE_SIZE
151 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
152 #endif
154 /* Structure to keep track of source filenames. */
156 struct filename_entry {
157 unsigned number;
158 const char * name;
161 typedef struct filename_entry filename_entry;
163 /* Pointer to an array of elements, each one having the structure above. */
165 static filename_entry *filename_table;
167 /* Total number of entries in the table (i.e. array) pointed to by
168 `filename_table'. This is the *total* and includes both used and
169 unused slots. */
171 static unsigned ft_entries_allocated;
173 /* Number of entries in the filename_table which are actually in use. */
175 static unsigned ft_entries;
177 /* Size (in elements) of increments by which we may expand the filename
178 table. Actually, a single hunk of space of this size should be enough
179 for most typical programs. */
181 #define FT_ENTRIES_INCREMENT 64
183 /* Local pointer to the name of the main input file. Initialized in
184 dwarfout_init. */
186 static const char *primary_filename;
188 /* Pointer to the most recent filename for which we produced some line info. */
190 static const char *last_filename;
192 /* Counter to generate unique names for DIEs. */
194 static unsigned next_unused_dienum = 1;
196 /* Number of the DIE which is currently being generated. */
198 static unsigned current_dienum;
200 /* Number to use for the special "pubname" label on the next DIE which
201 represents a function or data object defined in this compilation
202 unit which has "extern" linkage. */
204 static int next_pubname_number = 0;
206 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
208 /* Pointer to a dynamically allocated list of pre-reserved and still
209 pending sibling DIE numbers. Note that this list will grow as needed. */
211 static unsigned *pending_sibling_stack;
213 /* Counter to keep track of the number of pre-reserved and still pending
214 sibling DIE numbers. */
216 static unsigned pending_siblings;
218 /* The currently allocated size of the above list (expressed in number of
219 list elements). */
221 static unsigned pending_siblings_allocated;
223 /* Size (in elements) of increments by which we may expand the pending
224 sibling stack. Actually, a single hunk of space of this size should
225 be enough for most typical programs. */
227 #define PENDING_SIBLINGS_INCREMENT 64
229 /* Non-zero if we are performing our file-scope finalization pass and if
230 we should force out Dwarf descriptions of any and all file-scope
231 tagged types which are still incomplete types. */
233 static int finalizing = 0;
235 /* A pointer to the base of a list of pending types which we haven't
236 generated DIEs for yet, but which we will have to come back to
237 later on. */
239 static tree *pending_types_list;
241 /* Number of elements currently allocated for the pending_types_list. */
243 static unsigned pending_types_allocated;
245 /* Number of elements of pending_types_list currently in use. */
247 static unsigned pending_types;
249 /* Size (in elements) of increments by which we may expand the pending
250 types list. Actually, a single hunk of space of this size should
251 be enough for most typical programs. */
253 #define PENDING_TYPES_INCREMENT 64
255 /* A pointer to the base of a list of incomplete types which might be
256 completed at some later time. */
258 static tree *incomplete_types_list;
260 /* Number of elements currently allocated for the incomplete_types_list. */
261 static unsigned incomplete_types_allocated;
263 /* Number of elements of incomplete_types_list currently in use. */
264 static unsigned incomplete_types;
266 /* Size (in elements) of increments by which we may expand the incomplete
267 types list. Actually, a single hunk of space of this size should
268 be enough for most typical programs. */
269 #define INCOMPLETE_TYPES_INCREMENT 64
271 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
272 This is used in a hack to help us get the DIEs describing types of
273 formal parameters to come *after* all of the DIEs describing the formal
274 parameters themselves. That's necessary in order to be compatible
275 with what the brain-damaged svr4 SDB debugger requires. */
277 static tree fake_containing_scope;
279 /* The number of the current function definition that we are generating
280 debugging information for. These numbers range from 1 up to the maximum
281 number of function definitions contained within the current compilation
282 unit. These numbers are used to create unique labels for various things
283 contained within various function definitions. */
285 static unsigned current_funcdef_number = 1;
287 /* A pointer to the ..._DECL node which we have most recently been working
288 on. We keep this around just in case something about it looks screwy
289 and we want to tell the user what the source coordinates for the actual
290 declaration are. */
292 static tree dwarf_last_decl;
294 /* A flag indicating that we are emitting the member declarations of a
295 class, so member functions and variables should not be entirely emitted.
296 This is a kludge to avoid passing a second argument to output_*_die. */
298 static int in_class;
300 /* Forward declarations for functions defined in this file. */
302 static const char *dwarf_tag_name PARAMS ((unsigned));
303 static const char *dwarf_attr_name PARAMS ((unsigned));
304 static const char *dwarf_stack_op_name PARAMS ((unsigned));
305 static const char *dwarf_typemod_name PARAMS ((unsigned));
306 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
307 static const char *dwarf_fund_type_name PARAMS ((unsigned));
308 static tree decl_ultimate_origin PARAMS ((tree));
309 static tree block_ultimate_origin PARAMS ((tree));
310 static tree decl_class_context PARAMS ((tree));
311 #if 0
312 static void output_unsigned_leb128 PARAMS ((unsigned long));
313 static void output_signed_leb128 PARAMS ((long));
314 #endif
315 static int fundamental_type_code PARAMS ((tree));
316 static tree root_type_1 PARAMS ((tree, int));
317 static tree root_type PARAMS ((tree));
318 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
319 static void write_modifier_bytes PARAMS ((tree, int, int));
320 static inline int type_is_fundamental PARAMS ((tree));
321 static void equate_decl_number_to_die_number PARAMS ((tree));
322 static inline void equate_type_number_to_die_number PARAMS ((tree));
323 static void output_reg_number PARAMS ((rtx));
324 static void output_mem_loc_descriptor PARAMS ((rtx));
325 static void output_loc_descriptor PARAMS ((rtx));
326 static void output_bound_representation PARAMS ((tree, unsigned, int));
327 static void output_enumeral_list PARAMS ((tree));
328 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
329 static inline tree field_type PARAMS ((tree));
330 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
331 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
332 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
333 static inline void sibling_attribute PARAMS ((void));
334 static void location_attribute PARAMS ((rtx));
335 static void data_member_location_attribute PARAMS ((tree));
336 static void const_value_attribute PARAMS ((rtx));
337 static void location_or_const_value_attribute PARAMS ((tree));
338 static inline void name_attribute PARAMS ((const char *));
339 static inline void fund_type_attribute PARAMS ((unsigned));
340 static void mod_fund_type_attribute PARAMS ((tree, int, int));
341 static inline void user_def_type_attribute PARAMS ((tree));
342 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
343 #ifdef USE_ORDERING_ATTRIBUTE
344 static inline void ordering_attribute PARAMS ((unsigned));
345 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
346 static void subscript_data_attribute PARAMS ((tree));
347 static void byte_size_attribute PARAMS ((tree));
348 static inline void bit_offset_attribute PARAMS ((tree));
349 static inline void bit_size_attribute PARAMS ((tree));
350 static inline void element_list_attribute PARAMS ((tree));
351 static inline void stmt_list_attribute PARAMS ((const char *));
352 static inline void low_pc_attribute PARAMS ((const char *));
353 static inline void high_pc_attribute PARAMS ((const char *));
354 static inline void body_begin_attribute PARAMS ((const char *));
355 static inline void body_end_attribute PARAMS ((const char *));
356 static inline void language_attribute PARAMS ((unsigned));
357 static inline void member_attribute PARAMS ((tree));
358 #if 0
359 static inline void string_length_attribute PARAMS ((tree));
360 #endif
361 static inline void comp_dir_attribute PARAMS ((const char *));
362 static inline void sf_names_attribute PARAMS ((const char *));
363 static inline void src_info_attribute PARAMS ((const char *));
364 static inline void mac_info_attribute PARAMS ((const char *));
365 static inline void prototyped_attribute PARAMS ((tree));
366 static inline void producer_attribute PARAMS ((const char *));
367 static inline void inline_attribute PARAMS ((tree));
368 static inline void containing_type_attribute PARAMS ((tree));
369 static inline void abstract_origin_attribute PARAMS ((tree));
370 #ifdef DWARF_DECL_COORDINATES
371 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
372 #endif /* defined(DWARF_DECL_COORDINATES) */
373 static inline void pure_or_virtual_attribute PARAMS ((tree));
374 static void name_and_src_coords_attributes PARAMS ((tree));
375 static void type_attribute PARAMS ((tree, int, int));
376 static const char *type_tag PARAMS ((tree));
377 static inline void dienum_push PARAMS ((void));
378 static inline void dienum_pop PARAMS ((void));
379 static inline tree member_declared_type PARAMS ((tree));
380 static const char *function_start_label PARAMS ((tree));
381 static void output_array_type_die PARAMS ((void *));
382 static void output_set_type_die PARAMS ((void *));
383 #if 0
384 static void output_entry_point_die PARAMS ((void *));
385 #endif
386 static void output_inlined_enumeration_type_die PARAMS ((void *));
387 static void output_inlined_structure_type_die PARAMS ((void *));
388 static void output_inlined_union_type_die PARAMS ((void *));
389 static void output_enumeration_type_die PARAMS ((void *));
390 static void output_formal_parameter_die PARAMS ((void *));
391 static void output_global_subroutine_die PARAMS ((void *));
392 static void output_global_variable_die PARAMS ((void *));
393 static void output_label_die PARAMS ((void *));
394 static void output_lexical_block_die PARAMS ((void *));
395 static void output_inlined_subroutine_die PARAMS ((void *));
396 static void output_local_variable_die PARAMS ((void *));
397 static void output_member_die PARAMS ((void *));
398 #if 0
399 static void output_pointer_type_die PARAMS ((void *));
400 static void output_reference_type_die PARAMS ((void *));
401 #endif
402 static void output_ptr_to_mbr_type_die PARAMS ((void *));
403 static void output_compile_unit_die PARAMS ((void *));
404 static void output_string_type_die PARAMS ((void *));
405 static void output_inheritance_die PARAMS ((void *));
406 static void output_structure_type_die PARAMS ((void *));
407 static void output_local_subroutine_die PARAMS ((void *));
408 static void output_subroutine_type_die PARAMS ((void *));
409 static void output_typedef_die PARAMS ((void *));
410 static void output_union_type_die PARAMS ((void *));
411 static void output_unspecified_parameters_die PARAMS ((void *));
412 static void output_padded_null_die PARAMS ((void *));
413 static void output_die PARAMS ((void (*)(void *), void *));
414 static void end_sibling_chain PARAMS ((void));
415 static void output_formal_types PARAMS ((tree));
416 static void pend_type PARAMS ((tree));
417 static int type_ok_for_scope PARAMS ((tree, tree));
418 static void output_pending_types_for_scope PARAMS ((tree));
419 static void output_type PARAMS ((tree, tree));
420 static void output_tagged_type_instantiation PARAMS ((tree));
421 static void output_block PARAMS ((tree, int));
422 static void output_decls_for_scope PARAMS ((tree, int));
423 static void output_decl PARAMS ((tree, tree));
424 static void shuffle_filename_entry PARAMS ((filename_entry *));
425 static void generate_new_sfname_entry PARAMS ((void));
426 static unsigned lookup_filename PARAMS ((const char *));
427 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
428 static void generate_macinfo_entry PARAMS ((const char *, const char *));
429 static int is_pseudo_reg PARAMS ((rtx));
430 static tree type_main_variant PARAMS ((tree));
431 static int is_tagged_type PARAMS ((tree));
432 static int is_redundant_typedef PARAMS ((tree));
433 static void add_incomplete_type PARAMS ((tree));
434 static void retry_incomplete_types PARAMS ((void));
436 /* Definitions of defaults for assembler-dependent names of various
437 pseudo-ops and section names.
439 Theses may be overridden in your tm.h file (if necessary) for your
440 particular assembler. The default values provided here correspond to
441 what is expected by "standard" AT&T System V.4 assemblers. */
443 #ifndef FILE_ASM_OP
444 #define FILE_ASM_OP ".file"
445 #endif
446 #ifndef VERSION_ASM_OP
447 #define VERSION_ASM_OP ".version"
448 #endif
449 #ifndef UNALIGNED_SHORT_ASM_OP
450 #define UNALIGNED_SHORT_ASM_OP ".2byte"
451 #endif
452 #ifndef UNALIGNED_INT_ASM_OP
453 #define UNALIGNED_INT_ASM_OP ".4byte"
454 #endif
455 #ifndef ASM_BYTE_OP
456 #define ASM_BYTE_OP ".byte"
457 #endif
458 #ifndef SET_ASM_OP
459 #define SET_ASM_OP ".set"
460 #endif
462 /* Pseudo-ops for pushing the current section onto the section stack (and
463 simultaneously changing to a new section) and for poping back to the
464 section we were in immediately before this one. Note that most svr4
465 assemblers only maintain a one level stack... you can push all the
466 sections you want, but you can only pop out one level. (The sparc
467 svr4 assembler is an exception to this general rule.) That's
468 OK because we only use at most one level of the section stack herein. */
470 #ifndef PUSHSECTION_ASM_OP
471 #define PUSHSECTION_ASM_OP ".section"
472 #endif
473 #ifndef POPSECTION_ASM_OP
474 #define POPSECTION_ASM_OP ".previous"
475 #endif
477 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
478 to print the PUSHSECTION_ASM_OP and the section name. The default here
479 works for almost all svr4 assemblers, except for the sparc, where the
480 section name must be enclosed in double quotes. (See sparcv4.h.) */
482 #ifndef PUSHSECTION_FORMAT
483 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
484 #endif
486 #ifndef DEBUG_SECTION
487 #define DEBUG_SECTION ".debug"
488 #endif
489 #ifndef LINE_SECTION
490 #define LINE_SECTION ".line"
491 #endif
492 #ifndef SFNAMES_SECTION
493 #define SFNAMES_SECTION ".debug_sfnames"
494 #endif
495 #ifndef SRCINFO_SECTION
496 #define SRCINFO_SECTION ".debug_srcinfo"
497 #endif
498 #ifndef MACINFO_SECTION
499 #define MACINFO_SECTION ".debug_macinfo"
500 #endif
501 #ifndef PUBNAMES_SECTION
502 #define PUBNAMES_SECTION ".debug_pubnames"
503 #endif
504 #ifndef ARANGES_SECTION
505 #define ARANGES_SECTION ".debug_aranges"
506 #endif
507 #ifndef TEXT_SECTION
508 #define TEXT_SECTION ".text"
509 #endif
510 #ifndef DATA_SECTION
511 #define DATA_SECTION ".data"
512 #endif
513 #ifndef DATA1_SECTION
514 #define DATA1_SECTION ".data1"
515 #endif
516 #ifndef RODATA_SECTION
517 #define RODATA_SECTION ".rodata"
518 #endif
519 #ifndef RODATA1_SECTION
520 #define RODATA1_SECTION ".rodata1"
521 #endif
522 #ifndef BSS_SECTION
523 #define BSS_SECTION ".bss"
524 #endif
526 /* Definitions of defaults for formats and names of various special
527 (artificial) labels which may be generated within this file (when
528 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
530 If necessary, these may be overridden from within your tm.h file,
531 but typically, you should never need to override these.
533 These labels have been hacked (temporarily) so that they all begin with
534 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
535 stock m88k/svr4 assembler, both of which need to see .L at the start of
536 a label in order to prevent that label from going into the linker symbol
537 table). When I get time, I'll have to fix this the right way so that we
538 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
539 but that will require a rather massive set of changes. For the moment,
540 the following definitions out to produce the right results for all svr4
541 and svr3 assemblers. -- rfg
544 #ifndef TEXT_BEGIN_LABEL
545 #define TEXT_BEGIN_LABEL "*.L_text_b"
546 #endif
547 #ifndef TEXT_END_LABEL
548 #define TEXT_END_LABEL "*.L_text_e"
549 #endif
551 #ifndef DATA_BEGIN_LABEL
552 #define DATA_BEGIN_LABEL "*.L_data_b"
553 #endif
554 #ifndef DATA_END_LABEL
555 #define DATA_END_LABEL "*.L_data_e"
556 #endif
558 #ifndef DATA1_BEGIN_LABEL
559 #define DATA1_BEGIN_LABEL "*.L_data1_b"
560 #endif
561 #ifndef DATA1_END_LABEL
562 #define DATA1_END_LABEL "*.L_data1_e"
563 #endif
565 #ifndef RODATA_BEGIN_LABEL
566 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
567 #endif
568 #ifndef RODATA_END_LABEL
569 #define RODATA_END_LABEL "*.L_rodata_e"
570 #endif
572 #ifndef RODATA1_BEGIN_LABEL
573 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
574 #endif
575 #ifndef RODATA1_END_LABEL
576 #define RODATA1_END_LABEL "*.L_rodata1_e"
577 #endif
579 #ifndef BSS_BEGIN_LABEL
580 #define BSS_BEGIN_LABEL "*.L_bss_b"
581 #endif
582 #ifndef BSS_END_LABEL
583 #define BSS_END_LABEL "*.L_bss_e"
584 #endif
586 #ifndef LINE_BEGIN_LABEL
587 #define LINE_BEGIN_LABEL "*.L_line_b"
588 #endif
589 #ifndef LINE_LAST_ENTRY_LABEL
590 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
591 #endif
592 #ifndef LINE_END_LABEL
593 #define LINE_END_LABEL "*.L_line_e"
594 #endif
596 #ifndef DEBUG_BEGIN_LABEL
597 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
598 #endif
599 #ifndef SFNAMES_BEGIN_LABEL
600 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
601 #endif
602 #ifndef SRCINFO_BEGIN_LABEL
603 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
604 #endif
605 #ifndef MACINFO_BEGIN_LABEL
606 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
607 #endif
609 #ifndef DIE_BEGIN_LABEL_FMT
610 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
611 #endif
612 #ifndef DIE_END_LABEL_FMT
613 #define DIE_END_LABEL_FMT "*.L_D%u_e"
614 #endif
615 #ifndef PUB_DIE_LABEL_FMT
616 #define PUB_DIE_LABEL_FMT "*.L_P%u"
617 #endif
618 #ifndef INSN_LABEL_FMT
619 #define INSN_LABEL_FMT "*.L_I%u_%u"
620 #endif
621 #ifndef BLOCK_BEGIN_LABEL_FMT
622 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
623 #endif
624 #ifndef BLOCK_END_LABEL_FMT
625 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
626 #endif
627 #ifndef SS_BEGIN_LABEL_FMT
628 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
629 #endif
630 #ifndef SS_END_LABEL_FMT
631 #define SS_END_LABEL_FMT "*.L_s%u_e"
632 #endif
633 #ifndef EE_BEGIN_LABEL_FMT
634 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
635 #endif
636 #ifndef EE_END_LABEL_FMT
637 #define EE_END_LABEL_FMT "*.L_e%u_e"
638 #endif
639 #ifndef MT_BEGIN_LABEL_FMT
640 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
641 #endif
642 #ifndef MT_END_LABEL_FMT
643 #define MT_END_LABEL_FMT "*.L_t%u_e"
644 #endif
645 #ifndef LOC_BEGIN_LABEL_FMT
646 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
647 #endif
648 #ifndef LOC_END_LABEL_FMT
649 #define LOC_END_LABEL_FMT "*.L_l%u_e"
650 #endif
651 #ifndef BOUND_BEGIN_LABEL_FMT
652 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
653 #endif
654 #ifndef BOUND_END_LABEL_FMT
655 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
656 #endif
657 #ifndef DERIV_BEGIN_LABEL_FMT
658 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
659 #endif
660 #ifndef DERIV_END_LABEL_FMT
661 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
662 #endif
663 #ifndef SL_BEGIN_LABEL_FMT
664 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
665 #endif
666 #ifndef SL_END_LABEL_FMT
667 #define SL_END_LABEL_FMT "*.L_sl%u_e"
668 #endif
669 #ifndef BODY_BEGIN_LABEL_FMT
670 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
671 #endif
672 #ifndef BODY_END_LABEL_FMT
673 #define BODY_END_LABEL_FMT "*.L_b%u_e"
674 #endif
675 #ifndef FUNC_END_LABEL_FMT
676 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
677 #endif
678 #ifndef TYPE_NAME_FMT
679 #define TYPE_NAME_FMT "*.L_T%u"
680 #endif
681 #ifndef DECL_NAME_FMT
682 #define DECL_NAME_FMT "*.L_E%u"
683 #endif
684 #ifndef LINE_CODE_LABEL_FMT
685 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
686 #endif
687 #ifndef SFNAMES_ENTRY_LABEL_FMT
688 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
689 #endif
690 #ifndef LINE_ENTRY_LABEL_FMT
691 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
692 #endif
694 /* Definitions of defaults for various types of primitive assembly language
695 output operations.
697 If necessary, these may be overridden from within your tm.h file,
698 but typically, you shouldn't need to override these. */
700 #ifndef ASM_OUTPUT_PUSH_SECTION
701 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
702 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
703 #endif
705 #ifndef ASM_OUTPUT_POP_SECTION
706 #define ASM_OUTPUT_POP_SECTION(FILE) \
707 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
708 #endif
710 #ifndef ASM_OUTPUT_DWARF_DELTA2
711 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
712 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
713 assemble_name (FILE, LABEL1); \
714 fprintf (FILE, "-"); \
715 assemble_name (FILE, LABEL2); \
716 fprintf (FILE, "\n"); \
717 } while (0)
718 #endif
720 #ifndef ASM_OUTPUT_DWARF_DELTA4
721 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
722 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
723 assemble_name (FILE, LABEL1); \
724 fprintf (FILE, "-"); \
725 assemble_name (FILE, LABEL2); \
726 fprintf (FILE, "\n"); \
727 } while (0)
728 #endif
730 #ifndef ASM_OUTPUT_DWARF_TAG
731 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
732 do { \
733 fprintf ((FILE), "\t%s\t0x%x", \
734 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
735 if (flag_debug_asm) \
736 fprintf ((FILE), "\t%s %s", \
737 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
738 fputc ('\n', (FILE)); \
739 } while (0)
740 #endif
742 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
743 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
744 do { \
745 fprintf ((FILE), "\t%s\t0x%x", \
746 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
747 if (flag_debug_asm) \
748 fprintf ((FILE), "\t%s %s", \
749 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
750 fputc ('\n', (FILE)); \
751 } while (0)
752 #endif
754 #ifndef ASM_OUTPUT_DWARF_STACK_OP
755 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
756 do { \
757 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
758 if (flag_debug_asm) \
759 fprintf ((FILE), "\t%s %s", \
760 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
761 fputc ('\n', (FILE)); \
762 } while (0)
763 #endif
765 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
766 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
767 do { \
768 fprintf ((FILE), "\t%s\t0x%x", \
769 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
770 if (flag_debug_asm) \
771 fprintf ((FILE), "\t%s %s", \
772 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
773 fputc ('\n', (FILE)); \
774 } while (0)
775 #endif
777 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
778 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
779 do { \
780 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
781 if (flag_debug_asm) \
782 fprintf ((FILE), "\t%s %s", \
783 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
784 fputc ('\n', (FILE)); \
785 } while (0)
786 #endif
788 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
789 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
790 do { \
791 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
792 if (flag_debug_asm) \
793 fprintf ((FILE), "\t%s %s", \
794 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
795 fputc ('\n', (FILE)); \
796 } while (0)
797 #endif
799 #ifndef ASM_OUTPUT_DWARF_ADDR
800 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
801 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
802 assemble_name (FILE, LABEL); \
803 fprintf (FILE, "\n"); \
804 } while (0)
805 #endif
807 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
808 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
809 do { \
810 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
811 output_addr_const ((FILE), (RTX)); \
812 fputc ('\n', (FILE)); \
813 } while (0)
814 #endif
816 #ifndef ASM_OUTPUT_DWARF_REF
817 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
818 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
819 assemble_name (FILE, LABEL); \
820 fprintf (FILE, "\n"); \
821 } while (0)
822 #endif
824 #ifndef ASM_OUTPUT_DWARF_DATA1
825 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
826 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
827 #endif
829 #ifndef ASM_OUTPUT_DWARF_DATA2
830 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
831 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
832 #endif
834 #ifndef ASM_OUTPUT_DWARF_DATA4
835 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
836 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
837 #endif
839 #ifndef ASM_OUTPUT_DWARF_DATA8
840 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
841 do { \
842 if (WORDS_BIG_ENDIAN) \
844 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
845 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
847 else \
849 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
850 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
852 } while (0)
853 #endif
855 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
856 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
857 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
858 defined, we call it, then issue the line feed. If not, we supply a
859 default defintion of calling ASM_OUTPUT_ASCII */
861 #ifndef ASM_OUTPUT_DWARF_STRING
862 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
863 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
864 #else
865 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
866 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
867 #endif
870 /************************ general utility functions **************************/
872 inline static int
873 is_pseudo_reg (rtl)
874 register rtx rtl;
876 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
877 || ((GET_CODE (rtl) == SUBREG)
878 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
881 inline static tree
882 type_main_variant (type)
883 register tree type;
885 type = TYPE_MAIN_VARIANT (type);
887 /* There really should be only one main variant among any group of variants
888 of a given type (and all of the MAIN_VARIANT values for all members of
889 the group should point to that one type) but sometimes the C front-end
890 messes this up for array types, so we work around that bug here. */
892 if (TREE_CODE (type) == ARRAY_TYPE)
894 while (type != TYPE_MAIN_VARIANT (type))
895 type = TYPE_MAIN_VARIANT (type);
898 return type;
901 /* Return non-zero if the given type node represents a tagged type. */
903 inline static int
904 is_tagged_type (type)
905 register tree type;
907 register enum tree_code code = TREE_CODE (type);
909 return (code == RECORD_TYPE || code == UNION_TYPE
910 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
913 static const char *
914 dwarf_tag_name (tag)
915 register unsigned tag;
917 switch (tag)
919 case TAG_padding: return "TAG_padding";
920 case TAG_array_type: return "TAG_array_type";
921 case TAG_class_type: return "TAG_class_type";
922 case TAG_entry_point: return "TAG_entry_point";
923 case TAG_enumeration_type: return "TAG_enumeration_type";
924 case TAG_formal_parameter: return "TAG_formal_parameter";
925 case TAG_global_subroutine: return "TAG_global_subroutine";
926 case TAG_global_variable: return "TAG_global_variable";
927 case TAG_label: return "TAG_label";
928 case TAG_lexical_block: return "TAG_lexical_block";
929 case TAG_local_variable: return "TAG_local_variable";
930 case TAG_member: return "TAG_member";
931 case TAG_pointer_type: return "TAG_pointer_type";
932 case TAG_reference_type: return "TAG_reference_type";
933 case TAG_compile_unit: return "TAG_compile_unit";
934 case TAG_string_type: return "TAG_string_type";
935 case TAG_structure_type: return "TAG_structure_type";
936 case TAG_subroutine: return "TAG_subroutine";
937 case TAG_subroutine_type: return "TAG_subroutine_type";
938 case TAG_typedef: return "TAG_typedef";
939 case TAG_union_type: return "TAG_union_type";
940 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
941 case TAG_variant: return "TAG_variant";
942 case TAG_common_block: return "TAG_common_block";
943 case TAG_common_inclusion: return "TAG_common_inclusion";
944 case TAG_inheritance: return "TAG_inheritance";
945 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
946 case TAG_module: return "TAG_module";
947 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
948 case TAG_set_type: return "TAG_set_type";
949 case TAG_subrange_type: return "TAG_subrange_type";
950 case TAG_with_stmt: return "TAG_with_stmt";
952 /* GNU extensions. */
954 case TAG_format_label: return "TAG_format_label";
955 case TAG_namelist: return "TAG_namelist";
956 case TAG_function_template: return "TAG_function_template";
957 case TAG_class_template: return "TAG_class_template";
959 default: return "TAG_<unknown>";
963 static const char *
964 dwarf_attr_name (attr)
965 register unsigned attr;
967 switch (attr)
969 case AT_sibling: return "AT_sibling";
970 case AT_location: return "AT_location";
971 case AT_name: return "AT_name";
972 case AT_fund_type: return "AT_fund_type";
973 case AT_mod_fund_type: return "AT_mod_fund_type";
974 case AT_user_def_type: return "AT_user_def_type";
975 case AT_mod_u_d_type: return "AT_mod_u_d_type";
976 case AT_ordering: return "AT_ordering";
977 case AT_subscr_data: return "AT_subscr_data";
978 case AT_byte_size: return "AT_byte_size";
979 case AT_bit_offset: return "AT_bit_offset";
980 case AT_bit_size: return "AT_bit_size";
981 case AT_element_list: return "AT_element_list";
982 case AT_stmt_list: return "AT_stmt_list";
983 case AT_low_pc: return "AT_low_pc";
984 case AT_high_pc: return "AT_high_pc";
985 case AT_language: return "AT_language";
986 case AT_member: return "AT_member";
987 case AT_discr: return "AT_discr";
988 case AT_discr_value: return "AT_discr_value";
989 case AT_string_length: return "AT_string_length";
990 case AT_common_reference: return "AT_common_reference";
991 case AT_comp_dir: return "AT_comp_dir";
992 case AT_const_value_string: return "AT_const_value_string";
993 case AT_const_value_data2: return "AT_const_value_data2";
994 case AT_const_value_data4: return "AT_const_value_data4";
995 case AT_const_value_data8: return "AT_const_value_data8";
996 case AT_const_value_block2: return "AT_const_value_block2";
997 case AT_const_value_block4: return "AT_const_value_block4";
998 case AT_containing_type: return "AT_containing_type";
999 case AT_default_value_addr: return "AT_default_value_addr";
1000 case AT_default_value_data2: return "AT_default_value_data2";
1001 case AT_default_value_data4: return "AT_default_value_data4";
1002 case AT_default_value_data8: return "AT_default_value_data8";
1003 case AT_default_value_string: return "AT_default_value_string";
1004 case AT_friends: return "AT_friends";
1005 case AT_inline: return "AT_inline";
1006 case AT_is_optional: return "AT_is_optional";
1007 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1008 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1009 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1010 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1011 case AT_private: return "AT_private";
1012 case AT_producer: return "AT_producer";
1013 case AT_program: return "AT_program";
1014 case AT_protected: return "AT_protected";
1015 case AT_prototyped: return "AT_prototyped";
1016 case AT_public: return "AT_public";
1017 case AT_pure_virtual: return "AT_pure_virtual";
1018 case AT_return_addr: return "AT_return_addr";
1019 case AT_abstract_origin: return "AT_abstract_origin";
1020 case AT_start_scope: return "AT_start_scope";
1021 case AT_stride_size: return "AT_stride_size";
1022 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1023 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1024 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1025 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1026 case AT_virtual: return "AT_virtual";
1028 /* GNU extensions */
1030 case AT_sf_names: return "AT_sf_names";
1031 case AT_src_info: return "AT_src_info";
1032 case AT_mac_info: return "AT_mac_info";
1033 case AT_src_coords: return "AT_src_coords";
1034 case AT_body_begin: return "AT_body_begin";
1035 case AT_body_end: return "AT_body_end";
1037 default: return "AT_<unknown>";
1041 static const char *
1042 dwarf_stack_op_name (op)
1043 register unsigned op;
1045 switch (op)
1047 case OP_REG: return "OP_REG";
1048 case OP_BASEREG: return "OP_BASEREG";
1049 case OP_ADDR: return "OP_ADDR";
1050 case OP_CONST: return "OP_CONST";
1051 case OP_DEREF2: return "OP_DEREF2";
1052 case OP_DEREF4: return "OP_DEREF4";
1053 case OP_ADD: return "OP_ADD";
1054 default: return "OP_<unknown>";
1058 static const char *
1059 dwarf_typemod_name (mod)
1060 register unsigned mod;
1062 switch (mod)
1064 case MOD_pointer_to: return "MOD_pointer_to";
1065 case MOD_reference_to: return "MOD_reference_to";
1066 case MOD_const: return "MOD_const";
1067 case MOD_volatile: return "MOD_volatile";
1068 default: return "MOD_<unknown>";
1072 static const char *
1073 dwarf_fmt_byte_name (fmt)
1074 register unsigned fmt;
1076 switch (fmt)
1078 case FMT_FT_C_C: return "FMT_FT_C_C";
1079 case FMT_FT_C_X: return "FMT_FT_C_X";
1080 case FMT_FT_X_C: return "FMT_FT_X_C";
1081 case FMT_FT_X_X: return "FMT_FT_X_X";
1082 case FMT_UT_C_C: return "FMT_UT_C_C";
1083 case FMT_UT_C_X: return "FMT_UT_C_X";
1084 case FMT_UT_X_C: return "FMT_UT_X_C";
1085 case FMT_UT_X_X: return "FMT_UT_X_X";
1086 case FMT_ET: return "FMT_ET";
1087 default: return "FMT_<unknown>";
1091 static const char *
1092 dwarf_fund_type_name (ft)
1093 register unsigned ft;
1095 switch (ft)
1097 case FT_char: return "FT_char";
1098 case FT_signed_char: return "FT_signed_char";
1099 case FT_unsigned_char: return "FT_unsigned_char";
1100 case FT_short: return "FT_short";
1101 case FT_signed_short: return "FT_signed_short";
1102 case FT_unsigned_short: return "FT_unsigned_short";
1103 case FT_integer: return "FT_integer";
1104 case FT_signed_integer: return "FT_signed_integer";
1105 case FT_unsigned_integer: return "FT_unsigned_integer";
1106 case FT_long: return "FT_long";
1107 case FT_signed_long: return "FT_signed_long";
1108 case FT_unsigned_long: return "FT_unsigned_long";
1109 case FT_pointer: return "FT_pointer";
1110 case FT_float: return "FT_float";
1111 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1112 case FT_ext_prec_float: return "FT_ext_prec_float";
1113 case FT_complex: return "FT_complex";
1114 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1115 case FT_void: return "FT_void";
1116 case FT_boolean: return "FT_boolean";
1117 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1118 case FT_label: return "FT_label";
1120 /* GNU extensions. */
1122 case FT_long_long: return "FT_long_long";
1123 case FT_signed_long_long: return "FT_signed_long_long";
1124 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1126 case FT_int8: return "FT_int8";
1127 case FT_signed_int8: return "FT_signed_int8";
1128 case FT_unsigned_int8: return "FT_unsigned_int8";
1129 case FT_int16: return "FT_int16";
1130 case FT_signed_int16: return "FT_signed_int16";
1131 case FT_unsigned_int16: return "FT_unsigned_int16";
1132 case FT_int32: return "FT_int32";
1133 case FT_signed_int32: return "FT_signed_int32";
1134 case FT_unsigned_int32: return "FT_unsigned_int32";
1135 case FT_int64: return "FT_int64";
1136 case FT_signed_int64: return "FT_signed_int64";
1137 case FT_unsigned_int64: return "FT_unsigned_int64";
1138 case FT_int128: return "FT_int128";
1139 case FT_signed_int128: return "FT_signed_int128";
1140 case FT_unsigned_int128: return "FT_unsigned_int128";
1142 case FT_real32: return "FT_real32";
1143 case FT_real64: return "FT_real64";
1144 case FT_real96: return "FT_real96";
1145 case FT_real128: return "FT_real128";
1147 default: return "FT_<unknown>";
1151 /* Determine the "ultimate origin" of a decl. The decl may be an
1152 inlined instance of an inlined instance of a decl which is local
1153 to an inline function, so we have to trace all of the way back
1154 through the origin chain to find out what sort of node actually
1155 served as the original seed for the given block. */
1157 static tree
1158 decl_ultimate_origin (decl)
1159 register tree decl;
1161 #ifdef ENABLE_CHECKING
1162 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1163 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1164 most distant ancestor, this should never happen. */
1165 abort ();
1166 #endif
1168 return DECL_ABSTRACT_ORIGIN (decl);
1171 /* Determine the "ultimate origin" of a block. The block may be an
1172 inlined instance of an inlined instance of a block which is local
1173 to an inline function, so we have to trace all of the way back
1174 through the origin chain to find out what sort of node actually
1175 served as the original seed for the given block. */
1177 static tree
1178 block_ultimate_origin (block)
1179 register tree block;
1181 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1183 if (immediate_origin == NULL)
1184 return NULL;
1185 else
1187 register tree ret_val;
1188 register tree lookahead = immediate_origin;
1192 ret_val = lookahead;
1193 lookahead = (TREE_CODE (ret_val) == BLOCK)
1194 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1195 : NULL;
1197 while (lookahead != NULL && lookahead != ret_val);
1198 return ret_val;
1202 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1203 of a virtual function may refer to a base class, so we check the 'this'
1204 parameter. */
1206 static tree
1207 decl_class_context (decl)
1208 tree decl;
1210 tree context = NULL_TREE;
1211 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1212 context = DECL_CONTEXT (decl);
1213 else
1214 context = TYPE_MAIN_VARIANT
1215 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1217 if (context && !TYPE_P (context))
1218 context = NULL_TREE;
1220 return context;
1223 #if 0
1224 static void
1225 output_unsigned_leb128 (value)
1226 register unsigned long value;
1228 register unsigned long orig_value = value;
1232 register unsigned byte = (value & 0x7f);
1234 value >>= 7;
1235 if (value != 0) /* more bytes to follow */
1236 byte |= 0x80;
1237 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1238 if (flag_debug_asm && value == 0)
1239 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1240 ASM_COMMENT_START, orig_value);
1241 fputc ('\n', asm_out_file);
1243 while (value != 0);
1246 static void
1247 output_signed_leb128 (value)
1248 register long value;
1250 register long orig_value = value;
1251 register int negative = (value < 0);
1252 register int more;
1256 register unsigned byte = (value & 0x7f);
1258 value >>= 7;
1259 if (negative)
1260 value |= 0xfe000000; /* manually sign extend */
1261 if (((value == 0) && ((byte & 0x40) == 0))
1262 || ((value == -1) && ((byte & 0x40) == 1)))
1263 more = 0;
1264 else
1266 byte |= 0x80;
1267 more = 1;
1269 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1270 if (flag_debug_asm && more == 0)
1271 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1272 ASM_COMMENT_START, orig_value);
1273 fputc ('\n', asm_out_file);
1275 while (more);
1277 #endif
1279 /**************** utility functions for attribute functions ******************/
1281 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1282 type code for the given type.
1284 This routine must only be called for GCC type nodes that correspond to
1285 Dwarf fundamental types.
1287 The current Dwarf draft specification calls for Dwarf fundamental types
1288 to accurately reflect the fact that a given type was either a "plain"
1289 integral type or an explicitly "signed" integral type. Unfortunately,
1290 we can't always do this, because GCC may already have thrown away the
1291 information about the precise way in which the type was originally
1292 specified, as in:
1294 typedef signed int my_type;
1296 struct s { my_type f; };
1298 Since we may be stuck here without enought information to do exactly
1299 what is called for in the Dwarf draft specification, we do the best
1300 that we can under the circumstances and always use the "plain" integral
1301 fundamental type codes for int, short, and long types. That's probably
1302 good enough. The additional accuracy called for in the current DWARF
1303 draft specification is probably never even useful in practice. */
1305 static int
1306 fundamental_type_code (type)
1307 register tree type;
1309 if (TREE_CODE (type) == ERROR_MARK)
1310 return 0;
1312 switch (TREE_CODE (type))
1314 case ERROR_MARK:
1315 return FT_void;
1317 case VOID_TYPE:
1318 return FT_void;
1320 case INTEGER_TYPE:
1321 /* Carefully distinguish all the standard types of C,
1322 without messing up if the language is not C.
1323 Note that we check only for the names that contain spaces;
1324 other names might occur by coincidence in other languages. */
1325 if (TYPE_NAME (type) != 0
1326 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1327 && DECL_NAME (TYPE_NAME (type)) != 0
1328 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1330 const char *name =
1331 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1333 if (!strcmp (name, "unsigned char"))
1334 return FT_unsigned_char;
1335 if (!strcmp (name, "signed char"))
1336 return FT_signed_char;
1337 if (!strcmp (name, "unsigned int"))
1338 return FT_unsigned_integer;
1339 if (!strcmp (name, "short int"))
1340 return FT_short;
1341 if (!strcmp (name, "short unsigned int"))
1342 return FT_unsigned_short;
1343 if (!strcmp (name, "long int"))
1344 return FT_long;
1345 if (!strcmp (name, "long unsigned int"))
1346 return FT_unsigned_long;
1347 if (!strcmp (name, "long long int"))
1348 return FT_long_long; /* Not grok'ed by svr4 SDB */
1349 if (!strcmp (name, "long long unsigned int"))
1350 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1353 /* Most integer types will be sorted out above, however, for the
1354 sake of special `array index' integer types, the following code
1355 is also provided. */
1357 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1358 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1360 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1361 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1363 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1364 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1366 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1367 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1369 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1370 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1372 if (TYPE_MODE (type) == TImode)
1373 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1375 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1376 if (TYPE_PRECISION (type) == 1)
1377 return FT_boolean;
1379 abort ();
1381 case REAL_TYPE:
1382 /* Carefully distinguish all the standard types of C,
1383 without messing up if the language is not C. */
1384 if (TYPE_NAME (type) != 0
1385 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1386 && DECL_NAME (TYPE_NAME (type)) != 0
1387 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1389 const char *name =
1390 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1392 /* Note that here we can run afowl of a serious bug in "classic"
1393 svr4 SDB debuggers. They don't seem to understand the
1394 FT_ext_prec_float type (even though they should). */
1396 if (!strcmp (name, "long double"))
1397 return FT_ext_prec_float;
1400 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1402 /* On the SH, when compiling with -m3e or -m4-single-only, both
1403 float and double are 32 bits. But since the debugger doesn't
1404 know about the subtarget, it always thinks double is 64 bits.
1405 So we have to tell the debugger that the type is float to
1406 make the output of the 'print' command etc. readable. */
1407 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1408 return FT_float;
1409 return FT_dbl_prec_float;
1411 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1412 return FT_float;
1414 /* Note that here we can run afowl of a serious bug in "classic"
1415 svr4 SDB debuggers. They don't seem to understand the
1416 FT_ext_prec_float type (even though they should). */
1418 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1419 return FT_ext_prec_float;
1420 abort ();
1422 case COMPLEX_TYPE:
1423 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1425 case CHAR_TYPE:
1426 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1428 case BOOLEAN_TYPE:
1429 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1431 default:
1432 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1434 return 0;
1437 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1438 the Dwarf "root" type for the given input type. The Dwarf "root" type
1439 of a given type is generally the same as the given type, except that if
1440 the given type is a pointer or reference type, then the root type of
1441 the given type is the root type of the "basis" type for the pointer or
1442 reference type. (This definition of the "root" type is recursive.)
1443 Also, the root type of a `const' qualified type or a `volatile'
1444 qualified type is the root type of the given type without the
1445 qualifiers. */
1447 static tree
1448 root_type_1 (type, count)
1449 register tree type;
1450 register int count;
1452 /* Give up after searching 1000 levels, in case this is a recursive
1453 pointer type. Such types are possible in Ada, but it is not possible
1454 to represent them in DWARF1 debug info. */
1455 if (count > 1000)
1456 return error_mark_node;
1458 switch (TREE_CODE (type))
1460 case ERROR_MARK:
1461 return error_mark_node;
1463 case POINTER_TYPE:
1464 case REFERENCE_TYPE:
1465 return root_type_1 (TREE_TYPE (type), count+1);
1467 default:
1468 return type;
1472 static tree
1473 root_type (type)
1474 register tree type;
1476 type = root_type_1 (type, 0);
1477 if (type != error_mark_node)
1478 type = type_main_variant (type);
1479 return type;
1482 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1483 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1485 static void
1486 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1487 register tree type;
1488 register int decl_const;
1489 register int decl_volatile;
1490 register int count;
1492 if (TREE_CODE (type) == ERROR_MARK)
1493 return;
1495 /* Give up after searching 1000 levels, in case this is a recursive
1496 pointer type. Such types are possible in Ada, but it is not possible
1497 to represent them in DWARF1 debug info. */
1498 if (count > 1000)
1499 return;
1501 if (TYPE_READONLY (type) || decl_const)
1502 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1503 if (TYPE_VOLATILE (type) || decl_volatile)
1504 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1505 switch (TREE_CODE (type))
1507 case POINTER_TYPE:
1508 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1509 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1510 return;
1512 case REFERENCE_TYPE:
1513 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1514 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1515 return;
1517 case ERROR_MARK:
1518 default:
1519 return;
1523 static void
1524 write_modifier_bytes (type, decl_const, decl_volatile)
1525 register tree type;
1526 register int decl_const;
1527 register int decl_volatile;
1529 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1532 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1533 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1535 static inline int
1536 type_is_fundamental (type)
1537 register tree type;
1539 switch (TREE_CODE (type))
1541 case ERROR_MARK:
1542 case VOID_TYPE:
1543 case INTEGER_TYPE:
1544 case REAL_TYPE:
1545 case COMPLEX_TYPE:
1546 case BOOLEAN_TYPE:
1547 case CHAR_TYPE:
1548 return 1;
1550 case SET_TYPE:
1551 case ARRAY_TYPE:
1552 case RECORD_TYPE:
1553 case UNION_TYPE:
1554 case QUAL_UNION_TYPE:
1555 case ENUMERAL_TYPE:
1556 case FUNCTION_TYPE:
1557 case METHOD_TYPE:
1558 case POINTER_TYPE:
1559 case REFERENCE_TYPE:
1560 case FILE_TYPE:
1561 case OFFSET_TYPE:
1562 case LANG_TYPE:
1563 case VECTOR_TYPE:
1564 return 0;
1566 default:
1567 abort ();
1569 return 0;
1572 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1573 equate directive which will associate a symbolic name with the current DIE.
1575 The name used is an artificial label generated from the DECL_UID number
1576 associated with the given decl node. The name it gets equated to is the
1577 symbolic label that we (previously) output at the start of the DIE that
1578 we are currently generating.
1580 Calling this function while generating some "decl related" form of DIE
1581 makes it possible to later refer to the DIE which represents the given
1582 decl simply by re-generating the symbolic name from the ..._DECL node's
1583 UID number. */
1585 static void
1586 equate_decl_number_to_die_number (decl)
1587 register tree decl;
1589 /* In the case where we are generating a DIE for some ..._DECL node
1590 which represents either some inline function declaration or some
1591 entity declared within an inline function declaration/definition,
1592 setup a symbolic name for the current DIE so that we have a name
1593 for this DIE that we can easily refer to later on within
1594 AT_abstract_origin attributes. */
1596 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1597 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1599 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1600 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1601 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1604 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1605 equate directive which will associate a symbolic name with the current DIE.
1607 The name used is an artificial label generated from the TYPE_UID number
1608 associated with the given type node. The name it gets equated to is the
1609 symbolic label that we (previously) output at the start of the DIE that
1610 we are currently generating.
1612 Calling this function while generating some "type related" form of DIE
1613 makes it easy to later refer to the DIE which represents the given type
1614 simply by re-generating the alternative name from the ..._TYPE node's
1615 UID number. */
1617 static inline void
1618 equate_type_number_to_die_number (type)
1619 register tree type;
1621 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1622 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1624 /* We are generating a DIE to represent the main variant of this type
1625 (i.e the type without any const or volatile qualifiers) so in order
1626 to get the equate to come out right, we need to get the main variant
1627 itself here. */
1629 type = type_main_variant (type);
1631 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1632 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1633 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1636 static void
1637 output_reg_number (rtl)
1638 register rtx rtl;
1640 register unsigned regno = REGNO (rtl);
1642 if (regno >= DWARF_FRAME_REGISTERS)
1644 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1645 regno);
1646 regno = 0;
1648 fprintf (asm_out_file, "\t%s\t0x%x",
1649 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1650 if (flag_debug_asm)
1652 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1653 PRINT_REG (rtl, 0, asm_out_file);
1655 fputc ('\n', asm_out_file);
1658 /* The following routine is a nice and simple transducer. It converts the
1659 RTL for a variable or parameter (resident in memory) into an equivalent
1660 Dwarf representation of a mechanism for getting the address of that same
1661 variable onto the top of a hypothetical "address evaluation" stack.
1663 When creating memory location descriptors, we are effectively trans-
1664 forming the RTL for a memory-resident object into its Dwarf postfix
1665 expression equivalent. This routine just recursively descends an
1666 RTL tree, turning it into Dwarf postfix code as it goes. */
1668 static void
1669 output_mem_loc_descriptor (rtl)
1670 register rtx rtl;
1672 /* Note that for a dynamically sized array, the location we will
1673 generate a description of here will be the lowest numbered location
1674 which is actually within the array. That's *not* necessarily the
1675 same as the zeroth element of the array. */
1677 #ifdef ASM_SIMPLIFY_DWARF_ADDR
1678 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
1679 #endif
1681 switch (GET_CODE (rtl))
1683 case SUBREG:
1685 /* The case of a subreg may arise when we have a local (register)
1686 variable or a formal (register) parameter which doesn't quite
1687 fill up an entire register. For now, just assume that it is
1688 legitimate to make the Dwarf info refer to the whole register
1689 which contains the given subreg. */
1691 rtl = XEXP (rtl, 0);
1692 /* Drop thru. */
1694 case REG:
1696 /* Whenever a register number forms a part of the description of
1697 the method for calculating the (dynamic) address of a memory
1698 resident object, DWARF rules require the register number to
1699 be referred to as a "base register". This distinction is not
1700 based in any way upon what category of register the hardware
1701 believes the given register belongs to. This is strictly
1702 DWARF terminology we're dealing with here.
1704 Note that in cases where the location of a memory-resident data
1705 object could be expressed as:
1707 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1709 the actual DWARF location descriptor that we generate may just
1710 be OP_BASEREG (basereg). This may look deceptively like the
1711 object in question was allocated to a register (rather than
1712 in memory) so DWARF consumers need to be aware of the subtle
1713 distinction between OP_REG and OP_BASEREG. */
1715 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1716 output_reg_number (rtl);
1717 break;
1719 case MEM:
1720 output_mem_loc_descriptor (XEXP (rtl, 0));
1721 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1722 break;
1724 case CONST:
1725 case SYMBOL_REF:
1726 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1727 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1728 break;
1730 case PLUS:
1731 output_mem_loc_descriptor (XEXP (rtl, 0));
1732 output_mem_loc_descriptor (XEXP (rtl, 1));
1733 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1734 break;
1736 case CONST_INT:
1737 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1738 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1739 break;
1741 case MULT:
1742 /* If a pseudo-reg is optimized away, it is possible for it to
1743 be replaced with a MEM containing a multiply. Use a GNU extension
1744 to describe it. */
1745 output_mem_loc_descriptor (XEXP (rtl, 0));
1746 output_mem_loc_descriptor (XEXP (rtl, 1));
1747 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1748 break;
1750 default:
1751 abort ();
1755 /* Output a proper Dwarf location descriptor for a variable or parameter
1756 which is either allocated in a register or in a memory location. For
1757 a register, we just generate an OP_REG and the register number. For a
1758 memory location we provide a Dwarf postfix expression describing how to
1759 generate the (dynamic) address of the object onto the address stack. */
1761 static void
1762 output_loc_descriptor (rtl)
1763 register rtx rtl;
1765 switch (GET_CODE (rtl))
1767 case SUBREG:
1769 /* The case of a subreg may arise when we have a local (register)
1770 variable or a formal (register) parameter which doesn't quite
1771 fill up an entire register. For now, just assume that it is
1772 legitimate to make the Dwarf info refer to the whole register
1773 which contains the given subreg. */
1775 rtl = XEXP (rtl, 0);
1776 /* Drop thru. */
1778 case REG:
1779 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1780 output_reg_number (rtl);
1781 break;
1783 case MEM:
1784 output_mem_loc_descriptor (XEXP (rtl, 0));
1785 break;
1787 default:
1788 abort (); /* Should never happen */
1792 /* Given a tree node describing an array bound (either lower or upper)
1793 output a representation for that bound. */
1795 static void
1796 output_bound_representation (bound, dim_num, u_or_l)
1797 register tree bound;
1798 register unsigned dim_num; /* For multi-dimensional arrays. */
1799 register char u_or_l; /* Designates upper or lower bound. */
1801 switch (TREE_CODE (bound))
1804 case ERROR_MARK:
1805 return;
1807 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1809 case INTEGER_CST:
1810 if (host_integerp (bound, 0))
1811 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
1812 break;
1814 default:
1816 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1817 SAVE_EXPR nodes, in which case we can do something, or as
1818 an expression, which we cannot represent. */
1820 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1821 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1823 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1824 current_dienum, dim_num, u_or_l);
1826 sprintf (end_label, BOUND_END_LABEL_FMT,
1827 current_dienum, dim_num, u_or_l);
1829 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1830 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1832 /* If optimization is turned on, the SAVE_EXPRs that describe
1833 how to access the upper bound values are essentially bogus.
1834 They only describe (at best) how to get at these values at
1835 the points in the generated code right after they have just
1836 been computed. Worse yet, in the typical case, the upper
1837 bound values will not even *be* computed in the optimized
1838 code, so these SAVE_EXPRs are entirely bogus.
1840 In order to compensate for this fact, we check here to see
1841 if optimization is enabled, and if so, we effectively create
1842 an empty location description for the (unknown and unknowable)
1843 upper bound.
1845 This should not cause too much trouble for existing (stupid?)
1846 debuggers because they have to deal with empty upper bounds
1847 location descriptions anyway in order to be able to deal with
1848 incomplete array types.
1850 Of course an intelligent debugger (GDB?) should be able to
1851 comprehend that a missing upper bound specification in a
1852 array type used for a storage class `auto' local array variable
1853 indicates that the upper bound is both unknown (at compile-
1854 time) and unknowable (at run-time) due to optimization. */
1856 if (! optimize)
1858 while (TREE_CODE (bound) == NOP_EXPR
1859 || TREE_CODE (bound) == CONVERT_EXPR)
1860 bound = TREE_OPERAND (bound, 0);
1862 if (TREE_CODE (bound) == SAVE_EXPR)
1863 output_loc_descriptor
1864 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1867 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1869 break;
1874 /* Recursive function to output a sequence of value/name pairs for
1875 enumeration constants in reversed order. This is called from
1876 enumeration_type_die. */
1878 static void
1879 output_enumeral_list (link)
1880 register tree link;
1882 if (link)
1884 output_enumeral_list (TREE_CHAIN (link));
1886 if (host_integerp (TREE_VALUE (link), 0))
1887 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1888 tree_low_cst (TREE_VALUE (link), 0));
1890 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
1891 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1895 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1896 which is not less than the value itself. */
1898 static inline HOST_WIDE_INT
1899 ceiling (value, boundary)
1900 register HOST_WIDE_INT value;
1901 register unsigned int boundary;
1903 return (((value + boundary - 1) / boundary) * boundary);
1906 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1907 pointer to the declared type for the relevant field variable, or return
1908 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1910 static inline tree
1911 field_type (decl)
1912 register tree decl;
1914 register tree type;
1916 if (TREE_CODE (decl) == ERROR_MARK)
1917 return integer_type_node;
1919 type = DECL_BIT_FIELD_TYPE (decl);
1920 if (type == NULL)
1921 type = TREE_TYPE (decl);
1922 return type;
1925 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1926 node, return the alignment in bits for the type, or else return
1927 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1929 static inline unsigned int
1930 simple_type_align_in_bits (type)
1931 register tree type;
1933 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1936 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1937 node, return the size in bits for the type if it is a constant, or
1938 else return the alignment for the type if the type's size is not
1939 constant, or else return BITS_PER_WORD if the type actually turns out
1940 to be an ERROR_MARK node. */
1942 static inline unsigned HOST_WIDE_INT
1943 simple_type_size_in_bits (type)
1944 register tree type;
1946 if (TREE_CODE (type) == ERROR_MARK)
1947 return BITS_PER_WORD;
1948 else
1950 register tree type_size_tree = TYPE_SIZE (type);
1952 if (! host_integerp (type_size_tree, 1))
1953 return TYPE_ALIGN (type);
1955 return tree_low_cst (type_size_tree, 1);
1959 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1960 return the byte offset of the lowest addressed byte of the "containing
1961 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1962 mine what that offset is, either because the argument turns out to be a
1963 pointer to an ERROR_MARK node, or because the offset is actually variable.
1964 (We can't handle the latter case just yet.) */
1966 static HOST_WIDE_INT
1967 field_byte_offset (decl)
1968 register tree decl;
1970 unsigned int type_align_in_bytes;
1971 unsigned int type_align_in_bits;
1972 unsigned HOST_WIDE_INT type_size_in_bits;
1973 HOST_WIDE_INT object_offset_in_align_units;
1974 HOST_WIDE_INT object_offset_in_bits;
1975 HOST_WIDE_INT object_offset_in_bytes;
1976 tree type;
1977 tree field_size_tree;
1978 HOST_WIDE_INT bitpos_int;
1979 HOST_WIDE_INT deepest_bitpos;
1980 unsigned HOST_WIDE_INT field_size_in_bits;
1982 if (TREE_CODE (decl) == ERROR_MARK)
1983 return 0;
1985 if (TREE_CODE (decl) != FIELD_DECL)
1986 abort ();
1988 type = field_type (decl);
1989 field_size_tree = DECL_SIZE (decl);
1991 /* If there was an error, the size could be zero. */
1992 if (! field_size_tree)
1994 if (errorcount)
1995 return 0;
1997 abort ();
2000 /* We cannot yet cope with fields whose positions or sizes are variable,
2001 so for now, when we see such things, we simply return 0. Someday,
2002 we may be able to handle such cases, but it will be damn difficult. */
2004 if (! host_integerp (bit_position (decl), 0)
2005 || ! host_integerp (field_size_tree, 1))
2006 return 0;
2008 bitpos_int = int_bit_position (decl);
2009 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2011 type_size_in_bits = simple_type_size_in_bits (type);
2012 type_align_in_bits = simple_type_align_in_bits (type);
2013 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2015 /* Note that the GCC front-end doesn't make any attempt to keep track
2016 of the starting bit offset (relative to the start of the containing
2017 structure type) of the hypothetical "containing object" for a bit-
2018 field. Thus, when computing the byte offset value for the start of
2019 the "containing object" of a bit-field, we must deduce this infor-
2020 mation on our own.
2022 This can be rather tricky to do in some cases. For example, handling
2023 the following structure type definition when compiling for an i386/i486
2024 target (which only aligns long long's to 32-bit boundaries) can be very
2025 tricky:
2027 struct S {
2028 int field1;
2029 long long field2:31;
2032 Fortunately, there is a simple rule-of-thumb which can be used in such
2033 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2034 the structure shown above. It decides to do this based upon one simple
2035 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2036 taining object" for each bit-field at the first (i.e. lowest addressed)
2037 legitimate alignment boundary (based upon the required minimum alignment
2038 for the declared type of the field) which it can possibly use, subject
2039 to the condition that there is still enough available space remaining
2040 in the containing object (when allocated at the selected point) to
2041 fully accommodate all of the bits of the bit-field itself.
2043 This simple rule makes it obvious why GCC allocates 8 bytes for each
2044 object of the structure type shown above. When looking for a place to
2045 allocate the "containing object" for `field2', the compiler simply tries
2046 to allocate a 64-bit "containing object" at each successive 32-bit
2047 boundary (starting at zero) until it finds a place to allocate that 64-
2048 bit field such that at least 31 contiguous (and previously unallocated)
2049 bits remain within that selected 64 bit field. (As it turns out, for
2050 the example above, the compiler finds that it is OK to allocate the
2051 "containing object" 64-bit field at bit-offset zero within the
2052 structure type.)
2054 Here we attempt to work backwards from the limited set of facts we're
2055 given, and we try to deduce from those facts, where GCC must have
2056 believed that the containing object started (within the structure type).
2058 The value we deduce is then used (by the callers of this routine) to
2059 generate AT_location and AT_bit_offset attributes for fields (both
2060 bit-fields and, in the case of AT_location, regular fields as well). */
2062 /* Figure out the bit-distance from the start of the structure to the
2063 "deepest" bit of the bit-field. */
2064 deepest_bitpos = bitpos_int + field_size_in_bits;
2066 /* This is the tricky part. Use some fancy footwork to deduce where the
2067 lowest addressed bit of the containing object must be. */
2068 object_offset_in_bits
2069 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2071 /* Compute the offset of the containing object in "alignment units". */
2072 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2074 /* Compute the offset of the containing object in bytes. */
2075 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2077 /* The above code assumes that the field does not cross an alignment
2078 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2079 or if the structure is packed. If this happens, then we get an object
2080 which starts after the bitfield, which means that the bit offset is
2081 negative. Gdb fails when given negative bit offsets. We avoid this
2082 by recomputing using the first bit of the bitfield. This will give
2083 us an object which does not completely contain the bitfield, but it
2084 will be aligned, and it will contain the first bit of the bitfield.
2086 However, only do this for a BYTES_BIG_ENDIAN target. For a
2087 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2088 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2089 then we end up computing the object byte offset for the wrong word of the
2090 desired bitfield, which in turn causes the field offset to be negative
2091 in bit_offset_attribute. */
2092 if (BYTES_BIG_ENDIAN
2093 && object_offset_in_bits > bitpos_int)
2095 deepest_bitpos = bitpos_int + 1;
2096 object_offset_in_bits
2097 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2098 object_offset_in_align_units = (object_offset_in_bits
2099 / type_align_in_bits);
2100 object_offset_in_bytes = (object_offset_in_align_units
2101 * type_align_in_bytes);
2104 return object_offset_in_bytes;
2107 /****************************** attributes *********************************/
2109 /* The following routines are responsible for writing out the various types
2110 of Dwarf attributes (and any following data bytes associated with them).
2111 These routines are listed in order based on the numerical codes of their
2112 associated attributes. */
2114 /* Generate an AT_sibling attribute. */
2116 static inline void
2117 sibling_attribute ()
2119 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2121 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2122 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2123 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2126 /* Output the form of location attributes suitable for whole variables and
2127 whole parameters. Note that the location attributes for struct fields
2128 are generated by the routine `data_member_location_attribute' below. */
2130 static void
2131 location_attribute (rtl)
2132 register rtx rtl;
2134 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2135 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2137 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2138 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2139 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2140 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2141 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2143 /* Handle a special case. If we are about to output a location descriptor
2144 for a variable or parameter which has been optimized out of existence,
2145 don't do that. Instead we output a zero-length location descriptor
2146 value as part of the location attribute.
2148 A variable which has been optimized out of existence will have a
2149 DECL_RTL value which denotes a pseudo-reg.
2151 Currently, in some rare cases, variables can have DECL_RTL values
2152 which look like (MEM (REG pseudo-reg#)). These cases are due to
2153 bugs elsewhere in the compiler. We treat such cases
2154 as if the variable(s) in question had been optimized out of existence.
2156 Note that in all cases where we wish to express the fact that a
2157 variable has been optimized out of existence, we do not simply
2158 suppress the generation of the entire location attribute because
2159 the absence of a location attribute in certain kinds of DIEs is
2160 used to indicate something else entirely... i.e. that the DIE
2161 represents an object declaration, but not a definition. So saith
2162 the PLSIG.
2165 if (! is_pseudo_reg (rtl)
2166 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2167 output_loc_descriptor (rtl);
2169 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2172 /* Output the specialized form of location attribute used for data members
2173 of struct and union types.
2175 In the special case of a FIELD_DECL node which represents a bit-field,
2176 the "offset" part of this special location descriptor must indicate the
2177 distance in bytes from the lowest-addressed byte of the containing
2178 struct or union type to the lowest-addressed byte of the "containing
2179 object" for the bit-field. (See the `field_byte_offset' function above.)
2181 For any given bit-field, the "containing object" is a hypothetical
2182 object (of some integral or enum type) within which the given bit-field
2183 lives. The type of this hypothetical "containing object" is always the
2184 same as the declared type of the individual bit-field itself (for GCC
2185 anyway... the DWARF spec doesn't actually mandate this).
2187 Note that it is the size (in bytes) of the hypothetical "containing
2188 object" which will be given in the AT_byte_size attribute for this
2189 bit-field. (See the `byte_size_attribute' function below.) It is
2190 also used when calculating the value of the AT_bit_offset attribute.
2191 (See the `bit_offset_attribute' function below.) */
2193 static void
2194 data_member_location_attribute (t)
2195 register tree t;
2197 register unsigned object_offset_in_bytes;
2198 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2199 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2201 if (TREE_CODE (t) == TREE_VEC)
2202 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2203 else
2204 object_offset_in_bytes = field_byte_offset (t);
2206 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2207 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2208 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2209 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2210 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2211 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2212 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2213 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2214 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2217 /* Output an AT_const_value attribute for a variable or a parameter which
2218 does not have a "location" either in memory or in a register. These
2219 things can arise in GNU C when a constant is passed as an actual
2220 parameter to an inlined function. They can also arise in C++ where
2221 declared constants do not necessarily get memory "homes". */
2223 static void
2224 const_value_attribute (rtl)
2225 register rtx rtl;
2227 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2228 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2230 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2231 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2232 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2233 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2234 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2236 switch (GET_CODE (rtl))
2238 case CONST_INT:
2239 /* Note that a CONST_INT rtx could represent either an integer or
2240 a floating-point constant. A CONST_INT is used whenever the
2241 constant will fit into a single word. In all such cases, the
2242 original mode of the constant value is wiped out, and the
2243 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2244 precise mode information for these constants, we always just
2245 output them using 4 bytes. */
2247 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2248 break;
2250 case CONST_DOUBLE:
2251 /* Note that a CONST_DOUBLE rtx could represent either an integer
2252 or a floating-point constant. A CONST_DOUBLE is used whenever
2253 the constant requires more than one word in order to be adequately
2254 represented. In all such cases, the original mode of the constant
2255 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2256 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2258 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2259 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2260 (unsigned int) CONST_DOUBLE_LOW (rtl));
2261 break;
2263 case CONST_STRING:
2264 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2265 break;
2267 case SYMBOL_REF:
2268 case LABEL_REF:
2269 case CONST:
2270 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2271 break;
2273 case PLUS:
2274 /* In cases where an inlined instance of an inline function is passed
2275 the address of an `auto' variable (which is local to the caller)
2276 we can get a situation where the DECL_RTL of the artificial
2277 local variable (for the inlining) which acts as a stand-in for
2278 the corresponding formal parameter (of the inline function)
2279 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2280 This is not exactly a compile-time constant expression, but it
2281 isn't the address of the (artificial) local variable either.
2282 Rather, it represents the *value* which the artificial local
2283 variable always has during its lifetime. We currently have no
2284 way to represent such quasi-constant values in Dwarf, so for now
2285 we just punt and generate an AT_const_value attribute with form
2286 FORM_BLOCK4 and a length of zero. */
2287 break;
2289 default:
2290 abort (); /* No other kinds of rtx should be possible here. */
2293 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2296 /* Generate *either* an AT_location attribute or else an AT_const_value
2297 data attribute for a variable or a parameter. We generate the
2298 AT_const_value attribute only in those cases where the given
2299 variable or parameter does not have a true "location" either in
2300 memory or in a register. This can happen (for example) when a
2301 constant is passed as an actual argument in a call to an inline
2302 function. (It's possible that these things can crop up in other
2303 ways also.) Note that one type of constant value which can be
2304 passed into an inlined function is a constant pointer. This can
2305 happen for example if an actual argument in an inlined function
2306 call evaluates to a compile-time constant address. */
2308 static void
2309 location_or_const_value_attribute (decl)
2310 register tree decl;
2312 register rtx rtl;
2314 if (TREE_CODE (decl) == ERROR_MARK)
2315 return;
2317 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2319 /* Should never happen. */
2320 abort ();
2321 return;
2324 /* Here we have to decide where we are going to say the parameter "lives"
2325 (as far as the debugger is concerned). We only have a couple of choices.
2326 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2327 normally indicates where the parameter lives during most of the activa-
2328 tion of the function. If optimization is enabled however, this could
2329 be either NULL or else a pseudo-reg. Both of those cases indicate that
2330 the parameter doesn't really live anywhere (as far as the code generation
2331 parts of GCC are concerned) during most of the function's activation.
2332 That will happen (for example) if the parameter is never referenced
2333 within the function.
2335 We could just generate a location descriptor here for all non-NULL
2336 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2337 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2338 cases where DECL_RTL is NULL or is a pseudo-reg.
2340 Note however that we can only get away with using DECL_INCOMING_RTL as
2341 a backup substitute for DECL_RTL in certain limited cases. In cases
2342 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2343 we can be sure that the parameter was passed using the same type as it
2344 is declared to have within the function, and that its DECL_INCOMING_RTL
2345 points us to a place where a value of that type is passed. In cases
2346 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2347 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2348 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2349 points us to a value of some type which is *different* from the type
2350 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2351 to generate a location attribute in such cases, the debugger would
2352 end up (for example) trying to fetch a `float' from a place which
2353 actually contains the first part of a `double'. That would lead to
2354 really incorrect and confusing output at debug-time, and we don't
2355 want that now do we?
2357 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2358 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2359 couple of cute exceptions however. On little-endian machines we can
2360 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2361 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2362 an integral type which is smaller than TREE_TYPE(decl). These cases
2363 arise when (on a little-endian machine) a non-prototyped function has
2364 a parameter declared to be of type `short' or `char'. In such cases,
2365 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2366 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2367 passed `int' value. If the debugger then uses that address to fetch a
2368 `short' or a `char' (on a little-endian machine) the result will be the
2369 correct data, so we allow for such exceptional cases below.
2371 Note that our goal here is to describe the place where the given formal
2372 parameter lives during most of the function's activation (i.e. between
2373 the end of the prologue and the start of the epilogue). We'll do that
2374 as best as we can. Note however that if the given formal parameter is
2375 modified sometime during the execution of the function, then a stack
2376 backtrace (at debug-time) will show the function as having been called
2377 with the *new* value rather than the value which was originally passed
2378 in. This happens rarely enough that it is not a major problem, but it
2379 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2380 may generate two additional attributes for any given TAG_formal_parameter
2381 DIE which will describe the "passed type" and the "passed location" for
2382 the given formal parameter in addition to the attributes we now generate
2383 to indicate the "declared type" and the "active location" for each
2384 parameter. This additional set of attributes could be used by debuggers
2385 for stack backtraces.
2387 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2388 can be NULL also. This happens (for example) for inlined-instances of
2389 inline function formal parameters which are never referenced. This really
2390 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2391 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2392 these values for inlined instances of inline function parameters, so
2393 when we see such cases, we are just out-of-luck for the time
2394 being (until integrate.c gets fixed).
2397 /* Use DECL_RTL as the "location" unless we find something better. */
2398 rtl = DECL_RTL (decl);
2400 if (TREE_CODE (decl) == PARM_DECL)
2401 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2403 /* This decl represents a formal parameter which was optimized out. */
2404 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2405 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2407 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2408 *all* cases where (rtl == NULL_RTX) just below. */
2410 if (declared_type == passed_type)
2411 rtl = DECL_INCOMING_RTL (decl);
2412 else if (! BYTES_BIG_ENDIAN)
2413 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2414 /* NMS WTF? */
2415 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2416 rtl = DECL_INCOMING_RTL (decl);
2419 if (rtl == NULL_RTX)
2420 return;
2422 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2423 #ifdef LEAF_REG_REMAP
2424 if (current_function_uses_only_leaf_regs)
2425 leaf_renumber_regs_insn (rtl);
2426 #endif
2428 switch (GET_CODE (rtl))
2430 case ADDRESSOF:
2431 /* The address of a variable that was optimized away; don't emit
2432 anything. */
2433 break;
2435 case CONST_INT:
2436 case CONST_DOUBLE:
2437 case CONST_STRING:
2438 case SYMBOL_REF:
2439 case LABEL_REF:
2440 case CONST:
2441 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2442 const_value_attribute (rtl);
2443 break;
2445 case MEM:
2446 case REG:
2447 case SUBREG:
2448 location_attribute (rtl);
2449 break;
2451 case CONCAT:
2452 /* ??? CONCAT is used for complex variables, which may have the real
2453 part stored in one place and the imag part stored somewhere else.
2454 DWARF1 has no way to describe a variable that lives in two different
2455 places, so we just describe where the first part lives, and hope that
2456 the second part is stored after it. */
2457 location_attribute (XEXP (rtl, 0));
2458 break;
2460 default:
2461 abort (); /* Should never happen. */
2465 /* Generate an AT_name attribute given some string value to be included as
2466 the value of the attribute. */
2468 static inline void
2469 name_attribute (name_string)
2470 register const char *name_string;
2472 if (name_string && *name_string)
2474 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2475 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2479 static inline void
2480 fund_type_attribute (ft_code)
2481 register unsigned ft_code;
2483 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2484 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2487 static void
2488 mod_fund_type_attribute (type, decl_const, decl_volatile)
2489 register tree type;
2490 register int decl_const;
2491 register int decl_volatile;
2493 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2494 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2496 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2497 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2498 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2499 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2500 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2501 write_modifier_bytes (type, decl_const, decl_volatile);
2502 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2503 fundamental_type_code (root_type (type)));
2504 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2507 static inline void
2508 user_def_type_attribute (type)
2509 register tree type;
2511 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2513 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2514 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2515 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2518 static void
2519 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2520 register tree type;
2521 register int decl_const;
2522 register int decl_volatile;
2524 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2525 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2526 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2528 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2529 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2530 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2531 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2532 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2533 write_modifier_bytes (type, decl_const, decl_volatile);
2534 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2535 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2536 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2539 #ifdef USE_ORDERING_ATTRIBUTE
2540 static inline void
2541 ordering_attribute (ordering)
2542 register unsigned ordering;
2544 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2545 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2547 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2549 /* Note that the block of subscript information for an array type also
2550 includes information about the element type of type given array type. */
2552 static void
2553 subscript_data_attribute (type)
2554 register tree type;
2556 register unsigned dimension_number;
2557 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2558 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2560 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2561 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2562 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2563 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2564 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2566 /* The GNU compilers represent multidimensional array types as sequences
2567 of one dimensional array types whose element types are themselves array
2568 types. Here we squish that down, so that each multidimensional array
2569 type gets only one array_type DIE in the Dwarf debugging info. The
2570 draft Dwarf specification say that we are allowed to do this kind
2571 of compression in C (because there is no difference between an
2572 array or arrays and a multidimensional array in C) but for other
2573 source languages (e.g. Ada) we probably shouldn't do this. */
2575 for (dimension_number = 0;
2576 TREE_CODE (type) == ARRAY_TYPE;
2577 type = TREE_TYPE (type), dimension_number++)
2579 register tree domain = TYPE_DOMAIN (type);
2581 /* Arrays come in three flavors. Unspecified bounds, fixed
2582 bounds, and (in GNU C only) variable bounds. Handle all
2583 three forms here. */
2585 if (domain)
2587 /* We have an array type with specified bounds. */
2589 register tree lower = TYPE_MIN_VALUE (domain);
2590 register tree upper = TYPE_MAX_VALUE (domain);
2592 /* Handle only fundamental types as index types for now. */
2594 if (! type_is_fundamental (domain))
2595 abort ();
2597 /* Output the representation format byte for this dimension. */
2599 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2600 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2601 (upper && TREE_CODE (upper) == INTEGER_CST)));
2603 /* Output the index type for this dimension. */
2605 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2606 fundamental_type_code (domain));
2608 /* Output the representation for the lower bound. */
2610 output_bound_representation (lower, dimension_number, 'l');
2612 /* Output the representation for the upper bound. */
2614 output_bound_representation (upper, dimension_number, 'u');
2616 else
2618 /* We have an array type with an unspecified length. For C and
2619 C++ we can assume that this really means that (a) the index
2620 type is an integral type, and (b) the lower bound is zero.
2621 Note that Dwarf defines the representation of an unspecified
2622 (upper) bound as being a zero-length location description. */
2624 /* Output the array-bounds format byte. */
2626 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2628 /* Output the (assumed) index type. */
2630 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2632 /* Output the (assumed) lower bound (constant) value. */
2634 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2636 /* Output the (empty) location description for the upper bound. */
2638 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2642 /* Output the prefix byte that says that the element type is coming up. */
2644 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2646 /* Output a representation of the type of the elements of this array type. */
2648 type_attribute (type, 0, 0);
2650 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2653 static void
2654 byte_size_attribute (tree_node)
2655 register tree tree_node;
2657 register unsigned size;
2659 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2660 switch (TREE_CODE (tree_node))
2662 case ERROR_MARK:
2663 size = 0;
2664 break;
2666 case ENUMERAL_TYPE:
2667 case RECORD_TYPE:
2668 case UNION_TYPE:
2669 case QUAL_UNION_TYPE:
2670 case ARRAY_TYPE:
2671 size = int_size_in_bytes (tree_node);
2672 break;
2674 case FIELD_DECL:
2675 /* For a data member of a struct or union, the AT_byte_size is
2676 generally given as the number of bytes normally allocated for
2677 an object of the *declared* type of the member itself. This
2678 is true even for bit-fields. */
2679 size = simple_type_size_in_bits (field_type (tree_node))
2680 / BITS_PER_UNIT;
2681 break;
2683 default:
2684 abort ();
2687 /* Note that `size' might be -1 when we get to this point. If it
2688 is, that indicates that the byte size of the entity in question
2689 is variable. We have no good way of expressing this fact in Dwarf
2690 at the present time, so just let the -1 pass on through. */
2692 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2695 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2696 which specifies the distance in bits from the highest order bit of the
2697 "containing object" for the bit-field to the highest order bit of the
2698 bit-field itself.
2700 For any given bit-field, the "containing object" is a hypothetical
2701 object (of some integral or enum type) within which the given bit-field
2702 lives. The type of this hypothetical "containing object" is always the
2703 same as the declared type of the individual bit-field itself.
2705 The determination of the exact location of the "containing object" for
2706 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2707 function (above).
2709 Note that it is the size (in bytes) of the hypothetical "containing
2710 object" which will be given in the AT_byte_size attribute for this
2711 bit-field. (See `byte_size_attribute' above.) */
2713 static inline void
2714 bit_offset_attribute (decl)
2715 register tree decl;
2717 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
2718 tree type = DECL_BIT_FIELD_TYPE (decl);
2719 HOST_WIDE_INT bitpos_int;
2720 HOST_WIDE_INT highest_order_object_bit_offset;
2721 HOST_WIDE_INT highest_order_field_bit_offset;
2722 HOST_WIDE_INT bit_offset;
2724 /* Must be a bit field. */
2725 if (!type
2726 || TREE_CODE (decl) != FIELD_DECL)
2727 abort ();
2729 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
2730 if we encounter such things, just return without generating any
2731 attribute whatsoever. */
2733 if (! host_integerp (bit_position (decl), 0)
2734 || ! host_integerp (DECL_SIZE (decl), 1))
2735 return;
2737 bitpos_int = int_bit_position (decl);
2739 /* Note that the bit offset is always the distance (in bits) from the
2740 highest-order bit of the "containing object" to the highest-order
2741 bit of the bit-field itself. Since the "high-order end" of any
2742 object or field is different on big-endian and little-endian machines,
2743 the computation below must take account of these differences. */
2745 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2746 highest_order_field_bit_offset = bitpos_int;
2748 if (! BYTES_BIG_ENDIAN)
2750 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
2751 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2754 bit_offset =
2755 (! BYTES_BIG_ENDIAN
2756 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2757 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2759 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2760 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2763 /* For a FIELD_DECL node which represents a bit field, output an attribute
2764 which specifies the length in bits of the given field. */
2766 static inline void
2767 bit_size_attribute (decl)
2768 register tree decl;
2770 /* Must be a field and a bit field. */
2771 if (TREE_CODE (decl) != FIELD_DECL
2772 || ! DECL_BIT_FIELD_TYPE (decl))
2773 abort ();
2775 if (host_integerp (DECL_SIZE (decl), 1))
2777 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2778 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2779 tree_low_cst (DECL_SIZE (decl), 1));
2783 /* The following routine outputs the `element_list' attribute for enumeration
2784 type DIEs. The element_lits attribute includes the names and values of
2785 all of the enumeration constants associated with the given enumeration
2786 type. */
2788 static inline void
2789 element_list_attribute (element)
2790 register tree element;
2792 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2793 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2795 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2796 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2797 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2798 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2799 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2801 /* Here we output a list of value/name pairs for each enumeration constant
2802 defined for this enumeration type (as required), but we do it in REVERSE
2803 order. The order is the one required by the draft #5 Dwarf specification
2804 published by the UI/PLSIG. */
2806 output_enumeral_list (element); /* Recursively output the whole list. */
2808 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2811 /* Generate an AT_stmt_list attribute. These are normally present only in
2812 DIEs with a TAG_compile_unit tag. */
2814 static inline void
2815 stmt_list_attribute (label)
2816 register const char *label;
2818 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2819 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2820 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2823 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2824 for a subroutine DIE. */
2826 static inline void
2827 low_pc_attribute (asm_low_label)
2828 register const char *asm_low_label;
2830 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2831 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2834 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2835 subroutine DIE. */
2837 static inline void
2838 high_pc_attribute (asm_high_label)
2839 register const char *asm_high_label;
2841 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2842 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2845 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2847 static inline void
2848 body_begin_attribute (asm_begin_label)
2849 register const char *asm_begin_label;
2851 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2852 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2855 /* Generate an AT_body_end attribute for a subroutine DIE. */
2857 static inline void
2858 body_end_attribute (asm_end_label)
2859 register const char *asm_end_label;
2861 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2862 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2865 /* Generate an AT_language attribute given a LANG value. These attributes
2866 are used only within TAG_compile_unit DIEs. */
2868 static inline void
2869 language_attribute (language_code)
2870 register unsigned language_code;
2872 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2873 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2876 static inline void
2877 member_attribute (context)
2878 register tree context;
2880 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2882 /* Generate this attribute only for members in C++. */
2884 if (context != NULL && is_tagged_type (context))
2886 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2887 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2888 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2892 #if 0
2893 static inline void
2894 string_length_attribute (upper_bound)
2895 register tree upper_bound;
2897 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2898 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2900 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2901 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2902 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2903 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2904 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2905 output_bound_representation (upper_bound, 0, 'u');
2906 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2908 #endif
2910 static inline void
2911 comp_dir_attribute (dirname)
2912 register const char *dirname;
2914 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2915 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
2918 static inline void
2919 sf_names_attribute (sf_names_start_label)
2920 register const char *sf_names_start_label;
2922 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2923 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2924 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2927 static inline void
2928 src_info_attribute (src_info_start_label)
2929 register const char *src_info_start_label;
2931 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2932 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2933 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2936 static inline void
2937 mac_info_attribute (mac_info_start_label)
2938 register const char *mac_info_start_label;
2940 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2941 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2942 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2945 static inline void
2946 prototyped_attribute (func_type)
2947 register tree func_type;
2949 if ((strcmp (language_string, "GNU C") == 0)
2950 && (TYPE_ARG_TYPES (func_type) != NULL))
2952 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2953 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2957 static inline void
2958 producer_attribute (producer)
2959 register const char *producer;
2961 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2962 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
2965 static inline void
2966 inline_attribute (decl)
2967 register tree decl;
2969 if (DECL_INLINE (decl))
2971 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2972 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2976 static inline void
2977 containing_type_attribute (containing_type)
2978 register tree containing_type;
2980 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2982 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2983 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2984 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2987 static inline void
2988 abstract_origin_attribute (origin)
2989 register tree origin;
2991 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2993 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2994 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2996 case 'd':
2997 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2998 break;
3000 case 't':
3001 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3002 break;
3004 default:
3005 abort (); /* Should never happen. */
3008 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3011 #ifdef DWARF_DECL_COORDINATES
3012 static inline void
3013 src_coords_attribute (src_fileno, src_lineno)
3014 register unsigned src_fileno;
3015 register unsigned src_lineno;
3017 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3018 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3019 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3021 #endif /* defined(DWARF_DECL_COORDINATES) */
3023 static inline void
3024 pure_or_virtual_attribute (func_decl)
3025 register tree func_decl;
3027 if (DECL_VIRTUAL_P (func_decl))
3029 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3030 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3031 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3032 else
3033 #endif
3034 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3035 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3039 /************************* end of attributes *****************************/
3041 /********************* utility routines for DIEs *************************/
3043 /* Output an AT_name attribute and an AT_src_coords attribute for the
3044 given decl, but only if it actually has a name. */
3046 static void
3047 name_and_src_coords_attributes (decl)
3048 register tree decl;
3050 register tree decl_name = DECL_NAME (decl);
3052 if (decl_name && IDENTIFIER_POINTER (decl_name))
3054 name_attribute (IDENTIFIER_POINTER (decl_name));
3055 #ifdef DWARF_DECL_COORDINATES
3057 register unsigned file_index;
3059 /* This is annoying, but we have to pop out of the .debug section
3060 for a moment while we call `lookup_filename' because calling it
3061 may cause a temporary switch into the .debug_sfnames section and
3062 most svr4 assemblers are not smart enough to be able to nest
3063 section switches to any depth greater than one. Note that we
3064 also can't skirt this issue by delaying all output to the
3065 .debug_sfnames section unit the end of compilation because that
3066 would cause us to have inter-section forward references and
3067 Fred Fish sez that m68k/svr4 assemblers botch those. */
3069 ASM_OUTPUT_POP_SECTION (asm_out_file);
3070 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3071 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3073 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3075 #endif /* defined(DWARF_DECL_COORDINATES) */
3079 /* Many forms of DIEs contain a "type description" part. The following
3080 routine writes out these "type descriptor" parts. */
3082 static void
3083 type_attribute (type, decl_const, decl_volatile)
3084 register tree type;
3085 register int decl_const;
3086 register int decl_volatile;
3088 register enum tree_code code = TREE_CODE (type);
3089 register int root_type_modified;
3091 if (code == ERROR_MARK)
3092 return;
3094 /* Handle a special case. For functions whose return type is void,
3095 we generate *no* type attribute. (Note that no object may have
3096 type `void', so this only applies to function return types. */
3098 if (code == VOID_TYPE)
3099 return;
3101 /* If this is a subtype, find the underlying type. Eventually,
3102 this should write out the appropriate subtype info. */
3103 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3104 && TREE_TYPE (type) != 0)
3105 type = TREE_TYPE (type), code = TREE_CODE (type);
3107 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3108 || decl_const || decl_volatile
3109 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3111 if (type_is_fundamental (root_type (type)))
3113 if (root_type_modified)
3114 mod_fund_type_attribute (type, decl_const, decl_volatile);
3115 else
3116 fund_type_attribute (fundamental_type_code (type));
3118 else
3120 if (root_type_modified)
3121 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3122 else
3123 /* We have to get the type_main_variant here (and pass that to the
3124 `user_def_type_attribute' routine) because the ..._TYPE node we
3125 have might simply be a *copy* of some original type node (where
3126 the copy was created to help us keep track of typedef names)
3127 and that copy might have a different TYPE_UID from the original
3128 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3129 is labeling a given type DIE for future reference, it always and
3130 only creates labels for DIEs representing *main variants*, and it
3131 never even knows about non-main-variants.) */
3132 user_def_type_attribute (type_main_variant (type));
3136 /* Given a tree pointer to a struct, class, union, or enum type node, return
3137 a pointer to the (string) tag name for the given type, or zero if the
3138 type was declared without a tag. */
3140 static const char *
3141 type_tag (type)
3142 register tree type;
3144 register const char *name = 0;
3146 if (TYPE_NAME (type) != 0)
3148 register tree t = 0;
3150 /* Find the IDENTIFIER_NODE for the type name. */
3151 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3152 t = TYPE_NAME (type);
3154 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3155 a TYPE_DECL node, regardless of whether or not a `typedef' was
3156 involved. */
3157 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3158 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3159 t = DECL_NAME (TYPE_NAME (type));
3161 /* Now get the name as a string, or invent one. */
3162 if (t != 0)
3163 name = IDENTIFIER_POINTER (t);
3166 return (name == 0 || *name == '\0') ? 0 : name;
3169 static inline void
3170 dienum_push ()
3172 /* Start by checking if the pending_sibling_stack needs to be expanded.
3173 If necessary, expand it. */
3175 if (pending_siblings == pending_siblings_allocated)
3177 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3178 pending_sibling_stack
3179 = (unsigned *) xrealloc (pending_sibling_stack,
3180 pending_siblings_allocated * sizeof(unsigned));
3183 pending_siblings++;
3184 NEXT_DIE_NUM = next_unused_dienum++;
3187 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3188 NEXT_DIE_NUM. */
3190 static inline void
3191 dienum_pop ()
3193 pending_siblings--;
3196 static inline tree
3197 member_declared_type (member)
3198 register tree member;
3200 return (DECL_BIT_FIELD_TYPE (member))
3201 ? DECL_BIT_FIELD_TYPE (member)
3202 : TREE_TYPE (member);
3205 /* Get the function's label, as described by its RTL.
3206 This may be different from the DECL_NAME name used
3207 in the source file. */
3209 static const char *
3210 function_start_label (decl)
3211 register tree decl;
3213 rtx x;
3214 const char *fnname;
3216 x = DECL_RTL (decl);
3217 if (GET_CODE (x) != MEM)
3218 abort ();
3219 x = XEXP (x, 0);
3220 if (GET_CODE (x) != SYMBOL_REF)
3221 abort ();
3222 fnname = XSTR (x, 0);
3223 return fnname;
3227 /******************************* DIEs ************************************/
3229 /* Output routines for individual types of DIEs. */
3231 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3233 static void
3234 output_array_type_die (arg)
3235 register void *arg;
3237 register tree type = arg;
3239 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3240 sibling_attribute ();
3241 equate_type_number_to_die_number (type);
3242 member_attribute (TYPE_CONTEXT (type));
3244 /* I believe that we can default the array ordering. SDB will probably
3245 do the right things even if AT_ordering is not present. It's not
3246 even an issue until we start to get into multidimensional arrays
3247 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3248 dimensional arrays, then we'll have to put the AT_ordering attribute
3249 back in. (But if and when we find out that we need to put these in,
3250 we will only do so for multidimensional arrays. After all, we don't
3251 want to waste space in the .debug section now do we?) */
3253 #ifdef USE_ORDERING_ATTRIBUTE
3254 ordering_attribute (ORD_row_major);
3255 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3257 subscript_data_attribute (type);
3260 static void
3261 output_set_type_die (arg)
3262 register void *arg;
3264 register tree type = arg;
3266 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3267 sibling_attribute ();
3268 equate_type_number_to_die_number (type);
3269 member_attribute (TYPE_CONTEXT (type));
3270 type_attribute (TREE_TYPE (type), 0, 0);
3273 #if 0
3274 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3276 static void
3277 output_entry_point_die (arg)
3278 register void *arg;
3280 register tree decl = arg;
3281 register tree origin = decl_ultimate_origin (decl);
3283 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3284 sibling_attribute ();
3285 dienum_push ();
3286 if (origin != NULL)
3287 abstract_origin_attribute (origin);
3288 else
3290 name_and_src_coords_attributes (decl);
3291 member_attribute (DECL_CONTEXT (decl));
3292 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3294 if (DECL_ABSTRACT (decl))
3295 equate_decl_number_to_die_number (decl);
3296 else
3297 low_pc_attribute (function_start_label (decl));
3299 #endif
3301 /* Output a DIE to represent an inlined instance of an enumeration type. */
3303 static void
3304 output_inlined_enumeration_type_die (arg)
3305 register void *arg;
3307 register tree type = arg;
3309 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3310 sibling_attribute ();
3311 if (!TREE_ASM_WRITTEN (type))
3312 abort ();
3313 abstract_origin_attribute (type);
3316 /* Output a DIE to represent an inlined instance of a structure type. */
3318 static void
3319 output_inlined_structure_type_die (arg)
3320 register void *arg;
3322 register tree type = arg;
3324 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3325 sibling_attribute ();
3326 if (!TREE_ASM_WRITTEN (type))
3327 abort ();
3328 abstract_origin_attribute (type);
3331 /* Output a DIE to represent an inlined instance of a union type. */
3333 static void
3334 output_inlined_union_type_die (arg)
3335 register void *arg;
3337 register tree type = arg;
3339 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3340 sibling_attribute ();
3341 if (!TREE_ASM_WRITTEN (type))
3342 abort ();
3343 abstract_origin_attribute (type);
3346 /* Output a DIE to represent an enumeration type. Note that these DIEs
3347 include all of the information about the enumeration values also.
3348 This information is encoded into the element_list attribute. */
3350 static void
3351 output_enumeration_type_die (arg)
3352 register void *arg;
3354 register tree type = arg;
3356 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3357 sibling_attribute ();
3358 equate_type_number_to_die_number (type);
3359 name_attribute (type_tag (type));
3360 member_attribute (TYPE_CONTEXT (type));
3362 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3363 given enum type is incomplete, do not generate the AT_byte_size
3364 attribute or the AT_element_list attribute. */
3366 if (COMPLETE_TYPE_P (type))
3368 byte_size_attribute (type);
3369 element_list_attribute (TYPE_FIELDS (type));
3373 /* Output a DIE to represent either a real live formal parameter decl or
3374 to represent just the type of some formal parameter position in some
3375 function type.
3377 Note that this routine is a bit unusual because its argument may be
3378 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3379 represents an inlining of some PARM_DECL) or else some sort of a
3380 ..._TYPE node. If it's the former then this function is being called
3381 to output a DIE to represent a formal parameter object (or some inlining
3382 thereof). If it's the latter, then this function is only being called
3383 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3384 formal argument type of some subprogram type. */
3386 static void
3387 output_formal_parameter_die (arg)
3388 register void *arg;
3390 register tree node = arg;
3392 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3393 sibling_attribute ();
3395 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3397 case 'd': /* We were called with some kind of a ..._DECL node. */
3399 register tree origin = decl_ultimate_origin (node);
3401 if (origin != NULL)
3402 abstract_origin_attribute (origin);
3403 else
3405 name_and_src_coords_attributes (node);
3406 type_attribute (TREE_TYPE (node),
3407 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3409 if (DECL_ABSTRACT (node))
3410 equate_decl_number_to_die_number (node);
3411 else
3412 location_or_const_value_attribute (node);
3414 break;
3416 case 't': /* We were called with some kind of a ..._TYPE node. */
3417 type_attribute (node, 0, 0);
3418 break;
3420 default:
3421 abort (); /* Should never happen. */
3425 /* Output a DIE to represent a declared function (either file-scope
3426 or block-local) which has "external linkage" (according to ANSI-C). */
3428 static void
3429 output_global_subroutine_die (arg)
3430 register void *arg;
3432 register tree decl = arg;
3433 register tree origin = decl_ultimate_origin (decl);
3435 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3436 sibling_attribute ();
3437 dienum_push ();
3438 if (origin != NULL)
3439 abstract_origin_attribute (origin);
3440 else
3442 register tree type = TREE_TYPE (decl);
3444 name_and_src_coords_attributes (decl);
3445 inline_attribute (decl);
3446 prototyped_attribute (type);
3447 member_attribute (DECL_CONTEXT (decl));
3448 type_attribute (TREE_TYPE (type), 0, 0);
3449 pure_or_virtual_attribute (decl);
3451 if (DECL_ABSTRACT (decl))
3452 equate_decl_number_to_die_number (decl);
3453 else
3455 if (! DECL_EXTERNAL (decl) && ! in_class
3456 && decl == current_function_decl)
3458 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3460 low_pc_attribute (function_start_label (decl));
3461 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3462 high_pc_attribute (label);
3463 if (use_gnu_debug_info_extensions)
3465 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3466 body_begin_attribute (label);
3467 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3468 body_end_attribute (label);
3474 /* Output a DIE to represent a declared data object (either file-scope
3475 or block-local) which has "external linkage" (according to ANSI-C). */
3477 static void
3478 output_global_variable_die (arg)
3479 register void *arg;
3481 register tree decl = arg;
3482 register tree origin = decl_ultimate_origin (decl);
3484 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3485 sibling_attribute ();
3486 if (origin != NULL)
3487 abstract_origin_attribute (origin);
3488 else
3490 name_and_src_coords_attributes (decl);
3491 member_attribute (DECL_CONTEXT (decl));
3492 type_attribute (TREE_TYPE (decl),
3493 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3495 if (DECL_ABSTRACT (decl))
3496 equate_decl_number_to_die_number (decl);
3497 else
3499 if (! DECL_EXTERNAL (decl) && ! in_class
3500 && current_function_decl == decl_function_context (decl))
3501 location_or_const_value_attribute (decl);
3505 static void
3506 output_label_die (arg)
3507 register void *arg;
3509 register tree decl = arg;
3510 register tree origin = decl_ultimate_origin (decl);
3512 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3513 sibling_attribute ();
3514 if (origin != NULL)
3515 abstract_origin_attribute (origin);
3516 else
3517 name_and_src_coords_attributes (decl);
3518 if (DECL_ABSTRACT (decl))
3519 equate_decl_number_to_die_number (decl);
3520 else
3522 register rtx insn = DECL_RTL (decl);
3524 /* Deleted labels are programmer specified labels which have been
3525 eliminated because of various optimisations. We still emit them
3526 here so that it is possible to put breakpoints on them. */
3527 if (GET_CODE (insn) == CODE_LABEL
3528 || ((GET_CODE (insn) == NOTE
3529 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3531 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3533 /* When optimization is enabled (via -O) some parts of the compiler
3534 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3535 represent source-level labels which were explicitly declared by
3536 the user. This really shouldn't be happening though, so catch
3537 it if it ever does happen. */
3539 if (INSN_DELETED_P (insn))
3540 abort (); /* Should never happen. */
3542 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3543 (unsigned) INSN_UID (insn));
3544 low_pc_attribute (label);
3549 static void
3550 output_lexical_block_die (arg)
3551 register void *arg;
3553 register tree stmt = arg;
3555 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3556 sibling_attribute ();
3557 dienum_push ();
3558 if (! BLOCK_ABSTRACT (stmt))
3560 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3561 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3563 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3564 low_pc_attribute (begin_label);
3565 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3566 high_pc_attribute (end_label);
3570 static void
3571 output_inlined_subroutine_die (arg)
3572 register void *arg;
3574 register tree stmt = arg;
3576 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3577 sibling_attribute ();
3578 dienum_push ();
3579 abstract_origin_attribute (block_ultimate_origin (stmt));
3580 if (! BLOCK_ABSTRACT (stmt))
3582 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3583 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3585 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3586 low_pc_attribute (begin_label);
3587 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3588 high_pc_attribute (end_label);
3592 /* Output a DIE to represent a declared data object (either file-scope
3593 or block-local) which has "internal linkage" (according to ANSI-C). */
3595 static void
3596 output_local_variable_die (arg)
3597 register void *arg;
3599 register tree decl = arg;
3600 register tree origin = decl_ultimate_origin (decl);
3602 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3603 sibling_attribute ();
3604 if (origin != NULL)
3605 abstract_origin_attribute (origin);
3606 else
3608 name_and_src_coords_attributes (decl);
3609 member_attribute (DECL_CONTEXT (decl));
3610 type_attribute (TREE_TYPE (decl),
3611 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3613 if (DECL_ABSTRACT (decl))
3614 equate_decl_number_to_die_number (decl);
3615 else
3616 location_or_const_value_attribute (decl);
3619 static void
3620 output_member_die (arg)
3621 register void *arg;
3623 register tree decl = arg;
3625 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3626 sibling_attribute ();
3627 name_and_src_coords_attributes (decl);
3628 member_attribute (DECL_CONTEXT (decl));
3629 type_attribute (member_declared_type (decl),
3630 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3631 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3633 byte_size_attribute (decl);
3634 bit_size_attribute (decl);
3635 bit_offset_attribute (decl);
3637 data_member_location_attribute (decl);
3640 #if 0
3641 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3642 modified types instead.
3644 We keep this code here just in case these types of DIEs may be
3645 needed to represent certain things in other languages (e.g. Pascal)
3646 someday. */
3648 static void
3649 output_pointer_type_die (arg)
3650 register void *arg;
3652 register tree type = arg;
3654 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3655 sibling_attribute ();
3656 equate_type_number_to_die_number (type);
3657 member_attribute (TYPE_CONTEXT (type));
3658 type_attribute (TREE_TYPE (type), 0, 0);
3661 static void
3662 output_reference_type_die (arg)
3663 register void *arg;
3665 register tree type = arg;
3667 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3668 sibling_attribute ();
3669 equate_type_number_to_die_number (type);
3670 member_attribute (TYPE_CONTEXT (type));
3671 type_attribute (TREE_TYPE (type), 0, 0);
3673 #endif
3675 static void
3676 output_ptr_to_mbr_type_die (arg)
3677 register void *arg;
3679 register tree type = arg;
3681 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3682 sibling_attribute ();
3683 equate_type_number_to_die_number (type);
3684 member_attribute (TYPE_CONTEXT (type));
3685 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3686 type_attribute (TREE_TYPE (type), 0, 0);
3689 static void
3690 output_compile_unit_die (arg)
3691 register void *arg;
3693 register const char *main_input_filename = arg;
3695 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3696 sibling_attribute ();
3697 dienum_push ();
3698 name_attribute (main_input_filename);
3701 char producer[250];
3703 sprintf (producer, "%s %s", language_string, version_string);
3704 producer_attribute (producer);
3707 if (strcmp (language_string, "GNU C++") == 0)
3708 language_attribute (LANG_C_PLUS_PLUS);
3709 else if (strcmp (language_string, "GNU Ada") == 0)
3710 language_attribute (LANG_ADA83);
3711 else if (strcmp (language_string, "GNU F77") == 0)
3712 language_attribute (LANG_FORTRAN77);
3713 else if (strcmp (language_string, "GNU Pascal") == 0)
3714 language_attribute (LANG_PASCAL83);
3715 else if (flag_traditional)
3716 language_attribute (LANG_C);
3717 else
3718 language_attribute (LANG_C89);
3719 low_pc_attribute (TEXT_BEGIN_LABEL);
3720 high_pc_attribute (TEXT_END_LABEL);
3721 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3722 stmt_list_attribute (LINE_BEGIN_LABEL);
3723 last_filename = xstrdup (main_input_filename);
3726 const char *wd = getpwd ();
3727 if (wd)
3728 comp_dir_attribute (wd);
3731 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3733 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3734 src_info_attribute (SRCINFO_BEGIN_LABEL);
3735 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3736 mac_info_attribute (MACINFO_BEGIN_LABEL);
3740 static void
3741 output_string_type_die (arg)
3742 register void *arg;
3744 register tree type = arg;
3746 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3747 sibling_attribute ();
3748 equate_type_number_to_die_number (type);
3749 member_attribute (TYPE_CONTEXT (type));
3750 /* this is a fixed length string */
3751 byte_size_attribute (type);
3754 static void
3755 output_inheritance_die (arg)
3756 register void *arg;
3758 register tree binfo = arg;
3760 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3761 sibling_attribute ();
3762 type_attribute (BINFO_TYPE (binfo), 0, 0);
3763 data_member_location_attribute (binfo);
3764 if (TREE_VIA_VIRTUAL (binfo))
3766 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3767 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3769 if (TREE_VIA_PUBLIC (binfo))
3771 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3772 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3774 else if (TREE_VIA_PROTECTED (binfo))
3776 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3777 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3781 static void
3782 output_structure_type_die (arg)
3783 register void *arg;
3785 register tree type = arg;
3787 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3788 sibling_attribute ();
3789 equate_type_number_to_die_number (type);
3790 name_attribute (type_tag (type));
3791 member_attribute (TYPE_CONTEXT (type));
3793 /* If this type has been completed, then give it a byte_size attribute
3794 and prepare to give a list of members. Otherwise, don't do either of
3795 these things. In the latter case, we will not be generating a list
3796 of members (since we don't have any idea what they might be for an
3797 incomplete type). */
3799 if (COMPLETE_TYPE_P (type))
3801 dienum_push ();
3802 byte_size_attribute (type);
3806 /* Output a DIE to represent a declared function (either file-scope
3807 or block-local) which has "internal linkage" (according to ANSI-C). */
3809 static void
3810 output_local_subroutine_die (arg)
3811 register void *arg;
3813 register tree decl = arg;
3814 register tree origin = decl_ultimate_origin (decl);
3816 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3817 sibling_attribute ();
3818 dienum_push ();
3819 if (origin != NULL)
3820 abstract_origin_attribute (origin);
3821 else
3823 register tree type = TREE_TYPE (decl);
3825 name_and_src_coords_attributes (decl);
3826 inline_attribute (decl);
3827 prototyped_attribute (type);
3828 member_attribute (DECL_CONTEXT (decl));
3829 type_attribute (TREE_TYPE (type), 0, 0);
3830 pure_or_virtual_attribute (decl);
3832 if (DECL_ABSTRACT (decl))
3833 equate_decl_number_to_die_number (decl);
3834 else
3836 /* Avoid getting screwed up in cases where a function was declared
3837 static but where no definition was ever given for it. */
3839 if (TREE_ASM_WRITTEN (decl))
3841 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3842 low_pc_attribute (function_start_label (decl));
3843 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3844 high_pc_attribute (label);
3845 if (use_gnu_debug_info_extensions)
3847 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3848 body_begin_attribute (label);
3849 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3850 body_end_attribute (label);
3856 static void
3857 output_subroutine_type_die (arg)
3858 register void *arg;
3860 register tree type = arg;
3861 register tree return_type = TREE_TYPE (type);
3863 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3864 sibling_attribute ();
3865 dienum_push ();
3866 equate_type_number_to_die_number (type);
3867 prototyped_attribute (type);
3868 member_attribute (TYPE_CONTEXT (type));
3869 type_attribute (return_type, 0, 0);
3872 static void
3873 output_typedef_die (arg)
3874 register void *arg;
3876 register tree decl = arg;
3877 register tree origin = decl_ultimate_origin (decl);
3879 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3880 sibling_attribute ();
3881 if (origin != NULL)
3882 abstract_origin_attribute (origin);
3883 else
3885 name_and_src_coords_attributes (decl);
3886 member_attribute (DECL_CONTEXT (decl));
3887 type_attribute (TREE_TYPE (decl),
3888 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3890 if (DECL_ABSTRACT (decl))
3891 equate_decl_number_to_die_number (decl);
3894 static void
3895 output_union_type_die (arg)
3896 register void *arg;
3898 register tree type = arg;
3900 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3901 sibling_attribute ();
3902 equate_type_number_to_die_number (type);
3903 name_attribute (type_tag (type));
3904 member_attribute (TYPE_CONTEXT (type));
3906 /* If this type has been completed, then give it a byte_size attribute
3907 and prepare to give a list of members. Otherwise, don't do either of
3908 these things. In the latter case, we will not be generating a list
3909 of members (since we don't have any idea what they might be for an
3910 incomplete type). */
3912 if (COMPLETE_TYPE_P (type))
3914 dienum_push ();
3915 byte_size_attribute (type);
3919 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3920 at the end of an (ANSI prototyped) formal parameters list. */
3922 static void
3923 output_unspecified_parameters_die (arg)
3924 register void *arg;
3926 register tree decl_or_type = arg;
3928 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3929 sibling_attribute ();
3931 /* This kludge is here only for the sake of being compatible with what
3932 the USL CI5 C compiler does. The specification of Dwarf Version 1
3933 doesn't say that TAG_unspecified_parameters DIEs should contain any
3934 attributes other than the AT_sibling attribute, but they are certainly
3935 allowed to contain additional attributes, and the CI5 compiler
3936 generates AT_name, AT_fund_type, and AT_location attributes within
3937 TAG_unspecified_parameters DIEs which appear in the child lists for
3938 DIEs representing function definitions, so we do likewise here. */
3940 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3942 name_attribute ("...");
3943 fund_type_attribute (FT_pointer);
3944 /* location_attribute (?); */
3948 static void
3949 output_padded_null_die (arg)
3950 register void *arg ATTRIBUTE_UNUSED;
3952 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3955 /*************************** end of DIEs *********************************/
3957 /* Generate some type of DIE. This routine generates the generic outer
3958 wrapper stuff which goes around all types of DIE's (regardless of their
3959 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3960 DIE-length word, followed by the guts of the DIE itself. After the guts
3961 of the DIE, there must always be a terminator label for the DIE. */
3963 static void
3964 output_die (die_specific_output_function, param)
3965 register void (*die_specific_output_function) PARAMS ((void *));
3966 register void *param;
3968 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3969 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3971 current_dienum = NEXT_DIE_NUM;
3972 NEXT_DIE_NUM = next_unused_dienum;
3974 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3975 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3977 /* Write a label which will act as the name for the start of this DIE. */
3979 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3981 /* Write the DIE-length word. */
3983 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3985 /* Fill in the guts of the DIE. */
3987 next_unused_dienum++;
3988 die_specific_output_function (param);
3990 /* Write a label which will act as the name for the end of this DIE. */
3992 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3995 static void
3996 end_sibling_chain ()
3998 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
4000 current_dienum = NEXT_DIE_NUM;
4001 NEXT_DIE_NUM = next_unused_dienum;
4003 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4005 /* Write a label which will act as the name for the start of this DIE. */
4007 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4009 /* Write the DIE-length word. */
4011 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4013 dienum_pop ();
4016 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4017 TAG_unspecified_parameters DIE) to represent the types of the formal
4018 parameters as specified in some function type specification (except
4019 for those which appear as part of a function *definition*).
4021 Note that we must be careful here to output all of the parameter
4022 DIEs *before* we output any DIEs needed to represent the types of
4023 the formal parameters. This keeps svr4 SDB happy because it
4024 (incorrectly) thinks that the first non-parameter DIE it sees ends
4025 the formal parameter list. */
4027 static void
4028 output_formal_types (function_or_method_type)
4029 register tree function_or_method_type;
4031 register tree link;
4032 register tree formal_type = NULL;
4033 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4035 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4036 get bogus recursion when outputting tagged types local to a
4037 function declaration. */
4038 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4039 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4041 /* In the case where we are generating a formal types list for a C++
4042 non-static member function type, skip over the first thing on the
4043 TYPE_ARG_TYPES list because it only represents the type of the
4044 hidden `this pointer'. The debugger should be able to figure
4045 out (without being explicitly told) that this non-static member
4046 function type takes a `this pointer' and should be able to figure
4047 what the type of that hidden parameter is from the AT_member
4048 attribute of the parent TAG_subroutine_type DIE. */
4050 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4051 first_parm_type = TREE_CHAIN (first_parm_type);
4053 /* Make our first pass over the list of formal parameter types and output
4054 a TAG_formal_parameter DIE for each one. */
4056 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4058 formal_type = TREE_VALUE (link);
4059 if (formal_type == void_type_node)
4060 break;
4062 /* Output a (nameless) DIE to represent the formal parameter itself. */
4064 output_die (output_formal_parameter_die, formal_type);
4067 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4068 DIE to the end of the parameter list. */
4070 if (formal_type != void_type_node)
4071 output_die (output_unspecified_parameters_die, function_or_method_type);
4073 /* Make our second (and final) pass over the list of formal parameter types
4074 and output DIEs to represent those types (as necessary). */
4076 for (link = TYPE_ARG_TYPES (function_or_method_type);
4077 link;
4078 link = TREE_CHAIN (link))
4080 formal_type = TREE_VALUE (link);
4081 if (formal_type == void_type_node)
4082 break;
4084 output_type (formal_type, function_or_method_type);
4087 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4090 /* Remember a type in the pending_types_list. */
4092 static void
4093 pend_type (type)
4094 register tree type;
4096 if (pending_types == pending_types_allocated)
4098 pending_types_allocated += PENDING_TYPES_INCREMENT;
4099 pending_types_list
4100 = (tree *) xrealloc (pending_types_list,
4101 sizeof (tree) * pending_types_allocated);
4103 pending_types_list[pending_types++] = type;
4105 /* Mark the pending type as having been output already (even though
4106 it hasn't been). This prevents the type from being added to the
4107 pending_types_list more than once. */
4109 TREE_ASM_WRITTEN (type) = 1;
4112 /* Return non-zero if it is legitimate to output DIEs to represent a
4113 given type while we are generating the list of child DIEs for some
4114 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4116 See the comments within the function for a description of when it is
4117 considered legitimate to output DIEs for various kinds of types.
4119 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4120 or it may point to a BLOCK node (for types local to a block), or to a
4121 FUNCTION_DECL node (for types local to the heading of some function
4122 definition), or to a FUNCTION_TYPE node (for types local to the
4123 prototyped parameter list of a function type specification), or to a
4124 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4125 (in the case of C++ nested types).
4127 The `scope' parameter should likewise be NULL or should point to a
4128 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4129 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4131 This function is used only for deciding when to "pend" and when to
4132 "un-pend" types to/from the pending_types_list.
4134 Note that we sometimes make use of this "type pending" feature in a
4135 rather twisted way to temporarily delay the production of DIEs for the
4136 types of formal parameters. (We do this just to make svr4 SDB happy.)
4137 It order to delay the production of DIEs representing types of formal
4138 parameters, callers of this function supply `fake_containing_scope' as
4139 the `scope' parameter to this function. Given that fake_containing_scope
4140 is a tagged type which is *not* the containing scope for *any* other type,
4141 the desired effect is achieved, i.e. output of DIEs representing types
4142 is temporarily suspended, and any type DIEs which would have otherwise
4143 been output are instead placed onto the pending_types_list. Later on,
4144 we force these (temporarily pended) types to be output simply by calling
4145 `output_pending_types_for_scope' with an actual argument equal to the
4146 true scope of the types we temporarily pended. */
4148 static inline int
4149 type_ok_for_scope (type, scope)
4150 register tree type;
4151 register tree scope;
4153 /* Tagged types (i.e. struct, union, and enum types) must always be
4154 output only in the scopes where they actually belong (or else the
4155 scoping of their own tag names and the scoping of their member
4156 names will be incorrect). Non-tagged-types on the other hand can
4157 generally be output anywhere, except that svr4 SDB really doesn't
4158 want to see them nested within struct or union types, so here we
4159 say it is always OK to immediately output any such a (non-tagged)
4160 type, so long as we are not within such a context. Note that the
4161 only kinds of non-tagged types which we will be dealing with here
4162 (for C and C++ anyway) will be array types and function types. */
4164 return is_tagged_type (type)
4165 ? (TYPE_CONTEXT (type) == scope
4166 /* Ignore namespaces for the moment. */
4167 || (scope == NULL_TREE
4168 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4169 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4170 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4171 : (scope == NULL_TREE || ! is_tagged_type (scope));
4174 /* Output any pending types (from the pending_types list) which we can output
4175 now (taking into account the scope that we are working on now).
4177 For each type output, remove the given type from the pending_types_list
4178 *before* we try to output it.
4180 Note that we have to process the list in beginning-to-end order,
4181 because the call made here to output_type may cause yet more types
4182 to be added to the end of the list, and we may have to output some
4183 of them too. */
4185 static void
4186 output_pending_types_for_scope (containing_scope)
4187 register tree containing_scope;
4189 register unsigned i;
4191 for (i = 0; i < pending_types; )
4193 register tree type = pending_types_list[i];
4195 if (type_ok_for_scope (type, containing_scope))
4197 register tree *mover;
4198 register tree *limit;
4200 pending_types--;
4201 limit = &pending_types_list[pending_types];
4202 for (mover = &pending_types_list[i]; mover < limit; mover++)
4203 *mover = *(mover+1);
4205 /* Un-mark the type as having been output already (because it
4206 hasn't been, really). Then call output_type to generate a
4207 Dwarf representation of it. */
4209 TREE_ASM_WRITTEN (type) = 0;
4210 output_type (type, containing_scope);
4212 /* Don't increment the loop counter in this case because we
4213 have shifted all of the subsequent pending types down one
4214 element in the pending_types_list array. */
4216 else
4217 i++;
4221 /* Remember a type in the incomplete_types_list. */
4223 static void
4224 add_incomplete_type (type)
4225 tree type;
4227 if (incomplete_types == incomplete_types_allocated)
4229 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4230 incomplete_types_list
4231 = (tree *) xrealloc (incomplete_types_list,
4232 sizeof (tree) * incomplete_types_allocated);
4235 incomplete_types_list[incomplete_types++] = type;
4238 /* Walk through the list of incomplete types again, trying once more to
4239 emit full debugging info for them. */
4241 static void
4242 retry_incomplete_types ()
4244 register tree type;
4246 finalizing = 1;
4247 while (incomplete_types)
4249 --incomplete_types;
4250 type = incomplete_types_list[incomplete_types];
4251 output_type (type, NULL_TREE);
4255 static void
4256 output_type (type, containing_scope)
4257 register tree type;
4258 register tree containing_scope;
4260 if (type == 0 || type == error_mark_node)
4261 return;
4263 /* We are going to output a DIE to represent the unqualified version of
4264 this type (i.e. without any const or volatile qualifiers) so get
4265 the main variant (i.e. the unqualified version) of this type now. */
4267 type = type_main_variant (type);
4269 if (TREE_ASM_WRITTEN (type))
4271 if (finalizing && AGGREGATE_TYPE_P (type))
4273 register tree member;
4275 /* Some of our nested types might not have been defined when we
4276 were written out before; force them out now. */
4278 for (member = TYPE_FIELDS (type); member;
4279 member = TREE_CHAIN (member))
4280 if (TREE_CODE (member) == TYPE_DECL
4281 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4282 output_type (TREE_TYPE (member), containing_scope);
4284 return;
4287 /* If this is a nested type whose containing class hasn't been
4288 written out yet, writing it out will cover this one, too. */
4290 if (TYPE_CONTEXT (type)
4291 && TYPE_P (TYPE_CONTEXT (type))
4292 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4294 output_type (TYPE_CONTEXT (type), containing_scope);
4295 return;
4298 /* Don't generate any DIEs for this type now unless it is OK to do so
4299 (based upon what `type_ok_for_scope' tells us). */
4301 if (! type_ok_for_scope (type, containing_scope))
4303 pend_type (type);
4304 return;
4307 switch (TREE_CODE (type))
4309 case ERROR_MARK:
4310 break;
4312 case VECTOR_TYPE:
4313 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4314 break;
4316 case POINTER_TYPE:
4317 case REFERENCE_TYPE:
4318 /* Prevent infinite recursion in cases where this is a recursive
4319 type. Recursive types are possible in Ada. */
4320 TREE_ASM_WRITTEN (type) = 1;
4321 /* For these types, all that is required is that we output a DIE
4322 (or a set of DIEs) to represent the "basis" type. */
4323 output_type (TREE_TYPE (type), containing_scope);
4324 break;
4326 case OFFSET_TYPE:
4327 /* This code is used for C++ pointer-to-data-member types. */
4328 /* Output a description of the relevant class type. */
4329 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4330 /* Output a description of the type of the object pointed to. */
4331 output_type (TREE_TYPE (type), containing_scope);
4332 /* Now output a DIE to represent this pointer-to-data-member type
4333 itself. */
4334 output_die (output_ptr_to_mbr_type_die, type);
4335 break;
4337 case SET_TYPE:
4338 output_type (TYPE_DOMAIN (type), containing_scope);
4339 output_die (output_set_type_die, type);
4340 break;
4342 case FILE_TYPE:
4343 output_type (TREE_TYPE (type), containing_scope);
4344 abort (); /* No way to represent these in Dwarf yet! */
4345 break;
4347 case FUNCTION_TYPE:
4348 /* Force out return type (in case it wasn't forced out already). */
4349 output_type (TREE_TYPE (type), containing_scope);
4350 output_die (output_subroutine_type_die, type);
4351 output_formal_types (type);
4352 end_sibling_chain ();
4353 break;
4355 case METHOD_TYPE:
4356 /* Force out return type (in case it wasn't forced out already). */
4357 output_type (TREE_TYPE (type), containing_scope);
4358 output_die (output_subroutine_type_die, type);
4359 output_formal_types (type);
4360 end_sibling_chain ();
4361 break;
4363 case ARRAY_TYPE:
4364 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4366 output_type (TREE_TYPE (type), containing_scope);
4367 output_die (output_string_type_die, type);
4369 else
4371 register tree element_type;
4373 element_type = TREE_TYPE (type);
4374 while (TREE_CODE (element_type) == ARRAY_TYPE)
4375 element_type = TREE_TYPE (element_type);
4377 output_type (element_type, containing_scope);
4378 output_die (output_array_type_die, type);
4380 break;
4382 case ENUMERAL_TYPE:
4383 case RECORD_TYPE:
4384 case UNION_TYPE:
4385 case QUAL_UNION_TYPE:
4387 /* For a non-file-scope tagged type, we can always go ahead and
4388 output a Dwarf description of this type right now, even if
4389 the type in question is still incomplete, because if this
4390 local type *was* ever completed anywhere within its scope,
4391 that complete definition would already have been attached to
4392 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4393 node by the time we reach this point. That's true because of the
4394 way the front-end does its processing of file-scope declarations (of
4395 functions and class types) within which other types might be
4396 nested. The C and C++ front-ends always gobble up such "local
4397 scope" things en-mass before they try to output *any* debugging
4398 information for any of the stuff contained inside them and thus,
4399 we get the benefit here of what is (in effect) a pre-resolution
4400 of forward references to tagged types in local scopes.
4402 Note however that for file-scope tagged types we cannot assume
4403 that such pre-resolution of forward references has taken place.
4404 A given file-scope tagged type may appear to be incomplete when
4405 we reach this point, but it may yet be given a full definition
4406 (at file-scope) later on during compilation. In order to avoid
4407 generating a premature (and possibly incorrect) set of Dwarf
4408 DIEs for such (as yet incomplete) file-scope tagged types, we
4409 generate nothing at all for as-yet incomplete file-scope tagged
4410 types here unless we are making our special "finalization" pass
4411 for file-scope things at the very end of compilation. At that
4412 time, we will certainly know as much about each file-scope tagged
4413 type as we are ever going to know, so at that point in time, we
4414 can safely generate correct Dwarf descriptions for these file-
4415 scope tagged types. */
4417 if (!COMPLETE_TYPE_P (type)
4418 && (TYPE_CONTEXT (type) == NULL
4419 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4420 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4421 && !finalizing)
4423 /* We don't need to do this for function-local types. */
4424 if (! decl_function_context (TYPE_STUB_DECL (type)))
4425 add_incomplete_type (type);
4426 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4429 /* Prevent infinite recursion in cases where the type of some
4430 member of this type is expressed in terms of this type itself. */
4432 TREE_ASM_WRITTEN (type) = 1;
4434 /* Output a DIE to represent the tagged type itself. */
4436 switch (TREE_CODE (type))
4438 case ENUMERAL_TYPE:
4439 output_die (output_enumeration_type_die, type);
4440 return; /* a special case -- nothing left to do so just return */
4442 case RECORD_TYPE:
4443 output_die (output_structure_type_die, type);
4444 break;
4446 case UNION_TYPE:
4447 case QUAL_UNION_TYPE:
4448 output_die (output_union_type_die, type);
4449 break;
4451 default:
4452 abort (); /* Should never happen. */
4455 /* If this is not an incomplete type, output descriptions of
4456 each of its members.
4458 Note that as we output the DIEs necessary to represent the
4459 members of this record or union type, we will also be trying
4460 to output DIEs to represent the *types* of those members.
4461 However the `output_type' function (above) will specifically
4462 avoid generating type DIEs for member types *within* the list
4463 of member DIEs for this (containing) type execpt for those
4464 types (of members) which are explicitly marked as also being
4465 members of this (containing) type themselves. The g++ front-
4466 end can force any given type to be treated as a member of some
4467 other (containing) type by setting the TYPE_CONTEXT of the
4468 given (member) type to point to the TREE node representing the
4469 appropriate (containing) type.
4472 if (COMPLETE_TYPE_P (type))
4474 /* First output info about the base classes. */
4475 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4477 register tree bases = TYPE_BINFO_BASETYPES (type);
4478 register int n_bases = TREE_VEC_LENGTH (bases);
4479 register int i;
4481 for (i = 0; i < n_bases; i++)
4483 tree binfo = TREE_VEC_ELT (bases, i);
4484 output_type (BINFO_TYPE (binfo), containing_scope);
4485 output_die (output_inheritance_die, binfo);
4489 ++in_class;
4492 register tree normal_member;
4494 /* Now output info about the data members and type members. */
4496 for (normal_member = TYPE_FIELDS (type);
4497 normal_member;
4498 normal_member = TREE_CHAIN (normal_member))
4499 output_decl (normal_member, type);
4503 register tree func_member;
4505 /* Now output info about the function members (if any). */
4507 for (func_member = TYPE_METHODS (type);
4508 func_member;
4509 func_member = TREE_CHAIN (func_member))
4510 output_decl (func_member, type);
4513 --in_class;
4515 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4516 scopes (at least in C++) so we must now output any nested
4517 pending types which are local just to this type. */
4519 output_pending_types_for_scope (type);
4521 end_sibling_chain (); /* Terminate member chain. */
4524 break;
4526 case VOID_TYPE:
4527 case INTEGER_TYPE:
4528 case REAL_TYPE:
4529 case COMPLEX_TYPE:
4530 case BOOLEAN_TYPE:
4531 case CHAR_TYPE:
4532 break; /* No DIEs needed for fundamental types. */
4534 case LANG_TYPE: /* No Dwarf representation currently defined. */
4535 break;
4537 default:
4538 abort ();
4541 TREE_ASM_WRITTEN (type) = 1;
4544 static void
4545 output_tagged_type_instantiation (type)
4546 register tree type;
4548 if (type == 0 || type == error_mark_node)
4549 return;
4551 /* We are going to output a DIE to represent the unqualified version of
4552 this type (i.e. without any const or volatile qualifiers) so make
4553 sure that we have the main variant (i.e. the unqualified version) of
4554 this type now. */
4556 if (type != type_main_variant (type))
4557 abort ();
4559 if (!TREE_ASM_WRITTEN (type))
4560 abort ();
4562 switch (TREE_CODE (type))
4564 case ERROR_MARK:
4565 break;
4567 case ENUMERAL_TYPE:
4568 output_die (output_inlined_enumeration_type_die, type);
4569 break;
4571 case RECORD_TYPE:
4572 output_die (output_inlined_structure_type_die, type);
4573 break;
4575 case UNION_TYPE:
4576 case QUAL_UNION_TYPE:
4577 output_die (output_inlined_union_type_die, type);
4578 break;
4580 default:
4581 abort (); /* Should never happen. */
4585 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4586 the things which are local to the given block. */
4588 static void
4589 output_block (stmt, depth)
4590 register tree stmt;
4591 int depth;
4593 register int must_output_die = 0;
4594 register tree origin;
4595 register enum tree_code origin_code;
4597 /* Ignore blocks never really used to make RTL. */
4599 if (! stmt || ! TREE_USED (stmt)
4600 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
4601 return;
4603 /* Determine the "ultimate origin" of this block. This block may be an
4604 inlined instance of an inlined instance of inline function, so we
4605 have to trace all of the way back through the origin chain to find
4606 out what sort of node actually served as the original seed for the
4607 creation of the current block. */
4609 origin = block_ultimate_origin (stmt);
4610 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4612 /* Determine if we need to output any Dwarf DIEs at all to represent this
4613 block. */
4615 if (origin_code == FUNCTION_DECL)
4616 /* The outer scopes for inlinings *must* always be represented. We
4617 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4618 must_output_die = 1;
4619 else
4621 /* In the case where the current block represents an inlining of the
4622 "body block" of an inline function, we must *NOT* output any DIE
4623 for this block because we have already output a DIE to represent
4624 the whole inlined function scope and the "body block" of any
4625 function doesn't really represent a different scope according to
4626 ANSI C rules. So we check here to make sure that this block does
4627 not represent a "body block inlining" before trying to set the
4628 `must_output_die' flag. */
4630 if (! is_body_block (origin ? origin : stmt))
4632 /* Determine if this block directly contains any "significant"
4633 local declarations which we will need to output DIEs for. */
4635 if (debug_info_level > DINFO_LEVEL_TERSE)
4636 /* We are not in terse mode so *any* local declaration counts
4637 as being a "significant" one. */
4638 must_output_die = (BLOCK_VARS (stmt) != NULL);
4639 else
4641 register tree decl;
4643 /* We are in terse mode, so only local (nested) function
4644 definitions count as "significant" local declarations. */
4646 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4647 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4649 must_output_die = 1;
4650 break;
4656 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4657 DIE for any block which contains no significant local declarations
4658 at all. Rather, in such cases we just call `output_decls_for_scope'
4659 so that any needed Dwarf info for any sub-blocks will get properly
4660 generated. Note that in terse mode, our definition of what constitutes
4661 a "significant" local declaration gets restricted to include only
4662 inlined function instances and local (nested) function definitions. */
4664 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4665 /* We don't care about an abstract inlined subroutine. */;
4666 else if (must_output_die)
4668 output_die ((origin_code == FUNCTION_DECL)
4669 ? output_inlined_subroutine_die
4670 : output_lexical_block_die,
4671 stmt);
4672 output_decls_for_scope (stmt, depth);
4673 end_sibling_chain ();
4675 else
4676 output_decls_for_scope (stmt, depth);
4679 /* Output all of the decls declared within a given scope (also called
4680 a `binding contour') and (recursively) all of it's sub-blocks. */
4682 static void
4683 output_decls_for_scope (stmt, depth)
4684 register tree stmt;
4685 int depth;
4687 /* Ignore blocks never really used to make RTL. */
4689 if (! stmt || ! TREE_USED (stmt))
4690 return;
4692 /* Output the DIEs to represent all of the data objects, functions,
4693 typedefs, and tagged types declared directly within this block
4694 but not within any nested sub-blocks. */
4697 register tree decl;
4699 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4700 output_decl (decl, stmt);
4703 output_pending_types_for_scope (stmt);
4705 /* Output the DIEs to represent all sub-blocks (and the items declared
4706 therein) of this block. */
4709 register tree subblocks;
4711 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4712 subblocks;
4713 subblocks = BLOCK_CHAIN (subblocks))
4714 output_block (subblocks, depth + 1);
4718 /* Is this a typedef we can avoid emitting? */
4720 inline static int
4721 is_redundant_typedef (decl)
4722 register tree decl;
4724 if (TYPE_DECL_IS_STUB (decl))
4725 return 1;
4726 if (DECL_ARTIFICIAL (decl)
4727 && DECL_CONTEXT (decl)
4728 && is_tagged_type (DECL_CONTEXT (decl))
4729 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4730 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4731 /* Also ignore the artificial member typedef for the class name. */
4732 return 1;
4733 return 0;
4736 /* Output Dwarf .debug information for a decl described by DECL. */
4738 static void
4739 output_decl (decl, containing_scope)
4740 register tree decl;
4741 register tree containing_scope;
4743 /* Make a note of the decl node we are going to be working on. We may
4744 need to give the user the source coordinates of where it appeared in
4745 case we notice (later on) that something about it looks screwy. */
4747 dwarf_last_decl = decl;
4749 if (TREE_CODE (decl) == ERROR_MARK)
4750 return;
4752 /* If a structure is declared within an initialization, e.g. as the
4753 operand of a sizeof, then it will not have a name. We don't want
4754 to output a DIE for it, as the tree nodes are in the temporary obstack */
4756 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4757 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4758 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4759 || (TYPE_FIELDS (TREE_TYPE (decl))
4760 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4761 return;
4763 /* If this ..._DECL node is marked to be ignored, then ignore it. */
4765 if (DECL_IGNORED_P (decl))
4766 return;
4768 switch (TREE_CODE (decl))
4770 case CONST_DECL:
4771 /* The individual enumerators of an enum type get output when we
4772 output the Dwarf representation of the relevant enum type itself. */
4773 break;
4775 case FUNCTION_DECL:
4776 /* If we are in terse mode, don't output any DIEs to represent
4777 mere function declarations. Also, if we are conforming
4778 to the DWARF version 1 specification, don't output DIEs for
4779 mere function declarations. */
4781 if (DECL_INITIAL (decl) == NULL_TREE)
4782 #if (DWARF_VERSION > 1)
4783 if (debug_info_level <= DINFO_LEVEL_TERSE)
4784 #endif
4785 break;
4787 /* Before we describe the FUNCTION_DECL itself, make sure that we
4788 have described its return type. */
4790 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4793 /* And its containing type. */
4794 register tree origin = decl_class_context (decl);
4795 if (origin)
4796 output_type (origin, containing_scope);
4799 /* If we're emitting an out-of-line copy of an inline function,
4800 set up to refer to the abstract instance emitted from
4801 note_deferral_of_defined_inline_function. */
4802 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
4803 && ! (containing_scope && TYPE_P (containing_scope)))
4804 set_decl_origin_self (decl);
4806 /* If the following DIE will represent a function definition for a
4807 function with "extern" linkage, output a special "pubnames" DIE
4808 label just ahead of the actual DIE. A reference to this label
4809 was already generated in the .debug_pubnames section sub-entry
4810 for this function definition. */
4812 if (TREE_PUBLIC (decl))
4814 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4816 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4817 ASM_OUTPUT_LABEL (asm_out_file, label);
4820 /* Now output a DIE to represent the function itself. */
4822 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4823 ? output_global_subroutine_die
4824 : output_local_subroutine_die,
4825 decl);
4827 /* Now output descriptions of the arguments for this function.
4828 This gets (unnecessarily?) complex because of the fact that
4829 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4830 cases where there was a trailing `...' at the end of the formal
4831 parameter list. In order to find out if there was a trailing
4832 ellipsis or not, we must instead look at the type associated
4833 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4834 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4835 ends with a void_type_node then there should *not* be an ellipsis
4836 at the end. */
4838 /* In the case where we are describing a mere function declaration, all
4839 we need to do here (and all we *can* do here) is to describe
4840 the *types* of its formal parameters. */
4842 if (decl != current_function_decl || in_class)
4843 output_formal_types (TREE_TYPE (decl));
4844 else
4846 /* Generate DIEs to represent all known formal parameters */
4848 register tree arg_decls = DECL_ARGUMENTS (decl);
4849 register tree parm;
4851 /* WARNING! Kludge zone ahead! Here we have a special
4852 hack for svr4 SDB compatibility. Instead of passing the
4853 current FUNCTION_DECL node as the second parameter (i.e.
4854 the `containing_scope' parameter) to `output_decl' (as
4855 we ought to) we instead pass a pointer to our own private
4856 fake_containing_scope node. That node is a RECORD_TYPE
4857 node which NO OTHER TYPE may ever actually be a member of.
4859 This pointer will ultimately get passed into `output_type'
4860 as its `containing_scope' parameter. `Output_type' will
4861 then perform its part in the hack... i.e. it will pend
4862 the type of the formal parameter onto the pending_types
4863 list. Later on, when we are done generating the whole
4864 sequence of formal parameter DIEs for this function
4865 definition, we will un-pend all previously pended types
4866 of formal parameters for this function definition.
4868 This whole kludge prevents any type DIEs from being
4869 mixed in with the formal parameter DIEs. That's good
4870 because svr4 SDB believes that the list of formal
4871 parameter DIEs for a function ends wherever the first
4872 non-formal-parameter DIE appears. Thus, we have to
4873 keep the formal parameter DIEs segregated. They must
4874 all appear (consecutively) at the start of the list of
4875 children for the DIE representing the function definition.
4876 Then (and only then) may we output any additional DIEs
4877 needed to represent the types of these formal parameters.
4881 When generating DIEs, generate the unspecified_parameters
4882 DIE instead if we come across the arg "__builtin_va_alist"
4885 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4886 if (TREE_CODE (parm) == PARM_DECL)
4888 if (DECL_NAME(parm) &&
4889 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4890 "__builtin_va_alist") )
4891 output_die (output_unspecified_parameters_die, decl);
4892 else
4893 output_decl (parm, fake_containing_scope);
4897 Now that we have finished generating all of the DIEs to
4898 represent the formal parameters themselves, force out
4899 any DIEs needed to represent their types. We do this
4900 simply by un-pending all previously pended types which
4901 can legitimately go into the chain of children DIEs for
4902 the current FUNCTION_DECL.
4905 output_pending_types_for_scope (decl);
4908 Decide whether we need a unspecified_parameters DIE at the end.
4909 There are 2 more cases to do this for:
4910 1) the ansi ... declaration - this is detectable when the end
4911 of the arg list is not a void_type_node
4912 2) an unprototyped function declaration (not a definition). This
4913 just means that we have no info about the parameters at all.
4917 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4919 if (fn_arg_types)
4921 /* this is the prototyped case, check for ... */
4922 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4923 output_die (output_unspecified_parameters_die, decl);
4925 else
4927 /* this is unprototyped, check for undefined (just declaration) */
4928 if (!DECL_INITIAL (decl))
4929 output_die (output_unspecified_parameters_die, decl);
4933 /* Output Dwarf info for all of the stuff within the body of the
4934 function (if it has one - it may be just a declaration). */
4937 register tree outer_scope = DECL_INITIAL (decl);
4939 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4941 /* Note that here, `outer_scope' is a pointer to the outermost
4942 BLOCK node created to represent a function.
4943 This outermost BLOCK actually represents the outermost
4944 binding contour for the function, i.e. the contour in which
4945 the function's formal parameters and labels get declared.
4947 Curiously, it appears that the front end doesn't actually
4948 put the PARM_DECL nodes for the current function onto the
4949 BLOCK_VARS list for this outer scope. (They are strung
4950 off of the DECL_ARGUMENTS list for the function instead.)
4951 The BLOCK_VARS list for the `outer_scope' does provide us
4952 with a list of the LABEL_DECL nodes for the function however,
4953 and we output DWARF info for those here.
4955 Just within the `outer_scope' there will be a BLOCK node
4956 representing the function's outermost pair of curly braces,
4957 and any blocks used for the base and member initializers of
4958 a C++ constructor function. */
4960 output_decls_for_scope (outer_scope, 0);
4962 /* Finally, force out any pending types which are local to the
4963 outermost block of this function definition. These will
4964 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4965 node itself. */
4967 output_pending_types_for_scope (decl);
4972 /* Generate a terminator for the list of stuff `owned' by this
4973 function. */
4975 end_sibling_chain ();
4977 break;
4979 case TYPE_DECL:
4980 /* If we are in terse mode, don't generate any DIEs to represent
4981 any actual typedefs. Note that even when we are in terse mode,
4982 we must still output DIEs to represent those tagged types which
4983 are used (directly or indirectly) in the specification of either
4984 a return type or a formal parameter type of some function. */
4986 if (debug_info_level <= DINFO_LEVEL_TERSE)
4987 if (! TYPE_DECL_IS_STUB (decl)
4988 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4989 return;
4991 /* In the special case of a TYPE_DECL node representing
4992 the declaration of some type tag, if the given TYPE_DECL is
4993 marked as having been instantiated from some other (original)
4994 TYPE_DECL node (e.g. one which was generated within the original
4995 definition of an inline function) we have to generate a special
4996 (abbreviated) TAG_structure_type, TAG_union_type, or
4997 TAG_enumeration-type DIE here. */
4999 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
5001 output_tagged_type_instantiation (TREE_TYPE (decl));
5002 return;
5005 output_type (TREE_TYPE (decl), containing_scope);
5007 if (! is_redundant_typedef (decl))
5008 /* Output a DIE to represent the typedef itself. */
5009 output_die (output_typedef_die, decl);
5010 break;
5012 case LABEL_DECL:
5013 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5014 output_die (output_label_die, decl);
5015 break;
5017 case VAR_DECL:
5018 /* If we are conforming to the DWARF version 1 specification, don't
5019 generated any DIEs to represent mere external object declarations. */
5021 #if (DWARF_VERSION <= 1)
5022 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5023 break;
5024 #endif
5026 /* If we are in terse mode, don't generate any DIEs to represent
5027 any variable declarations or definitions. */
5029 if (debug_info_level <= DINFO_LEVEL_TERSE)
5030 break;
5032 /* Output any DIEs that are needed to specify the type of this data
5033 object. */
5035 output_type (TREE_TYPE (decl), containing_scope);
5038 /* And its containing type. */
5039 register tree origin = decl_class_context (decl);
5040 if (origin)
5041 output_type (origin, containing_scope);
5044 /* If the following DIE will represent a data object definition for a
5045 data object with "extern" linkage, output a special "pubnames" DIE
5046 label just ahead of the actual DIE. A reference to this label
5047 was already generated in the .debug_pubnames section sub-entry
5048 for this data object definition. */
5050 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5052 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5054 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5055 ASM_OUTPUT_LABEL (asm_out_file, label);
5058 /* Now output the DIE to represent the data object itself. This gets
5059 complicated because of the possibility that the VAR_DECL really
5060 represents an inlined instance of a formal parameter for an inline
5061 function. */
5064 register void (*func) PARAMS ((void *));
5065 register tree origin = decl_ultimate_origin (decl);
5067 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5068 func = output_formal_parameter_die;
5069 else
5071 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5072 func = output_global_variable_die;
5073 else
5074 func = output_local_variable_die;
5076 output_die (func, decl);
5078 break;
5080 case FIELD_DECL:
5081 /* Ignore the nameless fields that are used to skip bits. */
5082 if (DECL_NAME (decl) != 0)
5084 output_type (member_declared_type (decl), containing_scope);
5085 output_die (output_member_die, decl);
5087 break;
5089 case PARM_DECL:
5090 /* Force out the type of this formal, if it was not forced out yet.
5091 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5092 It should be able to grok the presence of type DIEs within a list
5093 of TAG_formal_parameter DIEs, but it doesn't. */
5095 output_type (TREE_TYPE (decl), containing_scope);
5096 output_die (output_formal_parameter_die, decl);
5097 break;
5099 case NAMESPACE_DECL:
5100 /* Ignore for now. */
5101 break;
5103 default:
5104 abort ();
5108 void
5109 dwarfout_file_scope_decl (decl, set_finalizing)
5110 register tree decl;
5111 register int set_finalizing;
5113 if (TREE_CODE (decl) == ERROR_MARK)
5114 return;
5116 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5118 if (DECL_IGNORED_P (decl))
5119 return;
5121 switch (TREE_CODE (decl))
5123 case FUNCTION_DECL:
5125 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5126 a builtin function. Explicit programmer-supplied declarations of
5127 these same functions should NOT be ignored however. */
5129 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5130 return;
5132 /* What we would really like to do here is to filter out all mere
5133 file-scope declarations of file-scope functions which are never
5134 referenced later within this translation unit (and keep all of
5135 ones that *are* referenced later on) but we aren't clairvoyant,
5136 so we have no idea which functions will be referenced in the
5137 future (i.e. later on within the current translation unit).
5138 So here we just ignore all file-scope function declarations
5139 which are not also definitions. If and when the debugger needs
5140 to know something about these functions, it wil have to hunt
5141 around and find the DWARF information associated with the
5142 *definition* of the function.
5144 Note that we can't just check `DECL_EXTERNAL' to find out which
5145 FUNCTION_DECL nodes represent definitions and which ones represent
5146 mere declarations. We have to check `DECL_INITIAL' instead. That's
5147 because the C front-end supports some weird semantics for "extern
5148 inline" function definitions. These can get inlined within the
5149 current translation unit (an thus, we need to generate DWARF info
5150 for their abstract instances so that the DWARF info for the
5151 concrete inlined instances can have something to refer to) but
5152 the compiler never generates any out-of-lines instances of such
5153 things (despite the fact that they *are* definitions). The
5154 important point is that the C front-end marks these "extern inline"
5155 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5156 anyway.
5158 Note that the C++ front-end also plays some similar games for inline
5159 function definitions appearing within include files which also
5160 contain `#pragma interface' pragmas. */
5162 if (DECL_INITIAL (decl) == NULL_TREE)
5163 return;
5165 if (TREE_PUBLIC (decl)
5166 && ! DECL_EXTERNAL (decl)
5167 && ! DECL_ABSTRACT (decl))
5169 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5171 /* Output a .debug_pubnames entry for a public function
5172 defined in this compilation unit. */
5174 fputc ('\n', asm_out_file);
5175 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5176 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5177 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5178 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5179 IDENTIFIER_POINTER (DECL_NAME (decl)));
5180 ASM_OUTPUT_POP_SECTION (asm_out_file);
5183 break;
5185 case VAR_DECL:
5187 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5188 object declaration and if the declaration was never even
5189 referenced from within this entire compilation unit. We
5190 suppress these DIEs in order to save space in the .debug section
5191 (by eliminating entries which are probably useless). Note that
5192 we must not suppress block-local extern declarations (whether
5193 used or not) because that would screw-up the debugger's name
5194 lookup mechanism and cause it to miss things which really ought
5195 to be in scope at a given point. */
5197 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5198 return;
5200 if (TREE_PUBLIC (decl)
5201 && ! DECL_EXTERNAL (decl)
5202 && GET_CODE (DECL_RTL (decl)) == MEM
5203 && ! DECL_ABSTRACT (decl))
5205 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5207 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5209 /* Output a .debug_pubnames entry for a public variable
5210 defined in this compilation unit. */
5212 fputc ('\n', asm_out_file);
5213 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5214 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5215 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5216 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5217 IDENTIFIER_POINTER (DECL_NAME (decl)));
5218 ASM_OUTPUT_POP_SECTION (asm_out_file);
5221 if (DECL_INITIAL (decl) == NULL)
5223 /* Output a .debug_aranges entry for a public variable
5224 which is tentatively defined in this compilation unit. */
5226 fputc ('\n', asm_out_file);
5227 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5228 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5229 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5230 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5231 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5232 ASM_OUTPUT_POP_SECTION (asm_out_file);
5236 /* If we are in terse mode, don't generate any DIEs to represent
5237 any variable declarations or definitions. */
5239 if (debug_info_level <= DINFO_LEVEL_TERSE)
5240 return;
5242 break;
5244 case TYPE_DECL:
5245 /* Don't bother trying to generate any DIEs to represent any of the
5246 normal built-in types for the language we are compiling, except
5247 in cases where the types in question are *not* DWARF fundamental
5248 types. We make an exception in the case of non-fundamental types
5249 for the sake of objective C (and perhaps C++) because the GNU
5250 front-ends for these languages may in fact create certain "built-in"
5251 types which are (for example) RECORD_TYPEs. In such cases, we
5252 really need to output these (non-fundamental) types because other
5253 DIEs may contain references to them. */
5255 /* Also ignore language dependent types here, because they are probably
5256 also built-in types. If we didn't ignore them, then we would get
5257 references to undefined labels because output_type doesn't support
5258 them. So, for now, we need to ignore them to avoid assembler
5259 errors. */
5261 /* ??? This code is different than the equivalent code in dwarf2out.c.
5262 The dwarf2out.c code is probably more correct. */
5264 if (DECL_SOURCE_LINE (decl) == 0
5265 && (type_is_fundamental (TREE_TYPE (decl))
5266 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5267 return;
5269 /* If we are in terse mode, don't generate any DIEs to represent
5270 any actual typedefs. Note that even when we are in terse mode,
5271 we must still output DIEs to represent those tagged types which
5272 are used (directly or indirectly) in the specification of either
5273 a return type or a formal parameter type of some function. */
5275 if (debug_info_level <= DINFO_LEVEL_TERSE)
5276 if (! TYPE_DECL_IS_STUB (decl)
5277 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5278 return;
5280 break;
5282 default:
5283 return;
5286 fputc ('\n', asm_out_file);
5287 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5288 finalizing = set_finalizing;
5289 output_decl (decl, NULL_TREE);
5291 /* NOTE: The call above to `output_decl' may have caused one or more
5292 file-scope named types (i.e. tagged types) to be placed onto the
5293 pending_types_list. We have to get those types off of that list
5294 at some point, and this is the perfect time to do it. If we didn't
5295 take them off now, they might still be on the list when cc1 finally
5296 exits. That might be OK if it weren't for the fact that when we put
5297 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5298 for these types, and that causes them never to be output unless
5299 `output_pending_types_for_scope' takes them off of the list and un-sets
5300 their TREE_ASM_WRITTEN flags. */
5302 output_pending_types_for_scope (NULL_TREE);
5304 /* The above call should have totally emptied the pending_types_list
5305 if this is not a nested function or class. If this is a nested type,
5306 then the remaining pending_types will be emitted when the containing type
5307 is handled. */
5309 if (! DECL_CONTEXT (decl))
5311 if (pending_types != 0)
5312 abort ();
5315 ASM_OUTPUT_POP_SECTION (asm_out_file);
5317 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5318 current_funcdef_number++;
5321 /* Output a marker (i.e. a label) for the beginning of the generated code
5322 for a lexical block. */
5324 void
5325 dwarfout_begin_block (blocknum)
5326 register unsigned blocknum;
5328 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5330 function_section (current_function_decl);
5331 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5332 ASM_OUTPUT_LABEL (asm_out_file, label);
5335 /* Output a marker (i.e. a label) for the end of the generated code
5336 for a lexical block. */
5338 void
5339 dwarfout_end_block (blocknum)
5340 register unsigned blocknum;
5342 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5344 function_section (current_function_decl);
5345 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5346 ASM_OUTPUT_LABEL (asm_out_file, label);
5349 /* Output a marker (i.e. a label) at a point in the assembly code which
5350 corresponds to a given source level label. */
5352 void
5353 dwarfout_label (insn)
5354 register rtx insn;
5356 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5358 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5360 function_section (current_function_decl);
5361 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5362 (unsigned) INSN_UID (insn));
5363 ASM_OUTPUT_LABEL (asm_out_file, label);
5367 /* Output a marker (i.e. a label) for the point in the generated code where
5368 the real body of the function begins (after parameters have been moved
5369 to their home locations). */
5371 void
5372 dwarfout_begin_function ()
5374 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5376 if (! use_gnu_debug_info_extensions)
5377 return;
5378 function_section (current_function_decl);
5379 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5380 ASM_OUTPUT_LABEL (asm_out_file, label);
5383 /* Output a marker (i.e. a label) for the point in the generated code where
5384 the real body of the function ends (just before the epilogue code). */
5386 void
5387 dwarfout_end_function ()
5389 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5391 if (! use_gnu_debug_info_extensions)
5392 return;
5393 function_section (current_function_decl);
5394 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5395 ASM_OUTPUT_LABEL (asm_out_file, label);
5398 /* Output a marker (i.e. a label) for the absolute end of the generated code
5399 for a function definition. This gets called *after* the epilogue code
5400 has been generated. */
5402 void
5403 dwarfout_end_epilogue ()
5405 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5407 /* Output a label to mark the endpoint of the code generated for this
5408 function. */
5410 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5411 ASM_OUTPUT_LABEL (asm_out_file, label);
5414 static void
5415 shuffle_filename_entry (new_zeroth)
5416 register filename_entry *new_zeroth;
5418 filename_entry temp_entry;
5419 register filename_entry *limit_p;
5420 register filename_entry *move_p;
5422 if (new_zeroth == &filename_table[0])
5423 return;
5425 temp_entry = *new_zeroth;
5427 /* Shift entries up in the table to make room at [0]. */
5429 limit_p = &filename_table[0];
5430 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5431 *move_p = *(move_p-1);
5433 /* Install the found entry at [0]. */
5435 filename_table[0] = temp_entry;
5438 /* Create a new (string) entry for the .debug_sfnames section. */
5440 static void
5441 generate_new_sfname_entry ()
5443 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5445 fputc ('\n', asm_out_file);
5446 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5447 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5448 ASM_OUTPUT_LABEL (asm_out_file, label);
5449 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5450 filename_table[0].name
5451 ? filename_table[0].name
5452 : "");
5453 ASM_OUTPUT_POP_SECTION (asm_out_file);
5456 /* Lookup a filename (in the list of filenames that we know about here in
5457 dwarfout.c) and return its "index". The index of each (known) filename
5458 is just a unique number which is associated with only that one filename.
5459 We need such numbers for the sake of generating labels (in the
5460 .debug_sfnames section) and references to those unique labels (in the
5461 .debug_srcinfo and .debug_macinfo sections).
5463 If the filename given as an argument is not found in our current list,
5464 add it to the list and assign it the next available unique index number.
5466 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5467 one), we shuffle the filename found (or added) up to the zeroth entry of
5468 our list of filenames (which is always searched linearly). We do this so
5469 as to optimize the most common case for these filename lookups within
5470 dwarfout.c. The most common case by far is the case where we call
5471 lookup_filename to lookup the very same filename that we did a lookup
5472 on the last time we called lookup_filename. We make sure that this
5473 common case is fast because such cases will constitute 99.9% of the
5474 lookups we ever do (in practice).
5476 If we add a new filename entry to our table, we go ahead and generate
5477 the corresponding entry in the .debug_sfnames section right away.
5478 Doing so allows us to avoid tickling an assembler bug (present in some
5479 m68k assemblers) which yields assembly-time errors in cases where the
5480 difference of two label addresses is taken and where the two labels
5481 are in a section *other* than the one where the difference is being
5482 calculated, and where at least one of the two symbol references is a
5483 forward reference. (This bug could be tickled by our .debug_srcinfo
5484 entries if we don't output their corresponding .debug_sfnames entries
5485 before them.) */
5487 static unsigned
5488 lookup_filename (file_name)
5489 const char *file_name;
5491 register filename_entry *search_p;
5492 register filename_entry *limit_p = &filename_table[ft_entries];
5494 for (search_p = filename_table; search_p < limit_p; search_p++)
5495 if (!strcmp (file_name, search_p->name))
5497 /* When we get here, we have found the filename that we were
5498 looking for in the filename_table. Now we want to make sure
5499 that it gets moved to the zero'th entry in the table (if it
5500 is not already there) so that subsequent attempts to find the
5501 same filename will find it as quickly as possible. */
5503 shuffle_filename_entry (search_p);
5504 return filename_table[0].number;
5507 /* We come here whenever we have a new filename which is not registered
5508 in the current table. Here we add it to the table. */
5510 /* Prepare to add a new table entry by making sure there is enough space
5511 in the table to do so. If not, expand the current table. */
5513 if (ft_entries == ft_entries_allocated)
5515 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5516 filename_table
5517 = (filename_entry *)
5518 xrealloc (filename_table,
5519 ft_entries_allocated * sizeof (filename_entry));
5522 /* Initially, add the new entry at the end of the filename table. */
5524 filename_table[ft_entries].number = ft_entries;
5525 filename_table[ft_entries].name = xstrdup (file_name);
5527 /* Shuffle the new entry into filename_table[0]. */
5529 shuffle_filename_entry (&filename_table[ft_entries]);
5531 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5532 generate_new_sfname_entry ();
5534 ft_entries++;
5535 return filename_table[0].number;
5538 static void
5539 generate_srcinfo_entry (line_entry_num, files_entry_num)
5540 unsigned line_entry_num;
5541 unsigned files_entry_num;
5543 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5545 fputc ('\n', asm_out_file);
5546 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5547 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5548 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5549 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5550 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5551 ASM_OUTPUT_POP_SECTION (asm_out_file);
5554 void
5555 dwarfout_line (filename, line)
5556 register const char *filename;
5557 register unsigned line;
5559 if (debug_info_level >= DINFO_LEVEL_NORMAL
5560 /* We can't emit line number info for functions in separate sections,
5561 because the assembler can't subtract labels in different sections. */
5562 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5564 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5565 static unsigned last_line_entry_num = 0;
5566 static unsigned prev_file_entry_num = (unsigned) -1;
5567 register unsigned this_file_entry_num;
5569 function_section (current_function_decl);
5570 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5571 ASM_OUTPUT_LABEL (asm_out_file, label);
5573 fputc ('\n', asm_out_file);
5575 if (use_gnu_debug_info_extensions)
5576 this_file_entry_num = lookup_filename (filename);
5577 else
5578 this_file_entry_num = (unsigned) -1;
5580 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5581 if (this_file_entry_num != prev_file_entry_num)
5583 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5585 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5586 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5590 register const char *tail = rindex (filename, '/');
5592 if (tail != NULL)
5593 filename = tail;
5596 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5597 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5598 filename, line);
5599 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5600 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5601 ASM_OUTPUT_POP_SECTION (asm_out_file);
5603 if (this_file_entry_num != prev_file_entry_num)
5604 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5605 prev_file_entry_num = this_file_entry_num;
5609 /* Generate an entry in the .debug_macinfo section. */
5611 static void
5612 generate_macinfo_entry (type_and_offset, string)
5613 register const char *type_and_offset;
5614 register const char *string;
5616 if (! use_gnu_debug_info_extensions)
5617 return;
5619 fputc ('\n', asm_out_file);
5620 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5621 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5622 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
5623 ASM_OUTPUT_POP_SECTION (asm_out_file);
5626 void
5627 dwarfout_start_new_source_file (filename)
5628 register const char *filename;
5630 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5631 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5633 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5634 sprintf (type_and_offset, "0x%08x+%s-%s",
5635 ((unsigned) MACINFO_start << 24),
5636 /* Hack: skip leading '*' . */
5637 (*label == '*') + label,
5638 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5639 generate_macinfo_entry (type_and_offset, "");
5642 void
5643 dwarfout_resume_previous_source_file (lineno)
5644 register unsigned lineno;
5646 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5648 sprintf (type_and_offset, "0x%08x+%u",
5649 ((unsigned) MACINFO_resume << 24), lineno);
5650 generate_macinfo_entry (type_and_offset, "");
5653 /* Called from check_newline in c-parse.y. The `buffer' parameter
5654 contains the tail part of the directive line, i.e. the part which
5655 is past the initial whitespace, #, whitespace, directive-name,
5656 whitespace part. */
5658 void
5659 dwarfout_define (lineno, buffer)
5660 register unsigned lineno;
5661 register const char *buffer;
5663 static int initialized = 0;
5664 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5666 if (!initialized)
5668 dwarfout_start_new_source_file (primary_filename);
5669 initialized = 1;
5671 sprintf (type_and_offset, "0x%08x+%u",
5672 ((unsigned) MACINFO_define << 24), lineno);
5673 generate_macinfo_entry (type_and_offset, buffer);
5676 /* Called from check_newline in c-parse.y. The `buffer' parameter
5677 contains the tail part of the directive line, i.e. the part which
5678 is past the initial whitespace, #, whitespace, directive-name,
5679 whitespace part. */
5681 void
5682 dwarfout_undef (lineno, buffer)
5683 register unsigned lineno;
5684 register const char *buffer;
5686 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5688 sprintf (type_and_offset, "0x%08x+%u",
5689 ((unsigned) MACINFO_undef << 24), lineno);
5690 generate_macinfo_entry (type_and_offset, buffer);
5693 /* Set up for Dwarf output at the start of compilation. */
5695 void
5696 dwarfout_init (asm_out_file, main_input_filename)
5697 register FILE *asm_out_file;
5698 register const char *main_input_filename;
5700 /* Remember the name of the primary input file. */
5702 primary_filename = main_input_filename;
5704 /* Allocate the initial hunk of the pending_sibling_stack. */
5706 pending_sibling_stack
5707 = (unsigned *)
5708 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5709 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5710 pending_siblings = 1;
5712 /* Allocate the initial hunk of the filename_table. */
5714 filename_table
5715 = (filename_entry *)
5716 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5717 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5718 ft_entries = 0;
5720 /* Allocate the initial hunk of the pending_types_list. */
5722 pending_types_list
5723 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5724 pending_types_allocated = PENDING_TYPES_INCREMENT;
5725 pending_types = 0;
5727 /* Create an artificial RECORD_TYPE node which we can use in our hack
5728 to get the DIEs representing types of formal parameters to come out
5729 only *after* the DIEs for the formal parameters themselves. */
5731 fake_containing_scope = make_node (RECORD_TYPE);
5733 /* Output a starting label for the .text section. */
5735 fputc ('\n', asm_out_file);
5736 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5737 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5738 ASM_OUTPUT_POP_SECTION (asm_out_file);
5740 /* Output a starting label for the .data section. */
5742 fputc ('\n', asm_out_file);
5743 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5744 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5745 ASM_OUTPUT_POP_SECTION (asm_out_file);
5747 #if 0 /* GNU C doesn't currently use .data1. */
5748 /* Output a starting label for the .data1 section. */
5750 fputc ('\n', asm_out_file);
5751 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5752 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5753 ASM_OUTPUT_POP_SECTION (asm_out_file);
5754 #endif
5756 /* Output a starting label for the .rodata section. */
5758 fputc ('\n', asm_out_file);
5759 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5760 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5761 ASM_OUTPUT_POP_SECTION (asm_out_file);
5763 #if 0 /* GNU C doesn't currently use .rodata1. */
5764 /* Output a starting label for the .rodata1 section. */
5766 fputc ('\n', asm_out_file);
5767 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5768 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5769 ASM_OUTPUT_POP_SECTION (asm_out_file);
5770 #endif
5772 /* Output a starting label for the .bss section. */
5774 fputc ('\n', asm_out_file);
5775 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5776 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5777 ASM_OUTPUT_POP_SECTION (asm_out_file);
5779 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5781 if (use_gnu_debug_info_extensions)
5783 /* Output a starting label and an initial (compilation directory)
5784 entry for the .debug_sfnames section. The starting label will be
5785 referenced by the initial entry in the .debug_srcinfo section. */
5787 fputc ('\n', asm_out_file);
5788 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5789 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5791 register const char *pwd = getpwd ();
5792 register char *dirname;
5794 if (!pwd)
5795 pfatal_with_name ("getpwd");
5796 dirname = concat (pwd, "/", NULL);
5797 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
5798 free (dirname);
5800 ASM_OUTPUT_POP_SECTION (asm_out_file);
5803 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5804 && use_gnu_debug_info_extensions)
5806 /* Output a starting label for the .debug_macinfo section. This
5807 label will be referenced by the AT_mac_info attribute in the
5808 TAG_compile_unit DIE. */
5810 fputc ('\n', asm_out_file);
5811 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5812 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5813 ASM_OUTPUT_POP_SECTION (asm_out_file);
5816 /* Generate the initial entry for the .line section. */
5818 fputc ('\n', asm_out_file);
5819 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5820 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5821 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5822 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5823 ASM_OUTPUT_POP_SECTION (asm_out_file);
5825 if (use_gnu_debug_info_extensions)
5827 /* Generate the initial entry for the .debug_srcinfo section. */
5829 fputc ('\n', asm_out_file);
5830 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5831 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5832 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5833 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5834 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5835 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5836 #ifdef DWARF_TIMESTAMPS
5837 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5838 #else
5839 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5840 #endif
5841 ASM_OUTPUT_POP_SECTION (asm_out_file);
5844 /* Generate the initial entry for the .debug_pubnames section. */
5846 fputc ('\n', asm_out_file);
5847 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5848 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5849 ASM_OUTPUT_POP_SECTION (asm_out_file);
5851 /* Generate the initial entry for the .debug_aranges section. */
5853 fputc ('\n', asm_out_file);
5854 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5855 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5856 ASM_OUTPUT_POP_SECTION (asm_out_file);
5859 /* Setup first DIE number == 1. */
5860 NEXT_DIE_NUM = next_unused_dienum++;
5862 /* Generate the initial DIE for the .debug section. Note that the
5863 (string) value given in the AT_name attribute of the TAG_compile_unit
5864 DIE will (typically) be a relative pathname and that this pathname
5865 should be taken as being relative to the directory from which the
5866 compiler was invoked when the given (base) source file was compiled. */
5868 fputc ('\n', asm_out_file);
5869 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5870 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5871 output_die (output_compile_unit_die, main_input_filename);
5872 ASM_OUTPUT_POP_SECTION (asm_out_file);
5874 fputc ('\n', asm_out_file);
5877 /* Output stuff that dwarf requires at the end of every file. */
5879 void
5880 dwarfout_finish ()
5882 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5884 fputc ('\n', asm_out_file);
5885 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5886 retry_incomplete_types ();
5887 fputc ('\n', asm_out_file);
5889 /* Mark the end of the chain of siblings which represent all file-scope
5890 declarations in this compilation unit. */
5892 /* The (null) DIE which represents the terminator for the (sibling linked)
5893 list of file-scope items is *special*. Normally, we would just call
5894 end_sibling_chain at this point in order to output a word with the
5895 value `4' and that word would act as the terminator for the list of
5896 DIEs describing file-scope items. Unfortunately, if we were to simply
5897 do that, the label that would follow this DIE in the .debug section
5898 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5899 machines) to a 4 byte boundary.
5901 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5902 the trick used is to insert extra (otherwise useless) padding bytes
5903 into the (null) DIE that we know must precede the ..D2 label in the
5904 .debug section. The amount of padding required can be anywhere between
5905 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5906 with the padding) would normally contain the value 4, but now it will
5907 also have to include the padding bytes, so it will instead have some
5908 value in the range 4..7.
5910 Fortunately, the rules of Dwarf say that any DIE whose length word
5911 contains *any* value less than 8 should be treated as a null DIE, so
5912 this trick works out nicely. Clever, eh? Don't give me any credit
5913 (or blame). I didn't think of this scheme. I just conformed to it.
5916 output_die (output_padded_null_die, (void *) 0);
5917 dienum_pop ();
5919 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5920 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5921 ASM_OUTPUT_POP_SECTION (asm_out_file);
5923 /* Output a terminator label for the .text section. */
5925 fputc ('\n', asm_out_file);
5926 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5927 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5928 ASM_OUTPUT_POP_SECTION (asm_out_file);
5930 /* Output a terminator label for the .data section. */
5932 fputc ('\n', asm_out_file);
5933 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5934 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5935 ASM_OUTPUT_POP_SECTION (asm_out_file);
5937 #if 0 /* GNU C doesn't currently use .data1. */
5938 /* Output a terminator label for the .data1 section. */
5940 fputc ('\n', asm_out_file);
5941 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5942 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5943 ASM_OUTPUT_POP_SECTION (asm_out_file);
5944 #endif
5946 /* Output a terminator label for the .rodata section. */
5948 fputc ('\n', asm_out_file);
5949 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5950 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5951 ASM_OUTPUT_POP_SECTION (asm_out_file);
5953 #if 0 /* GNU C doesn't currently use .rodata1. */
5954 /* Output a terminator label for the .rodata1 section. */
5956 fputc ('\n', asm_out_file);
5957 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5958 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5959 ASM_OUTPUT_POP_SECTION (asm_out_file);
5960 #endif
5962 /* Output a terminator label for the .bss section. */
5964 fputc ('\n', asm_out_file);
5965 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5966 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5967 ASM_OUTPUT_POP_SECTION (asm_out_file);
5969 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5971 /* Output a terminating entry for the .line section. */
5973 fputc ('\n', asm_out_file);
5974 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5975 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5976 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5977 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5978 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5979 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5980 ASM_OUTPUT_POP_SECTION (asm_out_file);
5982 if (use_gnu_debug_info_extensions)
5984 /* Output a terminating entry for the .debug_srcinfo section. */
5986 fputc ('\n', asm_out_file);
5987 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5988 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5989 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5990 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5991 ASM_OUTPUT_POP_SECTION (asm_out_file);
5994 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5996 /* Output terminating entries for the .debug_macinfo section. */
5998 dwarfout_resume_previous_source_file (0);
6000 fputc ('\n', asm_out_file);
6001 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
6002 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6003 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6004 ASM_OUTPUT_POP_SECTION (asm_out_file);
6007 /* Generate the terminating entry for the .debug_pubnames section. */
6009 fputc ('\n', asm_out_file);
6010 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
6011 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6012 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6013 ASM_OUTPUT_POP_SECTION (asm_out_file);
6015 /* Generate the terminating entries for the .debug_aranges section.
6017 Note that we want to do this only *after* we have output the end
6018 labels (for the various program sections) which we are going to
6019 refer to here. This allows us to work around a bug in the m68k
6020 svr4 assembler. That assembler gives bogus assembly-time errors
6021 if (within any given section) you try to take the difference of
6022 two relocatable symbols, both of which are located within some
6023 other section, and if one (or both?) of the symbols involved is
6024 being forward-referenced. By generating the .debug_aranges
6025 entries at this late point in the assembly output, we skirt the
6026 issue simply by avoiding forward-references.
6029 fputc ('\n', asm_out_file);
6030 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
6032 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6033 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6035 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6036 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6038 #if 0 /* GNU C doesn't currently use .data1. */
6039 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6040 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6041 DATA1_BEGIN_LABEL);
6042 #endif
6044 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6045 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6046 RODATA_BEGIN_LABEL);
6048 #if 0 /* GNU C doesn't currently use .rodata1. */
6049 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6050 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6051 RODATA1_BEGIN_LABEL);
6052 #endif
6054 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6055 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6057 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6058 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6060 ASM_OUTPUT_POP_SECTION (asm_out_file);
6063 /* There should not be any pending types left at the end. We need
6064 this now because it may not have been checked on the last call to
6065 dwarfout_file_scope_decl. */
6066 if (pending_types != 0)
6067 abort ();
6070 #endif /* DWARF_DEBUGGING_INFO */