Add movdi pattern to FR30 port.
[official-gcc.git] / gcc / dwarfout.c
blob32e056900ab09bd406e25493b30c12aaa8d28511
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 #if defined(DWARF_TIMESTAMPS)
41 #if !defined(POSIX)
42 extern time_t time PARAMS ((time_t *)); /* FIXME: use NEED_DECLARATION_TIME */
43 #endif /* !defined(POSIX) */
44 #endif /* defined(DWARF_TIMESTAMPS) */
46 /* We cannot use <assert.h> in GCC source, since that would include
47 GCC's assert.h, which may not be compatible with the host compiler. */
48 #undef assert
49 #ifdef NDEBUG
50 # define assert(e)
51 #else
52 # define assert(e) do { if (! (e)) abort (); } while (0)
53 #endif
55 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
56 regarding the GNU implementation of Dwarf. */
58 /* NOTE: In the comments in this file, many references are made to
59 so called "Debugging Information Entries". For the sake of brevity,
60 this term is abbreviated to `DIE' throughout the remainder of this
61 file. */
63 /* Note that the implementation of C++ support herein is (as yet) unfinished.
64 If you want to try to complete it, more power to you. */
66 /* How to start an assembler comment. */
67 #ifndef ASM_COMMENT_START
68 #define ASM_COMMENT_START ";#"
69 #endif
71 /* How to print out a register name. */
72 #ifndef PRINT_REG
73 #define PRINT_REG(RTX, CODE, FILE) \
74 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
75 #endif
77 /* Define a macro which returns non-zero for any tagged type which is
78 used (directly or indirectly) in the specification of either some
79 function's return type or some formal parameter of some function.
80 We use this macro when we are operating in "terse" mode to help us
81 know what tagged types have to be represented in Dwarf (even in
82 terse mode) and which ones don't.
84 A flag bit with this meaning really should be a part of the normal
85 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
86 for these nodes. For now, we have to just fake it. It it safe for
87 us to simply return zero for all complete tagged types (which will
88 get forced out anyway if they were used in the specification of some
89 formal or return type) and non-zero for all incomplete tagged types.
92 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
94 /* Define a macro which returns non-zero for a TYPE_DECL which was
95 implicitly generated for a tagged type.
97 Note that unlike the gcc front end (which generates a NULL named
98 TYPE_DECL node for each complete tagged type, each array type, and
99 each function type node created) the g++ front end generates a
100 _named_ TYPE_DECL node for each tagged type node created.
101 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
102 generate a DW_TAG_typedef DIE for them. */
103 #define TYPE_DECL_IS_STUB(decl) \
104 (DECL_NAME (decl) == NULL \
105 || (DECL_ARTIFICIAL (decl) \
106 && is_tagged_type (TREE_TYPE (decl)) \
107 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
109 extern int flag_traditional;
111 /* Maximum size (in bytes) of an artificially generated label. */
113 #define MAX_ARTIFICIAL_LABEL_BYTES 30
115 /* Make sure we know the sizes of the various types dwarf can describe.
116 These are only defaults. If the sizes are different for your target,
117 you should override these values by defining the appropriate symbols
118 in your tm.h file. */
120 #ifndef CHAR_TYPE_SIZE
121 #define CHAR_TYPE_SIZE BITS_PER_UNIT
122 #endif
124 #ifndef SHORT_TYPE_SIZE
125 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
126 #endif
128 #ifndef INT_TYPE_SIZE
129 #define INT_TYPE_SIZE BITS_PER_WORD
130 #endif
132 #ifndef LONG_TYPE_SIZE
133 #define LONG_TYPE_SIZE BITS_PER_WORD
134 #endif
136 #ifndef LONG_LONG_TYPE_SIZE
137 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
138 #endif
140 #ifndef WCHAR_TYPE_SIZE
141 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
142 #endif
144 #ifndef WCHAR_UNSIGNED
145 #define WCHAR_UNSIGNED 0
146 #endif
148 #ifndef FLOAT_TYPE_SIZE
149 #define FLOAT_TYPE_SIZE BITS_PER_WORD
150 #endif
152 #ifndef DOUBLE_TYPE_SIZE
153 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
154 #endif
156 #ifndef LONG_DOUBLE_TYPE_SIZE
157 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
158 #endif
160 /* Structure to keep track of source filenames. */
162 struct filename_entry {
163 unsigned number;
164 const char * name;
167 typedef struct filename_entry filename_entry;
169 /* Pointer to an array of elements, each one having the structure above. */
171 static filename_entry *filename_table;
173 /* Total number of entries in the table (i.e. array) pointed to by
174 `filename_table'. This is the *total* and includes both used and
175 unused slots. */
177 static unsigned ft_entries_allocated;
179 /* Number of entries in the filename_table which are actually in use. */
181 static unsigned ft_entries;
183 /* Size (in elements) of increments by which we may expand the filename
184 table. Actually, a single hunk of space of this size should be enough
185 for most typical programs. */
187 #define FT_ENTRIES_INCREMENT 64
189 /* Local pointer to the name of the main input file. Initialized in
190 dwarfout_init. */
192 static const char *primary_filename;
194 /* Pointer to the most recent filename for which we produced some line info. */
196 static const char *last_filename;
198 /* Counter to generate unique names for DIEs. */
200 static unsigned next_unused_dienum = 1;
202 /* Number of the DIE which is currently being generated. */
204 static unsigned current_dienum;
206 /* Number to use for the special "pubname" label on the next DIE which
207 represents a function or data object defined in this compilation
208 unit which has "extern" linkage. */
210 static int next_pubname_number = 0;
212 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
214 /* Pointer to a dynamically allocated list of pre-reserved and still
215 pending sibling DIE numbers. Note that this list will grow as needed. */
217 static unsigned *pending_sibling_stack;
219 /* Counter to keep track of the number of pre-reserved and still pending
220 sibling DIE numbers. */
222 static unsigned pending_siblings;
224 /* The currently allocated size of the above list (expressed in number of
225 list elements). */
227 static unsigned pending_siblings_allocated;
229 /* Size (in elements) of increments by which we may expand the pending
230 sibling stack. Actually, a single hunk of space of this size should
231 be enough for most typical programs. */
233 #define PENDING_SIBLINGS_INCREMENT 64
235 /* Non-zero if we are performing our file-scope finalization pass and if
236 we should force out Dwarf descriptions of any and all file-scope
237 tagged types which are still incomplete types. */
239 static int finalizing = 0;
241 /* A pointer to the base of a list of pending types which we haven't
242 generated DIEs for yet, but which we will have to come back to
243 later on. */
245 static tree *pending_types_list;
247 /* Number of elements currently allocated for the pending_types_list. */
249 static unsigned pending_types_allocated;
251 /* Number of elements of pending_types_list currently in use. */
253 static unsigned pending_types;
255 /* Size (in elements) of increments by which we may expand the pending
256 types list. Actually, a single hunk of space of this size should
257 be enough for most typical programs. */
259 #define PENDING_TYPES_INCREMENT 64
261 /* A pointer to the base of a list of incomplete types which might be
262 completed at some later time. */
264 static tree *incomplete_types_list;
266 /* Number of elements currently allocated for the incomplete_types_list. */
267 static unsigned incomplete_types_allocated;
269 /* Number of elements of incomplete_types_list currently in use. */
270 static unsigned incomplete_types;
272 /* Size (in elements) of increments by which we may expand the incomplete
273 types list. Actually, a single hunk of space of this size should
274 be enough for most typical programs. */
275 #define INCOMPLETE_TYPES_INCREMENT 64
277 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
278 This is used in a hack to help us get the DIEs describing types of
279 formal parameters to come *after* all of the DIEs describing the formal
280 parameters themselves. That's necessary in order to be compatible
281 with what the brain-damaged svr4 SDB debugger requires. */
283 static tree fake_containing_scope;
285 /* The number of the current function definition that we are generating
286 debugging information for. These numbers range from 1 up to the maximum
287 number of function definitions contained within the current compilation
288 unit. These numbers are used to create unique labels for various things
289 contained within various function definitions. */
291 static unsigned current_funcdef_number = 1;
293 /* A pointer to the ..._DECL node which we have most recently been working
294 on. We keep this around just in case something about it looks screwy
295 and we want to tell the user what the source coordinates for the actual
296 declaration are. */
298 static tree dwarf_last_decl;
300 /* A flag indicating that we are emitting the member declarations of a
301 class, so member functions and variables should not be entirely emitted.
302 This is a kludge to avoid passing a second argument to output_*_die. */
304 static int in_class;
306 /* Forward declarations for functions defined in this file. */
308 static const char *dwarf_tag_name PARAMS ((unsigned));
309 static const char *dwarf_attr_name PARAMS ((unsigned));
310 static const char *dwarf_stack_op_name PARAMS ((unsigned));
311 static const char *dwarf_typemod_name PARAMS ((unsigned));
312 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
313 static const char *dwarf_fund_type_name PARAMS ((unsigned));
314 static tree decl_ultimate_origin PARAMS ((tree));
315 static tree block_ultimate_origin PARAMS ((tree));
316 static tree decl_class_context PARAMS ((tree));
317 #if 0
318 static void output_unsigned_leb128 PARAMS ((unsigned long));
319 static void output_signed_leb128 PARAMS ((long));
320 #endif
321 static int fundamental_type_code PARAMS ((tree));
322 static tree root_type_1 PARAMS ((tree, int));
323 static tree root_type PARAMS ((tree));
324 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
325 static void write_modifier_bytes PARAMS ((tree, int, int));
326 static inline int type_is_fundamental PARAMS ((tree));
327 static void equate_decl_number_to_die_number PARAMS ((tree));
328 static inline void equate_type_number_to_die_number PARAMS ((tree));
329 static void output_reg_number PARAMS ((rtx));
330 static void output_mem_loc_descriptor PARAMS ((rtx));
331 static void output_loc_descriptor PARAMS ((rtx));
332 static void output_bound_representation PARAMS ((tree, unsigned, int));
333 static void output_enumeral_list PARAMS ((tree));
334 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
335 static inline tree field_type PARAMS ((tree));
336 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
337 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
338 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
339 static inline void sibling_attribute PARAMS ((void));
340 static void location_attribute PARAMS ((rtx));
341 static void data_member_location_attribute PARAMS ((tree));
342 static void const_value_attribute PARAMS ((rtx));
343 static void location_or_const_value_attribute PARAMS ((tree));
344 static inline void name_attribute PARAMS ((const char *));
345 static inline void fund_type_attribute PARAMS ((unsigned));
346 static void mod_fund_type_attribute PARAMS ((tree, int, int));
347 static inline void user_def_type_attribute PARAMS ((tree));
348 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
349 #ifdef USE_ORDERING_ATTRIBUTE
350 static inline void ordering_attribute PARAMS ((unsigned));
351 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
352 static void subscript_data_attribute PARAMS ((tree));
353 static void byte_size_attribute PARAMS ((tree));
354 static inline void bit_offset_attribute PARAMS ((tree));
355 static inline void bit_size_attribute PARAMS ((tree));
356 static inline void element_list_attribute PARAMS ((tree));
357 static inline void stmt_list_attribute PARAMS ((const char *));
358 static inline void low_pc_attribute PARAMS ((const char *));
359 static inline void high_pc_attribute PARAMS ((const char *));
360 static inline void body_begin_attribute PARAMS ((const char *));
361 static inline void body_end_attribute PARAMS ((const char *));
362 static inline void language_attribute PARAMS ((unsigned));
363 static inline void member_attribute PARAMS ((tree));
364 #if 0
365 static inline void string_length_attribute PARAMS ((tree));
366 #endif
367 static inline void comp_dir_attribute PARAMS ((const char *));
368 static inline void sf_names_attribute PARAMS ((const char *));
369 static inline void src_info_attribute PARAMS ((const char *));
370 static inline void mac_info_attribute PARAMS ((const char *));
371 static inline void prototyped_attribute PARAMS ((tree));
372 static inline void producer_attribute PARAMS ((const char *));
373 static inline void inline_attribute PARAMS ((tree));
374 static inline void containing_type_attribute PARAMS ((tree));
375 static inline void abstract_origin_attribute PARAMS ((tree));
376 #ifdef DWARF_DECL_COORDINATES
377 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
378 #endif /* defined(DWARF_DECL_COORDINATES) */
379 static inline void pure_or_virtual_attribute PARAMS ((tree));
380 static void name_and_src_coords_attributes PARAMS ((tree));
381 static void type_attribute PARAMS ((tree, int, int));
382 static const char *type_tag PARAMS ((tree));
383 static inline void dienum_push PARAMS ((void));
384 static inline void dienum_pop PARAMS ((void));
385 static inline tree member_declared_type PARAMS ((tree));
386 static const char *function_start_label PARAMS ((tree));
387 static void output_array_type_die PARAMS ((void *));
388 static void output_set_type_die PARAMS ((void *));
389 #if 0
390 static void output_entry_point_die PARAMS ((void *));
391 #endif
392 static void output_inlined_enumeration_type_die PARAMS ((void *));
393 static void output_inlined_structure_type_die PARAMS ((void *));
394 static void output_inlined_union_type_die PARAMS ((void *));
395 static void output_enumeration_type_die PARAMS ((void *));
396 static void output_formal_parameter_die PARAMS ((void *));
397 static void output_global_subroutine_die PARAMS ((void *));
398 static void output_global_variable_die PARAMS ((void *));
399 static void output_label_die PARAMS ((void *));
400 static void output_lexical_block_die PARAMS ((void *));
401 static void output_inlined_subroutine_die PARAMS ((void *));
402 static void output_local_variable_die PARAMS ((void *));
403 static void output_member_die PARAMS ((void *));
404 #if 0
405 static void output_pointer_type_die PARAMS ((void *));
406 static void output_reference_type_die PARAMS ((void *));
407 #endif
408 static void output_ptr_to_mbr_type_die PARAMS ((void *));
409 static void output_compile_unit_die PARAMS ((void *));
410 static void output_string_type_die PARAMS ((void *));
411 static void output_inheritance_die PARAMS ((void *));
412 static void output_structure_type_die PARAMS ((void *));
413 static void output_local_subroutine_die PARAMS ((void *));
414 static void output_subroutine_type_die PARAMS ((void *));
415 static void output_typedef_die PARAMS ((void *));
416 static void output_union_type_die PARAMS ((void *));
417 static void output_unspecified_parameters_die PARAMS ((void *));
418 static void output_padded_null_die PARAMS ((void *));
419 static void output_die PARAMS ((void (*)(void *), void *));
420 static void end_sibling_chain PARAMS ((void));
421 static void output_formal_types PARAMS ((tree));
422 static void pend_type PARAMS ((tree));
423 static int type_ok_for_scope PARAMS ((tree, tree));
424 static void output_pending_types_for_scope PARAMS ((tree));
425 static void output_type PARAMS ((tree, tree));
426 static void output_tagged_type_instantiation PARAMS ((tree));
427 static void output_block PARAMS ((tree, int));
428 static void output_decls_for_scope PARAMS ((tree, int));
429 static void output_decl PARAMS ((tree, tree));
430 static void shuffle_filename_entry PARAMS ((filename_entry *));
431 static void generate_new_sfname_entry PARAMS ((void));
432 static unsigned lookup_filename PARAMS ((const char *));
433 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
434 static void generate_macinfo_entry PARAMS ((const char *, const char *));
435 static int is_pseudo_reg PARAMS ((rtx));
436 static tree type_main_variant PARAMS ((tree));
437 static int is_tagged_type PARAMS ((tree));
438 static int is_redundant_typedef PARAMS ((tree));
439 static void add_incomplete_type PARAMS ((tree));
440 static void retry_incomplete_types PARAMS ((void));
442 /* Definitions of defaults for assembler-dependent names of various
443 pseudo-ops and section names.
445 Theses may be overridden in your tm.h file (if necessary) for your
446 particular assembler. The default values provided here correspond to
447 what is expected by "standard" AT&T System V.4 assemblers. */
449 #ifndef FILE_ASM_OP
450 #define FILE_ASM_OP ".file"
451 #endif
452 #ifndef VERSION_ASM_OP
453 #define VERSION_ASM_OP ".version"
454 #endif
455 #ifndef UNALIGNED_SHORT_ASM_OP
456 #define UNALIGNED_SHORT_ASM_OP ".2byte"
457 #endif
458 #ifndef UNALIGNED_INT_ASM_OP
459 #define UNALIGNED_INT_ASM_OP ".4byte"
460 #endif
461 #ifndef ASM_BYTE_OP
462 #define ASM_BYTE_OP ".byte"
463 #endif
464 #ifndef SET_ASM_OP
465 #define SET_ASM_OP ".set"
466 #endif
468 /* Pseudo-ops for pushing the current section onto the section stack (and
469 simultaneously changing to a new section) and for poping back to the
470 section we were in immediately before this one. Note that most svr4
471 assemblers only maintain a one level stack... you can push all the
472 sections you want, but you can only pop out one level. (The sparc
473 svr4 assembler is an exception to this general rule.) That's
474 OK because we only use at most one level of the section stack herein. */
476 #ifndef PUSHSECTION_ASM_OP
477 #define PUSHSECTION_ASM_OP ".section"
478 #endif
479 #ifndef POPSECTION_ASM_OP
480 #define POPSECTION_ASM_OP ".previous"
481 #endif
483 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
484 to print the PUSHSECTION_ASM_OP and the section name. The default here
485 works for almost all svr4 assemblers, except for the sparc, where the
486 section name must be enclosed in double quotes. (See sparcv4.h.) */
488 #ifndef PUSHSECTION_FORMAT
489 #define PUSHSECTION_FORMAT "\t%s\t%s\n"
490 #endif
492 #ifndef DEBUG_SECTION
493 #define DEBUG_SECTION ".debug"
494 #endif
495 #ifndef LINE_SECTION
496 #define LINE_SECTION ".line"
497 #endif
498 #ifndef SFNAMES_SECTION
499 #define SFNAMES_SECTION ".debug_sfnames"
500 #endif
501 #ifndef SRCINFO_SECTION
502 #define SRCINFO_SECTION ".debug_srcinfo"
503 #endif
504 #ifndef MACINFO_SECTION
505 #define MACINFO_SECTION ".debug_macinfo"
506 #endif
507 #ifndef PUBNAMES_SECTION
508 #define PUBNAMES_SECTION ".debug_pubnames"
509 #endif
510 #ifndef ARANGES_SECTION
511 #define ARANGES_SECTION ".debug_aranges"
512 #endif
513 #ifndef TEXT_SECTION
514 #define TEXT_SECTION ".text"
515 #endif
516 #ifndef DATA_SECTION
517 #define DATA_SECTION ".data"
518 #endif
519 #ifndef DATA1_SECTION
520 #define DATA1_SECTION ".data1"
521 #endif
522 #ifndef RODATA_SECTION
523 #define RODATA_SECTION ".rodata"
524 #endif
525 #ifndef RODATA1_SECTION
526 #define RODATA1_SECTION ".rodata1"
527 #endif
528 #ifndef BSS_SECTION
529 #define BSS_SECTION ".bss"
530 #endif
532 /* Definitions of defaults for formats and names of various special
533 (artificial) labels which may be generated within this file (when
534 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
536 If necessary, these may be overridden from within your tm.h file,
537 but typically, you should never need to override these.
539 These labels have been hacked (temporarily) so that they all begin with
540 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
541 stock m88k/svr4 assembler, both of which need to see .L at the start of
542 a label in order to prevent that label from going into the linker symbol
543 table). When I get time, I'll have to fix this the right way so that we
544 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
545 but that will require a rather massive set of changes. For the moment,
546 the following definitions out to produce the right results for all svr4
547 and svr3 assemblers. -- rfg
550 #ifndef TEXT_BEGIN_LABEL
551 #define TEXT_BEGIN_LABEL "*.L_text_b"
552 #endif
553 #ifndef TEXT_END_LABEL
554 #define TEXT_END_LABEL "*.L_text_e"
555 #endif
557 #ifndef DATA_BEGIN_LABEL
558 #define DATA_BEGIN_LABEL "*.L_data_b"
559 #endif
560 #ifndef DATA_END_LABEL
561 #define DATA_END_LABEL "*.L_data_e"
562 #endif
564 #ifndef DATA1_BEGIN_LABEL
565 #define DATA1_BEGIN_LABEL "*.L_data1_b"
566 #endif
567 #ifndef DATA1_END_LABEL
568 #define DATA1_END_LABEL "*.L_data1_e"
569 #endif
571 #ifndef RODATA_BEGIN_LABEL
572 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
573 #endif
574 #ifndef RODATA_END_LABEL
575 #define RODATA_END_LABEL "*.L_rodata_e"
576 #endif
578 #ifndef RODATA1_BEGIN_LABEL
579 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
580 #endif
581 #ifndef RODATA1_END_LABEL
582 #define RODATA1_END_LABEL "*.L_rodata1_e"
583 #endif
585 #ifndef BSS_BEGIN_LABEL
586 #define BSS_BEGIN_LABEL "*.L_bss_b"
587 #endif
588 #ifndef BSS_END_LABEL
589 #define BSS_END_LABEL "*.L_bss_e"
590 #endif
592 #ifndef LINE_BEGIN_LABEL
593 #define LINE_BEGIN_LABEL "*.L_line_b"
594 #endif
595 #ifndef LINE_LAST_ENTRY_LABEL
596 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
597 #endif
598 #ifndef LINE_END_LABEL
599 #define LINE_END_LABEL "*.L_line_e"
600 #endif
602 #ifndef DEBUG_BEGIN_LABEL
603 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
604 #endif
605 #ifndef SFNAMES_BEGIN_LABEL
606 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
607 #endif
608 #ifndef SRCINFO_BEGIN_LABEL
609 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
610 #endif
611 #ifndef MACINFO_BEGIN_LABEL
612 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
613 #endif
615 #ifndef DIE_BEGIN_LABEL_FMT
616 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
617 #endif
618 #ifndef DIE_END_LABEL_FMT
619 #define DIE_END_LABEL_FMT "*.L_D%u_e"
620 #endif
621 #ifndef PUB_DIE_LABEL_FMT
622 #define PUB_DIE_LABEL_FMT "*.L_P%u"
623 #endif
624 #ifndef INSN_LABEL_FMT
625 #define INSN_LABEL_FMT "*.L_I%u_%u"
626 #endif
627 #ifndef BLOCK_BEGIN_LABEL_FMT
628 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
629 #endif
630 #ifndef BLOCK_END_LABEL_FMT
631 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
632 #endif
633 #ifndef SS_BEGIN_LABEL_FMT
634 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
635 #endif
636 #ifndef SS_END_LABEL_FMT
637 #define SS_END_LABEL_FMT "*.L_s%u_e"
638 #endif
639 #ifndef EE_BEGIN_LABEL_FMT
640 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
641 #endif
642 #ifndef EE_END_LABEL_FMT
643 #define EE_END_LABEL_FMT "*.L_e%u_e"
644 #endif
645 #ifndef MT_BEGIN_LABEL_FMT
646 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
647 #endif
648 #ifndef MT_END_LABEL_FMT
649 #define MT_END_LABEL_FMT "*.L_t%u_e"
650 #endif
651 #ifndef LOC_BEGIN_LABEL_FMT
652 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
653 #endif
654 #ifndef LOC_END_LABEL_FMT
655 #define LOC_END_LABEL_FMT "*.L_l%u_e"
656 #endif
657 #ifndef BOUND_BEGIN_LABEL_FMT
658 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
659 #endif
660 #ifndef BOUND_END_LABEL_FMT
661 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
662 #endif
663 #ifndef DERIV_BEGIN_LABEL_FMT
664 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
665 #endif
666 #ifndef DERIV_END_LABEL_FMT
667 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
668 #endif
669 #ifndef SL_BEGIN_LABEL_FMT
670 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
671 #endif
672 #ifndef SL_END_LABEL_FMT
673 #define SL_END_LABEL_FMT "*.L_sl%u_e"
674 #endif
675 #ifndef BODY_BEGIN_LABEL_FMT
676 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
677 #endif
678 #ifndef BODY_END_LABEL_FMT
679 #define BODY_END_LABEL_FMT "*.L_b%u_e"
680 #endif
681 #ifndef FUNC_END_LABEL_FMT
682 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
683 #endif
684 #ifndef TYPE_NAME_FMT
685 #define TYPE_NAME_FMT "*.L_T%u"
686 #endif
687 #ifndef DECL_NAME_FMT
688 #define DECL_NAME_FMT "*.L_E%u"
689 #endif
690 #ifndef LINE_CODE_LABEL_FMT
691 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
692 #endif
693 #ifndef SFNAMES_ENTRY_LABEL_FMT
694 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
695 #endif
696 #ifndef LINE_ENTRY_LABEL_FMT
697 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
698 #endif
700 /* Definitions of defaults for various types of primitive assembly language
701 output operations.
703 If necessary, these may be overridden from within your tm.h file,
704 but typically, you shouldn't need to override these. */
706 #ifndef ASM_OUTPUT_PUSH_SECTION
707 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
708 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
709 #endif
711 #ifndef ASM_OUTPUT_POP_SECTION
712 #define ASM_OUTPUT_POP_SECTION(FILE) \
713 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
714 #endif
716 #ifndef ASM_OUTPUT_DWARF_DELTA2
717 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
718 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
719 assemble_name (FILE, LABEL1); \
720 fprintf (FILE, "-"); \
721 assemble_name (FILE, LABEL2); \
722 fprintf (FILE, "\n"); \
723 } while (0)
724 #endif
726 #ifndef ASM_OUTPUT_DWARF_DELTA4
727 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
728 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
729 assemble_name (FILE, LABEL1); \
730 fprintf (FILE, "-"); \
731 assemble_name (FILE, LABEL2); \
732 fprintf (FILE, "\n"); \
733 } while (0)
734 #endif
736 #ifndef ASM_OUTPUT_DWARF_TAG
737 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
738 do { \
739 fprintf ((FILE), "\t%s\t0x%x", \
740 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
741 if (flag_debug_asm) \
742 fprintf ((FILE), "\t%s %s", \
743 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
744 fputc ('\n', (FILE)); \
745 } while (0)
746 #endif
748 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
749 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
750 do { \
751 fprintf ((FILE), "\t%s\t0x%x", \
752 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
753 if (flag_debug_asm) \
754 fprintf ((FILE), "\t%s %s", \
755 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
756 fputc ('\n', (FILE)); \
757 } while (0)
758 #endif
760 #ifndef ASM_OUTPUT_DWARF_STACK_OP
761 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
762 do { \
763 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
764 if (flag_debug_asm) \
765 fprintf ((FILE), "\t%s %s", \
766 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
767 fputc ('\n', (FILE)); \
768 } while (0)
769 #endif
771 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
772 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
773 do { \
774 fprintf ((FILE), "\t%s\t0x%x", \
775 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
776 if (flag_debug_asm) \
777 fprintf ((FILE), "\t%s %s", \
778 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
779 fputc ('\n', (FILE)); \
780 } while (0)
781 #endif
783 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
784 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
785 do { \
786 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
787 if (flag_debug_asm) \
788 fprintf ((FILE), "\t%s %s", \
789 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
790 fputc ('\n', (FILE)); \
791 } while (0)
792 #endif
794 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
795 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
796 do { \
797 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
798 if (flag_debug_asm) \
799 fprintf ((FILE), "\t%s %s", \
800 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
801 fputc ('\n', (FILE)); \
802 } while (0)
803 #endif
805 #ifndef ASM_OUTPUT_DWARF_ADDR
806 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
807 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
808 assemble_name (FILE, LABEL); \
809 fprintf (FILE, "\n"); \
810 } while (0)
811 #endif
813 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
814 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
815 do { \
816 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
817 output_addr_const ((FILE), (RTX)); \
818 fputc ('\n', (FILE)); \
819 } while (0)
820 #endif
822 #ifndef ASM_OUTPUT_DWARF_REF
823 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
824 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
825 assemble_name (FILE, LABEL); \
826 fprintf (FILE, "\n"); \
827 } while (0)
828 #endif
830 #ifndef ASM_OUTPUT_DWARF_DATA1
831 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
832 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
833 #endif
835 #ifndef ASM_OUTPUT_DWARF_DATA2
836 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
837 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
838 #endif
840 #ifndef ASM_OUTPUT_DWARF_DATA4
841 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
842 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
843 #endif
845 #ifndef ASM_OUTPUT_DWARF_DATA8
846 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
847 do { \
848 if (WORDS_BIG_ENDIAN) \
850 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
851 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
853 else \
855 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
856 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
858 } while (0)
859 #endif
861 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
862 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
863 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
864 defined, we call it, then issue the line feed. If not, we supply a
865 default defintion of calling ASM_OUTPUT_ASCII */
867 #ifndef ASM_OUTPUT_DWARF_STRING
868 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
869 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
870 #else
871 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
872 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
873 #endif
876 /************************ general utility functions **************************/
878 inline static int
879 is_pseudo_reg (rtl)
880 register rtx rtl;
882 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
883 || ((GET_CODE (rtl) == SUBREG)
884 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
887 inline static tree
888 type_main_variant (type)
889 register tree type;
891 type = TYPE_MAIN_VARIANT (type);
893 /* There really should be only one main variant among any group of variants
894 of a given type (and all of the MAIN_VARIANT values for all members of
895 the group should point to that one type) but sometimes the C front-end
896 messes this up for array types, so we work around that bug here. */
898 if (TREE_CODE (type) == ARRAY_TYPE)
900 while (type != TYPE_MAIN_VARIANT (type))
901 type = TYPE_MAIN_VARIANT (type);
904 return type;
907 /* Return non-zero if the given type node represents a tagged type. */
909 inline static int
910 is_tagged_type (type)
911 register tree type;
913 register enum tree_code code = TREE_CODE (type);
915 return (code == RECORD_TYPE || code == UNION_TYPE
916 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
919 static const char *
920 dwarf_tag_name (tag)
921 register unsigned tag;
923 switch (tag)
925 case TAG_padding: return "TAG_padding";
926 case TAG_array_type: return "TAG_array_type";
927 case TAG_class_type: return "TAG_class_type";
928 case TAG_entry_point: return "TAG_entry_point";
929 case TAG_enumeration_type: return "TAG_enumeration_type";
930 case TAG_formal_parameter: return "TAG_formal_parameter";
931 case TAG_global_subroutine: return "TAG_global_subroutine";
932 case TAG_global_variable: return "TAG_global_variable";
933 case TAG_label: return "TAG_label";
934 case TAG_lexical_block: return "TAG_lexical_block";
935 case TAG_local_variable: return "TAG_local_variable";
936 case TAG_member: return "TAG_member";
937 case TAG_pointer_type: return "TAG_pointer_type";
938 case TAG_reference_type: return "TAG_reference_type";
939 case TAG_compile_unit: return "TAG_compile_unit";
940 case TAG_string_type: return "TAG_string_type";
941 case TAG_structure_type: return "TAG_structure_type";
942 case TAG_subroutine: return "TAG_subroutine";
943 case TAG_subroutine_type: return "TAG_subroutine_type";
944 case TAG_typedef: return "TAG_typedef";
945 case TAG_union_type: return "TAG_union_type";
946 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
947 case TAG_variant: return "TAG_variant";
948 case TAG_common_block: return "TAG_common_block";
949 case TAG_common_inclusion: return "TAG_common_inclusion";
950 case TAG_inheritance: return "TAG_inheritance";
951 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
952 case TAG_module: return "TAG_module";
953 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
954 case TAG_set_type: return "TAG_set_type";
955 case TAG_subrange_type: return "TAG_subrange_type";
956 case TAG_with_stmt: return "TAG_with_stmt";
958 /* GNU extensions. */
960 case TAG_format_label: return "TAG_format_label";
961 case TAG_namelist: return "TAG_namelist";
962 case TAG_function_template: return "TAG_function_template";
963 case TAG_class_template: return "TAG_class_template";
965 default: return "TAG_<unknown>";
969 static const char *
970 dwarf_attr_name (attr)
971 register unsigned attr;
973 switch (attr)
975 case AT_sibling: return "AT_sibling";
976 case AT_location: return "AT_location";
977 case AT_name: return "AT_name";
978 case AT_fund_type: return "AT_fund_type";
979 case AT_mod_fund_type: return "AT_mod_fund_type";
980 case AT_user_def_type: return "AT_user_def_type";
981 case AT_mod_u_d_type: return "AT_mod_u_d_type";
982 case AT_ordering: return "AT_ordering";
983 case AT_subscr_data: return "AT_subscr_data";
984 case AT_byte_size: return "AT_byte_size";
985 case AT_bit_offset: return "AT_bit_offset";
986 case AT_bit_size: return "AT_bit_size";
987 case AT_element_list: return "AT_element_list";
988 case AT_stmt_list: return "AT_stmt_list";
989 case AT_low_pc: return "AT_low_pc";
990 case AT_high_pc: return "AT_high_pc";
991 case AT_language: return "AT_language";
992 case AT_member: return "AT_member";
993 case AT_discr: return "AT_discr";
994 case AT_discr_value: return "AT_discr_value";
995 case AT_string_length: return "AT_string_length";
996 case AT_common_reference: return "AT_common_reference";
997 case AT_comp_dir: return "AT_comp_dir";
998 case AT_const_value_string: return "AT_const_value_string";
999 case AT_const_value_data2: return "AT_const_value_data2";
1000 case AT_const_value_data4: return "AT_const_value_data4";
1001 case AT_const_value_data8: return "AT_const_value_data8";
1002 case AT_const_value_block2: return "AT_const_value_block2";
1003 case AT_const_value_block4: return "AT_const_value_block4";
1004 case AT_containing_type: return "AT_containing_type";
1005 case AT_default_value_addr: return "AT_default_value_addr";
1006 case AT_default_value_data2: return "AT_default_value_data2";
1007 case AT_default_value_data4: return "AT_default_value_data4";
1008 case AT_default_value_data8: return "AT_default_value_data8";
1009 case AT_default_value_string: return "AT_default_value_string";
1010 case AT_friends: return "AT_friends";
1011 case AT_inline: return "AT_inline";
1012 case AT_is_optional: return "AT_is_optional";
1013 case AT_lower_bound_ref: return "AT_lower_bound_ref";
1014 case AT_lower_bound_data2: return "AT_lower_bound_data2";
1015 case AT_lower_bound_data4: return "AT_lower_bound_data4";
1016 case AT_lower_bound_data8: return "AT_lower_bound_data8";
1017 case AT_private: return "AT_private";
1018 case AT_producer: return "AT_producer";
1019 case AT_program: return "AT_program";
1020 case AT_protected: return "AT_protected";
1021 case AT_prototyped: return "AT_prototyped";
1022 case AT_public: return "AT_public";
1023 case AT_pure_virtual: return "AT_pure_virtual";
1024 case AT_return_addr: return "AT_return_addr";
1025 case AT_abstract_origin: return "AT_abstract_origin";
1026 case AT_start_scope: return "AT_start_scope";
1027 case AT_stride_size: return "AT_stride_size";
1028 case AT_upper_bound_ref: return "AT_upper_bound_ref";
1029 case AT_upper_bound_data2: return "AT_upper_bound_data2";
1030 case AT_upper_bound_data4: return "AT_upper_bound_data4";
1031 case AT_upper_bound_data8: return "AT_upper_bound_data8";
1032 case AT_virtual: return "AT_virtual";
1034 /* GNU extensions */
1036 case AT_sf_names: return "AT_sf_names";
1037 case AT_src_info: return "AT_src_info";
1038 case AT_mac_info: return "AT_mac_info";
1039 case AT_src_coords: return "AT_src_coords";
1040 case AT_body_begin: return "AT_body_begin";
1041 case AT_body_end: return "AT_body_end";
1043 default: return "AT_<unknown>";
1047 static const char *
1048 dwarf_stack_op_name (op)
1049 register unsigned op;
1051 switch (op)
1053 case OP_REG: return "OP_REG";
1054 case OP_BASEREG: return "OP_BASEREG";
1055 case OP_ADDR: return "OP_ADDR";
1056 case OP_CONST: return "OP_CONST";
1057 case OP_DEREF2: return "OP_DEREF2";
1058 case OP_DEREF4: return "OP_DEREF4";
1059 case OP_ADD: return "OP_ADD";
1060 default: return "OP_<unknown>";
1064 static const char *
1065 dwarf_typemod_name (mod)
1066 register unsigned mod;
1068 switch (mod)
1070 case MOD_pointer_to: return "MOD_pointer_to";
1071 case MOD_reference_to: return "MOD_reference_to";
1072 case MOD_const: return "MOD_const";
1073 case MOD_volatile: return "MOD_volatile";
1074 default: return "MOD_<unknown>";
1078 static const char *
1079 dwarf_fmt_byte_name (fmt)
1080 register unsigned fmt;
1082 switch (fmt)
1084 case FMT_FT_C_C: return "FMT_FT_C_C";
1085 case FMT_FT_C_X: return "FMT_FT_C_X";
1086 case FMT_FT_X_C: return "FMT_FT_X_C";
1087 case FMT_FT_X_X: return "FMT_FT_X_X";
1088 case FMT_UT_C_C: return "FMT_UT_C_C";
1089 case FMT_UT_C_X: return "FMT_UT_C_X";
1090 case FMT_UT_X_C: return "FMT_UT_X_C";
1091 case FMT_UT_X_X: return "FMT_UT_X_X";
1092 case FMT_ET: return "FMT_ET";
1093 default: return "FMT_<unknown>";
1097 static const char *
1098 dwarf_fund_type_name (ft)
1099 register unsigned ft;
1101 switch (ft)
1103 case FT_char: return "FT_char";
1104 case FT_signed_char: return "FT_signed_char";
1105 case FT_unsigned_char: return "FT_unsigned_char";
1106 case FT_short: return "FT_short";
1107 case FT_signed_short: return "FT_signed_short";
1108 case FT_unsigned_short: return "FT_unsigned_short";
1109 case FT_integer: return "FT_integer";
1110 case FT_signed_integer: return "FT_signed_integer";
1111 case FT_unsigned_integer: return "FT_unsigned_integer";
1112 case FT_long: return "FT_long";
1113 case FT_signed_long: return "FT_signed_long";
1114 case FT_unsigned_long: return "FT_unsigned_long";
1115 case FT_pointer: return "FT_pointer";
1116 case FT_float: return "FT_float";
1117 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1118 case FT_ext_prec_float: return "FT_ext_prec_float";
1119 case FT_complex: return "FT_complex";
1120 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1121 case FT_void: return "FT_void";
1122 case FT_boolean: return "FT_boolean";
1123 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1124 case FT_label: return "FT_label";
1126 /* GNU extensions. */
1128 case FT_long_long: return "FT_long_long";
1129 case FT_signed_long_long: return "FT_signed_long_long";
1130 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1132 case FT_int8: return "FT_int8";
1133 case FT_signed_int8: return "FT_signed_int8";
1134 case FT_unsigned_int8: return "FT_unsigned_int8";
1135 case FT_int16: return "FT_int16";
1136 case FT_signed_int16: return "FT_signed_int16";
1137 case FT_unsigned_int16: return "FT_unsigned_int16";
1138 case FT_int32: return "FT_int32";
1139 case FT_signed_int32: return "FT_signed_int32";
1140 case FT_unsigned_int32: return "FT_unsigned_int32";
1141 case FT_int64: return "FT_int64";
1142 case FT_signed_int64: return "FT_signed_int64";
1143 case FT_unsigned_int64: return "FT_unsigned_int64";
1145 case FT_real32: return "FT_real32";
1146 case FT_real64: return "FT_real64";
1147 case FT_real96: return "FT_real96";
1148 case FT_real128: return "FT_real128";
1150 default: return "FT_<unknown>";
1154 /* Determine the "ultimate origin" of a decl. The decl may be an
1155 inlined instance of an inlined instance of a decl which is local
1156 to an inline function, so we have to trace all of the way back
1157 through the origin chain to find out what sort of node actually
1158 served as the original seed for the given block. */
1160 static tree
1161 decl_ultimate_origin (decl)
1162 register tree decl;
1164 #ifdef ENABLE_CHECKING
1165 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1166 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1167 most distant ancestor, this should never happen. */
1168 abort ();
1169 #endif
1171 return DECL_ABSTRACT_ORIGIN (decl);
1174 /* Determine the "ultimate origin" of a block. The block may be an
1175 inlined instance of an inlined instance of a block which is local
1176 to an inline function, so we have to trace all of the way back
1177 through the origin chain to find out what sort of node actually
1178 served as the original seed for the given block. */
1180 static tree
1181 block_ultimate_origin (block)
1182 register tree block;
1184 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1186 if (immediate_origin == NULL)
1187 return NULL;
1188 else
1190 register tree ret_val;
1191 register tree lookahead = immediate_origin;
1195 ret_val = lookahead;
1196 lookahead = (TREE_CODE (ret_val) == BLOCK)
1197 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1198 : NULL;
1200 while (lookahead != NULL && lookahead != ret_val);
1201 return ret_val;
1205 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1206 of a virtual function may refer to a base class, so we check the 'this'
1207 parameter. */
1209 static tree
1210 decl_class_context (decl)
1211 tree decl;
1213 tree context = NULL_TREE;
1214 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1215 context = DECL_CONTEXT (decl);
1216 else
1217 context = TYPE_MAIN_VARIANT
1218 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1220 if (context && !TYPE_P (context))
1221 context = NULL_TREE;
1223 return context;
1226 #if 0
1227 static void
1228 output_unsigned_leb128 (value)
1229 register unsigned long value;
1231 register unsigned long orig_value = value;
1235 register unsigned byte = (value & 0x7f);
1237 value >>= 7;
1238 if (value != 0) /* more bytes to follow */
1239 byte |= 0x80;
1240 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1241 if (flag_debug_asm && value == 0)
1242 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1243 ASM_COMMENT_START, orig_value);
1244 fputc ('\n', asm_out_file);
1246 while (value != 0);
1249 static void
1250 output_signed_leb128 (value)
1251 register long value;
1253 register long orig_value = value;
1254 register int negative = (value < 0);
1255 register int more;
1259 register unsigned byte = (value & 0x7f);
1261 value >>= 7;
1262 if (negative)
1263 value |= 0xfe000000; /* manually sign extend */
1264 if (((value == 0) && ((byte & 0x40) == 0))
1265 || ((value == -1) && ((byte & 0x40) == 1)))
1266 more = 0;
1267 else
1269 byte |= 0x80;
1270 more = 1;
1272 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1273 if (flag_debug_asm && more == 0)
1274 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1275 ASM_COMMENT_START, orig_value);
1276 fputc ('\n', asm_out_file);
1278 while (more);
1280 #endif
1282 /**************** utility functions for attribute functions ******************/
1284 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1285 type code for the given type.
1287 This routine must only be called for GCC type nodes that correspond to
1288 Dwarf fundamental types.
1290 The current Dwarf draft specification calls for Dwarf fundamental types
1291 to accurately reflect the fact that a given type was either a "plain"
1292 integral type or an explicitly "signed" integral type. Unfortunately,
1293 we can't always do this, because GCC may already have thrown away the
1294 information about the precise way in which the type was originally
1295 specified, as in:
1297 typedef signed int my_type;
1299 struct s { my_type f; };
1301 Since we may be stuck here without enought information to do exactly
1302 what is called for in the Dwarf draft specification, we do the best
1303 that we can under the circumstances and always use the "plain" integral
1304 fundamental type codes for int, short, and long types. That's probably
1305 good enough. The additional accuracy called for in the current DWARF
1306 draft specification is probably never even useful in practice. */
1308 static int
1309 fundamental_type_code (type)
1310 register tree type;
1312 if (TREE_CODE (type) == ERROR_MARK)
1313 return 0;
1315 switch (TREE_CODE (type))
1317 case ERROR_MARK:
1318 return FT_void;
1320 case VOID_TYPE:
1321 return FT_void;
1323 case INTEGER_TYPE:
1324 /* Carefully distinguish all the standard types of C,
1325 without messing up if the language is not C.
1326 Note that we check only for the names that contain spaces;
1327 other names might occur by coincidence in other languages. */
1328 if (TYPE_NAME (type) != 0
1329 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1330 && DECL_NAME (TYPE_NAME (type)) != 0
1331 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1333 const char *name =
1334 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1336 if (!strcmp (name, "unsigned char"))
1337 return FT_unsigned_char;
1338 if (!strcmp (name, "signed char"))
1339 return FT_signed_char;
1340 if (!strcmp (name, "unsigned int"))
1341 return FT_unsigned_integer;
1342 if (!strcmp (name, "short int"))
1343 return FT_short;
1344 if (!strcmp (name, "short unsigned int"))
1345 return FT_unsigned_short;
1346 if (!strcmp (name, "long int"))
1347 return FT_long;
1348 if (!strcmp (name, "long unsigned int"))
1349 return FT_unsigned_long;
1350 if (!strcmp (name, "long long int"))
1351 return FT_long_long; /* Not grok'ed by svr4 SDB */
1352 if (!strcmp (name, "long long unsigned int"))
1353 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1356 /* Most integer types will be sorted out above, however, for the
1357 sake of special `array index' integer types, the following code
1358 is also provided. */
1360 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1361 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1363 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1364 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1366 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1367 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1369 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1370 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1372 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1373 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
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 return 0;
1565 default:
1566 abort ();
1568 return 0;
1571 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1572 equate directive which will associate a symbolic name with the current DIE.
1574 The name used is an artificial label generated from the DECL_UID number
1575 associated with the given decl node. The name it gets equated to is the
1576 symbolic label that we (previously) output at the start of the DIE that
1577 we are currently generating.
1579 Calling this function while generating some "decl related" form of DIE
1580 makes it possible to later refer to the DIE which represents the given
1581 decl simply by re-generating the symbolic name from the ..._DECL node's
1582 UID number. */
1584 static void
1585 equate_decl_number_to_die_number (decl)
1586 register tree decl;
1588 /* In the case where we are generating a DIE for some ..._DECL node
1589 which represents either some inline function declaration or some
1590 entity declared within an inline function declaration/definition,
1591 setup a symbolic name for the current DIE so that we have a name
1592 for this DIE that we can easily refer to later on within
1593 AT_abstract_origin attributes. */
1595 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1596 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1598 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1599 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1600 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1603 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1604 equate directive which will associate a symbolic name with the current DIE.
1606 The name used is an artificial label generated from the TYPE_UID number
1607 associated with the given type node. The name it gets equated to is the
1608 symbolic label that we (previously) output at the start of the DIE that
1609 we are currently generating.
1611 Calling this function while generating some "type related" form of DIE
1612 makes it easy to later refer to the DIE which represents the given type
1613 simply by re-generating the alternative name from the ..._TYPE node's
1614 UID number. */
1616 static inline void
1617 equate_type_number_to_die_number (type)
1618 register tree type;
1620 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1621 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1623 /* We are generating a DIE to represent the main variant of this type
1624 (i.e the type without any const or volatile qualifiers) so in order
1625 to get the equate to come out right, we need to get the main variant
1626 itself here. */
1628 type = type_main_variant (type);
1630 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1631 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1632 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1635 static void
1636 output_reg_number (rtl)
1637 register rtx rtl;
1639 register unsigned regno = REGNO (rtl);
1641 if (regno >= DWARF_FRAME_REGISTERS)
1643 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1644 regno);
1645 regno = 0;
1647 fprintf (asm_out_file, "\t%s\t0x%x",
1648 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1649 if (flag_debug_asm)
1651 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1652 PRINT_REG (rtl, 0, asm_out_file);
1654 fputc ('\n', asm_out_file);
1657 /* The following routine is a nice and simple transducer. It converts the
1658 RTL for a variable or parameter (resident in memory) into an equivalent
1659 Dwarf representation of a mechanism for getting the address of that same
1660 variable onto the top of a hypothetical "address evaluation" stack.
1662 When creating memory location descriptors, we are effectively trans-
1663 forming the RTL for a memory-resident object into its Dwarf postfix
1664 expression equivalent. This routine just recursively descends an
1665 RTL tree, turning it into Dwarf postfix code as it goes. */
1667 static void
1668 output_mem_loc_descriptor (rtl)
1669 register rtx rtl;
1671 /* Note that for a dynamically sized array, the location we will
1672 generate a description of here will be the lowest numbered location
1673 which is actually within the array. That's *not* necessarily the
1674 same as the zeroth element of the array. */
1676 #ifdef ASM_SIMPLIFY_DWARF_ADDR
1677 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
1678 #endif
1680 switch (GET_CODE (rtl))
1682 case SUBREG:
1684 /* The case of a subreg may arise when we have a local (register)
1685 variable or a formal (register) parameter which doesn't quite
1686 fill up an entire register. For now, just assume that it is
1687 legitimate to make the Dwarf info refer to the whole register
1688 which contains the given subreg. */
1690 rtl = XEXP (rtl, 0);
1691 /* Drop thru. */
1693 case REG:
1695 /* Whenever a register number forms a part of the description of
1696 the method for calculating the (dynamic) address of a memory
1697 resident object, DWARF rules require the register number to
1698 be referred to as a "base register". This distinction is not
1699 based in any way upon what category of register the hardware
1700 believes the given register belongs to. This is strictly
1701 DWARF terminology we're dealing with here.
1703 Note that in cases where the location of a memory-resident data
1704 object could be expressed as:
1706 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1708 the actual DWARF location descriptor that we generate may just
1709 be OP_BASEREG (basereg). This may look deceptively like the
1710 object in question was allocated to a register (rather than
1711 in memory) so DWARF consumers need to be aware of the subtle
1712 distinction between OP_REG and OP_BASEREG. */
1714 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1715 output_reg_number (rtl);
1716 break;
1718 case MEM:
1719 output_mem_loc_descriptor (XEXP (rtl, 0));
1720 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1721 break;
1723 case CONST:
1724 case SYMBOL_REF:
1725 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1726 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1727 break;
1729 case PLUS:
1730 output_mem_loc_descriptor (XEXP (rtl, 0));
1731 output_mem_loc_descriptor (XEXP (rtl, 1));
1732 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1733 break;
1735 case CONST_INT:
1736 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1737 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1738 break;
1740 case MULT:
1741 /* If a pseudo-reg is optimized away, it is possible for it to
1742 be replaced with a MEM containing a multiply. Use a GNU extension
1743 to describe it. */
1744 output_mem_loc_descriptor (XEXP (rtl, 0));
1745 output_mem_loc_descriptor (XEXP (rtl, 1));
1746 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1747 break;
1749 default:
1750 abort ();
1754 /* Output a proper Dwarf location descriptor for a variable or parameter
1755 which is either allocated in a register or in a memory location. For
1756 a register, we just generate an OP_REG and the register number. For a
1757 memory location we provide a Dwarf postfix expression describing how to
1758 generate the (dynamic) address of the object onto the address stack. */
1760 static void
1761 output_loc_descriptor (rtl)
1762 register rtx rtl;
1764 switch (GET_CODE (rtl))
1766 case SUBREG:
1768 /* The case of a subreg may arise when we have a local (register)
1769 variable or a formal (register) parameter which doesn't quite
1770 fill up an entire register. For now, just assume that it is
1771 legitimate to make the Dwarf info refer to the whole register
1772 which contains the given subreg. */
1774 rtl = XEXP (rtl, 0);
1775 /* Drop thru. */
1777 case REG:
1778 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1779 output_reg_number (rtl);
1780 break;
1782 case MEM:
1783 output_mem_loc_descriptor (XEXP (rtl, 0));
1784 break;
1786 default:
1787 abort (); /* Should never happen */
1791 /* Given a tree node describing an array bound (either lower or upper)
1792 output a representation for that bound. */
1794 static void
1795 output_bound_representation (bound, dim_num, u_or_l)
1796 register tree bound;
1797 register unsigned dim_num; /* For multi-dimensional arrays. */
1798 register char u_or_l; /* Designates upper or lower bound. */
1800 switch (TREE_CODE (bound))
1803 case ERROR_MARK:
1804 return;
1806 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1808 case INTEGER_CST:
1809 if (host_integerp (bound, 0))
1810 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
1811 break;
1813 default:
1815 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1816 SAVE_EXPR nodes, in which case we can do something, or as
1817 an expression, which we cannot represent. */
1819 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1820 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1822 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1823 current_dienum, dim_num, u_or_l);
1825 sprintf (end_label, BOUND_END_LABEL_FMT,
1826 current_dienum, dim_num, u_or_l);
1828 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1829 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1831 /* If optimization is turned on, the SAVE_EXPRs that describe
1832 how to access the upper bound values are essentially bogus.
1833 They only describe (at best) how to get at these values at
1834 the points in the generated code right after they have just
1835 been computed. Worse yet, in the typical case, the upper
1836 bound values will not even *be* computed in the optimized
1837 code, so these SAVE_EXPRs are entirely bogus.
1839 In order to compensate for this fact, we check here to see
1840 if optimization is enabled, and if so, we effectively create
1841 an empty location description for the (unknown and unknowable)
1842 upper bound.
1844 This should not cause too much trouble for existing (stupid?)
1845 debuggers because they have to deal with empty upper bounds
1846 location descriptions anyway in order to be able to deal with
1847 incomplete array types.
1849 Of course an intelligent debugger (GDB?) should be able to
1850 comprehend that a missing upper bound specification in a
1851 array type used for a storage class `auto' local array variable
1852 indicates that the upper bound is both unknown (at compile-
1853 time) and unknowable (at run-time) due to optimization. */
1855 if (! optimize)
1857 while (TREE_CODE (bound) == NOP_EXPR
1858 || TREE_CODE (bound) == CONVERT_EXPR)
1859 bound = TREE_OPERAND (bound, 0);
1861 if (TREE_CODE (bound) == SAVE_EXPR)
1862 output_loc_descriptor
1863 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1866 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1868 break;
1873 /* Recursive function to output a sequence of value/name pairs for
1874 enumeration constants in reversed order. This is called from
1875 enumeration_type_die. */
1877 static void
1878 output_enumeral_list (link)
1879 register tree link;
1881 if (link)
1883 output_enumeral_list (TREE_CHAIN (link));
1885 if (host_integerp (TREE_VALUE (link), 0))
1886 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1887 tree_low_cst (TREE_VALUE (link), 0));
1889 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
1890 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1894 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1895 which is not less than the value itself. */
1897 static inline HOST_WIDE_INT
1898 ceiling (value, boundary)
1899 register HOST_WIDE_INT value;
1900 register unsigned int boundary;
1902 return (((value + boundary - 1) / boundary) * boundary);
1905 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1906 pointer to the declared type for the relevant field variable, or return
1907 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1909 static inline tree
1910 field_type (decl)
1911 register tree decl;
1913 register tree type;
1915 if (TREE_CODE (decl) == ERROR_MARK)
1916 return integer_type_node;
1918 type = DECL_BIT_FIELD_TYPE (decl);
1919 if (type == NULL)
1920 type = TREE_TYPE (decl);
1921 return type;
1924 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1925 node, return the alignment in bits for the type, or else return
1926 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1928 static inline unsigned int
1929 simple_type_align_in_bits (type)
1930 register tree type;
1932 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1935 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1936 node, return the size in bits for the type if it is a constant, or
1937 else return the alignment for the type if the type's size is not
1938 constant, or else return BITS_PER_WORD if the type actually turns out
1939 to be an ERROR_MARK node. */
1941 static inline unsigned HOST_WIDE_INT
1942 simple_type_size_in_bits (type)
1943 register tree type;
1945 if (TREE_CODE (type) == ERROR_MARK)
1946 return BITS_PER_WORD;
1947 else
1949 register tree type_size_tree = TYPE_SIZE (type);
1951 if (! host_integerp (type_size_tree, 1))
1952 return TYPE_ALIGN (type);
1954 return tree_low_cst (type_size_tree, 1);
1958 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1959 return the byte offset of the lowest addressed byte of the "containing
1960 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1961 mine what that offset is, either because the argument turns out to be a
1962 pointer to an ERROR_MARK node, or because the offset is actually variable.
1963 (We can't handle the latter case just yet.) */
1965 static HOST_WIDE_INT
1966 field_byte_offset (decl)
1967 register tree decl;
1969 unsigned int type_align_in_bytes;
1970 unsigned int type_align_in_bits;
1971 unsigned HOST_WIDE_INT type_size_in_bits;
1972 HOST_WIDE_INT object_offset_in_align_units;
1973 HOST_WIDE_INT object_offset_in_bits;
1974 HOST_WIDE_INT object_offset_in_bytes;
1975 tree type;
1976 tree field_size_tree;
1977 HOST_WIDE_INT bitpos_int;
1978 HOST_WIDE_INT deepest_bitpos;
1979 unsigned HOST_WIDE_INT field_size_in_bits;
1981 if (TREE_CODE (decl) == ERROR_MARK)
1982 return 0;
1984 if (TREE_CODE (decl) != FIELD_DECL)
1985 abort ();
1987 type = field_type (decl);
1988 field_size_tree = DECL_SIZE (decl);
1990 /* If there was an error, the size could be zero. */
1991 if (! field_size_tree)
1993 if (errorcount)
1994 return 0;
1996 abort ();
1999 /* We cannot yet cope with fields whose positions or sizes are variable,
2000 so for now, when we see such things, we simply return 0. Someday,
2001 we may be able to handle such cases, but it will be damn difficult. */
2003 if (! host_integerp (bit_position (decl), 0)
2004 || ! host_integerp (field_size_tree, 1))
2005 return 0;
2007 bitpos_int = int_bit_position (decl);
2008 field_size_in_bits = tree_low_cst (field_size_tree, 1);
2010 type_size_in_bits = simple_type_size_in_bits (type);
2011 type_align_in_bits = simple_type_align_in_bits (type);
2012 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
2014 /* Note that the GCC front-end doesn't make any attempt to keep track
2015 of the starting bit offset (relative to the start of the containing
2016 structure type) of the hypothetical "containing object" for a bit-
2017 field. Thus, when computing the byte offset value for the start of
2018 the "containing object" of a bit-field, we must deduce this infor-
2019 mation on our own.
2021 This can be rather tricky to do in some cases. For example, handling
2022 the following structure type definition when compiling for an i386/i486
2023 target (which only aligns long long's to 32-bit boundaries) can be very
2024 tricky:
2026 struct S {
2027 int field1;
2028 long long field2:31;
2031 Fortunately, there is a simple rule-of-thumb which can be used in such
2032 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
2033 the structure shown above. It decides to do this based upon one simple
2034 rule for bit-field allocation. Quite simply, GCC allocates each "con-
2035 taining object" for each bit-field at the first (i.e. lowest addressed)
2036 legitimate alignment boundary (based upon the required minimum alignment
2037 for the declared type of the field) which it can possibly use, subject
2038 to the condition that there is still enough available space remaining
2039 in the containing object (when allocated at the selected point) to
2040 fully accommodate all of the bits of the bit-field itself.
2042 This simple rule makes it obvious why GCC allocates 8 bytes for each
2043 object of the structure type shown above. When looking for a place to
2044 allocate the "containing object" for `field2', the compiler simply tries
2045 to allocate a 64-bit "containing object" at each successive 32-bit
2046 boundary (starting at zero) until it finds a place to allocate that 64-
2047 bit field such that at least 31 contiguous (and previously unallocated)
2048 bits remain within that selected 64 bit field. (As it turns out, for
2049 the example above, the compiler finds that it is OK to allocate the
2050 "containing object" 64-bit field at bit-offset zero within the
2051 structure type.)
2053 Here we attempt to work backwards from the limited set of facts we're
2054 given, and we try to deduce from those facts, where GCC must have
2055 believed that the containing object started (within the structure type).
2057 The value we deduce is then used (by the callers of this routine) to
2058 generate AT_location and AT_bit_offset attributes for fields (both
2059 bit-fields and, in the case of AT_location, regular fields as well). */
2061 /* Figure out the bit-distance from the start of the structure to the
2062 "deepest" bit of the bit-field. */
2063 deepest_bitpos = bitpos_int + field_size_in_bits;
2065 /* This is the tricky part. Use some fancy footwork to deduce where the
2066 lowest addressed bit of the containing object must be. */
2067 object_offset_in_bits
2068 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2070 /* Compute the offset of the containing object in "alignment units". */
2071 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2073 /* Compute the offset of the containing object in bytes. */
2074 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2076 /* The above code assumes that the field does not cross an alignment
2077 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2078 or if the structure is packed. If this happens, then we get an object
2079 which starts after the bitfield, which means that the bit offset is
2080 negative. Gdb fails when given negative bit offsets. We avoid this
2081 by recomputing using the first bit of the bitfield. This will give
2082 us an object which does not completely contain the bitfield, but it
2083 will be aligned, and it will contain the first bit of the bitfield.
2085 However, only do this for a BYTES_BIG_ENDIAN target. For a
2086 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2087 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2088 then we end up computing the object byte offset for the wrong word of the
2089 desired bitfield, which in turn causes the field offset to be negative
2090 in bit_offset_attribute. */
2091 if (BYTES_BIG_ENDIAN
2092 && object_offset_in_bits > bitpos_int)
2094 deepest_bitpos = bitpos_int + 1;
2095 object_offset_in_bits
2096 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2097 object_offset_in_align_units = (object_offset_in_bits
2098 / type_align_in_bits);
2099 object_offset_in_bytes = (object_offset_in_align_units
2100 * type_align_in_bytes);
2103 return object_offset_in_bytes;
2106 /****************************** attributes *********************************/
2108 /* The following routines are responsible for writing out the various types
2109 of Dwarf attributes (and any following data bytes associated with them).
2110 These routines are listed in order based on the numerical codes of their
2111 associated attributes. */
2113 /* Generate an AT_sibling attribute. */
2115 static inline void
2116 sibling_attribute ()
2118 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2120 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2121 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2122 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2125 /* Output the form of location attributes suitable for whole variables and
2126 whole parameters. Note that the location attributes for struct fields
2127 are generated by the routine `data_member_location_attribute' below. */
2129 static void
2130 location_attribute (rtl)
2131 register rtx rtl;
2133 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2134 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2136 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2137 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2138 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2139 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2140 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2142 /* Handle a special case. If we are about to output a location descriptor
2143 for a variable or parameter which has been optimized out of existence,
2144 don't do that. Instead we output a zero-length location descriptor
2145 value as part of the location attribute.
2147 A variable which has been optimized out of existence will have a
2148 DECL_RTL value which denotes a pseudo-reg.
2150 Currently, in some rare cases, variables can have DECL_RTL values
2151 which look like (MEM (REG pseudo-reg#)). These cases are due to
2152 bugs elsewhere in the compiler. We treat such cases
2153 as if the variable(s) in question had been optimized out of existence.
2155 Note that in all cases where we wish to express the fact that a
2156 variable has been optimized out of existence, we do not simply
2157 suppress the generation of the entire location attribute because
2158 the absence of a location attribute in certain kinds of DIEs is
2159 used to indicate something else entirely... i.e. that the DIE
2160 represents an object declaration, but not a definition. So saith
2161 the PLSIG.
2164 if (! is_pseudo_reg (rtl)
2165 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2166 output_loc_descriptor (rtl);
2168 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2171 /* Output the specialized form of location attribute used for data members
2172 of struct and union types.
2174 In the special case of a FIELD_DECL node which represents a bit-field,
2175 the "offset" part of this special location descriptor must indicate the
2176 distance in bytes from the lowest-addressed byte of the containing
2177 struct or union type to the lowest-addressed byte of the "containing
2178 object" for the bit-field. (See the `field_byte_offset' function above.)
2180 For any given bit-field, the "containing object" is a hypothetical
2181 object (of some integral or enum type) within which the given bit-field
2182 lives. The type of this hypothetical "containing object" is always the
2183 same as the declared type of the individual bit-field itself (for GCC
2184 anyway... the DWARF spec doesn't actually mandate this).
2186 Note that it is the size (in bytes) of the hypothetical "containing
2187 object" which will be given in the AT_byte_size attribute for this
2188 bit-field. (See the `byte_size_attribute' function below.) It is
2189 also used when calculating the value of the AT_bit_offset attribute.
2190 (See the `bit_offset_attribute' function below.) */
2192 static void
2193 data_member_location_attribute (t)
2194 register tree t;
2196 register unsigned object_offset_in_bytes;
2197 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2198 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2200 if (TREE_CODE (t) == TREE_VEC)
2201 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2202 else
2203 object_offset_in_bytes = field_byte_offset (t);
2205 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2206 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2207 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2208 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2209 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2210 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2211 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2212 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2213 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2216 /* Output an AT_const_value attribute for a variable or a parameter which
2217 does not have a "location" either in memory or in a register. These
2218 things can arise in GNU C when a constant is passed as an actual
2219 parameter to an inlined function. They can also arise in C++ where
2220 declared constants do not necessarily get memory "homes". */
2222 static void
2223 const_value_attribute (rtl)
2224 register rtx rtl;
2226 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2227 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2229 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2230 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2231 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2232 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2233 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2235 switch (GET_CODE (rtl))
2237 case CONST_INT:
2238 /* Note that a CONST_INT rtx could represent either an integer or
2239 a floating-point constant. A CONST_INT is used whenever the
2240 constant will fit into a single word. In all such cases, the
2241 original mode of the constant value is wiped out, and the
2242 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2243 precise mode information for these constants, we always just
2244 output them using 4 bytes. */
2246 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2247 break;
2249 case CONST_DOUBLE:
2250 /* Note that a CONST_DOUBLE rtx could represent either an integer
2251 or a floating-point constant. A CONST_DOUBLE is used whenever
2252 the constant requires more than one word in order to be adequately
2253 represented. In all such cases, the original mode of the constant
2254 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2255 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2257 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2258 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2259 (unsigned int) CONST_DOUBLE_LOW (rtl));
2260 break;
2262 case CONST_STRING:
2263 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2264 break;
2266 case SYMBOL_REF:
2267 case LABEL_REF:
2268 case CONST:
2269 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2270 break;
2272 case PLUS:
2273 /* In cases where an inlined instance of an inline function is passed
2274 the address of an `auto' variable (which is local to the caller)
2275 we can get a situation where the DECL_RTL of the artificial
2276 local variable (for the inlining) which acts as a stand-in for
2277 the corresponding formal parameter (of the inline function)
2278 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2279 This is not exactly a compile-time constant expression, but it
2280 isn't the address of the (artificial) local variable either.
2281 Rather, it represents the *value* which the artificial local
2282 variable always has during its lifetime. We currently have no
2283 way to represent such quasi-constant values in Dwarf, so for now
2284 we just punt and generate an AT_const_value attribute with form
2285 FORM_BLOCK4 and a length of zero. */
2286 break;
2288 default:
2289 abort (); /* No other kinds of rtx should be possible here. */
2292 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2295 /* Generate *either* an AT_location attribute or else an AT_const_value
2296 data attribute for a variable or a parameter. We generate the
2297 AT_const_value attribute only in those cases where the given
2298 variable or parameter does not have a true "location" either in
2299 memory or in a register. This can happen (for example) when a
2300 constant is passed as an actual argument in a call to an inline
2301 function. (It's possible that these things can crop up in other
2302 ways also.) Note that one type of constant value which can be
2303 passed into an inlined function is a constant pointer. This can
2304 happen for example if an actual argument in an inlined function
2305 call evaluates to a compile-time constant address. */
2307 static void
2308 location_or_const_value_attribute (decl)
2309 register tree decl;
2311 register rtx rtl;
2313 if (TREE_CODE (decl) == ERROR_MARK)
2314 return;
2316 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2318 /* Should never happen. */
2319 abort ();
2320 return;
2323 /* Here we have to decide where we are going to say the parameter "lives"
2324 (as far as the debugger is concerned). We only have a couple of choices.
2325 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2326 normally indicates where the parameter lives during most of the activa-
2327 tion of the function. If optimization is enabled however, this could
2328 be either NULL or else a pseudo-reg. Both of those cases indicate that
2329 the parameter doesn't really live anywhere (as far as the code generation
2330 parts of GCC are concerned) during most of the function's activation.
2331 That will happen (for example) if the parameter is never referenced
2332 within the function.
2334 We could just generate a location descriptor here for all non-NULL
2335 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2336 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2337 cases where DECL_RTL is NULL or is a pseudo-reg.
2339 Note however that we can only get away with using DECL_INCOMING_RTL as
2340 a backup substitute for DECL_RTL in certain limited cases. In cases
2341 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2342 we can be sure that the parameter was passed using the same type as it
2343 is declared to have within the function, and that its DECL_INCOMING_RTL
2344 points us to a place where a value of that type is passed. In cases
2345 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2346 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2347 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2348 points us to a value of some type which is *different* from the type
2349 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2350 to generate a location attribute in such cases, the debugger would
2351 end up (for example) trying to fetch a `float' from a place which
2352 actually contains the first part of a `double'. That would lead to
2353 really incorrect and confusing output at debug-time, and we don't
2354 want that now do we?
2356 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2357 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2358 couple of cute exceptions however. On little-endian machines we can
2359 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2360 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2361 an integral type which is smaller than TREE_TYPE(decl). These cases
2362 arise when (on a little-endian machine) a non-prototyped function has
2363 a parameter declared to be of type `short' or `char'. In such cases,
2364 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2365 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2366 passed `int' value. If the debugger then uses that address to fetch a
2367 `short' or a `char' (on a little-endian machine) the result will be the
2368 correct data, so we allow for such exceptional cases below.
2370 Note that our goal here is to describe the place where the given formal
2371 parameter lives during most of the function's activation (i.e. between
2372 the end of the prologue and the start of the epilogue). We'll do that
2373 as best as we can. Note however that if the given formal parameter is
2374 modified sometime during the execution of the function, then a stack
2375 backtrace (at debug-time) will show the function as having been called
2376 with the *new* value rather than the value which was originally passed
2377 in. This happens rarely enough that it is not a major problem, but it
2378 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2379 may generate two additional attributes for any given TAG_formal_parameter
2380 DIE which will describe the "passed type" and the "passed location" for
2381 the given formal parameter in addition to the attributes we now generate
2382 to indicate the "declared type" and the "active location" for each
2383 parameter. This additional set of attributes could be used by debuggers
2384 for stack backtraces.
2386 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2387 can be NULL also. This happens (for example) for inlined-instances of
2388 inline function formal parameters which are never referenced. This really
2389 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2390 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2391 these values for inlined instances of inline function parameters, so
2392 when we see such cases, we are just out-of-luck for the time
2393 being (until integrate.c gets fixed).
2396 /* Use DECL_RTL as the "location" unless we find something better. */
2397 rtl = DECL_RTL (decl);
2399 if (TREE_CODE (decl) == PARM_DECL)
2400 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2402 /* This decl represents a formal parameter which was optimized out. */
2403 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2404 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2406 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2407 *all* cases where (rtl == NULL_RTX) just below. */
2409 if (declared_type == passed_type)
2410 rtl = DECL_INCOMING_RTL (decl);
2411 else if (! BYTES_BIG_ENDIAN)
2412 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2413 /* NMS WTF? */
2414 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2415 rtl = DECL_INCOMING_RTL (decl);
2418 if (rtl == NULL_RTX)
2419 return;
2421 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2422 #ifdef LEAF_REG_REMAP
2423 if (current_function_uses_only_leaf_regs)
2424 leaf_renumber_regs_insn (rtl);
2425 #endif
2427 switch (GET_CODE (rtl))
2429 case ADDRESSOF:
2430 /* The address of a variable that was optimized away; don't emit
2431 anything. */
2432 break;
2434 case CONST_INT:
2435 case CONST_DOUBLE:
2436 case CONST_STRING:
2437 case SYMBOL_REF:
2438 case LABEL_REF:
2439 case CONST:
2440 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2441 const_value_attribute (rtl);
2442 break;
2444 case MEM:
2445 case REG:
2446 case SUBREG:
2447 location_attribute (rtl);
2448 break;
2450 case CONCAT:
2451 /* ??? CONCAT is used for complex variables, which may have the real
2452 part stored in one place and the imag part stored somewhere else.
2453 DWARF1 has no way to describe a variable that lives in two different
2454 places, so we just describe where the first part lives, and hope that
2455 the second part is stored after it. */
2456 location_attribute (XEXP (rtl, 0));
2457 break;
2459 default:
2460 abort (); /* Should never happen. */
2464 /* Generate an AT_name attribute given some string value to be included as
2465 the value of the attribute. */
2467 static inline void
2468 name_attribute (name_string)
2469 register const char *name_string;
2471 if (name_string && *name_string)
2473 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2474 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2478 static inline void
2479 fund_type_attribute (ft_code)
2480 register unsigned ft_code;
2482 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2483 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2486 static void
2487 mod_fund_type_attribute (type, decl_const, decl_volatile)
2488 register tree type;
2489 register int decl_const;
2490 register int decl_volatile;
2492 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2493 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2495 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2496 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2497 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2498 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2499 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2500 write_modifier_bytes (type, decl_const, decl_volatile);
2501 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2502 fundamental_type_code (root_type (type)));
2503 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2506 static inline void
2507 user_def_type_attribute (type)
2508 register tree type;
2510 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2512 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2513 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2514 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2517 static void
2518 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2519 register tree type;
2520 register int decl_const;
2521 register int decl_volatile;
2523 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2524 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2525 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2527 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2528 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2529 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2530 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2531 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2532 write_modifier_bytes (type, decl_const, decl_volatile);
2533 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2534 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2535 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2538 #ifdef USE_ORDERING_ATTRIBUTE
2539 static inline void
2540 ordering_attribute (ordering)
2541 register unsigned ordering;
2543 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2544 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2546 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2548 /* Note that the block of subscript information for an array type also
2549 includes information about the element type of type given array type. */
2551 static void
2552 subscript_data_attribute (type)
2553 register tree type;
2555 register unsigned dimension_number;
2556 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2557 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2559 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2560 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2561 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2562 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2563 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2565 /* The GNU compilers represent multidimensional array types as sequences
2566 of one dimensional array types whose element types are themselves array
2567 types. Here we squish that down, so that each multidimensional array
2568 type gets only one array_type DIE in the Dwarf debugging info. The
2569 draft Dwarf specification say that we are allowed to do this kind
2570 of compression in C (because there is no difference between an
2571 array or arrays and a multidimensional array in C) but for other
2572 source languages (e.g. Ada) we probably shouldn't do this. */
2574 for (dimension_number = 0;
2575 TREE_CODE (type) == ARRAY_TYPE;
2576 type = TREE_TYPE (type), dimension_number++)
2578 register tree domain = TYPE_DOMAIN (type);
2580 /* Arrays come in three flavors. Unspecified bounds, fixed
2581 bounds, and (in GNU C only) variable bounds. Handle all
2582 three forms here. */
2584 if (domain)
2586 /* We have an array type with specified bounds. */
2588 register tree lower = TYPE_MIN_VALUE (domain);
2589 register tree upper = TYPE_MAX_VALUE (domain);
2591 /* Handle only fundamental types as index types for now. */
2593 if (! type_is_fundamental (domain))
2594 abort ();
2596 /* Output the representation format byte for this dimension. */
2598 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2599 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2600 (upper && TREE_CODE (upper) == INTEGER_CST)));
2602 /* Output the index type for this dimension. */
2604 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2605 fundamental_type_code (domain));
2607 /* Output the representation for the lower bound. */
2609 output_bound_representation (lower, dimension_number, 'l');
2611 /* Output the representation for the upper bound. */
2613 output_bound_representation (upper, dimension_number, 'u');
2615 else
2617 /* We have an array type with an unspecified length. For C and
2618 C++ we can assume that this really means that (a) the index
2619 type is an integral type, and (b) the lower bound is zero.
2620 Note that Dwarf defines the representation of an unspecified
2621 (upper) bound as being a zero-length location description. */
2623 /* Output the array-bounds format byte. */
2625 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2627 /* Output the (assumed) index type. */
2629 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2631 /* Output the (assumed) lower bound (constant) value. */
2633 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2635 /* Output the (empty) location description for the upper bound. */
2637 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2641 /* Output the prefix byte that says that the element type is coming up. */
2643 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2645 /* Output a representation of the type of the elements of this array type. */
2647 type_attribute (type, 0, 0);
2649 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2652 static void
2653 byte_size_attribute (tree_node)
2654 register tree tree_node;
2656 register unsigned size;
2658 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2659 switch (TREE_CODE (tree_node))
2661 case ERROR_MARK:
2662 size = 0;
2663 break;
2665 case ENUMERAL_TYPE:
2666 case RECORD_TYPE:
2667 case UNION_TYPE:
2668 case QUAL_UNION_TYPE:
2669 case ARRAY_TYPE:
2670 size = int_size_in_bytes (tree_node);
2671 break;
2673 case FIELD_DECL:
2674 /* For a data member of a struct or union, the AT_byte_size is
2675 generally given as the number of bytes normally allocated for
2676 an object of the *declared* type of the member itself. This
2677 is true even for bit-fields. */
2678 size = simple_type_size_in_bits (field_type (tree_node))
2679 / BITS_PER_UNIT;
2680 break;
2682 default:
2683 abort ();
2686 /* Note that `size' might be -1 when we get to this point. If it
2687 is, that indicates that the byte size of the entity in question
2688 is variable. We have no good way of expressing this fact in Dwarf
2689 at the present time, so just let the -1 pass on through. */
2691 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2694 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2695 which specifies the distance in bits from the highest order bit of the
2696 "containing object" for the bit-field to the highest order bit of the
2697 bit-field itself.
2699 For any given bit-field, the "containing object" is a hypothetical
2700 object (of some integral or enum type) within which the given bit-field
2701 lives. The type of this hypothetical "containing object" is always the
2702 same as the declared type of the individual bit-field itself.
2704 The determination of the exact location of the "containing object" for
2705 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2706 function (above).
2708 Note that it is the size (in bytes) of the hypothetical "containing
2709 object" which will be given in the AT_byte_size attribute for this
2710 bit-field. (See `byte_size_attribute' above.) */
2712 static inline void
2713 bit_offset_attribute (decl)
2714 register tree decl;
2716 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
2717 tree type = DECL_BIT_FIELD_TYPE (decl);
2718 HOST_WIDE_INT bitpos_int;
2719 HOST_WIDE_INT highest_order_object_bit_offset;
2720 HOST_WIDE_INT highest_order_field_bit_offset;
2721 HOST_WIDE_INT bit_offset;
2723 /* Must be a bit field. */
2724 if (!type
2725 || TREE_CODE (decl) != FIELD_DECL)
2726 abort ();
2728 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
2729 if we encounter such things, just return without generating any
2730 attribute whatsoever. */
2732 if (! host_integerp (bit_position (decl), 0)
2733 || ! host_integerp (DECL_SIZE (decl), 1))
2734 return;
2736 bitpos_int = int_bit_position (decl);
2738 /* Note that the bit offset is always the distance (in bits) from the
2739 highest-order bit of the "containing object" to the highest-order
2740 bit of the bit-field itself. Since the "high-order end" of any
2741 object or field is different on big-endian and little-endian machines,
2742 the computation below must take account of these differences. */
2744 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2745 highest_order_field_bit_offset = bitpos_int;
2747 if (! BYTES_BIG_ENDIAN)
2749 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
2750 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2753 bit_offset =
2754 (! BYTES_BIG_ENDIAN
2755 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2756 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2758 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2759 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2762 /* For a FIELD_DECL node which represents a bit field, output an attribute
2763 which specifies the length in bits of the given field. */
2765 static inline void
2766 bit_size_attribute (decl)
2767 register tree decl;
2769 /* Must be a field and a bit field. */
2770 if (TREE_CODE (decl) != FIELD_DECL
2771 || ! DECL_BIT_FIELD_TYPE (decl))
2772 abort ();
2774 if (host_integerp (DECL_SIZE (decl), 1))
2776 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2777 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2778 tree_low_cst (DECL_SIZE (decl), 1));
2782 /* The following routine outputs the `element_list' attribute for enumeration
2783 type DIEs. The element_lits attribute includes the names and values of
2784 all of the enumeration constants associated with the given enumeration
2785 type. */
2787 static inline void
2788 element_list_attribute (element)
2789 register tree element;
2791 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2792 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2794 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2795 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2796 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2797 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2798 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2800 /* Here we output a list of value/name pairs for each enumeration constant
2801 defined for this enumeration type (as required), but we do it in REVERSE
2802 order. The order is the one required by the draft #5 Dwarf specification
2803 published by the UI/PLSIG. */
2805 output_enumeral_list (element); /* Recursively output the whole list. */
2807 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2810 /* Generate an AT_stmt_list attribute. These are normally present only in
2811 DIEs with a TAG_compile_unit tag. */
2813 static inline void
2814 stmt_list_attribute (label)
2815 register const char *label;
2817 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2818 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2819 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2822 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2823 for a subroutine DIE. */
2825 static inline void
2826 low_pc_attribute (asm_low_label)
2827 register const char *asm_low_label;
2829 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2830 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2833 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2834 subroutine DIE. */
2836 static inline void
2837 high_pc_attribute (asm_high_label)
2838 register const char *asm_high_label;
2840 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2841 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2844 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2846 static inline void
2847 body_begin_attribute (asm_begin_label)
2848 register const char *asm_begin_label;
2850 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2851 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2854 /* Generate an AT_body_end attribute for a subroutine DIE. */
2856 static inline void
2857 body_end_attribute (asm_end_label)
2858 register const char *asm_end_label;
2860 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2861 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2864 /* Generate an AT_language attribute given a LANG value. These attributes
2865 are used only within TAG_compile_unit DIEs. */
2867 static inline void
2868 language_attribute (language_code)
2869 register unsigned language_code;
2871 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2872 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2875 static inline void
2876 member_attribute (context)
2877 register tree context;
2879 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2881 /* Generate this attribute only for members in C++. */
2883 if (context != NULL && is_tagged_type (context))
2885 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2886 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2887 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2891 #if 0
2892 static inline void
2893 string_length_attribute (upper_bound)
2894 register tree upper_bound;
2896 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2897 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2899 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2900 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2901 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2902 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2903 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2904 output_bound_representation (upper_bound, 0, 'u');
2905 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2907 #endif
2909 static inline void
2910 comp_dir_attribute (dirname)
2911 register const char *dirname;
2913 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2914 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
2917 static inline void
2918 sf_names_attribute (sf_names_start_label)
2919 register const char *sf_names_start_label;
2921 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2922 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2923 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2926 static inline void
2927 src_info_attribute (src_info_start_label)
2928 register const char *src_info_start_label;
2930 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2931 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2932 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2935 static inline void
2936 mac_info_attribute (mac_info_start_label)
2937 register const char *mac_info_start_label;
2939 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2940 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2941 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2944 static inline void
2945 prototyped_attribute (func_type)
2946 register tree func_type;
2948 if ((strcmp (language_string, "GNU C") == 0)
2949 && (TYPE_ARG_TYPES (func_type) != NULL))
2951 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2952 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2956 static inline void
2957 producer_attribute (producer)
2958 register const char *producer;
2960 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2961 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
2964 static inline void
2965 inline_attribute (decl)
2966 register tree decl;
2968 if (DECL_INLINE (decl))
2970 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2971 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2975 static inline void
2976 containing_type_attribute (containing_type)
2977 register tree containing_type;
2979 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2981 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2982 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2983 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2986 static inline void
2987 abstract_origin_attribute (origin)
2988 register tree origin;
2990 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2992 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2993 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2995 case 'd':
2996 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2997 break;
2999 case 't':
3000 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
3001 break;
3003 default:
3004 abort (); /* Should never happen. */
3007 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
3010 #ifdef DWARF_DECL_COORDINATES
3011 static inline void
3012 src_coords_attribute (src_fileno, src_lineno)
3013 register unsigned src_fileno;
3014 register unsigned src_lineno;
3016 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
3017 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
3018 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
3020 #endif /* defined(DWARF_DECL_COORDINATES) */
3022 static inline void
3023 pure_or_virtual_attribute (func_decl)
3024 register tree func_decl;
3026 if (DECL_VIRTUAL_P (func_decl))
3028 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
3029 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
3030 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
3031 else
3032 #endif
3033 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3034 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3038 /************************* end of attributes *****************************/
3040 /********************* utility routines for DIEs *************************/
3042 /* Output an AT_name attribute and an AT_src_coords attribute for the
3043 given decl, but only if it actually has a name. */
3045 static void
3046 name_and_src_coords_attributes (decl)
3047 register tree decl;
3049 register tree decl_name = DECL_NAME (decl);
3051 if (decl_name && IDENTIFIER_POINTER (decl_name))
3053 name_attribute (IDENTIFIER_POINTER (decl_name));
3054 #ifdef DWARF_DECL_COORDINATES
3056 register unsigned file_index;
3058 /* This is annoying, but we have to pop out of the .debug section
3059 for a moment while we call `lookup_filename' because calling it
3060 may cause a temporary switch into the .debug_sfnames section and
3061 most svr4 assemblers are not smart enough to be able to nest
3062 section switches to any depth greater than one. Note that we
3063 also can't skirt this issue by delaying all output to the
3064 .debug_sfnames section unit the end of compilation because that
3065 would cause us to have inter-section forward references and
3066 Fred Fish sez that m68k/svr4 assemblers botch those. */
3068 ASM_OUTPUT_POP_SECTION (asm_out_file);
3069 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3070 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3072 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3074 #endif /* defined(DWARF_DECL_COORDINATES) */
3078 /* Many forms of DIEs contain a "type description" part. The following
3079 routine writes out these "type descriptor" parts. */
3081 static void
3082 type_attribute (type, decl_const, decl_volatile)
3083 register tree type;
3084 register int decl_const;
3085 register int decl_volatile;
3087 register enum tree_code code = TREE_CODE (type);
3088 register int root_type_modified;
3090 if (code == ERROR_MARK)
3091 return;
3093 /* Handle a special case. For functions whose return type is void,
3094 we generate *no* type attribute. (Note that no object may have
3095 type `void', so this only applies to function return types. */
3097 if (code == VOID_TYPE)
3098 return;
3100 /* If this is a subtype, find the underlying type. Eventually,
3101 this should write out the appropriate subtype info. */
3102 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3103 && TREE_TYPE (type) != 0)
3104 type = TREE_TYPE (type), code = TREE_CODE (type);
3106 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3107 || decl_const || decl_volatile
3108 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3110 if (type_is_fundamental (root_type (type)))
3112 if (root_type_modified)
3113 mod_fund_type_attribute (type, decl_const, decl_volatile);
3114 else
3115 fund_type_attribute (fundamental_type_code (type));
3117 else
3119 if (root_type_modified)
3120 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3121 else
3122 /* We have to get the type_main_variant here (and pass that to the
3123 `user_def_type_attribute' routine) because the ..._TYPE node we
3124 have might simply be a *copy* of some original type node (where
3125 the copy was created to help us keep track of typedef names)
3126 and that copy might have a different TYPE_UID from the original
3127 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3128 is labeling a given type DIE for future reference, it always and
3129 only creates labels for DIEs representing *main variants*, and it
3130 never even knows about non-main-variants.) */
3131 user_def_type_attribute (type_main_variant (type));
3135 /* Given a tree pointer to a struct, class, union, or enum type node, return
3136 a pointer to the (string) tag name for the given type, or zero if the
3137 type was declared without a tag. */
3139 static const char *
3140 type_tag (type)
3141 register tree type;
3143 register const char *name = 0;
3145 if (TYPE_NAME (type) != 0)
3147 register tree t = 0;
3149 /* Find the IDENTIFIER_NODE for the type name. */
3150 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3151 t = TYPE_NAME (type);
3153 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3154 a TYPE_DECL node, regardless of whether or not a `typedef' was
3155 involved. */
3156 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3157 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3158 t = DECL_NAME (TYPE_NAME (type));
3160 /* Now get the name as a string, or invent one. */
3161 if (t != 0)
3162 name = IDENTIFIER_POINTER (t);
3165 return (name == 0 || *name == '\0') ? 0 : name;
3168 static inline void
3169 dienum_push ()
3171 /* Start by checking if the pending_sibling_stack needs to be expanded.
3172 If necessary, expand it. */
3174 if (pending_siblings == pending_siblings_allocated)
3176 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3177 pending_sibling_stack
3178 = (unsigned *) xrealloc (pending_sibling_stack,
3179 pending_siblings_allocated * sizeof(unsigned));
3182 pending_siblings++;
3183 NEXT_DIE_NUM = next_unused_dienum++;
3186 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3187 NEXT_DIE_NUM. */
3189 static inline void
3190 dienum_pop ()
3192 pending_siblings--;
3195 static inline tree
3196 member_declared_type (member)
3197 register tree member;
3199 return (DECL_BIT_FIELD_TYPE (member))
3200 ? DECL_BIT_FIELD_TYPE (member)
3201 : TREE_TYPE (member);
3204 /* Get the function's label, as described by its RTL.
3205 This may be different from the DECL_NAME name used
3206 in the source file. */
3208 static const char *
3209 function_start_label (decl)
3210 register tree decl;
3212 rtx x;
3213 const char *fnname;
3215 x = DECL_RTL (decl);
3216 if (GET_CODE (x) != MEM)
3217 abort ();
3218 x = XEXP (x, 0);
3219 if (GET_CODE (x) != SYMBOL_REF)
3220 abort ();
3221 fnname = XSTR (x, 0);
3222 return fnname;
3226 /******************************* DIEs ************************************/
3228 /* Output routines for individual types of DIEs. */
3230 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3232 static void
3233 output_array_type_die (arg)
3234 register void *arg;
3236 register tree type = arg;
3238 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3239 sibling_attribute ();
3240 equate_type_number_to_die_number (type);
3241 member_attribute (TYPE_CONTEXT (type));
3243 /* I believe that we can default the array ordering. SDB will probably
3244 do the right things even if AT_ordering is not present. It's not
3245 even an issue until we start to get into multidimensional arrays
3246 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3247 dimensional arrays, then we'll have to put the AT_ordering attribute
3248 back in. (But if and when we find out that we need to put these in,
3249 we will only do so for multidimensional arrays. After all, we don't
3250 want to waste space in the .debug section now do we?) */
3252 #ifdef USE_ORDERING_ATTRIBUTE
3253 ordering_attribute (ORD_row_major);
3254 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3256 subscript_data_attribute (type);
3259 static void
3260 output_set_type_die (arg)
3261 register void *arg;
3263 register tree type = arg;
3265 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3266 sibling_attribute ();
3267 equate_type_number_to_die_number (type);
3268 member_attribute (TYPE_CONTEXT (type));
3269 type_attribute (TREE_TYPE (type), 0, 0);
3272 #if 0
3273 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3275 static void
3276 output_entry_point_die (arg)
3277 register void *arg;
3279 register tree decl = arg;
3280 register tree origin = decl_ultimate_origin (decl);
3282 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3283 sibling_attribute ();
3284 dienum_push ();
3285 if (origin != NULL)
3286 abstract_origin_attribute (origin);
3287 else
3289 name_and_src_coords_attributes (decl);
3290 member_attribute (DECL_CONTEXT (decl));
3291 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3293 if (DECL_ABSTRACT (decl))
3294 equate_decl_number_to_die_number (decl);
3295 else
3296 low_pc_attribute (function_start_label (decl));
3298 #endif
3300 /* Output a DIE to represent an inlined instance of an enumeration type. */
3302 static void
3303 output_inlined_enumeration_type_die (arg)
3304 register void *arg;
3306 register tree type = arg;
3308 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3309 sibling_attribute ();
3310 if (!TREE_ASM_WRITTEN (type))
3311 abort ();
3312 abstract_origin_attribute (type);
3315 /* Output a DIE to represent an inlined instance of a structure type. */
3317 static void
3318 output_inlined_structure_type_die (arg)
3319 register void *arg;
3321 register tree type = arg;
3323 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3324 sibling_attribute ();
3325 if (!TREE_ASM_WRITTEN (type))
3326 abort ();
3327 abstract_origin_attribute (type);
3330 /* Output a DIE to represent an inlined instance of a union type. */
3332 static void
3333 output_inlined_union_type_die (arg)
3334 register void *arg;
3336 register tree type = arg;
3338 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3339 sibling_attribute ();
3340 if (!TREE_ASM_WRITTEN (type))
3341 abort ();
3342 abstract_origin_attribute (type);
3345 /* Output a DIE to represent an enumeration type. Note that these DIEs
3346 include all of the information about the enumeration values also.
3347 This information is encoded into the element_list attribute. */
3349 static void
3350 output_enumeration_type_die (arg)
3351 register void *arg;
3353 register tree type = arg;
3355 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3356 sibling_attribute ();
3357 equate_type_number_to_die_number (type);
3358 name_attribute (type_tag (type));
3359 member_attribute (TYPE_CONTEXT (type));
3361 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3362 given enum type is incomplete, do not generate the AT_byte_size
3363 attribute or the AT_element_list attribute. */
3365 if (COMPLETE_TYPE_P (type))
3367 byte_size_attribute (type);
3368 element_list_attribute (TYPE_FIELDS (type));
3372 /* Output a DIE to represent either a real live formal parameter decl or
3373 to represent just the type of some formal parameter position in some
3374 function type.
3376 Note that this routine is a bit unusual because its argument may be
3377 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3378 represents an inlining of some PARM_DECL) or else some sort of a
3379 ..._TYPE node. If it's the former then this function is being called
3380 to output a DIE to represent a formal parameter object (or some inlining
3381 thereof). If it's the latter, then this function is only being called
3382 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3383 formal argument type of some subprogram type. */
3385 static void
3386 output_formal_parameter_die (arg)
3387 register void *arg;
3389 register tree node = arg;
3391 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3392 sibling_attribute ();
3394 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3396 case 'd': /* We were called with some kind of a ..._DECL node. */
3398 register tree origin = decl_ultimate_origin (node);
3400 if (origin != NULL)
3401 abstract_origin_attribute (origin);
3402 else
3404 name_and_src_coords_attributes (node);
3405 type_attribute (TREE_TYPE (node),
3406 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3408 if (DECL_ABSTRACT (node))
3409 equate_decl_number_to_die_number (node);
3410 else
3411 location_or_const_value_attribute (node);
3413 break;
3415 case 't': /* We were called with some kind of a ..._TYPE node. */
3416 type_attribute (node, 0, 0);
3417 break;
3419 default:
3420 abort (); /* Should never happen. */
3424 /* Output a DIE to represent a declared function (either file-scope
3425 or block-local) which has "external linkage" (according to ANSI-C). */
3427 static void
3428 output_global_subroutine_die (arg)
3429 register void *arg;
3431 register tree decl = arg;
3432 register tree origin = decl_ultimate_origin (decl);
3434 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3435 sibling_attribute ();
3436 dienum_push ();
3437 if (origin != NULL)
3438 abstract_origin_attribute (origin);
3439 else
3441 register tree type = TREE_TYPE (decl);
3443 name_and_src_coords_attributes (decl);
3444 inline_attribute (decl);
3445 prototyped_attribute (type);
3446 member_attribute (DECL_CONTEXT (decl));
3447 type_attribute (TREE_TYPE (type), 0, 0);
3448 pure_or_virtual_attribute (decl);
3450 if (DECL_ABSTRACT (decl))
3451 equate_decl_number_to_die_number (decl);
3452 else
3454 if (! DECL_EXTERNAL (decl) && ! in_class
3455 && decl == current_function_decl)
3457 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3459 low_pc_attribute (function_start_label (decl));
3460 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3461 high_pc_attribute (label);
3462 if (use_gnu_debug_info_extensions)
3464 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3465 body_begin_attribute (label);
3466 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3467 body_end_attribute (label);
3473 /* Output a DIE to represent a declared data object (either file-scope
3474 or block-local) which has "external linkage" (according to ANSI-C). */
3476 static void
3477 output_global_variable_die (arg)
3478 register void *arg;
3480 register tree decl = arg;
3481 register tree origin = decl_ultimate_origin (decl);
3483 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3484 sibling_attribute ();
3485 if (origin != NULL)
3486 abstract_origin_attribute (origin);
3487 else
3489 name_and_src_coords_attributes (decl);
3490 member_attribute (DECL_CONTEXT (decl));
3491 type_attribute (TREE_TYPE (decl),
3492 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3494 if (DECL_ABSTRACT (decl))
3495 equate_decl_number_to_die_number (decl);
3496 else
3498 if (! DECL_EXTERNAL (decl) && ! in_class
3499 && current_function_decl == decl_function_context (decl))
3500 location_or_const_value_attribute (decl);
3504 static void
3505 output_label_die (arg)
3506 register void *arg;
3508 register tree decl = arg;
3509 register tree origin = decl_ultimate_origin (decl);
3511 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3512 sibling_attribute ();
3513 if (origin != NULL)
3514 abstract_origin_attribute (origin);
3515 else
3516 name_and_src_coords_attributes (decl);
3517 if (DECL_ABSTRACT (decl))
3518 equate_decl_number_to_die_number (decl);
3519 else
3521 register rtx insn = DECL_RTL (decl);
3523 /* Deleted labels are programmer specified labels which have been
3524 eliminated because of various optimisations. We still emit them
3525 here so that it is possible to put breakpoints on them. */
3526 if (GET_CODE (insn) == CODE_LABEL
3527 || ((GET_CODE (insn) == NOTE
3528 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3530 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3532 /* When optimization is enabled (via -O) some parts of the compiler
3533 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3534 represent source-level labels which were explicitly declared by
3535 the user. This really shouldn't be happening though, so catch
3536 it if it ever does happen. */
3538 if (INSN_DELETED_P (insn))
3539 abort (); /* Should never happen. */
3541 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3542 (unsigned) INSN_UID (insn));
3543 low_pc_attribute (label);
3548 static void
3549 output_lexical_block_die (arg)
3550 register void *arg;
3552 register tree stmt = arg;
3554 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3555 sibling_attribute ();
3556 dienum_push ();
3557 if (! BLOCK_ABSTRACT (stmt))
3559 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3560 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3562 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3563 low_pc_attribute (begin_label);
3564 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3565 high_pc_attribute (end_label);
3569 static void
3570 output_inlined_subroutine_die (arg)
3571 register void *arg;
3573 register tree stmt = arg;
3575 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3576 sibling_attribute ();
3577 dienum_push ();
3578 abstract_origin_attribute (block_ultimate_origin (stmt));
3579 if (! BLOCK_ABSTRACT (stmt))
3581 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3582 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3584 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3585 low_pc_attribute (begin_label);
3586 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3587 high_pc_attribute (end_label);
3591 /* Output a DIE to represent a declared data object (either file-scope
3592 or block-local) which has "internal linkage" (according to ANSI-C). */
3594 static void
3595 output_local_variable_die (arg)
3596 register void *arg;
3598 register tree decl = arg;
3599 register tree origin = decl_ultimate_origin (decl);
3601 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3602 sibling_attribute ();
3603 if (origin != NULL)
3604 abstract_origin_attribute (origin);
3605 else
3607 name_and_src_coords_attributes (decl);
3608 member_attribute (DECL_CONTEXT (decl));
3609 type_attribute (TREE_TYPE (decl),
3610 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3612 if (DECL_ABSTRACT (decl))
3613 equate_decl_number_to_die_number (decl);
3614 else
3615 location_or_const_value_attribute (decl);
3618 static void
3619 output_member_die (arg)
3620 register void *arg;
3622 register tree decl = arg;
3624 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3625 sibling_attribute ();
3626 name_and_src_coords_attributes (decl);
3627 member_attribute (DECL_CONTEXT (decl));
3628 type_attribute (member_declared_type (decl),
3629 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3630 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3632 byte_size_attribute (decl);
3633 bit_size_attribute (decl);
3634 bit_offset_attribute (decl);
3636 data_member_location_attribute (decl);
3639 #if 0
3640 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3641 modified types instead.
3643 We keep this code here just in case these types of DIEs may be
3644 needed to represent certain things in other languages (e.g. Pascal)
3645 someday. */
3647 static void
3648 output_pointer_type_die (arg)
3649 register void *arg;
3651 register tree type = arg;
3653 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3654 sibling_attribute ();
3655 equate_type_number_to_die_number (type);
3656 member_attribute (TYPE_CONTEXT (type));
3657 type_attribute (TREE_TYPE (type), 0, 0);
3660 static void
3661 output_reference_type_die (arg)
3662 register void *arg;
3664 register tree type = arg;
3666 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3667 sibling_attribute ();
3668 equate_type_number_to_die_number (type);
3669 member_attribute (TYPE_CONTEXT (type));
3670 type_attribute (TREE_TYPE (type), 0, 0);
3672 #endif
3674 static void
3675 output_ptr_to_mbr_type_die (arg)
3676 register void *arg;
3678 register tree type = arg;
3680 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3681 sibling_attribute ();
3682 equate_type_number_to_die_number (type);
3683 member_attribute (TYPE_CONTEXT (type));
3684 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3685 type_attribute (TREE_TYPE (type), 0, 0);
3688 static void
3689 output_compile_unit_die (arg)
3690 register void *arg;
3692 register const char *main_input_filename = arg;
3694 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3695 sibling_attribute ();
3696 dienum_push ();
3697 name_attribute (main_input_filename);
3700 char producer[250];
3702 sprintf (producer, "%s %s", language_string, version_string);
3703 producer_attribute (producer);
3706 if (strcmp (language_string, "GNU C++") == 0)
3707 language_attribute (LANG_C_PLUS_PLUS);
3708 else if (strcmp (language_string, "GNU Ada") == 0)
3709 language_attribute (LANG_ADA83);
3710 else if (strcmp (language_string, "GNU F77") == 0)
3711 language_attribute (LANG_FORTRAN77);
3712 else if (strcmp (language_string, "GNU Pascal") == 0)
3713 language_attribute (LANG_PASCAL83);
3714 else if (flag_traditional)
3715 language_attribute (LANG_C);
3716 else
3717 language_attribute (LANG_C89);
3718 low_pc_attribute (TEXT_BEGIN_LABEL);
3719 high_pc_attribute (TEXT_END_LABEL);
3720 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3721 stmt_list_attribute (LINE_BEGIN_LABEL);
3722 last_filename = xstrdup (main_input_filename);
3725 const char *wd = getpwd ();
3726 if (wd)
3727 comp_dir_attribute (wd);
3730 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3732 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3733 src_info_attribute (SRCINFO_BEGIN_LABEL);
3734 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3735 mac_info_attribute (MACINFO_BEGIN_LABEL);
3739 static void
3740 output_string_type_die (arg)
3741 register void *arg;
3743 register tree type = arg;
3745 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3746 sibling_attribute ();
3747 equate_type_number_to_die_number (type);
3748 member_attribute (TYPE_CONTEXT (type));
3749 /* this is a fixed length string */
3750 byte_size_attribute (type);
3753 static void
3754 output_inheritance_die (arg)
3755 register void *arg;
3757 register tree binfo = arg;
3759 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3760 sibling_attribute ();
3761 type_attribute (BINFO_TYPE (binfo), 0, 0);
3762 data_member_location_attribute (binfo);
3763 if (TREE_VIA_VIRTUAL (binfo))
3765 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3766 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3768 if (TREE_VIA_PUBLIC (binfo))
3770 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3771 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3773 else if (TREE_VIA_PROTECTED (binfo))
3775 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3776 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3780 static void
3781 output_structure_type_die (arg)
3782 register void *arg;
3784 register tree type = arg;
3786 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3787 sibling_attribute ();
3788 equate_type_number_to_die_number (type);
3789 name_attribute (type_tag (type));
3790 member_attribute (TYPE_CONTEXT (type));
3792 /* If this type has been completed, then give it a byte_size attribute
3793 and prepare to give a list of members. Otherwise, don't do either of
3794 these things. In the latter case, we will not be generating a list
3795 of members (since we don't have any idea what they might be for an
3796 incomplete type). */
3798 if (COMPLETE_TYPE_P (type))
3800 dienum_push ();
3801 byte_size_attribute (type);
3805 /* Output a DIE to represent a declared function (either file-scope
3806 or block-local) which has "internal linkage" (according to ANSI-C). */
3808 static void
3809 output_local_subroutine_die (arg)
3810 register void *arg;
3812 register tree decl = arg;
3813 register tree origin = decl_ultimate_origin (decl);
3815 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3816 sibling_attribute ();
3817 dienum_push ();
3818 if (origin != NULL)
3819 abstract_origin_attribute (origin);
3820 else
3822 register tree type = TREE_TYPE (decl);
3824 name_and_src_coords_attributes (decl);
3825 inline_attribute (decl);
3826 prototyped_attribute (type);
3827 member_attribute (DECL_CONTEXT (decl));
3828 type_attribute (TREE_TYPE (type), 0, 0);
3829 pure_or_virtual_attribute (decl);
3831 if (DECL_ABSTRACT (decl))
3832 equate_decl_number_to_die_number (decl);
3833 else
3835 /* Avoid getting screwed up in cases where a function was declared
3836 static but where no definition was ever given for it. */
3838 if (TREE_ASM_WRITTEN (decl))
3840 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3841 low_pc_attribute (function_start_label (decl));
3842 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3843 high_pc_attribute (label);
3844 if (use_gnu_debug_info_extensions)
3846 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3847 body_begin_attribute (label);
3848 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3849 body_end_attribute (label);
3855 static void
3856 output_subroutine_type_die (arg)
3857 register void *arg;
3859 register tree type = arg;
3860 register tree return_type = TREE_TYPE (type);
3862 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3863 sibling_attribute ();
3864 dienum_push ();
3865 equate_type_number_to_die_number (type);
3866 prototyped_attribute (type);
3867 member_attribute (TYPE_CONTEXT (type));
3868 type_attribute (return_type, 0, 0);
3871 static void
3872 output_typedef_die (arg)
3873 register void *arg;
3875 register tree decl = arg;
3876 register tree origin = decl_ultimate_origin (decl);
3878 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3879 sibling_attribute ();
3880 if (origin != NULL)
3881 abstract_origin_attribute (origin);
3882 else
3884 name_and_src_coords_attributes (decl);
3885 member_attribute (DECL_CONTEXT (decl));
3886 type_attribute (TREE_TYPE (decl),
3887 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3889 if (DECL_ABSTRACT (decl))
3890 equate_decl_number_to_die_number (decl);
3893 static void
3894 output_union_type_die (arg)
3895 register void *arg;
3897 register tree type = arg;
3899 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3900 sibling_attribute ();
3901 equate_type_number_to_die_number (type);
3902 name_attribute (type_tag (type));
3903 member_attribute (TYPE_CONTEXT (type));
3905 /* If this type has been completed, then give it a byte_size attribute
3906 and prepare to give a list of members. Otherwise, don't do either of
3907 these things. In the latter case, we will not be generating a list
3908 of members (since we don't have any idea what they might be for an
3909 incomplete type). */
3911 if (COMPLETE_TYPE_P (type))
3913 dienum_push ();
3914 byte_size_attribute (type);
3918 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3919 at the end of an (ANSI prototyped) formal parameters list. */
3921 static void
3922 output_unspecified_parameters_die (arg)
3923 register void *arg;
3925 register tree decl_or_type = arg;
3927 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3928 sibling_attribute ();
3930 /* This kludge is here only for the sake of being compatible with what
3931 the USL CI5 C compiler does. The specification of Dwarf Version 1
3932 doesn't say that TAG_unspecified_parameters DIEs should contain any
3933 attributes other than the AT_sibling attribute, but they are certainly
3934 allowed to contain additional attributes, and the CI5 compiler
3935 generates AT_name, AT_fund_type, and AT_location attributes within
3936 TAG_unspecified_parameters DIEs which appear in the child lists for
3937 DIEs representing function definitions, so we do likewise here. */
3939 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3941 name_attribute ("...");
3942 fund_type_attribute (FT_pointer);
3943 /* location_attribute (?); */
3947 static void
3948 output_padded_null_die (arg)
3949 register void *arg ATTRIBUTE_UNUSED;
3951 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3954 /*************************** end of DIEs *********************************/
3956 /* Generate some type of DIE. This routine generates the generic outer
3957 wrapper stuff which goes around all types of DIE's (regardless of their
3958 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3959 DIE-length word, followed by the guts of the DIE itself. After the guts
3960 of the DIE, there must always be a terminator label for the DIE. */
3962 static void
3963 output_die (die_specific_output_function, param)
3964 register void (*die_specific_output_function) PARAMS ((void *));
3965 register void *param;
3967 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3968 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3970 current_dienum = NEXT_DIE_NUM;
3971 NEXT_DIE_NUM = next_unused_dienum;
3973 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3974 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3976 /* Write a label which will act as the name for the start of this DIE. */
3978 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3980 /* Write the DIE-length word. */
3982 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3984 /* Fill in the guts of the DIE. */
3986 next_unused_dienum++;
3987 die_specific_output_function (param);
3989 /* Write a label which will act as the name for the end of this DIE. */
3991 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3994 static void
3995 end_sibling_chain ()
3997 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3999 current_dienum = NEXT_DIE_NUM;
4000 NEXT_DIE_NUM = next_unused_dienum;
4002 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
4004 /* Write a label which will act as the name for the start of this DIE. */
4006 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
4008 /* Write the DIE-length word. */
4010 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4012 dienum_pop ();
4015 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
4016 TAG_unspecified_parameters DIE) to represent the types of the formal
4017 parameters as specified in some function type specification (except
4018 for those which appear as part of a function *definition*).
4020 Note that we must be careful here to output all of the parameter
4021 DIEs *before* we output any DIEs needed to represent the types of
4022 the formal parameters. This keeps svr4 SDB happy because it
4023 (incorrectly) thinks that the first non-parameter DIE it sees ends
4024 the formal parameter list. */
4026 static void
4027 output_formal_types (function_or_method_type)
4028 register tree function_or_method_type;
4030 register tree link;
4031 register tree formal_type = NULL;
4032 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
4034 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
4035 get bogus recursion when outputting tagged types local to a
4036 function declaration. */
4037 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
4038 TREE_ASM_WRITTEN (function_or_method_type) = 1;
4040 /* In the case where we are generating a formal types list for a C++
4041 non-static member function type, skip over the first thing on the
4042 TYPE_ARG_TYPES list because it only represents the type of the
4043 hidden `this pointer'. The debugger should be able to figure
4044 out (without being explicitly told) that this non-static member
4045 function type takes a `this pointer' and should be able to figure
4046 what the type of that hidden parameter is from the AT_member
4047 attribute of the parent TAG_subroutine_type DIE. */
4049 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
4050 first_parm_type = TREE_CHAIN (first_parm_type);
4052 /* Make our first pass over the list of formal parameter types and output
4053 a TAG_formal_parameter DIE for each one. */
4055 for (link = first_parm_type; link; link = TREE_CHAIN (link))
4057 formal_type = TREE_VALUE (link);
4058 if (formal_type == void_type_node)
4059 break;
4061 /* Output a (nameless) DIE to represent the formal parameter itself. */
4063 output_die (output_formal_parameter_die, formal_type);
4066 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4067 DIE to the end of the parameter list. */
4069 if (formal_type != void_type_node)
4070 output_die (output_unspecified_parameters_die, function_or_method_type);
4072 /* Make our second (and final) pass over the list of formal parameter types
4073 and output DIEs to represent those types (as necessary). */
4075 for (link = TYPE_ARG_TYPES (function_or_method_type);
4076 link;
4077 link = TREE_CHAIN (link))
4079 formal_type = TREE_VALUE (link);
4080 if (formal_type == void_type_node)
4081 break;
4083 output_type (formal_type, function_or_method_type);
4086 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4089 /* Remember a type in the pending_types_list. */
4091 static void
4092 pend_type (type)
4093 register tree type;
4095 if (pending_types == pending_types_allocated)
4097 pending_types_allocated += PENDING_TYPES_INCREMENT;
4098 pending_types_list
4099 = (tree *) xrealloc (pending_types_list,
4100 sizeof (tree) * pending_types_allocated);
4102 pending_types_list[pending_types++] = type;
4104 /* Mark the pending type as having been output already (even though
4105 it hasn't been). This prevents the type from being added to the
4106 pending_types_list more than once. */
4108 TREE_ASM_WRITTEN (type) = 1;
4111 /* Return non-zero if it is legitimate to output DIEs to represent a
4112 given type while we are generating the list of child DIEs for some
4113 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4115 See the comments within the function for a description of when it is
4116 considered legitimate to output DIEs for various kinds of types.
4118 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4119 or it may point to a BLOCK node (for types local to a block), or to a
4120 FUNCTION_DECL node (for types local to the heading of some function
4121 definition), or to a FUNCTION_TYPE node (for types local to the
4122 prototyped parameter list of a function type specification), or to a
4123 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4124 (in the case of C++ nested types).
4126 The `scope' parameter should likewise be NULL or should point to a
4127 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4128 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4130 This function is used only for deciding when to "pend" and when to
4131 "un-pend" types to/from the pending_types_list.
4133 Note that we sometimes make use of this "type pending" feature in a
4134 rather twisted way to temporarily delay the production of DIEs for the
4135 types of formal parameters. (We do this just to make svr4 SDB happy.)
4136 It order to delay the production of DIEs representing types of formal
4137 parameters, callers of this function supply `fake_containing_scope' as
4138 the `scope' parameter to this function. Given that fake_containing_scope
4139 is a tagged type which is *not* the containing scope for *any* other type,
4140 the desired effect is achieved, i.e. output of DIEs representing types
4141 is temporarily suspended, and any type DIEs which would have otherwise
4142 been output are instead placed onto the pending_types_list. Later on,
4143 we force these (temporarily pended) types to be output simply by calling
4144 `output_pending_types_for_scope' with an actual argument equal to the
4145 true scope of the types we temporarily pended. */
4147 static inline int
4148 type_ok_for_scope (type, scope)
4149 register tree type;
4150 register tree scope;
4152 /* Tagged types (i.e. struct, union, and enum types) must always be
4153 output only in the scopes where they actually belong (or else the
4154 scoping of their own tag names and the scoping of their member
4155 names will be incorrect). Non-tagged-types on the other hand can
4156 generally be output anywhere, except that svr4 SDB really doesn't
4157 want to see them nested within struct or union types, so here we
4158 say it is always OK to immediately output any such a (non-tagged)
4159 type, so long as we are not within such a context. Note that the
4160 only kinds of non-tagged types which we will be dealing with here
4161 (for C and C++ anyway) will be array types and function types. */
4163 return is_tagged_type (type)
4164 ? (TYPE_CONTEXT (type) == scope
4165 /* Ignore namespaces for the moment. */
4166 || (scope == NULL_TREE
4167 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4168 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4169 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4170 : (scope == NULL_TREE || ! is_tagged_type (scope));
4173 /* Output any pending types (from the pending_types list) which we can output
4174 now (taking into account the scope that we are working on now).
4176 For each type output, remove the given type from the pending_types_list
4177 *before* we try to output it.
4179 Note that we have to process the list in beginning-to-end order,
4180 because the call made here to output_type may cause yet more types
4181 to be added to the end of the list, and we may have to output some
4182 of them too. */
4184 static void
4185 output_pending_types_for_scope (containing_scope)
4186 register tree containing_scope;
4188 register unsigned i;
4190 for (i = 0; i < pending_types; )
4192 register tree type = pending_types_list[i];
4194 if (type_ok_for_scope (type, containing_scope))
4196 register tree *mover;
4197 register tree *limit;
4199 pending_types--;
4200 limit = &pending_types_list[pending_types];
4201 for (mover = &pending_types_list[i]; mover < limit; mover++)
4202 *mover = *(mover+1);
4204 /* Un-mark the type as having been output already (because it
4205 hasn't been, really). Then call output_type to generate a
4206 Dwarf representation of it. */
4208 TREE_ASM_WRITTEN (type) = 0;
4209 output_type (type, containing_scope);
4211 /* Don't increment the loop counter in this case because we
4212 have shifted all of the subsequent pending types down one
4213 element in the pending_types_list array. */
4215 else
4216 i++;
4220 /* Remember a type in the incomplete_types_list. */
4222 static void
4223 add_incomplete_type (type)
4224 tree type;
4226 if (incomplete_types == incomplete_types_allocated)
4228 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4229 incomplete_types_list
4230 = (tree *) xrealloc (incomplete_types_list,
4231 sizeof (tree) * incomplete_types_allocated);
4234 incomplete_types_list[incomplete_types++] = type;
4237 /* Walk through the list of incomplete types again, trying once more to
4238 emit full debugging info for them. */
4240 static void
4241 retry_incomplete_types ()
4243 register tree type;
4245 finalizing = 1;
4246 while (incomplete_types)
4248 --incomplete_types;
4249 type = incomplete_types_list[incomplete_types];
4250 output_type (type, NULL_TREE);
4254 static void
4255 output_type (type, containing_scope)
4256 register tree type;
4257 register tree containing_scope;
4259 if (type == 0 || type == error_mark_node)
4260 return;
4262 /* We are going to output a DIE to represent the unqualified version of
4263 this type (i.e. without any const or volatile qualifiers) so get
4264 the main variant (i.e. the unqualified version) of this type now. */
4266 type = type_main_variant (type);
4268 if (TREE_ASM_WRITTEN (type))
4270 if (finalizing && AGGREGATE_TYPE_P (type))
4272 register tree member;
4274 /* Some of our nested types might not have been defined when we
4275 were written out before; force them out now. */
4277 for (member = TYPE_FIELDS (type); member;
4278 member = TREE_CHAIN (member))
4279 if (TREE_CODE (member) == TYPE_DECL
4280 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4281 output_type (TREE_TYPE (member), containing_scope);
4283 return;
4286 /* If this is a nested type whose containing class hasn't been
4287 written out yet, writing it out will cover this one, too. */
4289 if (TYPE_CONTEXT (type)
4290 && TYPE_P (TYPE_CONTEXT (type))
4291 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4293 output_type (TYPE_CONTEXT (type), containing_scope);
4294 return;
4297 /* Don't generate any DIEs for this type now unless it is OK to do so
4298 (based upon what `type_ok_for_scope' tells us). */
4300 if (! type_ok_for_scope (type, containing_scope))
4302 pend_type (type);
4303 return;
4306 switch (TREE_CODE (type))
4308 case ERROR_MARK:
4309 break;
4311 case POINTER_TYPE:
4312 case REFERENCE_TYPE:
4313 /* Prevent infinite recursion in cases where this is a recursive
4314 type. Recursive types are possible in Ada. */
4315 TREE_ASM_WRITTEN (type) = 1;
4316 /* For these types, all that is required is that we output a DIE
4317 (or a set of DIEs) to represent the "basis" type. */
4318 output_type (TREE_TYPE (type), containing_scope);
4319 break;
4321 case OFFSET_TYPE:
4322 /* This code is used for C++ pointer-to-data-member types. */
4323 /* Output a description of the relevant class type. */
4324 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4325 /* Output a description of the type of the object pointed to. */
4326 output_type (TREE_TYPE (type), containing_scope);
4327 /* Now output a DIE to represent this pointer-to-data-member type
4328 itself. */
4329 output_die (output_ptr_to_mbr_type_die, type);
4330 break;
4332 case SET_TYPE:
4333 output_type (TYPE_DOMAIN (type), containing_scope);
4334 output_die (output_set_type_die, type);
4335 break;
4337 case FILE_TYPE:
4338 output_type (TREE_TYPE (type), containing_scope);
4339 abort (); /* No way to represent these in Dwarf yet! */
4340 break;
4342 case FUNCTION_TYPE:
4343 /* Force out return type (in case it wasn't forced out already). */
4344 output_type (TREE_TYPE (type), containing_scope);
4345 output_die (output_subroutine_type_die, type);
4346 output_formal_types (type);
4347 end_sibling_chain ();
4348 break;
4350 case METHOD_TYPE:
4351 /* Force out return type (in case it wasn't forced out already). */
4352 output_type (TREE_TYPE (type), containing_scope);
4353 output_die (output_subroutine_type_die, type);
4354 output_formal_types (type);
4355 end_sibling_chain ();
4356 break;
4358 case ARRAY_TYPE:
4359 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4361 output_type (TREE_TYPE (type), containing_scope);
4362 output_die (output_string_type_die, type);
4364 else
4366 register tree element_type;
4368 element_type = TREE_TYPE (type);
4369 while (TREE_CODE (element_type) == ARRAY_TYPE)
4370 element_type = TREE_TYPE (element_type);
4372 output_type (element_type, containing_scope);
4373 output_die (output_array_type_die, type);
4375 break;
4377 case ENUMERAL_TYPE:
4378 case RECORD_TYPE:
4379 case UNION_TYPE:
4380 case QUAL_UNION_TYPE:
4382 /* For a non-file-scope tagged type, we can always go ahead and
4383 output a Dwarf description of this type right now, even if
4384 the type in question is still incomplete, because if this
4385 local type *was* ever completed anywhere within its scope,
4386 that complete definition would already have been attached to
4387 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4388 node by the time we reach this point. That's true because of the
4389 way the front-end does its processing of file-scope declarations (of
4390 functions and class types) within which other types might be
4391 nested. The C and C++ front-ends always gobble up such "local
4392 scope" things en-mass before they try to output *any* debugging
4393 information for any of the stuff contained inside them and thus,
4394 we get the benefit here of what is (in effect) a pre-resolution
4395 of forward references to tagged types in local scopes.
4397 Note however that for file-scope tagged types we cannot assume
4398 that such pre-resolution of forward references has taken place.
4399 A given file-scope tagged type may appear to be incomplete when
4400 we reach this point, but it may yet be given a full definition
4401 (at file-scope) later on during compilation. In order to avoid
4402 generating a premature (and possibly incorrect) set of Dwarf
4403 DIEs for such (as yet incomplete) file-scope tagged types, we
4404 generate nothing at all for as-yet incomplete file-scope tagged
4405 types here unless we are making our special "finalization" pass
4406 for file-scope things at the very end of compilation. At that
4407 time, we will certainly know as much about each file-scope tagged
4408 type as we are ever going to know, so at that point in time, we
4409 can safely generate correct Dwarf descriptions for these file-
4410 scope tagged types. */
4412 if (!COMPLETE_TYPE_P (type)
4413 && (TYPE_CONTEXT (type) == NULL
4414 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4415 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4416 && !finalizing)
4418 /* We don't need to do this for function-local types. */
4419 if (! decl_function_context (TYPE_STUB_DECL (type)))
4420 add_incomplete_type (type);
4421 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4424 /* Prevent infinite recursion in cases where the type of some
4425 member of this type is expressed in terms of this type itself. */
4427 TREE_ASM_WRITTEN (type) = 1;
4429 /* Output a DIE to represent the tagged type itself. */
4431 switch (TREE_CODE (type))
4433 case ENUMERAL_TYPE:
4434 output_die (output_enumeration_type_die, type);
4435 return; /* a special case -- nothing left to do so just return */
4437 case RECORD_TYPE:
4438 output_die (output_structure_type_die, type);
4439 break;
4441 case UNION_TYPE:
4442 case QUAL_UNION_TYPE:
4443 output_die (output_union_type_die, type);
4444 break;
4446 default:
4447 abort (); /* Should never happen. */
4450 /* If this is not an incomplete type, output descriptions of
4451 each of its members.
4453 Note that as we output the DIEs necessary to represent the
4454 members of this record or union type, we will also be trying
4455 to output DIEs to represent the *types* of those members.
4456 However the `output_type' function (above) will specifically
4457 avoid generating type DIEs for member types *within* the list
4458 of member DIEs for this (containing) type execpt for those
4459 types (of members) which are explicitly marked as also being
4460 members of this (containing) type themselves. The g++ front-
4461 end can force any given type to be treated as a member of some
4462 other (containing) type by setting the TYPE_CONTEXT of the
4463 given (member) type to point to the TREE node representing the
4464 appropriate (containing) type.
4467 if (COMPLETE_TYPE_P (type))
4469 /* First output info about the base classes. */
4470 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4472 register tree bases = TYPE_BINFO_BASETYPES (type);
4473 register int n_bases = TREE_VEC_LENGTH (bases);
4474 register int i;
4476 for (i = 0; i < n_bases; i++)
4478 tree binfo = TREE_VEC_ELT (bases, i);
4479 output_type (BINFO_TYPE (binfo), containing_scope);
4480 output_die (output_inheritance_die, binfo);
4484 ++in_class;
4487 register tree normal_member;
4489 /* Now output info about the data members and type members. */
4491 for (normal_member = TYPE_FIELDS (type);
4492 normal_member;
4493 normal_member = TREE_CHAIN (normal_member))
4494 output_decl (normal_member, type);
4498 register tree func_member;
4500 /* Now output info about the function members (if any). */
4502 for (func_member = TYPE_METHODS (type);
4503 func_member;
4504 func_member = TREE_CHAIN (func_member))
4505 output_decl (func_member, type);
4508 --in_class;
4510 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4511 scopes (at least in C++) so we must now output any nested
4512 pending types which are local just to this type. */
4514 output_pending_types_for_scope (type);
4516 end_sibling_chain (); /* Terminate member chain. */
4519 break;
4521 case VOID_TYPE:
4522 case INTEGER_TYPE:
4523 case REAL_TYPE:
4524 case COMPLEX_TYPE:
4525 case BOOLEAN_TYPE:
4526 case CHAR_TYPE:
4527 break; /* No DIEs needed for fundamental types. */
4529 case LANG_TYPE: /* No Dwarf representation currently defined. */
4530 break;
4532 default:
4533 abort ();
4536 TREE_ASM_WRITTEN (type) = 1;
4539 static void
4540 output_tagged_type_instantiation (type)
4541 register tree type;
4543 if (type == 0 || type == error_mark_node)
4544 return;
4546 /* We are going to output a DIE to represent the unqualified version of
4547 this type (i.e. without any const or volatile qualifiers) so make
4548 sure that we have the main variant (i.e. the unqualified version) of
4549 this type now. */
4551 if (type != type_main_variant (type))
4552 abort ();
4554 if (!TREE_ASM_WRITTEN (type))
4555 abort ();
4557 switch (TREE_CODE (type))
4559 case ERROR_MARK:
4560 break;
4562 case ENUMERAL_TYPE:
4563 output_die (output_inlined_enumeration_type_die, type);
4564 break;
4566 case RECORD_TYPE:
4567 output_die (output_inlined_structure_type_die, type);
4568 break;
4570 case UNION_TYPE:
4571 case QUAL_UNION_TYPE:
4572 output_die (output_inlined_union_type_die, type);
4573 break;
4575 default:
4576 abort (); /* Should never happen. */
4580 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4581 the things which are local to the given block. */
4583 static void
4584 output_block (stmt, depth)
4585 register tree stmt;
4586 int depth;
4588 register int must_output_die = 0;
4589 register tree origin;
4590 register enum tree_code origin_code;
4592 /* Ignore blocks never really used to make RTL. */
4594 if (! stmt || ! TREE_USED (stmt)
4595 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
4596 return;
4598 /* Determine the "ultimate origin" of this block. This block may be an
4599 inlined instance of an inlined instance of inline function, so we
4600 have to trace all of the way back through the origin chain to find
4601 out what sort of node actually served as the original seed for the
4602 creation of the current block. */
4604 origin = block_ultimate_origin (stmt);
4605 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4607 /* Determine if we need to output any Dwarf DIEs at all to represent this
4608 block. */
4610 if (origin_code == FUNCTION_DECL)
4611 /* The outer scopes for inlinings *must* always be represented. We
4612 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4613 must_output_die = 1;
4614 else
4616 /* In the case where the current block represents an inlining of the
4617 "body block" of an inline function, we must *NOT* output any DIE
4618 for this block because we have already output a DIE to represent
4619 the whole inlined function scope and the "body block" of any
4620 function doesn't really represent a different scope according to
4621 ANSI C rules. So we check here to make sure that this block does
4622 not represent a "body block inlining" before trying to set the
4623 `must_output_die' flag. */
4625 if (! is_body_block (origin ? origin : stmt))
4627 /* Determine if this block directly contains any "significant"
4628 local declarations which we will need to output DIEs for. */
4630 if (debug_info_level > DINFO_LEVEL_TERSE)
4631 /* We are not in terse mode so *any* local declaration counts
4632 as being a "significant" one. */
4633 must_output_die = (BLOCK_VARS (stmt) != NULL);
4634 else
4636 register tree decl;
4638 /* We are in terse mode, so only local (nested) function
4639 definitions count as "significant" local declarations. */
4641 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4642 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4644 must_output_die = 1;
4645 break;
4651 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4652 DIE for any block which contains no significant local declarations
4653 at all. Rather, in such cases we just call `output_decls_for_scope'
4654 so that any needed Dwarf info for any sub-blocks will get properly
4655 generated. Note that in terse mode, our definition of what constitutes
4656 a "significant" local declaration gets restricted to include only
4657 inlined function instances and local (nested) function definitions. */
4659 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4660 /* We don't care about an abstract inlined subroutine. */;
4661 else if (must_output_die)
4663 output_die ((origin_code == FUNCTION_DECL)
4664 ? output_inlined_subroutine_die
4665 : output_lexical_block_die,
4666 stmt);
4667 output_decls_for_scope (stmt, depth);
4668 end_sibling_chain ();
4670 else
4671 output_decls_for_scope (stmt, depth);
4674 /* Output all of the decls declared within a given scope (also called
4675 a `binding contour') and (recursively) all of it's sub-blocks. */
4677 static void
4678 output_decls_for_scope (stmt, depth)
4679 register tree stmt;
4680 int depth;
4682 /* Ignore blocks never really used to make RTL. */
4684 if (! stmt || ! TREE_USED (stmt))
4685 return;
4687 /* Output the DIEs to represent all of the data objects, functions,
4688 typedefs, and tagged types declared directly within this block
4689 but not within any nested sub-blocks. */
4692 register tree decl;
4694 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4695 output_decl (decl, stmt);
4698 output_pending_types_for_scope (stmt);
4700 /* Output the DIEs to represent all sub-blocks (and the items declared
4701 therein) of this block. */
4704 register tree subblocks;
4706 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4707 subblocks;
4708 subblocks = BLOCK_CHAIN (subblocks))
4709 output_block (subblocks, depth + 1);
4713 /* Is this a typedef we can avoid emitting? */
4715 inline static int
4716 is_redundant_typedef (decl)
4717 register tree decl;
4719 if (TYPE_DECL_IS_STUB (decl))
4720 return 1;
4721 if (DECL_ARTIFICIAL (decl)
4722 && DECL_CONTEXT (decl)
4723 && is_tagged_type (DECL_CONTEXT (decl))
4724 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4725 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4726 /* Also ignore the artificial member typedef for the class name. */
4727 return 1;
4728 return 0;
4731 /* Output Dwarf .debug information for a decl described by DECL. */
4733 static void
4734 output_decl (decl, containing_scope)
4735 register tree decl;
4736 register tree containing_scope;
4738 /* Make a note of the decl node we are going to be working on. We may
4739 need to give the user the source coordinates of where it appeared in
4740 case we notice (later on) that something about it looks screwy. */
4742 dwarf_last_decl = decl;
4744 if (TREE_CODE (decl) == ERROR_MARK)
4745 return;
4747 /* If a structure is declared within an initialization, e.g. as the
4748 operand of a sizeof, then it will not have a name. We don't want
4749 to output a DIE for it, as the tree nodes are in the temporary obstack */
4751 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4752 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4753 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4754 || (TYPE_FIELDS (TREE_TYPE (decl))
4755 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4756 return;
4758 /* If this ..._DECL node is marked to be ignored, then ignore it. */
4760 if (DECL_IGNORED_P (decl))
4761 return;
4763 switch (TREE_CODE (decl))
4765 case CONST_DECL:
4766 /* The individual enumerators of an enum type get output when we
4767 output the Dwarf representation of the relevant enum type itself. */
4768 break;
4770 case FUNCTION_DECL:
4771 /* If we are in terse mode, don't output any DIEs to represent
4772 mere function declarations. Also, if we are conforming
4773 to the DWARF version 1 specification, don't output DIEs for
4774 mere function declarations. */
4776 if (DECL_INITIAL (decl) == NULL_TREE)
4777 #if (DWARF_VERSION > 1)
4778 if (debug_info_level <= DINFO_LEVEL_TERSE)
4779 #endif
4780 break;
4782 /* Before we describe the FUNCTION_DECL itself, make sure that we
4783 have described its return type. */
4785 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4788 /* And its containing type. */
4789 register tree origin = decl_class_context (decl);
4790 if (origin)
4791 output_type (origin, containing_scope);
4794 /* If we're emitting an out-of-line copy of an inline function,
4795 set up to refer to the abstract instance emitted from
4796 note_deferral_of_defined_inline_function. */
4797 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
4798 && ! (containing_scope && TYPE_P (containing_scope)))
4799 set_decl_origin_self (decl);
4801 /* If the following DIE will represent a function definition for a
4802 function with "extern" linkage, output a special "pubnames" DIE
4803 label just ahead of the actual DIE. A reference to this label
4804 was already generated in the .debug_pubnames section sub-entry
4805 for this function definition. */
4807 if (TREE_PUBLIC (decl))
4809 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4811 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4812 ASM_OUTPUT_LABEL (asm_out_file, label);
4815 /* Now output a DIE to represent the function itself. */
4817 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4818 ? output_global_subroutine_die
4819 : output_local_subroutine_die,
4820 decl);
4822 /* Now output descriptions of the arguments for this function.
4823 This gets (unnecessarily?) complex because of the fact that
4824 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4825 cases where there was a trailing `...' at the end of the formal
4826 parameter list. In order to find out if there was a trailing
4827 ellipsis or not, we must instead look at the type associated
4828 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4829 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4830 ends with a void_type_node then there should *not* be an ellipsis
4831 at the end. */
4833 /* In the case where we are describing a mere function declaration, all
4834 we need to do here (and all we *can* do here) is to describe
4835 the *types* of its formal parameters. */
4837 if (decl != current_function_decl || in_class)
4838 output_formal_types (TREE_TYPE (decl));
4839 else
4841 /* Generate DIEs to represent all known formal parameters */
4843 register tree arg_decls = DECL_ARGUMENTS (decl);
4844 register tree parm;
4846 /* WARNING! Kludge zone ahead! Here we have a special
4847 hack for svr4 SDB compatibility. Instead of passing the
4848 current FUNCTION_DECL node as the second parameter (i.e.
4849 the `containing_scope' parameter) to `output_decl' (as
4850 we ought to) we instead pass a pointer to our own private
4851 fake_containing_scope node. That node is a RECORD_TYPE
4852 node which NO OTHER TYPE may ever actually be a member of.
4854 This pointer will ultimately get passed into `output_type'
4855 as its `containing_scope' parameter. `Output_type' will
4856 then perform its part in the hack... i.e. it will pend
4857 the type of the formal parameter onto the pending_types
4858 list. Later on, when we are done generating the whole
4859 sequence of formal parameter DIEs for this function
4860 definition, we will un-pend all previously pended types
4861 of formal parameters for this function definition.
4863 This whole kludge prevents any type DIEs from being
4864 mixed in with the formal parameter DIEs. That's good
4865 because svr4 SDB believes that the list of formal
4866 parameter DIEs for a function ends wherever the first
4867 non-formal-parameter DIE appears. Thus, we have to
4868 keep the formal parameter DIEs segregated. They must
4869 all appear (consecutively) at the start of the list of
4870 children for the DIE representing the function definition.
4871 Then (and only then) may we output any additional DIEs
4872 needed to represent the types of these formal parameters.
4876 When generating DIEs, generate the unspecified_parameters
4877 DIE instead if we come across the arg "__builtin_va_alist"
4880 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4881 if (TREE_CODE (parm) == PARM_DECL)
4883 if (DECL_NAME(parm) &&
4884 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4885 "__builtin_va_alist") )
4886 output_die (output_unspecified_parameters_die, decl);
4887 else
4888 output_decl (parm, fake_containing_scope);
4892 Now that we have finished generating all of the DIEs to
4893 represent the formal parameters themselves, force out
4894 any DIEs needed to represent their types. We do this
4895 simply by un-pending all previously pended types which
4896 can legitimately go into the chain of children DIEs for
4897 the current FUNCTION_DECL.
4900 output_pending_types_for_scope (decl);
4903 Decide whether we need a unspecified_parameters DIE at the end.
4904 There are 2 more cases to do this for:
4905 1) the ansi ... declaration - this is detectable when the end
4906 of the arg list is not a void_type_node
4907 2) an unprototyped function declaration (not a definition). This
4908 just means that we have no info about the parameters at all.
4912 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4914 if (fn_arg_types)
4916 /* this is the prototyped case, check for ... */
4917 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4918 output_die (output_unspecified_parameters_die, decl);
4920 else
4922 /* this is unprototyped, check for undefined (just declaration) */
4923 if (!DECL_INITIAL (decl))
4924 output_die (output_unspecified_parameters_die, decl);
4928 /* Output Dwarf info for all of the stuff within the body of the
4929 function (if it has one - it may be just a declaration). */
4932 register tree outer_scope = DECL_INITIAL (decl);
4934 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4936 /* Note that here, `outer_scope' is a pointer to the outermost
4937 BLOCK node created to represent a function.
4938 This outermost BLOCK actually represents the outermost
4939 binding contour for the function, i.e. the contour in which
4940 the function's formal parameters and labels get declared.
4942 Curiously, it appears that the front end doesn't actually
4943 put the PARM_DECL nodes for the current function onto the
4944 BLOCK_VARS list for this outer scope. (They are strung
4945 off of the DECL_ARGUMENTS list for the function instead.)
4946 The BLOCK_VARS list for the `outer_scope' does provide us
4947 with a list of the LABEL_DECL nodes for the function however,
4948 and we output DWARF info for those here.
4950 Just within the `outer_scope' there will be a BLOCK node
4951 representing the function's outermost pair of curly braces,
4952 and any blocks used for the base and member initializers of
4953 a C++ constructor function. */
4955 output_decls_for_scope (outer_scope, 0);
4957 /* Finally, force out any pending types which are local to the
4958 outermost block of this function definition. These will
4959 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4960 node itself. */
4962 output_pending_types_for_scope (decl);
4967 /* Generate a terminator for the list of stuff `owned' by this
4968 function. */
4970 end_sibling_chain ();
4972 break;
4974 case TYPE_DECL:
4975 /* If we are in terse mode, don't generate any DIEs to represent
4976 any actual typedefs. Note that even when we are in terse mode,
4977 we must still output DIEs to represent those tagged types which
4978 are used (directly or indirectly) in the specification of either
4979 a return type or a formal parameter type of some function. */
4981 if (debug_info_level <= DINFO_LEVEL_TERSE)
4982 if (! TYPE_DECL_IS_STUB (decl)
4983 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4984 return;
4986 /* In the special case of a TYPE_DECL node representing
4987 the declaration of some type tag, if the given TYPE_DECL is
4988 marked as having been instantiated from some other (original)
4989 TYPE_DECL node (e.g. one which was generated within the original
4990 definition of an inline function) we have to generate a special
4991 (abbreviated) TAG_structure_type, TAG_union_type, or
4992 TAG_enumeration-type DIE here. */
4994 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4996 output_tagged_type_instantiation (TREE_TYPE (decl));
4997 return;
5000 output_type (TREE_TYPE (decl), containing_scope);
5002 if (! is_redundant_typedef (decl))
5003 /* Output a DIE to represent the typedef itself. */
5004 output_die (output_typedef_die, decl);
5005 break;
5007 case LABEL_DECL:
5008 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5009 output_die (output_label_die, decl);
5010 break;
5012 case VAR_DECL:
5013 /* If we are conforming to the DWARF version 1 specification, don't
5014 generated any DIEs to represent mere external object declarations. */
5016 #if (DWARF_VERSION <= 1)
5017 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
5018 break;
5019 #endif
5021 /* If we are in terse mode, don't generate any DIEs to represent
5022 any variable declarations or definitions. */
5024 if (debug_info_level <= DINFO_LEVEL_TERSE)
5025 break;
5027 /* Output any DIEs that are needed to specify the type of this data
5028 object. */
5030 output_type (TREE_TYPE (decl), containing_scope);
5033 /* And its containing type. */
5034 register tree origin = decl_class_context (decl);
5035 if (origin)
5036 output_type (origin, containing_scope);
5039 /* If the following DIE will represent a data object definition for a
5040 data object with "extern" linkage, output a special "pubnames" DIE
5041 label just ahead of the actual DIE. A reference to this label
5042 was already generated in the .debug_pubnames section sub-entry
5043 for this data object definition. */
5045 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
5047 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5049 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
5050 ASM_OUTPUT_LABEL (asm_out_file, label);
5053 /* Now output the DIE to represent the data object itself. This gets
5054 complicated because of the possibility that the VAR_DECL really
5055 represents an inlined instance of a formal parameter for an inline
5056 function. */
5059 register void (*func) PARAMS ((void *));
5060 register tree origin = decl_ultimate_origin (decl);
5062 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5063 func = output_formal_parameter_die;
5064 else
5066 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5067 func = output_global_variable_die;
5068 else
5069 func = output_local_variable_die;
5071 output_die (func, decl);
5073 break;
5075 case FIELD_DECL:
5076 /* Ignore the nameless fields that are used to skip bits. */
5077 if (DECL_NAME (decl) != 0)
5079 output_type (member_declared_type (decl), containing_scope);
5080 output_die (output_member_die, decl);
5082 break;
5084 case PARM_DECL:
5085 /* Force out the type of this formal, if it was not forced out yet.
5086 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5087 It should be able to grok the presence of type DIEs within a list
5088 of TAG_formal_parameter DIEs, but it doesn't. */
5090 output_type (TREE_TYPE (decl), containing_scope);
5091 output_die (output_formal_parameter_die, decl);
5092 break;
5094 case NAMESPACE_DECL:
5095 /* Ignore for now. */
5096 break;
5098 default:
5099 abort ();
5103 void
5104 dwarfout_file_scope_decl (decl, set_finalizing)
5105 register tree decl;
5106 register int set_finalizing;
5108 if (TREE_CODE (decl) == ERROR_MARK)
5109 return;
5111 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5113 if (DECL_IGNORED_P (decl))
5114 return;
5116 switch (TREE_CODE (decl))
5118 case FUNCTION_DECL:
5120 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5121 a builtin function. Explicit programmer-supplied declarations of
5122 these same functions should NOT be ignored however. */
5124 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5125 return;
5127 /* What we would really like to do here is to filter out all mere
5128 file-scope declarations of file-scope functions which are never
5129 referenced later within this translation unit (and keep all of
5130 ones that *are* referenced later on) but we aren't clairvoyant,
5131 so we have no idea which functions will be referenced in the
5132 future (i.e. later on within the current translation unit).
5133 So here we just ignore all file-scope function declarations
5134 which are not also definitions. If and when the debugger needs
5135 to know something about these functions, it wil have to hunt
5136 around and find the DWARF information associated with the
5137 *definition* of the function.
5139 Note that we can't just check `DECL_EXTERNAL' to find out which
5140 FUNCTION_DECL nodes represent definitions and which ones represent
5141 mere declarations. We have to check `DECL_INITIAL' instead. That's
5142 because the C front-end supports some weird semantics for "extern
5143 inline" function definitions. These can get inlined within the
5144 current translation unit (an thus, we need to generate DWARF info
5145 for their abstract instances so that the DWARF info for the
5146 concrete inlined instances can have something to refer to) but
5147 the compiler never generates any out-of-lines instances of such
5148 things (despite the fact that they *are* definitions). The
5149 important point is that the C front-end marks these "extern inline"
5150 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5151 anyway.
5153 Note that the C++ front-end also plays some similar games for inline
5154 function definitions appearing within include files which also
5155 contain `#pragma interface' pragmas. */
5157 if (DECL_INITIAL (decl) == NULL_TREE)
5158 return;
5160 if (TREE_PUBLIC (decl)
5161 && ! DECL_EXTERNAL (decl)
5162 && ! DECL_ABSTRACT (decl))
5164 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5166 /* Output a .debug_pubnames entry for a public function
5167 defined in this compilation unit. */
5169 fputc ('\n', asm_out_file);
5170 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5171 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5172 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5173 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5174 IDENTIFIER_POINTER (DECL_NAME (decl)));
5175 ASM_OUTPUT_POP_SECTION (asm_out_file);
5178 break;
5180 case VAR_DECL:
5182 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5183 object declaration and if the declaration was never even
5184 referenced from within this entire compilation unit. We
5185 suppress these DIEs in order to save space in the .debug section
5186 (by eliminating entries which are probably useless). Note that
5187 we must not suppress block-local extern declarations (whether
5188 used or not) because that would screw-up the debugger's name
5189 lookup mechanism and cause it to miss things which really ought
5190 to be in scope at a given point. */
5192 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5193 return;
5195 if (TREE_PUBLIC (decl)
5196 && ! DECL_EXTERNAL (decl)
5197 && GET_CODE (DECL_RTL (decl)) == MEM
5198 && ! DECL_ABSTRACT (decl))
5200 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5202 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5204 /* Output a .debug_pubnames entry for a public variable
5205 defined in this compilation unit. */
5207 fputc ('\n', asm_out_file);
5208 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5209 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5210 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5211 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5212 IDENTIFIER_POINTER (DECL_NAME (decl)));
5213 ASM_OUTPUT_POP_SECTION (asm_out_file);
5216 if (DECL_INITIAL (decl) == NULL)
5218 /* Output a .debug_aranges entry for a public variable
5219 which is tentatively defined in this compilation unit. */
5221 fputc ('\n', asm_out_file);
5222 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5223 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5224 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5225 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5226 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5227 ASM_OUTPUT_POP_SECTION (asm_out_file);
5231 /* If we are in terse mode, don't generate any DIEs to represent
5232 any variable declarations or definitions. */
5234 if (debug_info_level <= DINFO_LEVEL_TERSE)
5235 return;
5237 break;
5239 case TYPE_DECL:
5240 /* Don't bother trying to generate any DIEs to represent any of the
5241 normal built-in types for the language we are compiling, except
5242 in cases where the types in question are *not* DWARF fundamental
5243 types. We make an exception in the case of non-fundamental types
5244 for the sake of objective C (and perhaps C++) because the GNU
5245 front-ends for these languages may in fact create certain "built-in"
5246 types which are (for example) RECORD_TYPEs. In such cases, we
5247 really need to output these (non-fundamental) types because other
5248 DIEs may contain references to them. */
5250 /* Also ignore language dependent types here, because they are probably
5251 also built-in types. If we didn't ignore them, then we would get
5252 references to undefined labels because output_type doesn't support
5253 them. So, for now, we need to ignore them to avoid assembler
5254 errors. */
5256 /* ??? This code is different than the equivalent code in dwarf2out.c.
5257 The dwarf2out.c code is probably more correct. */
5259 if (DECL_SOURCE_LINE (decl) == 0
5260 && (type_is_fundamental (TREE_TYPE (decl))
5261 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5262 return;
5264 /* If we are in terse mode, don't generate any DIEs to represent
5265 any actual typedefs. Note that even when we are in terse mode,
5266 we must still output DIEs to represent those tagged types which
5267 are used (directly or indirectly) in the specification of either
5268 a return type or a formal parameter type of some function. */
5270 if (debug_info_level <= DINFO_LEVEL_TERSE)
5271 if (! TYPE_DECL_IS_STUB (decl)
5272 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5273 return;
5275 break;
5277 default:
5278 return;
5281 fputc ('\n', asm_out_file);
5282 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5283 finalizing = set_finalizing;
5284 output_decl (decl, NULL_TREE);
5286 /* NOTE: The call above to `output_decl' may have caused one or more
5287 file-scope named types (i.e. tagged types) to be placed onto the
5288 pending_types_list. We have to get those types off of that list
5289 at some point, and this is the perfect time to do it. If we didn't
5290 take them off now, they might still be on the list when cc1 finally
5291 exits. That might be OK if it weren't for the fact that when we put
5292 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5293 for these types, and that causes them never to be output unless
5294 `output_pending_types_for_scope' takes them off of the list and un-sets
5295 their TREE_ASM_WRITTEN flags. */
5297 output_pending_types_for_scope (NULL_TREE);
5299 /* The above call should have totally emptied the pending_types_list
5300 if this is not a nested function or class. If this is a nested type,
5301 then the remaining pending_types will be emitted when the containing type
5302 is handled. */
5304 if (! DECL_CONTEXT (decl))
5306 if (pending_types != 0)
5307 abort ();
5310 ASM_OUTPUT_POP_SECTION (asm_out_file);
5312 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5313 current_funcdef_number++;
5316 /* Output a marker (i.e. a label) for the beginning of the generated code
5317 for a lexical block. */
5319 void
5320 dwarfout_begin_block (blocknum)
5321 register unsigned blocknum;
5323 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5325 function_section (current_function_decl);
5326 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5327 ASM_OUTPUT_LABEL (asm_out_file, label);
5330 /* Output a marker (i.e. a label) for the end of the generated code
5331 for a lexical block. */
5333 void
5334 dwarfout_end_block (blocknum)
5335 register unsigned blocknum;
5337 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5339 function_section (current_function_decl);
5340 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5341 ASM_OUTPUT_LABEL (asm_out_file, label);
5344 /* Output a marker (i.e. a label) at a point in the assembly code which
5345 corresponds to a given source level label. */
5347 void
5348 dwarfout_label (insn)
5349 register rtx insn;
5351 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5353 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5355 function_section (current_function_decl);
5356 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
5357 (unsigned) INSN_UID (insn));
5358 ASM_OUTPUT_LABEL (asm_out_file, label);
5362 /* Output a marker (i.e. a label) for the point in the generated code where
5363 the real body of the function begins (after parameters have been moved
5364 to their home locations). */
5366 void
5367 dwarfout_begin_function ()
5369 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5371 if (! use_gnu_debug_info_extensions)
5372 return;
5373 function_section (current_function_decl);
5374 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5375 ASM_OUTPUT_LABEL (asm_out_file, label);
5378 /* Output a marker (i.e. a label) for the point in the generated code where
5379 the real body of the function ends (just before the epilogue code). */
5381 void
5382 dwarfout_end_function ()
5384 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5386 if (! use_gnu_debug_info_extensions)
5387 return;
5388 function_section (current_function_decl);
5389 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5390 ASM_OUTPUT_LABEL (asm_out_file, label);
5393 /* Output a marker (i.e. a label) for the absolute end of the generated code
5394 for a function definition. This gets called *after* the epilogue code
5395 has been generated. */
5397 void
5398 dwarfout_end_epilogue ()
5400 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5402 /* Output a label to mark the endpoint of the code generated for this
5403 function. */
5405 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5406 ASM_OUTPUT_LABEL (asm_out_file, label);
5409 static void
5410 shuffle_filename_entry (new_zeroth)
5411 register filename_entry *new_zeroth;
5413 filename_entry temp_entry;
5414 register filename_entry *limit_p;
5415 register filename_entry *move_p;
5417 if (new_zeroth == &filename_table[0])
5418 return;
5420 temp_entry = *new_zeroth;
5422 /* Shift entries up in the table to make room at [0]. */
5424 limit_p = &filename_table[0];
5425 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5426 *move_p = *(move_p-1);
5428 /* Install the found entry at [0]. */
5430 filename_table[0] = temp_entry;
5433 /* Create a new (string) entry for the .debug_sfnames section. */
5435 static void
5436 generate_new_sfname_entry ()
5438 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5440 fputc ('\n', asm_out_file);
5441 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5442 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5443 ASM_OUTPUT_LABEL (asm_out_file, label);
5444 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5445 filename_table[0].name
5446 ? filename_table[0].name
5447 : "");
5448 ASM_OUTPUT_POP_SECTION (asm_out_file);
5451 /* Lookup a filename (in the list of filenames that we know about here in
5452 dwarfout.c) and return its "index". The index of each (known) filename
5453 is just a unique number which is associated with only that one filename.
5454 We need such numbers for the sake of generating labels (in the
5455 .debug_sfnames section) and references to those unique labels (in the
5456 .debug_srcinfo and .debug_macinfo sections).
5458 If the filename given as an argument is not found in our current list,
5459 add it to the list and assign it the next available unique index number.
5461 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5462 one), we shuffle the filename found (or added) up to the zeroth entry of
5463 our list of filenames (which is always searched linearly). We do this so
5464 as to optimize the most common case for these filename lookups within
5465 dwarfout.c. The most common case by far is the case where we call
5466 lookup_filename to lookup the very same filename that we did a lookup
5467 on the last time we called lookup_filename. We make sure that this
5468 common case is fast because such cases will constitute 99.9% of the
5469 lookups we ever do (in practice).
5471 If we add a new filename entry to our table, we go ahead and generate
5472 the corresponding entry in the .debug_sfnames section right away.
5473 Doing so allows us to avoid tickling an assembler bug (present in some
5474 m68k assemblers) which yields assembly-time errors in cases where the
5475 difference of two label addresses is taken and where the two labels
5476 are in a section *other* than the one where the difference is being
5477 calculated, and where at least one of the two symbol references is a
5478 forward reference. (This bug could be tickled by our .debug_srcinfo
5479 entries if we don't output their corresponding .debug_sfnames entries
5480 before them.) */
5482 static unsigned
5483 lookup_filename (file_name)
5484 const char *file_name;
5486 register filename_entry *search_p;
5487 register filename_entry *limit_p = &filename_table[ft_entries];
5489 for (search_p = filename_table; search_p < limit_p; search_p++)
5490 if (!strcmp (file_name, search_p->name))
5492 /* When we get here, we have found the filename that we were
5493 looking for in the filename_table. Now we want to make sure
5494 that it gets moved to the zero'th entry in the table (if it
5495 is not already there) so that subsequent attempts to find the
5496 same filename will find it as quickly as possible. */
5498 shuffle_filename_entry (search_p);
5499 return filename_table[0].number;
5502 /* We come here whenever we have a new filename which is not registered
5503 in the current table. Here we add it to the table. */
5505 /* Prepare to add a new table entry by making sure there is enough space
5506 in the table to do so. If not, expand the current table. */
5508 if (ft_entries == ft_entries_allocated)
5510 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5511 filename_table
5512 = (filename_entry *)
5513 xrealloc (filename_table,
5514 ft_entries_allocated * sizeof (filename_entry));
5517 /* Initially, add the new entry at the end of the filename table. */
5519 filename_table[ft_entries].number = ft_entries;
5520 filename_table[ft_entries].name = xstrdup (file_name);
5522 /* Shuffle the new entry into filename_table[0]. */
5524 shuffle_filename_entry (&filename_table[ft_entries]);
5526 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5527 generate_new_sfname_entry ();
5529 ft_entries++;
5530 return filename_table[0].number;
5533 static void
5534 generate_srcinfo_entry (line_entry_num, files_entry_num)
5535 unsigned line_entry_num;
5536 unsigned files_entry_num;
5538 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5540 fputc ('\n', asm_out_file);
5541 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5542 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5543 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5544 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5545 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5546 ASM_OUTPUT_POP_SECTION (asm_out_file);
5549 void
5550 dwarfout_line (filename, line)
5551 register const char *filename;
5552 register unsigned line;
5554 if (debug_info_level >= DINFO_LEVEL_NORMAL
5555 /* We can't emit line number info for functions in separate sections,
5556 because the assembler can't subtract labels in different sections. */
5557 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5559 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5560 static unsigned last_line_entry_num = 0;
5561 static unsigned prev_file_entry_num = (unsigned) -1;
5562 register unsigned this_file_entry_num;
5564 function_section (current_function_decl);
5565 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5566 ASM_OUTPUT_LABEL (asm_out_file, label);
5568 fputc ('\n', asm_out_file);
5570 if (use_gnu_debug_info_extensions)
5571 this_file_entry_num = lookup_filename (filename);
5572 else
5573 this_file_entry_num = (unsigned) -1;
5575 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5576 if (this_file_entry_num != prev_file_entry_num)
5578 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5580 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5581 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5585 register const char *tail = rindex (filename, '/');
5587 if (tail != NULL)
5588 filename = tail;
5591 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5592 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5593 filename, line);
5594 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5595 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5596 ASM_OUTPUT_POP_SECTION (asm_out_file);
5598 if (this_file_entry_num != prev_file_entry_num)
5599 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5600 prev_file_entry_num = this_file_entry_num;
5604 /* Generate an entry in the .debug_macinfo section. */
5606 static void
5607 generate_macinfo_entry (type_and_offset, string)
5608 register const char *type_and_offset;
5609 register const char *string;
5611 if (! use_gnu_debug_info_extensions)
5612 return;
5614 fputc ('\n', asm_out_file);
5615 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5616 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5617 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
5618 ASM_OUTPUT_POP_SECTION (asm_out_file);
5621 void
5622 dwarfout_start_new_source_file (filename)
5623 register const char *filename;
5625 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5626 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5628 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5629 sprintf (type_and_offset, "0x%08x+%s-%s",
5630 ((unsigned) MACINFO_start << 24),
5631 /* Hack: skip leading '*' . */
5632 (*label == '*') + label,
5633 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5634 generate_macinfo_entry (type_and_offset, "");
5637 void
5638 dwarfout_resume_previous_source_file (lineno)
5639 register unsigned lineno;
5641 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5643 sprintf (type_and_offset, "0x%08x+%u",
5644 ((unsigned) MACINFO_resume << 24), lineno);
5645 generate_macinfo_entry (type_and_offset, "");
5648 /* Called from check_newline in c-parse.y. The `buffer' parameter
5649 contains the tail part of the directive line, i.e. the part which
5650 is past the initial whitespace, #, whitespace, directive-name,
5651 whitespace part. */
5653 void
5654 dwarfout_define (lineno, buffer)
5655 register unsigned lineno;
5656 register const char *buffer;
5658 static int initialized = 0;
5659 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5661 if (!initialized)
5663 dwarfout_start_new_source_file (primary_filename);
5664 initialized = 1;
5666 sprintf (type_and_offset, "0x%08x+%u",
5667 ((unsigned) MACINFO_define << 24), lineno);
5668 generate_macinfo_entry (type_and_offset, buffer);
5671 /* Called from check_newline in c-parse.y. The `buffer' parameter
5672 contains the tail part of the directive line, i.e. the part which
5673 is past the initial whitespace, #, whitespace, directive-name,
5674 whitespace part. */
5676 void
5677 dwarfout_undef (lineno, buffer)
5678 register unsigned lineno;
5679 register const char *buffer;
5681 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5683 sprintf (type_and_offset, "0x%08x+%u",
5684 ((unsigned) MACINFO_undef << 24), lineno);
5685 generate_macinfo_entry (type_and_offset, buffer);
5688 /* Set up for Dwarf output at the start of compilation. */
5690 void
5691 dwarfout_init (asm_out_file, main_input_filename)
5692 register FILE *asm_out_file;
5693 register const char *main_input_filename;
5695 /* Remember the name of the primary input file. */
5697 primary_filename = main_input_filename;
5699 /* Allocate the initial hunk of the pending_sibling_stack. */
5701 pending_sibling_stack
5702 = (unsigned *)
5703 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5704 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5705 pending_siblings = 1;
5707 /* Allocate the initial hunk of the filename_table. */
5709 filename_table
5710 = (filename_entry *)
5711 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5712 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5713 ft_entries = 0;
5715 /* Allocate the initial hunk of the pending_types_list. */
5717 pending_types_list
5718 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5719 pending_types_allocated = PENDING_TYPES_INCREMENT;
5720 pending_types = 0;
5722 /* Create an artificial RECORD_TYPE node which we can use in our hack
5723 to get the DIEs representing types of formal parameters to come out
5724 only *after* the DIEs for the formal parameters themselves. */
5726 fake_containing_scope = make_node (RECORD_TYPE);
5728 /* Output a starting label for the .text section. */
5730 fputc ('\n', asm_out_file);
5731 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5732 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5733 ASM_OUTPUT_POP_SECTION (asm_out_file);
5735 /* Output a starting label for the .data section. */
5737 fputc ('\n', asm_out_file);
5738 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5739 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5740 ASM_OUTPUT_POP_SECTION (asm_out_file);
5742 #if 0 /* GNU C doesn't currently use .data1. */
5743 /* Output a starting label for the .data1 section. */
5745 fputc ('\n', asm_out_file);
5746 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5747 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5748 ASM_OUTPUT_POP_SECTION (asm_out_file);
5749 #endif
5751 /* Output a starting label for the .rodata section. */
5753 fputc ('\n', asm_out_file);
5754 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5755 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5756 ASM_OUTPUT_POP_SECTION (asm_out_file);
5758 #if 0 /* GNU C doesn't currently use .rodata1. */
5759 /* Output a starting label for the .rodata1 section. */
5761 fputc ('\n', asm_out_file);
5762 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5763 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5764 ASM_OUTPUT_POP_SECTION (asm_out_file);
5765 #endif
5767 /* Output a starting label for the .bss section. */
5769 fputc ('\n', asm_out_file);
5770 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5771 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5772 ASM_OUTPUT_POP_SECTION (asm_out_file);
5774 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5776 if (use_gnu_debug_info_extensions)
5778 /* Output a starting label and an initial (compilation directory)
5779 entry for the .debug_sfnames section. The starting label will be
5780 referenced by the initial entry in the .debug_srcinfo section. */
5782 fputc ('\n', asm_out_file);
5783 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5784 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5786 register const char *pwd = getpwd ();
5787 register char *dirname;
5789 if (!pwd)
5790 pfatal_with_name ("getpwd");
5791 dirname = concat (pwd, "/", NULL);
5792 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
5793 free (dirname);
5795 ASM_OUTPUT_POP_SECTION (asm_out_file);
5798 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5799 && use_gnu_debug_info_extensions)
5801 /* Output a starting label for the .debug_macinfo section. This
5802 label will be referenced by the AT_mac_info attribute in the
5803 TAG_compile_unit DIE. */
5805 fputc ('\n', asm_out_file);
5806 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5807 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5808 ASM_OUTPUT_POP_SECTION (asm_out_file);
5811 /* Generate the initial entry for the .line section. */
5813 fputc ('\n', asm_out_file);
5814 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5815 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5816 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5817 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5818 ASM_OUTPUT_POP_SECTION (asm_out_file);
5820 if (use_gnu_debug_info_extensions)
5822 /* Generate the initial entry for the .debug_srcinfo section. */
5824 fputc ('\n', asm_out_file);
5825 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5826 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5827 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5828 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5829 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5830 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5831 #ifdef DWARF_TIMESTAMPS
5832 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5833 #else
5834 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5835 #endif
5836 ASM_OUTPUT_POP_SECTION (asm_out_file);
5839 /* Generate the initial entry for the .debug_pubnames section. */
5841 fputc ('\n', asm_out_file);
5842 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5843 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5844 ASM_OUTPUT_POP_SECTION (asm_out_file);
5846 /* Generate the initial entry for the .debug_aranges section. */
5848 fputc ('\n', asm_out_file);
5849 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5850 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5851 ASM_OUTPUT_POP_SECTION (asm_out_file);
5854 /* Setup first DIE number == 1. */
5855 NEXT_DIE_NUM = next_unused_dienum++;
5857 /* Generate the initial DIE for the .debug section. Note that the
5858 (string) value given in the AT_name attribute of the TAG_compile_unit
5859 DIE will (typically) be a relative pathname and that this pathname
5860 should be taken as being relative to the directory from which the
5861 compiler was invoked when the given (base) source file was compiled. */
5863 fputc ('\n', asm_out_file);
5864 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5865 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5866 output_die (output_compile_unit_die, main_input_filename);
5867 ASM_OUTPUT_POP_SECTION (asm_out_file);
5869 fputc ('\n', asm_out_file);
5872 /* Output stuff that dwarf requires at the end of every file. */
5874 void
5875 dwarfout_finish ()
5877 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5879 fputc ('\n', asm_out_file);
5880 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5881 retry_incomplete_types ();
5882 fputc ('\n', asm_out_file);
5884 /* Mark the end of the chain of siblings which represent all file-scope
5885 declarations in this compilation unit. */
5887 /* The (null) DIE which represents the terminator for the (sibling linked)
5888 list of file-scope items is *special*. Normally, we would just call
5889 end_sibling_chain at this point in order to output a word with the
5890 value `4' and that word would act as the terminator for the list of
5891 DIEs describing file-scope items. Unfortunately, if we were to simply
5892 do that, the label that would follow this DIE in the .debug section
5893 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5894 machines) to a 4 byte boundary.
5896 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5897 the trick used is to insert extra (otherwise useless) padding bytes
5898 into the (null) DIE that we know must precede the ..D2 label in the
5899 .debug section. The amount of padding required can be anywhere between
5900 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5901 with the padding) would normally contain the value 4, but now it will
5902 also have to include the padding bytes, so it will instead have some
5903 value in the range 4..7.
5905 Fortunately, the rules of Dwarf say that any DIE whose length word
5906 contains *any* value less than 8 should be treated as a null DIE, so
5907 this trick works out nicely. Clever, eh? Don't give me any credit
5908 (or blame). I didn't think of this scheme. I just conformed to it.
5911 output_die (output_padded_null_die, (void *) 0);
5912 dienum_pop ();
5914 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5915 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5916 ASM_OUTPUT_POP_SECTION (asm_out_file);
5918 /* Output a terminator label for the .text section. */
5920 fputc ('\n', asm_out_file);
5921 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5922 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5923 ASM_OUTPUT_POP_SECTION (asm_out_file);
5925 /* Output a terminator label for the .data section. */
5927 fputc ('\n', asm_out_file);
5928 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5929 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5930 ASM_OUTPUT_POP_SECTION (asm_out_file);
5932 #if 0 /* GNU C doesn't currently use .data1. */
5933 /* Output a terminator label for the .data1 section. */
5935 fputc ('\n', asm_out_file);
5936 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5937 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5938 ASM_OUTPUT_POP_SECTION (asm_out_file);
5939 #endif
5941 /* Output a terminator label for the .rodata section. */
5943 fputc ('\n', asm_out_file);
5944 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5945 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5946 ASM_OUTPUT_POP_SECTION (asm_out_file);
5948 #if 0 /* GNU C doesn't currently use .rodata1. */
5949 /* Output a terminator label for the .rodata1 section. */
5951 fputc ('\n', asm_out_file);
5952 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5953 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5954 ASM_OUTPUT_POP_SECTION (asm_out_file);
5955 #endif
5957 /* Output a terminator label for the .bss section. */
5959 fputc ('\n', asm_out_file);
5960 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5961 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5962 ASM_OUTPUT_POP_SECTION (asm_out_file);
5964 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5966 /* Output a terminating entry for the .line section. */
5968 fputc ('\n', asm_out_file);
5969 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5970 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5971 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5972 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5973 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5974 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5975 ASM_OUTPUT_POP_SECTION (asm_out_file);
5977 if (use_gnu_debug_info_extensions)
5979 /* Output a terminating entry for the .debug_srcinfo section. */
5981 fputc ('\n', asm_out_file);
5982 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5983 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5984 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5985 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5986 ASM_OUTPUT_POP_SECTION (asm_out_file);
5989 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5991 /* Output terminating entries for the .debug_macinfo section. */
5993 dwarfout_resume_previous_source_file (0);
5995 fputc ('\n', asm_out_file);
5996 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5997 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5998 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
5999 ASM_OUTPUT_POP_SECTION (asm_out_file);
6002 /* Generate the terminating entry for the .debug_pubnames section. */
6004 fputc ('\n', asm_out_file);
6005 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
6006 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6007 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
6008 ASM_OUTPUT_POP_SECTION (asm_out_file);
6010 /* Generate the terminating entries for the .debug_aranges section.
6012 Note that we want to do this only *after* we have output the end
6013 labels (for the various program sections) which we are going to
6014 refer to here. This allows us to work around a bug in the m68k
6015 svr4 assembler. That assembler gives bogus assembly-time errors
6016 if (within any given section) you try to take the difference of
6017 two relocatable symbols, both of which are located within some
6018 other section, and if one (or both?) of the symbols involved is
6019 being forward-referenced. By generating the .debug_aranges
6020 entries at this late point in the assembly output, we skirt the
6021 issue simply by avoiding forward-references.
6024 fputc ('\n', asm_out_file);
6025 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
6027 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
6028 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
6030 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
6031 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
6033 #if 0 /* GNU C doesn't currently use .data1. */
6034 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
6035 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
6036 DATA1_BEGIN_LABEL);
6037 #endif
6039 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
6040 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
6041 RODATA_BEGIN_LABEL);
6043 #if 0 /* GNU C doesn't currently use .rodata1. */
6044 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
6045 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
6046 RODATA1_BEGIN_LABEL);
6047 #endif
6049 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
6050 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
6052 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6053 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
6055 ASM_OUTPUT_POP_SECTION (asm_out_file);
6058 /* There should not be any pending types left at the end. We need
6059 this now because it may not have been checked on the last call to
6060 dwarfout_file_scope_decl. */
6061 if (pending_types != 0)
6062 abort ();
6065 #endif /* DWARF_DEBUGGING_INFO */