* invoke.texi: Document that -fcond-mismatch isn't supported for
[official-gcc.git] / gcc / dwarfout.c
blobe339820e87dac211c1cb592ffcf284bd374c11ad
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 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
41 regarding the GNU implementation of Dwarf. */
43 /* NOTE: In the comments in this file, many references are made to
44 so called "Debugging Information Entries". For the sake of brevity,
45 this term is abbreviated to `DIE' throughout the remainder of this
46 file. */
48 /* Note that the implementation of C++ support herein is (as yet) unfinished.
49 If you want to try to complete it, more power to you. */
51 /* How to start an assembler comment. */
52 #ifndef ASM_COMMENT_START
53 #define ASM_COMMENT_START ";#"
54 #endif
56 /* How to print out a register name. */
57 #ifndef PRINT_REG
58 #define PRINT_REG(RTX, CODE, FILE) \
59 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
60 #endif
62 /* Define a macro which returns non-zero for any tagged type which is
63 used (directly or indirectly) in the specification of either some
64 function's return type or some formal parameter of some function.
65 We use this macro when we are operating in "terse" mode to help us
66 know what tagged types have to be represented in Dwarf (even in
67 terse mode) and which ones don't.
69 A flag bit with this meaning really should be a part of the normal
70 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
71 for these nodes. For now, we have to just fake it. It it safe for
72 us to simply return zero for all complete tagged types (which will
73 get forced out anyway if they were used in the specification of some
74 formal or return type) and non-zero for all incomplete tagged types.
77 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
79 /* Define a macro which returns non-zero for a TYPE_DECL which was
80 implicitly generated for a tagged type.
82 Note that unlike the gcc front end (which generates a NULL named
83 TYPE_DECL node for each complete tagged type, each array type, and
84 each function type node created) the g++ front end generates a
85 _named_ TYPE_DECL node for each tagged type node created.
86 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
87 generate a DW_TAG_typedef DIE for them. */
88 #define TYPE_DECL_IS_STUB(decl) \
89 (DECL_NAME (decl) == NULL \
90 || (DECL_ARTIFICIAL (decl) \
91 && is_tagged_type (TREE_TYPE (decl)) \
92 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
94 extern int flag_traditional;
96 /* Maximum size (in bytes) of an artificially generated label. */
98 #define MAX_ARTIFICIAL_LABEL_BYTES 30
100 /* Structure to keep track of source filenames. */
102 struct filename_entry {
103 unsigned number;
104 const char * name;
107 typedef struct filename_entry filename_entry;
109 /* Pointer to an array of elements, each one having the structure above. */
111 static filename_entry *filename_table;
113 /* Total number of entries in the table (i.e. array) pointed to by
114 `filename_table'. This is the *total* and includes both used and
115 unused slots. */
117 static unsigned ft_entries_allocated;
119 /* Number of entries in the filename_table which are actually in use. */
121 static unsigned ft_entries;
123 /* Size (in elements) of increments by which we may expand the filename
124 table. Actually, a single hunk of space of this size should be enough
125 for most typical programs. */
127 #define FT_ENTRIES_INCREMENT 64
129 /* Local pointer to the name of the main input file. Initialized in
130 dwarfout_init. */
132 static const char *primary_filename;
134 /* Pointer to the most recent filename for which we produced some line info. */
136 static const char *last_filename;
138 /* Counter to generate unique names for DIEs. */
140 static unsigned next_unused_dienum = 1;
142 /* Number of the DIE which is currently being generated. */
144 static unsigned current_dienum;
146 /* Number to use for the special "pubname" label on the next DIE which
147 represents a function or data object defined in this compilation
148 unit which has "extern" linkage. */
150 static int next_pubname_number = 0;
152 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
154 /* Pointer to a dynamically allocated list of pre-reserved and still
155 pending sibling DIE numbers. Note that this list will grow as needed. */
157 static unsigned *pending_sibling_stack;
159 /* Counter to keep track of the number of pre-reserved and still pending
160 sibling DIE numbers. */
162 static unsigned pending_siblings;
164 /* The currently allocated size of the above list (expressed in number of
165 list elements). */
167 static unsigned pending_siblings_allocated;
169 /* Size (in elements) of increments by which we may expand the pending
170 sibling stack. Actually, a single hunk of space of this size should
171 be enough for most typical programs. */
173 #define PENDING_SIBLINGS_INCREMENT 64
175 /* Non-zero if we are performing our file-scope finalization pass and if
176 we should force out Dwarf descriptions of any and all file-scope
177 tagged types which are still incomplete types. */
179 static int finalizing = 0;
181 /* A pointer to the base of a list of pending types which we haven't
182 generated DIEs for yet, but which we will have to come back to
183 later on. */
185 static tree *pending_types_list;
187 /* Number of elements currently allocated for the pending_types_list. */
189 static unsigned pending_types_allocated;
191 /* Number of elements of pending_types_list currently in use. */
193 static unsigned pending_types;
195 /* Size (in elements) of increments by which we may expand the pending
196 types list. Actually, a single hunk of space of this size should
197 be enough for most typical programs. */
199 #define PENDING_TYPES_INCREMENT 64
201 /* A pointer to the base of a list of incomplete types which might be
202 completed at some later time. */
204 static tree *incomplete_types_list;
206 /* Number of elements currently allocated for the incomplete_types_list. */
207 static unsigned incomplete_types_allocated;
209 /* Number of elements of incomplete_types_list currently in use. */
210 static unsigned incomplete_types;
212 /* Size (in elements) of increments by which we may expand the incomplete
213 types list. Actually, a single hunk of space of this size should
214 be enough for most typical programs. */
215 #define INCOMPLETE_TYPES_INCREMENT 64
217 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
218 This is used in a hack to help us get the DIEs describing types of
219 formal parameters to come *after* all of the DIEs describing the formal
220 parameters themselves. That's necessary in order to be compatible
221 with what the brain-damaged svr4 SDB debugger requires. */
223 static tree fake_containing_scope;
225 /* The number of the current function definition that we are generating
226 debugging information for. These numbers range from 1 up to the maximum
227 number of function definitions contained within the current compilation
228 unit. These numbers are used to create unique labels for various things
229 contained within various function definitions. */
231 static unsigned current_funcdef_number = 1;
233 /* A pointer to the ..._DECL node which we have most recently been working
234 on. We keep this around just in case something about it looks screwy
235 and we want to tell the user what the source coordinates for the actual
236 declaration are. */
238 static tree dwarf_last_decl;
240 /* A flag indicating that we are emitting the member declarations of a
241 class, so member functions and variables should not be entirely emitted.
242 This is a kludge to avoid passing a second argument to output_*_die. */
244 static int in_class;
246 /* Forward declarations for functions defined in this file. */
248 static const char *dwarf_tag_name PARAMS ((unsigned));
249 static const char *dwarf_attr_name PARAMS ((unsigned));
250 static const char *dwarf_stack_op_name PARAMS ((unsigned));
251 static const char *dwarf_typemod_name PARAMS ((unsigned));
252 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
253 static const char *dwarf_fund_type_name PARAMS ((unsigned));
254 static tree decl_ultimate_origin PARAMS ((tree));
255 static tree block_ultimate_origin PARAMS ((tree));
256 static tree decl_class_context PARAMS ((tree));
257 #if 0
258 static void output_unsigned_leb128 PARAMS ((unsigned long));
259 static void output_signed_leb128 PARAMS ((long));
260 #endif
261 static int fundamental_type_code PARAMS ((tree));
262 static tree root_type_1 PARAMS ((tree, int));
263 static tree root_type PARAMS ((tree));
264 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
265 static void write_modifier_bytes PARAMS ((tree, int, int));
266 static inline int type_is_fundamental PARAMS ((tree));
267 static void equate_decl_number_to_die_number PARAMS ((tree));
268 static inline void equate_type_number_to_die_number PARAMS ((tree));
269 static void output_reg_number PARAMS ((rtx));
270 static void output_mem_loc_descriptor PARAMS ((rtx));
271 static void output_loc_descriptor PARAMS ((rtx));
272 static void output_bound_representation PARAMS ((tree, unsigned, int));
273 static void output_enumeral_list PARAMS ((tree));
274 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
275 static inline tree field_type PARAMS ((tree));
276 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
277 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
278 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
279 static inline void sibling_attribute PARAMS ((void));
280 static void location_attribute PARAMS ((rtx));
281 static void data_member_location_attribute PARAMS ((tree));
282 static void const_value_attribute PARAMS ((rtx));
283 static void location_or_const_value_attribute PARAMS ((tree));
284 static inline void name_attribute PARAMS ((const char *));
285 static inline void fund_type_attribute PARAMS ((unsigned));
286 static void mod_fund_type_attribute PARAMS ((tree, int, int));
287 static inline void user_def_type_attribute PARAMS ((tree));
288 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
289 #ifdef USE_ORDERING_ATTRIBUTE
290 static inline void ordering_attribute PARAMS ((unsigned));
291 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
292 static void subscript_data_attribute PARAMS ((tree));
293 static void byte_size_attribute PARAMS ((tree));
294 static inline void bit_offset_attribute PARAMS ((tree));
295 static inline void bit_size_attribute PARAMS ((tree));
296 static inline void element_list_attribute PARAMS ((tree));
297 static inline void stmt_list_attribute PARAMS ((const char *));
298 static inline void low_pc_attribute PARAMS ((const char *));
299 static inline void high_pc_attribute PARAMS ((const char *));
300 static inline void body_begin_attribute PARAMS ((const char *));
301 static inline void body_end_attribute PARAMS ((const char *));
302 static inline void language_attribute PARAMS ((unsigned));
303 static inline void member_attribute PARAMS ((tree));
304 #if 0
305 static inline void string_length_attribute PARAMS ((tree));
306 #endif
307 static inline void comp_dir_attribute PARAMS ((const char *));
308 static inline void sf_names_attribute PARAMS ((const char *));
309 static inline void src_info_attribute PARAMS ((const char *));
310 static inline void mac_info_attribute PARAMS ((const char *));
311 static inline void prototyped_attribute PARAMS ((tree));
312 static inline void producer_attribute PARAMS ((const char *));
313 static inline void inline_attribute PARAMS ((tree));
314 static inline void containing_type_attribute PARAMS ((tree));
315 static inline void abstract_origin_attribute PARAMS ((tree));
316 #ifdef DWARF_DECL_COORDINATES
317 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
318 #endif /* defined(DWARF_DECL_COORDINATES) */
319 static inline void pure_or_virtual_attribute PARAMS ((tree));
320 static void name_and_src_coords_attributes PARAMS ((tree));
321 static void type_attribute PARAMS ((tree, int, int));
322 static const char *type_tag PARAMS ((tree));
323 static inline void dienum_push PARAMS ((void));
324 static inline void dienum_pop PARAMS ((void));
325 static inline tree member_declared_type PARAMS ((tree));
326 static const char *function_start_label PARAMS ((tree));
327 static void output_array_type_die PARAMS ((void *));
328 static void output_set_type_die PARAMS ((void *));
329 #if 0
330 static void output_entry_point_die PARAMS ((void *));
331 #endif
332 static void output_inlined_enumeration_type_die PARAMS ((void *));
333 static void output_inlined_structure_type_die PARAMS ((void *));
334 static void output_inlined_union_type_die PARAMS ((void *));
335 static void output_enumeration_type_die PARAMS ((void *));
336 static void output_formal_parameter_die PARAMS ((void *));
337 static void output_global_subroutine_die PARAMS ((void *));
338 static void output_global_variable_die PARAMS ((void *));
339 static void output_label_die PARAMS ((void *));
340 static void output_lexical_block_die PARAMS ((void *));
341 static void output_inlined_subroutine_die PARAMS ((void *));
342 static void output_local_variable_die PARAMS ((void *));
343 static void output_member_die PARAMS ((void *));
344 #if 0
345 static void output_pointer_type_die PARAMS ((void *));
346 static void output_reference_type_die PARAMS ((void *));
347 #endif
348 static void output_ptr_to_mbr_type_die PARAMS ((void *));
349 static void output_compile_unit_die PARAMS ((void *));
350 static void output_string_type_die PARAMS ((void *));
351 static void output_inheritance_die PARAMS ((void *));
352 static void output_structure_type_die PARAMS ((void *));
353 static void output_local_subroutine_die PARAMS ((void *));
354 static void output_subroutine_type_die PARAMS ((void *));
355 static void output_typedef_die PARAMS ((void *));
356 static void output_union_type_die PARAMS ((void *));
357 static void output_unspecified_parameters_die PARAMS ((void *));
358 static void output_padded_null_die PARAMS ((void *));
359 static void output_die PARAMS ((void (*)(void *), void *));
360 static void end_sibling_chain PARAMS ((void));
361 static void output_formal_types PARAMS ((tree));
362 static void pend_type PARAMS ((tree));
363 static int type_ok_for_scope PARAMS ((tree, tree));
364 static void output_pending_types_for_scope PARAMS ((tree));
365 static void output_type PARAMS ((tree, tree));
366 static void output_tagged_type_instantiation PARAMS ((tree));
367 static void output_block PARAMS ((tree, int));
368 static void output_decls_for_scope PARAMS ((tree, int));
369 static void output_decl PARAMS ((tree, tree));
370 static void shuffle_filename_entry PARAMS ((filename_entry *));
371 static void generate_new_sfname_entry PARAMS ((void));
372 static unsigned lookup_filename PARAMS ((const char *));
373 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
374 static void generate_macinfo_entry PARAMS ((const char *, const char *));
375 static int is_pseudo_reg PARAMS ((rtx));
376 static tree type_main_variant PARAMS ((tree));
377 static int is_tagged_type PARAMS ((tree));
378 static int is_redundant_typedef PARAMS ((tree));
379 static void add_incomplete_type PARAMS ((tree));
380 static void retry_incomplete_types PARAMS ((void));
382 /* Definitions of defaults for assembler-dependent names of various
383 pseudo-ops and section names.
385 Theses may be overridden in your tm.h file (if necessary) for your
386 particular assembler. The default values provided here correspond to
387 what is expected by "standard" AT&T System V.4 assemblers. */
389 #ifndef FILE_ASM_OP
390 #define FILE_ASM_OP "\t.file\t"
391 #endif
392 #ifndef VERSION_ASM_OP
393 #define VERSION_ASM_OP "\t.version\t"
394 #endif
395 #ifndef UNALIGNED_SHORT_ASM_OP
396 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
397 #endif
398 #ifndef UNALIGNED_INT_ASM_OP
399 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
400 #endif
401 #ifndef ASM_BYTE_OP
402 #define ASM_BYTE_OP "\t.byte\t"
403 #endif
404 #ifndef SET_ASM_OP
405 #define SET_ASM_OP "\t.set\t"
406 #endif
408 /* Pseudo-ops for pushing the current section onto the section stack (and
409 simultaneously changing to a new section) and for poping back to the
410 section we were in immediately before this one. Note that most svr4
411 assemblers only maintain a one level stack... you can push all the
412 sections you want, but you can only pop out one level. (The sparc
413 svr4 assembler is an exception to this general rule.) That's
414 OK because we only use at most one level of the section stack herein. */
416 #ifndef PUSHSECTION_ASM_OP
417 #define PUSHSECTION_ASM_OP "\t.section\t"
418 #endif
419 #ifndef POPSECTION_ASM_OP
420 #define POPSECTION_ASM_OP "\t.previous"
421 #endif
423 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
424 to print the PUSHSECTION_ASM_OP and the section name. The default here
425 works for almost all svr4 assemblers, except for the sparc, where the
426 section name must be enclosed in double quotes. (See sparcv4.h.) */
428 #ifndef PUSHSECTION_FORMAT
429 #define PUSHSECTION_FORMAT "%s%s\n"
430 #endif
432 #ifndef DEBUG_SECTION
433 #define DEBUG_SECTION ".debug"
434 #endif
435 #ifndef LINE_SECTION
436 #define LINE_SECTION ".line"
437 #endif
438 #ifndef SFNAMES_SECTION
439 #define SFNAMES_SECTION ".debug_sfnames"
440 #endif
441 #ifndef SRCINFO_SECTION
442 #define SRCINFO_SECTION ".debug_srcinfo"
443 #endif
444 #ifndef MACINFO_SECTION
445 #define MACINFO_SECTION ".debug_macinfo"
446 #endif
447 #ifndef PUBNAMES_SECTION
448 #define PUBNAMES_SECTION ".debug_pubnames"
449 #endif
450 #ifndef ARANGES_SECTION
451 #define ARANGES_SECTION ".debug_aranges"
452 #endif
453 #ifndef TEXT_SECTION
454 #define TEXT_SECTION ".text"
455 #endif
456 #ifndef DATA_SECTION
457 #define DATA_SECTION ".data"
458 #endif
459 #ifndef DATA1_SECTION
460 #define DATA1_SECTION ".data1"
461 #endif
462 #ifndef RODATA_SECTION
463 #define RODATA_SECTION ".rodata"
464 #endif
465 #ifndef RODATA1_SECTION
466 #define RODATA1_SECTION ".rodata1"
467 #endif
468 #ifndef BSS_SECTION
469 #define BSS_SECTION ".bss"
470 #endif
472 /* Definitions of defaults for formats and names of various special
473 (artificial) labels which may be generated within this file (when
474 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
476 If necessary, these may be overridden from within your tm.h file,
477 but typically, you should never need to override these.
479 These labels have been hacked (temporarily) so that they all begin with
480 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
481 stock m88k/svr4 assembler, both of which need to see .L at the start of
482 a label in order to prevent that label from going into the linker symbol
483 table). When I get time, I'll have to fix this the right way so that we
484 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
485 but that will require a rather massive set of changes. For the moment,
486 the following definitions out to produce the right results for all svr4
487 and svr3 assemblers. -- rfg
490 #ifndef TEXT_BEGIN_LABEL
491 #define TEXT_BEGIN_LABEL "*.L_text_b"
492 #endif
493 #ifndef TEXT_END_LABEL
494 #define TEXT_END_LABEL "*.L_text_e"
495 #endif
497 #ifndef DATA_BEGIN_LABEL
498 #define DATA_BEGIN_LABEL "*.L_data_b"
499 #endif
500 #ifndef DATA_END_LABEL
501 #define DATA_END_LABEL "*.L_data_e"
502 #endif
504 #ifndef DATA1_BEGIN_LABEL
505 #define DATA1_BEGIN_LABEL "*.L_data1_b"
506 #endif
507 #ifndef DATA1_END_LABEL
508 #define DATA1_END_LABEL "*.L_data1_e"
509 #endif
511 #ifndef RODATA_BEGIN_LABEL
512 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
513 #endif
514 #ifndef RODATA_END_LABEL
515 #define RODATA_END_LABEL "*.L_rodata_e"
516 #endif
518 #ifndef RODATA1_BEGIN_LABEL
519 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
520 #endif
521 #ifndef RODATA1_END_LABEL
522 #define RODATA1_END_LABEL "*.L_rodata1_e"
523 #endif
525 #ifndef BSS_BEGIN_LABEL
526 #define BSS_BEGIN_LABEL "*.L_bss_b"
527 #endif
528 #ifndef BSS_END_LABEL
529 #define BSS_END_LABEL "*.L_bss_e"
530 #endif
532 #ifndef LINE_BEGIN_LABEL
533 #define LINE_BEGIN_LABEL "*.L_line_b"
534 #endif
535 #ifndef LINE_LAST_ENTRY_LABEL
536 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
537 #endif
538 #ifndef LINE_END_LABEL
539 #define LINE_END_LABEL "*.L_line_e"
540 #endif
542 #ifndef DEBUG_BEGIN_LABEL
543 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
544 #endif
545 #ifndef SFNAMES_BEGIN_LABEL
546 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
547 #endif
548 #ifndef SRCINFO_BEGIN_LABEL
549 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
550 #endif
551 #ifndef MACINFO_BEGIN_LABEL
552 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
553 #endif
555 #ifndef DIE_BEGIN_LABEL_FMT
556 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
557 #endif
558 #ifndef DIE_END_LABEL_FMT
559 #define DIE_END_LABEL_FMT "*.L_D%u_e"
560 #endif
561 #ifndef PUB_DIE_LABEL_FMT
562 #define PUB_DIE_LABEL_FMT "*.L_P%u"
563 #endif
564 #ifndef BLOCK_BEGIN_LABEL_FMT
565 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
566 #endif
567 #ifndef BLOCK_END_LABEL_FMT
568 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
569 #endif
570 #ifndef SS_BEGIN_LABEL_FMT
571 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
572 #endif
573 #ifndef SS_END_LABEL_FMT
574 #define SS_END_LABEL_FMT "*.L_s%u_e"
575 #endif
576 #ifndef EE_BEGIN_LABEL_FMT
577 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
578 #endif
579 #ifndef EE_END_LABEL_FMT
580 #define EE_END_LABEL_FMT "*.L_e%u_e"
581 #endif
582 #ifndef MT_BEGIN_LABEL_FMT
583 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
584 #endif
585 #ifndef MT_END_LABEL_FMT
586 #define MT_END_LABEL_FMT "*.L_t%u_e"
587 #endif
588 #ifndef LOC_BEGIN_LABEL_FMT
589 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
590 #endif
591 #ifndef LOC_END_LABEL_FMT
592 #define LOC_END_LABEL_FMT "*.L_l%u_e"
593 #endif
594 #ifndef BOUND_BEGIN_LABEL_FMT
595 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
596 #endif
597 #ifndef BOUND_END_LABEL_FMT
598 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
599 #endif
600 #ifndef DERIV_BEGIN_LABEL_FMT
601 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
602 #endif
603 #ifndef DERIV_END_LABEL_FMT
604 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
605 #endif
606 #ifndef SL_BEGIN_LABEL_FMT
607 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
608 #endif
609 #ifndef SL_END_LABEL_FMT
610 #define SL_END_LABEL_FMT "*.L_sl%u_e"
611 #endif
612 #ifndef BODY_BEGIN_LABEL_FMT
613 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
614 #endif
615 #ifndef BODY_END_LABEL_FMT
616 #define BODY_END_LABEL_FMT "*.L_b%u_e"
617 #endif
618 #ifndef FUNC_END_LABEL_FMT
619 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
620 #endif
621 #ifndef TYPE_NAME_FMT
622 #define TYPE_NAME_FMT "*.L_T%u"
623 #endif
624 #ifndef DECL_NAME_FMT
625 #define DECL_NAME_FMT "*.L_E%u"
626 #endif
627 #ifndef LINE_CODE_LABEL_FMT
628 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
629 #endif
630 #ifndef SFNAMES_ENTRY_LABEL_FMT
631 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
632 #endif
633 #ifndef LINE_ENTRY_LABEL_FMT
634 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
635 #endif
637 /* Definitions of defaults for various types of primitive assembly language
638 output operations.
640 If necessary, these may be overridden from within your tm.h file,
641 but typically, you shouldn't need to override these. */
643 #ifndef ASM_OUTPUT_PUSH_SECTION
644 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
645 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
646 #endif
648 #ifndef ASM_OUTPUT_POP_SECTION
649 #define ASM_OUTPUT_POP_SECTION(FILE) \
650 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
651 #endif
653 #ifndef ASM_OUTPUT_DWARF_DELTA2
654 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
655 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
656 assemble_name (FILE, LABEL1); \
657 fprintf (FILE, "-"); \
658 assemble_name (FILE, LABEL2); \
659 fprintf (FILE, "\n"); \
660 } while (0)
661 #endif
663 #ifndef ASM_OUTPUT_DWARF_DELTA4
664 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
665 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
666 assemble_name (FILE, LABEL1); \
667 fprintf (FILE, "-"); \
668 assemble_name (FILE, LABEL2); \
669 fprintf (FILE, "\n"); \
670 } while (0)
671 #endif
673 #ifndef ASM_OUTPUT_DWARF_TAG
674 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
675 do { \
676 fprintf ((FILE), "%s0x%x", \
677 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
678 if (flag_debug_asm) \
679 fprintf ((FILE), "\t%s %s", \
680 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
681 fputc ('\n', (FILE)); \
682 } while (0)
683 #endif
685 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
686 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
687 do { \
688 fprintf ((FILE), "%s0x%x", \
689 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
690 if (flag_debug_asm) \
691 fprintf ((FILE), "\t%s %s", \
692 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
693 fputc ('\n', (FILE)); \
694 } while (0)
695 #endif
697 #ifndef ASM_OUTPUT_DWARF_STACK_OP
698 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
699 do { \
700 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
701 if (flag_debug_asm) \
702 fprintf ((FILE), "\t%s %s", \
703 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
704 fputc ('\n', (FILE)); \
705 } while (0)
706 #endif
708 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
709 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
710 do { \
711 fprintf ((FILE), "%s0x%x", \
712 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
713 if (flag_debug_asm) \
714 fprintf ((FILE), "\t%s %s", \
715 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
716 fputc ('\n', (FILE)); \
717 } while (0)
718 #endif
720 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
721 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
722 do { \
723 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
724 if (flag_debug_asm) \
725 fprintf ((FILE), "\t%s %s", \
726 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
727 fputc ('\n', (FILE)); \
728 } while (0)
729 #endif
731 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
732 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
733 do { \
734 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
735 if (flag_debug_asm) \
736 fprintf ((FILE), "\t%s %s", \
737 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
738 fputc ('\n', (FILE)); \
739 } while (0)
740 #endif
742 #ifndef ASM_OUTPUT_DWARF_ADDR
743 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
744 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
745 assemble_name (FILE, LABEL); \
746 fprintf (FILE, "\n"); \
747 } while (0)
748 #endif
750 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
751 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
752 do { \
753 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
754 output_addr_const ((FILE), (RTX)); \
755 fputc ('\n', (FILE)); \
756 } while (0)
757 #endif
759 #ifndef ASM_OUTPUT_DWARF_REF
760 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
761 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
762 assemble_name (FILE, LABEL); \
763 fprintf (FILE, "\n"); \
764 } while (0)
765 #endif
767 #ifndef ASM_OUTPUT_DWARF_DATA1
768 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
769 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
770 #endif
772 #ifndef ASM_OUTPUT_DWARF_DATA2
773 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
774 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
775 #endif
777 #ifndef ASM_OUTPUT_DWARF_DATA4
778 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
779 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
780 #endif
782 #ifndef ASM_OUTPUT_DWARF_DATA8
783 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
784 do { \
785 if (WORDS_BIG_ENDIAN) \
787 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
788 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
790 else \
792 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
793 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
795 } while (0)
796 #endif
798 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
799 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
800 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
801 defined, we call it, then issue the line feed. If not, we supply a
802 default defintion of calling ASM_OUTPUT_ASCII */
804 #ifndef ASM_OUTPUT_DWARF_STRING
805 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
806 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
807 #else
808 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
809 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
810 #endif
813 /************************ general utility functions **************************/
815 inline static int
816 is_pseudo_reg (rtl)
817 register rtx rtl;
819 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
820 || ((GET_CODE (rtl) == SUBREG)
821 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
824 inline static tree
825 type_main_variant (type)
826 register tree type;
828 type = TYPE_MAIN_VARIANT (type);
830 /* There really should be only one main variant among any group of variants
831 of a given type (and all of the MAIN_VARIANT values for all members of
832 the group should point to that one type) but sometimes the C front-end
833 messes this up for array types, so we work around that bug here. */
835 if (TREE_CODE (type) == ARRAY_TYPE)
837 while (type != TYPE_MAIN_VARIANT (type))
838 type = TYPE_MAIN_VARIANT (type);
841 return type;
844 /* Return non-zero if the given type node represents a tagged type. */
846 inline static int
847 is_tagged_type (type)
848 register tree type;
850 register enum tree_code code = TREE_CODE (type);
852 return (code == RECORD_TYPE || code == UNION_TYPE
853 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
856 static const char *
857 dwarf_tag_name (tag)
858 register unsigned tag;
860 switch (tag)
862 case TAG_padding: return "TAG_padding";
863 case TAG_array_type: return "TAG_array_type";
864 case TAG_class_type: return "TAG_class_type";
865 case TAG_entry_point: return "TAG_entry_point";
866 case TAG_enumeration_type: return "TAG_enumeration_type";
867 case TAG_formal_parameter: return "TAG_formal_parameter";
868 case TAG_global_subroutine: return "TAG_global_subroutine";
869 case TAG_global_variable: return "TAG_global_variable";
870 case TAG_label: return "TAG_label";
871 case TAG_lexical_block: return "TAG_lexical_block";
872 case TAG_local_variable: return "TAG_local_variable";
873 case TAG_member: return "TAG_member";
874 case TAG_pointer_type: return "TAG_pointer_type";
875 case TAG_reference_type: return "TAG_reference_type";
876 case TAG_compile_unit: return "TAG_compile_unit";
877 case TAG_string_type: return "TAG_string_type";
878 case TAG_structure_type: return "TAG_structure_type";
879 case TAG_subroutine: return "TAG_subroutine";
880 case TAG_subroutine_type: return "TAG_subroutine_type";
881 case TAG_typedef: return "TAG_typedef";
882 case TAG_union_type: return "TAG_union_type";
883 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
884 case TAG_variant: return "TAG_variant";
885 case TAG_common_block: return "TAG_common_block";
886 case TAG_common_inclusion: return "TAG_common_inclusion";
887 case TAG_inheritance: return "TAG_inheritance";
888 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
889 case TAG_module: return "TAG_module";
890 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
891 case TAG_set_type: return "TAG_set_type";
892 case TAG_subrange_type: return "TAG_subrange_type";
893 case TAG_with_stmt: return "TAG_with_stmt";
895 /* GNU extensions. */
897 case TAG_format_label: return "TAG_format_label";
898 case TAG_namelist: return "TAG_namelist";
899 case TAG_function_template: return "TAG_function_template";
900 case TAG_class_template: return "TAG_class_template";
902 default: return "TAG_<unknown>";
906 static const char *
907 dwarf_attr_name (attr)
908 register unsigned attr;
910 switch (attr)
912 case AT_sibling: return "AT_sibling";
913 case AT_location: return "AT_location";
914 case AT_name: return "AT_name";
915 case AT_fund_type: return "AT_fund_type";
916 case AT_mod_fund_type: return "AT_mod_fund_type";
917 case AT_user_def_type: return "AT_user_def_type";
918 case AT_mod_u_d_type: return "AT_mod_u_d_type";
919 case AT_ordering: return "AT_ordering";
920 case AT_subscr_data: return "AT_subscr_data";
921 case AT_byte_size: return "AT_byte_size";
922 case AT_bit_offset: return "AT_bit_offset";
923 case AT_bit_size: return "AT_bit_size";
924 case AT_element_list: return "AT_element_list";
925 case AT_stmt_list: return "AT_stmt_list";
926 case AT_low_pc: return "AT_low_pc";
927 case AT_high_pc: return "AT_high_pc";
928 case AT_language: return "AT_language";
929 case AT_member: return "AT_member";
930 case AT_discr: return "AT_discr";
931 case AT_discr_value: return "AT_discr_value";
932 case AT_string_length: return "AT_string_length";
933 case AT_common_reference: return "AT_common_reference";
934 case AT_comp_dir: return "AT_comp_dir";
935 case AT_const_value_string: return "AT_const_value_string";
936 case AT_const_value_data2: return "AT_const_value_data2";
937 case AT_const_value_data4: return "AT_const_value_data4";
938 case AT_const_value_data8: return "AT_const_value_data8";
939 case AT_const_value_block2: return "AT_const_value_block2";
940 case AT_const_value_block4: return "AT_const_value_block4";
941 case AT_containing_type: return "AT_containing_type";
942 case AT_default_value_addr: return "AT_default_value_addr";
943 case AT_default_value_data2: return "AT_default_value_data2";
944 case AT_default_value_data4: return "AT_default_value_data4";
945 case AT_default_value_data8: return "AT_default_value_data8";
946 case AT_default_value_string: return "AT_default_value_string";
947 case AT_friends: return "AT_friends";
948 case AT_inline: return "AT_inline";
949 case AT_is_optional: return "AT_is_optional";
950 case AT_lower_bound_ref: return "AT_lower_bound_ref";
951 case AT_lower_bound_data2: return "AT_lower_bound_data2";
952 case AT_lower_bound_data4: return "AT_lower_bound_data4";
953 case AT_lower_bound_data8: return "AT_lower_bound_data8";
954 case AT_private: return "AT_private";
955 case AT_producer: return "AT_producer";
956 case AT_program: return "AT_program";
957 case AT_protected: return "AT_protected";
958 case AT_prototyped: return "AT_prototyped";
959 case AT_public: return "AT_public";
960 case AT_pure_virtual: return "AT_pure_virtual";
961 case AT_return_addr: return "AT_return_addr";
962 case AT_abstract_origin: return "AT_abstract_origin";
963 case AT_start_scope: return "AT_start_scope";
964 case AT_stride_size: return "AT_stride_size";
965 case AT_upper_bound_ref: return "AT_upper_bound_ref";
966 case AT_upper_bound_data2: return "AT_upper_bound_data2";
967 case AT_upper_bound_data4: return "AT_upper_bound_data4";
968 case AT_upper_bound_data8: return "AT_upper_bound_data8";
969 case AT_virtual: return "AT_virtual";
971 /* GNU extensions */
973 case AT_sf_names: return "AT_sf_names";
974 case AT_src_info: return "AT_src_info";
975 case AT_mac_info: return "AT_mac_info";
976 case AT_src_coords: return "AT_src_coords";
977 case AT_body_begin: return "AT_body_begin";
978 case AT_body_end: return "AT_body_end";
980 default: return "AT_<unknown>";
984 static const char *
985 dwarf_stack_op_name (op)
986 register unsigned op;
988 switch (op)
990 case OP_REG: return "OP_REG";
991 case OP_BASEREG: return "OP_BASEREG";
992 case OP_ADDR: return "OP_ADDR";
993 case OP_CONST: return "OP_CONST";
994 case OP_DEREF2: return "OP_DEREF2";
995 case OP_DEREF4: return "OP_DEREF4";
996 case OP_ADD: return "OP_ADD";
997 default: return "OP_<unknown>";
1001 static const char *
1002 dwarf_typemod_name (mod)
1003 register unsigned mod;
1005 switch (mod)
1007 case MOD_pointer_to: return "MOD_pointer_to";
1008 case MOD_reference_to: return "MOD_reference_to";
1009 case MOD_const: return "MOD_const";
1010 case MOD_volatile: return "MOD_volatile";
1011 default: return "MOD_<unknown>";
1015 static const char *
1016 dwarf_fmt_byte_name (fmt)
1017 register unsigned fmt;
1019 switch (fmt)
1021 case FMT_FT_C_C: return "FMT_FT_C_C";
1022 case FMT_FT_C_X: return "FMT_FT_C_X";
1023 case FMT_FT_X_C: return "FMT_FT_X_C";
1024 case FMT_FT_X_X: return "FMT_FT_X_X";
1025 case FMT_UT_C_C: return "FMT_UT_C_C";
1026 case FMT_UT_C_X: return "FMT_UT_C_X";
1027 case FMT_UT_X_C: return "FMT_UT_X_C";
1028 case FMT_UT_X_X: return "FMT_UT_X_X";
1029 case FMT_ET: return "FMT_ET";
1030 default: return "FMT_<unknown>";
1034 static const char *
1035 dwarf_fund_type_name (ft)
1036 register unsigned ft;
1038 switch (ft)
1040 case FT_char: return "FT_char";
1041 case FT_signed_char: return "FT_signed_char";
1042 case FT_unsigned_char: return "FT_unsigned_char";
1043 case FT_short: return "FT_short";
1044 case FT_signed_short: return "FT_signed_short";
1045 case FT_unsigned_short: return "FT_unsigned_short";
1046 case FT_integer: return "FT_integer";
1047 case FT_signed_integer: return "FT_signed_integer";
1048 case FT_unsigned_integer: return "FT_unsigned_integer";
1049 case FT_long: return "FT_long";
1050 case FT_signed_long: return "FT_signed_long";
1051 case FT_unsigned_long: return "FT_unsigned_long";
1052 case FT_pointer: return "FT_pointer";
1053 case FT_float: return "FT_float";
1054 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1055 case FT_ext_prec_float: return "FT_ext_prec_float";
1056 case FT_complex: return "FT_complex";
1057 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1058 case FT_void: return "FT_void";
1059 case FT_boolean: return "FT_boolean";
1060 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1061 case FT_label: return "FT_label";
1063 /* GNU extensions. */
1065 case FT_long_long: return "FT_long_long";
1066 case FT_signed_long_long: return "FT_signed_long_long";
1067 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1069 case FT_int8: return "FT_int8";
1070 case FT_signed_int8: return "FT_signed_int8";
1071 case FT_unsigned_int8: return "FT_unsigned_int8";
1072 case FT_int16: return "FT_int16";
1073 case FT_signed_int16: return "FT_signed_int16";
1074 case FT_unsigned_int16: return "FT_unsigned_int16";
1075 case FT_int32: return "FT_int32";
1076 case FT_signed_int32: return "FT_signed_int32";
1077 case FT_unsigned_int32: return "FT_unsigned_int32";
1078 case FT_int64: return "FT_int64";
1079 case FT_signed_int64: return "FT_signed_int64";
1080 case FT_unsigned_int64: return "FT_unsigned_int64";
1081 case FT_int128: return "FT_int128";
1082 case FT_signed_int128: return "FT_signed_int128";
1083 case FT_unsigned_int128: return "FT_unsigned_int128";
1085 case FT_real32: return "FT_real32";
1086 case FT_real64: return "FT_real64";
1087 case FT_real96: return "FT_real96";
1088 case FT_real128: return "FT_real128";
1090 default: return "FT_<unknown>";
1094 /* Determine the "ultimate origin" of a decl. The decl may be an
1095 inlined instance of an inlined instance of a decl which is local
1096 to an inline function, so we have to trace all of the way back
1097 through the origin chain to find out what sort of node actually
1098 served as the original seed for the given block. */
1100 static tree
1101 decl_ultimate_origin (decl)
1102 register tree decl;
1104 #ifdef ENABLE_CHECKING
1105 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1106 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1107 most distant ancestor, this should never happen. */
1108 abort ();
1109 #endif
1111 return DECL_ABSTRACT_ORIGIN (decl);
1114 /* Determine the "ultimate origin" of a block. The block may be an
1115 inlined instance of an inlined instance of a block which is local
1116 to an inline function, so we have to trace all of the way back
1117 through the origin chain to find out what sort of node actually
1118 served as the original seed for the given block. */
1120 static tree
1121 block_ultimate_origin (block)
1122 register tree block;
1124 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1126 if (immediate_origin == NULL)
1127 return NULL;
1128 else
1130 register tree ret_val;
1131 register tree lookahead = immediate_origin;
1135 ret_val = lookahead;
1136 lookahead = (TREE_CODE (ret_val) == BLOCK)
1137 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1138 : NULL;
1140 while (lookahead != NULL && lookahead != ret_val);
1141 return ret_val;
1145 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1146 of a virtual function may refer to a base class, so we check the 'this'
1147 parameter. */
1149 static tree
1150 decl_class_context (decl)
1151 tree decl;
1153 tree context = NULL_TREE;
1154 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1155 context = DECL_CONTEXT (decl);
1156 else
1157 context = TYPE_MAIN_VARIANT
1158 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1160 if (context && !TYPE_P (context))
1161 context = NULL_TREE;
1163 return context;
1166 #if 0
1167 static void
1168 output_unsigned_leb128 (value)
1169 register unsigned long value;
1171 register unsigned long orig_value = value;
1175 register unsigned byte = (value & 0x7f);
1177 value >>= 7;
1178 if (value != 0) /* more bytes to follow */
1179 byte |= 0x80;
1180 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1181 if (flag_debug_asm && value == 0)
1182 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1183 ASM_COMMENT_START, orig_value);
1184 fputc ('\n', asm_out_file);
1186 while (value != 0);
1189 static void
1190 output_signed_leb128 (value)
1191 register long value;
1193 register long orig_value = value;
1194 register int negative = (value < 0);
1195 register int more;
1199 register unsigned byte = (value & 0x7f);
1201 value >>= 7;
1202 if (negative)
1203 value |= 0xfe000000; /* manually sign extend */
1204 if (((value == 0) && ((byte & 0x40) == 0))
1205 || ((value == -1) && ((byte & 0x40) == 1)))
1206 more = 0;
1207 else
1209 byte |= 0x80;
1210 more = 1;
1212 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1213 if (flag_debug_asm && more == 0)
1214 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1215 ASM_COMMENT_START, orig_value);
1216 fputc ('\n', asm_out_file);
1218 while (more);
1220 #endif
1222 /**************** utility functions for attribute functions ******************/
1224 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1225 type code for the given type.
1227 This routine must only be called for GCC type nodes that correspond to
1228 Dwarf fundamental types.
1230 The current Dwarf draft specification calls for Dwarf fundamental types
1231 to accurately reflect the fact that a given type was either a "plain"
1232 integral type or an explicitly "signed" integral type. Unfortunately,
1233 we can't always do this, because GCC may already have thrown away the
1234 information about the precise way in which the type was originally
1235 specified, as in:
1237 typedef signed int my_type;
1239 struct s { my_type f; };
1241 Since we may be stuck here without enought information to do exactly
1242 what is called for in the Dwarf draft specification, we do the best
1243 that we can under the circumstances and always use the "plain" integral
1244 fundamental type codes for int, short, and long types. That's probably
1245 good enough. The additional accuracy called for in the current DWARF
1246 draft specification is probably never even useful in practice. */
1248 static int
1249 fundamental_type_code (type)
1250 register tree type;
1252 if (TREE_CODE (type) == ERROR_MARK)
1253 return 0;
1255 switch (TREE_CODE (type))
1257 case ERROR_MARK:
1258 return FT_void;
1260 case VOID_TYPE:
1261 return FT_void;
1263 case INTEGER_TYPE:
1264 /* Carefully distinguish all the standard types of C,
1265 without messing up if the language is not C.
1266 Note that we check only for the names that contain spaces;
1267 other names might occur by coincidence in other languages. */
1268 if (TYPE_NAME (type) != 0
1269 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1270 && DECL_NAME (TYPE_NAME (type)) != 0
1271 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1273 const char *name =
1274 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1276 if (!strcmp (name, "unsigned char"))
1277 return FT_unsigned_char;
1278 if (!strcmp (name, "signed char"))
1279 return FT_signed_char;
1280 if (!strcmp (name, "unsigned int"))
1281 return FT_unsigned_integer;
1282 if (!strcmp (name, "short int"))
1283 return FT_short;
1284 if (!strcmp (name, "short unsigned int"))
1285 return FT_unsigned_short;
1286 if (!strcmp (name, "long int"))
1287 return FT_long;
1288 if (!strcmp (name, "long unsigned int"))
1289 return FT_unsigned_long;
1290 if (!strcmp (name, "long long int"))
1291 return FT_long_long; /* Not grok'ed by svr4 SDB */
1292 if (!strcmp (name, "long long unsigned int"))
1293 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1296 /* Most integer types will be sorted out above, however, for the
1297 sake of special `array index' integer types, the following code
1298 is also provided. */
1300 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1301 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1303 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1304 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1306 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1307 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1309 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1310 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1312 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1313 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1315 if (TYPE_MODE (type) == TImode)
1316 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1318 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1319 if (TYPE_PRECISION (type) == 1)
1320 return FT_boolean;
1322 abort ();
1324 case REAL_TYPE:
1325 /* Carefully distinguish all the standard types of C,
1326 without messing up if the language is not C. */
1327 if (TYPE_NAME (type) != 0
1328 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1329 && DECL_NAME (TYPE_NAME (type)) != 0
1330 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1332 const char *name =
1333 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1335 /* Note that here we can run afowl of a serious bug in "classic"
1336 svr4 SDB debuggers. They don't seem to understand the
1337 FT_ext_prec_float type (even though they should). */
1339 if (!strcmp (name, "long double"))
1340 return FT_ext_prec_float;
1343 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1345 /* On the SH, when compiling with -m3e or -m4-single-only, both
1346 float and double are 32 bits. But since the debugger doesn't
1347 know about the subtarget, it always thinks double is 64 bits.
1348 So we have to tell the debugger that the type is float to
1349 make the output of the 'print' command etc. readable. */
1350 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1351 return FT_float;
1352 return FT_dbl_prec_float;
1354 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1355 return FT_float;
1357 /* Note that here we can run afowl of a serious bug in "classic"
1358 svr4 SDB debuggers. They don't seem to understand the
1359 FT_ext_prec_float type (even though they should). */
1361 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1362 return FT_ext_prec_float;
1363 abort ();
1365 case COMPLEX_TYPE:
1366 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1368 case CHAR_TYPE:
1369 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1371 case BOOLEAN_TYPE:
1372 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1374 default:
1375 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1377 return 0;
1380 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1381 the Dwarf "root" type for the given input type. The Dwarf "root" type
1382 of a given type is generally the same as the given type, except that if
1383 the given type is a pointer or reference type, then the root type of
1384 the given type is the root type of the "basis" type for the pointer or
1385 reference type. (This definition of the "root" type is recursive.)
1386 Also, the root type of a `const' qualified type or a `volatile'
1387 qualified type is the root type of the given type without the
1388 qualifiers. */
1390 static tree
1391 root_type_1 (type, count)
1392 register tree type;
1393 register int count;
1395 /* Give up after searching 1000 levels, in case this is a recursive
1396 pointer type. Such types are possible in Ada, but it is not possible
1397 to represent them in DWARF1 debug info. */
1398 if (count > 1000)
1399 return error_mark_node;
1401 switch (TREE_CODE (type))
1403 case ERROR_MARK:
1404 return error_mark_node;
1406 case POINTER_TYPE:
1407 case REFERENCE_TYPE:
1408 return root_type_1 (TREE_TYPE (type), count+1);
1410 default:
1411 return type;
1415 static tree
1416 root_type (type)
1417 register tree type;
1419 type = root_type_1 (type, 0);
1420 if (type != error_mark_node)
1421 type = type_main_variant (type);
1422 return type;
1425 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1426 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1428 static void
1429 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1430 register tree type;
1431 register int decl_const;
1432 register int decl_volatile;
1433 register int count;
1435 if (TREE_CODE (type) == ERROR_MARK)
1436 return;
1438 /* Give up after searching 1000 levels, in case this is a recursive
1439 pointer type. Such types are possible in Ada, but it is not possible
1440 to represent them in DWARF1 debug info. */
1441 if (count > 1000)
1442 return;
1444 if (TYPE_READONLY (type) || decl_const)
1445 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1446 if (TYPE_VOLATILE (type) || decl_volatile)
1447 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1448 switch (TREE_CODE (type))
1450 case POINTER_TYPE:
1451 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1452 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1453 return;
1455 case REFERENCE_TYPE:
1456 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1457 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1458 return;
1460 case ERROR_MARK:
1461 default:
1462 return;
1466 static void
1467 write_modifier_bytes (type, decl_const, decl_volatile)
1468 register tree type;
1469 register int decl_const;
1470 register int decl_volatile;
1472 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1475 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1476 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1478 static inline int
1479 type_is_fundamental (type)
1480 register tree type;
1482 switch (TREE_CODE (type))
1484 case ERROR_MARK:
1485 case VOID_TYPE:
1486 case INTEGER_TYPE:
1487 case REAL_TYPE:
1488 case COMPLEX_TYPE:
1489 case BOOLEAN_TYPE:
1490 case CHAR_TYPE:
1491 return 1;
1493 case SET_TYPE:
1494 case ARRAY_TYPE:
1495 case RECORD_TYPE:
1496 case UNION_TYPE:
1497 case QUAL_UNION_TYPE:
1498 case ENUMERAL_TYPE:
1499 case FUNCTION_TYPE:
1500 case METHOD_TYPE:
1501 case POINTER_TYPE:
1502 case REFERENCE_TYPE:
1503 case FILE_TYPE:
1504 case OFFSET_TYPE:
1505 case LANG_TYPE:
1506 case VECTOR_TYPE:
1507 return 0;
1509 default:
1510 abort ();
1512 return 0;
1515 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1516 equate directive which will associate a symbolic name with the current DIE.
1518 The name used is an artificial label generated from the DECL_UID number
1519 associated with the given decl node. The name it gets equated to is the
1520 symbolic label that we (previously) output at the start of the DIE that
1521 we are currently generating.
1523 Calling this function while generating some "decl related" form of DIE
1524 makes it possible to later refer to the DIE which represents the given
1525 decl simply by re-generating the symbolic name from the ..._DECL node's
1526 UID number. */
1528 static void
1529 equate_decl_number_to_die_number (decl)
1530 register tree decl;
1532 /* In the case where we are generating a DIE for some ..._DECL node
1533 which represents either some inline function declaration or some
1534 entity declared within an inline function declaration/definition,
1535 setup a symbolic name for the current DIE so that we have a name
1536 for this DIE that we can easily refer to later on within
1537 AT_abstract_origin attributes. */
1539 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1540 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1542 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1543 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1544 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1547 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1548 equate directive which will associate a symbolic name with the current DIE.
1550 The name used is an artificial label generated from the TYPE_UID number
1551 associated with the given type node. The name it gets equated to is the
1552 symbolic label that we (previously) output at the start of the DIE that
1553 we are currently generating.
1555 Calling this function while generating some "type related" form of DIE
1556 makes it easy to later refer to the DIE which represents the given type
1557 simply by re-generating the alternative name from the ..._TYPE node's
1558 UID number. */
1560 static inline void
1561 equate_type_number_to_die_number (type)
1562 register tree type;
1564 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1565 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1567 /* We are generating a DIE to represent the main variant of this type
1568 (i.e the type without any const or volatile qualifiers) so in order
1569 to get the equate to come out right, we need to get the main variant
1570 itself here. */
1572 type = type_main_variant (type);
1574 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1575 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1576 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1579 static void
1580 output_reg_number (rtl)
1581 register rtx rtl;
1583 register unsigned regno = REGNO (rtl);
1585 if (regno >= DWARF_FRAME_REGISTERS)
1587 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1588 regno);
1589 regno = 0;
1591 fprintf (asm_out_file, "%s0x%x",
1592 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1593 if (flag_debug_asm)
1595 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1596 PRINT_REG (rtl, 0, asm_out_file);
1598 fputc ('\n', asm_out_file);
1601 /* The following routine is a nice and simple transducer. It converts the
1602 RTL for a variable or parameter (resident in memory) into an equivalent
1603 Dwarf representation of a mechanism for getting the address of that same
1604 variable onto the top of a hypothetical "address evaluation" stack.
1606 When creating memory location descriptors, we are effectively trans-
1607 forming the RTL for a memory-resident object into its Dwarf postfix
1608 expression equivalent. This routine just recursively descends an
1609 RTL tree, turning it into Dwarf postfix code as it goes. */
1611 static void
1612 output_mem_loc_descriptor (rtl)
1613 register rtx rtl;
1615 /* Note that for a dynamically sized array, the location we will
1616 generate a description of here will be the lowest numbered location
1617 which is actually within the array. That's *not* necessarily the
1618 same as the zeroth element of the array. */
1620 #ifdef ASM_SIMPLIFY_DWARF_ADDR
1621 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
1622 #endif
1624 switch (GET_CODE (rtl))
1626 case SUBREG:
1628 /* The case of a subreg may arise when we have a local (register)
1629 variable or a formal (register) parameter which doesn't quite
1630 fill up an entire register. For now, just assume that it is
1631 legitimate to make the Dwarf info refer to the whole register
1632 which contains the given subreg. */
1634 rtl = XEXP (rtl, 0);
1635 /* Drop thru. */
1637 case REG:
1639 /* Whenever a register number forms a part of the description of
1640 the method for calculating the (dynamic) address of a memory
1641 resident object, DWARF rules require the register number to
1642 be referred to as a "base register". This distinction is not
1643 based in any way upon what category of register the hardware
1644 believes the given register belongs to. This is strictly
1645 DWARF terminology we're dealing with here.
1647 Note that in cases where the location of a memory-resident data
1648 object could be expressed as:
1650 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1652 the actual DWARF location descriptor that we generate may just
1653 be OP_BASEREG (basereg). This may look deceptively like the
1654 object in question was allocated to a register (rather than
1655 in memory) so DWARF consumers need to be aware of the subtle
1656 distinction between OP_REG and OP_BASEREG. */
1658 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1659 output_reg_number (rtl);
1660 break;
1662 case MEM:
1663 output_mem_loc_descriptor (XEXP (rtl, 0));
1664 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1665 break;
1667 case CONST:
1668 case SYMBOL_REF:
1669 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1670 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1671 break;
1673 case PLUS:
1674 output_mem_loc_descriptor (XEXP (rtl, 0));
1675 output_mem_loc_descriptor (XEXP (rtl, 1));
1676 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1677 break;
1679 case CONST_INT:
1680 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1681 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1682 break;
1684 case MULT:
1685 /* If a pseudo-reg is optimized away, it is possible for it to
1686 be replaced with a MEM containing a multiply. Use a GNU extension
1687 to describe it. */
1688 output_mem_loc_descriptor (XEXP (rtl, 0));
1689 output_mem_loc_descriptor (XEXP (rtl, 1));
1690 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1691 break;
1693 default:
1694 abort ();
1698 /* Output a proper Dwarf location descriptor for a variable or parameter
1699 which is either allocated in a register or in a memory location. For
1700 a register, we just generate an OP_REG and the register number. For a
1701 memory location we provide a Dwarf postfix expression describing how to
1702 generate the (dynamic) address of the object onto the address stack. */
1704 static void
1705 output_loc_descriptor (rtl)
1706 register rtx rtl;
1708 switch (GET_CODE (rtl))
1710 case SUBREG:
1712 /* The case of a subreg may arise when we have a local (register)
1713 variable or a formal (register) parameter which doesn't quite
1714 fill up an entire register. For now, just assume that it is
1715 legitimate to make the Dwarf info refer to the whole register
1716 which contains the given subreg. */
1718 rtl = XEXP (rtl, 0);
1719 /* Drop thru. */
1721 case REG:
1722 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1723 output_reg_number (rtl);
1724 break;
1726 case MEM:
1727 output_mem_loc_descriptor (XEXP (rtl, 0));
1728 break;
1730 default:
1731 abort (); /* Should never happen */
1735 /* Given a tree node describing an array bound (either lower or upper)
1736 output a representation for that bound. */
1738 static void
1739 output_bound_representation (bound, dim_num, u_or_l)
1740 register tree bound;
1741 register unsigned dim_num; /* For multi-dimensional arrays. */
1742 register char u_or_l; /* Designates upper or lower bound. */
1744 switch (TREE_CODE (bound))
1747 case ERROR_MARK:
1748 return;
1750 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1752 case INTEGER_CST:
1753 if (host_integerp (bound, 0))
1754 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
1755 break;
1757 default:
1759 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1760 SAVE_EXPR nodes, in which case we can do something, or as
1761 an expression, which we cannot represent. */
1763 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1764 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1766 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1767 current_dienum, dim_num, u_or_l);
1769 sprintf (end_label, BOUND_END_LABEL_FMT,
1770 current_dienum, dim_num, u_or_l);
1772 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1773 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1775 /* If optimization is turned on, the SAVE_EXPRs that describe
1776 how to access the upper bound values are essentially bogus.
1777 They only describe (at best) how to get at these values at
1778 the points in the generated code right after they have just
1779 been computed. Worse yet, in the typical case, the upper
1780 bound values will not even *be* computed in the optimized
1781 code, so these SAVE_EXPRs are entirely bogus.
1783 In order to compensate for this fact, we check here to see
1784 if optimization is enabled, and if so, we effectively create
1785 an empty location description for the (unknown and unknowable)
1786 upper bound.
1788 This should not cause too much trouble for existing (stupid?)
1789 debuggers because they have to deal with empty upper bounds
1790 location descriptions anyway in order to be able to deal with
1791 incomplete array types.
1793 Of course an intelligent debugger (GDB?) should be able to
1794 comprehend that a missing upper bound specification in a
1795 array type used for a storage class `auto' local array variable
1796 indicates that the upper bound is both unknown (at compile-
1797 time) and unknowable (at run-time) due to optimization. */
1799 if (! optimize)
1801 while (TREE_CODE (bound) == NOP_EXPR
1802 || TREE_CODE (bound) == CONVERT_EXPR)
1803 bound = TREE_OPERAND (bound, 0);
1805 if (TREE_CODE (bound) == SAVE_EXPR)
1806 output_loc_descriptor
1807 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1810 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1812 break;
1817 /* Recursive function to output a sequence of value/name pairs for
1818 enumeration constants in reversed order. This is called from
1819 enumeration_type_die. */
1821 static void
1822 output_enumeral_list (link)
1823 register tree link;
1825 if (link)
1827 output_enumeral_list (TREE_CHAIN (link));
1829 if (host_integerp (TREE_VALUE (link), 0))
1830 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1831 tree_low_cst (TREE_VALUE (link), 0));
1833 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
1834 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1838 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1839 which is not less than the value itself. */
1841 static inline HOST_WIDE_INT
1842 ceiling (value, boundary)
1843 register HOST_WIDE_INT value;
1844 register unsigned int boundary;
1846 return (((value + boundary - 1) / boundary) * boundary);
1849 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1850 pointer to the declared type for the relevant field variable, or return
1851 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1853 static inline tree
1854 field_type (decl)
1855 register tree decl;
1857 register tree type;
1859 if (TREE_CODE (decl) == ERROR_MARK)
1860 return integer_type_node;
1862 type = DECL_BIT_FIELD_TYPE (decl);
1863 if (type == NULL)
1864 type = TREE_TYPE (decl);
1865 return type;
1868 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1869 node, return the alignment in bits for the type, or else return
1870 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1872 static inline unsigned int
1873 simple_type_align_in_bits (type)
1874 register tree type;
1876 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1879 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1880 node, return the size in bits for the type if it is a constant, or
1881 else return the alignment for the type if the type's size is not
1882 constant, or else return BITS_PER_WORD if the type actually turns out
1883 to be an ERROR_MARK node. */
1885 static inline unsigned HOST_WIDE_INT
1886 simple_type_size_in_bits (type)
1887 register tree type;
1889 tree type_size_tree;
1891 if (TREE_CODE (type) == ERROR_MARK)
1892 return BITS_PER_WORD;
1893 type_size_tree = TYPE_SIZE (type);
1895 if (type_size_tree == NULL_TREE)
1896 return 0;
1897 if (! host_integerp (type_size_tree, 1))
1898 return TYPE_ALIGN (type);
1899 return tree_low_cst (type_size_tree, 1);
1902 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1903 return the byte offset of the lowest addressed byte of the "containing
1904 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1905 mine what that offset is, either because the argument turns out to be a
1906 pointer to an ERROR_MARK node, or because the offset is actually variable.
1907 (We can't handle the latter case just yet.) */
1909 static HOST_WIDE_INT
1910 field_byte_offset (decl)
1911 register tree decl;
1913 unsigned int type_align_in_bytes;
1914 unsigned int type_align_in_bits;
1915 unsigned HOST_WIDE_INT type_size_in_bits;
1916 HOST_WIDE_INT object_offset_in_align_units;
1917 HOST_WIDE_INT object_offset_in_bits;
1918 HOST_WIDE_INT object_offset_in_bytes;
1919 tree type;
1920 tree field_size_tree;
1921 HOST_WIDE_INT bitpos_int;
1922 HOST_WIDE_INT deepest_bitpos;
1923 unsigned HOST_WIDE_INT field_size_in_bits;
1925 if (TREE_CODE (decl) == ERROR_MARK)
1926 return 0;
1928 if (TREE_CODE (decl) != FIELD_DECL)
1929 abort ();
1931 type = field_type (decl);
1932 field_size_tree = DECL_SIZE (decl);
1934 /* The size could be unspecified if there was an error, or for
1935 a flexible array member. */
1936 if (! field_size_tree)
1937 field_size_tree = bitsize_zero_node;
1939 /* We cannot yet cope with fields whose positions or sizes are variable,
1940 so for now, when we see such things, we simply return 0. Someday,
1941 we may be able to handle such cases, but it will be damn difficult. */
1943 if (! host_integerp (bit_position (decl), 0)
1944 || ! host_integerp (field_size_tree, 1))
1945 return 0;
1947 bitpos_int = int_bit_position (decl);
1948 field_size_in_bits = tree_low_cst (field_size_tree, 1);
1950 type_size_in_bits = simple_type_size_in_bits (type);
1951 type_align_in_bits = simple_type_align_in_bits (type);
1952 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1954 /* Note that the GCC front-end doesn't make any attempt to keep track
1955 of the starting bit offset (relative to the start of the containing
1956 structure type) of the hypothetical "containing object" for a bit-
1957 field. Thus, when computing the byte offset value for the start of
1958 the "containing object" of a bit-field, we must deduce this infor-
1959 mation on our own.
1961 This can be rather tricky to do in some cases. For example, handling
1962 the following structure type definition when compiling for an i386/i486
1963 target (which only aligns long long's to 32-bit boundaries) can be very
1964 tricky:
1966 struct S {
1967 int field1;
1968 long long field2:31;
1971 Fortunately, there is a simple rule-of-thumb which can be used in such
1972 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
1973 the structure shown above. It decides to do this based upon one simple
1974 rule for bit-field allocation. Quite simply, GCC allocates each "con-
1975 taining object" for each bit-field at the first (i.e. lowest addressed)
1976 legitimate alignment boundary (based upon the required minimum alignment
1977 for the declared type of the field) which it can possibly use, subject
1978 to the condition that there is still enough available space remaining
1979 in the containing object (when allocated at the selected point) to
1980 fully accommodate all of the bits of the bit-field itself.
1982 This simple rule makes it obvious why GCC allocates 8 bytes for each
1983 object of the structure type shown above. When looking for a place to
1984 allocate the "containing object" for `field2', the compiler simply tries
1985 to allocate a 64-bit "containing object" at each successive 32-bit
1986 boundary (starting at zero) until it finds a place to allocate that 64-
1987 bit field such that at least 31 contiguous (and previously unallocated)
1988 bits remain within that selected 64 bit field. (As it turns out, for
1989 the example above, the compiler finds that it is OK to allocate the
1990 "containing object" 64-bit field at bit-offset zero within the
1991 structure type.)
1993 Here we attempt to work backwards from the limited set of facts we're
1994 given, and we try to deduce from those facts, where GCC must have
1995 believed that the containing object started (within the structure type).
1997 The value we deduce is then used (by the callers of this routine) to
1998 generate AT_location and AT_bit_offset attributes for fields (both
1999 bit-fields and, in the case of AT_location, regular fields as well). */
2001 /* Figure out the bit-distance from the start of the structure to the
2002 "deepest" bit of the bit-field. */
2003 deepest_bitpos = bitpos_int + field_size_in_bits;
2005 /* This is the tricky part. Use some fancy footwork to deduce where the
2006 lowest addressed bit of the containing object must be. */
2007 object_offset_in_bits
2008 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2010 /* Compute the offset of the containing object in "alignment units". */
2011 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2013 /* Compute the offset of the containing object in bytes. */
2014 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2016 /* The above code assumes that the field does not cross an alignment
2017 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2018 or if the structure is packed. If this happens, then we get an object
2019 which starts after the bitfield, which means that the bit offset is
2020 negative. Gdb fails when given negative bit offsets. We avoid this
2021 by recomputing using the first bit of the bitfield. This will give
2022 us an object which does not completely contain the bitfield, but it
2023 will be aligned, and it will contain the first bit of the bitfield.
2025 However, only do this for a BYTES_BIG_ENDIAN target. For a
2026 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2027 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2028 then we end up computing the object byte offset for the wrong word of the
2029 desired bitfield, which in turn causes the field offset to be negative
2030 in bit_offset_attribute. */
2031 if (BYTES_BIG_ENDIAN
2032 && object_offset_in_bits > bitpos_int)
2034 deepest_bitpos = bitpos_int + 1;
2035 object_offset_in_bits
2036 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2037 object_offset_in_align_units = (object_offset_in_bits
2038 / type_align_in_bits);
2039 object_offset_in_bytes = (object_offset_in_align_units
2040 * type_align_in_bytes);
2043 return object_offset_in_bytes;
2046 /****************************** attributes *********************************/
2048 /* The following routines are responsible for writing out the various types
2049 of Dwarf attributes (and any following data bytes associated with them).
2050 These routines are listed in order based on the numerical codes of their
2051 associated attributes. */
2053 /* Generate an AT_sibling attribute. */
2055 static inline void
2056 sibling_attribute ()
2058 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2060 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2061 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2062 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2065 /* Output the form of location attributes suitable for whole variables and
2066 whole parameters. Note that the location attributes for struct fields
2067 are generated by the routine `data_member_location_attribute' below. */
2069 static void
2070 location_attribute (rtl)
2071 register rtx rtl;
2073 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2074 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2076 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2077 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2078 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2079 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2080 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2082 /* Handle a special case. If we are about to output a location descriptor
2083 for a variable or parameter which has been optimized out of existence,
2084 don't do that. Instead we output a zero-length location descriptor
2085 value as part of the location attribute.
2087 A variable which has been optimized out of existence will have a
2088 DECL_RTL value which denotes a pseudo-reg.
2090 Currently, in some rare cases, variables can have DECL_RTL values
2091 which look like (MEM (REG pseudo-reg#)). These cases are due to
2092 bugs elsewhere in the compiler. We treat such cases
2093 as if the variable(s) in question had been optimized out of existence.
2095 Note that in all cases where we wish to express the fact that a
2096 variable has been optimized out of existence, we do not simply
2097 suppress the generation of the entire location attribute because
2098 the absence of a location attribute in certain kinds of DIEs is
2099 used to indicate something else entirely... i.e. that the DIE
2100 represents an object declaration, but not a definition. So saith
2101 the PLSIG.
2104 if (! is_pseudo_reg (rtl)
2105 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2106 output_loc_descriptor (rtl);
2108 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2111 /* Output the specialized form of location attribute used for data members
2112 of struct and union types.
2114 In the special case of a FIELD_DECL node which represents a bit-field,
2115 the "offset" part of this special location descriptor must indicate the
2116 distance in bytes from the lowest-addressed byte of the containing
2117 struct or union type to the lowest-addressed byte of the "containing
2118 object" for the bit-field. (See the `field_byte_offset' function above.)
2120 For any given bit-field, the "containing object" is a hypothetical
2121 object (of some integral or enum type) within which the given bit-field
2122 lives. The type of this hypothetical "containing object" is always the
2123 same as the declared type of the individual bit-field itself (for GCC
2124 anyway... the DWARF spec doesn't actually mandate this).
2126 Note that it is the size (in bytes) of the hypothetical "containing
2127 object" which will be given in the AT_byte_size attribute for this
2128 bit-field. (See the `byte_size_attribute' function below.) It is
2129 also used when calculating the value of the AT_bit_offset attribute.
2130 (See the `bit_offset_attribute' function below.) */
2132 static void
2133 data_member_location_attribute (t)
2134 register tree t;
2136 register unsigned object_offset_in_bytes;
2137 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2138 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2140 if (TREE_CODE (t) == TREE_VEC)
2141 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2142 else
2143 object_offset_in_bytes = field_byte_offset (t);
2145 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2146 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2147 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2148 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2149 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2150 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2151 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2152 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2153 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2156 /* Output an AT_const_value attribute for a variable or a parameter which
2157 does not have a "location" either in memory or in a register. These
2158 things can arise in GNU C when a constant is passed as an actual
2159 parameter to an inlined function. They can also arise in C++ where
2160 declared constants do not necessarily get memory "homes". */
2162 static void
2163 const_value_attribute (rtl)
2164 register rtx rtl;
2166 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2167 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2169 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2170 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2171 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2172 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2173 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2175 switch (GET_CODE (rtl))
2177 case CONST_INT:
2178 /* Note that a CONST_INT rtx could represent either an integer or
2179 a floating-point constant. A CONST_INT is used whenever the
2180 constant will fit into a single word. In all such cases, the
2181 original mode of the constant value is wiped out, and the
2182 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2183 precise mode information for these constants, we always just
2184 output them using 4 bytes. */
2186 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2187 break;
2189 case CONST_DOUBLE:
2190 /* Note that a CONST_DOUBLE rtx could represent either an integer
2191 or a floating-point constant. A CONST_DOUBLE is used whenever
2192 the constant requires more than one word in order to be adequately
2193 represented. In all such cases, the original mode of the constant
2194 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2195 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2197 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2198 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2199 (unsigned int) CONST_DOUBLE_LOW (rtl));
2200 break;
2202 case CONST_STRING:
2203 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2204 break;
2206 case SYMBOL_REF:
2207 case LABEL_REF:
2208 case CONST:
2209 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2210 break;
2212 case PLUS:
2213 /* In cases where an inlined instance of an inline function is passed
2214 the address of an `auto' variable (which is local to the caller)
2215 we can get a situation where the DECL_RTL of the artificial
2216 local variable (for the inlining) which acts as a stand-in for
2217 the corresponding formal parameter (of the inline function)
2218 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2219 This is not exactly a compile-time constant expression, but it
2220 isn't the address of the (artificial) local variable either.
2221 Rather, it represents the *value* which the artificial local
2222 variable always has during its lifetime. We currently have no
2223 way to represent such quasi-constant values in Dwarf, so for now
2224 we just punt and generate an AT_const_value attribute with form
2225 FORM_BLOCK4 and a length of zero. */
2226 break;
2228 default:
2229 abort (); /* No other kinds of rtx should be possible here. */
2232 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2235 /* Generate *either* an AT_location attribute or else an AT_const_value
2236 data attribute for a variable or a parameter. We generate the
2237 AT_const_value attribute only in those cases where the given
2238 variable or parameter does not have a true "location" either in
2239 memory or in a register. This can happen (for example) when a
2240 constant is passed as an actual argument in a call to an inline
2241 function. (It's possible that these things can crop up in other
2242 ways also.) Note that one type of constant value which can be
2243 passed into an inlined function is a constant pointer. This can
2244 happen for example if an actual argument in an inlined function
2245 call evaluates to a compile-time constant address. */
2247 static void
2248 location_or_const_value_attribute (decl)
2249 register tree decl;
2251 register rtx rtl;
2253 if (TREE_CODE (decl) == ERROR_MARK)
2254 return;
2256 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2258 /* Should never happen. */
2259 abort ();
2260 return;
2263 /* Here we have to decide where we are going to say the parameter "lives"
2264 (as far as the debugger is concerned). We only have a couple of choices.
2265 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2266 normally indicates where the parameter lives during most of the activa-
2267 tion of the function. If optimization is enabled however, this could
2268 be either NULL or else a pseudo-reg. Both of those cases indicate that
2269 the parameter doesn't really live anywhere (as far as the code generation
2270 parts of GCC are concerned) during most of the function's activation.
2271 That will happen (for example) if the parameter is never referenced
2272 within the function.
2274 We could just generate a location descriptor here for all non-NULL
2275 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2276 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2277 cases where DECL_RTL is NULL or is a pseudo-reg.
2279 Note however that we can only get away with using DECL_INCOMING_RTL as
2280 a backup substitute for DECL_RTL in certain limited cases. In cases
2281 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2282 we can be sure that the parameter was passed using the same type as it
2283 is declared to have within the function, and that its DECL_INCOMING_RTL
2284 points us to a place where a value of that type is passed. In cases
2285 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2286 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2287 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2288 points us to a value of some type which is *different* from the type
2289 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2290 to generate a location attribute in such cases, the debugger would
2291 end up (for example) trying to fetch a `float' from a place which
2292 actually contains the first part of a `double'. That would lead to
2293 really incorrect and confusing output at debug-time, and we don't
2294 want that now do we?
2296 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2297 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2298 couple of cute exceptions however. On little-endian machines we can
2299 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2300 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2301 an integral type which is smaller than TREE_TYPE(decl). These cases
2302 arise when (on a little-endian machine) a non-prototyped function has
2303 a parameter declared to be of type `short' or `char'. In such cases,
2304 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2305 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2306 passed `int' value. If the debugger then uses that address to fetch a
2307 `short' or a `char' (on a little-endian machine) the result will be the
2308 correct data, so we allow for such exceptional cases below.
2310 Note that our goal here is to describe the place where the given formal
2311 parameter lives during most of the function's activation (i.e. between
2312 the end of the prologue and the start of the epilogue). We'll do that
2313 as best as we can. Note however that if the given formal parameter is
2314 modified sometime during the execution of the function, then a stack
2315 backtrace (at debug-time) will show the function as having been called
2316 with the *new* value rather than the value which was originally passed
2317 in. This happens rarely enough that it is not a major problem, but it
2318 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2319 may generate two additional attributes for any given TAG_formal_parameter
2320 DIE which will describe the "passed type" and the "passed location" for
2321 the given formal parameter in addition to the attributes we now generate
2322 to indicate the "declared type" and the "active location" for each
2323 parameter. This additional set of attributes could be used by debuggers
2324 for stack backtraces.
2326 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2327 can be NULL also. This happens (for example) for inlined-instances of
2328 inline function formal parameters which are never referenced. This really
2329 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2330 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2331 these values for inlined instances of inline function parameters, so
2332 when we see such cases, we are just out-of-luck for the time
2333 being (until integrate.c gets fixed).
2336 /* Use DECL_RTL as the "location" unless we find something better. */
2337 rtl = DECL_RTL (decl);
2339 if (TREE_CODE (decl) == PARM_DECL)
2340 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2342 /* This decl represents a formal parameter which was optimized out. */
2343 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2344 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2346 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2347 *all* cases where (rtl == NULL_RTX) just below. */
2349 if (declared_type == passed_type)
2350 rtl = DECL_INCOMING_RTL (decl);
2351 else if (! BYTES_BIG_ENDIAN)
2352 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2353 /* NMS WTF? */
2354 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2355 rtl = DECL_INCOMING_RTL (decl);
2358 if (rtl == NULL_RTX)
2359 return;
2361 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2362 #ifdef LEAF_REG_REMAP
2363 if (current_function_uses_only_leaf_regs)
2364 leaf_renumber_regs_insn (rtl);
2365 #endif
2367 switch (GET_CODE (rtl))
2369 case ADDRESSOF:
2370 /* The address of a variable that was optimized away; don't emit
2371 anything. */
2372 break;
2374 case CONST_INT:
2375 case CONST_DOUBLE:
2376 case CONST_STRING:
2377 case SYMBOL_REF:
2378 case LABEL_REF:
2379 case CONST:
2380 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2381 const_value_attribute (rtl);
2382 break;
2384 case MEM:
2385 case REG:
2386 case SUBREG:
2387 location_attribute (rtl);
2388 break;
2390 case CONCAT:
2391 /* ??? CONCAT is used for complex variables, which may have the real
2392 part stored in one place and the imag part stored somewhere else.
2393 DWARF1 has no way to describe a variable that lives in two different
2394 places, so we just describe where the first part lives, and hope that
2395 the second part is stored after it. */
2396 location_attribute (XEXP (rtl, 0));
2397 break;
2399 default:
2400 abort (); /* Should never happen. */
2404 /* Generate an AT_name attribute given some string value to be included as
2405 the value of the attribute. */
2407 static inline void
2408 name_attribute (name_string)
2409 register const char *name_string;
2411 if (name_string && *name_string)
2413 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2414 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2418 static inline void
2419 fund_type_attribute (ft_code)
2420 register unsigned ft_code;
2422 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2423 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2426 static void
2427 mod_fund_type_attribute (type, decl_const, decl_volatile)
2428 register tree type;
2429 register int decl_const;
2430 register int decl_volatile;
2432 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2433 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2435 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2436 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2437 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2438 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2439 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2440 write_modifier_bytes (type, decl_const, decl_volatile);
2441 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2442 fundamental_type_code (root_type (type)));
2443 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2446 static inline void
2447 user_def_type_attribute (type)
2448 register tree type;
2450 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2452 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2453 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2454 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2457 static void
2458 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2459 register tree type;
2460 register int decl_const;
2461 register int decl_volatile;
2463 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2464 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2465 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2467 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2468 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2469 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2470 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2471 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2472 write_modifier_bytes (type, decl_const, decl_volatile);
2473 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2474 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2475 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2478 #ifdef USE_ORDERING_ATTRIBUTE
2479 static inline void
2480 ordering_attribute (ordering)
2481 register unsigned ordering;
2483 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2484 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2486 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2488 /* Note that the block of subscript information for an array type also
2489 includes information about the element type of type given array type. */
2491 static void
2492 subscript_data_attribute (type)
2493 register tree type;
2495 register unsigned dimension_number;
2496 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2497 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2499 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2500 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2501 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2502 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2503 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2505 /* The GNU compilers represent multidimensional array types as sequences
2506 of one dimensional array types whose element types are themselves array
2507 types. Here we squish that down, so that each multidimensional array
2508 type gets only one array_type DIE in the Dwarf debugging info. The
2509 draft Dwarf specification say that we are allowed to do this kind
2510 of compression in C (because there is no difference between an
2511 array or arrays and a multidimensional array in C) but for other
2512 source languages (e.g. Ada) we probably shouldn't do this. */
2514 for (dimension_number = 0;
2515 TREE_CODE (type) == ARRAY_TYPE;
2516 type = TREE_TYPE (type), dimension_number++)
2518 register tree domain = TYPE_DOMAIN (type);
2520 /* Arrays come in three flavors. Unspecified bounds, fixed
2521 bounds, and (in GNU C only) variable bounds. Handle all
2522 three forms here. */
2524 if (domain)
2526 /* We have an array type with specified bounds. */
2528 register tree lower = TYPE_MIN_VALUE (domain);
2529 register tree upper = TYPE_MAX_VALUE (domain);
2531 /* Handle only fundamental types as index types for now. */
2532 if (! type_is_fundamental (domain))
2533 abort ();
2535 /* Output the representation format byte for this dimension. */
2536 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2537 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2538 upper && TREE_CODE (upper) == INTEGER_CST));
2540 /* Output the index type for this dimension. */
2541 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2542 fundamental_type_code (domain));
2544 /* Output the representation for the lower bound. */
2545 output_bound_representation (lower, dimension_number, 'l');
2547 /* Output the representation for the upper bound. */
2548 if (upper)
2549 output_bound_representation (upper, dimension_number, 'u');
2550 else
2551 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2553 else
2555 /* We have an array type with an unspecified length. For C and
2556 C++ we can assume that this really means that (a) the index
2557 type is an integral type, and (b) the lower bound is zero.
2558 Note that Dwarf defines the representation of an unspecified
2559 (upper) bound as being a zero-length location description. */
2561 /* Output the array-bounds format byte. */
2563 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2565 /* Output the (assumed) index type. */
2567 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2569 /* Output the (assumed) lower bound (constant) value. */
2571 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2573 /* Output the (empty) location description for the upper bound. */
2575 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2579 /* Output the prefix byte that says that the element type is coming up. */
2581 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2583 /* Output a representation of the type of the elements of this array type. */
2585 type_attribute (type, 0, 0);
2587 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2590 static void
2591 byte_size_attribute (tree_node)
2592 register tree tree_node;
2594 register unsigned size;
2596 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2597 switch (TREE_CODE (tree_node))
2599 case ERROR_MARK:
2600 size = 0;
2601 break;
2603 case ENUMERAL_TYPE:
2604 case RECORD_TYPE:
2605 case UNION_TYPE:
2606 case QUAL_UNION_TYPE:
2607 case ARRAY_TYPE:
2608 size = int_size_in_bytes (tree_node);
2609 break;
2611 case FIELD_DECL:
2612 /* For a data member of a struct or union, the AT_byte_size is
2613 generally given as the number of bytes normally allocated for
2614 an object of the *declared* type of the member itself. This
2615 is true even for bit-fields. */
2616 size = simple_type_size_in_bits (field_type (tree_node))
2617 / BITS_PER_UNIT;
2618 break;
2620 default:
2621 abort ();
2624 /* Note that `size' might be -1 when we get to this point. If it
2625 is, that indicates that the byte size of the entity in question
2626 is variable. We have no good way of expressing this fact in Dwarf
2627 at the present time, so just let the -1 pass on through. */
2629 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2632 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2633 which specifies the distance in bits from the highest order bit of the
2634 "containing object" for the bit-field to the highest order bit of the
2635 bit-field itself.
2637 For any given bit-field, the "containing object" is a hypothetical
2638 object (of some integral or enum type) within which the given bit-field
2639 lives. The type of this hypothetical "containing object" is always the
2640 same as the declared type of the individual bit-field itself.
2642 The determination of the exact location of the "containing object" for
2643 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2644 function (above).
2646 Note that it is the size (in bytes) of the hypothetical "containing
2647 object" which will be given in the AT_byte_size attribute for this
2648 bit-field. (See `byte_size_attribute' above.) */
2650 static inline void
2651 bit_offset_attribute (decl)
2652 register tree decl;
2654 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
2655 tree type = DECL_BIT_FIELD_TYPE (decl);
2656 HOST_WIDE_INT bitpos_int;
2657 HOST_WIDE_INT highest_order_object_bit_offset;
2658 HOST_WIDE_INT highest_order_field_bit_offset;
2659 HOST_WIDE_INT bit_offset;
2661 /* Must be a bit field. */
2662 if (!type
2663 || TREE_CODE (decl) != FIELD_DECL)
2664 abort ();
2666 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
2667 if we encounter such things, just return without generating any
2668 attribute whatsoever. */
2670 if (! host_integerp (bit_position (decl), 0)
2671 || ! host_integerp (DECL_SIZE (decl), 1))
2672 return;
2674 bitpos_int = int_bit_position (decl);
2676 /* Note that the bit offset is always the distance (in bits) from the
2677 highest-order bit of the "containing object" to the highest-order
2678 bit of the bit-field itself. Since the "high-order end" of any
2679 object or field is different on big-endian and little-endian machines,
2680 the computation below must take account of these differences. */
2682 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2683 highest_order_field_bit_offset = bitpos_int;
2685 if (! BYTES_BIG_ENDIAN)
2687 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
2688 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2691 bit_offset =
2692 (! BYTES_BIG_ENDIAN
2693 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2694 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2696 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2697 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2700 /* For a FIELD_DECL node which represents a bit field, output an attribute
2701 which specifies the length in bits of the given field. */
2703 static inline void
2704 bit_size_attribute (decl)
2705 register tree decl;
2707 /* Must be a field and a bit field. */
2708 if (TREE_CODE (decl) != FIELD_DECL
2709 || ! DECL_BIT_FIELD_TYPE (decl))
2710 abort ();
2712 if (host_integerp (DECL_SIZE (decl), 1))
2714 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2715 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2716 tree_low_cst (DECL_SIZE (decl), 1));
2720 /* The following routine outputs the `element_list' attribute for enumeration
2721 type DIEs. The element_lits attribute includes the names and values of
2722 all of the enumeration constants associated with the given enumeration
2723 type. */
2725 static inline void
2726 element_list_attribute (element)
2727 register tree element;
2729 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2730 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2732 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2733 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2734 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2735 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2736 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2738 /* Here we output a list of value/name pairs for each enumeration constant
2739 defined for this enumeration type (as required), but we do it in REVERSE
2740 order. The order is the one required by the draft #5 Dwarf specification
2741 published by the UI/PLSIG. */
2743 output_enumeral_list (element); /* Recursively output the whole list. */
2745 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2748 /* Generate an AT_stmt_list attribute. These are normally present only in
2749 DIEs with a TAG_compile_unit tag. */
2751 static inline void
2752 stmt_list_attribute (label)
2753 register const char *label;
2755 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2756 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2757 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2760 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2761 for a subroutine DIE. */
2763 static inline void
2764 low_pc_attribute (asm_low_label)
2765 register const char *asm_low_label;
2767 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2768 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2771 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2772 subroutine DIE. */
2774 static inline void
2775 high_pc_attribute (asm_high_label)
2776 register const char *asm_high_label;
2778 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2779 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2782 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2784 static inline void
2785 body_begin_attribute (asm_begin_label)
2786 register const char *asm_begin_label;
2788 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2789 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2792 /* Generate an AT_body_end attribute for a subroutine DIE. */
2794 static inline void
2795 body_end_attribute (asm_end_label)
2796 register const char *asm_end_label;
2798 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2799 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2802 /* Generate an AT_language attribute given a LANG value. These attributes
2803 are used only within TAG_compile_unit DIEs. */
2805 static inline void
2806 language_attribute (language_code)
2807 register unsigned language_code;
2809 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2810 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2813 static inline void
2814 member_attribute (context)
2815 register tree context;
2817 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2819 /* Generate this attribute only for members in C++. */
2821 if (context != NULL && is_tagged_type (context))
2823 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2824 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2825 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2829 #if 0
2830 static inline void
2831 string_length_attribute (upper_bound)
2832 register tree upper_bound;
2834 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2835 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2837 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2838 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2839 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2840 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2841 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2842 output_bound_representation (upper_bound, 0, 'u');
2843 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2845 #endif
2847 static inline void
2848 comp_dir_attribute (dirname)
2849 register const char *dirname;
2851 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2852 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
2855 static inline void
2856 sf_names_attribute (sf_names_start_label)
2857 register const char *sf_names_start_label;
2859 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2860 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2861 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2864 static inline void
2865 src_info_attribute (src_info_start_label)
2866 register const char *src_info_start_label;
2868 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2869 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2870 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2873 static inline void
2874 mac_info_attribute (mac_info_start_label)
2875 register const char *mac_info_start_label;
2877 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2878 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2879 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2882 static inline void
2883 prototyped_attribute (func_type)
2884 register tree func_type;
2886 if ((strcmp (language_string, "GNU C") == 0)
2887 && (TYPE_ARG_TYPES (func_type) != NULL))
2889 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2890 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2894 static inline void
2895 producer_attribute (producer)
2896 register const char *producer;
2898 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2899 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
2902 static inline void
2903 inline_attribute (decl)
2904 register tree decl;
2906 if (DECL_INLINE (decl))
2908 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2909 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2913 static inline void
2914 containing_type_attribute (containing_type)
2915 register tree containing_type;
2917 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2919 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2920 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2921 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2924 static inline void
2925 abstract_origin_attribute (origin)
2926 register tree origin;
2928 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2930 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2931 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2933 case 'd':
2934 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2935 break;
2937 case 't':
2938 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2939 break;
2941 default:
2942 abort (); /* Should never happen. */
2945 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2948 #ifdef DWARF_DECL_COORDINATES
2949 static inline void
2950 src_coords_attribute (src_fileno, src_lineno)
2951 register unsigned src_fileno;
2952 register unsigned src_lineno;
2954 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2955 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2956 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2958 #endif /* defined(DWARF_DECL_COORDINATES) */
2960 static inline void
2961 pure_or_virtual_attribute (func_decl)
2962 register tree func_decl;
2964 if (DECL_VIRTUAL_P (func_decl))
2966 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
2967 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2968 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2969 else
2970 #endif
2971 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2972 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2976 /************************* end of attributes *****************************/
2978 /********************* utility routines for DIEs *************************/
2980 /* Output an AT_name attribute and an AT_src_coords attribute for the
2981 given decl, but only if it actually has a name. */
2983 static void
2984 name_and_src_coords_attributes (decl)
2985 register tree decl;
2987 register tree decl_name = DECL_NAME (decl);
2989 if (decl_name && IDENTIFIER_POINTER (decl_name))
2991 name_attribute (IDENTIFIER_POINTER (decl_name));
2992 #ifdef DWARF_DECL_COORDINATES
2994 register unsigned file_index;
2996 /* This is annoying, but we have to pop out of the .debug section
2997 for a moment while we call `lookup_filename' because calling it
2998 may cause a temporary switch into the .debug_sfnames section and
2999 most svr4 assemblers are not smart enough to be able to nest
3000 section switches to any depth greater than one. Note that we
3001 also can't skirt this issue by delaying all output to the
3002 .debug_sfnames section unit the end of compilation because that
3003 would cause us to have inter-section forward references and
3004 Fred Fish sez that m68k/svr4 assemblers botch those. */
3006 ASM_OUTPUT_POP_SECTION (asm_out_file);
3007 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3008 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3010 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3012 #endif /* defined(DWARF_DECL_COORDINATES) */
3016 /* Many forms of DIEs contain a "type description" part. The following
3017 routine writes out these "type descriptor" parts. */
3019 static void
3020 type_attribute (type, decl_const, decl_volatile)
3021 register tree type;
3022 register int decl_const;
3023 register int decl_volatile;
3025 register enum tree_code code = TREE_CODE (type);
3026 register int root_type_modified;
3028 if (code == ERROR_MARK)
3029 return;
3031 /* Handle a special case. For functions whose return type is void,
3032 we generate *no* type attribute. (Note that no object may have
3033 type `void', so this only applies to function return types. */
3035 if (code == VOID_TYPE)
3036 return;
3038 /* If this is a subtype, find the underlying type. Eventually,
3039 this should write out the appropriate subtype info. */
3040 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3041 && TREE_TYPE (type) != 0)
3042 type = TREE_TYPE (type), code = TREE_CODE (type);
3044 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3045 || decl_const || decl_volatile
3046 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3048 if (type_is_fundamental (root_type (type)))
3050 if (root_type_modified)
3051 mod_fund_type_attribute (type, decl_const, decl_volatile);
3052 else
3053 fund_type_attribute (fundamental_type_code (type));
3055 else
3057 if (root_type_modified)
3058 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3059 else
3060 /* We have to get the type_main_variant here (and pass that to the
3061 `user_def_type_attribute' routine) because the ..._TYPE node we
3062 have might simply be a *copy* of some original type node (where
3063 the copy was created to help us keep track of typedef names)
3064 and that copy might have a different TYPE_UID from the original
3065 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3066 is labeling a given type DIE for future reference, it always and
3067 only creates labels for DIEs representing *main variants*, and it
3068 never even knows about non-main-variants.) */
3069 user_def_type_attribute (type_main_variant (type));
3073 /* Given a tree pointer to a struct, class, union, or enum type node, return
3074 a pointer to the (string) tag name for the given type, or zero if the
3075 type was declared without a tag. */
3077 static const char *
3078 type_tag (type)
3079 register tree type;
3081 register const char *name = 0;
3083 if (TYPE_NAME (type) != 0)
3085 register tree t = 0;
3087 /* Find the IDENTIFIER_NODE for the type name. */
3088 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3089 t = TYPE_NAME (type);
3091 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3092 a TYPE_DECL node, regardless of whether or not a `typedef' was
3093 involved. */
3094 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3095 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3096 t = DECL_NAME (TYPE_NAME (type));
3098 /* Now get the name as a string, or invent one. */
3099 if (t != 0)
3100 name = IDENTIFIER_POINTER (t);
3103 return (name == 0 || *name == '\0') ? 0 : name;
3106 static inline void
3107 dienum_push ()
3109 /* Start by checking if the pending_sibling_stack needs to be expanded.
3110 If necessary, expand it. */
3112 if (pending_siblings == pending_siblings_allocated)
3114 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3115 pending_sibling_stack
3116 = (unsigned *) xrealloc (pending_sibling_stack,
3117 pending_siblings_allocated * sizeof(unsigned));
3120 pending_siblings++;
3121 NEXT_DIE_NUM = next_unused_dienum++;
3124 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3125 NEXT_DIE_NUM. */
3127 static inline void
3128 dienum_pop ()
3130 pending_siblings--;
3133 static inline tree
3134 member_declared_type (member)
3135 register tree member;
3137 return (DECL_BIT_FIELD_TYPE (member))
3138 ? DECL_BIT_FIELD_TYPE (member)
3139 : TREE_TYPE (member);
3142 /* Get the function's label, as described by its RTL.
3143 This may be different from the DECL_NAME name used
3144 in the source file. */
3146 static const char *
3147 function_start_label (decl)
3148 register tree decl;
3150 rtx x;
3151 const char *fnname;
3153 x = DECL_RTL (decl);
3154 if (GET_CODE (x) != MEM)
3155 abort ();
3156 x = XEXP (x, 0);
3157 if (GET_CODE (x) != SYMBOL_REF)
3158 abort ();
3159 fnname = XSTR (x, 0);
3160 return fnname;
3164 /******************************* DIEs ************************************/
3166 /* Output routines for individual types of DIEs. */
3168 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3170 static void
3171 output_array_type_die (arg)
3172 register void *arg;
3174 register tree type = arg;
3176 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3177 sibling_attribute ();
3178 equate_type_number_to_die_number (type);
3179 member_attribute (TYPE_CONTEXT (type));
3181 /* I believe that we can default the array ordering. SDB will probably
3182 do the right things even if AT_ordering is not present. It's not
3183 even an issue until we start to get into multidimensional arrays
3184 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3185 dimensional arrays, then we'll have to put the AT_ordering attribute
3186 back in. (But if and when we find out that we need to put these in,
3187 we will only do so for multidimensional arrays. After all, we don't
3188 want to waste space in the .debug section now do we?) */
3190 #ifdef USE_ORDERING_ATTRIBUTE
3191 ordering_attribute (ORD_row_major);
3192 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3194 subscript_data_attribute (type);
3197 static void
3198 output_set_type_die (arg)
3199 register void *arg;
3201 register tree type = arg;
3203 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3204 sibling_attribute ();
3205 equate_type_number_to_die_number (type);
3206 member_attribute (TYPE_CONTEXT (type));
3207 type_attribute (TREE_TYPE (type), 0, 0);
3210 #if 0
3211 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3213 static void
3214 output_entry_point_die (arg)
3215 register void *arg;
3217 register tree decl = arg;
3218 register tree origin = decl_ultimate_origin (decl);
3220 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3221 sibling_attribute ();
3222 dienum_push ();
3223 if (origin != NULL)
3224 abstract_origin_attribute (origin);
3225 else
3227 name_and_src_coords_attributes (decl);
3228 member_attribute (DECL_CONTEXT (decl));
3229 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3231 if (DECL_ABSTRACT (decl))
3232 equate_decl_number_to_die_number (decl);
3233 else
3234 low_pc_attribute (function_start_label (decl));
3236 #endif
3238 /* Output a DIE to represent an inlined instance of an enumeration type. */
3240 static void
3241 output_inlined_enumeration_type_die (arg)
3242 register void *arg;
3244 register tree type = arg;
3246 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3247 sibling_attribute ();
3248 if (!TREE_ASM_WRITTEN (type))
3249 abort ();
3250 abstract_origin_attribute (type);
3253 /* Output a DIE to represent an inlined instance of a structure type. */
3255 static void
3256 output_inlined_structure_type_die (arg)
3257 register void *arg;
3259 register tree type = arg;
3261 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3262 sibling_attribute ();
3263 if (!TREE_ASM_WRITTEN (type))
3264 abort ();
3265 abstract_origin_attribute (type);
3268 /* Output a DIE to represent an inlined instance of a union type. */
3270 static void
3271 output_inlined_union_type_die (arg)
3272 register void *arg;
3274 register tree type = arg;
3276 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3277 sibling_attribute ();
3278 if (!TREE_ASM_WRITTEN (type))
3279 abort ();
3280 abstract_origin_attribute (type);
3283 /* Output a DIE to represent an enumeration type. Note that these DIEs
3284 include all of the information about the enumeration values also.
3285 This information is encoded into the element_list attribute. */
3287 static void
3288 output_enumeration_type_die (arg)
3289 register void *arg;
3291 register tree type = arg;
3293 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3294 sibling_attribute ();
3295 equate_type_number_to_die_number (type);
3296 name_attribute (type_tag (type));
3297 member_attribute (TYPE_CONTEXT (type));
3299 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3300 given enum type is incomplete, do not generate the AT_byte_size
3301 attribute or the AT_element_list attribute. */
3303 if (COMPLETE_TYPE_P (type))
3305 byte_size_attribute (type);
3306 element_list_attribute (TYPE_FIELDS (type));
3310 /* Output a DIE to represent either a real live formal parameter decl or
3311 to represent just the type of some formal parameter position in some
3312 function type.
3314 Note that this routine is a bit unusual because its argument may be
3315 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3316 represents an inlining of some PARM_DECL) or else some sort of a
3317 ..._TYPE node. If it's the former then this function is being called
3318 to output a DIE to represent a formal parameter object (or some inlining
3319 thereof). If it's the latter, then this function is only being called
3320 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3321 formal argument type of some subprogram type. */
3323 static void
3324 output_formal_parameter_die (arg)
3325 register void *arg;
3327 register tree node = arg;
3329 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3330 sibling_attribute ();
3332 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3334 case 'd': /* We were called with some kind of a ..._DECL node. */
3336 register tree origin = decl_ultimate_origin (node);
3338 if (origin != NULL)
3339 abstract_origin_attribute (origin);
3340 else
3342 name_and_src_coords_attributes (node);
3343 type_attribute (TREE_TYPE (node),
3344 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3346 if (DECL_ABSTRACT (node))
3347 equate_decl_number_to_die_number (node);
3348 else
3349 location_or_const_value_attribute (node);
3351 break;
3353 case 't': /* We were called with some kind of a ..._TYPE node. */
3354 type_attribute (node, 0, 0);
3355 break;
3357 default:
3358 abort (); /* Should never happen. */
3362 /* Output a DIE to represent a declared function (either file-scope
3363 or block-local) which has "external linkage" (according to ANSI-C). */
3365 static void
3366 output_global_subroutine_die (arg)
3367 register void *arg;
3369 register tree decl = arg;
3370 register tree origin = decl_ultimate_origin (decl);
3372 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3373 sibling_attribute ();
3374 dienum_push ();
3375 if (origin != NULL)
3376 abstract_origin_attribute (origin);
3377 else
3379 register tree type = TREE_TYPE (decl);
3381 name_and_src_coords_attributes (decl);
3382 inline_attribute (decl);
3383 prototyped_attribute (type);
3384 member_attribute (DECL_CONTEXT (decl));
3385 type_attribute (TREE_TYPE (type), 0, 0);
3386 pure_or_virtual_attribute (decl);
3388 if (DECL_ABSTRACT (decl))
3389 equate_decl_number_to_die_number (decl);
3390 else
3392 if (! DECL_EXTERNAL (decl) && ! in_class
3393 && decl == current_function_decl)
3395 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3397 low_pc_attribute (function_start_label (decl));
3398 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3399 high_pc_attribute (label);
3400 if (use_gnu_debug_info_extensions)
3402 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3403 body_begin_attribute (label);
3404 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3405 body_end_attribute (label);
3411 /* Output a DIE to represent a declared data object (either file-scope
3412 or block-local) which has "external linkage" (according to ANSI-C). */
3414 static void
3415 output_global_variable_die (arg)
3416 register void *arg;
3418 register tree decl = arg;
3419 register tree origin = decl_ultimate_origin (decl);
3421 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3422 sibling_attribute ();
3423 if (origin != NULL)
3424 abstract_origin_attribute (origin);
3425 else
3427 name_and_src_coords_attributes (decl);
3428 member_attribute (DECL_CONTEXT (decl));
3429 type_attribute (TREE_TYPE (decl),
3430 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3432 if (DECL_ABSTRACT (decl))
3433 equate_decl_number_to_die_number (decl);
3434 else
3436 if (! DECL_EXTERNAL (decl) && ! in_class
3437 && current_function_decl == decl_function_context (decl))
3438 location_or_const_value_attribute (decl);
3442 static void
3443 output_label_die (arg)
3444 register void *arg;
3446 register tree decl = arg;
3447 register tree origin = decl_ultimate_origin (decl);
3449 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3450 sibling_attribute ();
3451 if (origin != NULL)
3452 abstract_origin_attribute (origin);
3453 else
3454 name_and_src_coords_attributes (decl);
3455 if (DECL_ABSTRACT (decl))
3456 equate_decl_number_to_die_number (decl);
3457 else
3459 register rtx insn = DECL_RTL (decl);
3461 /* Deleted labels are programmer specified labels which have been
3462 eliminated because of various optimisations. We still emit them
3463 here so that it is possible to put breakpoints on them. */
3464 if (GET_CODE (insn) == CODE_LABEL
3465 || ((GET_CODE (insn) == NOTE
3466 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3468 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3470 /* When optimization is enabled (via -O) some parts of the compiler
3471 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3472 represent source-level labels which were explicitly declared by
3473 the user. This really shouldn't be happening though, so catch
3474 it if it ever does happen. */
3476 if (INSN_DELETED_P (insn))
3477 abort (); /* Should never happen. */
3479 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
3480 low_pc_attribute (label);
3485 static void
3486 output_lexical_block_die (arg)
3487 register void *arg;
3489 register tree stmt = arg;
3491 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3492 sibling_attribute ();
3493 dienum_push ();
3494 if (! BLOCK_ABSTRACT (stmt))
3496 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3497 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3499 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3500 low_pc_attribute (begin_label);
3501 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3502 high_pc_attribute (end_label);
3506 static void
3507 output_inlined_subroutine_die (arg)
3508 register void *arg;
3510 register tree stmt = arg;
3512 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3513 sibling_attribute ();
3514 dienum_push ();
3515 abstract_origin_attribute (block_ultimate_origin (stmt));
3516 if (! BLOCK_ABSTRACT (stmt))
3518 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3519 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3521 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3522 low_pc_attribute (begin_label);
3523 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3524 high_pc_attribute (end_label);
3528 /* Output a DIE to represent a declared data object (either file-scope
3529 or block-local) which has "internal linkage" (according to ANSI-C). */
3531 static void
3532 output_local_variable_die (arg)
3533 register void *arg;
3535 register tree decl = arg;
3536 register tree origin = decl_ultimate_origin (decl);
3538 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3539 sibling_attribute ();
3540 if (origin != NULL)
3541 abstract_origin_attribute (origin);
3542 else
3544 name_and_src_coords_attributes (decl);
3545 member_attribute (DECL_CONTEXT (decl));
3546 type_attribute (TREE_TYPE (decl),
3547 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3549 if (DECL_ABSTRACT (decl))
3550 equate_decl_number_to_die_number (decl);
3551 else
3552 location_or_const_value_attribute (decl);
3555 static void
3556 output_member_die (arg)
3557 register void *arg;
3559 register tree decl = arg;
3561 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3562 sibling_attribute ();
3563 name_and_src_coords_attributes (decl);
3564 member_attribute (DECL_CONTEXT (decl));
3565 type_attribute (member_declared_type (decl),
3566 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3567 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3569 byte_size_attribute (decl);
3570 bit_size_attribute (decl);
3571 bit_offset_attribute (decl);
3573 data_member_location_attribute (decl);
3576 #if 0
3577 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3578 modified types instead.
3580 We keep this code here just in case these types of DIEs may be
3581 needed to represent certain things in other languages (e.g. Pascal)
3582 someday. */
3584 static void
3585 output_pointer_type_die (arg)
3586 register void *arg;
3588 register tree type = arg;
3590 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3591 sibling_attribute ();
3592 equate_type_number_to_die_number (type);
3593 member_attribute (TYPE_CONTEXT (type));
3594 type_attribute (TREE_TYPE (type), 0, 0);
3597 static void
3598 output_reference_type_die (arg)
3599 register void *arg;
3601 register tree type = arg;
3603 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3604 sibling_attribute ();
3605 equate_type_number_to_die_number (type);
3606 member_attribute (TYPE_CONTEXT (type));
3607 type_attribute (TREE_TYPE (type), 0, 0);
3609 #endif
3611 static void
3612 output_ptr_to_mbr_type_die (arg)
3613 register void *arg;
3615 register tree type = arg;
3617 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3618 sibling_attribute ();
3619 equate_type_number_to_die_number (type);
3620 member_attribute (TYPE_CONTEXT (type));
3621 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3622 type_attribute (TREE_TYPE (type), 0, 0);
3625 static void
3626 output_compile_unit_die (arg)
3627 register void *arg;
3629 register const char *main_input_filename = arg;
3631 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3632 sibling_attribute ();
3633 dienum_push ();
3634 name_attribute (main_input_filename);
3637 char producer[250];
3639 sprintf (producer, "%s %s", language_string, version_string);
3640 producer_attribute (producer);
3643 if (strcmp (language_string, "GNU C++") == 0)
3644 language_attribute (LANG_C_PLUS_PLUS);
3645 else if (strcmp (language_string, "GNU Ada") == 0)
3646 language_attribute (LANG_ADA83);
3647 else if (strcmp (language_string, "GNU F77") == 0)
3648 language_attribute (LANG_FORTRAN77);
3649 else if (strcmp (language_string, "GNU Pascal") == 0)
3650 language_attribute (LANG_PASCAL83);
3651 else if (strcmp (language_string, "GNU Java") == 0)
3652 language_attribute (LANG_JAVA);
3653 else if (flag_traditional)
3654 language_attribute (LANG_C);
3655 else
3656 language_attribute (LANG_C89);
3657 low_pc_attribute (TEXT_BEGIN_LABEL);
3658 high_pc_attribute (TEXT_END_LABEL);
3659 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3660 stmt_list_attribute (LINE_BEGIN_LABEL);
3661 last_filename = xstrdup (main_input_filename);
3664 const char *wd = getpwd ();
3665 if (wd)
3666 comp_dir_attribute (wd);
3669 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3671 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3672 src_info_attribute (SRCINFO_BEGIN_LABEL);
3673 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3674 mac_info_attribute (MACINFO_BEGIN_LABEL);
3678 static void
3679 output_string_type_die (arg)
3680 register void *arg;
3682 register tree type = arg;
3684 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3685 sibling_attribute ();
3686 equate_type_number_to_die_number (type);
3687 member_attribute (TYPE_CONTEXT (type));
3688 /* this is a fixed length string */
3689 byte_size_attribute (type);
3692 static void
3693 output_inheritance_die (arg)
3694 register void *arg;
3696 register tree binfo = arg;
3698 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3699 sibling_attribute ();
3700 type_attribute (BINFO_TYPE (binfo), 0, 0);
3701 data_member_location_attribute (binfo);
3702 if (TREE_VIA_VIRTUAL (binfo))
3704 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3705 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3707 if (TREE_VIA_PUBLIC (binfo))
3709 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3710 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3712 else if (TREE_VIA_PROTECTED (binfo))
3714 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3715 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3719 static void
3720 output_structure_type_die (arg)
3721 register void *arg;
3723 register tree type = arg;
3725 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3726 sibling_attribute ();
3727 equate_type_number_to_die_number (type);
3728 name_attribute (type_tag (type));
3729 member_attribute (TYPE_CONTEXT (type));
3731 /* If this type has been completed, then give it a byte_size attribute
3732 and prepare to give a list of members. Otherwise, don't do either of
3733 these things. In the latter case, we will not be generating a list
3734 of members (since we don't have any idea what they might be for an
3735 incomplete type). */
3737 if (COMPLETE_TYPE_P (type))
3739 dienum_push ();
3740 byte_size_attribute (type);
3744 /* Output a DIE to represent a declared function (either file-scope
3745 or block-local) which has "internal linkage" (according to ANSI-C). */
3747 static void
3748 output_local_subroutine_die (arg)
3749 register void *arg;
3751 register tree decl = arg;
3752 register tree origin = decl_ultimate_origin (decl);
3754 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3755 sibling_attribute ();
3756 dienum_push ();
3757 if (origin != NULL)
3758 abstract_origin_attribute (origin);
3759 else
3761 register tree type = TREE_TYPE (decl);
3763 name_and_src_coords_attributes (decl);
3764 inline_attribute (decl);
3765 prototyped_attribute (type);
3766 member_attribute (DECL_CONTEXT (decl));
3767 type_attribute (TREE_TYPE (type), 0, 0);
3768 pure_or_virtual_attribute (decl);
3770 if (DECL_ABSTRACT (decl))
3771 equate_decl_number_to_die_number (decl);
3772 else
3774 /* Avoid getting screwed up in cases where a function was declared
3775 static but where no definition was ever given for it. */
3777 if (TREE_ASM_WRITTEN (decl))
3779 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3780 low_pc_attribute (function_start_label (decl));
3781 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3782 high_pc_attribute (label);
3783 if (use_gnu_debug_info_extensions)
3785 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3786 body_begin_attribute (label);
3787 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3788 body_end_attribute (label);
3794 static void
3795 output_subroutine_type_die (arg)
3796 register void *arg;
3798 register tree type = arg;
3799 register tree return_type = TREE_TYPE (type);
3801 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3802 sibling_attribute ();
3803 dienum_push ();
3804 equate_type_number_to_die_number (type);
3805 prototyped_attribute (type);
3806 member_attribute (TYPE_CONTEXT (type));
3807 type_attribute (return_type, 0, 0);
3810 static void
3811 output_typedef_die (arg)
3812 register void *arg;
3814 register tree decl = arg;
3815 register tree origin = decl_ultimate_origin (decl);
3817 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3818 sibling_attribute ();
3819 if (origin != NULL)
3820 abstract_origin_attribute (origin);
3821 else
3823 name_and_src_coords_attributes (decl);
3824 member_attribute (DECL_CONTEXT (decl));
3825 type_attribute (TREE_TYPE (decl),
3826 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3828 if (DECL_ABSTRACT (decl))
3829 equate_decl_number_to_die_number (decl);
3832 static void
3833 output_union_type_die (arg)
3834 register void *arg;
3836 register tree type = arg;
3838 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3839 sibling_attribute ();
3840 equate_type_number_to_die_number (type);
3841 name_attribute (type_tag (type));
3842 member_attribute (TYPE_CONTEXT (type));
3844 /* If this type has been completed, then give it a byte_size attribute
3845 and prepare to give a list of members. Otherwise, don't do either of
3846 these things. In the latter case, we will not be generating a list
3847 of members (since we don't have any idea what they might be for an
3848 incomplete type). */
3850 if (COMPLETE_TYPE_P (type))
3852 dienum_push ();
3853 byte_size_attribute (type);
3857 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3858 at the end of an (ANSI prototyped) formal parameters list. */
3860 static void
3861 output_unspecified_parameters_die (arg)
3862 register void *arg;
3864 register tree decl_or_type = arg;
3866 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3867 sibling_attribute ();
3869 /* This kludge is here only for the sake of being compatible with what
3870 the USL CI5 C compiler does. The specification of Dwarf Version 1
3871 doesn't say that TAG_unspecified_parameters DIEs should contain any
3872 attributes other than the AT_sibling attribute, but they are certainly
3873 allowed to contain additional attributes, and the CI5 compiler
3874 generates AT_name, AT_fund_type, and AT_location attributes within
3875 TAG_unspecified_parameters DIEs which appear in the child lists for
3876 DIEs representing function definitions, so we do likewise here. */
3878 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3880 name_attribute ("...");
3881 fund_type_attribute (FT_pointer);
3882 /* location_attribute (?); */
3886 static void
3887 output_padded_null_die (arg)
3888 register void *arg ATTRIBUTE_UNUSED;
3890 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3893 /*************************** end of DIEs *********************************/
3895 /* Generate some type of DIE. This routine generates the generic outer
3896 wrapper stuff which goes around all types of DIE's (regardless of their
3897 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3898 DIE-length word, followed by the guts of the DIE itself. After the guts
3899 of the DIE, there must always be a terminator label for the DIE. */
3901 static void
3902 output_die (die_specific_output_function, param)
3903 register void (*die_specific_output_function) PARAMS ((void *));
3904 register void *param;
3906 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3907 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3909 current_dienum = NEXT_DIE_NUM;
3910 NEXT_DIE_NUM = next_unused_dienum;
3912 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3913 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3915 /* Write a label which will act as the name for the start of this DIE. */
3917 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3919 /* Write the DIE-length word. */
3921 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3923 /* Fill in the guts of the DIE. */
3925 next_unused_dienum++;
3926 die_specific_output_function (param);
3928 /* Write a label which will act as the name for the end of this DIE. */
3930 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3933 static void
3934 end_sibling_chain ()
3936 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3938 current_dienum = NEXT_DIE_NUM;
3939 NEXT_DIE_NUM = next_unused_dienum;
3941 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3943 /* Write a label which will act as the name for the start of this DIE. */
3945 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3947 /* Write the DIE-length word. */
3949 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3951 dienum_pop ();
3954 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3955 TAG_unspecified_parameters DIE) to represent the types of the formal
3956 parameters as specified in some function type specification (except
3957 for those which appear as part of a function *definition*).
3959 Note that we must be careful here to output all of the parameter
3960 DIEs *before* we output any DIEs needed to represent the types of
3961 the formal parameters. This keeps svr4 SDB happy because it
3962 (incorrectly) thinks that the first non-parameter DIE it sees ends
3963 the formal parameter list. */
3965 static void
3966 output_formal_types (function_or_method_type)
3967 register tree function_or_method_type;
3969 register tree link;
3970 register tree formal_type = NULL;
3971 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3973 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
3974 get bogus recursion when outputting tagged types local to a
3975 function declaration. */
3976 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
3977 TREE_ASM_WRITTEN (function_or_method_type) = 1;
3979 /* In the case where we are generating a formal types list for a C++
3980 non-static member function type, skip over the first thing on the
3981 TYPE_ARG_TYPES list because it only represents the type of the
3982 hidden `this pointer'. The debugger should be able to figure
3983 out (without being explicitly told) that this non-static member
3984 function type takes a `this pointer' and should be able to figure
3985 what the type of that hidden parameter is from the AT_member
3986 attribute of the parent TAG_subroutine_type DIE. */
3988 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3989 first_parm_type = TREE_CHAIN (first_parm_type);
3991 /* Make our first pass over the list of formal parameter types and output
3992 a TAG_formal_parameter DIE for each one. */
3994 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3996 formal_type = TREE_VALUE (link);
3997 if (formal_type == void_type_node)
3998 break;
4000 /* Output a (nameless) DIE to represent the formal parameter itself. */
4002 output_die (output_formal_parameter_die, formal_type);
4005 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4006 DIE to the end of the parameter list. */
4008 if (formal_type != void_type_node)
4009 output_die (output_unspecified_parameters_die, function_or_method_type);
4011 /* Make our second (and final) pass over the list of formal parameter types
4012 and output DIEs to represent those types (as necessary). */
4014 for (link = TYPE_ARG_TYPES (function_or_method_type);
4015 link;
4016 link = TREE_CHAIN (link))
4018 formal_type = TREE_VALUE (link);
4019 if (formal_type == void_type_node)
4020 break;
4022 output_type (formal_type, function_or_method_type);
4025 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4028 /* Remember a type in the pending_types_list. */
4030 static void
4031 pend_type (type)
4032 register tree type;
4034 if (pending_types == pending_types_allocated)
4036 pending_types_allocated += PENDING_TYPES_INCREMENT;
4037 pending_types_list
4038 = (tree *) xrealloc (pending_types_list,
4039 sizeof (tree) * pending_types_allocated);
4041 pending_types_list[pending_types++] = type;
4043 /* Mark the pending type as having been output already (even though
4044 it hasn't been). This prevents the type from being added to the
4045 pending_types_list more than once. */
4047 TREE_ASM_WRITTEN (type) = 1;
4050 /* Return non-zero if it is legitimate to output DIEs to represent a
4051 given type while we are generating the list of child DIEs for some
4052 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4054 See the comments within the function for a description of when it is
4055 considered legitimate to output DIEs for various kinds of types.
4057 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4058 or it may point to a BLOCK node (for types local to a block), or to a
4059 FUNCTION_DECL node (for types local to the heading of some function
4060 definition), or to a FUNCTION_TYPE node (for types local to the
4061 prototyped parameter list of a function type specification), or to a
4062 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4063 (in the case of C++ nested types).
4065 The `scope' parameter should likewise be NULL or should point to a
4066 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4067 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4069 This function is used only for deciding when to "pend" and when to
4070 "un-pend" types to/from the pending_types_list.
4072 Note that we sometimes make use of this "type pending" feature in a
4073 rather twisted way to temporarily delay the production of DIEs for the
4074 types of formal parameters. (We do this just to make svr4 SDB happy.)
4075 It order to delay the production of DIEs representing types of formal
4076 parameters, callers of this function supply `fake_containing_scope' as
4077 the `scope' parameter to this function. Given that fake_containing_scope
4078 is a tagged type which is *not* the containing scope for *any* other type,
4079 the desired effect is achieved, i.e. output of DIEs representing types
4080 is temporarily suspended, and any type DIEs which would have otherwise
4081 been output are instead placed onto the pending_types_list. Later on,
4082 we force these (temporarily pended) types to be output simply by calling
4083 `output_pending_types_for_scope' with an actual argument equal to the
4084 true scope of the types we temporarily pended. */
4086 static inline int
4087 type_ok_for_scope (type, scope)
4088 register tree type;
4089 register tree scope;
4091 /* Tagged types (i.e. struct, union, and enum types) must always be
4092 output only in the scopes where they actually belong (or else the
4093 scoping of their own tag names and the scoping of their member
4094 names will be incorrect). Non-tagged-types on the other hand can
4095 generally be output anywhere, except that svr4 SDB really doesn't
4096 want to see them nested within struct or union types, so here we
4097 say it is always OK to immediately output any such a (non-tagged)
4098 type, so long as we are not within such a context. Note that the
4099 only kinds of non-tagged types which we will be dealing with here
4100 (for C and C++ anyway) will be array types and function types. */
4102 return is_tagged_type (type)
4103 ? (TYPE_CONTEXT (type) == scope
4104 /* Ignore namespaces for the moment. */
4105 || (scope == NULL_TREE
4106 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4107 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4108 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4109 : (scope == NULL_TREE || ! is_tagged_type (scope));
4112 /* Output any pending types (from the pending_types list) which we can output
4113 now (taking into account the scope that we are working on now).
4115 For each type output, remove the given type from the pending_types_list
4116 *before* we try to output it.
4118 Note that we have to process the list in beginning-to-end order,
4119 because the call made here to output_type may cause yet more types
4120 to be added to the end of the list, and we may have to output some
4121 of them too. */
4123 static void
4124 output_pending_types_for_scope (containing_scope)
4125 register tree containing_scope;
4127 register unsigned i;
4129 for (i = 0; i < pending_types; )
4131 register tree type = pending_types_list[i];
4133 if (type_ok_for_scope (type, containing_scope))
4135 register tree *mover;
4136 register tree *limit;
4138 pending_types--;
4139 limit = &pending_types_list[pending_types];
4140 for (mover = &pending_types_list[i]; mover < limit; mover++)
4141 *mover = *(mover+1);
4143 /* Un-mark the type as having been output already (because it
4144 hasn't been, really). Then call output_type to generate a
4145 Dwarf representation of it. */
4147 TREE_ASM_WRITTEN (type) = 0;
4148 output_type (type, containing_scope);
4150 /* Don't increment the loop counter in this case because we
4151 have shifted all of the subsequent pending types down one
4152 element in the pending_types_list array. */
4154 else
4155 i++;
4159 /* Remember a type in the incomplete_types_list. */
4161 static void
4162 add_incomplete_type (type)
4163 tree type;
4165 if (incomplete_types == incomplete_types_allocated)
4167 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4168 incomplete_types_list
4169 = (tree *) xrealloc (incomplete_types_list,
4170 sizeof (tree) * incomplete_types_allocated);
4173 incomplete_types_list[incomplete_types++] = type;
4176 /* Walk through the list of incomplete types again, trying once more to
4177 emit full debugging info for them. */
4179 static void
4180 retry_incomplete_types ()
4182 register tree type;
4184 finalizing = 1;
4185 while (incomplete_types)
4187 --incomplete_types;
4188 type = incomplete_types_list[incomplete_types];
4189 output_type (type, NULL_TREE);
4193 static void
4194 output_type (type, containing_scope)
4195 register tree type;
4196 register tree containing_scope;
4198 if (type == 0 || type == error_mark_node)
4199 return;
4201 /* We are going to output a DIE to represent the unqualified version of
4202 this type (i.e. without any const or volatile qualifiers) so get
4203 the main variant (i.e. the unqualified version) of this type now. */
4205 type = type_main_variant (type);
4207 if (TREE_ASM_WRITTEN (type))
4209 if (finalizing && AGGREGATE_TYPE_P (type))
4211 register tree member;
4213 /* Some of our nested types might not have been defined when we
4214 were written out before; force them out now. */
4216 for (member = TYPE_FIELDS (type); member;
4217 member = TREE_CHAIN (member))
4218 if (TREE_CODE (member) == TYPE_DECL
4219 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4220 output_type (TREE_TYPE (member), containing_scope);
4222 return;
4225 /* If this is a nested type whose containing class hasn't been
4226 written out yet, writing it out will cover this one, too. */
4228 if (TYPE_CONTEXT (type)
4229 && TYPE_P (TYPE_CONTEXT (type))
4230 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4232 output_type (TYPE_CONTEXT (type), containing_scope);
4233 return;
4236 /* Don't generate any DIEs for this type now unless it is OK to do so
4237 (based upon what `type_ok_for_scope' tells us). */
4239 if (! type_ok_for_scope (type, containing_scope))
4241 pend_type (type);
4242 return;
4245 switch (TREE_CODE (type))
4247 case ERROR_MARK:
4248 break;
4250 case VECTOR_TYPE:
4251 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4252 break;
4254 case POINTER_TYPE:
4255 case REFERENCE_TYPE:
4256 /* Prevent infinite recursion in cases where this is a recursive
4257 type. Recursive types are possible in Ada. */
4258 TREE_ASM_WRITTEN (type) = 1;
4259 /* For these types, all that is required is that we output a DIE
4260 (or a set of DIEs) to represent the "basis" type. */
4261 output_type (TREE_TYPE (type), containing_scope);
4262 break;
4264 case OFFSET_TYPE:
4265 /* This code is used for C++ pointer-to-data-member types. */
4266 /* Output a description of the relevant class type. */
4267 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4268 /* Output a description of the type of the object pointed to. */
4269 output_type (TREE_TYPE (type), containing_scope);
4270 /* Now output a DIE to represent this pointer-to-data-member type
4271 itself. */
4272 output_die (output_ptr_to_mbr_type_die, type);
4273 break;
4275 case SET_TYPE:
4276 output_type (TYPE_DOMAIN (type), containing_scope);
4277 output_die (output_set_type_die, type);
4278 break;
4280 case FILE_TYPE:
4281 output_type (TREE_TYPE (type), containing_scope);
4282 abort (); /* No way to represent these in Dwarf yet! */
4283 break;
4285 case FUNCTION_TYPE:
4286 /* Force out return type (in case it wasn't forced out already). */
4287 output_type (TREE_TYPE (type), containing_scope);
4288 output_die (output_subroutine_type_die, type);
4289 output_formal_types (type);
4290 end_sibling_chain ();
4291 break;
4293 case METHOD_TYPE:
4294 /* Force out return type (in case it wasn't forced out already). */
4295 output_type (TREE_TYPE (type), containing_scope);
4296 output_die (output_subroutine_type_die, type);
4297 output_formal_types (type);
4298 end_sibling_chain ();
4299 break;
4301 case ARRAY_TYPE:
4302 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4304 output_type (TREE_TYPE (type), containing_scope);
4305 output_die (output_string_type_die, type);
4307 else
4309 register tree element_type;
4311 element_type = TREE_TYPE (type);
4312 while (TREE_CODE (element_type) == ARRAY_TYPE)
4313 element_type = TREE_TYPE (element_type);
4315 output_type (element_type, containing_scope);
4316 output_die (output_array_type_die, type);
4318 break;
4320 case ENUMERAL_TYPE:
4321 case RECORD_TYPE:
4322 case UNION_TYPE:
4323 case QUAL_UNION_TYPE:
4325 /* For a non-file-scope tagged type, we can always go ahead and
4326 output a Dwarf description of this type right now, even if
4327 the type in question is still incomplete, because if this
4328 local type *was* ever completed anywhere within its scope,
4329 that complete definition would already have been attached to
4330 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4331 node by the time we reach this point. That's true because of the
4332 way the front-end does its processing of file-scope declarations (of
4333 functions and class types) within which other types might be
4334 nested. The C and C++ front-ends always gobble up such "local
4335 scope" things en-mass before they try to output *any* debugging
4336 information for any of the stuff contained inside them and thus,
4337 we get the benefit here of what is (in effect) a pre-resolution
4338 of forward references to tagged types in local scopes.
4340 Note however that for file-scope tagged types we cannot assume
4341 that such pre-resolution of forward references has taken place.
4342 A given file-scope tagged type may appear to be incomplete when
4343 we reach this point, but it may yet be given a full definition
4344 (at file-scope) later on during compilation. In order to avoid
4345 generating a premature (and possibly incorrect) set of Dwarf
4346 DIEs for such (as yet incomplete) file-scope tagged types, we
4347 generate nothing at all for as-yet incomplete file-scope tagged
4348 types here unless we are making our special "finalization" pass
4349 for file-scope things at the very end of compilation. At that
4350 time, we will certainly know as much about each file-scope tagged
4351 type as we are ever going to know, so at that point in time, we
4352 can safely generate correct Dwarf descriptions for these file-
4353 scope tagged types. */
4355 if (!COMPLETE_TYPE_P (type)
4356 && (TYPE_CONTEXT (type) == NULL
4357 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4358 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4359 && !finalizing)
4361 /* We don't need to do this for function-local types. */
4362 if (! decl_function_context (TYPE_STUB_DECL (type)))
4363 add_incomplete_type (type);
4364 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4367 /* Prevent infinite recursion in cases where the type of some
4368 member of this type is expressed in terms of this type itself. */
4370 TREE_ASM_WRITTEN (type) = 1;
4372 /* Output a DIE to represent the tagged type itself. */
4374 switch (TREE_CODE (type))
4376 case ENUMERAL_TYPE:
4377 output_die (output_enumeration_type_die, type);
4378 return; /* a special case -- nothing left to do so just return */
4380 case RECORD_TYPE:
4381 output_die (output_structure_type_die, type);
4382 break;
4384 case UNION_TYPE:
4385 case QUAL_UNION_TYPE:
4386 output_die (output_union_type_die, type);
4387 break;
4389 default:
4390 abort (); /* Should never happen. */
4393 /* If this is not an incomplete type, output descriptions of
4394 each of its members.
4396 Note that as we output the DIEs necessary to represent the
4397 members of this record or union type, we will also be trying
4398 to output DIEs to represent the *types* of those members.
4399 However the `output_type' function (above) will specifically
4400 avoid generating type DIEs for member types *within* the list
4401 of member DIEs for this (containing) type execpt for those
4402 types (of members) which are explicitly marked as also being
4403 members of this (containing) type themselves. The g++ front-
4404 end can force any given type to be treated as a member of some
4405 other (containing) type by setting the TYPE_CONTEXT of the
4406 given (member) type to point to the TREE node representing the
4407 appropriate (containing) type.
4410 if (COMPLETE_TYPE_P (type))
4412 /* First output info about the base classes. */
4413 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4415 register tree bases = TYPE_BINFO_BASETYPES (type);
4416 register int n_bases = TREE_VEC_LENGTH (bases);
4417 register int i;
4419 for (i = 0; i < n_bases; i++)
4421 tree binfo = TREE_VEC_ELT (bases, i);
4422 output_type (BINFO_TYPE (binfo), containing_scope);
4423 output_die (output_inheritance_die, binfo);
4427 ++in_class;
4430 register tree normal_member;
4432 /* Now output info about the data members and type members. */
4434 for (normal_member = TYPE_FIELDS (type);
4435 normal_member;
4436 normal_member = TREE_CHAIN (normal_member))
4437 output_decl (normal_member, type);
4441 register tree func_member;
4443 /* Now output info about the function members (if any). */
4445 for (func_member = TYPE_METHODS (type);
4446 func_member;
4447 func_member = TREE_CHAIN (func_member))
4448 output_decl (func_member, type);
4451 --in_class;
4453 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4454 scopes (at least in C++) so we must now output any nested
4455 pending types which are local just to this type. */
4457 output_pending_types_for_scope (type);
4459 end_sibling_chain (); /* Terminate member chain. */
4462 break;
4464 case VOID_TYPE:
4465 case INTEGER_TYPE:
4466 case REAL_TYPE:
4467 case COMPLEX_TYPE:
4468 case BOOLEAN_TYPE:
4469 case CHAR_TYPE:
4470 break; /* No DIEs needed for fundamental types. */
4472 case LANG_TYPE: /* No Dwarf representation currently defined. */
4473 break;
4475 default:
4476 abort ();
4479 TREE_ASM_WRITTEN (type) = 1;
4482 static void
4483 output_tagged_type_instantiation (type)
4484 register tree type;
4486 if (type == 0 || type == error_mark_node)
4487 return;
4489 /* We are going to output a DIE to represent the unqualified version of
4490 this type (i.e. without any const or volatile qualifiers) so make
4491 sure that we have the main variant (i.e. the unqualified version) of
4492 this type now. */
4494 if (type != type_main_variant (type))
4495 abort ();
4497 if (!TREE_ASM_WRITTEN (type))
4498 abort ();
4500 switch (TREE_CODE (type))
4502 case ERROR_MARK:
4503 break;
4505 case ENUMERAL_TYPE:
4506 output_die (output_inlined_enumeration_type_die, type);
4507 break;
4509 case RECORD_TYPE:
4510 output_die (output_inlined_structure_type_die, type);
4511 break;
4513 case UNION_TYPE:
4514 case QUAL_UNION_TYPE:
4515 output_die (output_inlined_union_type_die, type);
4516 break;
4518 default:
4519 abort (); /* Should never happen. */
4523 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4524 the things which are local to the given block. */
4526 static void
4527 output_block (stmt, depth)
4528 register tree stmt;
4529 int depth;
4531 register int must_output_die = 0;
4532 register tree origin;
4533 register enum tree_code origin_code;
4535 /* Ignore blocks never really used to make RTL. */
4537 if (! stmt || ! TREE_USED (stmt)
4538 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
4539 return;
4541 /* Determine the "ultimate origin" of this block. This block may be an
4542 inlined instance of an inlined instance of inline function, so we
4543 have to trace all of the way back through the origin chain to find
4544 out what sort of node actually served as the original seed for the
4545 creation of the current block. */
4547 origin = block_ultimate_origin (stmt);
4548 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4550 /* Determine if we need to output any Dwarf DIEs at all to represent this
4551 block. */
4553 if (origin_code == FUNCTION_DECL)
4554 /* The outer scopes for inlinings *must* always be represented. We
4555 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4556 must_output_die = 1;
4557 else
4559 /* In the case where the current block represents an inlining of the
4560 "body block" of an inline function, we must *NOT* output any DIE
4561 for this block because we have already output a DIE to represent
4562 the whole inlined function scope and the "body block" of any
4563 function doesn't really represent a different scope according to
4564 ANSI C rules. So we check here to make sure that this block does
4565 not represent a "body block inlining" before trying to set the
4566 `must_output_die' flag. */
4568 if (! is_body_block (origin ? origin : stmt))
4570 /* Determine if this block directly contains any "significant"
4571 local declarations which we will need to output DIEs for. */
4573 if (debug_info_level > DINFO_LEVEL_TERSE)
4574 /* We are not in terse mode so *any* local declaration counts
4575 as being a "significant" one. */
4576 must_output_die = (BLOCK_VARS (stmt) != NULL);
4577 else
4579 register tree decl;
4581 /* We are in terse mode, so only local (nested) function
4582 definitions count as "significant" local declarations. */
4584 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4585 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4587 must_output_die = 1;
4588 break;
4594 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4595 DIE for any block which contains no significant local declarations
4596 at all. Rather, in such cases we just call `output_decls_for_scope'
4597 so that any needed Dwarf info for any sub-blocks will get properly
4598 generated. Note that in terse mode, our definition of what constitutes
4599 a "significant" local declaration gets restricted to include only
4600 inlined function instances and local (nested) function definitions. */
4602 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4603 /* We don't care about an abstract inlined subroutine. */;
4604 else if (must_output_die)
4606 output_die ((origin_code == FUNCTION_DECL)
4607 ? output_inlined_subroutine_die
4608 : output_lexical_block_die,
4609 stmt);
4610 output_decls_for_scope (stmt, depth);
4611 end_sibling_chain ();
4613 else
4614 output_decls_for_scope (stmt, depth);
4617 /* Output all of the decls declared within a given scope (also called
4618 a `binding contour') and (recursively) all of it's sub-blocks. */
4620 static void
4621 output_decls_for_scope (stmt, depth)
4622 register tree stmt;
4623 int depth;
4625 /* Ignore blocks never really used to make RTL. */
4627 if (! stmt || ! TREE_USED (stmt))
4628 return;
4630 /* Output the DIEs to represent all of the data objects, functions,
4631 typedefs, and tagged types declared directly within this block
4632 but not within any nested sub-blocks. */
4635 register tree decl;
4637 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4638 output_decl (decl, stmt);
4641 output_pending_types_for_scope (stmt);
4643 /* Output the DIEs to represent all sub-blocks (and the items declared
4644 therein) of this block. */
4647 register tree subblocks;
4649 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4650 subblocks;
4651 subblocks = BLOCK_CHAIN (subblocks))
4652 output_block (subblocks, depth + 1);
4656 /* Is this a typedef we can avoid emitting? */
4658 inline static int
4659 is_redundant_typedef (decl)
4660 register tree decl;
4662 if (TYPE_DECL_IS_STUB (decl))
4663 return 1;
4664 if (DECL_ARTIFICIAL (decl)
4665 && DECL_CONTEXT (decl)
4666 && is_tagged_type (DECL_CONTEXT (decl))
4667 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4668 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4669 /* Also ignore the artificial member typedef for the class name. */
4670 return 1;
4671 return 0;
4674 /* Output Dwarf .debug information for a decl described by DECL. */
4676 static void
4677 output_decl (decl, containing_scope)
4678 register tree decl;
4679 register tree containing_scope;
4681 /* Make a note of the decl node we are going to be working on. We may
4682 need to give the user the source coordinates of where it appeared in
4683 case we notice (later on) that something about it looks screwy. */
4685 dwarf_last_decl = decl;
4687 if (TREE_CODE (decl) == ERROR_MARK)
4688 return;
4690 /* If a structure is declared within an initialization, e.g. as the
4691 operand of a sizeof, then it will not have a name. We don't want
4692 to output a DIE for it, as the tree nodes are in the temporary obstack */
4694 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4695 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4696 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4697 || (TYPE_FIELDS (TREE_TYPE (decl))
4698 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4699 return;
4701 /* If this ..._DECL node is marked to be ignored, then ignore it. */
4703 if (DECL_IGNORED_P (decl))
4704 return;
4706 switch (TREE_CODE (decl))
4708 case CONST_DECL:
4709 /* The individual enumerators of an enum type get output when we
4710 output the Dwarf representation of the relevant enum type itself. */
4711 break;
4713 case FUNCTION_DECL:
4714 /* If we are in terse mode, don't output any DIEs to represent
4715 mere function declarations. Also, if we are conforming
4716 to the DWARF version 1 specification, don't output DIEs for
4717 mere function declarations. */
4719 if (DECL_INITIAL (decl) == NULL_TREE)
4720 #if (DWARF_VERSION > 1)
4721 if (debug_info_level <= DINFO_LEVEL_TERSE)
4722 #endif
4723 break;
4725 /* Before we describe the FUNCTION_DECL itself, make sure that we
4726 have described its return type. */
4728 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4731 /* And its containing type. */
4732 register tree origin = decl_class_context (decl);
4733 if (origin)
4734 output_type (origin, containing_scope);
4737 /* If we're emitting an out-of-line copy of an inline function,
4738 set up to refer to the abstract instance emitted from
4739 note_deferral_of_defined_inline_function. */
4740 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
4741 && ! (containing_scope && TYPE_P (containing_scope)))
4742 set_decl_origin_self (decl);
4744 /* If the following DIE will represent a function definition for a
4745 function with "extern" linkage, output a special "pubnames" DIE
4746 label just ahead of the actual DIE. A reference to this label
4747 was already generated in the .debug_pubnames section sub-entry
4748 for this function definition. */
4750 if (TREE_PUBLIC (decl))
4752 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4754 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4755 ASM_OUTPUT_LABEL (asm_out_file, label);
4758 /* Now output a DIE to represent the function itself. */
4760 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4761 ? output_global_subroutine_die
4762 : output_local_subroutine_die,
4763 decl);
4765 /* Now output descriptions of the arguments for this function.
4766 This gets (unnecessarily?) complex because of the fact that
4767 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4768 cases where there was a trailing `...' at the end of the formal
4769 parameter list. In order to find out if there was a trailing
4770 ellipsis or not, we must instead look at the type associated
4771 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4772 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4773 ends with a void_type_node then there should *not* be an ellipsis
4774 at the end. */
4776 /* In the case where we are describing a mere function declaration, all
4777 we need to do here (and all we *can* do here) is to describe
4778 the *types* of its formal parameters. */
4780 if (decl != current_function_decl || in_class)
4781 output_formal_types (TREE_TYPE (decl));
4782 else
4784 /* Generate DIEs to represent all known formal parameters */
4786 register tree arg_decls = DECL_ARGUMENTS (decl);
4787 register tree parm;
4789 /* WARNING! Kludge zone ahead! Here we have a special
4790 hack for svr4 SDB compatibility. Instead of passing the
4791 current FUNCTION_DECL node as the second parameter (i.e.
4792 the `containing_scope' parameter) to `output_decl' (as
4793 we ought to) we instead pass a pointer to our own private
4794 fake_containing_scope node. That node is a RECORD_TYPE
4795 node which NO OTHER TYPE may ever actually be a member of.
4797 This pointer will ultimately get passed into `output_type'
4798 as its `containing_scope' parameter. `Output_type' will
4799 then perform its part in the hack... i.e. it will pend
4800 the type of the formal parameter onto the pending_types
4801 list. Later on, when we are done generating the whole
4802 sequence of formal parameter DIEs for this function
4803 definition, we will un-pend all previously pended types
4804 of formal parameters for this function definition.
4806 This whole kludge prevents any type DIEs from being
4807 mixed in with the formal parameter DIEs. That's good
4808 because svr4 SDB believes that the list of formal
4809 parameter DIEs for a function ends wherever the first
4810 non-formal-parameter DIE appears. Thus, we have to
4811 keep the formal parameter DIEs segregated. They must
4812 all appear (consecutively) at the start of the list of
4813 children for the DIE representing the function definition.
4814 Then (and only then) may we output any additional DIEs
4815 needed to represent the types of these formal parameters.
4819 When generating DIEs, generate the unspecified_parameters
4820 DIE instead if we come across the arg "__builtin_va_alist"
4823 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4824 if (TREE_CODE (parm) == PARM_DECL)
4826 if (DECL_NAME(parm) &&
4827 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4828 "__builtin_va_alist") )
4829 output_die (output_unspecified_parameters_die, decl);
4830 else
4831 output_decl (parm, fake_containing_scope);
4835 Now that we have finished generating all of the DIEs to
4836 represent the formal parameters themselves, force out
4837 any DIEs needed to represent their types. We do this
4838 simply by un-pending all previously pended types which
4839 can legitimately go into the chain of children DIEs for
4840 the current FUNCTION_DECL.
4843 output_pending_types_for_scope (decl);
4846 Decide whether we need a unspecified_parameters DIE at the end.
4847 There are 2 more cases to do this for:
4848 1) the ansi ... declaration - this is detectable when the end
4849 of the arg list is not a void_type_node
4850 2) an unprototyped function declaration (not a definition). This
4851 just means that we have no info about the parameters at all.
4855 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4857 if (fn_arg_types)
4859 /* this is the prototyped case, check for ... */
4860 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4861 output_die (output_unspecified_parameters_die, decl);
4863 else
4865 /* this is unprototyped, check for undefined (just declaration) */
4866 if (!DECL_INITIAL (decl))
4867 output_die (output_unspecified_parameters_die, decl);
4871 /* Output Dwarf info for all of the stuff within the body of the
4872 function (if it has one - it may be just a declaration). */
4875 register tree outer_scope = DECL_INITIAL (decl);
4877 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4879 /* Note that here, `outer_scope' is a pointer to the outermost
4880 BLOCK node created to represent a function.
4881 This outermost BLOCK actually represents the outermost
4882 binding contour for the function, i.e. the contour in which
4883 the function's formal parameters and labels get declared.
4885 Curiously, it appears that the front end doesn't actually
4886 put the PARM_DECL nodes for the current function onto the
4887 BLOCK_VARS list for this outer scope. (They are strung
4888 off of the DECL_ARGUMENTS list for the function instead.)
4889 The BLOCK_VARS list for the `outer_scope' does provide us
4890 with a list of the LABEL_DECL nodes for the function however,
4891 and we output DWARF info for those here.
4893 Just within the `outer_scope' there will be a BLOCK node
4894 representing the function's outermost pair of curly braces,
4895 and any blocks used for the base and member initializers of
4896 a C++ constructor function. */
4898 output_decls_for_scope (outer_scope, 0);
4900 /* Finally, force out any pending types which are local to the
4901 outermost block of this function definition. These will
4902 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4903 node itself. */
4905 output_pending_types_for_scope (decl);
4910 /* Generate a terminator for the list of stuff `owned' by this
4911 function. */
4913 end_sibling_chain ();
4915 break;
4917 case TYPE_DECL:
4918 /* If we are in terse mode, don't generate any DIEs to represent
4919 any actual typedefs. Note that even when we are in terse mode,
4920 we must still output DIEs to represent those tagged types which
4921 are used (directly or indirectly) in the specification of either
4922 a return type or a formal parameter type of some function. */
4924 if (debug_info_level <= DINFO_LEVEL_TERSE)
4925 if (! TYPE_DECL_IS_STUB (decl)
4926 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4927 return;
4929 /* In the special case of a TYPE_DECL node representing
4930 the declaration of some type tag, if the given TYPE_DECL is
4931 marked as having been instantiated from some other (original)
4932 TYPE_DECL node (e.g. one which was generated within the original
4933 definition of an inline function) we have to generate a special
4934 (abbreviated) TAG_structure_type, TAG_union_type, or
4935 TAG_enumeration-type DIE here. */
4937 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4939 output_tagged_type_instantiation (TREE_TYPE (decl));
4940 return;
4943 output_type (TREE_TYPE (decl), containing_scope);
4945 if (! is_redundant_typedef (decl))
4946 /* Output a DIE to represent the typedef itself. */
4947 output_die (output_typedef_die, decl);
4948 break;
4950 case LABEL_DECL:
4951 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4952 output_die (output_label_die, decl);
4953 break;
4955 case VAR_DECL:
4956 /* If we are conforming to the DWARF version 1 specification, don't
4957 generated any DIEs to represent mere external object declarations. */
4959 #if (DWARF_VERSION <= 1)
4960 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4961 break;
4962 #endif
4964 /* If we are in terse mode, don't generate any DIEs to represent
4965 any variable declarations or definitions. */
4967 if (debug_info_level <= DINFO_LEVEL_TERSE)
4968 break;
4970 /* Output any DIEs that are needed to specify the type of this data
4971 object. */
4973 output_type (TREE_TYPE (decl), containing_scope);
4976 /* And its containing type. */
4977 register tree origin = decl_class_context (decl);
4978 if (origin)
4979 output_type (origin, containing_scope);
4982 /* If the following DIE will represent a data object definition for a
4983 data object with "extern" linkage, output a special "pubnames" DIE
4984 label just ahead of the actual DIE. A reference to this label
4985 was already generated in the .debug_pubnames section sub-entry
4986 for this data object definition. */
4988 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4990 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4992 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4993 ASM_OUTPUT_LABEL (asm_out_file, label);
4996 /* Now output the DIE to represent the data object itself. This gets
4997 complicated because of the possibility that the VAR_DECL really
4998 represents an inlined instance of a formal parameter for an inline
4999 function. */
5002 register void (*func) PARAMS ((void *));
5003 register tree origin = decl_ultimate_origin (decl);
5005 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5006 func = output_formal_parameter_die;
5007 else
5009 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5010 func = output_global_variable_die;
5011 else
5012 func = output_local_variable_die;
5014 output_die (func, decl);
5016 break;
5018 case FIELD_DECL:
5019 /* Ignore the nameless fields that are used to skip bits. */
5020 if (DECL_NAME (decl) != 0)
5022 output_type (member_declared_type (decl), containing_scope);
5023 output_die (output_member_die, decl);
5025 break;
5027 case PARM_DECL:
5028 /* Force out the type of this formal, if it was not forced out yet.
5029 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5030 It should be able to grok the presence of type DIEs within a list
5031 of TAG_formal_parameter DIEs, but it doesn't. */
5033 output_type (TREE_TYPE (decl), containing_scope);
5034 output_die (output_formal_parameter_die, decl);
5035 break;
5037 case NAMESPACE_DECL:
5038 /* Ignore for now. */
5039 break;
5041 default:
5042 abort ();
5046 void
5047 dwarfout_file_scope_decl (decl, set_finalizing)
5048 register tree decl;
5049 register int set_finalizing;
5051 if (TREE_CODE (decl) == ERROR_MARK)
5052 return;
5054 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5056 if (DECL_IGNORED_P (decl))
5057 return;
5059 switch (TREE_CODE (decl))
5061 case FUNCTION_DECL:
5063 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5064 a builtin function. Explicit programmer-supplied declarations of
5065 these same functions should NOT be ignored however. */
5067 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5068 return;
5070 /* What we would really like to do here is to filter out all mere
5071 file-scope declarations of file-scope functions which are never
5072 referenced later within this translation unit (and keep all of
5073 ones that *are* referenced later on) but we aren't clairvoyant,
5074 so we have no idea which functions will be referenced in the
5075 future (i.e. later on within the current translation unit).
5076 So here we just ignore all file-scope function declarations
5077 which are not also definitions. If and when the debugger needs
5078 to know something about these functions, it wil have to hunt
5079 around and find the DWARF information associated with the
5080 *definition* of the function.
5082 Note that we can't just check `DECL_EXTERNAL' to find out which
5083 FUNCTION_DECL nodes represent definitions and which ones represent
5084 mere declarations. We have to check `DECL_INITIAL' instead. That's
5085 because the C front-end supports some weird semantics for "extern
5086 inline" function definitions. These can get inlined within the
5087 current translation unit (an thus, we need to generate DWARF info
5088 for their abstract instances so that the DWARF info for the
5089 concrete inlined instances can have something to refer to) but
5090 the compiler never generates any out-of-lines instances of such
5091 things (despite the fact that they *are* definitions). The
5092 important point is that the C front-end marks these "extern inline"
5093 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5094 anyway.
5096 Note that the C++ front-end also plays some similar games for inline
5097 function definitions appearing within include files which also
5098 contain `#pragma interface' pragmas. */
5100 if (DECL_INITIAL (decl) == NULL_TREE)
5101 return;
5103 if (TREE_PUBLIC (decl)
5104 && ! DECL_EXTERNAL (decl)
5105 && ! DECL_ABSTRACT (decl))
5107 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5109 /* Output a .debug_pubnames entry for a public function
5110 defined in this compilation unit. */
5112 fputc ('\n', asm_out_file);
5113 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5114 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5115 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5116 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5117 IDENTIFIER_POINTER (DECL_NAME (decl)));
5118 ASM_OUTPUT_POP_SECTION (asm_out_file);
5121 break;
5123 case VAR_DECL:
5125 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5126 object declaration and if the declaration was never even
5127 referenced from within this entire compilation unit. We
5128 suppress these DIEs in order to save space in the .debug section
5129 (by eliminating entries which are probably useless). Note that
5130 we must not suppress block-local extern declarations (whether
5131 used or not) because that would screw-up the debugger's name
5132 lookup mechanism and cause it to miss things which really ought
5133 to be in scope at a given point. */
5135 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5136 return;
5138 if (TREE_PUBLIC (decl)
5139 && ! DECL_EXTERNAL (decl)
5140 && GET_CODE (DECL_RTL (decl)) == MEM
5141 && ! DECL_ABSTRACT (decl))
5143 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5145 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5147 /* Output a .debug_pubnames entry for a public variable
5148 defined in this compilation unit. */
5150 fputc ('\n', asm_out_file);
5151 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5152 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5153 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5154 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5155 IDENTIFIER_POINTER (DECL_NAME (decl)));
5156 ASM_OUTPUT_POP_SECTION (asm_out_file);
5159 if (DECL_INITIAL (decl) == NULL)
5161 /* Output a .debug_aranges entry for a public variable
5162 which is tentatively defined in this compilation unit. */
5164 fputc ('\n', asm_out_file);
5165 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5166 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5167 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5168 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5169 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5170 ASM_OUTPUT_POP_SECTION (asm_out_file);
5174 /* If we are in terse mode, don't generate any DIEs to represent
5175 any variable declarations or definitions. */
5177 if (debug_info_level <= DINFO_LEVEL_TERSE)
5178 return;
5180 break;
5182 case TYPE_DECL:
5183 /* Don't bother trying to generate any DIEs to represent any of the
5184 normal built-in types for the language we are compiling, except
5185 in cases where the types in question are *not* DWARF fundamental
5186 types. We make an exception in the case of non-fundamental types
5187 for the sake of objective C (and perhaps C++) because the GNU
5188 front-ends for these languages may in fact create certain "built-in"
5189 types which are (for example) RECORD_TYPEs. In such cases, we
5190 really need to output these (non-fundamental) types because other
5191 DIEs may contain references to them. */
5193 /* Also ignore language dependent types here, because they are probably
5194 also built-in types. If we didn't ignore them, then we would get
5195 references to undefined labels because output_type doesn't support
5196 them. So, for now, we need to ignore them to avoid assembler
5197 errors. */
5199 /* ??? This code is different than the equivalent code in dwarf2out.c.
5200 The dwarf2out.c code is probably more correct. */
5202 if (DECL_SOURCE_LINE (decl) == 0
5203 && (type_is_fundamental (TREE_TYPE (decl))
5204 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5205 return;
5207 /* If we are in terse mode, don't generate any DIEs to represent
5208 any actual typedefs. Note that even when we are in terse mode,
5209 we must still output DIEs to represent those tagged types which
5210 are used (directly or indirectly) in the specification of either
5211 a return type or a formal parameter type of some function. */
5213 if (debug_info_level <= DINFO_LEVEL_TERSE)
5214 if (! TYPE_DECL_IS_STUB (decl)
5215 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5216 return;
5218 break;
5220 default:
5221 return;
5224 fputc ('\n', asm_out_file);
5225 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5226 finalizing = set_finalizing;
5227 output_decl (decl, NULL_TREE);
5229 /* NOTE: The call above to `output_decl' may have caused one or more
5230 file-scope named types (i.e. tagged types) to be placed onto the
5231 pending_types_list. We have to get those types off of that list
5232 at some point, and this is the perfect time to do it. If we didn't
5233 take them off now, they might still be on the list when cc1 finally
5234 exits. That might be OK if it weren't for the fact that when we put
5235 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5236 for these types, and that causes them never to be output unless
5237 `output_pending_types_for_scope' takes them off of the list and un-sets
5238 their TREE_ASM_WRITTEN flags. */
5240 output_pending_types_for_scope (NULL_TREE);
5242 /* The above call should have totally emptied the pending_types_list
5243 if this is not a nested function or class. If this is a nested type,
5244 then the remaining pending_types will be emitted when the containing type
5245 is handled. */
5247 if (! DECL_CONTEXT (decl))
5249 if (pending_types != 0)
5250 abort ();
5253 ASM_OUTPUT_POP_SECTION (asm_out_file);
5255 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5256 current_funcdef_number++;
5259 /* Output a marker (i.e. a label) for the beginning of the generated code
5260 for a lexical block. */
5262 void
5263 dwarfout_begin_block (blocknum)
5264 register unsigned blocknum;
5266 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5268 function_section (current_function_decl);
5269 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5270 ASM_OUTPUT_LABEL (asm_out_file, label);
5273 /* Output a marker (i.e. a label) for the end of the generated code
5274 for a lexical block. */
5276 void
5277 dwarfout_end_block (blocknum)
5278 register unsigned blocknum;
5280 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5282 function_section (current_function_decl);
5283 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5284 ASM_OUTPUT_LABEL (asm_out_file, label);
5287 /* Output a marker (i.e. a label) for the point in the generated code where
5288 the real body of the function begins (after parameters have been moved
5289 to their home locations). */
5291 void
5292 dwarfout_begin_function ()
5294 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5296 if (! use_gnu_debug_info_extensions)
5297 return;
5298 function_section (current_function_decl);
5299 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5300 ASM_OUTPUT_LABEL (asm_out_file, label);
5303 /* Output a marker (i.e. a label) for the point in the generated code where
5304 the real body of the function ends (just before the epilogue code). */
5306 void
5307 dwarfout_end_function ()
5309 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5311 if (! use_gnu_debug_info_extensions)
5312 return;
5313 function_section (current_function_decl);
5314 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5315 ASM_OUTPUT_LABEL (asm_out_file, label);
5318 /* Output a marker (i.e. a label) for the absolute end of the generated code
5319 for a function definition. This gets called *after* the epilogue code
5320 has been generated. */
5322 void
5323 dwarfout_end_epilogue ()
5325 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5327 /* Output a label to mark the endpoint of the code generated for this
5328 function. */
5330 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5331 ASM_OUTPUT_LABEL (asm_out_file, label);
5334 static void
5335 shuffle_filename_entry (new_zeroth)
5336 register filename_entry *new_zeroth;
5338 filename_entry temp_entry;
5339 register filename_entry *limit_p;
5340 register filename_entry *move_p;
5342 if (new_zeroth == &filename_table[0])
5343 return;
5345 temp_entry = *new_zeroth;
5347 /* Shift entries up in the table to make room at [0]. */
5349 limit_p = &filename_table[0];
5350 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5351 *move_p = *(move_p-1);
5353 /* Install the found entry at [0]. */
5355 filename_table[0] = temp_entry;
5358 /* Create a new (string) entry for the .debug_sfnames section. */
5360 static void
5361 generate_new_sfname_entry ()
5363 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5365 fputc ('\n', asm_out_file);
5366 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5367 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5368 ASM_OUTPUT_LABEL (asm_out_file, label);
5369 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5370 filename_table[0].name
5371 ? filename_table[0].name
5372 : "");
5373 ASM_OUTPUT_POP_SECTION (asm_out_file);
5376 /* Lookup a filename (in the list of filenames that we know about here in
5377 dwarfout.c) and return its "index". The index of each (known) filename
5378 is just a unique number which is associated with only that one filename.
5379 We need such numbers for the sake of generating labels (in the
5380 .debug_sfnames section) and references to those unique labels (in the
5381 .debug_srcinfo and .debug_macinfo sections).
5383 If the filename given as an argument is not found in our current list,
5384 add it to the list and assign it the next available unique index number.
5386 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5387 one), we shuffle the filename found (or added) up to the zeroth entry of
5388 our list of filenames (which is always searched linearly). We do this so
5389 as to optimize the most common case for these filename lookups within
5390 dwarfout.c. The most common case by far is the case where we call
5391 lookup_filename to lookup the very same filename that we did a lookup
5392 on the last time we called lookup_filename. We make sure that this
5393 common case is fast because such cases will constitute 99.9% of the
5394 lookups we ever do (in practice).
5396 If we add a new filename entry to our table, we go ahead and generate
5397 the corresponding entry in the .debug_sfnames section right away.
5398 Doing so allows us to avoid tickling an assembler bug (present in some
5399 m68k assemblers) which yields assembly-time errors in cases where the
5400 difference of two label addresses is taken and where the two labels
5401 are in a section *other* than the one where the difference is being
5402 calculated, and where at least one of the two symbol references is a
5403 forward reference. (This bug could be tickled by our .debug_srcinfo
5404 entries if we don't output their corresponding .debug_sfnames entries
5405 before them.) */
5407 static unsigned
5408 lookup_filename (file_name)
5409 const char *file_name;
5411 register filename_entry *search_p;
5412 register filename_entry *limit_p = &filename_table[ft_entries];
5414 for (search_p = filename_table; search_p < limit_p; search_p++)
5415 if (!strcmp (file_name, search_p->name))
5417 /* When we get here, we have found the filename that we were
5418 looking for in the filename_table. Now we want to make sure
5419 that it gets moved to the zero'th entry in the table (if it
5420 is not already there) so that subsequent attempts to find the
5421 same filename will find it as quickly as possible. */
5423 shuffle_filename_entry (search_p);
5424 return filename_table[0].number;
5427 /* We come here whenever we have a new filename which is not registered
5428 in the current table. Here we add it to the table. */
5430 /* Prepare to add a new table entry by making sure there is enough space
5431 in the table to do so. If not, expand the current table. */
5433 if (ft_entries == ft_entries_allocated)
5435 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5436 filename_table
5437 = (filename_entry *)
5438 xrealloc (filename_table,
5439 ft_entries_allocated * sizeof (filename_entry));
5442 /* Initially, add the new entry at the end of the filename table. */
5444 filename_table[ft_entries].number = ft_entries;
5445 filename_table[ft_entries].name = xstrdup (file_name);
5447 /* Shuffle the new entry into filename_table[0]. */
5449 shuffle_filename_entry (&filename_table[ft_entries]);
5451 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5452 generate_new_sfname_entry ();
5454 ft_entries++;
5455 return filename_table[0].number;
5458 static void
5459 generate_srcinfo_entry (line_entry_num, files_entry_num)
5460 unsigned line_entry_num;
5461 unsigned files_entry_num;
5463 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5465 fputc ('\n', asm_out_file);
5466 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5467 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5468 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5469 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5470 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5471 ASM_OUTPUT_POP_SECTION (asm_out_file);
5474 void
5475 dwarfout_line (filename, line)
5476 register const char *filename;
5477 register unsigned line;
5479 if (debug_info_level >= DINFO_LEVEL_NORMAL
5480 /* We can't emit line number info for functions in separate sections,
5481 because the assembler can't subtract labels in different sections. */
5482 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5484 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5485 static unsigned last_line_entry_num = 0;
5486 static unsigned prev_file_entry_num = (unsigned) -1;
5487 register unsigned this_file_entry_num;
5489 function_section (current_function_decl);
5490 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5491 ASM_OUTPUT_LABEL (asm_out_file, label);
5493 fputc ('\n', asm_out_file);
5495 if (use_gnu_debug_info_extensions)
5496 this_file_entry_num = lookup_filename (filename);
5497 else
5498 this_file_entry_num = (unsigned) -1;
5500 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5501 if (this_file_entry_num != prev_file_entry_num)
5503 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5505 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5506 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5510 register const char *tail = strrchr (filename, '/');
5512 if (tail != NULL)
5513 filename = tail;
5516 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
5517 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5518 filename, line);
5519 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5520 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5521 ASM_OUTPUT_POP_SECTION (asm_out_file);
5523 if (this_file_entry_num != prev_file_entry_num)
5524 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5525 prev_file_entry_num = this_file_entry_num;
5529 /* Generate an entry in the .debug_macinfo section. */
5531 static void
5532 generate_macinfo_entry (type_and_offset, string)
5533 register const char *type_and_offset;
5534 register const char *string;
5536 if (! use_gnu_debug_info_extensions)
5537 return;
5539 fputc ('\n', asm_out_file);
5540 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5541 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5542 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
5543 ASM_OUTPUT_POP_SECTION (asm_out_file);
5546 void
5547 dwarfout_start_new_source_file (filename)
5548 register const char *filename;
5550 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5551 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5553 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5554 sprintf (type_and_offset, "0x%08x+%s-%s",
5555 ((unsigned) MACINFO_start << 24),
5556 /* Hack: skip leading '*' . */
5557 (*label == '*') + label,
5558 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5559 generate_macinfo_entry (type_and_offset, "");
5562 void
5563 dwarfout_resume_previous_source_file (lineno)
5564 register unsigned lineno;
5566 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5568 sprintf (type_and_offset, "0x%08x+%u",
5569 ((unsigned) MACINFO_resume << 24), lineno);
5570 generate_macinfo_entry (type_and_offset, "");
5573 /* Called from check_newline in c-parse.y. The `buffer' parameter
5574 contains the tail part of the directive line, i.e. the part which
5575 is past the initial whitespace, #, whitespace, directive-name,
5576 whitespace part. */
5578 void
5579 dwarfout_define (lineno, buffer)
5580 register unsigned lineno;
5581 register const char *buffer;
5583 static int initialized = 0;
5584 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5586 if (!initialized)
5588 dwarfout_start_new_source_file (primary_filename);
5589 initialized = 1;
5591 sprintf (type_and_offset, "0x%08x+%u",
5592 ((unsigned) MACINFO_define << 24), lineno);
5593 generate_macinfo_entry (type_and_offset, buffer);
5596 /* Called from check_newline in c-parse.y. The `buffer' parameter
5597 contains the tail part of the directive line, i.e. the part which
5598 is past the initial whitespace, #, whitespace, directive-name,
5599 whitespace part. */
5601 void
5602 dwarfout_undef (lineno, buffer)
5603 register unsigned lineno;
5604 register const char *buffer;
5606 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5608 sprintf (type_and_offset, "0x%08x+%u",
5609 ((unsigned) MACINFO_undef << 24), lineno);
5610 generate_macinfo_entry (type_and_offset, buffer);
5613 /* Set up for Dwarf output at the start of compilation. */
5615 void
5616 dwarfout_init (asm_out_file, main_input_filename)
5617 register FILE *asm_out_file;
5618 register const char *main_input_filename;
5620 /* Remember the name of the primary input file. */
5622 primary_filename = main_input_filename;
5624 /* Allocate the initial hunk of the pending_sibling_stack. */
5626 pending_sibling_stack
5627 = (unsigned *)
5628 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5629 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5630 pending_siblings = 1;
5632 /* Allocate the initial hunk of the filename_table. */
5634 filename_table
5635 = (filename_entry *)
5636 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5637 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5638 ft_entries = 0;
5640 /* Allocate the initial hunk of the pending_types_list. */
5642 pending_types_list
5643 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5644 pending_types_allocated = PENDING_TYPES_INCREMENT;
5645 pending_types = 0;
5647 /* Create an artificial RECORD_TYPE node which we can use in our hack
5648 to get the DIEs representing types of formal parameters to come out
5649 only *after* the DIEs for the formal parameters themselves. */
5651 fake_containing_scope = make_node (RECORD_TYPE);
5653 /* Output a starting label for the .text section. */
5655 fputc ('\n', asm_out_file);
5656 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5657 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5658 ASM_OUTPUT_POP_SECTION (asm_out_file);
5660 /* Output a starting label for the .data section. */
5662 fputc ('\n', asm_out_file);
5663 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5664 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5665 ASM_OUTPUT_POP_SECTION (asm_out_file);
5667 #if 0 /* GNU C doesn't currently use .data1. */
5668 /* Output a starting label for the .data1 section. */
5670 fputc ('\n', asm_out_file);
5671 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5672 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5673 ASM_OUTPUT_POP_SECTION (asm_out_file);
5674 #endif
5676 /* Output a starting label for the .rodata section. */
5678 fputc ('\n', asm_out_file);
5679 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5680 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5681 ASM_OUTPUT_POP_SECTION (asm_out_file);
5683 #if 0 /* GNU C doesn't currently use .rodata1. */
5684 /* Output a starting label for the .rodata1 section. */
5686 fputc ('\n', asm_out_file);
5687 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5688 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5689 ASM_OUTPUT_POP_SECTION (asm_out_file);
5690 #endif
5692 /* Output a starting label for the .bss section. */
5694 fputc ('\n', asm_out_file);
5695 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5696 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5697 ASM_OUTPUT_POP_SECTION (asm_out_file);
5699 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5701 if (use_gnu_debug_info_extensions)
5703 /* Output a starting label and an initial (compilation directory)
5704 entry for the .debug_sfnames section. The starting label will be
5705 referenced by the initial entry in the .debug_srcinfo section. */
5707 fputc ('\n', asm_out_file);
5708 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5709 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5711 register const char *pwd = getpwd ();
5712 register char *dirname;
5714 if (!pwd)
5715 pfatal_with_name ("getpwd");
5716 dirname = concat (pwd, "/", NULL);
5717 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
5718 free (dirname);
5720 ASM_OUTPUT_POP_SECTION (asm_out_file);
5723 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5724 && use_gnu_debug_info_extensions)
5726 /* Output a starting label for the .debug_macinfo section. This
5727 label will be referenced by the AT_mac_info attribute in the
5728 TAG_compile_unit DIE. */
5730 fputc ('\n', asm_out_file);
5731 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5732 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5733 ASM_OUTPUT_POP_SECTION (asm_out_file);
5736 /* Generate the initial entry for the .line section. */
5738 fputc ('\n', asm_out_file);
5739 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5740 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5741 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5742 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5743 ASM_OUTPUT_POP_SECTION (asm_out_file);
5745 if (use_gnu_debug_info_extensions)
5747 /* Generate the initial entry for the .debug_srcinfo section. */
5749 fputc ('\n', asm_out_file);
5750 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5751 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5752 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5753 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5754 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5755 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5756 #ifdef DWARF_TIMESTAMPS
5757 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5758 #else
5759 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5760 #endif
5761 ASM_OUTPUT_POP_SECTION (asm_out_file);
5764 /* Generate the initial entry for the .debug_pubnames section. */
5766 fputc ('\n', asm_out_file);
5767 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5768 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5769 ASM_OUTPUT_POP_SECTION (asm_out_file);
5771 /* Generate the initial entry for the .debug_aranges section. */
5773 fputc ('\n', asm_out_file);
5774 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5775 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5776 ASM_OUTPUT_POP_SECTION (asm_out_file);
5779 /* Setup first DIE number == 1. */
5780 NEXT_DIE_NUM = next_unused_dienum++;
5782 /* Generate the initial DIE for the .debug section. Note that the
5783 (string) value given in the AT_name attribute of the TAG_compile_unit
5784 DIE will (typically) be a relative pathname and that this pathname
5785 should be taken as being relative to the directory from which the
5786 compiler was invoked when the given (base) source file was compiled. */
5788 fputc ('\n', asm_out_file);
5789 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5790 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5791 output_die (output_compile_unit_die, main_input_filename);
5792 ASM_OUTPUT_POP_SECTION (asm_out_file);
5794 fputc ('\n', asm_out_file);
5797 /* Output stuff that dwarf requires at the end of every file. */
5799 void
5800 dwarfout_finish ()
5802 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5804 fputc ('\n', asm_out_file);
5805 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5806 retry_incomplete_types ();
5807 fputc ('\n', asm_out_file);
5809 /* Mark the end of the chain of siblings which represent all file-scope
5810 declarations in this compilation unit. */
5812 /* The (null) DIE which represents the terminator for the (sibling linked)
5813 list of file-scope items is *special*. Normally, we would just call
5814 end_sibling_chain at this point in order to output a word with the
5815 value `4' and that word would act as the terminator for the list of
5816 DIEs describing file-scope items. Unfortunately, if we were to simply
5817 do that, the label that would follow this DIE in the .debug section
5818 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5819 machines) to a 4 byte boundary.
5821 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5822 the trick used is to insert extra (otherwise useless) padding bytes
5823 into the (null) DIE that we know must precede the ..D2 label in the
5824 .debug section. The amount of padding required can be anywhere between
5825 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5826 with the padding) would normally contain the value 4, but now it will
5827 also have to include the padding bytes, so it will instead have some
5828 value in the range 4..7.
5830 Fortunately, the rules of Dwarf say that any DIE whose length word
5831 contains *any* value less than 8 should be treated as a null DIE, so
5832 this trick works out nicely. Clever, eh? Don't give me any credit
5833 (or blame). I didn't think of this scheme. I just conformed to it.
5836 output_die (output_padded_null_die, (void *) 0);
5837 dienum_pop ();
5839 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5840 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5841 ASM_OUTPUT_POP_SECTION (asm_out_file);
5843 /* Output a terminator label for the .text section. */
5845 fputc ('\n', asm_out_file);
5846 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5847 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5848 ASM_OUTPUT_POP_SECTION (asm_out_file);
5850 /* Output a terminator label for the .data section. */
5852 fputc ('\n', asm_out_file);
5853 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5854 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5855 ASM_OUTPUT_POP_SECTION (asm_out_file);
5857 #if 0 /* GNU C doesn't currently use .data1. */
5858 /* Output a terminator label for the .data1 section. */
5860 fputc ('\n', asm_out_file);
5861 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5862 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5863 ASM_OUTPUT_POP_SECTION (asm_out_file);
5864 #endif
5866 /* Output a terminator label for the .rodata section. */
5868 fputc ('\n', asm_out_file);
5869 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5870 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5871 ASM_OUTPUT_POP_SECTION (asm_out_file);
5873 #if 0 /* GNU C doesn't currently use .rodata1. */
5874 /* Output a terminator label for the .rodata1 section. */
5876 fputc ('\n', asm_out_file);
5877 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5878 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5879 ASM_OUTPUT_POP_SECTION (asm_out_file);
5880 #endif
5882 /* Output a terminator label for the .bss section. */
5884 fputc ('\n', asm_out_file);
5885 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5886 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5887 ASM_OUTPUT_POP_SECTION (asm_out_file);
5889 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5891 /* Output a terminating entry for the .line section. */
5893 fputc ('\n', asm_out_file);
5894 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5895 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5896 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5897 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5898 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5899 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5900 ASM_OUTPUT_POP_SECTION (asm_out_file);
5902 if (use_gnu_debug_info_extensions)
5904 /* Output a terminating entry for the .debug_srcinfo section. */
5906 fputc ('\n', asm_out_file);
5907 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5908 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5909 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5910 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5911 ASM_OUTPUT_POP_SECTION (asm_out_file);
5914 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5916 /* Output terminating entries for the .debug_macinfo section. */
5918 dwarfout_resume_previous_source_file (0);
5920 fputc ('\n', asm_out_file);
5921 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5922 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5923 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
5924 ASM_OUTPUT_POP_SECTION (asm_out_file);
5927 /* Generate the terminating entry for the .debug_pubnames section. */
5929 fputc ('\n', asm_out_file);
5930 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5931 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5932 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
5933 ASM_OUTPUT_POP_SECTION (asm_out_file);
5935 /* Generate the terminating entries for the .debug_aranges section.
5937 Note that we want to do this only *after* we have output the end
5938 labels (for the various program sections) which we are going to
5939 refer to here. This allows us to work around a bug in the m68k
5940 svr4 assembler. That assembler gives bogus assembly-time errors
5941 if (within any given section) you try to take the difference of
5942 two relocatable symbols, both of which are located within some
5943 other section, and if one (or both?) of the symbols involved is
5944 being forward-referenced. By generating the .debug_aranges
5945 entries at this late point in the assembly output, we skirt the
5946 issue simply by avoiding forward-references.
5949 fputc ('\n', asm_out_file);
5950 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5952 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5953 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5955 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5956 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5958 #if 0 /* GNU C doesn't currently use .data1. */
5959 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5960 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5961 DATA1_BEGIN_LABEL);
5962 #endif
5964 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5965 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5966 RODATA_BEGIN_LABEL);
5968 #if 0 /* GNU C doesn't currently use .rodata1. */
5969 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5970 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5971 RODATA1_BEGIN_LABEL);
5972 #endif
5974 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5975 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5977 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5978 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5980 ASM_OUTPUT_POP_SECTION (asm_out_file);
5983 /* There should not be any pending types left at the end. We need
5984 this now because it may not have been checked on the last call to
5985 dwarfout_file_scope_decl. */
5986 if (pending_types != 0)
5987 abort ();
5990 #endif /* DWARF_DEBUGGING_INFO */