* Makefile.in (SYSTEM_H): Define.
[official-gcc.git] / gcc / dwarfout.c
blob370d14f4d88c52086523bc3ff4c6cb7aa5d5c504
1 /* Output Dwarf format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 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 "dwarfout.h"
36 #include "toplev.h"
37 #include "tm_p.h"
39 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
40 regarding the GNU implementation of Dwarf. */
42 /* NOTE: In the comments in this file, many references are made to
43 so called "Debugging Information Entries". For the sake of brevity,
44 this term is abbreviated to `DIE' throughout the remainder of this
45 file. */
47 /* Note that the implementation of C++ support herein is (as yet) unfinished.
48 If you want to try to complete it, more power to you. */
50 /* How to start an assembler comment. */
51 #ifndef ASM_COMMENT_START
52 #define ASM_COMMENT_START ";#"
53 #endif
55 /* How to print out a register name. */
56 #ifndef PRINT_REG
57 #define PRINT_REG(RTX, CODE, FILE) \
58 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
59 #endif
61 /* Define a macro which returns non-zero for any tagged type which is
62 used (directly or indirectly) in the specification of either some
63 function's return type or some formal parameter of some function.
64 We use this macro when we are operating in "terse" mode to help us
65 know what tagged types have to be represented in Dwarf (even in
66 terse mode) and which ones don't.
68 A flag bit with this meaning really should be a part of the normal
69 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
70 for these nodes. For now, we have to just fake it. It it safe for
71 us to simply return zero for all complete tagged types (which will
72 get forced out anyway if they were used in the specification of some
73 formal or return type) and non-zero for all incomplete tagged types.
76 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
78 /* Define a macro which returns non-zero for a TYPE_DECL which was
79 implicitly generated for a tagged type.
81 Note that unlike the gcc front end (which generates a NULL named
82 TYPE_DECL node for each complete tagged type, each array type, and
83 each function type node created) the g++ front end generates a
84 _named_ TYPE_DECL node for each tagged type node created.
85 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
86 generate a DW_TAG_typedef DIE for them. */
87 #define TYPE_DECL_IS_STUB(decl) \
88 (DECL_NAME (decl) == NULL \
89 || (DECL_ARTIFICIAL (decl) \
90 && is_tagged_type (TREE_TYPE (decl)) \
91 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
93 extern int flag_traditional;
95 /* Maximum size (in bytes) of an artificially generated label. */
97 #define MAX_ARTIFICIAL_LABEL_BYTES 30
99 /* Structure to keep track of source filenames. */
101 struct filename_entry {
102 unsigned number;
103 const char * name;
106 typedef struct filename_entry filename_entry;
108 /* Pointer to an array of elements, each one having the structure above. */
110 static filename_entry *filename_table;
112 /* Total number of entries in the table (i.e. array) pointed to by
113 `filename_table'. This is the *total* and includes both used and
114 unused slots. */
116 static unsigned ft_entries_allocated;
118 /* Number of entries in the filename_table which are actually in use. */
120 static unsigned ft_entries;
122 /* Size (in elements) of increments by which we may expand the filename
123 table. Actually, a single hunk of space of this size should be enough
124 for most typical programs. */
126 #define FT_ENTRIES_INCREMENT 64
128 /* Local pointer to the name of the main input file. Initialized in
129 dwarfout_init. */
131 static const char *primary_filename;
133 /* Pointer to the most recent filename for which we produced some line info. */
135 static const char *last_filename;
137 /* Counter to generate unique names for DIEs. */
139 static unsigned next_unused_dienum = 1;
141 /* Number of the DIE which is currently being generated. */
143 static unsigned current_dienum;
145 /* Number to use for the special "pubname" label on the next DIE which
146 represents a function or data object defined in this compilation
147 unit which has "extern" linkage. */
149 static int next_pubname_number = 0;
151 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
153 /* Pointer to a dynamically allocated list of pre-reserved and still
154 pending sibling DIE numbers. Note that this list will grow as needed. */
156 static unsigned *pending_sibling_stack;
158 /* Counter to keep track of the number of pre-reserved and still pending
159 sibling DIE numbers. */
161 static unsigned pending_siblings;
163 /* The currently allocated size of the above list (expressed in number of
164 list elements). */
166 static unsigned pending_siblings_allocated;
168 /* Size (in elements) of increments by which we may expand the pending
169 sibling stack. Actually, a single hunk of space of this size should
170 be enough for most typical programs. */
172 #define PENDING_SIBLINGS_INCREMENT 64
174 /* Non-zero if we are performing our file-scope finalization pass and if
175 we should force out Dwarf descriptions of any and all file-scope
176 tagged types which are still incomplete types. */
178 static int finalizing = 0;
180 /* A pointer to the base of a list of pending types which we haven't
181 generated DIEs for yet, but which we will have to come back to
182 later on. */
184 static tree *pending_types_list;
186 /* Number of elements currently allocated for the pending_types_list. */
188 static unsigned pending_types_allocated;
190 /* Number of elements of pending_types_list currently in use. */
192 static unsigned pending_types;
194 /* Size (in elements) of increments by which we may expand the pending
195 types list. Actually, a single hunk of space of this size should
196 be enough for most typical programs. */
198 #define PENDING_TYPES_INCREMENT 64
200 /* A pointer to the base of a list of incomplete types which might be
201 completed at some later time. */
203 static tree *incomplete_types_list;
205 /* Number of elements currently allocated for the incomplete_types_list. */
206 static unsigned incomplete_types_allocated;
208 /* Number of elements of incomplete_types_list currently in use. */
209 static unsigned incomplete_types;
211 /* Size (in elements) of increments by which we may expand the incomplete
212 types list. Actually, a single hunk of space of this size should
213 be enough for most typical programs. */
214 #define INCOMPLETE_TYPES_INCREMENT 64
216 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
217 This is used in a hack to help us get the DIEs describing types of
218 formal parameters to come *after* all of the DIEs describing the formal
219 parameters themselves. That's necessary in order to be compatible
220 with what the brain-damaged svr4 SDB debugger requires. */
222 static tree fake_containing_scope;
224 /* The number of the current function definition that we are generating
225 debugging information for. These numbers range from 1 up to the maximum
226 number of function definitions contained within the current compilation
227 unit. These numbers are used to create unique labels for various things
228 contained within various function definitions. */
230 static unsigned current_funcdef_number = 1;
232 /* A pointer to the ..._DECL node which we have most recently been working
233 on. We keep this around just in case something about it looks screwy
234 and we want to tell the user what the source coordinates for the actual
235 declaration are. */
237 static tree dwarf_last_decl;
239 /* A flag indicating that we are emitting the member declarations of a
240 class, so member functions and variables should not be entirely emitted.
241 This is a kludge to avoid passing a second argument to output_*_die. */
243 static int in_class;
245 /* Forward declarations for functions defined in this file. */
247 static const char *dwarf_tag_name PARAMS ((unsigned));
248 static const char *dwarf_attr_name PARAMS ((unsigned));
249 static const char *dwarf_stack_op_name PARAMS ((unsigned));
250 static const char *dwarf_typemod_name PARAMS ((unsigned));
251 static const char *dwarf_fmt_byte_name PARAMS ((unsigned));
252 static const char *dwarf_fund_type_name PARAMS ((unsigned));
253 static tree decl_ultimate_origin PARAMS ((tree));
254 static tree block_ultimate_origin PARAMS ((tree));
255 static tree decl_class_context PARAMS ((tree));
256 #if 0
257 static void output_unsigned_leb128 PARAMS ((unsigned long));
258 static void output_signed_leb128 PARAMS ((long));
259 #endif
260 static int fundamental_type_code PARAMS ((tree));
261 static tree root_type_1 PARAMS ((tree, int));
262 static tree root_type PARAMS ((tree));
263 static void write_modifier_bytes_1 PARAMS ((tree, int, int, int));
264 static void write_modifier_bytes PARAMS ((tree, int, int));
265 static inline int type_is_fundamental PARAMS ((tree));
266 static void equate_decl_number_to_die_number PARAMS ((tree));
267 static inline void equate_type_number_to_die_number PARAMS ((tree));
268 static void output_reg_number PARAMS ((rtx));
269 static void output_mem_loc_descriptor PARAMS ((rtx));
270 static void output_loc_descriptor PARAMS ((rtx));
271 static void output_bound_representation PARAMS ((tree, unsigned, int));
272 static void output_enumeral_list PARAMS ((tree));
273 static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
274 static inline tree field_type PARAMS ((tree));
275 static inline unsigned int simple_type_align_in_bits PARAMS ((tree));
276 static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
277 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
278 static inline void sibling_attribute PARAMS ((void));
279 static void location_attribute PARAMS ((rtx));
280 static void data_member_location_attribute PARAMS ((tree));
281 static void const_value_attribute PARAMS ((rtx));
282 static void location_or_const_value_attribute PARAMS ((tree));
283 static inline void name_attribute PARAMS ((const char *));
284 static inline void fund_type_attribute PARAMS ((unsigned));
285 static void mod_fund_type_attribute PARAMS ((tree, int, int));
286 static inline void user_def_type_attribute PARAMS ((tree));
287 static void mod_u_d_type_attribute PARAMS ((tree, int, int));
288 #ifdef USE_ORDERING_ATTRIBUTE
289 static inline void ordering_attribute PARAMS ((unsigned));
290 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
291 static void subscript_data_attribute PARAMS ((tree));
292 static void byte_size_attribute PARAMS ((tree));
293 static inline void bit_offset_attribute PARAMS ((tree));
294 static inline void bit_size_attribute PARAMS ((tree));
295 static inline void element_list_attribute PARAMS ((tree));
296 static inline void stmt_list_attribute PARAMS ((const char *));
297 static inline void low_pc_attribute PARAMS ((const char *));
298 static inline void high_pc_attribute PARAMS ((const char *));
299 static inline void body_begin_attribute PARAMS ((const char *));
300 static inline void body_end_attribute PARAMS ((const char *));
301 static inline void language_attribute PARAMS ((unsigned));
302 static inline void member_attribute PARAMS ((tree));
303 #if 0
304 static inline void string_length_attribute PARAMS ((tree));
305 #endif
306 static inline void comp_dir_attribute PARAMS ((const char *));
307 static inline void sf_names_attribute PARAMS ((const char *));
308 static inline void src_info_attribute PARAMS ((const char *));
309 static inline void mac_info_attribute PARAMS ((const char *));
310 static inline void prototyped_attribute PARAMS ((tree));
311 static inline void producer_attribute PARAMS ((const char *));
312 static inline void inline_attribute PARAMS ((tree));
313 static inline void containing_type_attribute PARAMS ((tree));
314 static inline void abstract_origin_attribute PARAMS ((tree));
315 #ifdef DWARF_DECL_COORDINATES
316 static inline void src_coords_attribute PARAMS ((unsigned, unsigned));
317 #endif /* defined(DWARF_DECL_COORDINATES) */
318 static inline void pure_or_virtual_attribute PARAMS ((tree));
319 static void name_and_src_coords_attributes PARAMS ((tree));
320 static void type_attribute PARAMS ((tree, int, int));
321 static const char *type_tag PARAMS ((tree));
322 static inline void dienum_push PARAMS ((void));
323 static inline void dienum_pop PARAMS ((void));
324 static inline tree member_declared_type PARAMS ((tree));
325 static const char *function_start_label PARAMS ((tree));
326 static void output_array_type_die PARAMS ((void *));
327 static void output_set_type_die PARAMS ((void *));
328 #if 0
329 static void output_entry_point_die PARAMS ((void *));
330 #endif
331 static void output_inlined_enumeration_type_die PARAMS ((void *));
332 static void output_inlined_structure_type_die PARAMS ((void *));
333 static void output_inlined_union_type_die PARAMS ((void *));
334 static void output_enumeration_type_die PARAMS ((void *));
335 static void output_formal_parameter_die PARAMS ((void *));
336 static void output_global_subroutine_die PARAMS ((void *));
337 static void output_global_variable_die PARAMS ((void *));
338 static void output_label_die PARAMS ((void *));
339 static void output_lexical_block_die PARAMS ((void *));
340 static void output_inlined_subroutine_die PARAMS ((void *));
341 static void output_local_variable_die PARAMS ((void *));
342 static void output_member_die PARAMS ((void *));
343 #if 0
344 static void output_pointer_type_die PARAMS ((void *));
345 static void output_reference_type_die PARAMS ((void *));
346 #endif
347 static void output_ptr_to_mbr_type_die PARAMS ((void *));
348 static void output_compile_unit_die PARAMS ((void *));
349 static void output_string_type_die PARAMS ((void *));
350 static void output_inheritance_die PARAMS ((void *));
351 static void output_structure_type_die PARAMS ((void *));
352 static void output_local_subroutine_die PARAMS ((void *));
353 static void output_subroutine_type_die PARAMS ((void *));
354 static void output_typedef_die PARAMS ((void *));
355 static void output_union_type_die PARAMS ((void *));
356 static void output_unspecified_parameters_die PARAMS ((void *));
357 static void output_padded_null_die PARAMS ((void *));
358 static void output_die PARAMS ((void (*)(void *), void *));
359 static void end_sibling_chain PARAMS ((void));
360 static void output_formal_types PARAMS ((tree));
361 static void pend_type PARAMS ((tree));
362 static int type_ok_for_scope PARAMS ((tree, tree));
363 static void output_pending_types_for_scope PARAMS ((tree));
364 static void output_type PARAMS ((tree, tree));
365 static void output_tagged_type_instantiation PARAMS ((tree));
366 static void output_block PARAMS ((tree, int));
367 static void output_decls_for_scope PARAMS ((tree, int));
368 static void output_decl PARAMS ((tree, tree));
369 static void shuffle_filename_entry PARAMS ((filename_entry *));
370 static void generate_new_sfname_entry PARAMS ((void));
371 static unsigned lookup_filename PARAMS ((const char *));
372 static void generate_srcinfo_entry PARAMS ((unsigned, unsigned));
373 static void generate_macinfo_entry PARAMS ((const char *, const char *));
374 static int is_pseudo_reg PARAMS ((rtx));
375 static tree type_main_variant PARAMS ((tree));
376 static int is_tagged_type PARAMS ((tree));
377 static int is_redundant_typedef PARAMS ((tree));
378 static void add_incomplete_type PARAMS ((tree));
379 static void retry_incomplete_types PARAMS ((void));
381 /* Definitions of defaults for assembler-dependent names of various
382 pseudo-ops and section names.
384 Theses may be overridden in your tm.h file (if necessary) for your
385 particular assembler. The default values provided here correspond to
386 what is expected by "standard" AT&T System V.4 assemblers. */
388 #ifndef FILE_ASM_OP
389 #define FILE_ASM_OP "\t.file\t"
390 #endif
391 #ifndef VERSION_ASM_OP
392 #define VERSION_ASM_OP "\t.version\t"
393 #endif
394 #ifndef UNALIGNED_SHORT_ASM_OP
395 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
396 #endif
397 #ifndef UNALIGNED_INT_ASM_OP
398 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
399 #endif
400 #ifndef ASM_BYTE_OP
401 #define ASM_BYTE_OP "\t.byte\t"
402 #endif
403 #ifndef SET_ASM_OP
404 #define SET_ASM_OP "\t.set\t"
405 #endif
407 /* Pseudo-ops for pushing the current section onto the section stack (and
408 simultaneously changing to a new section) and for poping back to the
409 section we were in immediately before this one. Note that most svr4
410 assemblers only maintain a one level stack... you can push all the
411 sections you want, but you can only pop out one level. (The sparc
412 svr4 assembler is an exception to this general rule.) That's
413 OK because we only use at most one level of the section stack herein. */
415 #ifndef PUSHSECTION_ASM_OP
416 #define PUSHSECTION_ASM_OP "\t.section\t"
417 #endif
418 #ifndef POPSECTION_ASM_OP
419 #define POPSECTION_ASM_OP "\t.previous"
420 #endif
422 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
423 to print the PUSHSECTION_ASM_OP and the section name. The default here
424 works for almost all svr4 assemblers, except for the sparc, where the
425 section name must be enclosed in double quotes. (See sparcv4.h.) */
427 #ifndef PUSHSECTION_FORMAT
428 #define PUSHSECTION_FORMAT "%s%s\n"
429 #endif
431 #ifndef DEBUG_SECTION
432 #define DEBUG_SECTION ".debug"
433 #endif
434 #ifndef LINE_SECTION
435 #define LINE_SECTION ".line"
436 #endif
437 #ifndef SFNAMES_SECTION
438 #define SFNAMES_SECTION ".debug_sfnames"
439 #endif
440 #ifndef SRCINFO_SECTION
441 #define SRCINFO_SECTION ".debug_srcinfo"
442 #endif
443 #ifndef MACINFO_SECTION
444 #define MACINFO_SECTION ".debug_macinfo"
445 #endif
446 #ifndef PUBNAMES_SECTION
447 #define PUBNAMES_SECTION ".debug_pubnames"
448 #endif
449 #ifndef ARANGES_SECTION
450 #define ARANGES_SECTION ".debug_aranges"
451 #endif
452 #ifndef TEXT_SECTION
453 #define TEXT_SECTION ".text"
454 #endif
455 #ifndef DATA_SECTION
456 #define DATA_SECTION ".data"
457 #endif
458 #ifndef DATA1_SECTION
459 #define DATA1_SECTION ".data1"
460 #endif
461 #ifndef RODATA_SECTION
462 #define RODATA_SECTION ".rodata"
463 #endif
464 #ifndef RODATA1_SECTION
465 #define RODATA1_SECTION ".rodata1"
466 #endif
467 #ifndef BSS_SECTION
468 #define BSS_SECTION ".bss"
469 #endif
471 /* Definitions of defaults for formats and names of various special
472 (artificial) labels which may be generated within this file (when
473 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
475 If necessary, these may be overridden from within your tm.h file,
476 but typically, you should never need to override these.
478 These labels have been hacked (temporarily) so that they all begin with
479 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
480 stock m88k/svr4 assembler, both of which need to see .L at the start of
481 a label in order to prevent that label from going into the linker symbol
482 table). When I get time, I'll have to fix this the right way so that we
483 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
484 but that will require a rather massive set of changes. For the moment,
485 the following definitions out to produce the right results for all svr4
486 and svr3 assemblers. -- rfg
489 #ifndef TEXT_BEGIN_LABEL
490 #define TEXT_BEGIN_LABEL "*.L_text_b"
491 #endif
492 #ifndef TEXT_END_LABEL
493 #define TEXT_END_LABEL "*.L_text_e"
494 #endif
496 #ifndef DATA_BEGIN_LABEL
497 #define DATA_BEGIN_LABEL "*.L_data_b"
498 #endif
499 #ifndef DATA_END_LABEL
500 #define DATA_END_LABEL "*.L_data_e"
501 #endif
503 #ifndef DATA1_BEGIN_LABEL
504 #define DATA1_BEGIN_LABEL "*.L_data1_b"
505 #endif
506 #ifndef DATA1_END_LABEL
507 #define DATA1_END_LABEL "*.L_data1_e"
508 #endif
510 #ifndef RODATA_BEGIN_LABEL
511 #define RODATA_BEGIN_LABEL "*.L_rodata_b"
512 #endif
513 #ifndef RODATA_END_LABEL
514 #define RODATA_END_LABEL "*.L_rodata_e"
515 #endif
517 #ifndef RODATA1_BEGIN_LABEL
518 #define RODATA1_BEGIN_LABEL "*.L_rodata1_b"
519 #endif
520 #ifndef RODATA1_END_LABEL
521 #define RODATA1_END_LABEL "*.L_rodata1_e"
522 #endif
524 #ifndef BSS_BEGIN_LABEL
525 #define BSS_BEGIN_LABEL "*.L_bss_b"
526 #endif
527 #ifndef BSS_END_LABEL
528 #define BSS_END_LABEL "*.L_bss_e"
529 #endif
531 #ifndef LINE_BEGIN_LABEL
532 #define LINE_BEGIN_LABEL "*.L_line_b"
533 #endif
534 #ifndef LINE_LAST_ENTRY_LABEL
535 #define LINE_LAST_ENTRY_LABEL "*.L_line_last"
536 #endif
537 #ifndef LINE_END_LABEL
538 #define LINE_END_LABEL "*.L_line_e"
539 #endif
541 #ifndef DEBUG_BEGIN_LABEL
542 #define DEBUG_BEGIN_LABEL "*.L_debug_b"
543 #endif
544 #ifndef SFNAMES_BEGIN_LABEL
545 #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b"
546 #endif
547 #ifndef SRCINFO_BEGIN_LABEL
548 #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b"
549 #endif
550 #ifndef MACINFO_BEGIN_LABEL
551 #define MACINFO_BEGIN_LABEL "*.L_macinfo_b"
552 #endif
554 #ifndef DIE_BEGIN_LABEL_FMT
555 #define DIE_BEGIN_LABEL_FMT "*.L_D%u"
556 #endif
557 #ifndef DIE_END_LABEL_FMT
558 #define DIE_END_LABEL_FMT "*.L_D%u_e"
559 #endif
560 #ifndef PUB_DIE_LABEL_FMT
561 #define PUB_DIE_LABEL_FMT "*.L_P%u"
562 #endif
563 #ifndef BLOCK_BEGIN_LABEL_FMT
564 #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u"
565 #endif
566 #ifndef BLOCK_END_LABEL_FMT
567 #define BLOCK_END_LABEL_FMT "*.L_B%u_e"
568 #endif
569 #ifndef SS_BEGIN_LABEL_FMT
570 #define SS_BEGIN_LABEL_FMT "*.L_s%u"
571 #endif
572 #ifndef SS_END_LABEL_FMT
573 #define SS_END_LABEL_FMT "*.L_s%u_e"
574 #endif
575 #ifndef EE_BEGIN_LABEL_FMT
576 #define EE_BEGIN_LABEL_FMT "*.L_e%u"
577 #endif
578 #ifndef EE_END_LABEL_FMT
579 #define EE_END_LABEL_FMT "*.L_e%u_e"
580 #endif
581 #ifndef MT_BEGIN_LABEL_FMT
582 #define MT_BEGIN_LABEL_FMT "*.L_t%u"
583 #endif
584 #ifndef MT_END_LABEL_FMT
585 #define MT_END_LABEL_FMT "*.L_t%u_e"
586 #endif
587 #ifndef LOC_BEGIN_LABEL_FMT
588 #define LOC_BEGIN_LABEL_FMT "*.L_l%u"
589 #endif
590 #ifndef LOC_END_LABEL_FMT
591 #define LOC_END_LABEL_FMT "*.L_l%u_e"
592 #endif
593 #ifndef BOUND_BEGIN_LABEL_FMT
594 #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c"
595 #endif
596 #ifndef BOUND_END_LABEL_FMT
597 #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e"
598 #endif
599 #ifndef DERIV_BEGIN_LABEL_FMT
600 #define DERIV_BEGIN_LABEL_FMT "*.L_d%u"
601 #endif
602 #ifndef DERIV_END_LABEL_FMT
603 #define DERIV_END_LABEL_FMT "*.L_d%u_e"
604 #endif
605 #ifndef SL_BEGIN_LABEL_FMT
606 #define SL_BEGIN_LABEL_FMT "*.L_sl%u"
607 #endif
608 #ifndef SL_END_LABEL_FMT
609 #define SL_END_LABEL_FMT "*.L_sl%u_e"
610 #endif
611 #ifndef BODY_BEGIN_LABEL_FMT
612 #define BODY_BEGIN_LABEL_FMT "*.L_b%u"
613 #endif
614 #ifndef BODY_END_LABEL_FMT
615 #define BODY_END_LABEL_FMT "*.L_b%u_e"
616 #endif
617 #ifndef FUNC_END_LABEL_FMT
618 #define FUNC_END_LABEL_FMT "*.L_f%u_e"
619 #endif
620 #ifndef TYPE_NAME_FMT
621 #define TYPE_NAME_FMT "*.L_T%u"
622 #endif
623 #ifndef DECL_NAME_FMT
624 #define DECL_NAME_FMT "*.L_E%u"
625 #endif
626 #ifndef LINE_CODE_LABEL_FMT
627 #define LINE_CODE_LABEL_FMT "*.L_LC%u"
628 #endif
629 #ifndef SFNAMES_ENTRY_LABEL_FMT
630 #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u"
631 #endif
632 #ifndef LINE_ENTRY_LABEL_FMT
633 #define LINE_ENTRY_LABEL_FMT "*.L_LE%u"
634 #endif
636 /* Definitions of defaults for various types of primitive assembly language
637 output operations.
639 If necessary, these may be overridden from within your tm.h file,
640 but typically, you shouldn't need to override these. */
642 #ifndef ASM_OUTPUT_PUSH_SECTION
643 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
644 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
645 #endif
647 #ifndef ASM_OUTPUT_POP_SECTION
648 #define ASM_OUTPUT_POP_SECTION(FILE) \
649 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
650 #endif
652 #ifndef ASM_OUTPUT_DWARF_DELTA2
653 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
654 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
655 assemble_name (FILE, LABEL1); \
656 fprintf (FILE, "-"); \
657 assemble_name (FILE, LABEL2); \
658 fprintf (FILE, "\n"); \
659 } while (0)
660 #endif
662 #ifndef ASM_OUTPUT_DWARF_DELTA4
663 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
664 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
665 assemble_name (FILE, LABEL1); \
666 fprintf (FILE, "-"); \
667 assemble_name (FILE, LABEL2); \
668 fprintf (FILE, "\n"); \
669 } while (0)
670 #endif
672 #ifndef ASM_OUTPUT_DWARF_TAG
673 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
674 do { \
675 fprintf ((FILE), "%s0x%x", \
676 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
677 if (flag_debug_asm) \
678 fprintf ((FILE), "\t%s %s", \
679 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
680 fputc ('\n', (FILE)); \
681 } while (0)
682 #endif
684 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
685 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
686 do { \
687 fprintf ((FILE), "%s0x%x", \
688 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
689 if (flag_debug_asm) \
690 fprintf ((FILE), "\t%s %s", \
691 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
692 fputc ('\n', (FILE)); \
693 } while (0)
694 #endif
696 #ifndef ASM_OUTPUT_DWARF_STACK_OP
697 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
698 do { \
699 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) OP); \
700 if (flag_debug_asm) \
701 fprintf ((FILE), "\t%s %s", \
702 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
703 fputc ('\n', (FILE)); \
704 } while (0)
705 #endif
707 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
708 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
709 do { \
710 fprintf ((FILE), "%s0x%x", \
711 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
712 if (flag_debug_asm) \
713 fprintf ((FILE), "\t%s %s", \
714 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
715 fputc ('\n', (FILE)); \
716 } while (0)
717 #endif
719 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
720 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
721 do { \
722 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) FMT); \
723 if (flag_debug_asm) \
724 fprintf ((FILE), "\t%s %s", \
725 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
726 fputc ('\n', (FILE)); \
727 } while (0)
728 #endif
730 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
731 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
732 do { \
733 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) MOD); \
734 if (flag_debug_asm) \
735 fprintf ((FILE), "\t%s %s", \
736 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
737 fputc ('\n', (FILE)); \
738 } while (0)
739 #endif
741 #ifndef ASM_OUTPUT_DWARF_ADDR
742 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
743 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
744 assemble_name (FILE, LABEL); \
745 fprintf (FILE, "\n"); \
746 } while (0)
747 #endif
749 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
750 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
751 do { \
752 fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
753 output_addr_const ((FILE), (RTX)); \
754 fputc ('\n', (FILE)); \
755 } while (0)
756 #endif
758 #ifndef ASM_OUTPUT_DWARF_REF
759 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
760 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
761 assemble_name (FILE, LABEL); \
762 fprintf (FILE, "\n"); \
763 } while (0)
764 #endif
766 #ifndef ASM_OUTPUT_DWARF_DATA1
767 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
768 fprintf ((FILE), "%s0x%x\n", ASM_BYTE_OP, VALUE)
769 #endif
771 #ifndef ASM_OUTPUT_DWARF_DATA2
772 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
773 fprintf ((FILE), "%s0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
774 #endif
776 #ifndef ASM_OUTPUT_DWARF_DATA4
777 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
778 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
779 #endif
781 #ifndef ASM_OUTPUT_DWARF_DATA8
782 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
783 do { \
784 if (WORDS_BIG_ENDIAN) \
786 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
787 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
789 else \
791 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE); \
792 fprintf ((FILE), "%s0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
794 } while (0)
795 #endif
797 /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to
798 NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE
799 based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is
800 defined, we call it, then issue the line feed. If not, we supply a
801 default defintion of calling ASM_OUTPUT_ASCII */
803 #ifndef ASM_OUTPUT_DWARF_STRING
804 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
805 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
806 #else
807 #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \
808 ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n")
809 #endif
812 /************************ general utility functions **************************/
814 inline static int
815 is_pseudo_reg (rtl)
816 register rtx rtl;
818 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
819 || ((GET_CODE (rtl) == SUBREG)
820 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
823 inline static tree
824 type_main_variant (type)
825 register tree type;
827 type = TYPE_MAIN_VARIANT (type);
829 /* There really should be only one main variant among any group of variants
830 of a given type (and all of the MAIN_VARIANT values for all members of
831 the group should point to that one type) but sometimes the C front-end
832 messes this up for array types, so we work around that bug here. */
834 if (TREE_CODE (type) == ARRAY_TYPE)
836 while (type != TYPE_MAIN_VARIANT (type))
837 type = TYPE_MAIN_VARIANT (type);
840 return type;
843 /* Return non-zero if the given type node represents a tagged type. */
845 inline static int
846 is_tagged_type (type)
847 register tree type;
849 register enum tree_code code = TREE_CODE (type);
851 return (code == RECORD_TYPE || code == UNION_TYPE
852 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
855 static const char *
856 dwarf_tag_name (tag)
857 register unsigned tag;
859 switch (tag)
861 case TAG_padding: return "TAG_padding";
862 case TAG_array_type: return "TAG_array_type";
863 case TAG_class_type: return "TAG_class_type";
864 case TAG_entry_point: return "TAG_entry_point";
865 case TAG_enumeration_type: return "TAG_enumeration_type";
866 case TAG_formal_parameter: return "TAG_formal_parameter";
867 case TAG_global_subroutine: return "TAG_global_subroutine";
868 case TAG_global_variable: return "TAG_global_variable";
869 case TAG_label: return "TAG_label";
870 case TAG_lexical_block: return "TAG_lexical_block";
871 case TAG_local_variable: return "TAG_local_variable";
872 case TAG_member: return "TAG_member";
873 case TAG_pointer_type: return "TAG_pointer_type";
874 case TAG_reference_type: return "TAG_reference_type";
875 case TAG_compile_unit: return "TAG_compile_unit";
876 case TAG_string_type: return "TAG_string_type";
877 case TAG_structure_type: return "TAG_structure_type";
878 case TAG_subroutine: return "TAG_subroutine";
879 case TAG_subroutine_type: return "TAG_subroutine_type";
880 case TAG_typedef: return "TAG_typedef";
881 case TAG_union_type: return "TAG_union_type";
882 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
883 case TAG_variant: return "TAG_variant";
884 case TAG_common_block: return "TAG_common_block";
885 case TAG_common_inclusion: return "TAG_common_inclusion";
886 case TAG_inheritance: return "TAG_inheritance";
887 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
888 case TAG_module: return "TAG_module";
889 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
890 case TAG_set_type: return "TAG_set_type";
891 case TAG_subrange_type: return "TAG_subrange_type";
892 case TAG_with_stmt: return "TAG_with_stmt";
894 /* GNU extensions. */
896 case TAG_format_label: return "TAG_format_label";
897 case TAG_namelist: return "TAG_namelist";
898 case TAG_function_template: return "TAG_function_template";
899 case TAG_class_template: return "TAG_class_template";
901 default: return "TAG_<unknown>";
905 static const char *
906 dwarf_attr_name (attr)
907 register unsigned attr;
909 switch (attr)
911 case AT_sibling: return "AT_sibling";
912 case AT_location: return "AT_location";
913 case AT_name: return "AT_name";
914 case AT_fund_type: return "AT_fund_type";
915 case AT_mod_fund_type: return "AT_mod_fund_type";
916 case AT_user_def_type: return "AT_user_def_type";
917 case AT_mod_u_d_type: return "AT_mod_u_d_type";
918 case AT_ordering: return "AT_ordering";
919 case AT_subscr_data: return "AT_subscr_data";
920 case AT_byte_size: return "AT_byte_size";
921 case AT_bit_offset: return "AT_bit_offset";
922 case AT_bit_size: return "AT_bit_size";
923 case AT_element_list: return "AT_element_list";
924 case AT_stmt_list: return "AT_stmt_list";
925 case AT_low_pc: return "AT_low_pc";
926 case AT_high_pc: return "AT_high_pc";
927 case AT_language: return "AT_language";
928 case AT_member: return "AT_member";
929 case AT_discr: return "AT_discr";
930 case AT_discr_value: return "AT_discr_value";
931 case AT_string_length: return "AT_string_length";
932 case AT_common_reference: return "AT_common_reference";
933 case AT_comp_dir: return "AT_comp_dir";
934 case AT_const_value_string: return "AT_const_value_string";
935 case AT_const_value_data2: return "AT_const_value_data2";
936 case AT_const_value_data4: return "AT_const_value_data4";
937 case AT_const_value_data8: return "AT_const_value_data8";
938 case AT_const_value_block2: return "AT_const_value_block2";
939 case AT_const_value_block4: return "AT_const_value_block4";
940 case AT_containing_type: return "AT_containing_type";
941 case AT_default_value_addr: return "AT_default_value_addr";
942 case AT_default_value_data2: return "AT_default_value_data2";
943 case AT_default_value_data4: return "AT_default_value_data4";
944 case AT_default_value_data8: return "AT_default_value_data8";
945 case AT_default_value_string: return "AT_default_value_string";
946 case AT_friends: return "AT_friends";
947 case AT_inline: return "AT_inline";
948 case AT_is_optional: return "AT_is_optional";
949 case AT_lower_bound_ref: return "AT_lower_bound_ref";
950 case AT_lower_bound_data2: return "AT_lower_bound_data2";
951 case AT_lower_bound_data4: return "AT_lower_bound_data4";
952 case AT_lower_bound_data8: return "AT_lower_bound_data8";
953 case AT_private: return "AT_private";
954 case AT_producer: return "AT_producer";
955 case AT_program: return "AT_program";
956 case AT_protected: return "AT_protected";
957 case AT_prototyped: return "AT_prototyped";
958 case AT_public: return "AT_public";
959 case AT_pure_virtual: return "AT_pure_virtual";
960 case AT_return_addr: return "AT_return_addr";
961 case AT_abstract_origin: return "AT_abstract_origin";
962 case AT_start_scope: return "AT_start_scope";
963 case AT_stride_size: return "AT_stride_size";
964 case AT_upper_bound_ref: return "AT_upper_bound_ref";
965 case AT_upper_bound_data2: return "AT_upper_bound_data2";
966 case AT_upper_bound_data4: return "AT_upper_bound_data4";
967 case AT_upper_bound_data8: return "AT_upper_bound_data8";
968 case AT_virtual: return "AT_virtual";
970 /* GNU extensions */
972 case AT_sf_names: return "AT_sf_names";
973 case AT_src_info: return "AT_src_info";
974 case AT_mac_info: return "AT_mac_info";
975 case AT_src_coords: return "AT_src_coords";
976 case AT_body_begin: return "AT_body_begin";
977 case AT_body_end: return "AT_body_end";
979 default: return "AT_<unknown>";
983 static const char *
984 dwarf_stack_op_name (op)
985 register unsigned op;
987 switch (op)
989 case OP_REG: return "OP_REG";
990 case OP_BASEREG: return "OP_BASEREG";
991 case OP_ADDR: return "OP_ADDR";
992 case OP_CONST: return "OP_CONST";
993 case OP_DEREF2: return "OP_DEREF2";
994 case OP_DEREF4: return "OP_DEREF4";
995 case OP_ADD: return "OP_ADD";
996 default: return "OP_<unknown>";
1000 static const char *
1001 dwarf_typemod_name (mod)
1002 register unsigned mod;
1004 switch (mod)
1006 case MOD_pointer_to: return "MOD_pointer_to";
1007 case MOD_reference_to: return "MOD_reference_to";
1008 case MOD_const: return "MOD_const";
1009 case MOD_volatile: return "MOD_volatile";
1010 default: return "MOD_<unknown>";
1014 static const char *
1015 dwarf_fmt_byte_name (fmt)
1016 register unsigned fmt;
1018 switch (fmt)
1020 case FMT_FT_C_C: return "FMT_FT_C_C";
1021 case FMT_FT_C_X: return "FMT_FT_C_X";
1022 case FMT_FT_X_C: return "FMT_FT_X_C";
1023 case FMT_FT_X_X: return "FMT_FT_X_X";
1024 case FMT_UT_C_C: return "FMT_UT_C_C";
1025 case FMT_UT_C_X: return "FMT_UT_C_X";
1026 case FMT_UT_X_C: return "FMT_UT_X_C";
1027 case FMT_UT_X_X: return "FMT_UT_X_X";
1028 case FMT_ET: return "FMT_ET";
1029 default: return "FMT_<unknown>";
1033 static const char *
1034 dwarf_fund_type_name (ft)
1035 register unsigned ft;
1037 switch (ft)
1039 case FT_char: return "FT_char";
1040 case FT_signed_char: return "FT_signed_char";
1041 case FT_unsigned_char: return "FT_unsigned_char";
1042 case FT_short: return "FT_short";
1043 case FT_signed_short: return "FT_signed_short";
1044 case FT_unsigned_short: return "FT_unsigned_short";
1045 case FT_integer: return "FT_integer";
1046 case FT_signed_integer: return "FT_signed_integer";
1047 case FT_unsigned_integer: return "FT_unsigned_integer";
1048 case FT_long: return "FT_long";
1049 case FT_signed_long: return "FT_signed_long";
1050 case FT_unsigned_long: return "FT_unsigned_long";
1051 case FT_pointer: return "FT_pointer";
1052 case FT_float: return "FT_float";
1053 case FT_dbl_prec_float: return "FT_dbl_prec_float";
1054 case FT_ext_prec_float: return "FT_ext_prec_float";
1055 case FT_complex: return "FT_complex";
1056 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
1057 case FT_void: return "FT_void";
1058 case FT_boolean: return "FT_boolean";
1059 case FT_ext_prec_complex: return "FT_ext_prec_complex";
1060 case FT_label: return "FT_label";
1062 /* GNU extensions. */
1064 case FT_long_long: return "FT_long_long";
1065 case FT_signed_long_long: return "FT_signed_long_long";
1066 case FT_unsigned_long_long: return "FT_unsigned_long_long";
1068 case FT_int8: return "FT_int8";
1069 case FT_signed_int8: return "FT_signed_int8";
1070 case FT_unsigned_int8: return "FT_unsigned_int8";
1071 case FT_int16: return "FT_int16";
1072 case FT_signed_int16: return "FT_signed_int16";
1073 case FT_unsigned_int16: return "FT_unsigned_int16";
1074 case FT_int32: return "FT_int32";
1075 case FT_signed_int32: return "FT_signed_int32";
1076 case FT_unsigned_int32: return "FT_unsigned_int32";
1077 case FT_int64: return "FT_int64";
1078 case FT_signed_int64: return "FT_signed_int64";
1079 case FT_unsigned_int64: return "FT_unsigned_int64";
1080 case FT_int128: return "FT_int128";
1081 case FT_signed_int128: return "FT_signed_int128";
1082 case FT_unsigned_int128: return "FT_unsigned_int128";
1084 case FT_real32: return "FT_real32";
1085 case FT_real64: return "FT_real64";
1086 case FT_real96: return "FT_real96";
1087 case FT_real128: return "FT_real128";
1089 default: return "FT_<unknown>";
1093 /* Determine the "ultimate origin" of a decl. The decl may be an
1094 inlined instance of an inlined instance of a decl which is local
1095 to an inline function, so we have to trace all of the way back
1096 through the origin chain to find out what sort of node actually
1097 served as the original seed for the given block. */
1099 static tree
1100 decl_ultimate_origin (decl)
1101 register tree decl;
1103 #ifdef ENABLE_CHECKING
1104 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
1105 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
1106 most distant ancestor, this should never happen. */
1107 abort ();
1108 #endif
1110 return DECL_ABSTRACT_ORIGIN (decl);
1113 /* Determine the "ultimate origin" of a block. The block may be an
1114 inlined instance of an inlined instance of a block which is local
1115 to an inline function, so we have to trace all of the way back
1116 through the origin chain to find out what sort of node actually
1117 served as the original seed for the given block. */
1119 static tree
1120 block_ultimate_origin (block)
1121 register tree block;
1123 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1125 if (immediate_origin == NULL)
1126 return NULL;
1127 else
1129 register tree ret_val;
1130 register tree lookahead = immediate_origin;
1134 ret_val = lookahead;
1135 lookahead = (TREE_CODE (ret_val) == BLOCK)
1136 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1137 : NULL;
1139 while (lookahead != NULL && lookahead != ret_val);
1140 return ret_val;
1144 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1145 of a virtual function may refer to a base class, so we check the 'this'
1146 parameter. */
1148 static tree
1149 decl_class_context (decl)
1150 tree decl;
1152 tree context = NULL_TREE;
1153 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1154 context = DECL_CONTEXT (decl);
1155 else
1156 context = TYPE_MAIN_VARIANT
1157 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1159 if (context && !TYPE_P (context))
1160 context = NULL_TREE;
1162 return context;
1165 #if 0
1166 static void
1167 output_unsigned_leb128 (value)
1168 register unsigned long value;
1170 register unsigned long orig_value = value;
1174 register unsigned byte = (value & 0x7f);
1176 value >>= 7;
1177 if (value != 0) /* more bytes to follow */
1178 byte |= 0x80;
1179 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1180 if (flag_debug_asm && value == 0)
1181 fprintf (asm_out_file, "\t%s ULEB128 number - value = %lu",
1182 ASM_COMMENT_START, orig_value);
1183 fputc ('\n', asm_out_file);
1185 while (value != 0);
1188 static void
1189 output_signed_leb128 (value)
1190 register long value;
1192 register long orig_value = value;
1193 register int negative = (value < 0);
1194 register int more;
1198 register unsigned byte = (value & 0x7f);
1200 value >>= 7;
1201 if (negative)
1202 value |= 0xfe000000; /* manually sign extend */
1203 if (((value == 0) && ((byte & 0x40) == 0))
1204 || ((value == -1) && ((byte & 0x40) == 1)))
1205 more = 0;
1206 else
1208 byte |= 0x80;
1209 more = 1;
1211 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP, (unsigned) byte);
1212 if (flag_debug_asm && more == 0)
1213 fprintf (asm_out_file, "\t%s SLEB128 number - value = %ld",
1214 ASM_COMMENT_START, orig_value);
1215 fputc ('\n', asm_out_file);
1217 while (more);
1219 #endif
1221 /**************** utility functions for attribute functions ******************/
1223 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1224 type code for the given type.
1226 This routine must only be called for GCC type nodes that correspond to
1227 Dwarf fundamental types.
1229 The current Dwarf draft specification calls for Dwarf fundamental types
1230 to accurately reflect the fact that a given type was either a "plain"
1231 integral type or an explicitly "signed" integral type. Unfortunately,
1232 we can't always do this, because GCC may already have thrown away the
1233 information about the precise way in which the type was originally
1234 specified, as in:
1236 typedef signed int my_type;
1238 struct s { my_type f; };
1240 Since we may be stuck here without enought information to do exactly
1241 what is called for in the Dwarf draft specification, we do the best
1242 that we can under the circumstances and always use the "plain" integral
1243 fundamental type codes for int, short, and long types. That's probably
1244 good enough. The additional accuracy called for in the current DWARF
1245 draft specification is probably never even useful in practice. */
1247 static int
1248 fundamental_type_code (type)
1249 register tree type;
1251 if (TREE_CODE (type) == ERROR_MARK)
1252 return 0;
1254 switch (TREE_CODE (type))
1256 case ERROR_MARK:
1257 return FT_void;
1259 case VOID_TYPE:
1260 return FT_void;
1262 case INTEGER_TYPE:
1263 /* Carefully distinguish all the standard types of C,
1264 without messing up if the language is not C.
1265 Note that we check only for the names that contain spaces;
1266 other names might occur by coincidence in other languages. */
1267 if (TYPE_NAME (type) != 0
1268 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1269 && DECL_NAME (TYPE_NAME (type)) != 0
1270 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1272 const char *name =
1273 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1275 if (!strcmp (name, "unsigned char"))
1276 return FT_unsigned_char;
1277 if (!strcmp (name, "signed char"))
1278 return FT_signed_char;
1279 if (!strcmp (name, "unsigned int"))
1280 return FT_unsigned_integer;
1281 if (!strcmp (name, "short int"))
1282 return FT_short;
1283 if (!strcmp (name, "short unsigned int"))
1284 return FT_unsigned_short;
1285 if (!strcmp (name, "long int"))
1286 return FT_long;
1287 if (!strcmp (name, "long unsigned int"))
1288 return FT_unsigned_long;
1289 if (!strcmp (name, "long long int"))
1290 return FT_long_long; /* Not grok'ed by svr4 SDB */
1291 if (!strcmp (name, "long long unsigned int"))
1292 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1295 /* Most integer types will be sorted out above, however, for the
1296 sake of special `array index' integer types, the following code
1297 is also provided. */
1299 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1300 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1302 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1303 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1305 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1306 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1308 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1309 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1311 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1312 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1314 if (TYPE_MODE (type) == TImode)
1315 return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128);
1317 /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */
1318 if (TYPE_PRECISION (type) == 1)
1319 return FT_boolean;
1321 abort ();
1323 case REAL_TYPE:
1324 /* Carefully distinguish all the standard types of C,
1325 without messing up if the language is not C. */
1326 if (TYPE_NAME (type) != 0
1327 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1328 && DECL_NAME (TYPE_NAME (type)) != 0
1329 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1331 const char *name =
1332 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1334 /* Note that here we can run afowl of a serious bug in "classic"
1335 svr4 SDB debuggers. They don't seem to understand the
1336 FT_ext_prec_float type (even though they should). */
1338 if (!strcmp (name, "long double"))
1339 return FT_ext_prec_float;
1342 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1344 /* On the SH, when compiling with -m3e or -m4-single-only, both
1345 float and double are 32 bits. But since the debugger doesn't
1346 know about the subtarget, it always thinks double is 64 bits.
1347 So we have to tell the debugger that the type is float to
1348 make the output of the 'print' command etc. readable. */
1349 if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32)
1350 return FT_float;
1351 return FT_dbl_prec_float;
1353 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1354 return FT_float;
1356 /* Note that here we can run afowl of a serious bug in "classic"
1357 svr4 SDB debuggers. They don't seem to understand the
1358 FT_ext_prec_float type (even though they should). */
1360 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1361 return FT_ext_prec_float;
1362 abort ();
1364 case COMPLEX_TYPE:
1365 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1367 case CHAR_TYPE:
1368 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1370 case BOOLEAN_TYPE:
1371 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1373 default:
1374 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1376 return 0;
1379 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1380 the Dwarf "root" type for the given input type. The Dwarf "root" type
1381 of a given type is generally the same as the given type, except that if
1382 the given type is a pointer or reference type, then the root type of
1383 the given type is the root type of the "basis" type for the pointer or
1384 reference type. (This definition of the "root" type is recursive.)
1385 Also, the root type of a `const' qualified type or a `volatile'
1386 qualified type is the root type of the given type without the
1387 qualifiers. */
1389 static tree
1390 root_type_1 (type, count)
1391 register tree type;
1392 register int count;
1394 /* Give up after searching 1000 levels, in case this is a recursive
1395 pointer type. Such types are possible in Ada, but it is not possible
1396 to represent them in DWARF1 debug info. */
1397 if (count > 1000)
1398 return error_mark_node;
1400 switch (TREE_CODE (type))
1402 case ERROR_MARK:
1403 return error_mark_node;
1405 case POINTER_TYPE:
1406 case REFERENCE_TYPE:
1407 return root_type_1 (TREE_TYPE (type), count+1);
1409 default:
1410 return type;
1414 static tree
1415 root_type (type)
1416 register tree type;
1418 type = root_type_1 (type, 0);
1419 if (type != error_mark_node)
1420 type = type_main_variant (type);
1421 return type;
1424 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1425 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1427 static void
1428 write_modifier_bytes_1 (type, decl_const, decl_volatile, count)
1429 register tree type;
1430 register int decl_const;
1431 register int decl_volatile;
1432 register int count;
1434 if (TREE_CODE (type) == ERROR_MARK)
1435 return;
1437 /* Give up after searching 1000 levels, in case this is a recursive
1438 pointer type. Such types are possible in Ada, but it is not possible
1439 to represent them in DWARF1 debug info. */
1440 if (count > 1000)
1441 return;
1443 if (TYPE_READONLY (type) || decl_const)
1444 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1445 if (TYPE_VOLATILE (type) || decl_volatile)
1446 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1447 switch (TREE_CODE (type))
1449 case POINTER_TYPE:
1450 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1451 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1452 return;
1454 case REFERENCE_TYPE:
1455 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1456 write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1);
1457 return;
1459 case ERROR_MARK:
1460 default:
1461 return;
1465 static void
1466 write_modifier_bytes (type, decl_const, decl_volatile)
1467 register tree type;
1468 register int decl_const;
1469 register int decl_volatile;
1471 write_modifier_bytes_1 (type, decl_const, decl_volatile, 0);
1474 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1475 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1477 static inline int
1478 type_is_fundamental (type)
1479 register tree type;
1481 switch (TREE_CODE (type))
1483 case ERROR_MARK:
1484 case VOID_TYPE:
1485 case INTEGER_TYPE:
1486 case REAL_TYPE:
1487 case COMPLEX_TYPE:
1488 case BOOLEAN_TYPE:
1489 case CHAR_TYPE:
1490 return 1;
1492 case SET_TYPE:
1493 case ARRAY_TYPE:
1494 case RECORD_TYPE:
1495 case UNION_TYPE:
1496 case QUAL_UNION_TYPE:
1497 case ENUMERAL_TYPE:
1498 case FUNCTION_TYPE:
1499 case METHOD_TYPE:
1500 case POINTER_TYPE:
1501 case REFERENCE_TYPE:
1502 case FILE_TYPE:
1503 case OFFSET_TYPE:
1504 case LANG_TYPE:
1505 case VECTOR_TYPE:
1506 return 0;
1508 default:
1509 abort ();
1511 return 0;
1514 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1515 equate directive which will associate a symbolic name with the current DIE.
1517 The name used is an artificial label generated from the DECL_UID number
1518 associated with the given decl node. The name it gets equated to is the
1519 symbolic label that we (previously) output at the start of the DIE that
1520 we are currently generating.
1522 Calling this function while generating some "decl related" form of DIE
1523 makes it possible to later refer to the DIE which represents the given
1524 decl simply by re-generating the symbolic name from the ..._DECL node's
1525 UID number. */
1527 static void
1528 equate_decl_number_to_die_number (decl)
1529 register tree decl;
1531 /* In the case where we are generating a DIE for some ..._DECL node
1532 which represents either some inline function declaration or some
1533 entity declared within an inline function declaration/definition,
1534 setup a symbolic name for the current DIE so that we have a name
1535 for this DIE that we can easily refer to later on within
1536 AT_abstract_origin attributes. */
1538 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1539 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1541 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1542 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1543 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1546 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1547 equate directive which will associate a symbolic name with the current DIE.
1549 The name used is an artificial label generated from the TYPE_UID number
1550 associated with the given type node. The name it gets equated to is the
1551 symbolic label that we (previously) output at the start of the DIE that
1552 we are currently generating.
1554 Calling this function while generating some "type related" form of DIE
1555 makes it easy to later refer to the DIE which represents the given type
1556 simply by re-generating the alternative name from the ..._TYPE node's
1557 UID number. */
1559 static inline void
1560 equate_type_number_to_die_number (type)
1561 register tree type;
1563 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1564 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1566 /* We are generating a DIE to represent the main variant of this type
1567 (i.e the type without any const or volatile qualifiers) so in order
1568 to get the equate to come out right, we need to get the main variant
1569 itself here. */
1571 type = type_main_variant (type);
1573 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1574 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1575 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1578 static void
1579 output_reg_number (rtl)
1580 register rtx rtl;
1582 register unsigned regno = REGNO (rtl);
1584 if (regno >= DWARF_FRAME_REGISTERS)
1586 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1587 regno);
1588 regno = 0;
1590 fprintf (asm_out_file, "%s0x%x",
1591 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1592 if (flag_debug_asm)
1594 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1595 PRINT_REG (rtl, 0, asm_out_file);
1597 fputc ('\n', asm_out_file);
1600 /* The following routine is a nice and simple transducer. It converts the
1601 RTL for a variable or parameter (resident in memory) into an equivalent
1602 Dwarf representation of a mechanism for getting the address of that same
1603 variable onto the top of a hypothetical "address evaluation" stack.
1605 When creating memory location descriptors, we are effectively trans-
1606 forming the RTL for a memory-resident object into its Dwarf postfix
1607 expression equivalent. This routine just recursively descends an
1608 RTL tree, turning it into Dwarf postfix code as it goes. */
1610 static void
1611 output_mem_loc_descriptor (rtl)
1612 register rtx rtl;
1614 /* Note that for a dynamically sized array, the location we will
1615 generate a description of here will be the lowest numbered location
1616 which is actually within the array. That's *not* necessarily the
1617 same as the zeroth element of the array. */
1619 #ifdef ASM_SIMPLIFY_DWARF_ADDR
1620 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
1621 #endif
1623 switch (GET_CODE (rtl))
1625 case SUBREG:
1627 /* The case of a subreg may arise when we have a local (register)
1628 variable or a formal (register) parameter which doesn't quite
1629 fill up an entire register. For now, just assume that it is
1630 legitimate to make the Dwarf info refer to the whole register
1631 which contains the given subreg. */
1633 rtl = XEXP (rtl, 0);
1634 /* Drop thru. */
1636 case REG:
1638 /* Whenever a register number forms a part of the description of
1639 the method for calculating the (dynamic) address of a memory
1640 resident object, DWARF rules require the register number to
1641 be referred to as a "base register". This distinction is not
1642 based in any way upon what category of register the hardware
1643 believes the given register belongs to. This is strictly
1644 DWARF terminology we're dealing with here.
1646 Note that in cases where the location of a memory-resident data
1647 object could be expressed as:
1649 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1651 the actual DWARF location descriptor that we generate may just
1652 be OP_BASEREG (basereg). This may look deceptively like the
1653 object in question was allocated to a register (rather than
1654 in memory) so DWARF consumers need to be aware of the subtle
1655 distinction between OP_REG and OP_BASEREG. */
1657 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1658 output_reg_number (rtl);
1659 break;
1661 case MEM:
1662 output_mem_loc_descriptor (XEXP (rtl, 0));
1663 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1664 break;
1666 case CONST:
1667 case SYMBOL_REF:
1668 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1669 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1670 break;
1672 case PLUS:
1673 output_mem_loc_descriptor (XEXP (rtl, 0));
1674 output_mem_loc_descriptor (XEXP (rtl, 1));
1675 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1676 break;
1678 case CONST_INT:
1679 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1680 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1681 break;
1683 case MULT:
1684 /* If a pseudo-reg is optimized away, it is possible for it to
1685 be replaced with a MEM containing a multiply. Use a GNU extension
1686 to describe it. */
1687 output_mem_loc_descriptor (XEXP (rtl, 0));
1688 output_mem_loc_descriptor (XEXP (rtl, 1));
1689 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT);
1690 break;
1692 default:
1693 abort ();
1697 /* Output a proper Dwarf location descriptor for a variable or parameter
1698 which is either allocated in a register or in a memory location. For
1699 a register, we just generate an OP_REG and the register number. For a
1700 memory location we provide a Dwarf postfix expression describing how to
1701 generate the (dynamic) address of the object onto the address stack. */
1703 static void
1704 output_loc_descriptor (rtl)
1705 register rtx rtl;
1707 switch (GET_CODE (rtl))
1709 case SUBREG:
1711 /* The case of a subreg may arise when we have a local (register)
1712 variable or a formal (register) parameter which doesn't quite
1713 fill up an entire register. For now, just assume that it is
1714 legitimate to make the Dwarf info refer to the whole register
1715 which contains the given subreg. */
1717 rtl = XEXP (rtl, 0);
1718 /* Drop thru. */
1720 case REG:
1721 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1722 output_reg_number (rtl);
1723 break;
1725 case MEM:
1726 output_mem_loc_descriptor (XEXP (rtl, 0));
1727 break;
1729 default:
1730 abort (); /* Should never happen */
1734 /* Given a tree node describing an array bound (either lower or upper)
1735 output a representation for that bound. */
1737 static void
1738 output_bound_representation (bound, dim_num, u_or_l)
1739 register tree bound;
1740 register unsigned dim_num; /* For multi-dimensional arrays. */
1741 register char u_or_l; /* Designates upper or lower bound. */
1743 switch (TREE_CODE (bound))
1746 case ERROR_MARK:
1747 return;
1749 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1751 case INTEGER_CST:
1752 if (host_integerp (bound, 0))
1753 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0));
1754 break;
1756 default:
1758 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1759 SAVE_EXPR nodes, in which case we can do something, or as
1760 an expression, which we cannot represent. */
1762 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1763 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1765 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1766 current_dienum, dim_num, u_or_l);
1768 sprintf (end_label, BOUND_END_LABEL_FMT,
1769 current_dienum, dim_num, u_or_l);
1771 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1772 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1774 /* If optimization is turned on, the SAVE_EXPRs that describe
1775 how to access the upper bound values are essentially bogus.
1776 They only describe (at best) how to get at these values at
1777 the points in the generated code right after they have just
1778 been computed. Worse yet, in the typical case, the upper
1779 bound values will not even *be* computed in the optimized
1780 code, so these SAVE_EXPRs are entirely bogus.
1782 In order to compensate for this fact, we check here to see
1783 if optimization is enabled, and if so, we effectively create
1784 an empty location description for the (unknown and unknowable)
1785 upper bound.
1787 This should not cause too much trouble for existing (stupid?)
1788 debuggers because they have to deal with empty upper bounds
1789 location descriptions anyway in order to be able to deal with
1790 incomplete array types.
1792 Of course an intelligent debugger (GDB?) should be able to
1793 comprehend that a missing upper bound specification in a
1794 array type used for a storage class `auto' local array variable
1795 indicates that the upper bound is both unknown (at compile-
1796 time) and unknowable (at run-time) due to optimization. */
1798 if (! optimize)
1800 while (TREE_CODE (bound) == NOP_EXPR
1801 || TREE_CODE (bound) == CONVERT_EXPR)
1802 bound = TREE_OPERAND (bound, 0);
1804 if (TREE_CODE (bound) == SAVE_EXPR)
1805 output_loc_descriptor
1806 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1809 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1811 break;
1816 /* Recursive function to output a sequence of value/name pairs for
1817 enumeration constants in reversed order. This is called from
1818 enumeration_type_die. */
1820 static void
1821 output_enumeral_list (link)
1822 register tree link;
1824 if (link)
1826 output_enumeral_list (TREE_CHAIN (link));
1828 if (host_integerp (TREE_VALUE (link), 0))
1829 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1830 tree_low_cst (TREE_VALUE (link), 0));
1832 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
1833 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1837 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1838 which is not less than the value itself. */
1840 static inline HOST_WIDE_INT
1841 ceiling (value, boundary)
1842 register HOST_WIDE_INT value;
1843 register unsigned int boundary;
1845 return (((value + boundary - 1) / boundary) * boundary);
1848 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1849 pointer to the declared type for the relevant field variable, or return
1850 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1852 static inline tree
1853 field_type (decl)
1854 register tree decl;
1856 register tree type;
1858 if (TREE_CODE (decl) == ERROR_MARK)
1859 return integer_type_node;
1861 type = DECL_BIT_FIELD_TYPE (decl);
1862 if (type == NULL)
1863 type = TREE_TYPE (decl);
1864 return type;
1867 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1868 node, return the alignment in bits for the type, or else return
1869 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1871 static inline unsigned int
1872 simple_type_align_in_bits (type)
1873 register tree type;
1875 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1878 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1879 node, return the size in bits for the type if it is a constant, or
1880 else return the alignment for the type if the type's size is not
1881 constant, or else return BITS_PER_WORD if the type actually turns out
1882 to be an ERROR_MARK node. */
1884 static inline unsigned HOST_WIDE_INT
1885 simple_type_size_in_bits (type)
1886 register tree type;
1888 tree type_size_tree;
1890 if (TREE_CODE (type) == ERROR_MARK)
1891 return BITS_PER_WORD;
1892 type_size_tree = TYPE_SIZE (type);
1894 if (type_size_tree == NULL_TREE)
1895 return 0;
1896 if (! host_integerp (type_size_tree, 1))
1897 return TYPE_ALIGN (type);
1898 return tree_low_cst (type_size_tree, 1);
1901 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1902 return the byte offset of the lowest addressed byte of the "containing
1903 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1904 mine what that offset is, either because the argument turns out to be a
1905 pointer to an ERROR_MARK node, or because the offset is actually variable.
1906 (We can't handle the latter case just yet.) */
1908 static HOST_WIDE_INT
1909 field_byte_offset (decl)
1910 register tree decl;
1912 unsigned int type_align_in_bytes;
1913 unsigned int type_align_in_bits;
1914 unsigned HOST_WIDE_INT type_size_in_bits;
1915 HOST_WIDE_INT object_offset_in_align_units;
1916 HOST_WIDE_INT object_offset_in_bits;
1917 HOST_WIDE_INT object_offset_in_bytes;
1918 tree type;
1919 tree field_size_tree;
1920 HOST_WIDE_INT bitpos_int;
1921 HOST_WIDE_INT deepest_bitpos;
1922 unsigned HOST_WIDE_INT field_size_in_bits;
1924 if (TREE_CODE (decl) == ERROR_MARK)
1925 return 0;
1927 if (TREE_CODE (decl) != FIELD_DECL)
1928 abort ();
1930 type = field_type (decl);
1931 field_size_tree = DECL_SIZE (decl);
1933 /* The size could be unspecified if there was an error, or for
1934 a flexible array member. */
1935 if (! field_size_tree)
1936 field_size_tree = bitsize_zero_node;
1938 /* We cannot yet cope with fields whose positions or sizes are variable,
1939 so for now, when we see such things, we simply return 0. Someday,
1940 we may be able to handle such cases, but it will be damn difficult. */
1942 if (! host_integerp (bit_position (decl), 0)
1943 || ! host_integerp (field_size_tree, 1))
1944 return 0;
1946 bitpos_int = int_bit_position (decl);
1947 field_size_in_bits = tree_low_cst (field_size_tree, 1);
1949 type_size_in_bits = simple_type_size_in_bits (type);
1950 type_align_in_bits = simple_type_align_in_bits (type);
1951 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1953 /* Note that the GCC front-end doesn't make any attempt to keep track
1954 of the starting bit offset (relative to the start of the containing
1955 structure type) of the hypothetical "containing object" for a bit-
1956 field. Thus, when computing the byte offset value for the start of
1957 the "containing object" of a bit-field, we must deduce this infor-
1958 mation on our own.
1960 This can be rather tricky to do in some cases. For example, handling
1961 the following structure type definition when compiling for an i386/i486
1962 target (which only aligns long long's to 32-bit boundaries) can be very
1963 tricky:
1965 struct S {
1966 int field1;
1967 long long field2:31;
1970 Fortunately, there is a simple rule-of-thumb which can be used in such
1971 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
1972 the structure shown above. It decides to do this based upon one simple
1973 rule for bit-field allocation. Quite simply, GCC allocates each "con-
1974 taining object" for each bit-field at the first (i.e. lowest addressed)
1975 legitimate alignment boundary (based upon the required minimum alignment
1976 for the declared type of the field) which it can possibly use, subject
1977 to the condition that there is still enough available space remaining
1978 in the containing object (when allocated at the selected point) to
1979 fully accommodate all of the bits of the bit-field itself.
1981 This simple rule makes it obvious why GCC allocates 8 bytes for each
1982 object of the structure type shown above. When looking for a place to
1983 allocate the "containing object" for `field2', the compiler simply tries
1984 to allocate a 64-bit "containing object" at each successive 32-bit
1985 boundary (starting at zero) until it finds a place to allocate that 64-
1986 bit field such that at least 31 contiguous (and previously unallocated)
1987 bits remain within that selected 64 bit field. (As it turns out, for
1988 the example above, the compiler finds that it is OK to allocate the
1989 "containing object" 64-bit field at bit-offset zero within the
1990 structure type.)
1992 Here we attempt to work backwards from the limited set of facts we're
1993 given, and we try to deduce from those facts, where GCC must have
1994 believed that the containing object started (within the structure type).
1996 The value we deduce is then used (by the callers of this routine) to
1997 generate AT_location and AT_bit_offset attributes for fields (both
1998 bit-fields and, in the case of AT_location, regular fields as well). */
2000 /* Figure out the bit-distance from the start of the structure to the
2001 "deepest" bit of the bit-field. */
2002 deepest_bitpos = bitpos_int + field_size_in_bits;
2004 /* This is the tricky part. Use some fancy footwork to deduce where the
2005 lowest addressed bit of the containing object must be. */
2006 object_offset_in_bits
2007 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2009 /* Compute the offset of the containing object in "alignment units". */
2010 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
2012 /* Compute the offset of the containing object in bytes. */
2013 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
2015 /* The above code assumes that the field does not cross an alignment
2016 boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined,
2017 or if the structure is packed. If this happens, then we get an object
2018 which starts after the bitfield, which means that the bit offset is
2019 negative. Gdb fails when given negative bit offsets. We avoid this
2020 by recomputing using the first bit of the bitfield. This will give
2021 us an object which does not completely contain the bitfield, but it
2022 will be aligned, and it will contain the first bit of the bitfield.
2024 However, only do this for a BYTES_BIG_ENDIAN target. For a
2025 ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first
2026 first bit of the bitfield. If we recompute using bitpos_int + 1 below,
2027 then we end up computing the object byte offset for the wrong word of the
2028 desired bitfield, which in turn causes the field offset to be negative
2029 in bit_offset_attribute. */
2030 if (BYTES_BIG_ENDIAN
2031 && object_offset_in_bits > bitpos_int)
2033 deepest_bitpos = bitpos_int + 1;
2034 object_offset_in_bits
2035 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
2036 object_offset_in_align_units = (object_offset_in_bits
2037 / type_align_in_bits);
2038 object_offset_in_bytes = (object_offset_in_align_units
2039 * type_align_in_bytes);
2042 return object_offset_in_bytes;
2045 /****************************** attributes *********************************/
2047 /* The following routines are responsible for writing out the various types
2048 of Dwarf attributes (and any following data bytes associated with them).
2049 These routines are listed in order based on the numerical codes of their
2050 associated attributes. */
2052 /* Generate an AT_sibling attribute. */
2054 static inline void
2055 sibling_attribute ()
2057 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2059 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
2060 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
2061 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2064 /* Output the form of location attributes suitable for whole variables and
2065 whole parameters. Note that the location attributes for struct fields
2066 are generated by the routine `data_member_location_attribute' below. */
2068 static void
2069 location_attribute (rtl)
2070 register rtx rtl;
2072 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2073 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2075 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2076 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2077 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2078 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2079 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2081 /* Handle a special case. If we are about to output a location descriptor
2082 for a variable or parameter which has been optimized out of existence,
2083 don't do that. Instead we output a zero-length location descriptor
2084 value as part of the location attribute.
2086 A variable which has been optimized out of existence will have a
2087 DECL_RTL value which denotes a pseudo-reg.
2089 Currently, in some rare cases, variables can have DECL_RTL values
2090 which look like (MEM (REG pseudo-reg#)). These cases are due to
2091 bugs elsewhere in the compiler. We treat such cases
2092 as if the variable(s) in question had been optimized out of existence.
2094 Note that in all cases where we wish to express the fact that a
2095 variable has been optimized out of existence, we do not simply
2096 suppress the generation of the entire location attribute because
2097 the absence of a location attribute in certain kinds of DIEs is
2098 used to indicate something else entirely... i.e. that the DIE
2099 represents an object declaration, but not a definition. So saith
2100 the PLSIG.
2103 if (! is_pseudo_reg (rtl)
2104 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
2105 output_loc_descriptor (rtl);
2107 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2110 /* Output the specialized form of location attribute used for data members
2111 of struct and union types.
2113 In the special case of a FIELD_DECL node which represents a bit-field,
2114 the "offset" part of this special location descriptor must indicate the
2115 distance in bytes from the lowest-addressed byte of the containing
2116 struct or union type to the lowest-addressed byte of the "containing
2117 object" for the bit-field. (See the `field_byte_offset' function above.)
2119 For any given bit-field, the "containing object" is a hypothetical
2120 object (of some integral or enum type) within which the given bit-field
2121 lives. The type of this hypothetical "containing object" is always the
2122 same as the declared type of the individual bit-field itself (for GCC
2123 anyway... the DWARF spec doesn't actually mandate this).
2125 Note that it is the size (in bytes) of the hypothetical "containing
2126 object" which will be given in the AT_byte_size attribute for this
2127 bit-field. (See the `byte_size_attribute' function below.) It is
2128 also used when calculating the value of the AT_bit_offset attribute.
2129 (See the `bit_offset_attribute' function below.) */
2131 static void
2132 data_member_location_attribute (t)
2133 register tree t;
2135 register unsigned object_offset_in_bytes;
2136 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2137 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2139 if (TREE_CODE (t) == TREE_VEC)
2140 object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0);
2141 else
2142 object_offset_in_bytes = field_byte_offset (t);
2144 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
2145 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2146 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2147 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2148 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2149 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
2150 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
2151 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
2152 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2155 /* Output an AT_const_value attribute for a variable or a parameter which
2156 does not have a "location" either in memory or in a register. These
2157 things can arise in GNU C when a constant is passed as an actual
2158 parameter to an inlined function. They can also arise in C++ where
2159 declared constants do not necessarily get memory "homes". */
2161 static void
2162 const_value_attribute (rtl)
2163 register rtx rtl;
2165 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2166 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2168 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2169 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2170 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2171 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2172 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2174 switch (GET_CODE (rtl))
2176 case CONST_INT:
2177 /* Note that a CONST_INT rtx could represent either an integer or
2178 a floating-point constant. A CONST_INT is used whenever the
2179 constant will fit into a single word. In all such cases, the
2180 original mode of the constant value is wiped out, and the
2181 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2182 precise mode information for these constants, we always just
2183 output them using 4 bytes. */
2185 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2186 break;
2188 case CONST_DOUBLE:
2189 /* Note that a CONST_DOUBLE rtx could represent either an integer
2190 or a floating-point constant. A CONST_DOUBLE is used whenever
2191 the constant requires more than one word in order to be adequately
2192 represented. In all such cases, the original mode of the constant
2193 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2194 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2196 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2197 (unsigned int) CONST_DOUBLE_HIGH (rtl),
2198 (unsigned int) CONST_DOUBLE_LOW (rtl));
2199 break;
2201 case CONST_STRING:
2202 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0));
2203 break;
2205 case SYMBOL_REF:
2206 case LABEL_REF:
2207 case CONST:
2208 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2209 break;
2211 case PLUS:
2212 /* In cases where an inlined instance of an inline function is passed
2213 the address of an `auto' variable (which is local to the caller)
2214 we can get a situation where the DECL_RTL of the artificial
2215 local variable (for the inlining) which acts as a stand-in for
2216 the corresponding formal parameter (of the inline function)
2217 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2218 This is not exactly a compile-time constant expression, but it
2219 isn't the address of the (artificial) local variable either.
2220 Rather, it represents the *value* which the artificial local
2221 variable always has during its lifetime. We currently have no
2222 way to represent such quasi-constant values in Dwarf, so for now
2223 we just punt and generate an AT_const_value attribute with form
2224 FORM_BLOCK4 and a length of zero. */
2225 break;
2227 default:
2228 abort (); /* No other kinds of rtx should be possible here. */
2231 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2234 /* Generate *either* an AT_location attribute or else an AT_const_value
2235 data attribute for a variable or a parameter. We generate the
2236 AT_const_value attribute only in those cases where the given
2237 variable or parameter does not have a true "location" either in
2238 memory or in a register. This can happen (for example) when a
2239 constant is passed as an actual argument in a call to an inline
2240 function. (It's possible that these things can crop up in other
2241 ways also.) Note that one type of constant value which can be
2242 passed into an inlined function is a constant pointer. This can
2243 happen for example if an actual argument in an inlined function
2244 call evaluates to a compile-time constant address. */
2246 static void
2247 location_or_const_value_attribute (decl)
2248 register tree decl;
2250 register rtx rtl;
2252 if (TREE_CODE (decl) == ERROR_MARK)
2253 return;
2255 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2257 /* Should never happen. */
2258 abort ();
2259 return;
2262 /* Here we have to decide where we are going to say the parameter "lives"
2263 (as far as the debugger is concerned). We only have a couple of choices.
2264 GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL
2265 normally indicates where the parameter lives during most of the activa-
2266 tion of the function. If optimization is enabled however, this could
2267 be either NULL or else a pseudo-reg. Both of those cases indicate that
2268 the parameter doesn't really live anywhere (as far as the code generation
2269 parts of GCC are concerned) during most of the function's activation.
2270 That will happen (for example) if the parameter is never referenced
2271 within the function.
2273 We could just generate a location descriptor here for all non-NULL
2274 non-pseudo values of DECL_RTL and ignore all of the rest, but we can
2275 be a little nicer than that if we also consider DECL_INCOMING_RTL in
2276 cases where DECL_RTL is NULL or is a pseudo-reg.
2278 Note however that we can only get away with using DECL_INCOMING_RTL as
2279 a backup substitute for DECL_RTL in certain limited cases. In cases
2280 where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
2281 we can be sure that the parameter was passed using the same type as it
2282 is declared to have within the function, and that its DECL_INCOMING_RTL
2283 points us to a place where a value of that type is passed. In cases
2284 where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
2285 however, we cannot (in general) use DECL_INCOMING_RTL as a backup
2286 substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
2287 points us to a value of some type which is *different* from the type
2288 of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL
2289 to generate a location attribute in such cases, the debugger would
2290 end up (for example) trying to fetch a `float' from a place which
2291 actually contains the first part of a `double'. That would lead to
2292 really incorrect and confusing output at debug-time, and we don't
2293 want that now do we?
2295 So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
2296 in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a
2297 couple of cute exceptions however. On little-endian machines we can
2298 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
2299 not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
2300 an integral type which is smaller than TREE_TYPE(decl). These cases
2301 arise when (on a little-endian machine) a non-prototyped function has
2302 a parameter declared to be of type `short' or `char'. In such cases,
2303 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
2304 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
2305 passed `int' value. If the debugger then uses that address to fetch a
2306 `short' or a `char' (on a little-endian machine) the result will be the
2307 correct data, so we allow for such exceptional cases below.
2309 Note that our goal here is to describe the place where the given formal
2310 parameter lives during most of the function's activation (i.e. between
2311 the end of the prologue and the start of the epilogue). We'll do that
2312 as best as we can. Note however that if the given formal parameter is
2313 modified sometime during the execution of the function, then a stack
2314 backtrace (at debug-time) will show the function as having been called
2315 with the *new* value rather than the value which was originally passed
2316 in. This happens rarely enough that it is not a major problem, but it
2317 *is* a problem, and I'd like to fix it. A future version of dwarfout.c
2318 may generate two additional attributes for any given TAG_formal_parameter
2319 DIE which will describe the "passed type" and the "passed location" for
2320 the given formal parameter in addition to the attributes we now generate
2321 to indicate the "declared type" and the "active location" for each
2322 parameter. This additional set of attributes could be used by debuggers
2323 for stack backtraces.
2325 Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
2326 can be NULL also. This happens (for example) for inlined-instances of
2327 inline function formal parameters which are never referenced. This really
2328 shouldn't be happening. All PARM_DECL nodes should get valid non-NULL
2329 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
2330 these values for inlined instances of inline function parameters, so
2331 when we see such cases, we are just out-of-luck for the time
2332 being (until integrate.c gets fixed).
2335 /* Use DECL_RTL as the "location" unless we find something better. */
2336 rtl = DECL_RTL (decl);
2338 if (TREE_CODE (decl) == PARM_DECL)
2339 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
2341 /* This decl represents a formal parameter which was optimized out. */
2342 register tree declared_type = type_main_variant (TREE_TYPE (decl));
2343 register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
2345 /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
2346 *all* cases where (rtl == NULL_RTX) just below. */
2348 if (declared_type == passed_type)
2349 rtl = DECL_INCOMING_RTL (decl);
2350 else if (! BYTES_BIG_ENDIAN)
2351 if (TREE_CODE (declared_type) == INTEGER_TYPE)
2352 /* NMS WTF? */
2353 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
2354 rtl = DECL_INCOMING_RTL (decl);
2357 if (rtl == NULL_RTX)
2358 return;
2360 rtl = eliminate_regs (rtl, 0, NULL_RTX);
2361 #ifdef LEAF_REG_REMAP
2362 if (current_function_uses_only_leaf_regs)
2363 leaf_renumber_regs_insn (rtl);
2364 #endif
2366 switch (GET_CODE (rtl))
2368 case ADDRESSOF:
2369 /* The address of a variable that was optimized away; don't emit
2370 anything. */
2371 break;
2373 case CONST_INT:
2374 case CONST_DOUBLE:
2375 case CONST_STRING:
2376 case SYMBOL_REF:
2377 case LABEL_REF:
2378 case CONST:
2379 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2380 const_value_attribute (rtl);
2381 break;
2383 case MEM:
2384 case REG:
2385 case SUBREG:
2386 location_attribute (rtl);
2387 break;
2389 case CONCAT:
2390 /* ??? CONCAT is used for complex variables, which may have the real
2391 part stored in one place and the imag part stored somewhere else.
2392 DWARF1 has no way to describe a variable that lives in two different
2393 places, so we just describe where the first part lives, and hope that
2394 the second part is stored after it. */
2395 location_attribute (XEXP (rtl, 0));
2396 break;
2398 default:
2399 abort (); /* Should never happen. */
2403 /* Generate an AT_name attribute given some string value to be included as
2404 the value of the attribute. */
2406 static inline void
2407 name_attribute (name_string)
2408 register const char *name_string;
2410 if (name_string && *name_string)
2412 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2413 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string);
2417 static inline void
2418 fund_type_attribute (ft_code)
2419 register unsigned ft_code;
2421 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2422 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2425 static void
2426 mod_fund_type_attribute (type, decl_const, decl_volatile)
2427 register tree type;
2428 register int decl_const;
2429 register int decl_volatile;
2431 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2432 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2434 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2435 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2436 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2437 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2438 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2439 write_modifier_bytes (type, decl_const, decl_volatile);
2440 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2441 fundamental_type_code (root_type (type)));
2442 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2445 static inline void
2446 user_def_type_attribute (type)
2447 register tree type;
2449 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2451 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2452 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2453 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2456 static void
2457 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2458 register tree type;
2459 register int decl_const;
2460 register int decl_volatile;
2462 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2463 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2464 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2466 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2467 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2468 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2469 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2470 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2471 write_modifier_bytes (type, decl_const, decl_volatile);
2472 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2473 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2474 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2477 #ifdef USE_ORDERING_ATTRIBUTE
2478 static inline void
2479 ordering_attribute (ordering)
2480 register unsigned ordering;
2482 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2483 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2485 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2487 /* Note that the block of subscript information for an array type also
2488 includes information about the element type of type given array type. */
2490 static void
2491 subscript_data_attribute (type)
2492 register tree type;
2494 register unsigned dimension_number;
2495 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2496 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2498 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2499 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2500 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2501 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2502 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2504 /* The GNU compilers represent multidimensional array types as sequences
2505 of one dimensional array types whose element types are themselves array
2506 types. Here we squish that down, so that each multidimensional array
2507 type gets only one array_type DIE in the Dwarf debugging info. The
2508 draft Dwarf specification say that we are allowed to do this kind
2509 of compression in C (because there is no difference between an
2510 array or arrays and a multidimensional array in C) but for other
2511 source languages (e.g. Ada) we probably shouldn't do this. */
2513 for (dimension_number = 0;
2514 TREE_CODE (type) == ARRAY_TYPE;
2515 type = TREE_TYPE (type), dimension_number++)
2517 register tree domain = TYPE_DOMAIN (type);
2519 /* Arrays come in three flavors. Unspecified bounds, fixed
2520 bounds, and (in GNU C only) variable bounds. Handle all
2521 three forms here. */
2523 if (domain)
2525 /* We have an array type with specified bounds. */
2527 register tree lower = TYPE_MIN_VALUE (domain);
2528 register tree upper = TYPE_MAX_VALUE (domain);
2530 /* Handle only fundamental types as index types for now. */
2531 if (! type_is_fundamental (domain))
2532 abort ();
2534 /* Output the representation format byte for this dimension. */
2535 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2536 FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
2537 upper && TREE_CODE (upper) == INTEGER_CST));
2539 /* Output the index type for this dimension. */
2540 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2541 fundamental_type_code (domain));
2543 /* Output the representation for the lower bound. */
2544 output_bound_representation (lower, dimension_number, 'l');
2546 /* Output the representation for the upper bound. */
2547 if (upper)
2548 output_bound_representation (upper, dimension_number, 'u');
2549 else
2550 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2552 else
2554 /* We have an array type with an unspecified length. For C and
2555 C++ we can assume that this really means that (a) the index
2556 type is an integral type, and (b) the lower bound is zero.
2557 Note that Dwarf defines the representation of an unspecified
2558 (upper) bound as being a zero-length location description. */
2560 /* Output the array-bounds format byte. */
2562 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2564 /* Output the (assumed) index type. */
2566 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2568 /* Output the (assumed) lower bound (constant) value. */
2570 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2572 /* Output the (empty) location description for the upper bound. */
2574 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2578 /* Output the prefix byte that says that the element type is coming up. */
2580 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2582 /* Output a representation of the type of the elements of this array type. */
2584 type_attribute (type, 0, 0);
2586 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2589 static void
2590 byte_size_attribute (tree_node)
2591 register tree tree_node;
2593 register unsigned size;
2595 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2596 switch (TREE_CODE (tree_node))
2598 case ERROR_MARK:
2599 size = 0;
2600 break;
2602 case ENUMERAL_TYPE:
2603 case RECORD_TYPE:
2604 case UNION_TYPE:
2605 case QUAL_UNION_TYPE:
2606 case ARRAY_TYPE:
2607 size = int_size_in_bytes (tree_node);
2608 break;
2610 case FIELD_DECL:
2611 /* For a data member of a struct or union, the AT_byte_size is
2612 generally given as the number of bytes normally allocated for
2613 an object of the *declared* type of the member itself. This
2614 is true even for bit-fields. */
2615 size = simple_type_size_in_bits (field_type (tree_node))
2616 / BITS_PER_UNIT;
2617 break;
2619 default:
2620 abort ();
2623 /* Note that `size' might be -1 when we get to this point. If it
2624 is, that indicates that the byte size of the entity in question
2625 is variable. We have no good way of expressing this fact in Dwarf
2626 at the present time, so just let the -1 pass on through. */
2628 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2631 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2632 which specifies the distance in bits from the highest order bit of the
2633 "containing object" for the bit-field to the highest order bit of the
2634 bit-field itself.
2636 For any given bit-field, the "containing object" is a hypothetical
2637 object (of some integral or enum type) within which the given bit-field
2638 lives. The type of this hypothetical "containing object" is always the
2639 same as the declared type of the individual bit-field itself.
2641 The determination of the exact location of the "containing object" for
2642 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2643 function (above).
2645 Note that it is the size (in bytes) of the hypothetical "containing
2646 object" which will be given in the AT_byte_size attribute for this
2647 bit-field. (See `byte_size_attribute' above.) */
2649 static inline void
2650 bit_offset_attribute (decl)
2651 register tree decl;
2653 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
2654 tree type = DECL_BIT_FIELD_TYPE (decl);
2655 HOST_WIDE_INT bitpos_int;
2656 HOST_WIDE_INT highest_order_object_bit_offset;
2657 HOST_WIDE_INT highest_order_field_bit_offset;
2658 HOST_WIDE_INT bit_offset;
2660 /* Must be a bit field. */
2661 if (!type
2662 || TREE_CODE (decl) != FIELD_DECL)
2663 abort ();
2665 /* We can't yet handle bit-fields whose offsets or sizes are variable, so
2666 if we encounter such things, just return without generating any
2667 attribute whatsoever. */
2669 if (! host_integerp (bit_position (decl), 0)
2670 || ! host_integerp (DECL_SIZE (decl), 1))
2671 return;
2673 bitpos_int = int_bit_position (decl);
2675 /* Note that the bit offset is always the distance (in bits) from the
2676 highest-order bit of the "containing object" to the highest-order
2677 bit of the bit-field itself. Since the "high-order end" of any
2678 object or field is different on big-endian and little-endian machines,
2679 the computation below must take account of these differences. */
2681 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2682 highest_order_field_bit_offset = bitpos_int;
2684 if (! BYTES_BIG_ENDIAN)
2686 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1);
2687 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2690 bit_offset =
2691 (! BYTES_BIG_ENDIAN
2692 ? highest_order_object_bit_offset - highest_order_field_bit_offset
2693 : highest_order_field_bit_offset - highest_order_object_bit_offset);
2695 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2696 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2699 /* For a FIELD_DECL node which represents a bit field, output an attribute
2700 which specifies the length in bits of the given field. */
2702 static inline void
2703 bit_size_attribute (decl)
2704 register tree decl;
2706 /* Must be a field and a bit field. */
2707 if (TREE_CODE (decl) != FIELD_DECL
2708 || ! DECL_BIT_FIELD_TYPE (decl))
2709 abort ();
2711 if (host_integerp (DECL_SIZE (decl), 1))
2713 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2714 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2715 tree_low_cst (DECL_SIZE (decl), 1));
2719 /* The following routine outputs the `element_list' attribute for enumeration
2720 type DIEs. The element_lits attribute includes the names and values of
2721 all of the enumeration constants associated with the given enumeration
2722 type. */
2724 static inline void
2725 element_list_attribute (element)
2726 register tree element;
2728 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2729 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2731 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2732 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2733 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2734 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2735 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2737 /* Here we output a list of value/name pairs for each enumeration constant
2738 defined for this enumeration type (as required), but we do it in REVERSE
2739 order. The order is the one required by the draft #5 Dwarf specification
2740 published by the UI/PLSIG. */
2742 output_enumeral_list (element); /* Recursively output the whole list. */
2744 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2747 /* Generate an AT_stmt_list attribute. These are normally present only in
2748 DIEs with a TAG_compile_unit tag. */
2750 static inline void
2751 stmt_list_attribute (label)
2752 register const char *label;
2754 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2755 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2756 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2759 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2760 for a subroutine DIE. */
2762 static inline void
2763 low_pc_attribute (asm_low_label)
2764 register const char *asm_low_label;
2766 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2767 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2770 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2771 subroutine DIE. */
2773 static inline void
2774 high_pc_attribute (asm_high_label)
2775 register const char *asm_high_label;
2777 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2778 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2781 /* Generate an AT_body_begin attribute for a subroutine DIE. */
2783 static inline void
2784 body_begin_attribute (asm_begin_label)
2785 register const char *asm_begin_label;
2787 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
2788 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
2791 /* Generate an AT_body_end attribute for a subroutine DIE. */
2793 static inline void
2794 body_end_attribute (asm_end_label)
2795 register const char *asm_end_label;
2797 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
2798 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
2801 /* Generate an AT_language attribute given a LANG value. These attributes
2802 are used only within TAG_compile_unit DIEs. */
2804 static inline void
2805 language_attribute (language_code)
2806 register unsigned language_code;
2808 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2809 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2812 static inline void
2813 member_attribute (context)
2814 register tree context;
2816 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2818 /* Generate this attribute only for members in C++. */
2820 if (context != NULL && is_tagged_type (context))
2822 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2823 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2824 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2828 #if 0
2829 static inline void
2830 string_length_attribute (upper_bound)
2831 register tree upper_bound;
2833 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2834 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2836 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2837 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2838 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2839 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2840 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2841 output_bound_representation (upper_bound, 0, 'u');
2842 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2844 #endif
2846 static inline void
2847 comp_dir_attribute (dirname)
2848 register const char *dirname;
2850 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2851 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
2854 static inline void
2855 sf_names_attribute (sf_names_start_label)
2856 register const char *sf_names_start_label;
2858 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2859 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2860 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2863 static inline void
2864 src_info_attribute (src_info_start_label)
2865 register const char *src_info_start_label;
2867 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2868 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2869 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2872 static inline void
2873 mac_info_attribute (mac_info_start_label)
2874 register const char *mac_info_start_label;
2876 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2877 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2878 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2881 static inline void
2882 prototyped_attribute (func_type)
2883 register tree func_type;
2885 if ((strcmp (language_string, "GNU C") == 0)
2886 && (TYPE_ARG_TYPES (func_type) != NULL))
2888 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2889 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2893 static inline void
2894 producer_attribute (producer)
2895 register const char *producer;
2897 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2898 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer);
2901 static inline void
2902 inline_attribute (decl)
2903 register tree decl;
2905 if (DECL_INLINE (decl))
2907 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2908 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2912 static inline void
2913 containing_type_attribute (containing_type)
2914 register tree containing_type;
2916 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2918 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2919 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2920 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2923 static inline void
2924 abstract_origin_attribute (origin)
2925 register tree origin;
2927 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2929 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2930 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2932 case 'd':
2933 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2934 break;
2936 case 't':
2937 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2938 break;
2940 default:
2941 abort (); /* Should never happen. */
2944 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2947 #ifdef DWARF_DECL_COORDINATES
2948 static inline void
2949 src_coords_attribute (src_fileno, src_lineno)
2950 register unsigned src_fileno;
2951 register unsigned src_lineno;
2953 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2954 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2955 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2957 #endif /* defined(DWARF_DECL_COORDINATES) */
2959 static inline void
2960 pure_or_virtual_attribute (func_decl)
2961 register tree func_decl;
2963 if (DECL_VIRTUAL_P (func_decl))
2965 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
2966 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2967 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2968 else
2969 #endif
2970 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2971 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
2975 /************************* end of attributes *****************************/
2977 /********************* utility routines for DIEs *************************/
2979 /* Output an AT_name attribute and an AT_src_coords attribute for the
2980 given decl, but only if it actually has a name. */
2982 static void
2983 name_and_src_coords_attributes (decl)
2984 register tree decl;
2986 register tree decl_name = DECL_NAME (decl);
2988 if (decl_name && IDENTIFIER_POINTER (decl_name))
2990 name_attribute (IDENTIFIER_POINTER (decl_name));
2991 #ifdef DWARF_DECL_COORDINATES
2993 register unsigned file_index;
2995 /* This is annoying, but we have to pop out of the .debug section
2996 for a moment while we call `lookup_filename' because calling it
2997 may cause a temporary switch into the .debug_sfnames section and
2998 most svr4 assemblers are not smart enough to be able to nest
2999 section switches to any depth greater than one. Note that we
3000 also can't skirt this issue by delaying all output to the
3001 .debug_sfnames section unit the end of compilation because that
3002 would cause us to have inter-section forward references and
3003 Fred Fish sez that m68k/svr4 assemblers botch those. */
3005 ASM_OUTPUT_POP_SECTION (asm_out_file);
3006 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
3007 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3009 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
3011 #endif /* defined(DWARF_DECL_COORDINATES) */
3015 /* Many forms of DIEs contain a "type description" part. The following
3016 routine writes out these "type descriptor" parts. */
3018 static void
3019 type_attribute (type, decl_const, decl_volatile)
3020 register tree type;
3021 register int decl_const;
3022 register int decl_volatile;
3024 register enum tree_code code = TREE_CODE (type);
3025 register int root_type_modified;
3027 if (code == ERROR_MARK)
3028 return;
3030 /* Handle a special case. For functions whose return type is void,
3031 we generate *no* type attribute. (Note that no object may have
3032 type `void', so this only applies to function return types. */
3034 if (code == VOID_TYPE)
3035 return;
3037 /* If this is a subtype, find the underlying type. Eventually,
3038 this should write out the appropriate subtype info. */
3039 while ((code == INTEGER_TYPE || code == REAL_TYPE)
3040 && TREE_TYPE (type) != 0)
3041 type = TREE_TYPE (type), code = TREE_CODE (type);
3043 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
3044 || decl_const || decl_volatile
3045 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
3047 if (type_is_fundamental (root_type (type)))
3049 if (root_type_modified)
3050 mod_fund_type_attribute (type, decl_const, decl_volatile);
3051 else
3052 fund_type_attribute (fundamental_type_code (type));
3054 else
3056 if (root_type_modified)
3057 mod_u_d_type_attribute (type, decl_const, decl_volatile);
3058 else
3059 /* We have to get the type_main_variant here (and pass that to the
3060 `user_def_type_attribute' routine) because the ..._TYPE node we
3061 have might simply be a *copy* of some original type node (where
3062 the copy was created to help us keep track of typedef names)
3063 and that copy might have a different TYPE_UID from the original
3064 ..._TYPE node. (Note that when `equate_type_number_to_die_number'
3065 is labeling a given type DIE for future reference, it always and
3066 only creates labels for DIEs representing *main variants*, and it
3067 never even knows about non-main-variants.) */
3068 user_def_type_attribute (type_main_variant (type));
3072 /* Given a tree pointer to a struct, class, union, or enum type node, return
3073 a pointer to the (string) tag name for the given type, or zero if the
3074 type was declared without a tag. */
3076 static const char *
3077 type_tag (type)
3078 register tree type;
3080 register const char *name = 0;
3082 if (TYPE_NAME (type) != 0)
3084 register tree t = 0;
3086 /* Find the IDENTIFIER_NODE for the type name. */
3087 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3088 t = TYPE_NAME (type);
3090 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
3091 a TYPE_DECL node, regardless of whether or not a `typedef' was
3092 involved. */
3093 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3094 && ! DECL_IGNORED_P (TYPE_NAME (type)))
3095 t = DECL_NAME (TYPE_NAME (type));
3097 /* Now get the name as a string, or invent one. */
3098 if (t != 0)
3099 name = IDENTIFIER_POINTER (t);
3102 return (name == 0 || *name == '\0') ? 0 : name;
3105 static inline void
3106 dienum_push ()
3108 /* Start by checking if the pending_sibling_stack needs to be expanded.
3109 If necessary, expand it. */
3111 if (pending_siblings == pending_siblings_allocated)
3113 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
3114 pending_sibling_stack
3115 = (unsigned *) xrealloc (pending_sibling_stack,
3116 pending_siblings_allocated * sizeof(unsigned));
3119 pending_siblings++;
3120 NEXT_DIE_NUM = next_unused_dienum++;
3123 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
3124 NEXT_DIE_NUM. */
3126 static inline void
3127 dienum_pop ()
3129 pending_siblings--;
3132 static inline tree
3133 member_declared_type (member)
3134 register tree member;
3136 return (DECL_BIT_FIELD_TYPE (member))
3137 ? DECL_BIT_FIELD_TYPE (member)
3138 : TREE_TYPE (member);
3141 /* Get the function's label, as described by its RTL.
3142 This may be different from the DECL_NAME name used
3143 in the source file. */
3145 static const char *
3146 function_start_label (decl)
3147 register tree decl;
3149 rtx x;
3150 const char *fnname;
3152 x = DECL_RTL (decl);
3153 if (GET_CODE (x) != MEM)
3154 abort ();
3155 x = XEXP (x, 0);
3156 if (GET_CODE (x) != SYMBOL_REF)
3157 abort ();
3158 fnname = XSTR (x, 0);
3159 return fnname;
3163 /******************************* DIEs ************************************/
3165 /* Output routines for individual types of DIEs. */
3167 /* Note that every type of DIE (except a null DIE) gets a sibling. */
3169 static void
3170 output_array_type_die (arg)
3171 register void *arg;
3173 register tree type = arg;
3175 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
3176 sibling_attribute ();
3177 equate_type_number_to_die_number (type);
3178 member_attribute (TYPE_CONTEXT (type));
3180 /* I believe that we can default the array ordering. SDB will probably
3181 do the right things even if AT_ordering is not present. It's not
3182 even an issue until we start to get into multidimensional arrays
3183 anyway. If SDB is ever caught doing the Wrong Thing for multi-
3184 dimensional arrays, then we'll have to put the AT_ordering attribute
3185 back in. (But if and when we find out that we need to put these in,
3186 we will only do so for multidimensional arrays. After all, we don't
3187 want to waste space in the .debug section now do we?) */
3189 #ifdef USE_ORDERING_ATTRIBUTE
3190 ordering_attribute (ORD_row_major);
3191 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
3193 subscript_data_attribute (type);
3196 static void
3197 output_set_type_die (arg)
3198 register void *arg;
3200 register tree type = arg;
3202 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
3203 sibling_attribute ();
3204 equate_type_number_to_die_number (type);
3205 member_attribute (TYPE_CONTEXT (type));
3206 type_attribute (TREE_TYPE (type), 0, 0);
3209 #if 0
3210 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
3212 static void
3213 output_entry_point_die (arg)
3214 register void *arg;
3216 register tree decl = arg;
3217 register tree origin = decl_ultimate_origin (decl);
3219 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
3220 sibling_attribute ();
3221 dienum_push ();
3222 if (origin != NULL)
3223 abstract_origin_attribute (origin);
3224 else
3226 name_and_src_coords_attributes (decl);
3227 member_attribute (DECL_CONTEXT (decl));
3228 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
3230 if (DECL_ABSTRACT (decl))
3231 equate_decl_number_to_die_number (decl);
3232 else
3233 low_pc_attribute (function_start_label (decl));
3235 #endif
3237 /* Output a DIE to represent an inlined instance of an enumeration type. */
3239 static void
3240 output_inlined_enumeration_type_die (arg)
3241 register void *arg;
3243 register tree type = arg;
3245 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3246 sibling_attribute ();
3247 if (!TREE_ASM_WRITTEN (type))
3248 abort ();
3249 abstract_origin_attribute (type);
3252 /* Output a DIE to represent an inlined instance of a structure type. */
3254 static void
3255 output_inlined_structure_type_die (arg)
3256 register void *arg;
3258 register tree type = arg;
3260 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3261 sibling_attribute ();
3262 if (!TREE_ASM_WRITTEN (type))
3263 abort ();
3264 abstract_origin_attribute (type);
3267 /* Output a DIE to represent an inlined instance of a union type. */
3269 static void
3270 output_inlined_union_type_die (arg)
3271 register void *arg;
3273 register tree type = arg;
3275 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3276 sibling_attribute ();
3277 if (!TREE_ASM_WRITTEN (type))
3278 abort ();
3279 abstract_origin_attribute (type);
3282 /* Output a DIE to represent an enumeration type. Note that these DIEs
3283 include all of the information about the enumeration values also.
3284 This information is encoded into the element_list attribute. */
3286 static void
3287 output_enumeration_type_die (arg)
3288 register void *arg;
3290 register tree type = arg;
3292 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3293 sibling_attribute ();
3294 equate_type_number_to_die_number (type);
3295 name_attribute (type_tag (type));
3296 member_attribute (TYPE_CONTEXT (type));
3298 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3299 given enum type is incomplete, do not generate the AT_byte_size
3300 attribute or the AT_element_list attribute. */
3302 if (COMPLETE_TYPE_P (type))
3304 byte_size_attribute (type);
3305 element_list_attribute (TYPE_FIELDS (type));
3309 /* Output a DIE to represent either a real live formal parameter decl or
3310 to represent just the type of some formal parameter position in some
3311 function type.
3313 Note that this routine is a bit unusual because its argument may be
3314 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3315 represents an inlining of some PARM_DECL) or else some sort of a
3316 ..._TYPE node. If it's the former then this function is being called
3317 to output a DIE to represent a formal parameter object (or some inlining
3318 thereof). If it's the latter, then this function is only being called
3319 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3320 formal argument type of some subprogram type. */
3322 static void
3323 output_formal_parameter_die (arg)
3324 register void *arg;
3326 register tree node = arg;
3328 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3329 sibling_attribute ();
3331 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3333 case 'd': /* We were called with some kind of a ..._DECL node. */
3335 register tree origin = decl_ultimate_origin (node);
3337 if (origin != NULL)
3338 abstract_origin_attribute (origin);
3339 else
3341 name_and_src_coords_attributes (node);
3342 type_attribute (TREE_TYPE (node),
3343 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3345 if (DECL_ABSTRACT (node))
3346 equate_decl_number_to_die_number (node);
3347 else
3348 location_or_const_value_attribute (node);
3350 break;
3352 case 't': /* We were called with some kind of a ..._TYPE node. */
3353 type_attribute (node, 0, 0);
3354 break;
3356 default:
3357 abort (); /* Should never happen. */
3361 /* Output a DIE to represent a declared function (either file-scope
3362 or block-local) which has "external linkage" (according to ANSI-C). */
3364 static void
3365 output_global_subroutine_die (arg)
3366 register void *arg;
3368 register tree decl = arg;
3369 register tree origin = decl_ultimate_origin (decl);
3371 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3372 sibling_attribute ();
3373 dienum_push ();
3374 if (origin != NULL)
3375 abstract_origin_attribute (origin);
3376 else
3378 register tree type = TREE_TYPE (decl);
3380 name_and_src_coords_attributes (decl);
3381 inline_attribute (decl);
3382 prototyped_attribute (type);
3383 member_attribute (DECL_CONTEXT (decl));
3384 type_attribute (TREE_TYPE (type), 0, 0);
3385 pure_or_virtual_attribute (decl);
3387 if (DECL_ABSTRACT (decl))
3388 equate_decl_number_to_die_number (decl);
3389 else
3391 if (! DECL_EXTERNAL (decl) && ! in_class
3392 && decl == current_function_decl)
3394 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3396 low_pc_attribute (function_start_label (decl));
3397 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3398 high_pc_attribute (label);
3399 if (use_gnu_debug_info_extensions)
3401 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3402 body_begin_attribute (label);
3403 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3404 body_end_attribute (label);
3410 /* Output a DIE to represent a declared data object (either file-scope
3411 or block-local) which has "external linkage" (according to ANSI-C). */
3413 static void
3414 output_global_variable_die (arg)
3415 register void *arg;
3417 register tree decl = arg;
3418 register tree origin = decl_ultimate_origin (decl);
3420 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3421 sibling_attribute ();
3422 if (origin != NULL)
3423 abstract_origin_attribute (origin);
3424 else
3426 name_and_src_coords_attributes (decl);
3427 member_attribute (DECL_CONTEXT (decl));
3428 type_attribute (TREE_TYPE (decl),
3429 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3431 if (DECL_ABSTRACT (decl))
3432 equate_decl_number_to_die_number (decl);
3433 else
3435 if (! DECL_EXTERNAL (decl) && ! in_class
3436 && current_function_decl == decl_function_context (decl))
3437 location_or_const_value_attribute (decl);
3441 static void
3442 output_label_die (arg)
3443 register void *arg;
3445 register tree decl = arg;
3446 register tree origin = decl_ultimate_origin (decl);
3448 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3449 sibling_attribute ();
3450 if (origin != NULL)
3451 abstract_origin_attribute (origin);
3452 else
3453 name_and_src_coords_attributes (decl);
3454 if (DECL_ABSTRACT (decl))
3455 equate_decl_number_to_die_number (decl);
3456 else
3458 register rtx insn = DECL_RTL (decl);
3460 /* Deleted labels are programmer specified labels which have been
3461 eliminated because of various optimisations. We still emit them
3462 here so that it is possible to put breakpoints on them. */
3463 if (GET_CODE (insn) == CODE_LABEL
3464 || ((GET_CODE (insn) == NOTE
3465 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
3467 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3469 /* When optimization is enabled (via -O) some parts of the compiler
3470 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3471 represent source-level labels which were explicitly declared by
3472 the user. This really shouldn't be happening though, so catch
3473 it if it ever does happen. */
3475 if (INSN_DELETED_P (insn))
3476 abort (); /* Should never happen. */
3478 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
3479 low_pc_attribute (label);
3484 static void
3485 output_lexical_block_die (arg)
3486 register void *arg;
3488 register tree stmt = arg;
3490 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3491 sibling_attribute ();
3492 dienum_push ();
3493 if (! BLOCK_ABSTRACT (stmt))
3495 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3496 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3498 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3499 low_pc_attribute (begin_label);
3500 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3501 high_pc_attribute (end_label);
3505 static void
3506 output_inlined_subroutine_die (arg)
3507 register void *arg;
3509 register tree stmt = arg;
3511 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3512 sibling_attribute ();
3513 dienum_push ();
3514 abstract_origin_attribute (block_ultimate_origin (stmt));
3515 if (! BLOCK_ABSTRACT (stmt))
3517 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3518 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3520 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt));
3521 low_pc_attribute (begin_label);
3522 sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt));
3523 high_pc_attribute (end_label);
3527 /* Output a DIE to represent a declared data object (either file-scope
3528 or block-local) which has "internal linkage" (according to ANSI-C). */
3530 static void
3531 output_local_variable_die (arg)
3532 register void *arg;
3534 register tree decl = arg;
3535 register tree origin = decl_ultimate_origin (decl);
3537 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3538 sibling_attribute ();
3539 if (origin != NULL)
3540 abstract_origin_attribute (origin);
3541 else
3543 name_and_src_coords_attributes (decl);
3544 member_attribute (DECL_CONTEXT (decl));
3545 type_attribute (TREE_TYPE (decl),
3546 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3548 if (DECL_ABSTRACT (decl))
3549 equate_decl_number_to_die_number (decl);
3550 else
3551 location_or_const_value_attribute (decl);
3554 static void
3555 output_member_die (arg)
3556 register void *arg;
3558 register tree decl = arg;
3560 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3561 sibling_attribute ();
3562 name_and_src_coords_attributes (decl);
3563 member_attribute (DECL_CONTEXT (decl));
3564 type_attribute (member_declared_type (decl),
3565 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3566 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3568 byte_size_attribute (decl);
3569 bit_size_attribute (decl);
3570 bit_offset_attribute (decl);
3572 data_member_location_attribute (decl);
3575 #if 0
3576 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3577 modified types instead.
3579 We keep this code here just in case these types of DIEs may be
3580 needed to represent certain things in other languages (e.g. Pascal)
3581 someday. */
3583 static void
3584 output_pointer_type_die (arg)
3585 register void *arg;
3587 register tree type = arg;
3589 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3590 sibling_attribute ();
3591 equate_type_number_to_die_number (type);
3592 member_attribute (TYPE_CONTEXT (type));
3593 type_attribute (TREE_TYPE (type), 0, 0);
3596 static void
3597 output_reference_type_die (arg)
3598 register void *arg;
3600 register tree type = arg;
3602 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3603 sibling_attribute ();
3604 equate_type_number_to_die_number (type);
3605 member_attribute (TYPE_CONTEXT (type));
3606 type_attribute (TREE_TYPE (type), 0, 0);
3608 #endif
3610 static void
3611 output_ptr_to_mbr_type_die (arg)
3612 register void *arg;
3614 register tree type = arg;
3616 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3617 sibling_attribute ();
3618 equate_type_number_to_die_number (type);
3619 member_attribute (TYPE_CONTEXT (type));
3620 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3621 type_attribute (TREE_TYPE (type), 0, 0);
3624 static void
3625 output_compile_unit_die (arg)
3626 register void *arg;
3628 register const char *main_input_filename = arg;
3630 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3631 sibling_attribute ();
3632 dienum_push ();
3633 name_attribute (main_input_filename);
3636 char producer[250];
3638 sprintf (producer, "%s %s", language_string, version_string);
3639 producer_attribute (producer);
3642 if (strcmp (language_string, "GNU C++") == 0)
3643 language_attribute (LANG_C_PLUS_PLUS);
3644 else if (strcmp (language_string, "GNU Ada") == 0)
3645 language_attribute (LANG_ADA83);
3646 else if (strcmp (language_string, "GNU F77") == 0)
3647 language_attribute (LANG_FORTRAN77);
3648 else if (strcmp (language_string, "GNU Pascal") == 0)
3649 language_attribute (LANG_PASCAL83);
3650 else if (strcmp (language_string, "GNU Java") == 0)
3651 language_attribute (LANG_JAVA);
3652 else if (flag_traditional)
3653 language_attribute (LANG_C);
3654 else
3655 language_attribute (LANG_C89);
3656 low_pc_attribute (TEXT_BEGIN_LABEL);
3657 high_pc_attribute (TEXT_END_LABEL);
3658 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3659 stmt_list_attribute (LINE_BEGIN_LABEL);
3660 last_filename = xstrdup (main_input_filename);
3663 const char *wd = getpwd ();
3664 if (wd)
3665 comp_dir_attribute (wd);
3668 if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions)
3670 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3671 src_info_attribute (SRCINFO_BEGIN_LABEL);
3672 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3673 mac_info_attribute (MACINFO_BEGIN_LABEL);
3677 static void
3678 output_string_type_die (arg)
3679 register void *arg;
3681 register tree type = arg;
3683 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3684 sibling_attribute ();
3685 equate_type_number_to_die_number (type);
3686 member_attribute (TYPE_CONTEXT (type));
3687 /* this is a fixed length string */
3688 byte_size_attribute (type);
3691 static void
3692 output_inheritance_die (arg)
3693 register void *arg;
3695 register tree binfo = arg;
3697 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance);
3698 sibling_attribute ();
3699 type_attribute (BINFO_TYPE (binfo), 0, 0);
3700 data_member_location_attribute (binfo);
3701 if (TREE_VIA_VIRTUAL (binfo))
3703 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
3704 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3706 if (TREE_VIA_PUBLIC (binfo))
3708 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public);
3709 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3711 else if (TREE_VIA_PROTECTED (binfo))
3713 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected);
3714 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
3718 static void
3719 output_structure_type_die (arg)
3720 register void *arg;
3722 register tree type = arg;
3724 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3725 sibling_attribute ();
3726 equate_type_number_to_die_number (type);
3727 name_attribute (type_tag (type));
3728 member_attribute (TYPE_CONTEXT (type));
3730 /* If this type has been completed, then give it a byte_size attribute
3731 and prepare to give a list of members. Otherwise, don't do either of
3732 these things. In the latter case, we will not be generating a list
3733 of members (since we don't have any idea what they might be for an
3734 incomplete type). */
3736 if (COMPLETE_TYPE_P (type))
3738 dienum_push ();
3739 byte_size_attribute (type);
3743 /* Output a DIE to represent a declared function (either file-scope
3744 or block-local) which has "internal linkage" (according to ANSI-C). */
3746 static void
3747 output_local_subroutine_die (arg)
3748 register void *arg;
3750 register tree decl = arg;
3751 register tree origin = decl_ultimate_origin (decl);
3753 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3754 sibling_attribute ();
3755 dienum_push ();
3756 if (origin != NULL)
3757 abstract_origin_attribute (origin);
3758 else
3760 register tree type = TREE_TYPE (decl);
3762 name_and_src_coords_attributes (decl);
3763 inline_attribute (decl);
3764 prototyped_attribute (type);
3765 member_attribute (DECL_CONTEXT (decl));
3766 type_attribute (TREE_TYPE (type), 0, 0);
3767 pure_or_virtual_attribute (decl);
3769 if (DECL_ABSTRACT (decl))
3770 equate_decl_number_to_die_number (decl);
3771 else
3773 /* Avoid getting screwed up in cases where a function was declared
3774 static but where no definition was ever given for it. */
3776 if (TREE_ASM_WRITTEN (decl))
3778 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3779 low_pc_attribute (function_start_label (decl));
3780 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3781 high_pc_attribute (label);
3782 if (use_gnu_debug_info_extensions)
3784 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
3785 body_begin_attribute (label);
3786 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
3787 body_end_attribute (label);
3793 static void
3794 output_subroutine_type_die (arg)
3795 register void *arg;
3797 register tree type = arg;
3798 register tree return_type = TREE_TYPE (type);
3800 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3801 sibling_attribute ();
3802 dienum_push ();
3803 equate_type_number_to_die_number (type);
3804 prototyped_attribute (type);
3805 member_attribute (TYPE_CONTEXT (type));
3806 type_attribute (return_type, 0, 0);
3809 static void
3810 output_typedef_die (arg)
3811 register void *arg;
3813 register tree decl = arg;
3814 register tree origin = decl_ultimate_origin (decl);
3816 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3817 sibling_attribute ();
3818 if (origin != NULL)
3819 abstract_origin_attribute (origin);
3820 else
3822 name_and_src_coords_attributes (decl);
3823 member_attribute (DECL_CONTEXT (decl));
3824 type_attribute (TREE_TYPE (decl),
3825 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3827 if (DECL_ABSTRACT (decl))
3828 equate_decl_number_to_die_number (decl);
3831 static void
3832 output_union_type_die (arg)
3833 register void *arg;
3835 register tree type = arg;
3837 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3838 sibling_attribute ();
3839 equate_type_number_to_die_number (type);
3840 name_attribute (type_tag (type));
3841 member_attribute (TYPE_CONTEXT (type));
3843 /* If this type has been completed, then give it a byte_size attribute
3844 and prepare to give a list of members. Otherwise, don't do either of
3845 these things. In the latter case, we will not be generating a list
3846 of members (since we don't have any idea what they might be for an
3847 incomplete type). */
3849 if (COMPLETE_TYPE_P (type))
3851 dienum_push ();
3852 byte_size_attribute (type);
3856 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3857 at the end of an (ANSI prototyped) formal parameters list. */
3859 static void
3860 output_unspecified_parameters_die (arg)
3861 register void *arg;
3863 register tree decl_or_type = arg;
3865 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3866 sibling_attribute ();
3868 /* This kludge is here only for the sake of being compatible with what
3869 the USL CI5 C compiler does. The specification of Dwarf Version 1
3870 doesn't say that TAG_unspecified_parameters DIEs should contain any
3871 attributes other than the AT_sibling attribute, but they are certainly
3872 allowed to contain additional attributes, and the CI5 compiler
3873 generates AT_name, AT_fund_type, and AT_location attributes within
3874 TAG_unspecified_parameters DIEs which appear in the child lists for
3875 DIEs representing function definitions, so we do likewise here. */
3877 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3879 name_attribute ("...");
3880 fund_type_attribute (FT_pointer);
3881 /* location_attribute (?); */
3885 static void
3886 output_padded_null_die (arg)
3887 register void *arg ATTRIBUTE_UNUSED;
3889 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3892 /*************************** end of DIEs *********************************/
3894 /* Generate some type of DIE. This routine generates the generic outer
3895 wrapper stuff which goes around all types of DIE's (regardless of their
3896 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3897 DIE-length word, followed by the guts of the DIE itself. After the guts
3898 of the DIE, there must always be a terminator label for the DIE. */
3900 static void
3901 output_die (die_specific_output_function, param)
3902 register void (*die_specific_output_function) PARAMS ((void *));
3903 register void *param;
3905 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3906 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3908 current_dienum = NEXT_DIE_NUM;
3909 NEXT_DIE_NUM = next_unused_dienum;
3911 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3912 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3914 /* Write a label which will act as the name for the start of this DIE. */
3916 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3918 /* Write the DIE-length word. */
3920 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3922 /* Fill in the guts of the DIE. */
3924 next_unused_dienum++;
3925 die_specific_output_function (param);
3927 /* Write a label which will act as the name for the end of this DIE. */
3929 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3932 static void
3933 end_sibling_chain ()
3935 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3937 current_dienum = NEXT_DIE_NUM;
3938 NEXT_DIE_NUM = next_unused_dienum;
3940 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3942 /* Write a label which will act as the name for the start of this DIE. */
3944 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3946 /* Write the DIE-length word. */
3948 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3950 dienum_pop ();
3953 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3954 TAG_unspecified_parameters DIE) to represent the types of the formal
3955 parameters as specified in some function type specification (except
3956 for those which appear as part of a function *definition*).
3958 Note that we must be careful here to output all of the parameter
3959 DIEs *before* we output any DIEs needed to represent the types of
3960 the formal parameters. This keeps svr4 SDB happy because it
3961 (incorrectly) thinks that the first non-parameter DIE it sees ends
3962 the formal parameter list. */
3964 static void
3965 output_formal_types (function_or_method_type)
3966 register tree function_or_method_type;
3968 register tree link;
3969 register tree formal_type = NULL;
3970 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3972 /* Set TREE_ASM_WRITTEN while processing the parameters, lest we
3973 get bogus recursion when outputting tagged types local to a
3974 function declaration. */
3975 int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type);
3976 TREE_ASM_WRITTEN (function_or_method_type) = 1;
3978 /* In the case where we are generating a formal types list for a C++
3979 non-static member function type, skip over the first thing on the
3980 TYPE_ARG_TYPES list because it only represents the type of the
3981 hidden `this pointer'. The debugger should be able to figure
3982 out (without being explicitly told) that this non-static member
3983 function type takes a `this pointer' and should be able to figure
3984 what the type of that hidden parameter is from the AT_member
3985 attribute of the parent TAG_subroutine_type DIE. */
3987 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3988 first_parm_type = TREE_CHAIN (first_parm_type);
3990 /* Make our first pass over the list of formal parameter types and output
3991 a TAG_formal_parameter DIE for each one. */
3993 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3995 formal_type = TREE_VALUE (link);
3996 if (formal_type == void_type_node)
3997 break;
3999 /* Output a (nameless) DIE to represent the formal parameter itself. */
4001 output_die (output_formal_parameter_die, formal_type);
4004 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
4005 DIE to the end of the parameter list. */
4007 if (formal_type != void_type_node)
4008 output_die (output_unspecified_parameters_die, function_or_method_type);
4010 /* Make our second (and final) pass over the list of formal parameter types
4011 and output DIEs to represent those types (as necessary). */
4013 for (link = TYPE_ARG_TYPES (function_or_method_type);
4014 link;
4015 link = TREE_CHAIN (link))
4017 formal_type = TREE_VALUE (link);
4018 if (formal_type == void_type_node)
4019 break;
4021 output_type (formal_type, function_or_method_type);
4024 TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written;
4027 /* Remember a type in the pending_types_list. */
4029 static void
4030 pend_type (type)
4031 register tree type;
4033 if (pending_types == pending_types_allocated)
4035 pending_types_allocated += PENDING_TYPES_INCREMENT;
4036 pending_types_list
4037 = (tree *) xrealloc (pending_types_list,
4038 sizeof (tree) * pending_types_allocated);
4040 pending_types_list[pending_types++] = type;
4042 /* Mark the pending type as having been output already (even though
4043 it hasn't been). This prevents the type from being added to the
4044 pending_types_list more than once. */
4046 TREE_ASM_WRITTEN (type) = 1;
4049 /* Return non-zero if it is legitimate to output DIEs to represent a
4050 given type while we are generating the list of child DIEs for some
4051 DIE (e.g. a function or lexical block DIE) associated with a given scope.
4053 See the comments within the function for a description of when it is
4054 considered legitimate to output DIEs for various kinds of types.
4056 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
4057 or it may point to a BLOCK node (for types local to a block), or to a
4058 FUNCTION_DECL node (for types local to the heading of some function
4059 definition), or to a FUNCTION_TYPE node (for types local to the
4060 prototyped parameter list of a function type specification), or to a
4061 RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
4062 (in the case of C++ nested types).
4064 The `scope' parameter should likewise be NULL or should point to a
4065 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
4066 node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
4068 This function is used only for deciding when to "pend" and when to
4069 "un-pend" types to/from the pending_types_list.
4071 Note that we sometimes make use of this "type pending" feature in a
4072 rather twisted way to temporarily delay the production of DIEs for the
4073 types of formal parameters. (We do this just to make svr4 SDB happy.)
4074 It order to delay the production of DIEs representing types of formal
4075 parameters, callers of this function supply `fake_containing_scope' as
4076 the `scope' parameter to this function. Given that fake_containing_scope
4077 is a tagged type which is *not* the containing scope for *any* other type,
4078 the desired effect is achieved, i.e. output of DIEs representing types
4079 is temporarily suspended, and any type DIEs which would have otherwise
4080 been output are instead placed onto the pending_types_list. Later on,
4081 we force these (temporarily pended) types to be output simply by calling
4082 `output_pending_types_for_scope' with an actual argument equal to the
4083 true scope of the types we temporarily pended. */
4085 static inline int
4086 type_ok_for_scope (type, scope)
4087 register tree type;
4088 register tree scope;
4090 /* Tagged types (i.e. struct, union, and enum types) must always be
4091 output only in the scopes where they actually belong (or else the
4092 scoping of their own tag names and the scoping of their member
4093 names will be incorrect). Non-tagged-types on the other hand can
4094 generally be output anywhere, except that svr4 SDB really doesn't
4095 want to see them nested within struct or union types, so here we
4096 say it is always OK to immediately output any such a (non-tagged)
4097 type, so long as we are not within such a context. Note that the
4098 only kinds of non-tagged types which we will be dealing with here
4099 (for C and C++ anyway) will be array types and function types. */
4101 return is_tagged_type (type)
4102 ? (TYPE_CONTEXT (type) == scope
4103 /* Ignore namespaces for the moment. */
4104 || (scope == NULL_TREE
4105 && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4106 || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type))
4107 && TREE_ASM_WRITTEN (TYPE_CONTEXT (type))))
4108 : (scope == NULL_TREE || ! is_tagged_type (scope));
4111 /* Output any pending types (from the pending_types list) which we can output
4112 now (taking into account the scope that we are working on now).
4114 For each type output, remove the given type from the pending_types_list
4115 *before* we try to output it.
4117 Note that we have to process the list in beginning-to-end order,
4118 because the call made here to output_type may cause yet more types
4119 to be added to the end of the list, and we may have to output some
4120 of them too. */
4122 static void
4123 output_pending_types_for_scope (containing_scope)
4124 register tree containing_scope;
4126 register unsigned i;
4128 for (i = 0; i < pending_types; )
4130 register tree type = pending_types_list[i];
4132 if (type_ok_for_scope (type, containing_scope))
4134 register tree *mover;
4135 register tree *limit;
4137 pending_types--;
4138 limit = &pending_types_list[pending_types];
4139 for (mover = &pending_types_list[i]; mover < limit; mover++)
4140 *mover = *(mover+1);
4142 /* Un-mark the type as having been output already (because it
4143 hasn't been, really). Then call output_type to generate a
4144 Dwarf representation of it. */
4146 TREE_ASM_WRITTEN (type) = 0;
4147 output_type (type, containing_scope);
4149 /* Don't increment the loop counter in this case because we
4150 have shifted all of the subsequent pending types down one
4151 element in the pending_types_list array. */
4153 else
4154 i++;
4158 /* Remember a type in the incomplete_types_list. */
4160 static void
4161 add_incomplete_type (type)
4162 tree type;
4164 if (incomplete_types == incomplete_types_allocated)
4166 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
4167 incomplete_types_list
4168 = (tree *) xrealloc (incomplete_types_list,
4169 sizeof (tree) * incomplete_types_allocated);
4172 incomplete_types_list[incomplete_types++] = type;
4175 /* Walk through the list of incomplete types again, trying once more to
4176 emit full debugging info for them. */
4178 static void
4179 retry_incomplete_types ()
4181 register tree type;
4183 finalizing = 1;
4184 while (incomplete_types)
4186 --incomplete_types;
4187 type = incomplete_types_list[incomplete_types];
4188 output_type (type, NULL_TREE);
4192 static void
4193 output_type (type, containing_scope)
4194 register tree type;
4195 register tree containing_scope;
4197 if (type == 0 || type == error_mark_node)
4198 return;
4200 /* We are going to output a DIE to represent the unqualified version of
4201 this type (i.e. without any const or volatile qualifiers) so get
4202 the main variant (i.e. the unqualified version) of this type now. */
4204 type = type_main_variant (type);
4206 if (TREE_ASM_WRITTEN (type))
4208 if (finalizing && AGGREGATE_TYPE_P (type))
4210 register tree member;
4212 /* Some of our nested types might not have been defined when we
4213 were written out before; force them out now. */
4215 for (member = TYPE_FIELDS (type); member;
4216 member = TREE_CHAIN (member))
4217 if (TREE_CODE (member) == TYPE_DECL
4218 && ! TREE_ASM_WRITTEN (TREE_TYPE (member)))
4219 output_type (TREE_TYPE (member), containing_scope);
4221 return;
4224 /* If this is a nested type whose containing class hasn't been
4225 written out yet, writing it out will cover this one, too. */
4227 if (TYPE_CONTEXT (type)
4228 && TYPE_P (TYPE_CONTEXT (type))
4229 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
4231 output_type (TYPE_CONTEXT (type), containing_scope);
4232 return;
4235 /* Don't generate any DIEs for this type now unless it is OK to do so
4236 (based upon what `type_ok_for_scope' tells us). */
4238 if (! type_ok_for_scope (type, containing_scope))
4240 pend_type (type);
4241 return;
4244 switch (TREE_CODE (type))
4246 case ERROR_MARK:
4247 break;
4249 case VECTOR_TYPE:
4250 output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope);
4251 break;
4253 case POINTER_TYPE:
4254 case REFERENCE_TYPE:
4255 /* Prevent infinite recursion in cases where this is a recursive
4256 type. Recursive types are possible in Ada. */
4257 TREE_ASM_WRITTEN (type) = 1;
4258 /* For these types, all that is required is that we output a DIE
4259 (or a set of DIEs) to represent the "basis" type. */
4260 output_type (TREE_TYPE (type), containing_scope);
4261 break;
4263 case OFFSET_TYPE:
4264 /* This code is used for C++ pointer-to-data-member types. */
4265 /* Output a description of the relevant class type. */
4266 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
4267 /* Output a description of the type of the object pointed to. */
4268 output_type (TREE_TYPE (type), containing_scope);
4269 /* Now output a DIE to represent this pointer-to-data-member type
4270 itself. */
4271 output_die (output_ptr_to_mbr_type_die, type);
4272 break;
4274 case SET_TYPE:
4275 output_type (TYPE_DOMAIN (type), containing_scope);
4276 output_die (output_set_type_die, type);
4277 break;
4279 case FILE_TYPE:
4280 output_type (TREE_TYPE (type), containing_scope);
4281 abort (); /* No way to represent these in Dwarf yet! */
4282 break;
4284 case FUNCTION_TYPE:
4285 /* Force out return type (in case it wasn't forced out already). */
4286 output_type (TREE_TYPE (type), containing_scope);
4287 output_die (output_subroutine_type_die, type);
4288 output_formal_types (type);
4289 end_sibling_chain ();
4290 break;
4292 case METHOD_TYPE:
4293 /* Force out return type (in case it wasn't forced out already). */
4294 output_type (TREE_TYPE (type), containing_scope);
4295 output_die (output_subroutine_type_die, type);
4296 output_formal_types (type);
4297 end_sibling_chain ();
4298 break;
4300 case ARRAY_TYPE:
4301 if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
4303 output_type (TREE_TYPE (type), containing_scope);
4304 output_die (output_string_type_die, type);
4306 else
4308 register tree element_type;
4310 element_type = TREE_TYPE (type);
4311 while (TREE_CODE (element_type) == ARRAY_TYPE)
4312 element_type = TREE_TYPE (element_type);
4314 output_type (element_type, containing_scope);
4315 output_die (output_array_type_die, type);
4317 break;
4319 case ENUMERAL_TYPE:
4320 case RECORD_TYPE:
4321 case UNION_TYPE:
4322 case QUAL_UNION_TYPE:
4324 /* For a non-file-scope tagged type, we can always go ahead and
4325 output a Dwarf description of this type right now, even if
4326 the type in question is still incomplete, because if this
4327 local type *was* ever completed anywhere within its scope,
4328 that complete definition would already have been attached to
4329 this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
4330 node by the time we reach this point. That's true because of the
4331 way the front-end does its processing of file-scope declarations (of
4332 functions and class types) within which other types might be
4333 nested. The C and C++ front-ends always gobble up such "local
4334 scope" things en-mass before they try to output *any* debugging
4335 information for any of the stuff contained inside them and thus,
4336 we get the benefit here of what is (in effect) a pre-resolution
4337 of forward references to tagged types in local scopes.
4339 Note however that for file-scope tagged types we cannot assume
4340 that such pre-resolution of forward references has taken place.
4341 A given file-scope tagged type may appear to be incomplete when
4342 we reach this point, but it may yet be given a full definition
4343 (at file-scope) later on during compilation. In order to avoid
4344 generating a premature (and possibly incorrect) set of Dwarf
4345 DIEs for such (as yet incomplete) file-scope tagged types, we
4346 generate nothing at all for as-yet incomplete file-scope tagged
4347 types here unless we are making our special "finalization" pass
4348 for file-scope things at the very end of compilation. At that
4349 time, we will certainly know as much about each file-scope tagged
4350 type as we are ever going to know, so at that point in time, we
4351 can safely generate correct Dwarf descriptions for these file-
4352 scope tagged types. */
4354 if (!COMPLETE_TYPE_P (type)
4355 && (TYPE_CONTEXT (type) == NULL
4356 || AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
4357 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)
4358 && !finalizing)
4360 /* We don't need to do this for function-local types. */
4361 if (! decl_function_context (TYPE_STUB_DECL (type)))
4362 add_incomplete_type (type);
4363 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
4366 /* Prevent infinite recursion in cases where the type of some
4367 member of this type is expressed in terms of this type itself. */
4369 TREE_ASM_WRITTEN (type) = 1;
4371 /* Output a DIE to represent the tagged type itself. */
4373 switch (TREE_CODE (type))
4375 case ENUMERAL_TYPE:
4376 output_die (output_enumeration_type_die, type);
4377 return; /* a special case -- nothing left to do so just return */
4379 case RECORD_TYPE:
4380 output_die (output_structure_type_die, type);
4381 break;
4383 case UNION_TYPE:
4384 case QUAL_UNION_TYPE:
4385 output_die (output_union_type_die, type);
4386 break;
4388 default:
4389 abort (); /* Should never happen. */
4392 /* If this is not an incomplete type, output descriptions of
4393 each of its members.
4395 Note that as we output the DIEs necessary to represent the
4396 members of this record or union type, we will also be trying
4397 to output DIEs to represent the *types* of those members.
4398 However the `output_type' function (above) will specifically
4399 avoid generating type DIEs for member types *within* the list
4400 of member DIEs for this (containing) type execpt for those
4401 types (of members) which are explicitly marked as also being
4402 members of this (containing) type themselves. The g++ front-
4403 end can force any given type to be treated as a member of some
4404 other (containing) type by setting the TYPE_CONTEXT of the
4405 given (member) type to point to the TREE node representing the
4406 appropriate (containing) type.
4409 if (COMPLETE_TYPE_P (type))
4411 /* First output info about the base classes. */
4412 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
4414 register tree bases = TYPE_BINFO_BASETYPES (type);
4415 register int n_bases = TREE_VEC_LENGTH (bases);
4416 register int i;
4418 for (i = 0; i < n_bases; i++)
4420 tree binfo = TREE_VEC_ELT (bases, i);
4421 output_type (BINFO_TYPE (binfo), containing_scope);
4422 output_die (output_inheritance_die, binfo);
4426 ++in_class;
4429 register tree normal_member;
4431 /* Now output info about the data members and type members. */
4433 for (normal_member = TYPE_FIELDS (type);
4434 normal_member;
4435 normal_member = TREE_CHAIN (normal_member))
4436 output_decl (normal_member, type);
4440 register tree func_member;
4442 /* Now output info about the function members (if any). */
4444 for (func_member = TYPE_METHODS (type);
4445 func_member;
4446 func_member = TREE_CHAIN (func_member))
4448 /* Don't include clones in the member list. */
4449 if (DECL_ABSTRACT_ORIGIN (func_member))
4450 continue;
4452 output_decl (func_member, type);
4456 --in_class;
4458 /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
4459 scopes (at least in C++) so we must now output any nested
4460 pending types which are local just to this type. */
4462 output_pending_types_for_scope (type);
4464 end_sibling_chain (); /* Terminate member chain. */
4467 break;
4469 case VOID_TYPE:
4470 case INTEGER_TYPE:
4471 case REAL_TYPE:
4472 case COMPLEX_TYPE:
4473 case BOOLEAN_TYPE:
4474 case CHAR_TYPE:
4475 break; /* No DIEs needed for fundamental types. */
4477 case LANG_TYPE: /* No Dwarf representation currently defined. */
4478 break;
4480 default:
4481 abort ();
4484 TREE_ASM_WRITTEN (type) = 1;
4487 static void
4488 output_tagged_type_instantiation (type)
4489 register tree type;
4491 if (type == 0 || type == error_mark_node)
4492 return;
4494 /* We are going to output a DIE to represent the unqualified version of
4495 this type (i.e. without any const or volatile qualifiers) so make
4496 sure that we have the main variant (i.e. the unqualified version) of
4497 this type now. */
4499 if (type != type_main_variant (type))
4500 abort ();
4502 if (!TREE_ASM_WRITTEN (type))
4503 abort ();
4505 switch (TREE_CODE (type))
4507 case ERROR_MARK:
4508 break;
4510 case ENUMERAL_TYPE:
4511 output_die (output_inlined_enumeration_type_die, type);
4512 break;
4514 case RECORD_TYPE:
4515 output_die (output_inlined_structure_type_die, type);
4516 break;
4518 case UNION_TYPE:
4519 case QUAL_UNION_TYPE:
4520 output_die (output_inlined_union_type_die, type);
4521 break;
4523 default:
4524 abort (); /* Should never happen. */
4528 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4529 the things which are local to the given block. */
4531 static void
4532 output_block (stmt, depth)
4533 register tree stmt;
4534 int depth;
4536 register int must_output_die = 0;
4537 register tree origin;
4538 register enum tree_code origin_code;
4540 /* Ignore blocks never really used to make RTL. */
4542 if (! stmt || ! TREE_USED (stmt)
4543 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
4544 return;
4546 /* Determine the "ultimate origin" of this block. This block may be an
4547 inlined instance of an inlined instance of inline function, so we
4548 have to trace all of the way back through the origin chain to find
4549 out what sort of node actually served as the original seed for the
4550 creation of the current block. */
4552 origin = block_ultimate_origin (stmt);
4553 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4555 /* Determine if we need to output any Dwarf DIEs at all to represent this
4556 block. */
4558 if (origin_code == FUNCTION_DECL)
4559 /* The outer scopes for inlinings *must* always be represented. We
4560 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4561 must_output_die = 1;
4562 else
4564 /* In the case where the current block represents an inlining of the
4565 "body block" of an inline function, we must *NOT* output any DIE
4566 for this block because we have already output a DIE to represent
4567 the whole inlined function scope and the "body block" of any
4568 function doesn't really represent a different scope according to
4569 ANSI C rules. So we check here to make sure that this block does
4570 not represent a "body block inlining" before trying to set the
4571 `must_output_die' flag. */
4573 if (! is_body_block (origin ? origin : stmt))
4575 /* Determine if this block directly contains any "significant"
4576 local declarations which we will need to output DIEs for. */
4578 if (debug_info_level > DINFO_LEVEL_TERSE)
4579 /* We are not in terse mode so *any* local declaration counts
4580 as being a "significant" one. */
4581 must_output_die = (BLOCK_VARS (stmt) != NULL);
4582 else
4584 register tree decl;
4586 /* We are in terse mode, so only local (nested) function
4587 definitions count as "significant" local declarations. */
4589 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4590 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4592 must_output_die = 1;
4593 break;
4599 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4600 DIE for any block which contains no significant local declarations
4601 at all. Rather, in such cases we just call `output_decls_for_scope'
4602 so that any needed Dwarf info for any sub-blocks will get properly
4603 generated. Note that in terse mode, our definition of what constitutes
4604 a "significant" local declaration gets restricted to include only
4605 inlined function instances and local (nested) function definitions. */
4607 if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt))
4608 /* We don't care about an abstract inlined subroutine. */;
4609 else if (must_output_die)
4611 output_die ((origin_code == FUNCTION_DECL)
4612 ? output_inlined_subroutine_die
4613 : output_lexical_block_die,
4614 stmt);
4615 output_decls_for_scope (stmt, depth);
4616 end_sibling_chain ();
4618 else
4619 output_decls_for_scope (stmt, depth);
4622 /* Output all of the decls declared within a given scope (also called
4623 a `binding contour') and (recursively) all of it's sub-blocks. */
4625 static void
4626 output_decls_for_scope (stmt, depth)
4627 register tree stmt;
4628 int depth;
4630 /* Ignore blocks never really used to make RTL. */
4632 if (! stmt || ! TREE_USED (stmt))
4633 return;
4635 /* Output the DIEs to represent all of the data objects, functions,
4636 typedefs, and tagged types declared directly within this block
4637 but not within any nested sub-blocks. */
4640 register tree decl;
4642 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4643 output_decl (decl, stmt);
4646 output_pending_types_for_scope (stmt);
4648 /* Output the DIEs to represent all sub-blocks (and the items declared
4649 therein) of this block. */
4652 register tree subblocks;
4654 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4655 subblocks;
4656 subblocks = BLOCK_CHAIN (subblocks))
4657 output_block (subblocks, depth + 1);
4661 /* Is this a typedef we can avoid emitting? */
4663 inline static int
4664 is_redundant_typedef (decl)
4665 register tree decl;
4667 if (TYPE_DECL_IS_STUB (decl))
4668 return 1;
4669 if (DECL_ARTIFICIAL (decl)
4670 && DECL_CONTEXT (decl)
4671 && is_tagged_type (DECL_CONTEXT (decl))
4672 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
4673 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
4674 /* Also ignore the artificial member typedef for the class name. */
4675 return 1;
4676 return 0;
4679 /* Output Dwarf .debug information for a decl described by DECL. */
4681 static void
4682 output_decl (decl, containing_scope)
4683 register tree decl;
4684 register tree containing_scope;
4686 /* Make a note of the decl node we are going to be working on. We may
4687 need to give the user the source coordinates of where it appeared in
4688 case we notice (later on) that something about it looks screwy. */
4690 dwarf_last_decl = decl;
4692 if (TREE_CODE (decl) == ERROR_MARK)
4693 return;
4695 /* If a structure is declared within an initialization, e.g. as the
4696 operand of a sizeof, then it will not have a name. We don't want
4697 to output a DIE for it, as the tree nodes are in the temporary obstack */
4699 if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4700 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
4701 && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0)
4702 || (TYPE_FIELDS (TREE_TYPE (decl))
4703 && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK))))
4704 return;
4706 /* If this ..._DECL node is marked to be ignored, then ignore it. */
4708 if (DECL_IGNORED_P (decl))
4709 return;
4711 switch (TREE_CODE (decl))
4713 case CONST_DECL:
4714 /* The individual enumerators of an enum type get output when we
4715 output the Dwarf representation of the relevant enum type itself. */
4716 break;
4718 case FUNCTION_DECL:
4719 /* If we are in terse mode, don't output any DIEs to represent
4720 mere function declarations. Also, if we are conforming
4721 to the DWARF version 1 specification, don't output DIEs for
4722 mere function declarations. */
4724 if (DECL_INITIAL (decl) == NULL_TREE)
4725 #if (DWARF_VERSION > 1)
4726 if (debug_info_level <= DINFO_LEVEL_TERSE)
4727 #endif
4728 break;
4730 /* Before we describe the FUNCTION_DECL itself, make sure that we
4731 have described its return type. */
4733 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4736 /* And its containing type. */
4737 register tree origin = decl_class_context (decl);
4738 if (origin)
4739 output_type (origin, containing_scope);
4742 /* If we're emitting an out-of-line copy of an inline function,
4743 set up to refer to the abstract instance emitted from
4744 note_deferral_of_defined_inline_function. */
4745 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
4746 && ! (containing_scope && TYPE_P (containing_scope)))
4747 set_decl_origin_self (decl);
4749 /* If the following DIE will represent a function definition for a
4750 function with "extern" linkage, output a special "pubnames" DIE
4751 label just ahead of the actual DIE. A reference to this label
4752 was already generated in the .debug_pubnames section sub-entry
4753 for this function definition. */
4755 if (TREE_PUBLIC (decl))
4757 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4759 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4760 ASM_OUTPUT_LABEL (asm_out_file, label);
4763 /* Now output a DIE to represent the function itself. */
4765 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4766 ? output_global_subroutine_die
4767 : output_local_subroutine_die,
4768 decl);
4770 /* Now output descriptions of the arguments for this function.
4771 This gets (unnecessarily?) complex because of the fact that
4772 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4773 cases where there was a trailing `...' at the end of the formal
4774 parameter list. In order to find out if there was a trailing
4775 ellipsis or not, we must instead look at the type associated
4776 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4777 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4778 ends with a void_type_node then there should *not* be an ellipsis
4779 at the end. */
4781 /* In the case where we are describing a mere function declaration, all
4782 we need to do here (and all we *can* do here) is to describe
4783 the *types* of its formal parameters. */
4785 if (decl != current_function_decl || in_class)
4786 output_formal_types (TREE_TYPE (decl));
4787 else
4789 /* Generate DIEs to represent all known formal parameters */
4791 register tree arg_decls = DECL_ARGUMENTS (decl);
4792 register tree parm;
4794 /* WARNING! Kludge zone ahead! Here we have a special
4795 hack for svr4 SDB compatibility. Instead of passing the
4796 current FUNCTION_DECL node as the second parameter (i.e.
4797 the `containing_scope' parameter) to `output_decl' (as
4798 we ought to) we instead pass a pointer to our own private
4799 fake_containing_scope node. That node is a RECORD_TYPE
4800 node which NO OTHER TYPE may ever actually be a member of.
4802 This pointer will ultimately get passed into `output_type'
4803 as its `containing_scope' parameter. `Output_type' will
4804 then perform its part in the hack... i.e. it will pend
4805 the type of the formal parameter onto the pending_types
4806 list. Later on, when we are done generating the whole
4807 sequence of formal parameter DIEs for this function
4808 definition, we will un-pend all previously pended types
4809 of formal parameters for this function definition.
4811 This whole kludge prevents any type DIEs from being
4812 mixed in with the formal parameter DIEs. That's good
4813 because svr4 SDB believes that the list of formal
4814 parameter DIEs for a function ends wherever the first
4815 non-formal-parameter DIE appears. Thus, we have to
4816 keep the formal parameter DIEs segregated. They must
4817 all appear (consecutively) at the start of the list of
4818 children for the DIE representing the function definition.
4819 Then (and only then) may we output any additional DIEs
4820 needed to represent the types of these formal parameters.
4824 When generating DIEs, generate the unspecified_parameters
4825 DIE instead if we come across the arg "__builtin_va_alist"
4828 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4829 if (TREE_CODE (parm) == PARM_DECL)
4831 if (DECL_NAME(parm) &&
4832 !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
4833 "__builtin_va_alist") )
4834 output_die (output_unspecified_parameters_die, decl);
4835 else
4836 output_decl (parm, fake_containing_scope);
4840 Now that we have finished generating all of the DIEs to
4841 represent the formal parameters themselves, force out
4842 any DIEs needed to represent their types. We do this
4843 simply by un-pending all previously pended types which
4844 can legitimately go into the chain of children DIEs for
4845 the current FUNCTION_DECL.
4848 output_pending_types_for_scope (decl);
4851 Decide whether we need a unspecified_parameters DIE at the end.
4852 There are 2 more cases to do this for:
4853 1) the ansi ... declaration - this is detectable when the end
4854 of the arg list is not a void_type_node
4855 2) an unprototyped function declaration (not a definition). This
4856 just means that we have no info about the parameters at all.
4860 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4862 if (fn_arg_types)
4864 /* this is the prototyped case, check for ... */
4865 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
4866 output_die (output_unspecified_parameters_die, decl);
4868 else
4870 /* this is unprototyped, check for undefined (just declaration) */
4871 if (!DECL_INITIAL (decl))
4872 output_die (output_unspecified_parameters_die, decl);
4876 /* Output Dwarf info for all of the stuff within the body of the
4877 function (if it has one - it may be just a declaration). */
4880 register tree outer_scope = DECL_INITIAL (decl);
4882 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4884 /* Note that here, `outer_scope' is a pointer to the outermost
4885 BLOCK node created to represent a function.
4886 This outermost BLOCK actually represents the outermost
4887 binding contour for the function, i.e. the contour in which
4888 the function's formal parameters and labels get declared.
4890 Curiously, it appears that the front end doesn't actually
4891 put the PARM_DECL nodes for the current function onto the
4892 BLOCK_VARS list for this outer scope. (They are strung
4893 off of the DECL_ARGUMENTS list for the function instead.)
4894 The BLOCK_VARS list for the `outer_scope' does provide us
4895 with a list of the LABEL_DECL nodes for the function however,
4896 and we output DWARF info for those here.
4898 Just within the `outer_scope' there will be a BLOCK node
4899 representing the function's outermost pair of curly braces,
4900 and any blocks used for the base and member initializers of
4901 a C++ constructor function. */
4903 output_decls_for_scope (outer_scope, 0);
4905 /* Finally, force out any pending types which are local to the
4906 outermost block of this function definition. These will
4907 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4908 node itself. */
4910 output_pending_types_for_scope (decl);
4915 /* Generate a terminator for the list of stuff `owned' by this
4916 function. */
4918 end_sibling_chain ();
4920 break;
4922 case TYPE_DECL:
4923 /* If we are in terse mode, don't generate any DIEs to represent
4924 any actual typedefs. Note that even when we are in terse mode,
4925 we must still output DIEs to represent those tagged types which
4926 are used (directly or indirectly) in the specification of either
4927 a return type or a formal parameter type of some function. */
4929 if (debug_info_level <= DINFO_LEVEL_TERSE)
4930 if (! TYPE_DECL_IS_STUB (decl)
4931 || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class))
4932 return;
4934 /* In the special case of a TYPE_DECL node representing
4935 the declaration of some type tag, if the given TYPE_DECL is
4936 marked as having been instantiated from some other (original)
4937 TYPE_DECL node (e.g. one which was generated within the original
4938 definition of an inline function) we have to generate a special
4939 (abbreviated) TAG_structure_type, TAG_union_type, or
4940 TAG_enumeration-type DIE here. */
4942 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
4944 output_tagged_type_instantiation (TREE_TYPE (decl));
4945 return;
4948 output_type (TREE_TYPE (decl), containing_scope);
4950 if (! is_redundant_typedef (decl))
4951 /* Output a DIE to represent the typedef itself. */
4952 output_die (output_typedef_die, decl);
4953 break;
4955 case LABEL_DECL:
4956 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4957 output_die (output_label_die, decl);
4958 break;
4960 case VAR_DECL:
4961 /* If we are conforming to the DWARF version 1 specification, don't
4962 generated any DIEs to represent mere external object declarations. */
4964 #if (DWARF_VERSION <= 1)
4965 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4966 break;
4967 #endif
4969 /* If we are in terse mode, don't generate any DIEs to represent
4970 any variable declarations or definitions. */
4972 if (debug_info_level <= DINFO_LEVEL_TERSE)
4973 break;
4975 /* Output any DIEs that are needed to specify the type of this data
4976 object. */
4978 output_type (TREE_TYPE (decl), containing_scope);
4981 /* And its containing type. */
4982 register tree origin = decl_class_context (decl);
4983 if (origin)
4984 output_type (origin, containing_scope);
4987 /* If the following DIE will represent a data object definition for a
4988 data object with "extern" linkage, output a special "pubnames" DIE
4989 label just ahead of the actual DIE. A reference to this label
4990 was already generated in the .debug_pubnames section sub-entry
4991 for this data object definition. */
4993 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4995 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4997 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4998 ASM_OUTPUT_LABEL (asm_out_file, label);
5001 /* Now output the DIE to represent the data object itself. This gets
5002 complicated because of the possibility that the VAR_DECL really
5003 represents an inlined instance of a formal parameter for an inline
5004 function. */
5007 register void (*func) PARAMS ((void *));
5008 register tree origin = decl_ultimate_origin (decl);
5010 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
5011 func = output_formal_parameter_die;
5012 else
5014 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
5015 func = output_global_variable_die;
5016 else
5017 func = output_local_variable_die;
5019 output_die (func, decl);
5021 break;
5023 case FIELD_DECL:
5024 /* Ignore the nameless fields that are used to skip bits. */
5025 if (DECL_NAME (decl) != 0)
5027 output_type (member_declared_type (decl), containing_scope);
5028 output_die (output_member_die, decl);
5030 break;
5032 case PARM_DECL:
5033 /* Force out the type of this formal, if it was not forced out yet.
5034 Note that here we can run afowl of a bug in "classic" svr4 SDB.
5035 It should be able to grok the presence of type DIEs within a list
5036 of TAG_formal_parameter DIEs, but it doesn't. */
5038 output_type (TREE_TYPE (decl), containing_scope);
5039 output_die (output_formal_parameter_die, decl);
5040 break;
5042 case NAMESPACE_DECL:
5043 /* Ignore for now. */
5044 break;
5046 default:
5047 abort ();
5051 void
5052 dwarfout_file_scope_decl (decl, set_finalizing)
5053 register tree decl;
5054 register int set_finalizing;
5056 if (TREE_CODE (decl) == ERROR_MARK)
5057 return;
5059 /* If this ..._DECL node is marked to be ignored, then ignore it. */
5061 if (DECL_IGNORED_P (decl))
5062 return;
5064 switch (TREE_CODE (decl))
5066 case FUNCTION_DECL:
5068 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
5069 a builtin function. Explicit programmer-supplied declarations of
5070 these same functions should NOT be ignored however. */
5072 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
5073 return;
5075 /* What we would really like to do here is to filter out all mere
5076 file-scope declarations of file-scope functions which are never
5077 referenced later within this translation unit (and keep all of
5078 ones that *are* referenced later on) but we aren't clairvoyant,
5079 so we have no idea which functions will be referenced in the
5080 future (i.e. later on within the current translation unit).
5081 So here we just ignore all file-scope function declarations
5082 which are not also definitions. If and when the debugger needs
5083 to know something about these functions, it wil have to hunt
5084 around and find the DWARF information associated with the
5085 *definition* of the function.
5087 Note that we can't just check `DECL_EXTERNAL' to find out which
5088 FUNCTION_DECL nodes represent definitions and which ones represent
5089 mere declarations. We have to check `DECL_INITIAL' instead. That's
5090 because the C front-end supports some weird semantics for "extern
5091 inline" function definitions. These can get inlined within the
5092 current translation unit (an thus, we need to generate DWARF info
5093 for their abstract instances so that the DWARF info for the
5094 concrete inlined instances can have something to refer to) but
5095 the compiler never generates any out-of-lines instances of such
5096 things (despite the fact that they *are* definitions). The
5097 important point is that the C front-end marks these "extern inline"
5098 functions as DECL_EXTERNAL, but we need to generate DWARF for them
5099 anyway.
5101 Note that the C++ front-end also plays some similar games for inline
5102 function definitions appearing within include files which also
5103 contain `#pragma interface' pragmas. */
5105 if (DECL_INITIAL (decl) == NULL_TREE)
5106 return;
5108 if (TREE_PUBLIC (decl)
5109 && ! DECL_EXTERNAL (decl)
5110 && ! DECL_ABSTRACT (decl))
5112 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5114 /* Output a .debug_pubnames entry for a public function
5115 defined in this compilation unit. */
5117 fputc ('\n', asm_out_file);
5118 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5119 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5120 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5121 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5122 IDENTIFIER_POINTER (DECL_NAME (decl)));
5123 ASM_OUTPUT_POP_SECTION (asm_out_file);
5126 break;
5128 case VAR_DECL:
5130 /* Ignore this VAR_DECL if it refers to a file-scope extern data
5131 object declaration and if the declaration was never even
5132 referenced from within this entire compilation unit. We
5133 suppress these DIEs in order to save space in the .debug section
5134 (by eliminating entries which are probably useless). Note that
5135 we must not suppress block-local extern declarations (whether
5136 used or not) because that would screw-up the debugger's name
5137 lookup mechanism and cause it to miss things which really ought
5138 to be in scope at a given point. */
5140 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
5141 return;
5143 if (TREE_PUBLIC (decl)
5144 && ! DECL_EXTERNAL (decl)
5145 && GET_CODE (DECL_RTL (decl)) == MEM
5146 && ! DECL_ABSTRACT (decl))
5148 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5150 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5152 /* Output a .debug_pubnames entry for a public variable
5153 defined in this compilation unit. */
5155 fputc ('\n', asm_out_file);
5156 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5157 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
5158 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
5159 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5160 IDENTIFIER_POINTER (DECL_NAME (decl)));
5161 ASM_OUTPUT_POP_SECTION (asm_out_file);
5164 if (DECL_INITIAL (decl) == NULL)
5166 /* Output a .debug_aranges entry for a public variable
5167 which is tentatively defined in this compilation unit. */
5169 fputc ('\n', asm_out_file);
5170 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5171 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
5172 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5173 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5174 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
5175 ASM_OUTPUT_POP_SECTION (asm_out_file);
5179 /* If we are in terse mode, don't generate any DIEs to represent
5180 any variable declarations or definitions. */
5182 if (debug_info_level <= DINFO_LEVEL_TERSE)
5183 return;
5185 break;
5187 case TYPE_DECL:
5188 /* Don't bother trying to generate any DIEs to represent any of the
5189 normal built-in types for the language we are compiling, except
5190 in cases where the types in question are *not* DWARF fundamental
5191 types. We make an exception in the case of non-fundamental types
5192 for the sake of objective C (and perhaps C++) because the GNU
5193 front-ends for these languages may in fact create certain "built-in"
5194 types which are (for example) RECORD_TYPEs. In such cases, we
5195 really need to output these (non-fundamental) types because other
5196 DIEs may contain references to them. */
5198 /* Also ignore language dependent types here, because they are probably
5199 also built-in types. If we didn't ignore them, then we would get
5200 references to undefined labels because output_type doesn't support
5201 them. So, for now, we need to ignore them to avoid assembler
5202 errors. */
5204 /* ??? This code is different than the equivalent code in dwarf2out.c.
5205 The dwarf2out.c code is probably more correct. */
5207 if (DECL_SOURCE_LINE (decl) == 0
5208 && (type_is_fundamental (TREE_TYPE (decl))
5209 || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE))
5210 return;
5212 /* If we are in terse mode, don't generate any DIEs to represent
5213 any actual typedefs. Note that even when we are in terse mode,
5214 we must still output DIEs to represent those tagged types which
5215 are used (directly or indirectly) in the specification of either
5216 a return type or a formal parameter type of some function. */
5218 if (debug_info_level <= DINFO_LEVEL_TERSE)
5219 if (! TYPE_DECL_IS_STUB (decl)
5220 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
5221 return;
5223 break;
5225 default:
5226 return;
5229 fputc ('\n', asm_out_file);
5230 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5231 finalizing = set_finalizing;
5232 output_decl (decl, NULL_TREE);
5234 /* NOTE: The call above to `output_decl' may have caused one or more
5235 file-scope named types (i.e. tagged types) to be placed onto the
5236 pending_types_list. We have to get those types off of that list
5237 at some point, and this is the perfect time to do it. If we didn't
5238 take them off now, they might still be on the list when cc1 finally
5239 exits. That might be OK if it weren't for the fact that when we put
5240 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
5241 for these types, and that causes them never to be output unless
5242 `output_pending_types_for_scope' takes them off of the list and un-sets
5243 their TREE_ASM_WRITTEN flags. */
5245 output_pending_types_for_scope (NULL_TREE);
5247 /* The above call should have totally emptied the pending_types_list
5248 if this is not a nested function or class. If this is a nested type,
5249 then the remaining pending_types will be emitted when the containing type
5250 is handled. */
5252 if (! DECL_CONTEXT (decl))
5254 if (pending_types != 0)
5255 abort ();
5258 ASM_OUTPUT_POP_SECTION (asm_out_file);
5260 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
5261 current_funcdef_number++;
5264 /* Output a marker (i.e. a label) for the beginning of the generated code
5265 for a lexical block. */
5267 void
5268 dwarfout_begin_block (blocknum)
5269 register unsigned blocknum;
5271 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5273 function_section (current_function_decl);
5274 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
5275 ASM_OUTPUT_LABEL (asm_out_file, label);
5278 /* Output a marker (i.e. a label) for the end of the generated code
5279 for a lexical block. */
5281 void
5282 dwarfout_end_block (blocknum)
5283 register unsigned blocknum;
5285 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5287 function_section (current_function_decl);
5288 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
5289 ASM_OUTPUT_LABEL (asm_out_file, label);
5292 /* Output a marker (i.e. a label) for the point in the generated code where
5293 the real body of the function begins (after parameters have been moved
5294 to their home locations). */
5296 void
5297 dwarfout_begin_function ()
5299 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5301 if (! use_gnu_debug_info_extensions)
5302 return;
5303 function_section (current_function_decl);
5304 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
5305 ASM_OUTPUT_LABEL (asm_out_file, label);
5308 /* Output a marker (i.e. a label) for the point in the generated code where
5309 the real body of the function ends (just before the epilogue code). */
5311 void
5312 dwarfout_end_function ()
5314 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5316 if (! use_gnu_debug_info_extensions)
5317 return;
5318 function_section (current_function_decl);
5319 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
5320 ASM_OUTPUT_LABEL (asm_out_file, label);
5323 /* Output a marker (i.e. a label) for the absolute end of the generated code
5324 for a function definition. This gets called *after* the epilogue code
5325 has been generated. */
5327 void
5328 dwarfout_end_epilogue ()
5330 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5332 /* Output a label to mark the endpoint of the code generated for this
5333 function. */
5335 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
5336 ASM_OUTPUT_LABEL (asm_out_file, label);
5339 static void
5340 shuffle_filename_entry (new_zeroth)
5341 register filename_entry *new_zeroth;
5343 filename_entry temp_entry;
5344 register filename_entry *limit_p;
5345 register filename_entry *move_p;
5347 if (new_zeroth == &filename_table[0])
5348 return;
5350 temp_entry = *new_zeroth;
5352 /* Shift entries up in the table to make room at [0]. */
5354 limit_p = &filename_table[0];
5355 for (move_p = new_zeroth; move_p > limit_p; move_p--)
5356 *move_p = *(move_p-1);
5358 /* Install the found entry at [0]. */
5360 filename_table[0] = temp_entry;
5363 /* Create a new (string) entry for the .debug_sfnames section. */
5365 static void
5366 generate_new_sfname_entry ()
5368 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5370 fputc ('\n', asm_out_file);
5371 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5372 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
5373 ASM_OUTPUT_LABEL (asm_out_file, label);
5374 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file,
5375 filename_table[0].name
5376 ? filename_table[0].name
5377 : "");
5378 ASM_OUTPUT_POP_SECTION (asm_out_file);
5381 /* Lookup a filename (in the list of filenames that we know about here in
5382 dwarfout.c) and return its "index". The index of each (known) filename
5383 is just a unique number which is associated with only that one filename.
5384 We need such numbers for the sake of generating labels (in the
5385 .debug_sfnames section) and references to those unique labels (in the
5386 .debug_srcinfo and .debug_macinfo sections).
5388 If the filename given as an argument is not found in our current list,
5389 add it to the list and assign it the next available unique index number.
5391 Whatever we do (i.e. whether we find a pre-existing filename or add a new
5392 one), we shuffle the filename found (or added) up to the zeroth entry of
5393 our list of filenames (which is always searched linearly). We do this so
5394 as to optimize the most common case for these filename lookups within
5395 dwarfout.c. The most common case by far is the case where we call
5396 lookup_filename to lookup the very same filename that we did a lookup
5397 on the last time we called lookup_filename. We make sure that this
5398 common case is fast because such cases will constitute 99.9% of the
5399 lookups we ever do (in practice).
5401 If we add a new filename entry to our table, we go ahead and generate
5402 the corresponding entry in the .debug_sfnames section right away.
5403 Doing so allows us to avoid tickling an assembler bug (present in some
5404 m68k assemblers) which yields assembly-time errors in cases where the
5405 difference of two label addresses is taken and where the two labels
5406 are in a section *other* than the one where the difference is being
5407 calculated, and where at least one of the two symbol references is a
5408 forward reference. (This bug could be tickled by our .debug_srcinfo
5409 entries if we don't output their corresponding .debug_sfnames entries
5410 before them.) */
5412 static unsigned
5413 lookup_filename (file_name)
5414 const char *file_name;
5416 register filename_entry *search_p;
5417 register filename_entry *limit_p = &filename_table[ft_entries];
5419 for (search_p = filename_table; search_p < limit_p; search_p++)
5420 if (!strcmp (file_name, search_p->name))
5422 /* When we get here, we have found the filename that we were
5423 looking for in the filename_table. Now we want to make sure
5424 that it gets moved to the zero'th entry in the table (if it
5425 is not already there) so that subsequent attempts to find the
5426 same filename will find it as quickly as possible. */
5428 shuffle_filename_entry (search_p);
5429 return filename_table[0].number;
5432 /* We come here whenever we have a new filename which is not registered
5433 in the current table. Here we add it to the table. */
5435 /* Prepare to add a new table entry by making sure there is enough space
5436 in the table to do so. If not, expand the current table. */
5438 if (ft_entries == ft_entries_allocated)
5440 ft_entries_allocated += FT_ENTRIES_INCREMENT;
5441 filename_table
5442 = (filename_entry *)
5443 xrealloc (filename_table,
5444 ft_entries_allocated * sizeof (filename_entry));
5447 /* Initially, add the new entry at the end of the filename table. */
5449 filename_table[ft_entries].number = ft_entries;
5450 filename_table[ft_entries].name = xstrdup (file_name);
5452 /* Shuffle the new entry into filename_table[0]. */
5454 shuffle_filename_entry (&filename_table[ft_entries]);
5456 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5457 generate_new_sfname_entry ();
5459 ft_entries++;
5460 return filename_table[0].number;
5463 static void
5464 generate_srcinfo_entry (line_entry_num, files_entry_num)
5465 unsigned line_entry_num;
5466 unsigned files_entry_num;
5468 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5470 fputc ('\n', asm_out_file);
5471 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5472 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
5473 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
5474 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
5475 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
5476 ASM_OUTPUT_POP_SECTION (asm_out_file);
5479 void
5480 dwarfout_line (filename, line)
5481 register const char *filename;
5482 register unsigned line;
5484 if (debug_info_level >= DINFO_LEVEL_NORMAL
5485 /* We can't emit line number info for functions in separate sections,
5486 because the assembler can't subtract labels in different sections. */
5487 && DECL_SECTION_NAME (current_function_decl) == NULL_TREE)
5489 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5490 static unsigned last_line_entry_num = 0;
5491 static unsigned prev_file_entry_num = (unsigned) -1;
5492 register unsigned this_file_entry_num;
5494 function_section (current_function_decl);
5495 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5496 ASM_OUTPUT_LABEL (asm_out_file, label);
5498 fputc ('\n', asm_out_file);
5500 if (use_gnu_debug_info_extensions)
5501 this_file_entry_num = lookup_filename (filename);
5502 else
5503 this_file_entry_num = (unsigned) -1;
5505 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5506 if (this_file_entry_num != prev_file_entry_num)
5508 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5510 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5511 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5515 register const char *tail = strrchr (filename, '/');
5517 if (tail != NULL)
5518 filename = tail;
5521 fprintf (asm_out_file, "%s%u\t%s %s:%u\n",
5522 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5523 filename, line);
5524 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5525 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5526 ASM_OUTPUT_POP_SECTION (asm_out_file);
5528 if (this_file_entry_num != prev_file_entry_num)
5529 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5530 prev_file_entry_num = this_file_entry_num;
5534 /* Generate an entry in the .debug_macinfo section. */
5536 static void
5537 generate_macinfo_entry (type_and_offset, string)
5538 register const char *type_and_offset;
5539 register const char *string;
5541 if (! use_gnu_debug_info_extensions)
5542 return;
5544 fputc ('\n', asm_out_file);
5545 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5546 fprintf (asm_out_file, "%s%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5547 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string);
5548 ASM_OUTPUT_POP_SECTION (asm_out_file);
5551 void
5552 dwarfout_start_new_source_file (filename)
5553 register const char *filename;
5555 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5556 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5558 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5559 sprintf (type_and_offset, "0x%08x+%s-%s",
5560 ((unsigned) MACINFO_start << 24),
5561 /* Hack: skip leading '*' . */
5562 (*label == '*') + label,
5563 (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL);
5564 generate_macinfo_entry (type_and_offset, "");
5567 void
5568 dwarfout_resume_previous_source_file (lineno)
5569 register unsigned lineno;
5571 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5573 sprintf (type_and_offset, "0x%08x+%u",
5574 ((unsigned) MACINFO_resume << 24), lineno);
5575 generate_macinfo_entry (type_and_offset, "");
5578 /* Called from check_newline in c-parse.y. The `buffer' parameter
5579 contains the tail part of the directive line, i.e. the part which
5580 is past the initial whitespace, #, whitespace, directive-name,
5581 whitespace part. */
5583 void
5584 dwarfout_define (lineno, buffer)
5585 register unsigned lineno;
5586 register const char *buffer;
5588 static int initialized = 0;
5589 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5591 if (!initialized)
5593 dwarfout_start_new_source_file (primary_filename);
5594 initialized = 1;
5596 sprintf (type_and_offset, "0x%08x+%u",
5597 ((unsigned) MACINFO_define << 24), lineno);
5598 generate_macinfo_entry (type_and_offset, buffer);
5601 /* Called from check_newline in c-parse.y. The `buffer' parameter
5602 contains the tail part of the directive line, i.e. the part which
5603 is past the initial whitespace, #, whitespace, directive-name,
5604 whitespace part. */
5606 void
5607 dwarfout_undef (lineno, buffer)
5608 register unsigned lineno;
5609 register const char *buffer;
5611 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5613 sprintf (type_and_offset, "0x%08x+%u",
5614 ((unsigned) MACINFO_undef << 24), lineno);
5615 generate_macinfo_entry (type_and_offset, buffer);
5618 /* Set up for Dwarf output at the start of compilation. */
5620 void
5621 dwarfout_init (asm_out_file, main_input_filename)
5622 register FILE *asm_out_file;
5623 register const char *main_input_filename;
5625 /* Remember the name of the primary input file. */
5627 primary_filename = main_input_filename;
5629 /* Allocate the initial hunk of the pending_sibling_stack. */
5631 pending_sibling_stack
5632 = (unsigned *)
5633 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5634 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5635 pending_siblings = 1;
5637 /* Allocate the initial hunk of the filename_table. */
5639 filename_table
5640 = (filename_entry *)
5641 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5642 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5643 ft_entries = 0;
5645 /* Allocate the initial hunk of the pending_types_list. */
5647 pending_types_list
5648 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5649 pending_types_allocated = PENDING_TYPES_INCREMENT;
5650 pending_types = 0;
5652 /* Create an artificial RECORD_TYPE node which we can use in our hack
5653 to get the DIEs representing types of formal parameters to come out
5654 only *after* the DIEs for the formal parameters themselves. */
5656 fake_containing_scope = make_node (RECORD_TYPE);
5658 /* Output a starting label for the .text section. */
5660 fputc ('\n', asm_out_file);
5661 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5662 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5663 ASM_OUTPUT_POP_SECTION (asm_out_file);
5665 /* Output a starting label for the .data section. */
5667 fputc ('\n', asm_out_file);
5668 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5669 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5670 ASM_OUTPUT_POP_SECTION (asm_out_file);
5672 #if 0 /* GNU C doesn't currently use .data1. */
5673 /* Output a starting label for the .data1 section. */
5675 fputc ('\n', asm_out_file);
5676 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5677 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5678 ASM_OUTPUT_POP_SECTION (asm_out_file);
5679 #endif
5681 /* Output a starting label for the .rodata section. */
5683 fputc ('\n', asm_out_file);
5684 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5685 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5686 ASM_OUTPUT_POP_SECTION (asm_out_file);
5688 #if 0 /* GNU C doesn't currently use .rodata1. */
5689 /* Output a starting label for the .rodata1 section. */
5691 fputc ('\n', asm_out_file);
5692 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5693 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5694 ASM_OUTPUT_POP_SECTION (asm_out_file);
5695 #endif
5697 /* Output a starting label for the .bss section. */
5699 fputc ('\n', asm_out_file);
5700 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5701 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5702 ASM_OUTPUT_POP_SECTION (asm_out_file);
5704 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5706 if (use_gnu_debug_info_extensions)
5708 /* Output a starting label and an initial (compilation directory)
5709 entry for the .debug_sfnames section. The starting label will be
5710 referenced by the initial entry in the .debug_srcinfo section. */
5712 fputc ('\n', asm_out_file);
5713 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5714 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5716 register const char *pwd = getpwd ();
5717 register char *dirname;
5719 if (!pwd)
5720 fatal_io_error ("can't get current directory");
5722 dirname = concat (pwd, "/", NULL);
5723 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
5724 free (dirname);
5726 ASM_OUTPUT_POP_SECTION (asm_out_file);
5729 if (debug_info_level >= DINFO_LEVEL_VERBOSE
5730 && use_gnu_debug_info_extensions)
5732 /* Output a starting label for the .debug_macinfo section. This
5733 label will be referenced by the AT_mac_info attribute in the
5734 TAG_compile_unit DIE. */
5736 fputc ('\n', asm_out_file);
5737 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5738 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5739 ASM_OUTPUT_POP_SECTION (asm_out_file);
5742 /* Generate the initial entry for the .line section. */
5744 fputc ('\n', asm_out_file);
5745 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5746 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5747 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5748 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5749 ASM_OUTPUT_POP_SECTION (asm_out_file);
5751 if (use_gnu_debug_info_extensions)
5753 /* Generate the initial entry for the .debug_srcinfo section. */
5755 fputc ('\n', asm_out_file);
5756 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5757 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5758 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5759 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5760 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5761 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5762 #ifdef DWARF_TIMESTAMPS
5763 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5764 #else
5765 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5766 #endif
5767 ASM_OUTPUT_POP_SECTION (asm_out_file);
5770 /* Generate the initial entry for the .debug_pubnames section. */
5772 fputc ('\n', asm_out_file);
5773 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5774 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5775 ASM_OUTPUT_POP_SECTION (asm_out_file);
5777 /* Generate the initial entry for the .debug_aranges section. */
5779 fputc ('\n', asm_out_file);
5780 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5781 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5782 ASM_OUTPUT_POP_SECTION (asm_out_file);
5785 /* Setup first DIE number == 1. */
5786 NEXT_DIE_NUM = next_unused_dienum++;
5788 /* Generate the initial DIE for the .debug section. Note that the
5789 (string) value given in the AT_name attribute of the TAG_compile_unit
5790 DIE will (typically) be a relative pathname and that this pathname
5791 should be taken as being relative to the directory from which the
5792 compiler was invoked when the given (base) source file was compiled. */
5794 fputc ('\n', asm_out_file);
5795 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5796 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5797 output_die (output_compile_unit_die, main_input_filename);
5798 ASM_OUTPUT_POP_SECTION (asm_out_file);
5800 fputc ('\n', asm_out_file);
5803 /* Output stuff that dwarf requires at the end of every file. */
5805 void
5806 dwarfout_finish ()
5808 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5810 fputc ('\n', asm_out_file);
5811 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5812 retry_incomplete_types ();
5813 fputc ('\n', asm_out_file);
5815 /* Mark the end of the chain of siblings which represent all file-scope
5816 declarations in this compilation unit. */
5818 /* The (null) DIE which represents the terminator for the (sibling linked)
5819 list of file-scope items is *special*. Normally, we would just call
5820 end_sibling_chain at this point in order to output a word with the
5821 value `4' and that word would act as the terminator for the list of
5822 DIEs describing file-scope items. Unfortunately, if we were to simply
5823 do that, the label that would follow this DIE in the .debug section
5824 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5825 machines) to a 4 byte boundary.
5827 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5828 the trick used is to insert extra (otherwise useless) padding bytes
5829 into the (null) DIE that we know must precede the ..D2 label in the
5830 .debug section. The amount of padding required can be anywhere between
5831 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5832 with the padding) would normally contain the value 4, but now it will
5833 also have to include the padding bytes, so it will instead have some
5834 value in the range 4..7.
5836 Fortunately, the rules of Dwarf say that any DIE whose length word
5837 contains *any* value less than 8 should be treated as a null DIE, so
5838 this trick works out nicely. Clever, eh? Don't give me any credit
5839 (or blame). I didn't think of this scheme. I just conformed to it.
5842 output_die (output_padded_null_die, (void *) 0);
5843 dienum_pop ();
5845 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5846 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5847 ASM_OUTPUT_POP_SECTION (asm_out_file);
5849 /* Output a terminator label for the .text section. */
5851 fputc ('\n', asm_out_file);
5852 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5853 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5854 ASM_OUTPUT_POP_SECTION (asm_out_file);
5856 /* Output a terminator label for the .data section. */
5858 fputc ('\n', asm_out_file);
5859 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5860 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5861 ASM_OUTPUT_POP_SECTION (asm_out_file);
5863 #if 0 /* GNU C doesn't currently use .data1. */
5864 /* Output a terminator label for the .data1 section. */
5866 fputc ('\n', asm_out_file);
5867 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5868 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5869 ASM_OUTPUT_POP_SECTION (asm_out_file);
5870 #endif
5872 /* Output a terminator label for the .rodata section. */
5874 fputc ('\n', asm_out_file);
5875 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5876 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5877 ASM_OUTPUT_POP_SECTION (asm_out_file);
5879 #if 0 /* GNU C doesn't currently use .rodata1. */
5880 /* Output a terminator label for the .rodata1 section. */
5882 fputc ('\n', asm_out_file);
5883 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5884 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5885 ASM_OUTPUT_POP_SECTION (asm_out_file);
5886 #endif
5888 /* Output a terminator label for the .bss section. */
5890 fputc ('\n', asm_out_file);
5891 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5892 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5893 ASM_OUTPUT_POP_SECTION (asm_out_file);
5895 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5897 /* Output a terminating entry for the .line section. */
5899 fputc ('\n', asm_out_file);
5900 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5901 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5902 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5903 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5904 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5905 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5906 ASM_OUTPUT_POP_SECTION (asm_out_file);
5908 if (use_gnu_debug_info_extensions)
5910 /* Output a terminating entry for the .debug_srcinfo section. */
5912 fputc ('\n', asm_out_file);
5913 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5914 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5915 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5916 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5917 ASM_OUTPUT_POP_SECTION (asm_out_file);
5920 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5922 /* Output terminating entries for the .debug_macinfo section. */
5924 dwarfout_resume_previous_source_file (0);
5926 fputc ('\n', asm_out_file);
5927 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5928 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5929 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
5930 ASM_OUTPUT_POP_SECTION (asm_out_file);
5933 /* Generate the terminating entry for the .debug_pubnames section. */
5935 fputc ('\n', asm_out_file);
5936 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5937 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5938 ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, "");
5939 ASM_OUTPUT_POP_SECTION (asm_out_file);
5941 /* Generate the terminating entries for the .debug_aranges section.
5943 Note that we want to do this only *after* we have output the end
5944 labels (for the various program sections) which we are going to
5945 refer to here. This allows us to work around a bug in the m68k
5946 svr4 assembler. That assembler gives bogus assembly-time errors
5947 if (within any given section) you try to take the difference of
5948 two relocatable symbols, both of which are located within some
5949 other section, and if one (or both?) of the symbols involved is
5950 being forward-referenced. By generating the .debug_aranges
5951 entries at this late point in the assembly output, we skirt the
5952 issue simply by avoiding forward-references.
5955 fputc ('\n', asm_out_file);
5956 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5958 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5959 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5961 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5962 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5964 #if 0 /* GNU C doesn't currently use .data1. */
5965 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5966 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5967 DATA1_BEGIN_LABEL);
5968 #endif
5970 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5971 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5972 RODATA_BEGIN_LABEL);
5974 #if 0 /* GNU C doesn't currently use .rodata1. */
5975 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5976 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5977 RODATA1_BEGIN_LABEL);
5978 #endif
5980 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5981 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5983 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5984 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5986 ASM_OUTPUT_POP_SECTION (asm_out_file);
5989 /* There should not be any pending types left at the end. We need
5990 this now because it may not have been checked on the last call to
5991 dwarfout_file_scope_decl. */
5992 if (pending_types != 0)
5993 abort ();
5996 #endif /* DWARF_DEBUGGING_INFO */