1 /* This file contains code written by Ron Guilmette (rfg@ncd.com) for
2 Network Computing Devices, August, September, October, November 1990.
4 Output Dwarf format symbol table information from the GNU C compiler.
5 Copyright (C) 1992 Free Software Foundation, Inc.
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #ifdef DWARF_DEBUGGING_INFO
31 #include "insn-config.h"
35 /* #define NDEBUG 1 */
38 #if defined(DWARF_TIMESTAMPS)
41 #else /* !defined(POSIX) */
42 #include <sys/types.h>
44 extern time_t time (time_t *);
45 #else /* !defined(__STDC__) */
46 extern time_t time ();
47 #endif /* !defined(__STDC__) */
48 #endif /* !defined(POSIX) */
49 #endif /* defined(DWARF_TIMESTAMPS) */
51 #if defined(USG) || defined(POSIX)
55 #define strrchr rindex
61 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
62 regarding the GNU implementation of Dwarf. */
64 /* NOTE: In the comments in this file, many references are made to
65 so called "Debugging Information Entries". For the sake of brevity,
66 this term is abbreviated to `DIE' throughout the remainder of this
69 /* Note that the implementation of C++ support herein is (as yet) unfinished.
70 If you want to try to complete it, more power to you. */
72 #if defined(__GNUC__) && (NDEBUG == 1)
73 #define inline static inline
78 /* How to start an assembler comment. */
79 #ifndef ASM_COMMENT_START
80 #define ASM_COMMENT_START ";#"
83 /* Define a macro which, when given a pointer to some BLOCK node, returns
84 a pointer to the FUNCTION_DECL node from which the given BLOCK node
85 was instantiated (as an inline expansion). This macro needs to be
86 defined properly in tree.h, however for the moment, we just fake it. */
88 #define BLOCK_INLINE_FUNCTION(block) 0
90 /* Define a macro which returns non-zero for any tagged type which is
91 used (directly or indirectly) in the specification of either some
92 function's return type or some formal parameter of some function.
93 We use this macro when we are operating in "terse" mode to help us
94 know what tagged types have to be represented in Dwarf (even in
95 terse mode) and which ones don't.
97 A flag bit with this meaning really should be a part of the normal
98 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
99 for these nodes. For now, we have to just fake it. It it safe for
100 us to simply return zero for all complete tagged types (which will
101 get forced out anyway if they were used in the specification of some
102 formal or return type) and non-zero for all incomplete tagged types.
105 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
107 #define BITFIELD_OFFSET_BITS(DECL) \
108 ((unsigned) TREE_INT_CST_LOW (DECL_FIELD_BITPOS (DECL)))
109 #define BITFIELD_OFFSET_UNITS(DECL) \
110 (BITFIELD_OFFSET_BITS(DECL) / (unsigned) BITS_PER_UNIT)
111 #define BITFIELD_OFFSET_WORDS_IN_UNITS(DECL) \
112 ((BITFIELD_OFFSET_BITS(DECL) / (unsigned) BITS_PER_WORD) * UNITS_PER_WORD)
114 extern int flag_traditional;
115 extern char *version_string;
116 extern char *language_string;
118 /* Maximum size (in bytes) of an artificially generated label. */
120 #define MAX_ARTIFICIAL_LABEL_BYTES 30
122 /* Make sure we know the sizes of the various types dwarf can describe.
123 These are only defaults. If the sizes are different for your target,
124 you should override these values by defining the appropriate symbols
125 in your tm.h file. */
127 #ifndef CHAR_TYPE_SIZE
128 #define CHAR_TYPE_SIZE BITS_PER_UNIT
131 #ifndef SHORT_TYPE_SIZE
132 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
135 #ifndef INT_TYPE_SIZE
136 #define INT_TYPE_SIZE BITS_PER_WORD
139 #ifndef LONG_TYPE_SIZE
140 #define LONG_TYPE_SIZE BITS_PER_WORD
143 #ifndef LONG_LONG_TYPE_SIZE
144 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
147 #ifndef WCHAR_TYPE_SIZE
148 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
151 #ifndef WCHAR_UNSIGNED
152 #define WCHAR_UNSIGNED 0
155 #ifndef FLOAT_TYPE_SIZE
156 #define FLOAT_TYPE_SIZE BITS_PER_WORD
159 #ifndef DOUBLE_TYPE_SIZE
160 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
163 #ifndef LONG_DOUBLE_TYPE_SIZE
164 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
167 /* Structure to keep track of source filenames. */
169 struct filename_entry {
174 typedef struct filename_entry filename_entry;
176 /* Pointer to an array of elements, each one having the structure above. */
178 static filename_entry *filename_table;
180 /* Total number of entries in the table (i.e. array) pointed to by
181 `filename_table'. This is the *total* and includes both used and
184 static unsigned ft_entries_allocated;
186 /* Number of entries in the filename_table which are actually in use. */
188 static unsigned ft_entries;
190 /* Size (in elements) of increments by which we may expand the filename
191 table. Actually, a single hunk of space of this size should be enough
192 for most typical programs. */
194 #define FT_ENTRIES_INCREMENT 64
196 /* Local pointer to the name of the main input file. Initialized in
199 static char *primary_filename;
201 /* Pointer to the most recent filename for which we produced some line info. */
203 static char *last_filename;
205 /* For Dwarf output, we must assign lexical-blocks id numbers
206 in the order in which their beginnings are encountered.
207 We output Dwarf debugging info that refers to the beginnings
208 and ends of the ranges of code for each lexical block with
209 assembler labels ..Bn and ..Bn.e, where n is the block number.
210 The labels themselves are generated in final.c, which assigns
211 numbers to the blocks in the same way. */
213 static unsigned next_block_number = 2;
215 /* Counter to generate unique names for DIEs. */
217 static unsigned next_unused_dienum = 1;
219 /* Number of the DIE which is currently being generated. */
221 static unsigned current_dienum;
223 /* Number to use for the special "pubname" label on the next DIE which
224 represents a function or data object defined in this compilation
225 unit which has "extern" linkage. */
227 static next_pubname_number = 0;
229 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
231 /* Pointer to a dynamically allocated list of pre-reserved and still
232 pending sibling DIE numbers. Note that this list will grow as needed. */
234 static unsigned *pending_sibling_stack;
236 /* Counter to keep track of the number of pre-reserved and still pending
237 sibling DIE numbers. */
239 static unsigned pending_siblings;
241 /* The currently allocated size of the above list (expressed in number of
244 static unsigned pending_siblings_allocated;
246 /* Size (in elements) of increments by which we may expand the pending
247 sibling stack. Actually, a single hunk of space of this size should
248 be enough for most typical programs. */
250 #define PENDING_SIBLINGS_INCREMENT 64
252 /* Non-zero if we are performing our file-scope finalization pass and if
253 we should force out Dwarf decsriptions of any and all file-scope
254 tagged types which are still incomplete types. */
256 static int finalizing = 0;
258 /* A pointer to the base of a list of pending types which we haven't
259 generated DIEs for yet, but which we will have to come back to
262 static tree *pending_types_list;
264 /* Number of elements currently allocated for the pending_types_list. */
266 static unsigned pending_types_allocated;
268 /* Number of elements of pending_types_list currently in use. */
270 static unsigned pending_types;
272 /* Size (in elements) of increments by which we may expand the pending
273 types list. Actually, a single hunk of space of this size should
274 be enough for most typical programs. */
276 #define PENDING_TYPES_INCREMENT 64
278 /* Pointer to an artifical RECORD_TYPE which we create in dwarfout_init.
279 This is used in a hack to help us get the DIEs describing types of
280 formal parameters to come *after* all of the DIEs describing the formal
281 parameters themselves. That's necessary in order to be compatible
282 with what the brain-dammaged svr4 SDB debugger requires. */
284 static tree fake_containing_scope;
286 /* The number of the current function definition that we are generating
287 debugging information for. These numbers range from 1 up to the maximum
288 number of function definitions contained within the current compilation
289 unit. These numbers are used to create unique labels for various things
290 contained within various function definitions. */
292 static unsigned current_funcdef_number = 1;
294 /* Forward declarations for functions defined in this file. */
296 static void output_type ();
297 static void type_attribute ();
298 static void output_decls_for_scope ();
299 static void output_decl ();
300 static unsigned lookup_filename ();
302 /* Definitions of defaults for assembler-dependent names of various
303 pseudo-ops and section names.
305 Theses may be overridden in your tm.h file (if necessary) for your
306 particular assembler. The default values provided here correspond to
307 what is expected by "standard" AT&T System V.4 assemblers. */
310 #define FILE_ASM_OP ".file"
312 #ifndef VERSION_ASM_OP
313 #define VERSION_ASM_OP ".version"
315 #ifndef UNALIGNED_SHORT_ASM_OP
316 #define UNALIGNED_SHORT_ASM_OP ".2byte"
318 #ifndef UNALIGNED_INT_ASM_OP
319 #define UNALIGNED_INT_ASM_OP ".4byte"
322 #define DEF_ASM_OP ".set"
325 #define ASM_BYTE_OP "\t.byte"
328 /* Pseudo-ops for pushing the current section onto the section stack (and
329 simultaneously changing to a new section) and for poping back to the
330 section we were in immediately before this one. Note that most svr4
331 assemblers only maintain a one level stack... you can push all the
332 sections you want, but you can only pop out one level. (The sparc
333 svr4 assembler might be an exception to this general rule.) That's
334 OK because we only use at most one level of the section stack herein. */
336 #ifndef PUSHSECTION_ASM_OP
337 #define PUSHSECTION_ASM_OP "\t.section"
339 #ifndef POPSECTION_ASM_OP
340 #define POPSECTION_ASM_OP "\t.previous"
343 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
344 to print the PUSHSECTION_ASM_OP and the section name. The default here
345 works for almost all svr4 assemblers, except for the sparc, where the
346 section name must be enclosed in double quotes. (See sparcv4.h.) */
348 #ifndef PUSHSECTION_FORMAT
349 #define PUSHSECTION_FORMAT "%s\t%s\n"
352 #ifndef DEBUG_SECTION
353 #define DEBUG_SECTION ".debug"
356 #define LINE_SECTION ".line"
358 #ifndef SFNAMES_SECTION
359 #define SFNAMES_SECTION ".debug_sfnames"
361 #ifndef SRCINFO_SECTION
362 #define SRCINFO_SECTION ".debug_srcinfo"
364 #ifndef MACINFO_SECTION
365 #define MACINFO_SECTION ".debug_macinfo"
367 #ifndef PUBNAMES_SECTION
368 #define PUBNAMES_SECTION ".debug_pubnames"
370 #ifndef ARANGES_SECTION
371 #define ARANGES_SECTION ".debug_aranges"
374 #define TEXT_SECTION ".text"
377 #define DATA_SECTION ".data"
379 #ifndef DATA1_SECTION
380 #define DATA1_SECTION ".data1"
382 #ifndef RODATA_SECTION
383 #define RODATA_SECTION ".rodata"
385 #ifndef RODATA1_SECTION
386 #define RODATA1_SECTION ".rodata1"
389 #define BSS_SECTION ".bss"
392 /* Definitions of defaults for formats and names of various special
393 (artificial) labels which may be generated within this file (when
394 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
396 If necessary, these may be overridden from within your tm.h file,
397 but typically, you should never need to override these. */
399 #ifndef TEXT_BEGIN_LABEL
400 #define TEXT_BEGIN_LABEL "._text_b"
402 #ifndef TEXT_END_LABEL
403 #define TEXT_END_LABEL "._text_e"
406 #ifndef DATA_BEGIN_LABEL
407 #define DATA_BEGIN_LABEL "._data_b"
409 #ifndef DATA_END_LABEL
410 #define DATA_END_LABEL "._data_e"
413 #ifndef DATA1_BEGIN_LABEL
414 #define DATA1_BEGIN_LABEL "._data1_b"
416 #ifndef DATA1_END_LABEL
417 #define DATA1_END_LABEL "._data1_e"
420 #ifndef RODATA_BEGIN_LABEL
421 #define RODATA_BEGIN_LABEL "._rodata_b"
423 #ifndef RODATA_END_LABEL
424 #define RODATA_END_LABEL "._rodata_e"
427 #ifndef RODATA1_BEGIN_LABEL
428 #define RODATA1_BEGIN_LABEL "._rodata1_b"
430 #ifndef RODATA1_END_LABEL
431 #define RODATA1_END_LABEL "._rodata1_e"
434 #ifndef BSS_BEGIN_LABEL
435 #define BSS_BEGIN_LABEL "._bss_b"
437 #ifndef BSS_END_LABEL
438 #define BSS_END_LABEL "._bss_e"
441 #ifndef LINE_BEGIN_LABEL
442 #define LINE_BEGIN_LABEL "._line_b"
444 #ifndef LINE_LAST_ENTRY_LABEL
445 #define LINE_LAST_ENTRY_LABEL "._line_last"
447 #ifndef LINE_END_LABEL
448 #define LINE_END_LABEL "._line_e"
451 #ifndef DEBUG_BEGIN_LABEL
452 #define DEBUG_BEGIN_LABEL "._debug_b"
454 #ifndef SFNAMES_BEGIN_LABEL
455 #define SFNAMES_BEGIN_LABEL "._sfnames_b"
457 #ifndef SRCINFO_BEGIN_LABEL
458 #define SRCINFO_BEGIN_LABEL "._srcinfo_b"
460 #ifndef MACINFO_BEGIN_LABEL
461 #define MACINFO_BEGIN_LABEL "._macinfo_b"
464 #ifndef DIE_BEGIN_LABEL_FMT
465 #define DIE_BEGIN_LABEL_FMT "._D%u"
467 #ifndef DIE_END_LABEL_FMT
468 #define DIE_END_LABEL_FMT "._D%u_e"
470 #ifndef PUB_DIE_LABEL_FMT
471 #define PUB_DIE_LABEL_FMT "._P%u"
473 #ifndef INSN_LABEL_FMT
474 #define INSN_LABEL_FMT "._I%u_%u"
476 #ifndef BLOCK_BEGIN_LABEL_FMT
477 #define BLOCK_BEGIN_LABEL_FMT "._B%u"
479 #ifndef BLOCK_END_LABEL_FMT
480 #define BLOCK_END_LABEL_FMT "._B%u_e"
482 #ifndef SS_BEGIN_LABEL_FMT
483 #define SS_BEGIN_LABEL_FMT "._s%u"
485 #ifndef SS_END_LABEL_FMT
486 #define SS_END_LABEL_FMT "._s%u_e"
488 #ifndef EE_BEGIN_LABEL_FMT
489 #define EE_BEGIN_LABEL_FMT "._e%u"
491 #ifndef EE_END_LABEL_FMT
492 #define EE_END_LABEL_FMT "._e%u_e"
494 #ifndef MT_BEGIN_LABEL_FMT
495 #define MT_BEGIN_LABEL_FMT "._t%u"
497 #ifndef MT_END_LABEL_FMT
498 #define MT_END_LABEL_FMT "._t%u_e"
500 #ifndef LOC_BEGIN_LABEL_FMT
501 #define LOC_BEGIN_LABEL_FMT "._l%u"
503 #ifndef LOC_END_LABEL_FMT
504 #define LOC_END_LABEL_FMT "._l%u_e"
506 #ifndef BOUND_BEGIN_LABEL_FMT
507 #define BOUND_BEGIN_LABEL_FMT "._b%u_%u_%c"
509 #ifndef BOUND_END_LABEL_FMT
510 #define BOUND_END_LABEL_FMT "._b%u_%u_%c_e"
512 #ifndef DERIV_BEGIN_LABEL_FMT
513 #define DERIV_BEGIN_LABEL_FMT "._d%u"
515 #ifndef DERIV_END_LABEL_FMT
516 #define DERIV_END_LABEL_FMT "._d%u_e"
518 #ifndef SL_BEGIN_LABEL_FMT
519 #define SL_BEGIN_LABEL_FMT "._sl%u"
521 #ifndef SL_END_LABEL_FMT
522 #define SL_END_LABEL_FMT "._sl%u_e"
524 #ifndef FUNC_END_LABEL_FMT
525 #define FUNC_END_LABEL_FMT "._f%u_e"
527 #ifndef TYPE_NAME_FMT
528 #define TYPE_NAME_FMT "._T%u"
530 #ifndef LINE_CODE_LABEL_FMT
531 #define LINE_CODE_LABEL_FMT "._LC%u"
533 #ifndef SFNAMES_ENTRY_LABEL_FMT
534 #define SFNAMES_ENTRY_LABEL_FMT "._F%u"
536 #ifndef LINE_ENTRY_LABEL_FMT
537 #define LINE_ENTRY_LABEL_FMT "._LE%u"
540 /* Definitions of defaults for various types of primitive assembly language
543 If necessary, these may be overridden from within your tm.h file,
544 but typically, you shouldn't need to override these. Two known
545 exceptions are the ASM_OUTPUT_PUSH_SECTION and ASM_OUTPUT_POP_SECTION
546 definitions, which need to be somewhat special for a sparc running svr4.
549 #ifndef ASM_OUTPUT_PUSH_SECTION
550 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
551 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
554 #ifndef ASM_OUTPUT_POP_SECTION
555 #define ASM_OUTPUT_POP_SECTION(FILE) \
556 fprintf ((FILE), "%s\n", POPSECTION_ASM_OP)
559 #ifndef ASM_OUTPUT_SOURCE_FILENAME
560 #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
561 fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME)
564 #ifndef ASM_OUTPUT_DEF
565 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
566 do { fprintf ((FILE), "\t%s\t", DEF_ASM_OP); \
567 assemble_name (FILE, LABEL1); \
568 fprintf (FILE, ","); \
569 assemble_name (FILE, LABEL2); \
570 fprintf (FILE, "\n"); \
574 #ifndef ASM_OUTPUT_DWARF_DELTA2
575 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
576 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
577 assemble_name (FILE, LABEL1); \
578 fprintf (FILE, "-"); \
579 assemble_name (FILE, LABEL2); \
580 fprintf (FILE, "\n"); \
584 #ifndef ASM_OUTPUT_DWARF_DELTA4
585 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
586 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
587 assemble_name (FILE, LABEL1); \
588 fprintf (FILE, "-"); \
589 assemble_name (FILE, LABEL2); \
590 fprintf (FILE, "\n"); \
594 #ifndef ASM_OUTPUT_DWARF_TAG
595 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
596 fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP, \
597 (unsigned) TAG, ASM_COMMENT_START, tag_name (TAG))
600 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
601 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTRIBUTE) \
602 fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP, \
603 (unsigned) ATTRIBUTE, ASM_COMMENT_START, attribute_name (ATTRIBUTE))
606 #ifndef ASM_OUTPUT_DWARF_STACK_OP
607 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
608 fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP, \
609 (unsigned) OP, ASM_COMMENT_START, stack_op_name (OP))
612 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
613 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
614 fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP, \
615 (unsigned) FT, ASM_COMMENT_START, fundamental_type_name (FT))
618 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
619 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
620 fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP, \
621 (unsigned) FMT, ASM_COMMENT_START, format_byte_name (FMT))
624 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
625 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
626 fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP, \
627 (unsigned) MOD, ASM_COMMENT_START, modifier_name (MOD))
630 #ifndef ASM_OUTPUT_DWARF_ADDR
631 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
632 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
633 assemble_name (FILE, LABEL); \
634 fprintf (FILE, "\n"); \
638 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
639 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
640 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
641 output_addr_const ((FILE), (RTX)); \
645 #ifndef ASM_OUTPUT_DWARF_REF
646 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
647 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
648 assemble_name (FILE, LABEL); \
649 fprintf (FILE, "\n"); \
653 #ifndef ASM_OUTPUT_DWARF_DATA1
654 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
655 fprintf ((FILE), "%s\t0x%x\n", ASM_BYTE_OP, VALUE)
658 #ifndef ASM_OUTPUT_DWARF_DATA2
659 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
660 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
663 #ifndef ASM_OUTPUT_DWARF_DATA4
664 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
665 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
668 #ifndef ASM_OUTPUT_DWARF_DATA8
669 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
671 if (WORDS_BIG_ENDIAN) \
673 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
674 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
678 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
679 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
684 /* choose a reasonable default for ASM_OUTPUT_ASCII, as that is what
685 varasm.c does. If the below is changed, please also change
686 definition in varasm.c Both of these should be factored out, into a
688 #ifndef ASM_OUTPUT_ASCII
689 #define ASM_OUTPUT_ASCII(MYFILE, MYSTRING, MYLENGTH) \
691 FILE *_hide_asm_out_file = MYFILE; \
692 char *_hide_p = MYSTRING; \
693 int _hide_thissize = MYLENGTH; \
695 FILE *asm_out_file = _hide_asm_out_file; \
697 int thissize = _hide_thissize; \
699 fprintf (asm_out_file, "\t.ascii \""); \
701 for (i = 0; i < thissize; i++) \
703 register int c = p[i]; \
704 if (c == '\"' || c == '\\') \
705 putc ('\\', asm_out_file); \
706 if (c >= ' ' && c < 0177) \
707 putc (c, asm_out_file); \
710 fprintf (asm_out_file, "\\%o", c); \
711 /* After an octal-escape, if a digit follows, \
712 terminate one string constant and start another. \
713 The Vax assembler fails to stop reading the escape \
714 after three digits, so this is the only way we \
715 can get it to parse the data properly. */ \
716 if (i < thissize - 1 \
717 && p[i + 1] >= '0' && p[i + 1] <= '9') \
718 fprintf (asm_out_file, "\"\n\t.ascii \""); \
721 fprintf (asm_out_file, "\"\n"); \
727 #ifndef ASM_OUTPUT_DWARF_STRING
728 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
729 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
732 /************************ general utility functions **************************/
738 register char *p = (char *) xmalloc (strlen (s) + 1);
746 register unsigned tag;
750 case TAG_padding: return "TAG_padding";
751 case TAG_array_type: return "TAG_array_type";
752 case TAG_class_type: return "TAG_class_type";
753 case TAG_entry_point: return "TAG_entry_point";
754 case TAG_enumeration_type: return "TAG_enumeration_type";
755 case TAG_formal_parameter: return "TAG_formal_parameter";
756 case TAG_global_subroutine: return "TAG_global_subroutine";
757 case TAG_global_variable: return "TAG_global_variable";
758 case TAG_imported_declaration: return "TAG_imported_declaration";
759 case TAG_label: return "TAG_label";
760 case TAG_lexical_block: return "TAG_lexical_block";
761 case TAG_local_variable: return "TAG_local_variable";
762 case TAG_member: return "TAG_member";
763 case TAG_pointer_type: return "TAG_pointer_type";
764 case TAG_reference_type: return "TAG_reference_type";
765 case TAG_compile_unit: return "TAG_compile_unit";
766 case TAG_string_type: return "TAG_string_type";
767 case TAG_structure_type: return "TAG_structure_type";
768 case TAG_subroutine: return "TAG_subroutine";
769 case TAG_subroutine_type: return "TAG_subroutine_type";
770 case TAG_typedef: return "TAG_typedef";
771 case TAG_union_type: return "TAG_union_type";
772 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
773 case TAG_variant: return "TAG_variant";
774 case TAG_format: return "TAG_format";
775 case TAG_with_stmt: return "TAG_with_stmt";
776 case TAG_set_type: return "TAG_set_type";
777 default: return "<unknown tag>";
782 attribute_name (attr)
783 register unsigned attr;
787 case AT_sibling: return "AT_sibling";
788 case AT_location: return "AT_location";
789 case AT_name: return "AT_name";
790 case AT_fund_type: return "AT_fund_type";
791 case AT_mod_fund_type: return "AT_mod_fund_type";
792 case AT_user_def_type: return "AT_user_def_type";
793 case AT_mod_u_d_type: return "AT_mod_u_d_type";
794 case AT_ordering: return "AT_ordering";
795 case AT_subscr_data: return "AT_subscr_data";
796 case AT_byte_size: return "AT_byte_size";
797 case AT_bit_offset: return "AT_bit_offset";
798 case AT_bit_size: return "AT_bit_size";
799 case AT_element_list: return "AT_element_list";
800 case AT_stmt_list: return "AT_stmt_list";
801 case AT_low_pc: return "AT_low_pc";
802 case AT_high_pc: return "AT_high_pc";
803 case AT_language: return "AT_language";
804 case AT_member: return "AT_member";
805 case AT_discr: return "AT_discr";
806 case AT_discr_value: return "AT_discr_value";
807 case AT_visibility: return "AT_visibility";
808 case AT_import: return "AT_import";
809 case AT_string_length: return "AT_string_length";
810 case AT_comp_dir: return "AT_comp_dir";
811 case AT_producer: return "AT_producer";
812 case AT_frame_base: return "AT_frame_base";
813 case AT_start_scope: return "AT_start_scope";
814 case AT_stride_size: return "AT_stride_size";
815 case AT_src_info: return "AT_src_info";
816 case AT_prototyped: return "AT_prototyped";
817 case AT_const_value_block4: return "AT_const_value_block4";
818 case AT_sf_names: return "AT_sf_names";
819 case AT_mac_info: return "AT_mac_info";
820 default: return "<unknown attribute>";
826 register unsigned op;
830 case OP_REG: return "OP_REG";
831 case OP_BASEREG: return "OP_BASEREG";
832 case OP_ADDR: return "OP_ADDR";
833 case OP_CONST: return "OP_CONST";
834 case OP_DEREF2: return "OP_DEREF2";
835 case OP_DEREF4: return "OP_DEREF4";
836 case OP_ADD: return "OP_ADD";
837 default: return "<unknown stack operator>";
843 register unsigned mod;
847 case MOD_pointer_to: return "MOD_pointer_to";
848 case MOD_reference_to: return "MOD_reference_to";
849 case MOD_const: return "MOD_const";
850 case MOD_volatile: return "MOD_volatile";
851 default: return "<unknown modifier>";
856 format_byte_name (fmt)
857 register unsigned fmt;
861 case FMT_FT_C_C: return "FMT_FT_C_C";
862 case FMT_FT_C_X: return "FMT_FT_C_X";
863 case FMT_FT_X_C: return "FMT_FT_X_C";
864 case FMT_FT_X_X: return "FMT_FT_X_X";
865 case FMT_UT_C_C: return "FMT_UT_C_C";
866 case FMT_UT_C_X: return "FMT_UT_C_X";
867 case FMT_UT_X_C: return "FMT_UT_X_C";
868 case FMT_UT_X_X: return "FMT_UT_X_X";
869 case FMT_ET: return "FMT_ET";
870 default: return "<unknown array bound format byte>";
874 fundamental_type_name (ft)
875 register unsigned ft;
879 case FT_char: return "FT_char";
880 case FT_signed_char: return "FT_signed_char";
881 case FT_unsigned_char: return "FT_unsigned_char";
882 case FT_short: return "FT_short";
883 case FT_signed_short: return "FT_signed_short";
884 case FT_unsigned_short: return "FT_unsigned_short";
885 case FT_integer: return "FT_integer";
886 case FT_signed_integer: return "FT_signed_integer";
887 case FT_unsigned_integer: return "FT_unsigned_integer";
888 case FT_long: return "FT_long";
889 case FT_signed_long: return "FT_signed_long";
890 case FT_unsigned_long: return "FT_unsigned_long";
891 case FT_pointer: return "FT_pointer";
892 case FT_float: return "FT_float";
893 case FT_dbl_prec_float: return "FT_dbl_prec_float";
894 case FT_ext_prec_float: return "FT_ext_prec_float";
895 case FT_complex: return "FT_complex";
896 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
897 case FT_void: return "FT_void";
898 case FT_boolean: return "FT_boolean";
899 case FT_long_long: return "FT_long_long";
900 case FT_signed_long_long: return "FT_signed_long_long";
901 case FT_unsigned_long_long: return "FT_unsigned_long_long";
902 default: return "<unknown fundamental type>";
906 /**************** utility functions for attribute functions ******************/
908 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
909 type code for the given type.
911 This routine must only be called for GCC type nodes that correspond to
912 Dwarf fundamental types.
914 The current Dwarf draft specification calls for Dwarf fundamental types
915 to accurately reflect the fact that a given type was either a "plain"
916 integral type or an explicitly "signed" integral type. Unfortuantely,
917 we can't always do this, because GCC may already have thrown away the
918 information about the precise way in which the type was originally
921 typedef signed int field_type;
923 struct s { field_type f; };
925 Since we may be stuck here without enought information to do exactly
926 what is called for in the Dwarf draft specification, we do the best
927 that we can under the circumstances and always use the "plain" integral
928 fundamental type codes for int, short, and long types. That's probably
929 good enough. The additional accuracy called for in the current DWARF
930 draft specification is probably never even useful in practice. */
933 fundamental_type_code (type)
936 if (TREE_CODE (type) == ERROR_MARK)
939 switch (TREE_CODE (type))
948 /* Carefully distinguish all the standard types of C,
949 without messing up if the language is not C.
950 Note that we check only for the names that contain spaces;
951 other names might occur by coincidence in other languages. */
952 if (TYPE_NAME (type) != 0
953 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
954 && DECL_NAME (TYPE_NAME (type)) != 0
955 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
957 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
959 if (!strcmp (name, "unsigned char"))
960 return FT_unsigned_char;
961 if (!strcmp (name, "signed char"))
962 return FT_signed_char;
963 if (!strcmp (name, "unsigned int"))
964 return FT_unsigned_integer;
965 if (!strcmp (name, "short int"))
967 if (!strcmp (name, "short unsigned int"))
968 return FT_unsigned_short;
969 if (!strcmp (name, "long int"))
971 if (!strcmp (name, "long unsigned int"))
972 return FT_unsigned_long;
973 if (!strcmp (name, "long long int"))
974 return FT_long_long; /* Not grok'ed by svr4 SDB */
975 if (!strcmp (name, "long long unsigned int"))
976 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
979 /* Most integer types will be sorted out above, however, for the
980 sake of special `array index' integer types, the following code
983 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
984 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
986 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
987 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
989 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
990 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
992 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
993 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
995 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
996 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1001 /* Carefully distinguish all the standard types of C,
1002 without messing up if the language is not C. */
1003 if (TYPE_NAME (type) != 0
1004 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1005 && DECL_NAME (TYPE_NAME (type)) != 0
1006 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1008 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1010 /* Note that here we can run afowl of a serious bug in "classic"
1011 svr4 SDB debuggers. They don't seem to understand the
1012 FT_ext_prec_float type (even though they should). */
1014 if (!strcmp (name, "long double"))
1015 return FT_ext_prec_float;
1018 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1019 return FT_dbl_prec_float;
1020 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1023 /* Note that here we can run afowl of a serious bug in "classic"
1024 svr4 SDB debuggers. They don't seem to understand the
1025 FT_ext_prec_float type (even though they should). */
1027 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1028 return FT_ext_prec_float;
1032 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1035 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1038 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1041 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1046 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1047 the Dwarf "root" type for the given input type. The Dwarf "root" type
1048 of a given type is generally the same as the given type, except that if
1049 the given type is a pointer or reference type, then the root type of
1050 the given type is the root type of the "basis" type for the pointer or
1051 reference type. (This definition of the "root" type is recursive.)
1052 Also, the root type of a `const' qualified type or a `volatile'
1053 qualified type is the root type of the given type without the
1060 if (TREE_CODE (type) == ERROR_MARK)
1061 return error_mark_node;
1063 switch (TREE_CODE (type))
1066 return error_mark_node;
1069 case REFERENCE_TYPE:
1070 return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type)));
1073 return TYPE_MAIN_VARIANT (type);
1077 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1078 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1081 write_modifier_bytes (type, decl_const, decl_volatile)
1083 register int decl_const;
1084 register int decl_volatile;
1086 if (TREE_CODE (type) == ERROR_MARK)
1089 if (TYPE_READONLY (type) || decl_const)
1090 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1091 if (TYPE_VOLATILE (type) || decl_volatile)
1092 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1093 switch (TREE_CODE (type))
1096 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1097 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1100 case REFERENCE_TYPE:
1101 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1102 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1111 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1112 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1115 type_is_fundamental (type)
1118 switch (TREE_CODE (type))
1137 case REFERENCE_TYPE:
1150 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1151 equate directive which will associate an easily remembered symbolic name
1152 with the current DIE.
1154 The name used is an artificial label generated from the TYPE_UID number
1155 associated with the given type node. The name it gets equated to is the
1156 symbolic label that we (previously) output at the start of the DIE that
1157 we are currently generating.
1159 Calling this function while generating some "type related" form of DIE
1160 makes it easy to later refer to the DIE which represents the given type
1161 simply by re-generating the alternative name from the ..._TYPE node's
1165 equate_type_number_to_die_number (type)
1168 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1169 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1171 /* We are generating a DIE to represent the main variant of this type
1172 (i.e the type without any const or volatile qualifiers) so in order
1173 to get the equate to come out right, we need to get the main variant
1176 type = TYPE_MAIN_VARIANT (type);
1178 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1179 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1180 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1183 /* The following routine is a nice and simple transducer. It converts the
1184 RTL for a variable or parameter (resident in memory) into an equivalent
1185 Dwarf representation of a mechanism for getting the address of that same
1186 variable onto the top of a hypothetical "address evaluation" stack.
1188 When creating memory location descriptors, we are effectively trans-
1189 forming the RTL for a memory-resident object into its Dwarf postfix
1190 expression equivalent. This routine just recursively descends an
1191 RTL tree, turning it into Dwarf postfix code as it goes. */
1194 output_mem_loc_descriptor (rtl)
1197 /* Note that for a dynamically sized array, the location we will
1198 generate a description of here will be the lowest numbered location
1199 which is actually within the array. That's *not* necessarily the
1200 same as the zeroth element of the array. */
1202 switch (GET_CODE (rtl))
1206 /* The case of a subreg may arise when we have a local (register)
1207 variable or a formal (register) parameter which doesn't quite
1208 fill up an entire register. For now, just assume that it is
1209 legitimate to make the Dwarf info refer to the whole register
1210 which contains the given subreg. */
1212 rtl = XEXP (rtl, 0);
1217 /* Whenever a register number forms a part of the description of
1218 the method for calculating the (dynamic) address of a memory
1219 resident object, Dwarf rules require the register number to
1220 be referred to as a "base register". This distinction is not
1221 based in any way upon what category of register the hardware
1222 believes the given register belongs to. This is strictly
1223 Dwarf terminology we're dealing with here. */
1225 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1226 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1227 DBX_REGISTER_NUMBER (REGNO (rtl)));
1231 output_mem_loc_descriptor (XEXP (rtl, 0));
1232 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1237 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1238 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1242 output_mem_loc_descriptor (XEXP (rtl, 0));
1243 output_mem_loc_descriptor (XEXP (rtl, 1));
1244 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1248 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1249 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1257 /* Output a proper Dwarf location descriptor for a variable or parameter
1258 which is either allocated in a register or in a memory location. For
1259 a register, we just generate an OP_REG and the register number. For a
1260 memory location we provide a Dwarf postfix expression describing how to
1261 generate the (dynamic) address of the object onto the address stack. */
1264 output_loc_descriptor (rtl)
1267 switch (GET_CODE (rtl))
1271 /* The case of a subreg may arise when we have a local (register)
1272 variable or a formal (register) parameter which doesn't quite
1273 fill up an entire register. For now, just assume that it is
1274 legitimate to make the Dwarf info refer to the whole register
1275 which contains the given subreg. */
1277 rtl = XEXP (rtl, 0);
1281 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1282 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1283 DBX_REGISTER_NUMBER (REGNO (rtl)));
1287 output_mem_loc_descriptor (XEXP (rtl, 0));
1291 abort (); /* Should never happen */
1295 /* Given a tree node describing an array bound (either lower or upper)
1296 output a representation for that bound. */
1299 output_bound_representation (bound, dim_num, u_or_l)
1300 register tree bound;
1301 register unsigned dim_num; /* For multi-dimensional arrays. */
1302 register char u_or_l; /* Designates upper or lower bound. */
1304 switch (TREE_CODE (bound))
1310 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1313 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1314 (unsigned) TREE_INT_CST_LOW (bound));
1317 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1321 bound = TREE_OPERAND (bound, 0);
1322 /* ... fall thru... */
1326 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1327 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1329 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1330 current_dienum, dim_num, u_or_l);
1332 sprintf (end_label, BOUND_END_LABEL_FMT,
1333 current_dienum, dim_num, u_or_l);
1335 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1336 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1338 /* If we are working on a bound for a dynamic dimension in C,
1339 the dynamic dimension in question had better have a static
1340 (zero) lower bound and a dynamic *upper* bound. */
1345 /* If optimization is turned on, the SAVE_EXPRs that describe
1346 how to access the upper bound values are essentially bogus.
1347 They only describe (at best) how to get at these values at
1348 the points in the generated code right after they have just
1349 been computed. Worse yet, in the typical case, the upper
1350 bound values will not even *be* computed in the optimized
1351 code, so these SAVE_EXPRs are entirely bogus.
1353 In order to compensate for this fact, we check here to see
1354 if optimization is enabled, and if so, we effectively create
1355 an empty location description for the (unknown and unknowable)
1358 This should not cause too much trouble for existing (stupid?)
1359 debuggers because they have to deal with empty upper bounds
1360 location descriptions anyway in order to be able to deal with
1361 incomplete array types.
1363 Of course an intelligent debugger (GDB?) should be able to
1364 comprehend that a missing upper bound specification in a
1365 array type used for a storage class `auto' local array variable
1366 indicates that the upper bound is both unknown (at compile-
1367 time) and unknowable (at run-time) due to optimization.
1371 output_loc_descriptor
1372 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, 0));
1374 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1383 /* Recursive function to output a sequence of value/name pairs for
1384 enumeration constants in reversed order. This is called from
1385 enumeration_type_die. */
1388 output_enumeral_list (link)
1393 output_enumeral_list (TREE_CHAIN (link));
1394 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1395 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1396 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1397 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1401 /****************************** attributes *********************************/
1403 /* The following routines are responsible for writing out the various types
1404 of Dwarf attributes (and any following data bytes associated with them).
1405 These routines are listed in order based on the numerical codes of their
1406 associated attributes. */
1408 /* Generate an AT_sibling attribute. */
1411 sibling_attribute ()
1413 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1415 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
1416 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
1417 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1420 /* Output the form of location attributes suitable for whole variables and
1421 whole parameters. Note that the location attributes for struct fields
1422 are generated by the routine `data_member_location_attribute' below. */
1425 location_attribute (rtl)
1428 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1429 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1431 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1432 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1433 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1434 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1435 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1437 /* Handle a special case. If we are about to output a location descriptor
1438 for a variable or parameter which has been optimized out of existence,
1439 don't do that. Instead we output a zero-length location descriptor
1440 value as part of the location attribute. Note that we cannot simply
1441 suppress the entire location attribute, because the absence of a
1442 location attribute in certain kinds of DIEs is used to indicate some-
1443 thing entirely different... i.e. that the DIE represents an object
1444 declaration, but not a definition. So sayeth the PLSIG. */
1446 if (((GET_CODE (rtl) != REG) || (REGNO (rtl) < FIRST_PSEUDO_REGISTER))
1447 && ((GET_CODE (rtl) != SUBREG)
1448 || (REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER)))
1449 output_loc_descriptor (eliminate_regs (rtl, 0, 0));
1451 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1454 /* Output the specialized form of location attribute used for data members
1458 data_member_location_attribute (decl)
1461 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1462 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1464 if (TREE_CODE (decl) == ERROR_MARK)
1467 if (TREE_CODE (decl) != FIELD_DECL)
1470 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1471 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1472 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1473 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1474 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1475 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1477 /* This is pretty strange, but existing compilers producing DWARF
1478 apparently calculate the byte offset of a field differently
1479 depending upon whether or not it is a bit-field. If the given
1480 field is *not* a bit-field, then the offset is simply the
1481 the byte offset of the given field from the beginning of the
1482 struct. For bit-fields however, the offset is the offset (in
1483 bytes) of the beginning of the *containing word* from the
1484 beginning of the whole struct. */
1486 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1487 (DECL_BIT_FIELD_TYPE (decl))
1488 ? BITFIELD_OFFSET_WORDS_IN_UNITS (decl)
1489 : BITFIELD_OFFSET_UNITS (decl));
1490 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1491 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1494 /* Output an AT_const_value attribute for a variable or a parameter which
1495 does not have a "location" either in memory or in a register. These
1496 things can arise in GNU C when a constant is passed as an actual
1497 parameter to an inlined function. They can also arise in C++ where
1498 declared constants do not necessarily get memory "homes". */
1501 const_value_attribute (rtl)
1504 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1505 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1507 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
1508 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1509 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1510 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
1511 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1513 switch (GET_CODE (rtl))
1516 /* Note that a CONST_INT rtx could represent either an integer or
1517 a floating-point constant. A CONST_INT is used whenever the
1518 constant will fit into a single word. In all such cases, the
1519 original mode of the constant value is wiped out, and the
1520 CONST_INT rtx is assigned VOIDmode. Since we no longer have
1521 precise mode information for these constants, we always just
1522 output them using 4 bytes. */
1524 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
1528 /* Note that a CONST_DOUBLE rtx could represent either an integer
1529 or a floating-point constant. A CONST_DOUBLE is used whenever
1530 the constant requires more than one word in order to be adequately
1531 represented. In all such cases, the original mode of the constant
1532 value is preserved as the mode of the CONST_DOUBLE rtx, but for
1533 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
1535 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
1536 (unsigned) CONST_DOUBLE_HIGH (rtl),
1537 (unsigned) CONST_DOUBLE_LOW (rtl));
1541 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
1547 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1551 /* In cases where an inlined instance of an inline function is passed
1552 the address of an `auto' variable (which is local to the caller)
1553 we can get a situation where the DECL_RTL of the artificial
1554 local variable (for the inlining) which acts as a stand-in for
1555 the corresponding formal parameter (of the inline function)
1556 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
1557 This is not exactly a compile-time constant expression, but it
1558 isn't the address of the (artificial) local variable either.
1559 Rather, it represents the *value* which the artificial local
1560 variable always has during its lifetime. We currently have no
1561 way to represent such quasi-constant values in Dwarf, so for now
1562 we just punt and generate an AT_const_value attribute with form
1563 FORM_BLOCK4 and a length of zero. */
1567 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1570 /* Generate *either* an AT_location attribute or else an AT_const_value
1571 data attribute for a variable or a parameter. We generate the
1572 AT_const_value attribute only in those cases where the given
1573 variable or parameter does not have a true "location" either in
1574 memory or in a register. This can happen (for example) when a
1575 constant is passed as an actual argument in a call to an inline
1576 function. (It's possible that these things can crop up in other
1577 ways also.) Note that one type of constant value which can be
1578 passed into an inlined function is a constant pointer. This can
1579 happen for example if an actual argument in an inlined function
1580 call evaluates to a compile-time constant address. */
1583 location_or_const_value_attribute (decl)
1588 if (TREE_CODE (decl) == ERROR_MARK)
1591 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
1594 /* It's not really clear what existing Dwarf debuggers need or expect
1595 as regards to location information for formal parameters. A later
1596 version of the Dwarf specification should resolve such issues, but
1597 for the time being, we assume here that debuggers want information
1598 about the location where the parameter was passed into the function.
1599 That seems to be what USL's CI5 compiler generates. Note that this
1600 will probably be different from the place where the parameter actual
1601 resides during function execution. Dwarf Version 2 will provide us
1602 with a means to describe that location also, but for now we can only
1603 describe the "passing" location. */
1605 #if 1 /* This is probably right, but it leads to a lot of trouble.
1606 Fixing one problem has been exposing another,
1607 all of which seemed to have no ill effects before.
1608 Let's try it again for now. */
1609 rtl = (TREE_CODE (decl) == PARM_DECL)
1610 ? DECL_INCOMING_RTL (decl)
1613 rtl = DECL_RTL (decl);
1619 switch (GET_CODE (rtl))
1627 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
1628 const_value_attribute (rtl);
1634 location_attribute (rtl);
1638 abort (); /* Should never happen. */
1642 /* Generate an AT_name attribute given some string value to be included as
1643 the value of the attribute. If the name is null, don't do anything. */
1646 name_attribute (name_string)
1647 register char *name_string;
1649 if (name_string && *name_string)
1651 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
1652 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
1657 fund_type_attribute (ft_code)
1658 register unsigned ft_code;
1660 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
1661 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
1665 mod_fund_type_attribute (type, decl_const, decl_volatile)
1667 register int decl_const;
1668 register int decl_volatile;
1670 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1671 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1673 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
1674 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
1675 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
1676 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1677 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1678 write_modifier_bytes (type, decl_const, decl_volatile);
1679 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
1680 fundamental_type_code (root_type (type)));
1681 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1685 user_def_type_attribute (type)
1688 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
1690 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
1691 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
1692 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
1696 mod_u_d_type_attribute (type, decl_const, decl_volatile)
1698 register int decl_const;
1699 register int decl_volatile;
1701 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1702 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1703 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
1705 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
1706 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
1707 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
1708 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1709 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1710 write_modifier_bytes (type, decl_const, decl_volatile);
1711 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
1712 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
1713 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1717 ordering_attribute (ordering)
1718 register unsigned ordering;
1720 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
1721 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
1724 /* Note that the block of subscript information for an array type also
1725 includes information about the element type of type given array type. */
1728 subscript_data_attribute (type)
1731 register unsigned dimension_number;
1732 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1733 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1735 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
1736 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
1737 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
1738 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1739 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1741 /* The GNU compilers represent multidimensional array types as sequences
1742 of one dimensional array types whose element types are themselves array
1743 types. Here we squish that down, so that each multidimensional array
1744 type gets only one array_type DIE in the Dwarf debugging info. The
1745 draft Dwarf specification say that we are allowed to do this kind
1746 of compression in C (because there is no difference between an
1747 array or arrays and a multidimensional array in C) but for other
1748 source languages (e.g. Ada) we probably shouldn't do this. */
1750 for (dimension_number = 0;
1751 TREE_CODE (type) == ARRAY_TYPE;
1752 type = TREE_TYPE (type), dimension_number++)
1754 register tree domain = TYPE_DOMAIN (type);
1756 /* Arrays come in three flavors. Unspecified bounds, fixed
1757 bounds, and (in GNU C only) variable bounds. Handle all
1758 three forms here. */
1762 /* We have an array type with specified bounds. */
1764 register tree lower = TYPE_MIN_VALUE (domain);
1765 register tree upper = TYPE_MAX_VALUE (domain);
1767 /* Handle only fundamental types as index types for now. */
1769 if (! type_is_fundamental (domain))
1772 /* Output the representation format byte for this dimension. */
1774 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
1776 TREE_CODE (lower) == INTEGER_CST,
1777 TREE_CODE (upper) == INTEGER_CST));
1779 /* Output the index type for this dimension. */
1781 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
1782 fundamental_type_code (domain));
1784 /* Output the representation for the lower bound. */
1786 output_bound_representation (lower, dimension_number, 'l');
1788 /* Output the representation for the upper bound. */
1790 output_bound_representation (upper, dimension_number, 'u');
1794 /* We have an array type with an unspecified length. For C and
1795 C++ we can assume that this really means that (a) the index
1796 type is an integral type, and (b) the lower bound is zero.
1797 Note that Dwarf defines the representation of an unspecified
1798 (upper) bound as being a zero-length location description. */
1800 /* Output the array-bounds format byte. */
1802 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
1804 /* Output the (assumed) index type. */
1806 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
1808 /* Output the (assumed) lower bound (constant) value. */
1810 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1812 /* Output the (empty) location description for the upper bound. */
1814 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
1818 /* Output the prefix byte that says that the element type is comming up. */
1820 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
1822 /* Output a representation of the type of the elements of this array type. */
1824 type_attribute (type, 0, 0);
1826 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1830 byte_size_attribute (tree_node)
1831 register tree tree_node;
1833 register unsigned size;
1835 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
1836 switch (TREE_CODE (tree_node))
1845 size = int_size_in_bytes (tree_node);
1850 register unsigned words;
1851 register unsigned bits;
1853 bits = TREE_INT_CST_LOW (DECL_SIZE (tree_node));
1854 words = (bits + (BITS_PER_WORD-1)) / BITS_PER_WORD;
1855 size = words * (BITS_PER_WORD / BITS_PER_UNIT);
1862 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
1865 /* For a FIELD_DECL node which represents a bit field, output an attribute
1866 which specifies the distance in bits from the start of the *word*
1867 containing the given field to the first bit of the field. */
1870 bit_offset_attribute (decl)
1873 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
1874 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
1876 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
1877 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
1878 BITFIELD_OFFSET_BITS (decl) % (unsigned) BITS_PER_WORD);
1881 /* For a FIELD_DECL node which represents a bit field, output an attribute
1882 which specifies the length in bits of the given field. */
1885 bit_size_attribute (decl)
1888 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
1889 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
1891 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
1892 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1893 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
1896 /* The following routine outputs the `element_list' attribute for enumeration
1897 type DIEs. The element_lits attribute includes the names and values of
1898 all of the enumeration constants associated with the given enumeration
1902 element_list_attribute (element)
1903 register tree element;
1905 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1906 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1908 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
1909 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
1910 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
1911 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
1912 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1914 /* Here we output a list of value/name pairs for each enumeration constant
1915 defined for this enumeration type (as required), but we do it in REVERSE
1916 order. The order is the one required by the draft #5 Dwarf specification
1917 published by the UI/PLSIG. */
1919 output_enumeral_list (element); /* Recursively output the whole list. */
1921 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1924 /* Generate an AT_stmt_list attribute. These are normally present only in
1925 DIEs with a TAG_compile_unit tag. */
1928 stmt_list_attribute (label)
1929 register char *label;
1931 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
1932 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
1933 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
1936 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
1937 for a subroutine DIE. */
1940 low_pc_attribute (asm_low_label)
1941 register char *asm_low_label;
1943 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
1944 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
1947 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
1951 high_pc_attribute (asm_high_label)
1952 register char *asm_high_label;
1954 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
1955 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
1958 /* Generate an AT_language attribute given a LANG value. These attributes
1959 are used only within TAG_compile_unit DIEs. */
1962 language_attribute (language_code)
1963 register unsigned language_code;
1965 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
1966 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
1970 member_attribute (context)
1971 register tree context;
1973 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1975 /* Generate this attribute only for members in C++. */
1978 && (TREE_CODE (context) == RECORD_TYPE
1979 || TREE_CODE (context) == UNION_TYPE))
1981 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
1982 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
1983 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1988 string_length_attribute (upper_bound)
1989 register tree upper_bound;
1991 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1992 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1994 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
1995 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
1996 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
1997 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1998 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1999 output_bound_representation (upper_bound, 0, 'u');
2000 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2004 comp_dir_attribute (dirname)
2005 register char *dirname;
2007 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2008 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2012 sf_names_attribute (sf_names_start_label)
2013 register char *sf_names_start_label;
2015 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2016 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2017 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2021 src_info_attribute (src_info_start_label)
2022 register char *src_info_start_label;
2024 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2025 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2026 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2030 mac_info_attribute (mac_info_start_label)
2031 register char *mac_info_start_label;
2033 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2034 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2035 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2039 prototyped_attribute (func_type)
2040 register tree func_type;
2042 if ((strcmp (language_string, "GNU C") == 0)
2043 && (TYPE_ARG_TYPES (func_type) != NULL))
2045 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2046 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2051 producer_attribute (producer)
2052 register char *producer;
2054 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2055 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2059 inline_attribute (decl)
2062 if (TREE_INLINE (decl))
2064 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2065 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2070 containing_type_attribute (containing_type)
2071 register tree containing_type;
2073 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2075 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2076 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2077 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2080 /************************* end of attributes *****************************/
2082 /********************* utility routines for DIEs *************************/
2084 /* Many forms of DIEs contain a "type description" part. The following
2085 routine writes out these "type descriptor" parts. */
2088 type_attribute (type, decl_const, decl_volatile)
2090 register int decl_const;
2091 register int decl_volatile;
2093 register enum tree_code code = TREE_CODE (type);
2094 register int root_type_modified;
2096 if (TREE_CODE (type) == ERROR_MARK)
2099 /* Handle a special case. For functions whose return type is void,
2100 we generate *no* type attribute. (Note that no object may have
2101 type `void', so this only applies to function return types. */
2103 if (TREE_CODE (type) == VOID_TYPE)
2106 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2107 || decl_const || decl_volatile
2108 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2110 if (type_is_fundamental (root_type (type)))
2111 if (root_type_modified)
2112 mod_fund_type_attribute (type, decl_const, decl_volatile);
2114 fund_type_attribute (fundamental_type_code (type));
2116 if (root_type_modified)
2117 mod_u_d_type_attribute (type, decl_const, decl_volatile);
2119 user_def_type_attribute (type);
2122 /* Given a tree pointer to a struct, class, union, or enum type node, return
2123 a pointer to the (string) tag name for the given type, or zero if the
2124 type was declared without a tag. */
2130 register char *name = 0;
2132 if (TYPE_NAME (type) != 0)
2134 register tree t = 0;
2136 /* Find the IDENTIFIER_NODE for the type name. */
2137 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2138 t = TYPE_NAME (type);
2140 /* The g++ front end makes the TYPE_NAME of *each* tagged type point
2141 to a TYPE_DECL node, regardless of whether or not a `typedef' was
2142 involved. This is distinctly different from what the gcc front-end
2143 does. It always makes the TYPE_NAME for each tagged type be either
2144 NULL (signifying an anonymous tagged type) or else a pointer to an
2145 IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf
2146 for both C and C++, but given this inconsistancy in the TREE
2147 representation of tagged types for C and C++ in the GNU front-ends,
2148 we cannot support both languages correctly unless we introduce some
2149 front-end specific code here, and rms objects to that, so we can
2150 only generate correct Dwarf for one of these two languages. C is
2151 more important, so for now we'll do the right thing for C and let
2155 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2156 t = DECL_NAME (TYPE_NAME (type));
2158 /* Now get the name as a string, or invent one. */
2160 name = IDENTIFIER_POINTER (t);
2163 return (name == 0 || *name == '\0') ? 0 : name;
2169 /* Start by checking if the pending_sibling_stack needs to be expanded.
2170 If necessary, expand it. */
2172 if (pending_siblings == pending_siblings_allocated)
2174 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
2175 pending_sibling_stack
2176 = (unsigned *) xrealloc (pending_sibling_stack,
2177 pending_siblings_allocated * sizeof(unsigned));
2181 NEXT_DIE_NUM = next_unused_dienum++;
2184 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
2194 member_declared_type (member)
2195 register tree member;
2197 return (DECL_BIT_FIELD_TYPE (member))
2198 ? DECL_BIT_FIELD_TYPE (member)
2199 : TREE_TYPE (member);
2202 /******************************* DIEs ************************************/
2204 /* Output routines for individual types of DIEs. */
2206 /* Note that every type of DIE (except a null DIE) gets a sibling. */
2209 output_array_type_die (arg)
2212 register tree type = arg;
2214 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
2215 sibling_attribute ();
2216 equate_type_number_to_die_number (type);
2217 member_attribute (TYPE_CONTEXT (type));
2219 /* I believe that we can default the array ordering. SDB will probably
2220 do the right things even if AT_ordering is not present. It's not
2221 even an issue until we start to get into multidimensional arrays
2222 anyway. If SDB is shown to do the wrong thing in those cases, then
2223 we'll have to put the AT_ordering attribute back in, but only for
2224 multidimensional array. (After all, we don't want to waste space
2225 in the .debug section now do we?) */
2228 ordering_attribute (ORD_row_major);
2231 subscript_data_attribute (type);
2235 output_set_type_die (arg)
2238 register tree type = arg;
2240 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
2241 sibling_attribute ();
2242 equate_type_number_to_die_number (type);
2243 member_attribute (TYPE_CONTEXT (type));
2244 type_attribute (TREE_TYPE (type), 0, 0);
2248 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
2250 output_entry_point_die (arg)
2253 register tree decl = arg;
2254 register tree type = TREE_TYPE (decl);
2255 register tree return_type = TREE_TYPE (type);
2257 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
2258 sibling_attribute ();
2260 if (DECL_NAME (decl))
2261 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2262 member_attribute (DECL_CONTEXT (decl));
2263 type_attribute (return_type, 0, 0);
2267 /* Output a DIE to represent an enumeration type. Note that these DIEs
2268 include all of the information about the enumeration values also.
2269 This information is encoded into the element_list attribute. */
2272 output_enumeration_type_die (arg)
2275 register tree type = arg;
2277 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2278 sibling_attribute ();
2279 equate_type_number_to_die_number (type);
2280 name_attribute (type_tag (type));
2281 member_attribute (TYPE_CONTEXT (type));
2283 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
2284 given enum type is incomplete, do not generate the AT_byte_size
2285 attribute or the AT_element_list attribute. */
2287 if (TYPE_SIZE (type))
2289 byte_size_attribute (type);
2290 element_list_attribute (TYPE_FIELDS (type));
2294 /* Output a DIE to represent either a real live formal parameter decl or
2295 to represent just the type of some formal parameter position in some
2298 Note that this routine is a bit unusual because its argument may be
2299 either a PARM_DECL node or else some sort of a ..._TYPE node. If it's
2300 the formar then this function is being called to output a real live
2301 formal parameter declaration. If it's the latter, then this function
2302 is only being called to output a TAG_formal_parameter DIE to stand as
2303 a placeholder for some formal argument type of some subprogram type. */
2306 output_formal_parameter_die (arg)
2309 register tree decl = arg;
2312 if (TREE_CODE (decl) == PARM_DECL)
2313 type = TREE_TYPE (decl);
2316 type = decl; /* we were called with a type, not a decl */
2320 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
2321 sibling_attribute ();
2324 if (DECL_NAME (decl))
2325 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2326 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2327 location_or_const_value_attribute (decl);
2330 type_attribute (type, 0, 0);
2333 /* Output a DIE to represent a declared function (either file-scope
2334 or block-local) which has "external linkage" (according to ANSI-C). */
2337 output_global_subroutine_die (arg)
2340 register tree decl = arg;
2341 register tree type = TREE_TYPE (decl);
2342 register tree return_type = TREE_TYPE (type);
2344 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
2345 sibling_attribute ();
2347 if (DECL_NAME (decl))
2348 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2349 inline_attribute (decl);
2350 prototyped_attribute (type);
2351 member_attribute (DECL_CONTEXT (decl));
2352 type_attribute (return_type, 0, 0);
2353 if (!TREE_EXTERNAL (decl))
2355 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2357 low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2358 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2359 high_pc_attribute (func_end_label);
2363 /* Output a DIE to represent a declared data object (either file-scope
2364 or block-local) which has "external linkage" (according to ANSI-C). */
2367 output_global_variable_die (arg)
2370 register tree decl = arg;
2371 register tree type = TREE_TYPE (decl);
2373 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
2374 sibling_attribute ();
2375 if (DECL_NAME (decl))
2376 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2377 member_attribute (DECL_CONTEXT (decl));
2378 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2379 if (!TREE_EXTERNAL (decl))
2380 location_or_const_value_attribute (decl);
2384 /* TAG_inline_subroutine has been retired by the UI/PLSIG. We're
2385 now supposed to use either TAG_subroutine or TAG_global_subroutine
2386 (depending on whether or not the function in question has internal
2387 or external linkage) and we're supposed to just put in an AT_inline
2390 output_inline_subroutine_die (arg)
2393 register tree decl = arg;
2394 register tree type = TREE_TYPE (decl);
2395 register tree return_type = TREE_TYPE (type);
2397 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inline_subroutine);
2398 sibling_attribute ();
2400 if (DECL_NAME (decl))
2401 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2402 prototyped_attribute (type);
2403 member_attribute (DECL_CONTEXT (decl));
2404 type_attribute (return_type, 0, 0);
2406 /* Note: For each inline function which gets an out-of-line body
2407 generated for it, we want to generate AT_low_pc and AT_high_pc
2408 attributes here for the function's out-of-line body.
2410 Unfortunately, the decision as to whether or not to generate an
2411 out-of-line body for any given inline function may not be made
2412 until we reach the end of the containing scope for the given
2413 inline function (because only then will it be known if the
2414 function was ever even called).
2416 For this reason, the output of DIEs representing file-scope inline
2417 functions gets delayed until a special post-pass which happens only
2418 after we have reached the end of the compilation unit. Because of
2419 this mechanism, we can always be sure (by the time we reach here)
2420 that TREE_ASM_WRITTEN(decl) will correctly indicate whether or not
2421 there was an out-of-line body generated for this inline function.
2424 if (!TREE_EXTERNAL (decl))
2426 if (TREE_ASM_WRITTEN (decl))
2428 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2430 low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2431 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2432 high_pc_attribute (func_end_label);
2439 output_label_die (arg)
2442 register tree decl = arg;
2443 register rtx insn = DECL_RTL (decl);
2445 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
2446 sibling_attribute ();
2447 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2449 /* When optimization is enabled (with -O) the code in jump.c and in flow.c
2450 may cause insns representing one of more of the user's own labels to
2451 be deleted. This happens whenever it is determined that a given label
2454 In such cases, we here generate an abbreviated form of a label DIE.
2455 This abbreviated version does *not* have a low_pc attribute. This
2456 should signify to the debugger that the label has been optimized away.
2458 Note that a CODE_LABEL can get deleted either by begin converted into
2459 a NOTE_INSN_DELETED note, or by simply having its INSN_DELETED_P flag
2460 set to true. We handle both cases here.
2463 if (GET_CODE (insn) == CODE_LABEL && ! INSN_DELETED_P (insn))
2465 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2467 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
2468 (unsigned) INSN_UID (insn));
2469 low_pc_attribute (label);
2474 output_lexical_block_die (arg)
2477 register tree stmt = arg;
2478 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2479 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2481 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
2482 sibling_attribute ();
2484 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
2485 low_pc_attribute (begin_label);
2486 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
2487 high_pc_attribute (end_label);
2491 output_inlined_subroutine_die (arg)
2494 register tree stmt = arg;
2495 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2496 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2498 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
2499 sibling_attribute ();
2501 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
2502 low_pc_attribute (begin_label);
2503 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
2504 high_pc_attribute (end_label);
2507 /* Output a DIE to represent a declared data object (either file-scope
2508 or block-local) which has "internal linkage" (according to ANSI-C). */
2511 output_local_variable_die (arg)
2514 register tree decl = arg;
2515 register tree type = TREE_TYPE (decl);
2517 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
2518 sibling_attribute ();
2519 if (DECL_NAME (decl))
2520 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2521 member_attribute (DECL_CONTEXT (decl));
2522 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2523 location_or_const_value_attribute (decl);
2527 output_member_die (arg)
2530 register tree decl = arg;
2532 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
2533 sibling_attribute ();
2534 if (DECL_NAME (decl))
2535 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2536 member_attribute (DECL_CONTEXT (decl));
2537 type_attribute (member_declared_type (decl),
2538 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2539 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
2541 byte_size_attribute (decl);
2542 bit_size_attribute (decl);
2543 bit_offset_attribute (decl);
2545 data_member_location_attribute (decl);
2549 /* Don't generate either pointer_type DIEs or reference_type DIEs. According
2550 to the 4-4-90 Dwarf draft spec (just after requirement #47):
2552 These two type entries are not currently generated by any compiler.
2553 Since the only way to name a pointer (or reference) type is C or C++
2554 is via a "typedef", an entry with the "typedef" tag is generated
2557 We keep this code here just in case these types of DIEs may be needed
2558 to represent certain things in other languages (e.g. Pascal) someday.
2562 output_pointer_type_die (arg)
2565 register tree type = arg;
2567 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
2568 sibling_attribute ();
2569 equate_type_number_to_die_number (type);
2570 member_attribute (TYPE_CONTEXT (type));
2571 type_attribute (TREE_TYPE (type), 0, 0);
2575 output_reference_type_die (arg)
2578 register tree type = arg;
2580 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
2581 sibling_attribute ();
2582 equate_type_number_to_die_number (type);
2583 member_attribute (TYPE_CONTEXT (type));
2584 type_attribute (TREE_TYPE (type), 0, 0);
2588 output_ptr_to_mbr_type_die (arg)
2591 register tree type = arg;
2593 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
2594 sibling_attribute ();
2595 equate_type_number_to_die_number (type);
2596 member_attribute (TYPE_CONTEXT (type));
2597 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
2598 type_attribute (TREE_TYPE (type), 0, 0);
2602 output_compile_unit_die (arg)
2605 register char *main_input_filename = arg;
2607 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
2608 sibling_attribute ();
2610 name_attribute (main_input_filename);
2615 sprintf (producer, "%s %s", language_string, version_string);
2616 producer_attribute (producer);
2619 if (strcmp (language_string, "GNU C++") == 0)
2620 language_attribute (LANG_C_PLUS_PLUS);
2621 else if (flag_traditional)
2622 language_attribute (LANG_C);
2624 language_attribute (LANG_C89);
2625 low_pc_attribute (TEXT_BEGIN_LABEL);
2626 high_pc_attribute (TEXT_END_LABEL);
2627 if (debug_info_level >= DINFO_LEVEL_NORMAL)
2628 stmt_list_attribute (LINE_BEGIN_LABEL);
2629 last_filename = xstrdup (main_input_filename);
2632 char *wd = getpwd ();
2634 comp_dir_attribute (wd);
2637 if (debug_info_level >= DINFO_LEVEL_NORMAL)
2639 sf_names_attribute (SFNAMES_BEGIN_LABEL);
2640 src_info_attribute (SRCINFO_BEGIN_LABEL);
2641 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
2642 mac_info_attribute (MACINFO_BEGIN_LABEL);
2647 output_string_type_die (arg)
2650 register tree type = arg;
2652 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
2653 sibling_attribute ();
2654 member_attribute (TYPE_CONTEXT (type));
2656 /* Fudge the string length attribute for now. */
2658 string_length_attribute (
2659 TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
2663 output_structure_type_die (arg)
2666 register tree type = arg;
2668 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
2669 sibling_attribute ();
2670 equate_type_number_to_die_number (type);
2671 name_attribute (type_tag (type));
2672 member_attribute (TYPE_CONTEXT (type));
2674 /* If this type has been completed, then give it a byte_size attribute
2675 and prepare to give a list of members. Otherwise, don't do either of
2676 these things. In the latter case, we will not be generating a list
2677 of members (since we don't have any idea what they might be for an
2678 incomplete type). */
2680 if (TYPE_SIZE (type))
2683 byte_size_attribute (type);
2687 /* Output a DIE to represent a declared function (either file-scope
2688 or block-local) which has "internal linkage" (according to ANSI-C). */
2691 output_local_subroutine_die (arg)
2694 register tree decl = arg;
2695 register tree type = TREE_TYPE (decl);
2696 register tree return_type = TREE_TYPE (type);
2697 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2699 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
2700 sibling_attribute ();
2702 if (DECL_NAME (decl))
2703 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2704 inline_attribute (decl);
2705 prototyped_attribute (type);
2706 member_attribute (DECL_CONTEXT (decl));
2707 type_attribute (return_type, 0, 0);
2709 /* Avoid getting screwed up in cases where a function was declared static
2710 but where no definition was ever given for it. */
2712 if (TREE_ASM_WRITTEN (decl))
2714 low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2715 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2716 high_pc_attribute (func_end_label);
2721 output_subroutine_type_die (arg)
2724 register tree type = arg;
2725 register tree return_type = TREE_TYPE (type);
2727 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
2728 sibling_attribute ();
2730 equate_type_number_to_die_number (type);
2731 prototyped_attribute (type);
2732 member_attribute (TYPE_CONTEXT (type));
2733 type_attribute (return_type, 0, 0);
2737 output_typedef_die (arg)
2740 register tree decl = arg;
2741 register tree type = TREE_TYPE (decl);
2743 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
2744 sibling_attribute ();
2745 if (DECL_NAME (decl))
2746 name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
2747 member_attribute (DECL_CONTEXT (decl));
2748 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2752 output_union_type_die (arg)
2755 register tree type = arg;
2757 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
2758 sibling_attribute ();
2759 equate_type_number_to_die_number (type);
2760 name_attribute (type_tag (type));
2761 member_attribute (TYPE_CONTEXT (type));
2763 /* If this type has been completed, then give it a byte_size attribute
2764 and prepare to give a list of members. Otherwise, don't do either of
2765 these things. In the latter case, we will not be generating a list
2766 of members (since we don't have any idea what they might be for an
2767 incomplete type). */
2769 if (TYPE_SIZE (type))
2772 byte_size_attribute (type);
2776 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
2777 at the end of an (ANSI prototyped) formal parameters list. */
2780 output_unspecified_parameters_die (arg)
2783 register tree decl_or_type = arg;
2785 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
2786 sibling_attribute ();
2788 /* This kludge is here only for the sake of being compatible with what
2789 the USL CI5 C compiler does. The specification of Dwarf Version 1
2790 doesn't say that TAG_unspecified_parameters DIEs should contain any
2791 attributes other than the AT_sibling attribute, but they are certainly
2792 allowed to contain additional attributes, and the CI5 compiler
2793 generates AT_name, AT_fund_type, and AT_location attributes within
2794 TAG_unspecified_parameters DIEs which appear in the child lists for
2795 DIEs representing function definitions, so we do likewise here. */
2797 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
2799 name_attribute ("...");
2800 fund_type_attribute (FT_pointer);
2801 /* location_attribute (?); */
2806 output_padded_null_die (arg)
2809 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
2812 /*************************** end of DIEs *********************************/
2814 /* Generate some type of DIE. This routine generates the generic outer
2815 wrapper stuff which goes around all types of DIE's (regardless of their
2816 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
2817 DIE-length word, followed by the guts of the DIE itself. After the guts
2818 of the DIE, there must always be a terminator label for the DIE. */
2821 output_die (die_specific_output_function, param)
2822 register void (*die_specific_output_function)();
2823 register void *param;
2825 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2826 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2828 current_dienum = NEXT_DIE_NUM;
2829 NEXT_DIE_NUM = next_unused_dienum;
2831 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2832 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
2834 /* Write a label which will act as the name for the start of this DIE. */
2836 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2838 /* Write the DIE-length word. */
2840 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2842 /* Fill in the guts of the DIE. */
2844 next_unused_dienum++;
2845 die_specific_output_function (param);
2847 /* Write a label which will act as the name for the end of this DIE. */
2849 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2853 end_sibling_chain ()
2855 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2857 current_dienum = NEXT_DIE_NUM;
2858 NEXT_DIE_NUM = next_unused_dienum;
2860 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
2862 /* Write a label which will act as the name for the start of this DIE. */
2864 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2866 /* Write the DIE-length word. */
2868 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
2873 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
2874 TAG_unspecified_parameters DIE) to represent the types of the formal
2875 parameters as specified in some function type specification (except
2876 for those which appear as part of a function *definition*).
2878 Note that we must be careful here to output all of the parameter DIEs
2879 *before* we output any DIEs needed to represent the types of the formal
2880 parameters. This keeps svr4 SDB happy because it (incorrectly) thinks
2881 that the first non-parameter DIE it sees ends the formal parameter list.
2885 output_formal_types (function_or_method_type)
2886 register tree function_or_method_type;
2889 register tree formal_type;
2890 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
2892 /* In the case where we are generating a formal types list for a C++
2893 non-static member function type, skip over the first thing on the
2894 TYPE_ARG_TYPES list because it only represents the type of the
2895 hidden `this pointer'. The debugger should be able to figure
2896 out (without being explicitly told) that this non-static member
2897 function type takes a `this pointer' and should be able to figure
2898 what the type of that hidden parameter is from the AT_member
2899 attribute of the parent TAG_subroutine_type DIE. */
2901 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
2902 first_parm_type = TREE_CHAIN (first_parm_type);
2904 /* Make our first pass over the list of formal parameter types and output
2905 a TAG_formal_parameter DIE for each one. */
2907 for (link = first_parm_type; link; link = TREE_CHAIN (link))
2909 formal_type = TREE_VALUE (link);
2910 if (formal_type == void_type_node)
2913 /* Output a (nameless) DIE to represent the formal parameter itself. */
2915 output_die (output_formal_parameter_die, formal_type);
2918 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
2919 DIE to the end of the parameter list. */
2921 if (formal_type != void_type_node)
2922 output_die (output_unspecified_parameters_die, function_or_method_type);
2924 /* Make our second (and final) pass over the list of formal parameter types
2925 and output DIEs to represent those types (as necessary). */
2927 for (link = TYPE_ARG_TYPES (function_or_method_type);
2929 link = TREE_CHAIN (link))
2931 formal_type = TREE_VALUE (link);
2932 if (formal_type == void_type_node)
2935 output_type (formal_type, function_or_method_type);
2939 /* Remember a type in the pending_types_list. */
2945 if (pending_types == pending_types_allocated)
2947 pending_types_allocated += PENDING_TYPES_INCREMENT;
2949 = (tree *) xrealloc (pending_types_list,
2950 sizeof (tree) * pending_types_allocated);
2952 pending_types_list[pending_types++] = type;
2954 /* Mark the pending type as having been output already (even though
2955 it hasn't been). This prevents the type from being added to the
2956 pending_types_list more than once. */
2958 TREE_ASM_WRITTEN (type) = 1;
2961 /* Return non-zero if it is legitimate to output DIEs to represent a
2962 given type while we are generating the list of child DIEs for some
2963 DIE associated with a given scope.
2965 This function returns non-zero if *either* of the following two conditions
2968 o the type actually belongs to the given scope (as evidenced
2969 by its TYPE_CONTEXT value), or
2971 o the type is anonymous, and the `scope' in question is *not*
2972 a RECORD_TYPE or UNION_TYPE.
2974 In theory, we should be able to generate DIEs for anonymous types
2975 *anywhere* (since the scope of an anonymous type is irrelevant)
2976 however svr4 SDB doesn't want to see other type DIEs within the
2977 lists of child DIEs for a TAG_structure_type or TAG_union_type DIE.
2979 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
2980 or it may point to a BLOCK node (for types local to a block), or to a
2981 FUNCTION_DECL node (for types local to the heading of some function
2982 definition), or to a FUNCTION_TYPE node (for types local to the
2983 prototyped parameter list of a function type specification), or to a
2984 RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types).
2986 The `scope' parameter should likewise be NULL or should point to a
2987 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
2988 node, or a UNION_TYPE node.
2990 This function is used only for deciding when to "pend" and when to
2991 "un-pend" types to/from the pending_types_list.
2993 Note that we sometimes make use of this "type pending" feature in a
2994 rather twisted way to temporarily delay the production of DIEs for the
2995 types of formal parameters. (We do this just to make svr4 SDB happy.)
2996 It order to delay the production of DIEs representing types of formal
2997 parameters, callers of this function supply `fake_containing_scope' as
2998 the `scope' parameter to this function. Given that fake_containing_scope
2999 is *not* the containing scope for *any* other type, the desired effect
3000 is achieved, i.e. output of DIEs representing types is temporarily
3001 suspended, and any type DIEs which would have been output otherwise
3002 are instead placed onto the pending_types_list. Later on, we can force
3003 these (temporarily pended) types to be output simply by calling
3004 `output_pending_types_for_scope' with an actual argument equal to the
3005 true scope of the types we temporarily pended.
3009 type_ok_for_scope (type, scope)
3011 register tree scope;
3013 return (TYPE_CONTEXT (type) == scope
3014 || (TYPE_NAME (type) == NULL
3015 && TREE_CODE (scope) != RECORD_TYPE
3016 && TREE_CODE (scope) != UNION_TYPE));
3019 /* Output any pending types (from the pending_types list) which we can output
3020 now (given the limitations of the scope that we are working on now).
3022 For each type output, remove the given type from the pending_types_list
3023 *before* we try to output it.
3025 Note that we have to process the list in beginning-to-end order,
3026 because the call made here to output_type may cause yet more types
3027 to be added to the end of the list, and we may have to output some
3032 output_pending_types_for_scope (containing_scope)
3033 register tree containing_scope;
3035 register unsigned i;
3037 for (i = 0; i < pending_types; )
3039 register tree type = pending_types_list[i];
3041 if (type_ok_for_scope (type, containing_scope))
3043 register tree *mover;
3044 register tree *limit;
3047 limit = &pending_types_list[pending_types];
3048 for (mover = &pending_types_list[i]; mover < limit; mover++)
3049 *mover = *(mover+1);
3051 /* Un-mark the type as having been output already (because it
3052 hasn't been, really). Then call output_type to generate a
3053 Dwarf representation of it. */
3055 TREE_ASM_WRITTEN (type) = 0;
3056 output_type (type, containing_scope);
3058 /* Don't increment the loop counter in this case because we
3059 have shifted all of the subsequent pending types down one
3060 element in the pending_types_list array. */
3068 output_type (type, containing_scope)
3070 register tree containing_scope;
3072 if (type == 0 || type == error_mark_node)
3075 /* We are going to output a DIE to represent the unqualified version of
3076 of this type (i.e. without any const or volatile qualifiers) so get
3077 the main variant (i.e. the unqualified version) of this type now. */
3079 type = TYPE_MAIN_VARIANT (type);
3081 if (TREE_ASM_WRITTEN (type))
3084 /* Don't generate any DIEs for this type now unless it is OK to do so
3085 (based upon what `type_ok_for_scope' tells us). */
3087 if (! type_ok_for_scope (type, containing_scope))
3093 switch (TREE_CODE (type))
3099 case REFERENCE_TYPE:
3100 /* For these types, all that is required is that we output a DIE
3101 (or a set of DIEs) to represent that "basis" type. */
3102 output_type (TREE_TYPE (type), containing_scope);
3106 /* This code is used for C++ pointer-to-data-member types. */
3107 /* Output a description of the relevant class type. */
3108 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
3109 /* Output a description of the type of the object pointed to. */
3110 output_type (TREE_TYPE (type), containing_scope);
3111 /* Now output a DIE to represent this pointer-to-data-member type
3113 output_die (output_ptr_to_mbr_type_die, type);
3117 output_type (TREE_TYPE (type), containing_scope);
3118 output_die (output_set_type_die, type);
3122 output_type (TREE_TYPE (type), containing_scope);
3123 abort (); /* No way to reprsent these in Dwarf yet! */
3127 output_type (TREE_TYPE (type), containing_scope);
3128 output_die (output_string_type_die, type);
3132 /* Force out return type (in case it wasn't forced out already). */
3133 output_type (TREE_TYPE (type), containing_scope);
3134 output_die (output_subroutine_type_die, type);
3135 output_formal_types (type);
3136 end_sibling_chain ();
3140 /* Force out return type (in case it wasn't forced out already). */
3141 output_type (TREE_TYPE (type), containing_scope);
3142 output_die (output_subroutine_type_die, type);
3143 output_formal_types (type);
3144 end_sibling_chain ();
3149 register tree element_type;
3151 element_type = TREE_TYPE (type);
3152 while (TREE_CODE (element_type) == ARRAY_TYPE)
3153 element_type = TREE_TYPE (element_type);
3155 output_type (element_type, containing_scope);
3156 output_die (output_array_type_die, type);
3164 /* For a non-file-scope tagged type, we can always go ahead and
3165 output a Dwarf description of this type right now, even if
3166 the type in question is still incomplete, because if this
3167 local type *was* ever completed anywhere within its scope,
3168 that complete definition would already have been attached to
3169 this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the
3170 time we reach this point. That's true because of the way the
3171 front-end does its processing of file-scope declarations (of
3172 functions and class types) within which other types might be
3173 nested. The C and C++ front-ends always gobble up such "local
3174 scope" things en-mass before they try to output *any* debugging
3175 information for any of the stuff contained inside them and thus,
3176 we get the benefit here of what is (in effect) a pre-resolution
3177 of forward references to tagged types in local scopes.
3179 Note however that for file-scope tagged types we cannot assume
3180 that such pre-resolution of forward references has taken place.
3181 A given file-scope tagged type may appear to be incomplete when
3182 we reach this point, but it may yet be given a full definition
3183 (at file-scope) later on during compilation. In order to avoid
3184 generating a premature (and possibly incorrect) set of Dwarf
3185 DIEs for such (as yet incomplete) file-scope tagged types, we
3186 generate nothing at all for as-yet incomplete file-scope tagged
3187 types here unless we are making our special "finalization" pass
3188 for file-scope things at the very end of compilation. At that
3189 time, we will certainly know as much about each file-scope tagged
3190 type as we are ever going to know, so at that point in time, we
3191 can safely generate correct Dwarf descriptions for these file-
3195 if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
3196 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
3198 /* Prevent infinite recursion in cases where the type of some
3199 member of this type is expressed in terms of this type itself. */
3201 TREE_ASM_WRITTEN (type) = 1;
3203 /* Output a DIE to represent the tagged type itself. */
3205 switch (TREE_CODE (type))
3208 output_die (output_enumeration_type_die, type);
3209 return; /* a special case -- nothing left to do so just return */
3212 output_die (output_structure_type_die, type);
3216 output_die (output_union_type_die, type);
3220 /* If this is not an incomplete type, output descriptions of
3221 each of its members.
3223 Note that as we output the DIEs necessary to represent the
3224 members of this record or union type, we will also be trying
3225 to output DIEs to represent the *types* of those members.
3226 However the `output_type' function (above) will specifically
3227 avoid generating type DIEs for member types *within* the list
3228 of member DIEs for this (containing) type execpt for those
3229 types (of members) which are explicitly marked as also being
3230 members of this (containing) type themselves. The g++ front-
3231 end can force any given type to be treated as a member of some
3232 other (containing) type by setting the TYPE_CONTEXT of the
3233 given (member) type to point to the TREE node representing the
3234 appropriate (containing) type.
3237 if (TYPE_SIZE (type))
3239 register tree member;
3241 /* First output info about the data members and type members. */
3243 for (member = TYPE_FIELDS (type);
3245 member = TREE_CHAIN (member))
3246 output_decl (member, type);
3248 /* Now output info about the function members (if any). */
3250 if (TYPE_METHODS (type))
3251 for (member = TREE_VEC_ELT (TYPE_METHODS (type), 0);
3253 member = TREE_CHAIN (member))
3254 output_decl (member, type);
3256 end_sibling_chain (); /* Terminate member chain. */
3267 break; /* No DIEs needed for fundamental types. */
3269 case LANG_TYPE: /* No Dwarf representation currently defined. */
3276 TREE_ASM_WRITTEN (type) = 1;
3279 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
3280 the things which are local to the given block. */
3286 register int have_significant_locals = 0;
3288 /* Ignore blocks never really used to make RTL. */
3290 if (! stmt || ! TREE_USED (stmt))
3293 /* Determine if this block contains any "significant" local declarations
3294 which we need to output DIEs for. */
3296 if (BLOCK_INLINE_FUNCTION (stmt))
3297 /* The outer scopes for inlinings *must* always be represented. */
3298 have_significant_locals = 1;
3300 if (debug_info_level > DINFO_LEVEL_TERSE)
3301 have_significant_locals = (BLOCK_VARS (stmt) != NULL);
3306 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3307 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
3309 have_significant_locals = 1;
3314 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
3315 DIE for any block which contains no significant local declarations
3316 at all. Rather, in such cases we just call `output_decls_for_scope'
3317 so that any needed Dwarf info for any sub-blocks will get properly
3318 generated. Note that in terse mode, our definition of what constitutes
3319 a "significant" local declaration gets restricted to include only
3320 inlined function instances and local (nested) function definitions. */
3322 if (have_significant_locals)
3324 output_die (BLOCK_INLINE_FUNCTION (stmt)
3325 ? output_inlined_subroutine_die
3326 : output_lexical_block_die,
3328 output_decls_for_scope (stmt);
3329 end_sibling_chain ();
3332 output_decls_for_scope (stmt);
3335 /* Output all of the decls declared within a given scope (also called
3336 a `binding contour') and (recursively) all of it's sub-blocks. */
3339 output_decls_for_scope (stmt)
3342 /* Ignore blocks never really used to make RTL. */
3344 if (! stmt || ! TREE_USED (stmt))
3347 next_block_number++;
3349 /* Output the DIEs to represent all of the data objects, functions,
3350 typedefs, and tagged types declared directly within this block
3351 but not within any nested sub-blocks. */
3356 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3357 output_decl (decl, stmt);
3360 output_pending_types_for_scope (stmt);
3362 /* Output the DIEs to represent all sub-blocks (and the items declared
3363 therein) of this block. */
3366 register tree subblocks;
3368 for (subblocks = BLOCK_SUBBLOCKS (stmt);
3370 subblocks = BLOCK_CHAIN (subblocks))
3371 output_block (subblocks);
3375 /* Output Dwarf .debug information for a decl described by DECL. */
3378 output_decl (decl, containing_scope)
3380 register tree containing_scope;
3382 switch (TREE_CODE (decl))
3388 /* The individual enumerators of an enum type get output when we
3389 output the Dwarf representation of the relevant enum type itself. */
3393 /* If we are in terse mode, don't output any DIEs to represent
3394 mere external function declarations. */
3396 if (TREE_EXTERNAL (decl) && debug_info_level <= DINFO_LEVEL_TERSE)
3399 /* Before we describe the FUNCTION_DECL itself, make sure that we
3400 have described its return type. */
3402 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
3404 /* If the following DIE will represent a function definition for a
3405 function with "extern" linkage, output a special "pubnames" DIE
3406 label just ahead of the actual DIE. A reference to this label
3407 was already generated in the .debug_pubnames section sub-entry
3408 for this function definition. */
3410 if (TREE_PUBLIC (decl))
3412 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3414 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
3415 ASM_OUTPUT_LABEL (asm_out_file, label);
3418 /* Now output a DIE to represent the function itself. */
3420 output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
3421 ? output_global_subroutine_die
3422 : output_local_subroutine_die,
3425 /* Now output descriptions of the arguments for this function.
3426 This gets (unnecessarily?) complex because of the fact that
3427 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
3428 cases where there was a trailing `...' at the end of the formal
3429 parameter list. In order to find out if there was a trailing
3430 ellipsis or not, we must instead look at the type associated
3431 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
3432 If the chain of type nodes hanging off of this FUNCTION_TYPE node
3433 ends with a void_type_node then there should *not* be an ellipsis
3436 /* In the case where we are describing an external function, all
3437 we need to do here (and all we *can* do here) is to describe
3438 the *types* of its formal parameters. */
3440 if (TREE_EXTERNAL (decl))
3441 output_formal_types (TREE_TYPE (decl));
3444 register tree arg_decls = DECL_ARGUMENTS (decl);
3446 /* In the case where the FUNCTION_DECL represents a C++ non-static
3447 member function, skip over the first thing on the DECL_ARGUMENTS
3448 chain. It only represents the hidden `this pointer' parameter
3449 and the debugger should know implicitly that non-static member
3450 functions have such a thing, and should be able to figure out
3451 exactly what the type of each `this pointer' is (from the
3452 AT_member attribute of the parent TAG_subroutine DIE) without
3453 being explicitly told. */
3455 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
3456 arg_decls = TREE_CHAIN (arg_decls);
3459 register tree last_arg;
3461 last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK)
3462 ? tree_last (arg_decls)
3465 /* Generate DIEs to represent all known formal parameters, but
3466 don't do it if this looks like a varargs function. A given
3467 function is considered to be a varargs function if (and only
3468 if) its last named argument is named `__builtin_va_alist'. */
3471 || ! DECL_NAME (last_arg)
3472 || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)),
3473 "__builtin_va_alist"))
3477 /* WARNING! Kludge zone ahead! Here we have a special
3478 hack for svr4 SDB compatibility. Instead of passing the
3479 current FUNCTION_DECL node as the second parameter (i.e.
3480 the `containing_scope' parameter) to `output_decl' (as
3481 we ought to) we instead pass a pointer to our own private
3482 fake_containing_scope node. That node is a RECORD_TYPE
3483 node which NO OTHER TYPE may ever actually be a member of.
3485 This pointer will ultimately get passed into `output_type'
3486 as its `containing_scope' parameter. `Output_type' will
3487 then perform its part in the hack... i.e. it will pend
3488 the type of the formal parameter onto the pending_types
3489 list. Later on, when we are done generating the whole
3490 sequence of formal parameter DIEs for this function
3491 definition, we will un-pend all previously pended types
3492 of formal parameters for this function definition.
3494 This whole kludge prevents any type DIEs from being
3495 mixed in with the formal parameter DIEs. That's good
3496 because svr4 SDB believes that the list of formal
3497 parameter DIEs for a function ends wherever the first
3498 non-formal-parameter DIE appears. Thus, we have to
3499 keep the formal parameter DIEs segregated. They must
3500 all appear (consecutively) at the start of the list of
3501 children for the DIE representing the function definition.
3502 Then (and only then) may we output any additional DIEs
3503 needed to represent the types of these formal parameters.
3506 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
3507 if (TREE_CODE (parm) == PARM_DECL)
3508 output_decl (parm, fake_containing_scope);
3510 /* Now that we have finished generating all of the DIEs to
3511 represent the formal parameters themselves, force out
3512 any DIEs needed to represent their types. We do this
3513 simply by un-pending all previously pended types which
3514 can legitimately go into the chain of children DIEs for
3515 the current FUNCTION_DECL. */
3517 output_pending_types_for_scope (decl);
3521 /* Now try to decide if we should put an ellipsis at the end. */
3524 register int has_ellipsis = TRUE; /* default assumption */
3525 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
3529 /* This function declaration/definition was prototyped. */
3531 /* If the list of formal argument types ends with a
3532 void_type_node, then the formals list did *not* end
3533 with an ellipsis. */
3535 if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
3536 has_ellipsis = FALSE;
3540 /* This function declaration/definition was not prototyped. */
3542 /* Note that all non-prototyped function *declarations* are
3543 assumed to represent varargs functions (until proven
3546 if (DECL_INITIAL (decl)) /* if this is a func definition */
3549 has_ellipsis = FALSE; /* no args == (void) */
3552 /* For a non-prototyped function definition which
3553 declares one or more formal parameters, if the name
3554 of the first formal parameter is *not*
3555 __builtin_va_alist then we must assume that this
3556 is *not* a varargs function. */
3558 if (DECL_NAME (arg_decls)
3559 && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
3560 "__builtin_va_alist"))
3561 has_ellipsis = FALSE;
3567 output_die (output_unspecified_parameters_die, decl);
3571 /* Output Dwarf info for all of the stuff within the body of the
3572 function (if it has one - it may be just a declaration). */
3575 register tree outer_scope = DECL_INITIAL (decl);
3577 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
3579 /* Note that here, `outer_scope' is a pointer to the outermost
3580 BLOCK node created to represent the body of a function.
3581 This outermost BLOCK actually represents the outermost
3582 binding contour for the function, i.e. the contour in which
3583 the function's formal parameters get declared. Just within
3584 this contour, there will be another (nested) BLOCK which
3585 represents the function's outermost block. We don't want
3586 to generate a lexical_block DIE to represent the outermost
3587 block of a function body, because that is not really an
3588 independent scope according to ANSI C rules. Rather, it is
3589 the same scope in which the parameters were declared and
3590 for Dwarf, we do not generate a TAG_lexical_block DIE for
3591 that scope. We must however see to it that the LABEL_DECLs
3592 associated with `outer_scope' get DIEs generated for them. */
3595 register tree label;
3597 for (label = BLOCK_VARS (outer_scope);
3599 label = TREE_CHAIN (label))
3600 output_decl (label, outer_scope);
3603 output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
3605 /* Finally, force out any pending types which are local to the
3606 outermost block of this function definition. These will
3607 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
3610 output_pending_types_for_scope (decl);
3614 /* Generate a terminator for the list of stuff `owned' by this
3617 end_sibling_chain ();
3622 /* If we are in terse mode, don't generate any DIEs to represent
3623 any actual typedefs. Note that even when we are in terse mode,
3624 we must still output DIEs to represent those tagged types which
3625 are used (directly or indirectly) in the specification of either
3626 a return type or a formal parameter type of some function. */
3628 if (debug_info_level <= DINFO_LEVEL_TERSE)
3629 if (DECL_NAME (decl) != NULL
3630 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
3633 output_type (TREE_TYPE (decl), containing_scope);
3635 /* Note that unlike the gcc front end (which generates a NULL named
3636 TYPE_DECL node for each complete tagged type, each array type,
3637 and each function type node created) the g++ front end generates
3638 a *named* TYPE_DECL node for each tagged type node created.
3639 Unfortunately, these g++ TYPE_DECL nodes cause us to output many
3640 superfluous and unnecessary TAG_typedef DIEs here. When g++ is
3641 fixed to stop generating these superfluous named TYPE_DECL nodes,
3642 the superfluous TAG_typedef DIEs will likewise cease. */
3644 if (DECL_NAME (decl))
3645 /* Output a DIE to represent the typedef itself. */
3646 output_die (output_typedef_die, decl);
3650 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3651 output_die (output_label_die, decl);
3655 /* If we are in terse mode, don't generate any DIEs to represent
3656 any variable declarations or definitions. */
3658 if (debug_info_level <= DINFO_LEVEL_TERSE)
3661 /* Output any DIEs that are needed to specify the type of this data
3664 output_type (TREE_TYPE (decl), containing_scope);
3666 /* If the following DIE will represent a data object definition for a
3667 data object with "extern" linkage, output a special "pubnames" DIE
3668 label just ahead of the actual DIE. A reference to this label
3669 was already generated in the .debug_pubnames section sub-entry
3670 for this data object definition. */
3672 if (TREE_PUBLIC (decl))
3674 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3676 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
3677 ASM_OUTPUT_LABEL (asm_out_file, label);
3680 /* Now output the DIE to represent the data object itself. */
3682 output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
3683 ? output_global_variable_die : output_local_variable_die,
3688 /* Ignore the nameless fields that are used to skip bits. */
3689 if (DECL_NAME (decl) != 0)
3691 output_type (member_declared_type (decl), containing_scope);
3692 output_die (output_member_die, decl);
3697 /* Force out the type of this formal, if it was not forced out yet.
3698 Note that here we can run afowl of a bug in "classic" svr4 SDB.
3699 It should be able to grok the presence of type DIEs within a list
3700 of TAG_formal_parameter DIEs, but it doesn't. */
3702 output_type (TREE_TYPE (decl), containing_scope);
3703 output_die (output_formal_parameter_die, decl);
3712 dwarfout_file_scope_decl (decl, set_finalizing)
3714 register int set_finalizing;
3716 switch (TREE_CODE (decl))
3720 /* Ignore this FUNCTION_DECL if it refers to a builtin function. */
3722 if (TREE_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
3725 /* Ignore this FUNCTION_DECL if it refers to a file-scope extern
3726 function declaration and if the declaration was never even
3727 referenced from within this entire compilation unit. We
3728 suppress these DIEs in order to save space in the .debug section
3729 (by eliminating entries which are probably useless). Note that
3730 we must not suppress block-local extern declarations (whether
3731 used or not) because that would screw-up the debugger's name
3732 lookup mechanism and cause it to miss things which really ought
3733 to be in scope at a given point. */
3735 if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
3738 if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl))
3740 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3742 /* Output a .debug_pubnames entry for a public function
3743 defined in this compilation unit. */
3745 fputc ('\n', asm_out_file);
3746 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
3747 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
3748 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3749 ASM_OUTPUT_DWARF_STRING (asm_out_file,
3750 IDENTIFIER_POINTER (DECL_NAME (decl)));
3751 ASM_OUTPUT_POP_SECTION (asm_out_file);
3758 /* Ignore this VAR_DECL if it refers to a file-scope extern data
3759 object declaration and if the declaration was never even
3760 referenced from within this entire compilation unit. We
3761 suppress these DIEs in order to save space in the .debug section
3762 (by eliminating entries which are probably useless). Note that
3763 we must not suppress block-local extern declarations (whether
3764 used or not) because that would screw-up the debugger's name
3765 lookup mechanism and cause it to miss things which really ought
3766 to be in scope at a given point. */
3768 if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
3771 if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl))
3773 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3775 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3777 /* Output a .debug_pubnames entry for a public variable
3778 defined in this compilation unit. */
3780 fputc ('\n', asm_out_file);
3781 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
3782 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
3783 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
3784 ASM_OUTPUT_DWARF_STRING (asm_out_file,
3785 IDENTIFIER_POINTER (DECL_NAME (decl)));
3786 ASM_OUTPUT_POP_SECTION (asm_out_file);
3789 if (DECL_INITIAL (decl) == NULL)
3791 /* Output a .debug_aranges entry for a public variable
3792 which is tenatively defined in this compilation unit. */
3794 fputc ('\n', asm_out_file);
3795 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
3796 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3797 IDENTIFIER_POINTER (DECL_NAME (decl)));
3798 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3799 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
3800 ASM_OUTPUT_POP_SECTION (asm_out_file);
3804 /* If we are in terse mode, don't generate any DIEs to represent
3805 any variable declarations or definitions. */
3807 if (debug_info_level <= DINFO_LEVEL_TERSE)
3813 /* Don't generate any DIEs to represent the standard built-in types. */
3815 if (DECL_SOURCE_LINE (decl) == 0)
3818 /* If we are in terse mode, don't generate any DIEs to represent
3819 any actual typedefs. Note that even when we are in terse mode,
3820 we must still output DIEs to represent those tagged types which
3821 are used (directly or indirectly) in the specification of either
3822 a return type or a formal parameter type of some function. */
3824 if (debug_info_level <= DINFO_LEVEL_TERSE)
3825 if (DECL_NAME (decl) != NULL
3826 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
3835 fputc ('\n', asm_out_file);
3836 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
3837 finalizing = set_finalizing;
3838 output_decl (decl, NULL);
3840 /* NOTE: The call above to `output_decl' may have caused one or more
3841 file-scope named types (i.e. tagged types) to be placed onto the
3842 pending_types_list. We have to get those types off of that list
3843 at some point, and this is the perfect time to do it. If we didn't
3844 take them off now, they might still be on the list when cc1 finally
3845 exits. That might be OK if it weren't for the fact that when we put
3846 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
3847 for these types, and that causes them never to be output unless
3848 `output_pending_types_for_scope' takes them off of the list and un-sets
3849 their TREE_ASM_WRITTEN flags. */
3851 output_pending_types_for_scope (NULL);
3853 /* The above call should have totally emptied the pending_types_list. */
3855 assert (pending_types == 0);
3857 ASM_OUTPUT_POP_SECTION (asm_out_file);
3859 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
3860 current_funcdef_number++;
3863 /* Output a marker (i.e. a label) for the beginning of the generated code
3864 for a lexical block. */
3867 dwarfout_begin_block (blocknum)
3868 register unsigned blocknum;
3870 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3873 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
3874 ASM_OUTPUT_LABEL (asm_out_file, label);
3877 /* Output a marker (i.e. a label) for the end of the generated code
3878 for a lexical block. */
3881 dwarfout_end_block (blocknum)
3882 register unsigned blocknum;
3884 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3887 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
3888 ASM_OUTPUT_LABEL (asm_out_file, label);
3891 /* Output a marker (i.e. a label) at a point in the assembly code which
3892 corresponds to a given source level label. */
3895 dwarfout_label (insn)
3898 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3900 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3903 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3904 (unsigned) INSN_UID (insn));
3905 ASM_OUTPUT_LABEL (asm_out_file, label);
3909 /* Output a marker (i.e. a label) for the absolute end of the generated code
3910 for a function definition. This gets called *after* the epilogue code
3911 has been generated. */
3914 dwarfout_end_epilogue ()
3916 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3918 /* Output a label to mark the endpoint of the code generated for this
3921 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
3922 ASM_OUTPUT_LABEL (asm_out_file, label);
3926 shuffle_filename_entry (new_zeroth)
3927 register filename_entry *new_zeroth;
3929 filename_entry temp_entry;
3930 register filename_entry *limit_p;
3931 register filename_entry *move_p;
3933 if (new_zeroth == &filename_table[0])
3936 temp_entry = *new_zeroth;
3938 /* Shift entries up in the table to make room at [0]. */
3940 limit_p = &filename_table[0];
3941 for (move_p = new_zeroth; move_p > limit_p; move_p--)
3942 *move_p = *(move_p-1);
3944 /* Install the found entry at [0]. */
3946 filename_table[0] = temp_entry;
3949 /* Create a new (string) entry for the .debug_sfnames section. */
3952 generate_new_sfname_entry ()
3954 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3956 fputc ('\n', asm_out_file);
3957 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
3958 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
3959 ASM_OUTPUT_LABEL (asm_out_file, label);
3960 ASM_OUTPUT_DWARF_STRING (asm_out_file,
3961 filename_table[0].name
3962 ? filename_table[0].name
3964 ASM_OUTPUT_POP_SECTION (asm_out_file);
3967 /* Lookup a filename (in the list of filenames that we know about here in
3968 dwarfout.c) and return its "index". The index of each (known) filename
3969 is just a unique number which is associated with only that one filename.
3970 We need such numbers for the sake of generating labels (in the
3971 .debug_sfnames section) and references to those unique labels (in the
3972 .debug_srcinfo and .debug_macinfo sections).
3974 If the filename given as an argument is not found in our current list,
3975 add it to the list and assign it the next available unique index number.
3977 Whatever we do (i.e. whether we find a pre-existing filename or add a new
3978 one), we shuffle the filename found (or added) up to the zeroth entry of
3979 our list of filenames (which is always searched linearly). We do this so
3980 as to optimize the most common case for these filename lookups within
3981 dwarfout.c. The most common case by far is the case where we call
3982 lookup_filename to lookup the very same filename that we did a lookup
3983 on the last time we called lookup_filename. We make sure that this
3984 common case is fast because such cases will constitute 99.9% of the
3985 lookups we ever do (in practice).
3987 If we add a new filename entry to our table, we go ahead and generate
3988 the corresponding entry in the .debug_sfnames section right away.
3989 Doing so allows us to avoid tickling an assembler bug (present in some
3990 m68k assemblers) which yields assembly-time errors in cases where the
3991 difference of two label addresses is taken and where the two labels
3992 are in a section *other* than the one where the difference is being
3993 calculated, and where at least one of the two symbol references is a
3994 forward reference. (This bug could be tickled by our .debug_srcinfo
3995 entries if we don't output their corresponding .debug_sfnames entries
4000 lookup_filename (file_name)
4003 register filename_entry *search_p;
4004 register filename_entry *limit_p = &filename_table[ft_entries];
4006 for (search_p = filename_table; search_p < limit_p; search_p++)
4007 if (!strcmp (file_name, search_p->name))
4009 /* When we get here, we have found the filename that we were
4010 looking for in the filename_table. Now we want to make sure
4011 that it gets moved to the zero'th entry in the table (if it
4012 is not already there) so that subsequent attempts to find the
4013 same filename will find it as quickly as possible. */
4015 shuffle_filename_entry (search_p);
4016 return filename_table[0].number;
4019 /* We come here whenever we have a new filename which is not registered
4020 in the current table. Here we add it to the table. */
4022 /* Prepare to add a new table entry by making sure there is enough space
4023 in the table to do so. If not, expand the current table. */
4025 if (ft_entries == ft_entries_allocated)
4027 ft_entries_allocated += FT_ENTRIES_INCREMENT;
4029 = (filename_entry *)
4030 xrealloc (filename_table,
4031 ft_entries_allocated * sizeof (filename_entry));
4034 /* Initially, add the new entry at the end of the filename table. */
4036 filename_table[ft_entries].number = ft_entries;
4037 filename_table[ft_entries].name = xstrdup (file_name);
4039 /* Shuffle the new entry into filename_table[0]. */
4041 shuffle_filename_entry (&filename_table[ft_entries]);
4043 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4044 generate_new_sfname_entry ();
4047 return filename_table[0].number;
4051 generate_srcinfo_entry (line_entry_num, files_entry_num)
4052 unsigned line_entry_num;
4053 unsigned files_entry_num;
4055 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4057 fputc ('\n', asm_out_file);
4058 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4059 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
4060 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
4061 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
4062 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
4063 ASM_OUTPUT_POP_SECTION (asm_out_file);
4067 dwarfout_line (filename, line)
4068 register char *filename;
4069 register unsigned line;
4071 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4073 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4074 static unsigned last_line_entry_num = 0;
4075 static unsigned prev_file_entry_num = (unsigned) -1;
4076 register unsigned this_file_entry_num = lookup_filename (filename);
4079 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
4080 ASM_OUTPUT_LABEL (asm_out_file, label);
4082 fputc ('\n', asm_out_file);
4083 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4085 if (this_file_entry_num != prev_file_entry_num)
4087 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
4089 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
4090 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
4094 register char *tail = strrchr (filename, '/');
4100 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
4101 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
4103 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
4104 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
4105 ASM_OUTPUT_POP_SECTION (asm_out_file);
4107 if (this_file_entry_num != prev_file_entry_num)
4108 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
4109 prev_file_entry_num = this_file_entry_num;
4113 /* Generate an entry in the .debug_macinfo section. */
4116 generate_macinfo_entry (type_and_offset, string)
4117 register char *type_and_offset;
4118 register char *string;
4120 fputc ('\n', asm_out_file);
4121 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4122 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
4123 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
4124 ASM_OUTPUT_POP_SECTION (asm_out_file);
4128 dwarfout_start_new_source_file (filename)
4129 register char *filename;
4131 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4132 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
4134 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
4135 sprintf (type_and_offset, "0x%08x+%s-%s",
4136 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
4137 generate_macinfo_entry (type_and_offset, "");
4141 dwarfout_resume_previous_source_file (lineno)
4142 register unsigned lineno;
4144 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4146 sprintf (type_and_offset, "0x%08x+%u",
4147 ((unsigned) MACINFO_resume << 24), lineno);
4148 generate_macinfo_entry (type_and_offset, "");
4151 /* Called from check_newline in c-parse.y. The `buffer' parameter
4152 contains the tail part of the directive line, i.e. the part which
4153 is past the initial whitespace, #, whitespace, directive-name,
4157 dwarfout_define (lineno, buffer)
4158 register unsigned lineno;
4159 register char *buffer;
4161 static int initialized = 0;
4162 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4166 dwarfout_start_new_source_file (primary_filename);
4169 sprintf (type_and_offset, "0x%08x+%u",
4170 ((unsigned) MACINFO_define << 24), lineno);
4171 generate_macinfo_entry (type_and_offset, buffer);
4174 /* Called from check_newline in c-parse.y. The `buffer' parameter
4175 contains the tail part of the directive line, i.e. the part which
4176 is past the initial whitespace, #, whitespace, directive-name,
4180 dwarfout_undef (lineno, buffer)
4181 register unsigned lineno;
4182 register char *buffer;
4184 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4186 sprintf (type_and_offset, "0x%08x+%u",
4187 ((unsigned) MACINFO_undef << 24), lineno);
4188 generate_macinfo_entry (type_and_offset, buffer);
4191 /* Set up for Dwarf output at the start of compilation. */
4194 dwarfout_init (asm_out_file, main_input_filename)
4195 register FILE *asm_out_file;
4196 register char *main_input_filename;
4198 /* Remember the name of the primary input file. */
4200 primary_filename = main_input_filename;
4202 /* Allocate the initial hunk of the pending_sibling_stack. */
4204 pending_sibling_stack
4206 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
4207 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
4208 pending_siblings = 1;
4210 /* Allocate the initial hunk of the filename_table. */
4213 = (filename_entry *)
4214 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
4215 ft_entries_allocated = FT_ENTRIES_INCREMENT;
4218 /* Allocate the initial hunk of the pending_types_list. */
4221 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
4222 pending_types_allocated = PENDING_TYPES_INCREMENT;
4225 /* Create an artificial RECORD_TYPE node which we can use in our hack
4226 to get the DIEs representing types of formal parameters to come out
4227 only *after* the DIEs for the formal parameters themselves. */
4229 fake_containing_scope = make_node (RECORD_TYPE);
4231 /* Output a starting label for the .text section. */
4233 fputc ('\n', asm_out_file);
4234 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
4235 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
4236 ASM_OUTPUT_POP_SECTION (asm_out_file);
4238 /* Output a starting label for the .data section. */
4240 fputc ('\n', asm_out_file);
4241 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
4242 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
4243 ASM_OUTPUT_POP_SECTION (asm_out_file);
4245 /* Output a starting label for the .data1 section. */
4247 fputc ('\n', asm_out_file);
4248 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
4249 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
4250 ASM_OUTPUT_POP_SECTION (asm_out_file);
4252 /* Output a starting label for the .rodata section. */
4254 fputc ('\n', asm_out_file);
4255 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
4256 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
4257 ASM_OUTPUT_POP_SECTION (asm_out_file);
4259 /* Output a starting label for the .rodata1 section. */
4261 fputc ('\n', asm_out_file);
4262 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
4263 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
4264 ASM_OUTPUT_POP_SECTION (asm_out_file);
4266 /* Output a starting label for the .bss section. */
4268 fputc ('\n', asm_out_file);
4269 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
4270 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
4271 ASM_OUTPUT_POP_SECTION (asm_out_file);
4273 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4275 /* Output a starting label and an initial (compilation directory)
4276 entry for the .debug_sfnames section. The starting label will be
4277 referenced by the initial entry in the .debug_srcinfo section. */
4279 fputc ('\n', asm_out_file);
4280 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
4281 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
4283 register char *pwd = getpwd ();
4284 register unsigned len = strlen (pwd);
4285 register char *dirname = (char *) xmalloc (len + 2);
4287 strcpy (dirname, pwd);
4288 strcpy (dirname + len, "/");
4289 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
4292 ASM_OUTPUT_POP_SECTION (asm_out_file);
4294 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4296 /* Output a starting label for the .debug_macinfo section. This
4297 label will be referenced by the AT_mac_info attribute in the
4298 TAG_compile_unit DIE. */
4300 fputc ('\n', asm_out_file);
4301 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4302 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
4303 ASM_OUTPUT_POP_SECTION (asm_out_file);
4306 /* Generate the initial entry for the .line section. */
4308 fputc ('\n', asm_out_file);
4309 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4310 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
4311 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
4312 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4313 ASM_OUTPUT_POP_SECTION (asm_out_file);
4315 /* Generate the initial entry for the .debug_srcinfo section. */
4317 fputc ('\n', asm_out_file);
4318 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4319 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
4320 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
4321 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
4322 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4323 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
4324 #ifdef DWARF_TIMESTAMPS
4325 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
4327 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
4329 ASM_OUTPUT_POP_SECTION (asm_out_file);
4331 /* Generate the initial entry for the .debug_pubnames section. */
4333 fputc ('\n', asm_out_file);
4334 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4335 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
4336 ASM_OUTPUT_POP_SECTION (asm_out_file);
4338 /* Generate the initial entry for the .debug_aranges section. */
4340 fputc ('\n', asm_out_file);
4341 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4342 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
4343 ASM_OUTPUT_POP_SECTION (asm_out_file);
4346 /* Setup first DIE number == 1. */
4347 NEXT_DIE_NUM = next_unused_dienum++;
4349 /* Generate the initial DIE for the .debug section. Note that the
4350 (string) value given in the AT_name attribute of the TAG_compile_unit
4351 DIE will (typically) be a relative pathname and that this pathname
4352 should be taken as being relative to the directory from which the
4353 compiler was invoked when the given (base) source file was compiled. */
4355 fputc ('\n', asm_out_file);
4356 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4357 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
4358 output_die (output_compile_unit_die, main_input_filename);
4359 ASM_OUTPUT_POP_SECTION (asm_out_file);
4361 fputc ('\n', asm_out_file);
4364 /* Output stuff that dwarf requires at the end of every file. */
4369 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4371 fputc ('\n', asm_out_file);
4372 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4374 /* Mark the end of the chain of siblings which represent all file-scope
4375 declarations in this compilation unit. */
4377 /* The (null) DIE which represents the terminator for the (sibling linked)
4378 list of file-scope items is *special*. Normally, we would just call
4379 end_sibling_chain at this point in order to output a word with the
4380 value `4' and that word would act as the terminator for the list of
4381 DIEs describing file-scope items. Unfortunately, if we were to simply
4382 do that, the label that would follow this DIE in the .debug section
4383 (i.e. `..D2') would *not* be properly aligned (as it must be on some
4384 machines) to a 4 byte boundary.
4386 In order to force the label `..D2' to get aligned to a 4 byte boundary,
4387 the trick used is to insert extra (otherwise useless) padding bytes
4388 into the (null) DIE that we know must preceed the ..D2 label in the
4389 .debug section. The amount of padding required can be anywhere between
4390 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
4391 with the padding) would normally contain the value 4, but now it will
4392 also have to include the padding bytes, so it will instead have some
4393 value in the range 4..7.
4395 Fortunately, the rules of Dwarf say that any DIE whose length word
4396 contains *any* value less than 8 should be treated as a null DIE, so
4397 this trick works out nicely. Clever, eh? Don't give me any credit
4398 (or blame). I didn't think of this scheme. I just conformed to it.
4401 output_die (output_padded_null_die, (void *)0);
4404 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
4405 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
4406 ASM_OUTPUT_POP_SECTION (asm_out_file);
4408 /* Output a terminator label for the .text section. */
4410 fputc ('\n', asm_out_file);
4411 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
4412 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
4413 ASM_OUTPUT_POP_SECTION (asm_out_file);
4415 /* Output a terminator label for the .data section. */
4417 fputc ('\n', asm_out_file);
4418 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
4419 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
4420 ASM_OUTPUT_POP_SECTION (asm_out_file);
4422 /* Output a terminator label for the .data1 section. */
4424 fputc ('\n', asm_out_file);
4425 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
4426 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
4427 ASM_OUTPUT_POP_SECTION (asm_out_file);
4429 /* Output a terminator label for the .rodata section. */
4431 fputc ('\n', asm_out_file);
4432 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
4433 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
4434 ASM_OUTPUT_POP_SECTION (asm_out_file);
4436 /* Output a terminator label for the .rodata1 section. */
4438 fputc ('\n', asm_out_file);
4439 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
4440 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
4441 ASM_OUTPUT_POP_SECTION (asm_out_file);
4443 /* Output a terminator label for the .bss section. */
4445 fputc ('\n', asm_out_file);
4446 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
4447 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
4448 ASM_OUTPUT_POP_SECTION (asm_out_file);
4450 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4452 /* Output a terminating entry for the .line section. */
4454 fputc ('\n', asm_out_file);
4455 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4456 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
4457 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4458 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
4459 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
4460 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
4461 ASM_OUTPUT_POP_SECTION (asm_out_file);
4463 /* Output a terminating entry for the .debug_srcinfo section. */
4465 fputc ('\n', asm_out_file);
4466 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4467 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
4468 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
4469 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
4470 ASM_OUTPUT_POP_SECTION (asm_out_file);
4472 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4474 /* Output terminating entries for the .debug_macinfo section. */
4476 dwarfout_resume_previous_source_file (0);
4478 fputc ('\n', asm_out_file);
4479 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4480 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4481 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
4482 ASM_OUTPUT_POP_SECTION (asm_out_file);
4485 /* Generate the terminating entry for the .debug_pubnames section. */
4487 fputc ('\n', asm_out_file);
4488 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4489 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4490 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
4491 ASM_OUTPUT_POP_SECTION (asm_out_file);
4493 /* Generate the terminating entries for the .debug_aranges section.
4495 Note that we want to do this only *after* we have output the end
4496 labels (for the various program sections) which we are going to
4497 refer to here. This allows us to work around a bug in the m68k
4498 svr4 assembler. That assembler gives bogus assembly-time errors
4499 if (within any given section) you try to take the difference of
4500 two relocatable symbols, both of which are located within some
4501 other section, and if one (or both?) of the symbols involved is
4502 being forward-referenced. By generating the .debug_aranges
4503 entries at this late point in the assembly output, we skirt the
4504 issue simply by avoiding forward-references.
4507 fputc ('\n', asm_out_file);
4508 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4510 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4511 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
4513 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
4514 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
4516 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
4517 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
4520 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
4521 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
4522 RODATA_BEGIN_LABEL);
4524 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
4525 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
4526 RODATA1_BEGIN_LABEL);
4528 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
4529 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
4531 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4532 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
4534 ASM_OUTPUT_POP_SECTION (asm_out_file);
4538 #endif /* DWARF_DEBUGGING_INFO */