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 "hard-reg-set.h"
32 #include "insn-config.h"
38 #define DWARF_VERSION 1
41 /* #define NDEBUG 1 */
44 #if defined(DWARF_TIMESTAMPS)
47 #else /* !defined(POSIX) */
48 #include <sys/types.h>
50 extern time_t time (time_t *);
51 #else /* !defined(__STDC__) */
52 extern time_t time ();
53 #endif /* !defined(__STDC__) */
54 #endif /* !defined(POSIX) */
55 #endif /* defined(DWARF_TIMESTAMPS) */
57 extern char *getpwd ();
59 extern char *index ();
60 extern char *rindex ();
62 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
63 regarding the GNU implementation of Dwarf. */
65 /* NOTE: In the comments in this file, many references are made to
66 so called "Debugging Information Entries". For the sake of brevity,
67 this term is abbreviated to `DIE' throughout the remainder of this
70 /* Note that the implementation of C++ support herein is (as yet) unfinished.
71 If you want to try to complete it, more power to you. */
73 #if defined(__GNUC__) && (NDEBUG == 1)
74 #define inline static inline
79 /* How to start an assembler comment. */
80 #ifndef ASM_COMMENT_START
81 #define ASM_COMMENT_START ";#"
84 /* How to print out a register name. */
86 #define PRINT_REG(RTX, CODE, FILE) \
87 fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
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 extern int flag_traditional;
108 extern char *version_string;
109 extern char *language_string;
111 /* Maximum size (in bytes) of an artificially generated label. */
113 #define MAX_ARTIFICIAL_LABEL_BYTES 30
115 /* Make sure we know the sizes of the various types dwarf can describe.
116 These are only defaults. If the sizes are different for your target,
117 you should override these values by defining the appropriate symbols
118 in your tm.h file. */
120 #ifndef CHAR_TYPE_SIZE
121 #define CHAR_TYPE_SIZE BITS_PER_UNIT
124 #ifndef SHORT_TYPE_SIZE
125 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
128 #ifndef INT_TYPE_SIZE
129 #define INT_TYPE_SIZE BITS_PER_WORD
132 #ifndef LONG_TYPE_SIZE
133 #define LONG_TYPE_SIZE BITS_PER_WORD
136 #ifndef LONG_LONG_TYPE_SIZE
137 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
140 #ifndef WCHAR_TYPE_SIZE
141 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
144 #ifndef WCHAR_UNSIGNED
145 #define WCHAR_UNSIGNED 0
148 #ifndef FLOAT_TYPE_SIZE
149 #define FLOAT_TYPE_SIZE BITS_PER_WORD
152 #ifndef DOUBLE_TYPE_SIZE
153 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
156 #ifndef LONG_DOUBLE_TYPE_SIZE
157 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
160 /* Structure to keep track of source filenames. */
162 struct filename_entry {
167 typedef struct filename_entry filename_entry;
169 /* Pointer to an array of elements, each one having the structure above. */
171 static filename_entry *filename_table;
173 /* Total number of entries in the table (i.e. array) pointed to by
174 `filename_table'. This is the *total* and includes both used and
177 static unsigned ft_entries_allocated;
179 /* Number of entries in the filename_table which are actually in use. */
181 static unsigned ft_entries;
183 /* Size (in elements) of increments by which we may expand the filename
184 table. Actually, a single hunk of space of this size should be enough
185 for most typical programs. */
187 #define FT_ENTRIES_INCREMENT 64
189 /* Local pointer to the name of the main input file. Initialized in
192 static char *primary_filename;
194 /* Pointer to the most recent filename for which we produced some line info. */
196 static char *last_filename;
198 /* For Dwarf output, we must assign lexical-blocks id numbers
199 in the order in which their beginnings are encountered.
200 We output Dwarf debugging info that refers to the beginnings
201 and ends of the ranges of code for each lexical block with
202 assembler labels ..Bn and ..Bn.e, where n is the block number.
203 The labels themselves are generated in final.c, which assigns
204 numbers to the blocks in the same way. */
206 static unsigned next_block_number = 2;
208 /* Counter to generate unique names for DIEs. */
210 static unsigned next_unused_dienum = 1;
212 /* Number of the DIE which is currently being generated. */
214 static unsigned current_dienum;
216 /* Number to use for the special "pubname" label on the next DIE which
217 represents a function or data object defined in this compilation
218 unit which has "extern" linkage. */
220 static next_pubname_number = 0;
222 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
224 /* Pointer to a dynamically allocated list of pre-reserved and still
225 pending sibling DIE numbers. Note that this list will grow as needed. */
227 static unsigned *pending_sibling_stack;
229 /* Counter to keep track of the number of pre-reserved and still pending
230 sibling DIE numbers. */
232 static unsigned pending_siblings;
234 /* The currently allocated size of the above list (expressed in number of
237 static unsigned pending_siblings_allocated;
239 /* Size (in elements) of increments by which we may expand the pending
240 sibling stack. Actually, a single hunk of space of this size should
241 be enough for most typical programs. */
243 #define PENDING_SIBLINGS_INCREMENT 64
245 /* Non-zero if we are performing our file-scope finalization pass and if
246 we should force out Dwarf descriptions of any and all file-scope
247 tagged types which are still incomplete types. */
249 static int finalizing = 0;
251 /* A pointer to the base of a list of pending types which we haven't
252 generated DIEs for yet, but which we will have to come back to
255 static tree *pending_types_list;
257 /* Number of elements currently allocated for the pending_types_list. */
259 static unsigned pending_types_allocated;
261 /* Number of elements of pending_types_list currently in use. */
263 static unsigned pending_types;
265 /* Size (in elements) of increments by which we may expand the pending
266 types list. Actually, a single hunk of space of this size should
267 be enough for most typical programs. */
269 #define PENDING_TYPES_INCREMENT 64
271 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
272 This is used in a hack to help us get the DIEs describing types of
273 formal parameters to come *after* all of the DIEs describing the formal
274 parameters themselves. That's necessary in order to be compatible
275 with what the brain-damaged svr4 SDB debugger requires. */
277 static tree fake_containing_scope;
279 /* The number of the current function definition that we are generating
280 debugging information for. These numbers range from 1 up to the maximum
281 number of function definitions contained within the current compilation
282 unit. These numbers are used to create unique labels for various things
283 contained within various function definitions. */
285 static unsigned current_funcdef_number = 1;
287 /* A pointer to the ..._DECL node which we have most recently been working
288 on. We keep this around just in case something about it looks screwy
289 and we want to tell the user what the source coordinates for the actual
292 static tree dwarf_last_decl;
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 ASM_BYTE_OP ".byte"
325 #define SET_ASM_OP ".set"
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 is 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 ".section"
339 #ifndef POPSECTION_ASM_OP
340 #define POPSECTION_ASM_OP ".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 These labels have been hacked (temporarily) so that they all begin with
400 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
401 stock m88k/svr4 assembler, both of which need to see .L at the start of
402 a label in order to prevent that label from going into the linker symbol
403 table). When I get time, I'll have to fix this the right way so that we
404 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
405 but that will require a rather massive set of changes. For the moment,
406 the following definitions out to produce the right results for all svr4
407 and svr3 assemblers. -- rfg
410 #ifndef TEXT_BEGIN_LABEL
411 #define TEXT_BEGIN_LABEL ".L_text_b"
413 #ifndef TEXT_END_LABEL
414 #define TEXT_END_LABEL ".L_text_e"
417 #ifndef DATA_BEGIN_LABEL
418 #define DATA_BEGIN_LABEL ".L_data_b"
420 #ifndef DATA_END_LABEL
421 #define DATA_END_LABEL ".L_data_e"
424 #ifndef DATA1_BEGIN_LABEL
425 #define DATA1_BEGIN_LABEL ".L_data1_b"
427 #ifndef DATA1_END_LABEL
428 #define DATA1_END_LABEL ".L_data1_e"
431 #ifndef RODATA_BEGIN_LABEL
432 #define RODATA_BEGIN_LABEL ".L_rodata_b"
434 #ifndef RODATA_END_LABEL
435 #define RODATA_END_LABEL ".L_rodata_e"
438 #ifndef RODATA1_BEGIN_LABEL
439 #define RODATA1_BEGIN_LABEL ".L_rodata1_b"
441 #ifndef RODATA1_END_LABEL
442 #define RODATA1_END_LABEL ".L_rodata1_e"
445 #ifndef BSS_BEGIN_LABEL
446 #define BSS_BEGIN_LABEL ".L_bss_b"
448 #ifndef BSS_END_LABEL
449 #define BSS_END_LABEL ".L_bss_e"
452 #ifndef LINE_BEGIN_LABEL
453 #define LINE_BEGIN_LABEL ".L_line_b"
455 #ifndef LINE_LAST_ENTRY_LABEL
456 #define LINE_LAST_ENTRY_LABEL ".L_line_last"
458 #ifndef LINE_END_LABEL
459 #define LINE_END_LABEL ".L_line_e"
462 #ifndef DEBUG_BEGIN_LABEL
463 #define DEBUG_BEGIN_LABEL ".L_debug_b"
465 #ifndef SFNAMES_BEGIN_LABEL
466 #define SFNAMES_BEGIN_LABEL ".L_sfnames_b"
468 #ifndef SRCINFO_BEGIN_LABEL
469 #define SRCINFO_BEGIN_LABEL ".L_srcinfo_b"
471 #ifndef MACINFO_BEGIN_LABEL
472 #define MACINFO_BEGIN_LABEL ".L_macinfo_b"
475 #ifndef DIE_BEGIN_LABEL_FMT
476 #define DIE_BEGIN_LABEL_FMT ".L_D%u"
478 #ifndef DIE_END_LABEL_FMT
479 #define DIE_END_LABEL_FMT ".L_D%u_e"
481 #ifndef PUB_DIE_LABEL_FMT
482 #define PUB_DIE_LABEL_FMT ".L_P%u"
484 #ifndef INSN_LABEL_FMT
485 #define INSN_LABEL_FMT ".L_I%u_%u"
487 #ifndef BLOCK_BEGIN_LABEL_FMT
488 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
490 #ifndef BLOCK_END_LABEL_FMT
491 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
493 #ifndef SS_BEGIN_LABEL_FMT
494 #define SS_BEGIN_LABEL_FMT ".L_s%u"
496 #ifndef SS_END_LABEL_FMT
497 #define SS_END_LABEL_FMT ".L_s%u_e"
499 #ifndef EE_BEGIN_LABEL_FMT
500 #define EE_BEGIN_LABEL_FMT ".L_e%u"
502 #ifndef EE_END_LABEL_FMT
503 #define EE_END_LABEL_FMT ".L_e%u_e"
505 #ifndef MT_BEGIN_LABEL_FMT
506 #define MT_BEGIN_LABEL_FMT ".L_t%u"
508 #ifndef MT_END_LABEL_FMT
509 #define MT_END_LABEL_FMT ".L_t%u_e"
511 #ifndef LOC_BEGIN_LABEL_FMT
512 #define LOC_BEGIN_LABEL_FMT ".L_l%u"
514 #ifndef LOC_END_LABEL_FMT
515 #define LOC_END_LABEL_FMT ".L_l%u_e"
517 #ifndef BOUND_BEGIN_LABEL_FMT
518 #define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c"
520 #ifndef BOUND_END_LABEL_FMT
521 #define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e"
523 #ifndef DERIV_BEGIN_LABEL_FMT
524 #define DERIV_BEGIN_LABEL_FMT ".L_d%u"
526 #ifndef DERIV_END_LABEL_FMT
527 #define DERIV_END_LABEL_FMT ".L_d%u_e"
529 #ifndef SL_BEGIN_LABEL_FMT
530 #define SL_BEGIN_LABEL_FMT ".L_sl%u"
532 #ifndef SL_END_LABEL_FMT
533 #define SL_END_LABEL_FMT ".L_sl%u_e"
535 #ifndef FUNC_END_LABEL_FMT
536 #define FUNC_END_LABEL_FMT ".L_f%u_e"
538 #ifndef TYPE_NAME_FMT
539 #define TYPE_NAME_FMT ".L_T%u"
541 #ifndef DECL_NAME_FMT
542 #define DECL_NAME_FMT ".L_E%u"
544 #ifndef LINE_CODE_LABEL_FMT
545 #define LINE_CODE_LABEL_FMT ".L_LC%u"
547 #ifndef SFNAMES_ENTRY_LABEL_FMT
548 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
550 #ifndef LINE_ENTRY_LABEL_FMT
551 #define LINE_ENTRY_LABEL_FMT ".L_LE%u"
554 /* Definitions of defaults for various types of primitive assembly language
557 If necessary, these may be overridden from within your tm.h file,
558 but typically, you shouldn't need to override these. One known
559 exception is ASM_OUTPUT_DEF which has to be different for stock
560 sparc/svr4 assemblers.
563 #ifndef ASM_OUTPUT_PUSH_SECTION
564 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
565 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
568 #ifndef ASM_OUTPUT_POP_SECTION
569 #define ASM_OUTPUT_POP_SECTION(FILE) \
570 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
573 #ifndef ASM_OUTPUT_SOURCE_FILENAME
574 #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
575 fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME)
578 #ifndef ASM_OUTPUT_DEF
579 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
580 do { fprintf ((FILE), "\t%s\t", SET_ASM_OP); \
581 assemble_name (FILE, LABEL1); \
582 fprintf (FILE, ","); \
583 assemble_name (FILE, LABEL2); \
584 fprintf (FILE, "\n"); \
588 #ifndef ASM_OUTPUT_DWARF_DELTA2
589 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
590 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
591 assemble_name (FILE, LABEL1); \
592 fprintf (FILE, "-"); \
593 assemble_name (FILE, LABEL2); \
594 fprintf (FILE, "\n"); \
598 #ifndef ASM_OUTPUT_DWARF_DELTA4
599 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
600 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
601 assemble_name (FILE, LABEL1); \
602 fprintf (FILE, "-"); \
603 assemble_name (FILE, LABEL2); \
604 fprintf (FILE, "\n"); \
608 #ifndef ASM_OUTPUT_DWARF_TAG
609 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
611 fprintf ((FILE), "\t%s\t0x%x", \
612 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
613 if (flag_verbose_asm) \
614 fprintf ((FILE), "\t%s %s", \
615 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
616 fputc ('\n', (FILE)); \
620 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
621 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
623 fprintf ((FILE), "\t%s\t0x%x", \
624 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
625 if (flag_verbose_asm) \
626 fprintf ((FILE), "\t%s %s", \
627 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
628 fputc ('\n', (FILE)); \
632 #ifndef ASM_OUTPUT_DWARF_STACK_OP
633 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
635 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
636 if (flag_verbose_asm) \
637 fprintf ((FILE), "\t%s %s", \
638 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
639 fputc ('\n', (FILE)); \
643 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
644 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
646 fprintf ((FILE), "\t%s\t0x%x", \
647 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
648 if (flag_verbose_asm) \
649 fprintf ((FILE), "\t%s %s", \
650 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
651 fputc ('\n', (FILE)); \
655 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
656 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
658 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
659 if (flag_verbose_asm) \
660 fprintf ((FILE), "\t%s %s", \
661 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
662 fputc ('\n', (FILE)); \
666 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
667 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
669 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
670 if (flag_verbose_asm) \
671 fprintf ((FILE), "\t%s %s", \
672 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
673 fputc ('\n', (FILE)); \
677 #ifndef ASM_OUTPUT_DWARF_ADDR
678 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
679 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
680 assemble_name (FILE, LABEL); \
681 fprintf (FILE, "\n"); \
685 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
686 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
688 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
689 output_addr_const ((FILE), (RTX)); \
690 fputc ('\n', (FILE)); \
694 #ifndef ASM_OUTPUT_DWARF_REF
695 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
696 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
697 assemble_name (FILE, LABEL); \
698 fprintf (FILE, "\n"); \
702 #ifndef ASM_OUTPUT_DWARF_DATA1
703 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
704 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
707 #ifndef ASM_OUTPUT_DWARF_DATA2
708 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
709 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
712 #ifndef ASM_OUTPUT_DWARF_DATA4
713 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
714 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
717 #ifndef ASM_OUTPUT_DWARF_DATA8
718 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
720 if (WORDS_BIG_ENDIAN) \
722 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
723 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
727 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
728 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
733 #ifndef ASM_OUTPUT_DWARF_STRING
734 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
735 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
738 /************************ general utility functions **************************/
744 register char *p = (char *) xmalloc (strlen (s) + 1);
754 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
755 || ((GET_CODE (rtl) == SUBREG)
756 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
759 /* Return non-zero if the given type node represents a tagged type. */
762 is_tagged_type (type)
765 register enum tree_code code = TREE_CODE (type);
767 return (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE);
772 register unsigned tag;
776 case TAG_padding: return "TAG_padding";
777 case TAG_array_type: return "TAG_array_type";
778 case TAG_class_type: return "TAG_class_type";
779 case TAG_entry_point: return "TAG_entry_point";
780 case TAG_enumeration_type: return "TAG_enumeration_type";
781 case TAG_formal_parameter: return "TAG_formal_parameter";
782 case TAG_global_subroutine: return "TAG_global_subroutine";
783 case TAG_global_variable: return "TAG_global_variable";
784 case TAG_label: return "TAG_label";
785 case TAG_lexical_block: return "TAG_lexical_block";
786 case TAG_local_variable: return "TAG_local_variable";
787 case TAG_member: return "TAG_member";
788 case TAG_pointer_type: return "TAG_pointer_type";
789 case TAG_reference_type: return "TAG_reference_type";
790 case TAG_compile_unit: return "TAG_compile_unit";
791 case TAG_string_type: return "TAG_string_type";
792 case TAG_structure_type: return "TAG_structure_type";
793 case TAG_subroutine: return "TAG_subroutine";
794 case TAG_subroutine_type: return "TAG_subroutine_type";
795 case TAG_typedef: return "TAG_typedef";
796 case TAG_union_type: return "TAG_union_type";
797 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
798 case TAG_variant: return "TAG_variant";
799 case TAG_common_block: return "TAG_common_block";
800 case TAG_common_inclusion: return "TAG_common_inclusion";
801 case TAG_inheritance: return "TAG_inheritance";
802 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
803 case TAG_module: return "TAG_module";
804 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
805 case TAG_set_type: return "TAG_set_type";
806 case TAG_subrange_type: return "TAG_subrange_type";
807 case TAG_with_stmt: return "TAG_with_stmt";
809 /* GNU extensions. */
811 case TAG_format_label: return "TAG_format_label";
812 case TAG_namelist: return "TAG_namelist";
813 case TAG_function_template: return "TAG_function_template";
814 case TAG_class_template: return "TAG_class_template";
816 default: return "TAG_<unknown>";
821 dwarf_attr_name (attr)
822 register unsigned attr;
826 case AT_sibling: return "AT_sibling";
827 case AT_location: return "AT_location";
828 case AT_name: return "AT_name";
829 case AT_fund_type: return "AT_fund_type";
830 case AT_mod_fund_type: return "AT_mod_fund_type";
831 case AT_user_def_type: return "AT_user_def_type";
832 case AT_mod_u_d_type: return "AT_mod_u_d_type";
833 case AT_ordering: return "AT_ordering";
834 case AT_subscr_data: return "AT_subscr_data";
835 case AT_byte_size: return "AT_byte_size";
836 case AT_bit_offset: return "AT_bit_offset";
837 case AT_bit_size: return "AT_bit_size";
838 case AT_element_list: return "AT_element_list";
839 case AT_stmt_list: return "AT_stmt_list";
840 case AT_low_pc: return "AT_low_pc";
841 case AT_high_pc: return "AT_high_pc";
842 case AT_language: return "AT_language";
843 case AT_member: return "AT_member";
844 case AT_discr: return "AT_discr";
845 case AT_discr_value: return "AT_discr_value";
846 case AT_string_length: return "AT_string_length";
847 case AT_common_reference: return "AT_common_reference";
848 case AT_comp_dir: return "AT_comp_dir";
849 case AT_const_value_string: return "AT_const_value_string";
850 case AT_const_value_data2: return "AT_const_value_data2";
851 case AT_const_value_data4: return "AT_const_value_data4";
852 case AT_const_value_data8: return "AT_const_value_data8";
853 case AT_const_value_block2: return "AT_const_value_block2";
854 case AT_const_value_block4: return "AT_const_value_block4";
855 case AT_containing_type: return "AT_containing_type";
856 case AT_default_value_addr: return "AT_default_value_addr";
857 case AT_default_value_data2: return "AT_default_value_data2";
858 case AT_default_value_data4: return "AT_default_value_data4";
859 case AT_default_value_data8: return "AT_default_value_data8";
860 case AT_default_value_string: return "AT_default_value_string";
861 case AT_friends: return "AT_friends";
862 case AT_inline: return "AT_inline";
863 case AT_is_optional: return "AT_is_optional";
864 case AT_lower_bound_ref: return "AT_lower_bound_ref";
865 case AT_lower_bound_data2: return "AT_lower_bound_data2";
866 case AT_lower_bound_data4: return "AT_lower_bound_data4";
867 case AT_lower_bound_data8: return "AT_lower_bound_data8";
868 case AT_private: return "AT_private";
869 case AT_producer: return "AT_producer";
870 case AT_program: return "AT_program";
871 case AT_protected: return "AT_protected";
872 case AT_prototyped: return "AT_prototyped";
873 case AT_public: return "AT_public";
874 case AT_pure_virtual: return "AT_pure_virtual";
875 case AT_return_addr: return "AT_return_addr";
876 case AT_abstract_origin: return "AT_abstract_origin";
877 case AT_start_scope: return "AT_start_scope";
878 case AT_stride_size: return "AT_stride_size";
879 case AT_upper_bound_ref: return "AT_upper_bound_ref";
880 case AT_upper_bound_data2: return "AT_upper_bound_data2";
881 case AT_upper_bound_data4: return "AT_upper_bound_data4";
882 case AT_upper_bound_data8: return "AT_upper_bound_data8";
883 case AT_virtual: return "AT_virtual";
887 case AT_sf_names: return "AT_sf_names";
888 case AT_src_info: return "AT_src_info";
889 case AT_mac_info: return "AT_mac_info";
890 case AT_src_coords: return "AT_src_coords";
892 default: return "AT_<unknown>";
897 dwarf_stack_op_name (op)
898 register unsigned op;
902 case OP_REG: return "OP_REG";
903 case OP_BASEREG: return "OP_BASEREG";
904 case OP_ADDR: return "OP_ADDR";
905 case OP_CONST: return "OP_CONST";
906 case OP_DEREF2: return "OP_DEREF2";
907 case OP_DEREF4: return "OP_DEREF4";
908 case OP_ADD: return "OP_ADD";
909 default: return "OP_<unknown>";
914 dwarf_typemod_name (mod)
915 register unsigned mod;
919 case MOD_pointer_to: return "MOD_pointer_to";
920 case MOD_reference_to: return "MOD_reference_to";
921 case MOD_const: return "MOD_const";
922 case MOD_volatile: return "MOD_volatile";
923 default: return "MOD_<unknown>";
928 dwarf_fmt_byte_name (fmt)
929 register unsigned fmt;
933 case FMT_FT_C_C: return "FMT_FT_C_C";
934 case FMT_FT_C_X: return "FMT_FT_C_X";
935 case FMT_FT_X_C: return "FMT_FT_X_C";
936 case FMT_FT_X_X: return "FMT_FT_X_X";
937 case FMT_UT_C_C: return "FMT_UT_C_C";
938 case FMT_UT_C_X: return "FMT_UT_C_X";
939 case FMT_UT_X_C: return "FMT_UT_X_C";
940 case FMT_UT_X_X: return "FMT_UT_X_X";
941 case FMT_ET: return "FMT_ET";
942 default: return "FMT_<unknown>";
946 dwarf_fund_type_name (ft)
947 register unsigned ft;
951 case FT_char: return "FT_char";
952 case FT_signed_char: return "FT_signed_char";
953 case FT_unsigned_char: return "FT_unsigned_char";
954 case FT_short: return "FT_short";
955 case FT_signed_short: return "FT_signed_short";
956 case FT_unsigned_short: return "FT_unsigned_short";
957 case FT_integer: return "FT_integer";
958 case FT_signed_integer: return "FT_signed_integer";
959 case FT_unsigned_integer: return "FT_unsigned_integer";
960 case FT_long: return "FT_long";
961 case FT_signed_long: return "FT_signed_long";
962 case FT_unsigned_long: return "FT_unsigned_long";
963 case FT_pointer: return "FT_pointer";
964 case FT_float: return "FT_float";
965 case FT_dbl_prec_float: return "FT_dbl_prec_float";
966 case FT_ext_prec_float: return "FT_ext_prec_float";
967 case FT_complex: return "FT_complex";
968 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
969 case FT_void: return "FT_void";
970 case FT_boolean: return "FT_boolean";
971 case FT_ext_prec_complex: return "FT_ext_prec_complex";
972 case FT_label: return "FT_label";
974 /* GNU extensions. */
976 case FT_long_long: return "FT_long_long";
977 case FT_signed_long_long: return "FT_signed_long_long";
978 case FT_unsigned_long_long: return "FT_unsigned_long_long";
980 case FT_int8: return "FT_int8";
981 case FT_signed_int8: return "FT_signed_int8";
982 case FT_unsigned_int8: return "FT_unsigned_int8";
983 case FT_int16: return "FT_int16";
984 case FT_signed_int16: return "FT_signed_int16";
985 case FT_unsigned_int16: return "FT_unsigned_int16";
986 case FT_int32: return "FT_int32";
987 case FT_signed_int32: return "FT_signed_int32";
988 case FT_unsigned_int32: return "FT_unsigned_int32";
989 case FT_int64: return "FT_int64";
990 case FT_signed_int64: return "FT_signed_int64";
991 case FT_unsigned_int64: return "FT_signed_int64";
993 case FT_real32: return "FT_real32";
994 case FT_real64: return "FT_real64";
995 case FT_real96: return "FT_real96";
996 case FT_real128: return "FT_real128";
998 default: return "FT_<unknown>";
1002 /* Determine the "ultimate origin" of a decl. The decl may be an
1003 inlined instance of an inlined instance of a decl which is local
1004 to an inline function, so we have to trace all of the way back
1005 through the origin chain to find out what sort of node actually
1006 served as the original seed for the given block. */
1009 decl_ultimate_origin (decl)
1012 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1014 if (immediate_origin == NULL)
1018 register tree ret_val;
1019 register tree lookahead = immediate_origin;
1023 ret_val = lookahead;
1024 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1026 while (lookahead != NULL && lookahead != ret_val);
1031 /* Determine the "ultimate origin" of a block. The block may be an
1032 inlined instance of an inlined instance of a block which is local
1033 to an inline function, so we have to trace all of the way back
1034 through the origin chain to find out what sort of node actually
1035 served as the original seed for the given block. */
1038 block_ultimate_origin (block)
1039 register tree block;
1041 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1043 if (immediate_origin == NULL)
1047 register tree ret_val;
1048 register tree lookahead = immediate_origin;
1052 ret_val = lookahead;
1053 lookahead = (TREE_CODE (ret_val) == BLOCK)
1054 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1057 while (lookahead != NULL && lookahead != ret_val);
1063 output_unsigned_leb128 (value)
1064 register unsigned long value;
1066 register unsigned long orig_value = value;
1070 register unsigned byte = (value & 0x7f);
1073 if (value != 0) /* more bytes to follow */
1075 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1076 if (flag_verbose_asm && value == 0)
1077 fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1078 ASM_COMMENT_START, orig_value);
1079 fputc ('\n', asm_out_file);
1085 output_signed_leb128 (value)
1086 register long value;
1088 register long orig_value = value;
1089 register int negative = (value < 0);
1094 register unsigned byte = (value & 0x7f);
1098 value |= 0xfe000000; /* manually sign extend */
1099 if (((value == 0) && ((byte & 0x40) == 0))
1100 || ((value == -1) && ((byte & 0x40) == 1)))
1107 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1108 if (flag_verbose_asm && more == 0)
1109 fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1110 ASM_COMMENT_START, orig_value);
1111 fputc ('\n', asm_out_file);
1116 /**************** utility functions for attribute functions ******************/
1118 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1119 node in question represents the outermost pair of curly braces (i.e.
1120 the "body block") of a function or method.
1122 For any BLOCK node representing a "body block" of a function or method,
1123 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1124 which represents the outermost (function) scope for the function or
1125 method (i.e. the one which includes the formal parameters). The
1126 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1131 is_body_block (stmt)
1134 if (TREE_CODE (stmt) == BLOCK)
1136 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1138 if (TREE_CODE (parent) == BLOCK)
1140 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1142 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1149 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1150 type code for the given type.
1152 This routine must only be called for GCC type nodes that correspond to
1153 Dwarf fundamental types.
1155 The current Dwarf draft specification calls for Dwarf fundamental types
1156 to accurately reflect the fact that a given type was either a "plain"
1157 integral type or an explicitly "signed" integral type. Unfortunately,
1158 we can't always do this, because GCC may already have thrown away the
1159 information about the precise way in which the type was originally
1162 typedef signed int my_type;
1164 struct s { my_type f; };
1166 Since we may be stuck here without enought information to do exactly
1167 what is called for in the Dwarf draft specification, we do the best
1168 that we can under the circumstances and always use the "plain" integral
1169 fundamental type codes for int, short, and long types. That's probably
1170 good enough. The additional accuracy called for in the current DWARF
1171 draft specification is probably never even useful in practice. */
1174 fundamental_type_code (type)
1177 if (TREE_CODE (type) == ERROR_MARK)
1180 switch (TREE_CODE (type))
1189 /* Carefully distinguish all the standard types of C,
1190 without messing up if the language is not C.
1191 Note that we check only for the names that contain spaces;
1192 other names might occur by coincidence in other languages. */
1193 if (TYPE_NAME (type) != 0
1194 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1195 && DECL_NAME (TYPE_NAME (type)) != 0
1196 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1198 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1200 if (!strcmp (name, "unsigned char"))
1201 return FT_unsigned_char;
1202 if (!strcmp (name, "signed char"))
1203 return FT_signed_char;
1204 if (!strcmp (name, "unsigned int"))
1205 return FT_unsigned_integer;
1206 if (!strcmp (name, "short int"))
1208 if (!strcmp (name, "short unsigned int"))
1209 return FT_unsigned_short;
1210 if (!strcmp (name, "long int"))
1212 if (!strcmp (name, "long unsigned int"))
1213 return FT_unsigned_long;
1214 if (!strcmp (name, "long long int"))
1215 return FT_long_long; /* Not grok'ed by svr4 SDB */
1216 if (!strcmp (name, "long long unsigned int"))
1217 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1220 /* Most integer types will be sorted out above, however, for the
1221 sake of special `array index' integer types, the following code
1222 is also provided. */
1224 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1225 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1227 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1228 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1230 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1231 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1233 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1234 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1236 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1237 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1242 /* Carefully distinguish all the standard types of C,
1243 without messing up if the language is not C. */
1244 if (TYPE_NAME (type) != 0
1245 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1246 && DECL_NAME (TYPE_NAME (type)) != 0
1247 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1249 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1251 /* Note that here we can run afowl of a serious bug in "classic"
1252 svr4 SDB debuggers. They don't seem to understand the
1253 FT_ext_prec_float type (even though they should). */
1255 if (!strcmp (name, "long double"))
1256 return FT_ext_prec_float;
1259 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1260 return FT_dbl_prec_float;
1261 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1264 /* Note that here we can run afowl of a serious bug in "classic"
1265 svr4 SDB debuggers. They don't seem to understand the
1266 FT_ext_prec_float type (even though they should). */
1268 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1269 return FT_ext_prec_float;
1273 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1276 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1279 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1282 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1287 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1288 the Dwarf "root" type for the given input type. The Dwarf "root" type
1289 of a given type is generally the same as the given type, except that if
1290 the given type is a pointer or reference type, then the root type of
1291 the given type is the root type of the "basis" type for the pointer or
1292 reference type. (This definition of the "root" type is recursive.)
1293 Also, the root type of a `const' qualified type or a `volatile'
1294 qualified type is the root type of the given type without the
1301 if (TREE_CODE (type) == ERROR_MARK)
1302 return error_mark_node;
1304 switch (TREE_CODE (type))
1307 return error_mark_node;
1310 case REFERENCE_TYPE:
1311 return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type)));
1314 return TYPE_MAIN_VARIANT (type);
1318 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1319 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1322 write_modifier_bytes (type, decl_const, decl_volatile)
1324 register int decl_const;
1325 register int decl_volatile;
1327 if (TREE_CODE (type) == ERROR_MARK)
1330 if (TYPE_READONLY (type) || decl_const)
1331 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1332 if (TYPE_VOLATILE (type) || decl_volatile)
1333 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1334 switch (TREE_CODE (type))
1337 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1338 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1341 case REFERENCE_TYPE:
1342 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1343 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1352 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1353 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1356 type_is_fundamental (type)
1359 switch (TREE_CODE (type))
1378 case REFERENCE_TYPE:
1391 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1392 equate directive which will associate a symbolic name with the current DIE.
1394 The name used is an artificial label generated from the DECL_UID number
1395 associated with the given decl node. The name it gets equated to is the
1396 symbolic label that we (previously) output at the start of the DIE that
1397 we are currently generating.
1399 Calling this function while generating some "decl related" form of DIE
1400 makes it possible to later refer to the DIE which represents the given
1401 decl simply by re-generating the symbolic name from the ..._DECL node's
1405 equate_decl_number_to_die_number (decl)
1408 /* In the case where we are generating a DIE for some ..._DECL node
1409 which represents either some inline function declaration or some
1410 entity declared within an inline function declaration/definition,
1411 setup a symbolic name for the current DIE so that we have a name
1412 for this DIE that we can easily refer to later on within
1413 AT_abstract_origin attributes. */
1415 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1416 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1418 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1419 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1420 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1423 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1424 equate directive which will associate a symbolic name with the current DIE.
1426 The name used is an artificial label generated from the TYPE_UID number
1427 associated with the given type node. The name it gets equated to is the
1428 symbolic label that we (previously) output at the start of the DIE that
1429 we are currently generating.
1431 Calling this function while generating some "type related" form of DIE
1432 makes it easy to later refer to the DIE which represents the given type
1433 simply by re-generating the alternative name from the ..._TYPE node's
1437 equate_type_number_to_die_number (type)
1440 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1441 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1443 /* We are generating a DIE to represent the main variant of this type
1444 (i.e the type without any const or volatile qualifiers) so in order
1445 to get the equate to come out right, we need to get the main variant
1448 type = TYPE_MAIN_VARIANT (type);
1450 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1451 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1452 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1456 output_reg_number (rtl)
1459 register unsigned regno = REGNO (rtl);
1461 if (regno >= FIRST_PSEUDO_REGISTER)
1463 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
1467 fprintf (asm_out_file, "\t%s\t0x%x",
1468 UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
1469 if (flag_verbose_asm)
1471 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
1472 PRINT_REG (rtl, 0, asm_out_file);
1474 fputc ('\n', asm_out_file);
1477 /* The following routine is a nice and simple transducer. It converts the
1478 RTL for a variable or parameter (resident in memory) into an equivalent
1479 Dwarf representation of a mechanism for getting the address of that same
1480 variable onto the top of a hypothetical "address evaluation" stack.
1482 When creating memory location descriptors, we are effectively trans-
1483 forming the RTL for a memory-resident object into its Dwarf postfix
1484 expression equivalent. This routine just recursively descends an
1485 RTL tree, turning it into Dwarf postfix code as it goes. */
1488 output_mem_loc_descriptor (rtl)
1491 /* Note that for a dynamically sized array, the location we will
1492 generate a description of here will be the lowest numbered location
1493 which is actually within the array. That's *not* necessarily the
1494 same as the zeroth element of the array. */
1496 switch (GET_CODE (rtl))
1500 /* The case of a subreg may arise when we have a local (register)
1501 variable or a formal (register) parameter which doesn't quite
1502 fill up an entire register. For now, just assume that it is
1503 legitimate to make the Dwarf info refer to the whole register
1504 which contains the given subreg. */
1506 rtl = XEXP (rtl, 0);
1511 /* Whenever a register number forms a part of the description of
1512 the method for calculating the (dynamic) address of a memory
1513 resident object, DWARF rules require the register number to
1514 be referred to as a "base register". This distinction is not
1515 based in any way upon what category of register the hardware
1516 believes the given register belongs to. This is strictly
1517 DWARF terminology we're dealing with here.
1519 Note that in cases where the location of a memory-resident data
1520 object could be expressed as:
1522 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1524 the actual DWARF location descriptor that we generate may just
1525 be OP_BASEREG (basereg). This may look deceptively like the
1526 object in question was allocated to a register (rather than
1527 in memory) so DWARF consumers need to be aware of the subtle
1528 distinction between OP_REG and OP_BASEREG. */
1530 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1531 output_reg_number (rtl);
1535 output_mem_loc_descriptor (XEXP (rtl, 0));
1536 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1541 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1542 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1546 output_mem_loc_descriptor (XEXP (rtl, 0));
1547 output_mem_loc_descriptor (XEXP (rtl, 1));
1548 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1552 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1553 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1561 /* Output a proper Dwarf location descriptor for a variable or parameter
1562 which is either allocated in a register or in a memory location. For
1563 a register, we just generate an OP_REG and the register number. For a
1564 memory location we provide a Dwarf postfix expression describing how to
1565 generate the (dynamic) address of the object onto the address stack. */
1568 output_loc_descriptor (rtl)
1571 switch (GET_CODE (rtl))
1575 /* The case of a subreg may arise when we have a local (register)
1576 variable or a formal (register) parameter which doesn't quite
1577 fill up an entire register. For now, just assume that it is
1578 legitimate to make the Dwarf info refer to the whole register
1579 which contains the given subreg. */
1581 rtl = XEXP (rtl, 0);
1585 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1586 output_reg_number (rtl);
1590 output_mem_loc_descriptor (XEXP (rtl, 0));
1594 abort (); /* Should never happen */
1598 /* Given a tree node describing an array bound (either lower or upper)
1599 output a representation for that bound. */
1602 output_bound_representation (bound, dim_num, u_or_l)
1603 register tree bound;
1604 register unsigned dim_num; /* For multi-dimensional arrays. */
1605 register char u_or_l; /* Designates upper or lower bound. */
1607 switch (TREE_CODE (bound))
1613 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1616 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1617 (unsigned) TREE_INT_CST_LOW (bound));
1620 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1624 bound = TREE_OPERAND (bound, 0);
1625 /* ... fall thru... */
1629 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1630 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1632 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1633 current_dienum, dim_num, u_or_l);
1635 sprintf (end_label, BOUND_END_LABEL_FMT,
1636 current_dienum, dim_num, u_or_l);
1638 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1639 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1641 /* If we are working on a bound for a dynamic dimension in C,
1642 the dynamic dimension in question had better have a static
1643 (zero) lower bound and a dynamic *upper* bound. */
1648 /* If optimization is turned on, the SAVE_EXPRs that describe
1649 how to access the upper bound values are essentially bogus.
1650 They only describe (at best) how to get at these values at
1651 the points in the generated code right after they have just
1652 been computed. Worse yet, in the typical case, the upper
1653 bound values will not even *be* computed in the optimized
1654 code, so these SAVE_EXPRs are entirely bogus.
1656 In order to compensate for this fact, we check here to see
1657 if optimization is enabled, and if so, we effectively create
1658 an empty location description for the (unknown and unknowable)
1661 This should not cause too much trouble for existing (stupid?)
1662 debuggers because they have to deal with empty upper bounds
1663 location descriptions anyway in order to be able to deal with
1664 incomplete array types.
1666 Of course an intelligent debugger (GDB?) should be able to
1667 comprehend that a missing upper bound specification in a
1668 array type used for a storage class `auto' local array variable
1669 indicates that the upper bound is both unknown (at compile-
1670 time) and unknowable (at run-time) due to optimization.
1674 output_loc_descriptor
1675 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1677 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1686 /* Recursive function to output a sequence of value/name pairs for
1687 enumeration constants in reversed order. This is called from
1688 enumeration_type_die. */
1691 output_enumeral_list (link)
1696 output_enumeral_list (TREE_CHAIN (link));
1697 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1698 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1699 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1700 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1704 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1705 which is not less than the value itself. */
1708 ceiling (value, boundary)
1709 register unsigned value;
1710 register unsigned boundary;
1712 return (((value + boundary - 1) / boundary) * boundary);
1715 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1716 pointer to the declared type for the relevant field variable, or return
1717 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1725 if (TREE_CODE (decl) == ERROR_MARK)
1726 return integer_type_node;
1728 type = DECL_BIT_FIELD_TYPE (decl);
1730 type = TREE_TYPE (decl);
1734 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1735 node, return the alignment in bits for the type, or else return
1736 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1739 simple_type_align_in_bits (type)
1742 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1745 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1746 node, return the size in bits for the type if it is a constant, or
1747 else return the alignment for the type if the type's size is not
1748 constant, or else return BITS_PER_WORD if the type actually turns out
1749 to be an ERROR_MARK node. */
1752 simple_type_size_in_bits (type)
1755 if (TREE_CODE (type) == ERROR_MARK)
1756 return BITS_PER_WORD;
1759 register tree type_size_tree = TYPE_SIZE (type);
1761 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1762 return TYPE_ALIGN (type);
1764 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1768 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1769 return the byte offset of the lowest addressed byte of the "containing
1770 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1771 mine what that offset is, either because the argument turns out to be a
1772 pointer to an ERROR_MARK node, or because the offset is actually variable.
1773 (We can't handle the latter case just yet.) */
1776 field_byte_offset (decl)
1779 register unsigned type_align_in_bytes;
1780 register unsigned type_align_in_bits;
1781 register unsigned type_size_in_bits;
1782 register unsigned object_offset_in_align_units;
1783 register unsigned object_offset_in_bits;
1784 register unsigned object_offset_in_bytes;
1786 register tree bitpos_tree;
1787 register tree field_size_tree;
1788 register unsigned bitpos_int;
1789 register unsigned deepest_bitpos;
1790 register unsigned field_size_in_bits;
1792 if (TREE_CODE (decl) == ERROR_MARK)
1795 if (TREE_CODE (decl) != FIELD_DECL)
1798 type = field_type (decl);
1800 bitpos_tree = DECL_FIELD_BITPOS (decl);
1801 field_size_tree = DECL_SIZE (decl);
1803 /* We cannot yet cope with fields whose positions or sizes are variable,
1804 so for now, when we see such things, we simply return 0. Someday,
1805 we may be able to handle such cases, but it will be damn difficult. */
1807 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1809 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1811 if (TREE_CODE (field_size_tree) != INTEGER_CST)
1813 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
1815 type_size_in_bits = simple_type_size_in_bits (type);
1817 type_align_in_bits = simple_type_align_in_bits (type);
1818 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1820 /* Note that the GCC front-end doesn't make any attempt to keep track
1821 of the starting bit offset (relative to the start of the containing
1822 structure type) of the hypothetical "containing object" for a bit-
1823 field. Thus, when computing the byte offset value for the start of
1824 the "containing object" of a bit-field, we must deduce this infor-
1827 This can be rather tricky to do in some cases. For example, handling
1828 the following structure type definition when compiling for an i386/i486
1829 target (which only aligns long long's to 32-bit boundaries) can be very
1834 long long field2:31;
1837 Fortunately, there is a simple rule-of-thumb which can be used in such
1838 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
1839 the structure shown above. It decides to do this based upon one simple
1840 rule for bit-field allocation. Quite simply, GCC allocates each "con-
1841 taining object" for each bit-field at the first (i.e. lowest addressed)
1842 legitimate alignment boundary (based upon the required minimum alignment
1843 for the declared type of the field) which it can possibly use, subject
1844 to the condition that there is still enough available space remaining
1845 in the containing object (when allocated at the selected point) to
1846 fully accomodate all of the bits of the bit-field itself.
1848 This simple rule makes it obvious why GCC allocates 8 bytes for each
1849 object of the structure type shown above. When looking for a place to
1850 allocate the "containing object" for `field2', the compiler simply tries
1851 to allocate a 64-bit "containing object" at each successive 32-bit
1852 boundary (starting at zero) until it finds a place to allocate that 64-
1853 bit field such that at least 31 contiguous (and previously unallocated)
1854 bits remain within that selected 64 bit field. (As it turns out, for
1855 the example above, the compiler finds that it is OK to allocate the
1856 "containing object" 64-bit field at bit-offset zero within the
1859 Here we attempt to work backwards from the limited set of facts we're
1860 given, and we try to deduce from those facts, where GCC must have
1861 believed that the containing object started (within the structure type).
1863 The value we deduce is then used (by the callers of this routine) to
1864 generate AT_location and AT_bit_offset attributes for fields (both
1865 bit-fields and, in the case of AT_location, regular fields as well).
1868 /* Figure out the bit-distance from the start of the structure to the
1869 "deepest" bit of the bit-field. */
1870 deepest_bitpos = bitpos_int + field_size_in_bits;
1872 /* This is the tricky part. Use some fancy footwork to deduce where the
1873 lowest addressed bit of the containing object must be. */
1874 object_offset_in_bits
1875 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
1877 /* Compute the offset of the containing object in "alignment units". */
1878 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
1880 /* Compute the offset of the containing object in bytes. */
1881 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
1883 return object_offset_in_bytes;
1886 /****************************** attributes *********************************/
1888 /* The following routines are responsible for writing out the various types
1889 of Dwarf attributes (and any following data bytes associated with them).
1890 These routines are listed in order based on the numerical codes of their
1891 associated attributes. */
1893 /* Generate an AT_sibling attribute. */
1896 sibling_attribute ()
1898 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1900 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
1901 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
1902 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1905 /* Output the form of location attributes suitable for whole variables and
1906 whole parameters. Note that the location attributes for struct fields
1907 are generated by the routine `data_member_location_attribute' below. */
1910 location_attribute (rtl)
1913 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1914 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1916 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1917 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1918 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1919 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1920 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1922 /* Handle a special case. If we are about to output a location descriptor
1923 for a variable or parameter which has been optimized out of existence,
1924 don't do that. Instead we output a zero-length location descriptor
1925 value as part of the location attribute.
1927 A variable which has been optimized out of existance will have a
1928 DECL_RTL value which denotes a pseudo-reg.
1930 Currently, in some rare cases, variables can have DECL_RTL values
1931 which look like (MEM (REG pseudo-reg#)). These cases are due to
1932 bugs elsewhere in the compiler. We treat such cases
1933 as if the variable(s) in question had been optimized out of existance.
1935 Note that in all cases where we wish to express the fact that a
1936 variable has been optimized out of existance, we do not simply
1937 suppress the generation of the entire location attribute because
1938 the absence of a location attribute in certain kinds of DIEs is
1939 used to indicate something else entirely... i.e. that the DIE
1940 represents an object declaration, but not a definition. So sayeth
1944 if (! is_pseudo_reg (rtl)
1945 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
1946 output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
1948 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1951 /* Output the specialized form of location attribute used for data members
1952 of struct and union types.
1954 In the special case of a FIELD_DECL node which represents a bit-field,
1955 the "offset" part of this special location descriptor must indicate the
1956 distance in bytes from the lowest-addressed byte of the containing
1957 struct or union type to the lowest-addressed byte of the "containing
1958 object" for the bit-field. (See the `field_byte_offset' function above.)
1960 For any given bit-field, the "containing object" is a hypothetical
1961 object (of some integral or enum type) within which the given bit-field
1962 lives. The type of this hypothetical "containing object" is always the
1963 same as the declared type of the individual bit-field itself (for GCC
1964 anyway... the DWARF spec doesn't actually mandate this).
1966 Note that it is the size (in bytes) of the hypothetical "containing
1967 object" which will be given in the AT_byte_size attribute for this
1968 bit-field. (See the `byte_size_attribute' function below.) It is
1969 also used when calculating the value of the AT_bit_offset attribute.
1970 (See the `bit_offset_attribute' function below.)
1974 data_member_location_attribute (decl)
1977 register unsigned object_offset_in_bytes = field_byte_offset (decl);
1978 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1979 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1981 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1982 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1983 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1984 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1985 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1986 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1987 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
1988 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1989 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1992 /* Output an AT_const_value attribute for a variable or a parameter which
1993 does not have a "location" either in memory or in a register. These
1994 things can arise in GNU C when a constant is passed as an actual
1995 parameter to an inlined function. They can also arise in C++ where
1996 declared constants do not necessarily get memory "homes". */
1999 const_value_attribute (rtl)
2002 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2003 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2005 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
2006 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
2007 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
2008 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2009 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2011 switch (GET_CODE (rtl))
2014 /* Note that a CONST_INT rtx could represent either an integer or
2015 a floating-point constant. A CONST_INT is used whenever the
2016 constant will fit into a single word. In all such cases, the
2017 original mode of the constant value is wiped out, and the
2018 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2019 precise mode information for these constants, we always just
2020 output them using 4 bytes. */
2022 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2026 /* Note that a CONST_DOUBLE rtx could represent either an integer
2027 or a floating-point constant. A CONST_DOUBLE is used whenever
2028 the constant requires more than one word in order to be adequately
2029 represented. In all such cases, the original mode of the constant
2030 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2031 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2033 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2034 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2035 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2039 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2045 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2049 /* In cases where an inlined instance of an inline function is passed
2050 the address of an `auto' variable (which is local to the caller)
2051 we can get a situation where the DECL_RTL of the artificial
2052 local variable (for the inlining) which acts as a stand-in for
2053 the corresponding formal parameter (of the inline function)
2054 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2055 This is not exactly a compile-time constant expression, but it
2056 isn't the address of the (artificial) local variable either.
2057 Rather, it represents the *value* which the artificial local
2058 variable always has during its lifetime. We currently have no
2059 way to represent such quasi-constant values in Dwarf, so for now
2060 we just punt and generate an AT_const_value attribute with form
2061 FORM_BLOCK4 and a length of zero. */
2065 abort (); /* No other kinds of rtx should be possible here. */
2068 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2071 /* Generate *either* an AT_location attribute or else an AT_const_value
2072 data attribute for a variable or a parameter. We generate the
2073 AT_const_value attribute only in those cases where the given
2074 variable or parameter does not have a true "location" either in
2075 memory or in a register. This can happen (for example) when a
2076 constant is passed as an actual argument in a call to an inline
2077 function. (It's possible that these things can crop up in other
2078 ways also.) Note that one type of constant value which can be
2079 passed into an inlined function is a constant pointer. This can
2080 happen for example if an actual argument in an inlined function
2081 call evaluates to a compile-time constant address. */
2084 location_or_const_value_attribute (decl)
2089 if (TREE_CODE (decl) == ERROR_MARK)
2092 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2095 /* Existing Dwarf debuggers need and expect the location descriptors for
2096 formal parameters to reflect either the place where the parameters get
2097 passed (if they are passed on the stack and in memory) or else the
2098 (preserved) registers which the parameters get copied to during the
2101 At least this is the way things are for most common CISC machines
2102 (e.g. x86 and m68k) where parameters are passed in the stack, and for
2103 most common RISC machines (e.g. i860 and m88k) where parameters are
2104 passed in registers.
2106 The rules for Sparc are a little weird for some reason. The DWARF
2107 generated by the USL C compiler for the Sparc/svr4 reference port says
2108 that the parameters are passed in the stack. I haven't figured out
2109 how to duplicate that behavior here (for the Sparc) yet, or even if
2112 Note that none of this is clearly spelled out in the current Dwarf
2113 version 1 specification, but it's obvious if you look at the output of
2114 the CI5 compiler, or if you try to use the svr4 SDB debugger. Hopefully,
2115 a later version of the Dwarf specification will clarify this. For now,
2116 we just need to generate the right thing. Note that Dwarf version 2
2117 will provide us with a means to describe *all* of the locations in which
2118 a given variable or parameter resides (and the PC ranges over which it
2119 occupies each one), but for now we can only describe one "location"
2120 for each formal parameter passed, and so we just try to mimic existing
2121 practice as much as possible.
2124 if (TREE_CODE (decl) != PARM_DECL)
2125 /* If this decl is not a formal parameter, just use DECL_RTL. */
2126 rtl = DECL_RTL (decl);
2129 if (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM)
2130 /* Parameter was passed in memory, so say that's where it lives. */
2131 rtl = DECL_INCOMING_RTL (decl);
2134 /* Parameter was passed in a register, so say it lives in the
2135 register it will be copied to during the prologue. */
2136 rtl = DECL_RTL (decl);
2138 /* Note that in cases where the formal parameter is never used
2139 and where this compilation is done with -O, the copying of
2140 of an incoming register parameter to another register (in
2141 the prologue) can be totally optimized away. (In such cases
2142 the DECL_RTL will indicate a pseudo-register.) We could just
2143 use the DECL_RTL (as we normally do for register parameters)
2144 in these cases, but if we did that, we would end up generating
2145 a null location descriptor. (See `location_attribute' above.)
2146 That would be acceptable (according to the DWARF spec) but it
2147 is probably more useful to say that the formal resides where
2148 it was passed instead of saying that it resides nowhere. */
2149 if (is_pseudo_reg (rtl))
2150 rtl = DECL_INCOMING_RTL (decl);
2157 switch (GET_CODE (rtl))
2165 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2166 const_value_attribute (rtl);
2172 location_attribute (rtl);
2176 abort (); /* Should never happen. */
2180 /* Generate an AT_name attribute given some string value to be included as
2181 the value of the attribute. */
2184 name_attribute (name_string)
2185 register char *name_string;
2187 if (name_string && *name_string)
2189 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2190 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2195 fund_type_attribute (ft_code)
2196 register unsigned ft_code;
2198 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2199 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2203 mod_fund_type_attribute (type, decl_const, decl_volatile)
2205 register int decl_const;
2206 register int decl_volatile;
2208 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2209 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2211 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2212 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2213 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2214 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2215 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2216 write_modifier_bytes (type, decl_const, decl_volatile);
2217 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2218 fundamental_type_code (root_type (type)));
2219 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2223 user_def_type_attribute (type)
2226 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2228 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2229 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2230 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2234 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2236 register int decl_const;
2237 register int decl_volatile;
2239 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2240 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2241 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2243 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2244 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2245 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2246 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2247 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2248 write_modifier_bytes (type, decl_const, decl_volatile);
2249 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2250 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2251 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2254 #ifdef USE_ORDERING_ATTRIBUTE
2256 ordering_attribute (ordering)
2257 register unsigned ordering;
2259 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2260 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2262 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2264 /* Note that the block of subscript information for an array type also
2265 includes information about the element type of type given array type. */
2268 subscript_data_attribute (type)
2271 register unsigned dimension_number;
2272 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2273 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2275 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2276 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2277 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2278 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2279 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2281 /* The GNU compilers represent multidimensional array types as sequences
2282 of one dimensional array types whose element types are themselves array
2283 types. Here we squish that down, so that each multidimensional array
2284 type gets only one array_type DIE in the Dwarf debugging info. The
2285 draft Dwarf specification say that we are allowed to do this kind
2286 of compression in C (because there is no difference between an
2287 array or arrays and a multidimensional array in C) but for other
2288 source languages (e.g. Ada) we probably shouldn't do this. */
2290 for (dimension_number = 0;
2291 TREE_CODE (type) == ARRAY_TYPE;
2292 type = TREE_TYPE (type), dimension_number++)
2294 register tree domain = TYPE_DOMAIN (type);
2296 /* Arrays come in three flavors. Unspecified bounds, fixed
2297 bounds, and (in GNU C only) variable bounds. Handle all
2298 three forms here. */
2302 /* We have an array type with specified bounds. */
2304 register tree lower = TYPE_MIN_VALUE (domain);
2305 register tree upper = TYPE_MAX_VALUE (domain);
2307 /* Handle only fundamental types as index types for now. */
2309 if (! type_is_fundamental (domain))
2312 /* Output the representation format byte for this dimension. */
2314 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2316 TREE_CODE (lower) == INTEGER_CST,
2317 TREE_CODE (upper) == INTEGER_CST));
2319 /* Output the index type for this dimension. */
2321 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2322 fundamental_type_code (domain));
2324 /* Output the representation for the lower bound. */
2326 output_bound_representation (lower, dimension_number, 'l');
2328 /* Output the representation for the upper bound. */
2330 output_bound_representation (upper, dimension_number, 'u');
2334 /* We have an array type with an unspecified length. For C and
2335 C++ we can assume that this really means that (a) the index
2336 type is an integral type, and (b) the lower bound is zero.
2337 Note that Dwarf defines the representation of an unspecified
2338 (upper) bound as being a zero-length location description. */
2340 /* Output the array-bounds format byte. */
2342 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2344 /* Output the (assumed) index type. */
2346 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2348 /* Output the (assumed) lower bound (constant) value. */
2350 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2352 /* Output the (empty) location description for the upper bound. */
2354 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2358 /* Output the prefix byte that says that the element type is comming up. */
2360 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2362 /* Output a representation of the type of the elements of this array type. */
2364 type_attribute (type, 0, 0);
2366 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2370 byte_size_attribute (tree_node)
2371 register tree tree_node;
2373 register unsigned size;
2375 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2376 switch (TREE_CODE (tree_node))
2385 size = int_size_in_bytes (tree_node);
2389 /* For a data member of a struct or union, the AT_byte_size is
2390 generally given as the number of bytes normally allocated for
2391 an object of the *declared* type of the member itself. This
2392 is true even for bit-fields. */
2393 size = simple_type_size_in_bits (field_type (tree_node))
2401 /* Note that `size' might be -1 when we get to this point. If it
2402 is, that indicates that the byte size of the entity in question
2403 is variable. We have no good way of expressing this fact in Dwarf
2404 at the present time, so just let the -1 pass on through. */
2406 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2409 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2410 which specifies the distance in bits from the highest order bit of the
2411 "containing object" for the bit-field to the highest order bit of the
2414 For any given bit-field, the "containing object" is a hypothetical
2415 object (of some integral or enum type) within which the given bit-field
2416 lives. The type of this hypothetical "containing object" is always the
2417 same as the declared type of the individual bit-field itself.
2419 The determination of the exact location of the "containing object" for
2420 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2423 Note that it is the size (in bytes) of the hypothetical "containing
2424 object" which will be given in the AT_byte_size attribute for this
2425 bit-field. (See `byte_size_attribute' above.)
2429 bit_offset_attribute (decl)
2432 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2433 register tree type = DECL_BIT_FIELD_TYPE (decl);
2434 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2435 register unsigned bitpos_int;
2436 register unsigned highest_order_object_bit_offset;
2437 register unsigned highest_order_field_bit_offset;
2438 register unsigned bit_offset;
2440 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2441 assert (type); /* Must be a bit field. */
2443 /* We can't yet handle bit-fields whose offsets are variable, so if we
2444 encounter such things, just return without generating any attribute
2447 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2449 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2451 /* Note that the bit offset is always the distance (in bits) from the
2452 highest-order bit of the "containing object" to the highest-order
2453 bit of the bit-field itself. Since the "high-order end" of any
2454 object or field is different on big-endian and little-endian machines,
2455 the computation below must take account of these differences. */
2457 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2458 highest_order_field_bit_offset = bitpos_int;
2460 #if (BYTES_BIG_ENDIAN == 0)
2461 highest_order_field_bit_offset
2462 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2464 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2465 #endif /* (BYTES_BIG_ENDIAN == 0) */
2468 #if (BYTES_BIG_ENDIAN == 0)
2469 highest_order_object_bit_offset - highest_order_field_bit_offset;
2470 #else /* (BYTES_BIG_ENDIAN != 0) */
2471 highest_order_field_bit_offset - highest_order_object_bit_offset;
2472 #endif /* (BYTES_BIG_ENDIAN != 0) */
2474 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2475 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2478 /* For a FIELD_DECL node which represents a bit field, output an attribute
2479 which specifies the length in bits of the given field. */
2482 bit_size_attribute (decl)
2485 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2486 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
2488 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2489 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2490 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2493 /* The following routine outputs the `element_list' attribute for enumeration
2494 type DIEs. The element_lits attribute includes the names and values of
2495 all of the enumeration constants associated with the given enumeration
2499 element_list_attribute (element)
2500 register tree element;
2502 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2503 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2505 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2506 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2507 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2508 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2509 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2511 /* Here we output a list of value/name pairs for each enumeration constant
2512 defined for this enumeration type (as required), but we do it in REVERSE
2513 order. The order is the one required by the draft #5 Dwarf specification
2514 published by the UI/PLSIG. */
2516 output_enumeral_list (element); /* Recursively output the whole list. */
2518 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2521 /* Generate an AT_stmt_list attribute. These are normally present only in
2522 DIEs with a TAG_compile_unit tag. */
2525 stmt_list_attribute (label)
2526 register char *label;
2528 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2529 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2530 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2533 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2534 for a subroutine DIE. */
2537 low_pc_attribute (asm_low_label)
2538 register char *asm_low_label;
2540 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2541 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2544 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2548 high_pc_attribute (asm_high_label)
2549 register char *asm_high_label;
2551 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2552 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2555 /* Generate an AT_language attribute given a LANG value. These attributes
2556 are used only within TAG_compile_unit DIEs. */
2559 language_attribute (language_code)
2560 register unsigned language_code;
2562 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2563 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2567 member_attribute (context)
2568 register tree context;
2570 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2572 /* Generate this attribute only for members in C++. */
2574 if (context != NULL && is_tagged_type (context))
2576 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2577 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2578 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2583 string_length_attribute (upper_bound)
2584 register tree upper_bound;
2586 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2587 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2589 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2590 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2591 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2592 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2593 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2594 output_bound_representation (upper_bound, 0, 'u');
2595 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2599 comp_dir_attribute (dirname)
2600 register char *dirname;
2602 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2603 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2607 sf_names_attribute (sf_names_start_label)
2608 register char *sf_names_start_label;
2610 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2611 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2612 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2616 src_info_attribute (src_info_start_label)
2617 register char *src_info_start_label;
2619 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2620 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2621 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2625 mac_info_attribute (mac_info_start_label)
2626 register char *mac_info_start_label;
2628 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2629 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2630 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2634 prototyped_attribute (func_type)
2635 register tree func_type;
2637 if ((strcmp (language_string, "GNU C") == 0)
2638 && (TYPE_ARG_TYPES (func_type) != NULL))
2640 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2641 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2646 producer_attribute (producer)
2647 register char *producer;
2649 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2650 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2654 inline_attribute (decl)
2657 if (DECL_INLINE (decl))
2659 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2660 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2665 containing_type_attribute (containing_type)
2666 register tree containing_type;
2668 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2670 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2671 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2672 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2676 abstract_origin_attribute (origin)
2677 register tree origin;
2679 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2681 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2682 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2685 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2689 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2693 abort (); /* Should never happen. */
2696 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2699 #ifdef DWARF_DECL_COORDINATES
2701 src_coords_attribute (src_fileno, src_lineno)
2702 register unsigned src_fileno;
2703 register unsigned src_lineno;
2705 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2706 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2707 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2709 #endif /* defined(DWARF_DECL_COORDINATES) */
2712 pure_or_virtual_attribute (func_decl)
2713 register tree func_decl;
2715 if (DECL_VIRTUAL_P (func_decl))
2717 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
2718 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2719 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2722 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2723 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2727 /************************* end of attributes *****************************/
2729 /********************* utility routines for DIEs *************************/
2731 /* Output an AT_name attribute and an AT_src_coords attribute for the
2732 given decl, but only if it actually has a name. */
2735 name_and_src_coords_attributes (decl)
2738 register tree decl_name = DECL_NAME (decl);
2740 if (decl_name && IDENTIFIER_POINTER (decl_name))
2742 name_attribute (IDENTIFIER_POINTER (decl_name));
2743 #ifdef DWARF_DECL_COORDINATES
2745 register unsigned file_index;
2747 /* This is annoying, but we have to pop out of the .debug section
2748 for a moment while we call `lookup_filename' because calling it
2749 may cause a temporary switch into the .debug_sfnames section and
2750 most svr4 assemblers are not smart enough be be able to nest
2751 section switches to any depth greater than one. Note that we
2752 also can't skirt this issue by delaying all output to the
2753 .debug_sfnames section unit the end of compilation because that
2754 would cause us to have inter-section forward references and
2755 Fred Fish sez that m68k/svr4 assemblers botch those. */
2757 ASM_OUTPUT_POP_SECTION (asm_out_file);
2758 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
2759 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
2761 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
2763 #endif /* defined(DWARF_DECL_COORDINATES) */
2767 /* Many forms of DIEs contain a "type description" part. The following
2768 routine writes out these "type descriptor" parts. */
2771 type_attribute (type, decl_const, decl_volatile)
2773 register int decl_const;
2774 register int decl_volatile;
2776 register enum tree_code code = TREE_CODE (type);
2777 register int root_type_modified;
2779 if (TREE_CODE (type) == ERROR_MARK)
2782 /* Handle a special case. For functions whose return type is void,
2783 we generate *no* type attribute. (Note that no object may have
2784 type `void', so this only applies to function return types. */
2786 if (TREE_CODE (type) == VOID_TYPE)
2789 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2790 || decl_const || decl_volatile
2791 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2793 if (type_is_fundamental (root_type (type)))
2794 if (root_type_modified)
2795 mod_fund_type_attribute (type, decl_const, decl_volatile);
2797 fund_type_attribute (fundamental_type_code (type));
2799 if (root_type_modified)
2800 mod_u_d_type_attribute (type, decl_const, decl_volatile);
2802 user_def_type_attribute (type);
2805 /* Given a tree pointer to a struct, class, union, or enum type node, return
2806 a pointer to the (string) tag name for the given type, or zero if the
2807 type was declared without a tag. */
2813 register char *name = 0;
2815 if (TYPE_NAME (type) != 0)
2817 register tree t = 0;
2819 /* Find the IDENTIFIER_NODE for the type name. */
2820 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2821 t = TYPE_NAME (type);
2823 /* The g++ front end makes the TYPE_NAME of *each* tagged type point
2824 to a TYPE_DECL node, regardless of whether or not a `typedef' was
2825 involved. This is distinctly different from what the gcc front-end
2826 does. It always makes the TYPE_NAME for each tagged type be either
2827 NULL (signifying an anonymous tagged type) or else a pointer to an
2828 IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf
2829 for both C and C++, but given this inconsistency in the TREE
2830 representation of tagged types for C and C++ in the GNU front-ends,
2831 we cannot support both languages correctly unless we introduce some
2832 front-end specific code here, and rms objects to that, so we can
2833 only generate correct Dwarf for one of these two languages. C is
2834 more important, so for now we'll do the right thing for C and let
2838 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2839 t = DECL_NAME (TYPE_NAME (type));
2841 /* Now get the name as a string, or invent one. */
2843 name = IDENTIFIER_POINTER (t);
2846 return (name == 0 || *name == '\0') ? 0 : name;
2852 /* Start by checking if the pending_sibling_stack needs to be expanded.
2853 If necessary, expand it. */
2855 if (pending_siblings == pending_siblings_allocated)
2857 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
2858 pending_sibling_stack
2859 = (unsigned *) xrealloc (pending_sibling_stack,
2860 pending_siblings_allocated * sizeof(unsigned));
2864 NEXT_DIE_NUM = next_unused_dienum++;
2867 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
2877 member_declared_type (member)
2878 register tree member;
2880 return (DECL_BIT_FIELD_TYPE (member))
2881 ? DECL_BIT_FIELD_TYPE (member)
2882 : TREE_TYPE (member);
2885 /******************************* DIEs ************************************/
2887 /* Output routines for individual types of DIEs. */
2889 /* Note that every type of DIE (except a null DIE) gets a sibling. */
2892 output_array_type_die (arg)
2895 register tree type = arg;
2897 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
2898 sibling_attribute ();
2899 equate_type_number_to_die_number (type);
2900 member_attribute (TYPE_CONTEXT (type));
2902 /* I believe that we can default the array ordering. SDB will probably
2903 do the right things even if AT_ordering is not present. It's not
2904 even an issue until we start to get into multidimensional arrays
2905 anyway. If SDB is ever caught doing the Wrong Thing for multi-
2906 dimensional arrays, then we'll have to put the AT_ordering attribute
2907 back in. (But if and when we find out that we need to put these in,
2908 we will only do so for multidimensional arrays. After all, we don't
2909 want to waste space in the .debug section now do we?) */
2911 #ifdef USE_ORDERING_ATTRIBUTE
2912 ordering_attribute (ORD_row_major);
2913 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2915 subscript_data_attribute (type);
2919 output_set_type_die (arg)
2922 register tree type = arg;
2924 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
2925 sibling_attribute ();
2926 equate_type_number_to_die_number (type);
2927 member_attribute (TYPE_CONTEXT (type));
2928 type_attribute (TREE_TYPE (type), 0, 0);
2932 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
2934 output_entry_point_die (arg)
2937 register tree decl = arg;
2938 register tree origin = decl_ultimate_origin (decl);
2940 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
2941 sibling_attribute ();
2944 abstract_origin_attribute (origin);
2947 name_and_src_coords_attributes (decl);
2948 member_attribute (DECL_CONTEXT (decl));
2949 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
2951 if (DECL_ABSTRACT (decl))
2952 equate_decl_number_to_die_number (decl);
2954 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
2958 /* Output a DIE to represent an inlined instance of an enumeration type. */
2961 output_inlined_enumeration_type_die (arg)
2964 register tree type = arg;
2966 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2967 sibling_attribute ();
2968 assert (TREE_ASM_WRITTEN (type));
2969 abstract_origin_attribute (type);
2972 /* Output a DIE to represent an inlined instance of a structure type. */
2975 output_inlined_structure_type_die (arg)
2978 register tree type = arg;
2980 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
2981 sibling_attribute ();
2982 assert (TREE_ASM_WRITTEN (type));
2983 abstract_origin_attribute (type);
2986 /* Output a DIE to represent an inlined instance of a union type. */
2989 output_inlined_union_type_die (arg)
2992 register tree type = arg;
2994 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
2995 sibling_attribute ();
2996 assert (TREE_ASM_WRITTEN (type));
2997 abstract_origin_attribute (type);
3000 /* Output a DIE to represent an enumeration type. Note that these DIEs
3001 include all of the information about the enumeration values also.
3002 This information is encoded into the element_list attribute. */
3005 output_enumeration_type_die (arg)
3008 register tree type = arg;
3010 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
3011 sibling_attribute ();
3012 equate_type_number_to_die_number (type);
3013 name_attribute (type_tag (type));
3014 member_attribute (TYPE_CONTEXT (type));
3016 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3017 given enum type is incomplete, do not generate the AT_byte_size
3018 attribute or the AT_element_list attribute. */
3020 if (TYPE_SIZE (type))
3022 byte_size_attribute (type);
3023 element_list_attribute (TYPE_FIELDS (type));
3027 /* Output a DIE to represent either a real live formal parameter decl or
3028 to represent just the type of some formal parameter position in some
3031 Note that this routine is a bit unusual because its argument may be
3032 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3033 represents an inlining of some PARM_DECL) or else some sort of a
3034 ..._TYPE node. If it's the former then this function is being called
3035 to output a DIE to represent a formal parameter object (or some inlining
3036 thereof). If it's the latter, then this function is only being called
3037 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3038 formal argument type of some subprogram type. */
3041 output_formal_parameter_die (arg)
3044 register tree node = arg;
3046 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3047 sibling_attribute ();
3049 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3051 case 'd': /* We were called with some kind of a ..._DECL node. */
3053 register tree origin = decl_ultimate_origin (node);
3056 abstract_origin_attribute (origin);
3059 name_and_src_coords_attributes (node);
3060 type_attribute (TREE_TYPE (node),
3061 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3063 if (DECL_ABSTRACT (node))
3064 equate_decl_number_to_die_number (node);
3066 location_or_const_value_attribute (node);
3070 case 't': /* We were called with some kind of a ..._TYPE node. */
3071 type_attribute (node, 0, 0);
3075 abort (); /* Should never happen. */
3079 /* Output a DIE to represent a declared function (either file-scope
3080 or block-local) which has "external linkage" (according to ANSI-C). */
3083 output_global_subroutine_die (arg)
3086 register tree decl = arg;
3087 register tree origin = decl_ultimate_origin (decl);
3089 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3090 sibling_attribute ();
3093 abstract_origin_attribute (origin);
3096 register tree type = TREE_TYPE (decl);
3098 name_and_src_coords_attributes (decl);
3099 inline_attribute (decl);
3100 prototyped_attribute (type);
3101 member_attribute (DECL_CONTEXT (decl));
3102 type_attribute (TREE_TYPE (type), 0, 0);
3103 pure_or_virtual_attribute (decl);
3105 if (DECL_ABSTRACT (decl))
3106 equate_decl_number_to_die_number (decl);
3109 if (! DECL_EXTERNAL (decl))
3111 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3113 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
3114 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3115 high_pc_attribute (func_end_label);
3120 /* Output a DIE to represent a declared data object (either file-scope
3121 or block-local) which has "external linkage" (according to ANSI-C). */
3124 output_global_variable_die (arg)
3127 register tree decl = arg;
3128 register tree origin = decl_ultimate_origin (decl);
3130 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3131 sibling_attribute ();
3133 abstract_origin_attribute (origin);
3136 name_and_src_coords_attributes (decl);
3137 member_attribute (DECL_CONTEXT (decl));
3138 type_attribute (TREE_TYPE (decl),
3139 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3141 if (DECL_ABSTRACT (decl))
3142 equate_decl_number_to_die_number (decl);
3145 if (!DECL_EXTERNAL (decl))
3146 location_or_const_value_attribute (decl);
3151 output_label_die (arg)
3154 register tree decl = arg;
3155 register tree origin = decl_ultimate_origin (decl);
3157 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3158 sibling_attribute ();
3160 abstract_origin_attribute (origin);
3162 name_and_src_coords_attributes (decl);
3163 if (DECL_ABSTRACT (decl))
3164 equate_decl_number_to_die_number (decl);
3167 register rtx insn = DECL_RTL (decl);
3169 if (GET_CODE (insn) == CODE_LABEL)
3171 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3173 /* When optimization is enabled (via -O) some parts of the compiler
3174 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3175 represent source-level labels which were explicitly declared by
3176 the user. This really shouldn't be happening though, so catch
3177 it if it ever does happen. */
3179 if (INSN_DELETED_P (insn))
3180 abort (); /* Should never happen. */
3182 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3183 (unsigned) INSN_UID (insn));
3184 low_pc_attribute (label);
3190 output_lexical_block_die (arg)
3193 register tree stmt = arg;
3195 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3196 sibling_attribute ();
3198 if (! BLOCK_ABSTRACT (stmt))
3200 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3201 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3203 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3204 low_pc_attribute (begin_label);
3205 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3206 high_pc_attribute (end_label);
3211 output_inlined_subroutine_die (arg)
3214 register tree stmt = arg;
3216 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3217 sibling_attribute ();
3219 abstract_origin_attribute (block_ultimate_origin (stmt));
3220 if (! BLOCK_ABSTRACT (stmt))
3222 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3223 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3225 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3226 low_pc_attribute (begin_label);
3227 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3228 high_pc_attribute (end_label);
3232 /* Output a DIE to represent a declared data object (either file-scope
3233 or block-local) which has "internal linkage" (according to ANSI-C). */
3236 output_local_variable_die (arg)
3239 register tree decl = arg;
3240 register tree origin = decl_ultimate_origin (decl);
3242 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3243 sibling_attribute ();
3245 abstract_origin_attribute (origin);
3248 name_and_src_coords_attributes (decl);
3249 member_attribute (DECL_CONTEXT (decl));
3250 type_attribute (TREE_TYPE (decl),
3251 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3253 if (DECL_ABSTRACT (decl))
3254 equate_decl_number_to_die_number (decl);
3256 location_or_const_value_attribute (decl);
3260 output_member_die (arg)
3263 register tree decl = arg;
3265 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3266 sibling_attribute ();
3267 name_and_src_coords_attributes (decl);
3268 member_attribute (DECL_CONTEXT (decl));
3269 type_attribute (member_declared_type (decl),
3270 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3271 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3273 byte_size_attribute (decl);
3274 bit_size_attribute (decl);
3275 bit_offset_attribute (decl);
3277 data_member_location_attribute (decl);
3281 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3282 modified types instead.
3284 We keep this code here just in case these types of DIEs may be needed
3285 to represent certain things in other languages (e.g. Pascal) someday.
3289 output_pointer_type_die (arg)
3292 register tree type = arg;
3294 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3295 sibling_attribute ();
3296 equate_type_number_to_die_number (type);
3297 member_attribute (TYPE_CONTEXT (type));
3298 type_attribute (TREE_TYPE (type), 0, 0);
3302 output_reference_type_die (arg)
3305 register tree type = arg;
3307 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3308 sibling_attribute ();
3309 equate_type_number_to_die_number (type);
3310 member_attribute (TYPE_CONTEXT (type));
3311 type_attribute (TREE_TYPE (type), 0, 0);
3316 output_ptr_to_mbr_type_die (arg)
3319 register tree type = arg;
3321 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3322 sibling_attribute ();
3323 equate_type_number_to_die_number (type);
3324 member_attribute (TYPE_CONTEXT (type));
3325 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3326 type_attribute (TREE_TYPE (type), 0, 0);
3330 output_compile_unit_die (arg)
3333 register char *main_input_filename = arg;
3335 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3336 sibling_attribute ();
3338 name_attribute (main_input_filename);
3343 sprintf (producer, "%s %s", language_string, version_string);
3344 producer_attribute (producer);
3347 if (strcmp (language_string, "GNU C++") == 0)
3348 language_attribute (LANG_C_PLUS_PLUS);
3349 else if (flag_traditional)
3350 language_attribute (LANG_C);
3352 language_attribute (LANG_C89);
3353 low_pc_attribute (TEXT_BEGIN_LABEL);
3354 high_pc_attribute (TEXT_END_LABEL);
3355 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3356 stmt_list_attribute (LINE_BEGIN_LABEL);
3357 last_filename = xstrdup (main_input_filename);
3360 char *wd = getpwd ();
3362 comp_dir_attribute (wd);
3365 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3367 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3368 src_info_attribute (SRCINFO_BEGIN_LABEL);
3369 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3370 mac_info_attribute (MACINFO_BEGIN_LABEL);
3375 output_string_type_die (arg)
3378 register tree type = arg;
3380 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3381 sibling_attribute ();
3382 member_attribute (TYPE_CONTEXT (type));
3384 /* Fudge the string length attribute for now. */
3386 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
3390 output_structure_type_die (arg)
3393 register tree type = arg;
3395 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3396 sibling_attribute ();
3397 equate_type_number_to_die_number (type);
3398 name_attribute (type_tag (type));
3399 member_attribute (TYPE_CONTEXT (type));
3401 /* If this type has been completed, then give it a byte_size attribute
3402 and prepare to give a list of members. Otherwise, don't do either of
3403 these things. In the latter case, we will not be generating a list
3404 of members (since we don't have any idea what they might be for an
3405 incomplete type). */
3407 if (TYPE_SIZE (type))
3410 byte_size_attribute (type);
3414 /* Output a DIE to represent a declared function (either file-scope
3415 or block-local) which has "internal linkage" (according to ANSI-C). */
3418 output_local_subroutine_die (arg)
3421 register tree decl = arg;
3422 register tree origin = decl_ultimate_origin (decl);
3424 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3425 sibling_attribute ();
3428 abstract_origin_attribute (origin);
3431 register tree type = TREE_TYPE (decl);
3433 name_and_src_coords_attributes (decl);
3434 inline_attribute (decl);
3435 prototyped_attribute (type);
3436 member_attribute (DECL_CONTEXT (decl));
3437 type_attribute (TREE_TYPE (type), 0, 0);
3438 pure_or_virtual_attribute (decl);
3440 if (DECL_ABSTRACT (decl))
3441 equate_decl_number_to_die_number (decl);
3444 /* Avoid getting screwed up in cases where a function was declared
3445 static but where no definition was ever given for it. */
3447 if (TREE_ASM_WRITTEN (decl))
3449 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3451 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
3452 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3453 high_pc_attribute (func_end_label);
3459 output_subroutine_type_die (arg)
3462 register tree type = arg;
3463 register tree return_type = TREE_TYPE (type);
3465 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3466 sibling_attribute ();
3468 equate_type_number_to_die_number (type);
3469 prototyped_attribute (type);
3470 member_attribute (TYPE_CONTEXT (type));
3471 type_attribute (return_type, 0, 0);
3475 output_typedef_die (arg)
3478 register tree decl = arg;
3479 register tree origin = decl_ultimate_origin (decl);
3481 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3482 sibling_attribute ();
3484 abstract_origin_attribute (origin);
3487 name_and_src_coords_attributes (decl);
3488 member_attribute (DECL_CONTEXT (decl));
3489 type_attribute (TREE_TYPE (decl),
3490 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3492 if (DECL_ABSTRACT (decl))
3493 equate_decl_number_to_die_number (decl);
3497 output_union_type_die (arg)
3500 register tree type = arg;
3502 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3503 sibling_attribute ();
3504 equate_type_number_to_die_number (type);
3505 name_attribute (type_tag (type));
3506 member_attribute (TYPE_CONTEXT (type));
3508 /* If this type has been completed, then give it a byte_size attribute
3509 and prepare to give a list of members. Otherwise, don't do either of
3510 these things. In the latter case, we will not be generating a list
3511 of members (since we don't have any idea what they might be for an
3512 incomplete type). */
3514 if (TYPE_SIZE (type))
3517 byte_size_attribute (type);
3521 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3522 at the end of an (ANSI prototyped) formal parameters list. */
3525 output_unspecified_parameters_die (arg)
3528 register tree decl_or_type = arg;
3530 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3531 sibling_attribute ();
3533 /* This kludge is here only for the sake of being compatible with what
3534 the USL CI5 C compiler does. The specification of Dwarf Version 1
3535 doesn't say that TAG_unspecified_parameters DIEs should contain any
3536 attributes other than the AT_sibling attribute, but they are certainly
3537 allowed to contain additional attributes, and the CI5 compiler
3538 generates AT_name, AT_fund_type, and AT_location attributes within
3539 TAG_unspecified_parameters DIEs which appear in the child lists for
3540 DIEs representing function definitions, so we do likewise here. */
3542 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3544 name_attribute ("...");
3545 fund_type_attribute (FT_pointer);
3546 /* location_attribute (?); */
3551 output_padded_null_die (arg)
3554 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3557 /*************************** end of DIEs *********************************/
3559 /* Generate some type of DIE. This routine generates the generic outer
3560 wrapper stuff which goes around all types of DIE's (regardless of their
3561 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3562 DIE-length word, followed by the guts of the DIE itself. After the guts
3563 of the DIE, there must always be a terminator label for the DIE. */
3566 output_die (die_specific_output_function, param)
3567 register void (*die_specific_output_function)();
3568 register void *param;
3570 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3571 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3573 current_dienum = NEXT_DIE_NUM;
3574 NEXT_DIE_NUM = next_unused_dienum;
3576 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3577 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3579 /* Write a label which will act as the name for the start of this DIE. */
3581 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3583 /* Write the DIE-length word. */
3585 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3587 /* Fill in the guts of the DIE. */
3589 next_unused_dienum++;
3590 die_specific_output_function (param);
3592 /* Write a label which will act as the name for the end of this DIE. */
3594 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3598 end_sibling_chain ()
3600 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3602 current_dienum = NEXT_DIE_NUM;
3603 NEXT_DIE_NUM = next_unused_dienum;
3605 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3607 /* Write a label which will act as the name for the start of this DIE. */
3609 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3611 /* Write the DIE-length word. */
3613 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3618 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3619 TAG_unspecified_parameters DIE) to represent the types of the formal
3620 parameters as specified in some function type specification (except
3621 for those which appear as part of a function *definition*).
3623 Note that we must be careful here to output all of the parameter DIEs
3624 *before* we output any DIEs needed to represent the types of the formal
3625 parameters. This keeps svr4 SDB happy because it (incorrectly) thinks
3626 that the first non-parameter DIE it sees ends the formal parameter list.
3630 output_formal_types (function_or_method_type)
3631 register tree function_or_method_type;
3634 register tree formal_type = NULL;
3635 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3637 /* In the case where we are generating a formal types list for a C++
3638 non-static member function type, skip over the first thing on the
3639 TYPE_ARG_TYPES list because it only represents the type of the
3640 hidden `this pointer'. The debugger should be able to figure
3641 out (without being explicitly told) that this non-static member
3642 function type takes a `this pointer' and should be able to figure
3643 what the type of that hidden parameter is from the AT_member
3644 attribute of the parent TAG_subroutine_type DIE. */
3646 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3647 first_parm_type = TREE_CHAIN (first_parm_type);
3649 /* Make our first pass over the list of formal parameter types and output
3650 a TAG_formal_parameter DIE for each one. */
3652 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3654 formal_type = TREE_VALUE (link);
3655 if (formal_type == void_type_node)
3658 /* Output a (nameless) DIE to represent the formal parameter itself. */
3660 output_die (output_formal_parameter_die, formal_type);
3663 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
3664 DIE to the end of the parameter list. */
3666 if (formal_type != void_type_node)
3667 output_die (output_unspecified_parameters_die, function_or_method_type);
3669 /* Make our second (and final) pass over the list of formal parameter types
3670 and output DIEs to represent those types (as necessary). */
3672 for (link = TYPE_ARG_TYPES (function_or_method_type);
3674 link = TREE_CHAIN (link))
3676 formal_type = TREE_VALUE (link);
3677 if (formal_type == void_type_node)
3680 output_type (formal_type, function_or_method_type);
3684 /* Remember a type in the pending_types_list. */
3690 if (pending_types == pending_types_allocated)
3692 pending_types_allocated += PENDING_TYPES_INCREMENT;
3694 = (tree *) xrealloc (pending_types_list,
3695 sizeof (tree) * pending_types_allocated);
3697 pending_types_list[pending_types++] = type;
3699 /* Mark the pending type as having been output already (even though
3700 it hasn't been). This prevents the type from being added to the
3701 pending_types_list more than once. */
3703 TREE_ASM_WRITTEN (type) = 1;
3706 /* Return non-zero if it is legitimate to output DIEs to represent a
3707 given type while we are generating the list of child DIEs for some
3708 DIE (e.g. a function or lexical block DIE) associated with a given scope.
3710 See the comments within the function for a description of when it is
3711 considered legitimate to output DIEs for various kinds of types.
3713 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
3714 or it may point to a BLOCK node (for types local to a block), or to a
3715 FUNCTION_DECL node (for types local to the heading of some function
3716 definition), or to a FUNCTION_TYPE node (for types local to the
3717 prototyped parameter list of a function type specification), or to a
3718 RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types).
3720 The `scope' parameter should likewise be NULL or should point to a
3721 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
3722 node, or a UNION_TYPE node.
3724 This function is used only for deciding when to "pend" and when to
3725 "un-pend" types to/from the pending_types_list.
3727 Note that we sometimes make use of this "type pending" feature in a
3728 rather twisted way to temporarily delay the production of DIEs for the
3729 types of formal parameters. (We do this just to make svr4 SDB happy.)
3730 It order to delay the production of DIEs representing types of formal
3731 parameters, callers of this function supply `fake_containing_scope' as
3732 the `scope' parameter to this function. Given that fake_containing_scope
3733 is a tagged type which is *not* the containing scope for *any* other type,
3734 the desired effect is achieved, i.e. output of DIEs representing types
3735 is temporarily suspended, and any type DIEs which would have otherwise
3736 been output are instead placed onto the pending_types_list. Later on,
3737 we force these (temporarily pended) types to be output simply by calling
3738 `output_pending_types_for_scope' with an actual argument equal to the
3739 true scope of the types we temporarily pended.
3743 type_ok_for_scope (type, scope)
3745 register tree scope;
3747 /* Tagged types (i.e. struct, union, and enum types) must always be
3748 output only in the scopes where they actually belong (or else the
3749 scoping of their own tag names and the scoping of their member
3750 names will be incorrect). Non-tagged-types on the other hand can
3751 generally be output anywhere, except that svr4 SDB really doesn't
3752 want to see them nested within struct or union types, so here we
3753 say it is always OK to immediately output any such a (non-tagged)
3754 type, so long as we are not within such a context. Note that the
3755 only kinds of non-tagged types which we will be dealing with here
3756 (for C and C++ anyway) will be array types and function types. */
3758 return is_tagged_type (type)
3759 ? (TYPE_CONTEXT (type) == scope)
3760 : (scope == NULL_TREE || ! is_tagged_type (scope));
3763 /* Output any pending types (from the pending_types list) which we can output
3764 now (taking into account the scope that we are working on now).
3766 For each type output, remove the given type from the pending_types_list
3767 *before* we try to output it.
3769 Note that we have to process the list in beginning-to-end order,
3770 because the call made here to output_type may cause yet more types
3771 to be added to the end of the list, and we may have to output some
3776 output_pending_types_for_scope (containing_scope)
3777 register tree containing_scope;
3779 register unsigned i;
3781 for (i = 0; i < pending_types; )
3783 register tree type = pending_types_list[i];
3785 if (type_ok_for_scope (type, containing_scope))
3787 register tree *mover;
3788 register tree *limit;
3791 limit = &pending_types_list[pending_types];
3792 for (mover = &pending_types_list[i]; mover < limit; mover++)
3793 *mover = *(mover+1);
3795 /* Un-mark the type as having been output already (because it
3796 hasn't been, really). Then call output_type to generate a
3797 Dwarf representation of it. */
3799 TREE_ASM_WRITTEN (type) = 0;
3800 output_type (type, containing_scope);
3802 /* Don't increment the loop counter in this case because we
3803 have shifted all of the subsequent pending types down one
3804 element in the pending_types_list array. */
3812 output_type (type, containing_scope)
3814 register tree containing_scope;
3816 if (type == 0 || type == error_mark_node)
3819 /* We are going to output a DIE to represent the unqualified version of
3820 of this type (i.e. without any const or volatile qualifiers) so get
3821 the main variant (i.e. the unqualified version) of this type now. */
3823 type = TYPE_MAIN_VARIANT (type);
3825 if (TREE_ASM_WRITTEN (type))
3828 /* Don't generate any DIEs for this type now unless it is OK to do so
3829 (based upon what `type_ok_for_scope' tells us). */
3831 if (! type_ok_for_scope (type, containing_scope))
3837 switch (TREE_CODE (type))
3843 case REFERENCE_TYPE:
3844 /* For these types, all that is required is that we output a DIE
3845 (or a set of DIEs) to represent that "basis" type. */
3846 output_type (TREE_TYPE (type), containing_scope);
3850 /* This code is used for C++ pointer-to-data-member types. */
3851 /* Output a description of the relevant class type. */
3852 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
3853 /* Output a description of the type of the object pointed to. */
3854 output_type (TREE_TYPE (type), containing_scope);
3855 /* Now output a DIE to represent this pointer-to-data-member type
3857 output_die (output_ptr_to_mbr_type_die, type);
3861 output_type (TREE_TYPE (type), containing_scope);
3862 output_die (output_set_type_die, type);
3866 output_type (TREE_TYPE (type), containing_scope);
3867 abort (); /* No way to represent these in Dwarf yet! */
3871 output_type (TREE_TYPE (type), containing_scope);
3872 output_die (output_string_type_die, type);
3876 /* Force out return type (in case it wasn't forced out already). */
3877 output_type (TREE_TYPE (type), containing_scope);
3878 output_die (output_subroutine_type_die, type);
3879 output_formal_types (type);
3880 end_sibling_chain ();
3884 /* Force out return type (in case it wasn't forced out already). */
3885 output_type (TREE_TYPE (type), containing_scope);
3886 output_die (output_subroutine_type_die, type);
3887 output_formal_types (type);
3888 end_sibling_chain ();
3893 register tree element_type;
3895 element_type = TREE_TYPE (type);
3896 while (TREE_CODE (element_type) == ARRAY_TYPE)
3897 element_type = TREE_TYPE (element_type);
3899 output_type (element_type, containing_scope);
3900 output_die (output_array_type_die, type);
3908 /* For a non-file-scope tagged type, we can always go ahead and
3909 output a Dwarf description of this type right now, even if
3910 the type in question is still incomplete, because if this
3911 local type *was* ever completed anywhere within its scope,
3912 that complete definition would already have been attached to
3913 this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the
3914 time we reach this point. That's true because of the way the
3915 front-end does its processing of file-scope declarations (of
3916 functions and class types) within which other types might be
3917 nested. The C and C++ front-ends always gobble up such "local
3918 scope" things en-mass before they try to output *any* debugging
3919 information for any of the stuff contained inside them and thus,
3920 we get the benefit here of what is (in effect) a pre-resolution
3921 of forward references to tagged types in local scopes.
3923 Note however that for file-scope tagged types we cannot assume
3924 that such pre-resolution of forward references has taken place.
3925 A given file-scope tagged type may appear to be incomplete when
3926 we reach this point, but it may yet be given a full definition
3927 (at file-scope) later on during compilation. In order to avoid
3928 generating a premature (and possibly incorrect) set of Dwarf
3929 DIEs for such (as yet incomplete) file-scope tagged types, we
3930 generate nothing at all for as-yet incomplete file-scope tagged
3931 types here unless we are making our special "finalization" pass
3932 for file-scope things at the very end of compilation. At that
3933 time, we will certainly know as much about each file-scope tagged
3934 type as we are ever going to know, so at that point in time, we
3935 can safely generate correct Dwarf descriptions for these file-
3939 if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
3940 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
3942 /* Prevent infinite recursion in cases where the type of some
3943 member of this type is expressed in terms of this type itself. */
3945 TREE_ASM_WRITTEN (type) = 1;
3947 /* Output a DIE to represent the tagged type itself. */
3949 switch (TREE_CODE (type))
3952 output_die (output_enumeration_type_die, type);
3953 return; /* a special case -- nothing left to do so just return */
3956 output_die (output_structure_type_die, type);
3960 output_die (output_union_type_die, type);
3964 abort (); /* Should never happen. */
3967 /* If this is not an incomplete type, output descriptions of
3968 each of its members.
3970 Note that as we output the DIEs necessary to represent the
3971 members of this record or union type, we will also be trying
3972 to output DIEs to represent the *types* of those members.
3973 However the `output_type' function (above) will specifically
3974 avoid generating type DIEs for member types *within* the list
3975 of member DIEs for this (containing) type execpt for those
3976 types (of members) which are explicitly marked as also being
3977 members of this (containing) type themselves. The g++ front-
3978 end can force any given type to be treated as a member of some
3979 other (containing) type by setting the TYPE_CONTEXT of the
3980 given (member) type to point to the TREE node representing the
3981 appropriate (containing) type.
3984 if (TYPE_SIZE (type))
3987 register tree normal_member;
3989 /* First output info about the data members and type members. */
3991 for (normal_member = TYPE_FIELDS (type);
3993 normal_member = TREE_CHAIN (normal_member))
3994 output_decl (normal_member, type);
3998 register tree vec_base;
4000 /* Now output info about the function members (if any). */
4002 vec_base = TYPE_METHODS (type);
4005 register tree first_func_member = TREE_VEC_ELT (vec_base, 0);
4006 register tree func_member;
4008 /* This isn't documented, but the first element of the
4009 vector of member functions can be NULL in cases where
4010 the class type in question didn't have either a
4011 constructor or a destructor declared for it. We have
4012 to make allowances for that here. */
4014 if (first_func_member == NULL)
4015 first_func_member = TREE_VEC_ELT (vec_base, 1);
4017 for (func_member = first_func_member;
4019 func_member = TREE_CHAIN (func_member))
4020 output_decl (func_member, type);
4024 /* RECORD_TYPEs and UNION_TYPEs are themselves scopes (at least
4025 in C++) so we must now output any nested pending types which
4026 are local just to this RECORD_TYPE or UNION_TYPE. */
4028 output_pending_types_for_scope (type);
4030 end_sibling_chain (); /* Terminate member chain. */
4041 break; /* No DIEs needed for fundamental types. */
4043 case LANG_TYPE: /* No Dwarf representation currently defined. */
4050 TREE_ASM_WRITTEN (type) = 1;
4054 output_tagged_type_instantiation (type)
4057 if (type == 0 || type == error_mark_node)
4060 /* We are going to output a DIE to represent the unqualified version of
4061 of this type (i.e. without any const or volatile qualifiers) so make
4062 sure that we have the main variant (i.e. the unqualified version) of
4065 assert (type == TYPE_MAIN_VARIANT (type));
4067 assert (TREE_ASM_WRITTEN (type));
4069 switch (TREE_CODE (type))
4075 output_die (output_inlined_enumeration_type_die, type);
4079 output_die (output_inlined_structure_type_die, type);
4083 output_die (output_inlined_union_type_die, type);
4087 abort (); /* Should never happen. */
4091 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4092 the things which are local to the given block. */
4098 register int must_output_die = 0;
4099 register tree origin;
4100 register enum tree_code origin_code;
4102 /* Ignore blocks never really used to make RTL. */
4104 if (! stmt || ! TREE_USED (stmt))
4107 /* Determine the "ultimate origin" of this block. This block may be an
4108 inlined instance of an inlined instance of inline function, so we
4109 have to trace all of the way back through the origin chain to find
4110 out what sort of node actually served as the original seed for the
4111 creation of the current block. */
4113 origin = block_ultimate_origin (stmt);
4114 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4116 /* Determine if we need to output any Dwarf DIEs at all to represent this
4119 if (origin_code == FUNCTION_DECL)
4120 /* The outer scopes for inlinings *must* always be represented. We
4121 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4122 must_output_die = 1;
4125 /* In the case where the current block represents an inlining of the
4126 "body block" of an inline function, we must *NOT* output any DIE
4127 for this block because we have already output a DIE to represent
4128 the whole inlined function scope and the "body block" of any
4129 function doesn't really represent a different scope according to
4130 ANSI C rules. So we check here to make sure that this block does
4131 not represent a "body block inlining" before trying to set the
4132 `must_output_die' flag. */
4134 if (origin == NULL || ! is_body_block (origin))
4136 /* Determine if this block directly contains any "significant"
4137 local declarations which we will need to output DIEs for. */
4139 if (debug_info_level > DINFO_LEVEL_TERSE)
4140 /* We are not in terse mode so *any* local declaration counts
4141 as being a "significant" one. */
4142 must_output_die = (BLOCK_VARS (stmt) != NULL);
4147 /* We are in terse mode, so only local (nested) function
4148 definitions count as "significant" local declarations. */
4150 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4151 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4153 must_output_die = 1;
4160 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4161 DIE for any block which contains no significant local declarations
4162 at all. Rather, in such cases we just call `output_decls_for_scope'
4163 so that any needed Dwarf info for any sub-blocks will get properly
4164 generated. Note that in terse mode, our definition of what constitutes
4165 a "significant" local declaration gets restricted to include only
4166 inlined function instances and local (nested) function definitions. */
4168 if (must_output_die)
4170 output_die ((origin_code == FUNCTION_DECL)
4171 ? output_inlined_subroutine_die
4172 : output_lexical_block_die,
4174 output_decls_for_scope (stmt);
4175 end_sibling_chain ();
4178 output_decls_for_scope (stmt);
4181 /* Output all of the decls declared within a given scope (also called
4182 a `binding contour') and (recursively) all of it's sub-blocks. */
4185 output_decls_for_scope (stmt)
4188 /* Ignore blocks never really used to make RTL. */
4190 if (! stmt || ! TREE_USED (stmt))
4193 if (! BLOCK_ABSTRACT (stmt))
4194 next_block_number++;
4196 /* Output the DIEs to represent all of the data objects, functions,
4197 typedefs, and tagged types declared directly within this block
4198 but not within any nested sub-blocks. */
4203 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4204 output_decl (decl, stmt);
4207 output_pending_types_for_scope (stmt);
4209 /* Output the DIEs to represent all sub-blocks (and the items declared
4210 therein) of this block. */
4213 register tree subblocks;
4215 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4217 subblocks = BLOCK_CHAIN (subblocks))
4218 output_block (subblocks);
4222 /* Output Dwarf .debug information for a decl described by DECL. */
4225 output_decl (decl, containing_scope)
4227 register tree containing_scope;
4229 /* Make a note of the decl node we are going to be working on. We may
4230 need to give the user the source coordinates of where it appeared in
4231 case we notice (later on) that something about it looks screwy. */
4233 dwarf_last_decl = decl;
4235 if (TREE_CODE (decl) == ERROR_MARK)
4238 /* If this ..._DECL node is marked to be ignored, then ignore it.
4239 But don't ignore a function definition, since that would screw
4240 up our count of blocks, and that it turn will completely screw up the
4241 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4242 attributes (for subsequent blocks). */
4244 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4247 switch (TREE_CODE (decl))
4250 /* The individual enumerators of an enum type get output when we
4251 output the Dwarf representation of the relevant enum type itself. */
4255 /* If we are in terse mode, don't output any DIEs to represent
4256 mere external function declarations. Also, if we are conforming
4257 to the DWARF version 1 specification, don't output DIEs for
4258 mere external function declarations. */
4260 if (DECL_EXTERNAL (decl))
4261 #if (DWARF_VERSION > 1)
4262 if (debug_info_level <= DINFO_LEVEL_TERSE)
4266 /* Before we describe the FUNCTION_DECL itself, make sure that we
4267 have described its return type. */
4269 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4271 /* If the following DIE will represent a function definition for a
4272 function with "extern" linkage, output a special "pubnames" DIE
4273 label just ahead of the actual DIE. A reference to this label
4274 was already generated in the .debug_pubnames section sub-entry
4275 for this function definition. */
4277 if (TREE_PUBLIC (decl))
4279 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4281 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4282 ASM_OUTPUT_LABEL (asm_out_file, label);
4285 /* Now output a DIE to represent the function itself. */
4287 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4288 ? output_global_subroutine_die
4289 : output_local_subroutine_die,
4292 /* Now output descriptions of the arguments for this function.
4293 This gets (unnecessarily?) complex because of the fact that
4294 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4295 cases where there was a trailing `...' at the end of the formal
4296 parameter list. In order to find out if there was a trailing
4297 ellipsis or not, we must instead look at the type associated
4298 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4299 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4300 ends with a void_type_node then there should *not* be an ellipsis
4303 /* In the case where we are describing an external function, all
4304 we need to do here (and all we *can* do here) is to describe
4305 the *types* of its formal parameters. */
4307 if (DECL_EXTERNAL (decl))
4308 output_formal_types (TREE_TYPE (decl));
4311 register tree arg_decls = DECL_ARGUMENTS (decl);
4314 register tree last_arg;
4316 last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK)
4317 ? tree_last (arg_decls)
4320 /* Generate DIEs to represent all known formal parameters, but
4321 don't do it if this looks like a varargs function. A given
4322 function is considered to be a varargs function if (and only
4323 if) its last named argument is named `__builtin_va_alist'. */
4326 || ! DECL_NAME (last_arg)
4327 || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)),
4328 "__builtin_va_alist"))
4332 /* WARNING! Kludge zone ahead! Here we have a special
4333 hack for svr4 SDB compatibility. Instead of passing the
4334 current FUNCTION_DECL node as the second parameter (i.e.
4335 the `containing_scope' parameter) to `output_decl' (as
4336 we ought to) we instead pass a pointer to our own private
4337 fake_containing_scope node. That node is a RECORD_TYPE
4338 node which NO OTHER TYPE may ever actually be a member of.
4340 This pointer will ultimately get passed into `output_type'
4341 as its `containing_scope' parameter. `Output_type' will
4342 then perform its part in the hack... i.e. it will pend
4343 the type of the formal parameter onto the pending_types
4344 list. Later on, when we are done generating the whole
4345 sequence of formal parameter DIEs for this function
4346 definition, we will un-pend all previously pended types
4347 of formal parameters for this function definition.
4349 This whole kludge prevents any type DIEs from being
4350 mixed in with the formal parameter DIEs. That's good
4351 because svr4 SDB believes that the list of formal
4352 parameter DIEs for a function ends wherever the first
4353 non-formal-parameter DIE appears. Thus, we have to
4354 keep the formal parameter DIEs segregated. They must
4355 all appear (consecutively) at the start of the list of
4356 children for the DIE representing the function definition.
4357 Then (and only then) may we output any additional DIEs
4358 needed to represent the types of these formal parameters.
4361 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4362 if (TREE_CODE (parm) == PARM_DECL)
4363 output_decl (parm, fake_containing_scope);
4365 /* Now that we have finished generating all of the DIEs to
4366 represent the formal parameters themselves, force out
4367 any DIEs needed to represent their types. We do this
4368 simply by un-pending all previously pended types which
4369 can legitimately go into the chain of children DIEs for
4370 the current FUNCTION_DECL. */
4372 output_pending_types_for_scope (decl);
4376 /* Now try to decide if we should put an ellipsis at the end. */
4379 register int has_ellipsis = TRUE; /* default assumption */
4380 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4384 /* This function declaration/definition was prototyped. */
4386 /* If the list of formal argument types ends with a
4387 void_type_node, then the formals list did *not* end
4388 with an ellipsis. */
4390 if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
4391 has_ellipsis = FALSE;
4395 /* This function declaration/definition was not prototyped. */
4397 /* Note that all non-prototyped function *declarations* are
4398 assumed to represent varargs functions (until proven
4401 if (DECL_INITIAL (decl)) /* if this is a func definition */
4404 has_ellipsis = FALSE; /* no args == (void) */
4407 /* For a non-prototyped function definition which
4408 declares one or more formal parameters, if the name
4409 of the first formal parameter is *not*
4410 __builtin_va_alist then we must assume that this
4411 is *not* a varargs function. */
4413 if (DECL_NAME (arg_decls)
4414 && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
4415 "__builtin_va_alist"))
4416 has_ellipsis = FALSE;
4422 output_die (output_unspecified_parameters_die, decl);
4426 /* Output Dwarf info for all of the stuff within the body of the
4427 function (if it has one - it may be just a declaration). */
4430 register tree outer_scope = DECL_INITIAL (decl);
4432 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4434 /* Note that here, `outer_scope' is a pointer to the outermost
4435 BLOCK node created to represent a function.
4436 This outermost BLOCK actually represents the outermost
4437 binding contour for the function, i.e. the contour in which
4438 the function's formal parameters and labels get declared.
4440 Curiously, it appears that the front end doesn't actually
4441 put the PARM_DECL nodes for the current function onto the
4442 BLOCK_VARS list for this outer scope. (They are strung
4443 off of the DECL_ARGUMENTS list for the function instead.)
4444 The BLOCK_VARS list for the `outer_scope' does provide us
4445 with a list of the LABEL_DECL nodes for the function however,
4446 and we output DWARF info for those here.
4448 Just within the `outer_scope' there will be another BLOCK
4449 node representing the function's outermost pair of curly
4450 braces. We musn't generate a lexical_block DIE for this
4451 outermost pair of curly braces because that is not really an
4452 independent scope according to ANSI C rules. Rather, it is
4453 the same scope in which the parameters were declared. */
4456 register tree label;
4458 for (label = BLOCK_VARS (outer_scope);
4460 label = TREE_CHAIN (label))
4461 output_decl (label, outer_scope);
4464 /* Note here that `BLOCK_SUBBLOCKS (outer_scope)' points to a
4465 list of BLOCK nodes which is always only one element long.
4466 That one element represents the outermost pair of curley
4467 braces for the function body. */
4469 output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
4471 /* Finally, force out any pending types which are local to the
4472 outermost block of this function definition. These will
4473 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4476 output_pending_types_for_scope (decl);
4480 /* Generate a terminator for the list of stuff `owned' by this
4483 end_sibling_chain ();
4488 /* If we are in terse mode, don't generate any DIEs to represent
4489 any actual typedefs. Note that even when we are in terse mode,
4490 we must still output DIEs to represent those tagged types which
4491 are used (directly or indirectly) in the specification of either
4492 a return type or a formal parameter type of some function. */
4494 if (debug_info_level <= DINFO_LEVEL_TERSE)
4495 if (DECL_NAME (decl) != NULL
4496 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4499 /* In the special case of a null-named TYPE_DECL node (representing
4500 the declaration of some type tag), if the given TYPE_DECL is
4501 marked as having been instantiated from some other (original)
4502 TYPE_DECL node (e.g. one which was generated within the original
4503 definition of an inline function) we have to generate a special
4504 (abbreviated) TAG_structure_type, TAG_union_type, or
4505 TAG_enumeration-type DIE here. */
4507 if (! DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
4509 output_tagged_type_instantiation (TREE_TYPE (decl));
4513 output_type (TREE_TYPE (decl), containing_scope);
4515 /* Note that unlike the gcc front end (which generates a NULL named
4516 TYPE_DECL node for each complete tagged type, each array type,
4517 and each function type node created) the g++ front end generates
4518 a *named* TYPE_DECL node for each tagged type node created.
4519 Unfortunately, these g++ TYPE_DECL nodes cause us to output many
4520 superfluous and unnecessary TAG_typedef DIEs here. When g++ is
4521 fixed to stop generating these superfluous named TYPE_DECL nodes,
4522 the superfluous TAG_typedef DIEs will likewise cease. */
4524 if (DECL_NAME (decl))
4525 /* Output a DIE to represent the typedef itself. */
4526 output_die (output_typedef_die, decl);
4530 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4531 output_die (output_label_die, decl);
4535 /* If we are conforming to the DWARF version 1 specification, don't
4536 generated any DIEs to represent mere external object declarations. */
4538 #if (DWARF_VERSION <= 1)
4539 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4543 /* If we are in terse mode, don't generate any DIEs to represent
4544 any variable declarations or definitions. */
4546 if (debug_info_level <= DINFO_LEVEL_TERSE)
4549 /* Output any DIEs that are needed to specify the type of this data
4552 output_type (TREE_TYPE (decl), containing_scope);
4554 /* If the following DIE will represent a data object definition for a
4555 data object with "extern" linkage, output a special "pubnames" DIE
4556 label just ahead of the actual DIE. A reference to this label
4557 was already generated in the .debug_pubnames section sub-entry
4558 for this data object definition. */
4560 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4562 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4564 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4565 ASM_OUTPUT_LABEL (asm_out_file, label);
4568 /* Now output the DIE to represent the data object itself. This gets
4569 complicated because of the possibility that the VAR_DECL really
4570 represents an inlined instance of a formal parameter for an inline
4574 register void (*func) ();
4575 register tree origin = decl_ultimate_origin (decl);
4577 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
4578 func = output_formal_parameter_die;
4581 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
4582 func = output_global_variable_die;
4584 func = output_local_variable_die;
4586 output_die (func, decl);
4591 /* Ignore the nameless fields that are used to skip bits. */
4592 if (DECL_NAME (decl) != 0)
4594 output_type (member_declared_type (decl), containing_scope);
4595 output_die (output_member_die, decl);
4600 /* Force out the type of this formal, if it was not forced out yet.
4601 Note that here we can run afowl of a bug in "classic" svr4 SDB.
4602 It should be able to grok the presence of type DIEs within a list
4603 of TAG_formal_parameter DIEs, but it doesn't. */
4605 output_type (TREE_TYPE (decl), containing_scope);
4606 output_die (output_formal_parameter_die, decl);
4615 dwarfout_file_scope_decl (decl, set_finalizing)
4617 register int set_finalizing;
4619 if (TREE_CODE (decl) == ERROR_MARK)
4622 /* If this ..._DECL node is marked to be ignored, then ignore it. We
4623 gotta hope that the node in question doesn't represent a function
4624 definition. If it does, then totally ignoring it is bound to screw
4625 up our count of blocks, and that it turn will completely screw up the
4626 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4627 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
4628 don't carry their own sequence numbers with them!) */
4630 if (DECL_IGNORED_P (decl))
4632 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4637 switch (TREE_CODE (decl))
4641 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
4642 a builtin function. Explicit programmer-supplied declarations of
4643 these same functions should NOT be ignored however. */
4645 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
4648 /* Ignore this FUNCTION_DECL if it refers to a file-scope extern
4649 function declaration and if the declaration was never even
4650 referenced from within this entire compilation unit. We
4651 suppress these DIEs in order to save space in the .debug section
4652 (by eliminating entries which are probably useless). Note that
4653 we must not suppress block-local extern declarations (whether
4654 used or not) because that would screw-up the debugger's name
4655 lookup mechanism and cause it to miss things which really ought
4656 to be in scope at a given point. */
4658 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
4661 if (TREE_PUBLIC (decl)
4662 && ! DECL_EXTERNAL (decl)
4663 && ! DECL_ABSTRACT (decl))
4665 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4667 /* Output a .debug_pubnames entry for a public function
4668 defined in this compilation unit. */
4670 fputc ('\n', asm_out_file);
4671 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4672 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4673 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4674 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4675 IDENTIFIER_POINTER (DECL_NAME (decl)));
4676 ASM_OUTPUT_POP_SECTION (asm_out_file);
4683 /* Ignore this VAR_DECL if it refers to a file-scope extern data
4684 object declaration and if the declaration was never even
4685 referenced from within this entire compilation unit. We
4686 suppress these DIEs in order to save space in the .debug section
4687 (by eliminating entries which are probably useless). Note that
4688 we must not suppress block-local extern declarations (whether
4689 used or not) because that would screw-up the debugger's name
4690 lookup mechanism and cause it to miss things which really ought
4691 to be in scope at a given point. */
4693 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
4696 if (TREE_PUBLIC (decl)
4697 && ! DECL_EXTERNAL (decl)
4698 && GET_CODE (DECL_RTL (decl)) == MEM
4699 && ! DECL_ABSTRACT (decl))
4701 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4703 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4705 /* Output a .debug_pubnames entry for a public variable
4706 defined in this compilation unit. */
4708 fputc ('\n', asm_out_file);
4709 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4710 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4711 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4712 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4713 IDENTIFIER_POINTER (DECL_NAME (decl)));
4714 ASM_OUTPUT_POP_SECTION (asm_out_file);
4717 if (DECL_INITIAL (decl) == NULL)
4719 /* Output a .debug_aranges entry for a public variable
4720 which is tentatively defined in this compilation unit. */
4722 fputc ('\n', asm_out_file);
4723 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4724 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
4725 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4726 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4727 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
4728 ASM_OUTPUT_POP_SECTION (asm_out_file);
4732 /* If we are in terse mode, don't generate any DIEs to represent
4733 any variable declarations or definitions. */
4735 if (debug_info_level <= DINFO_LEVEL_TERSE)
4741 /* Don't generate any DIEs to represent the standard built-in types. */
4743 if (DECL_SOURCE_LINE (decl) == 0)
4746 /* If we are in terse mode, don't generate any DIEs to represent
4747 any actual typedefs. Note that even when we are in terse mode,
4748 we must still output DIEs to represent those tagged types which
4749 are used (directly or indirectly) in the specification of either
4750 a return type or a formal parameter type of some function. */
4752 if (debug_info_level <= DINFO_LEVEL_TERSE)
4753 if (DECL_NAME (decl) != NULL
4754 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4763 fputc ('\n', asm_out_file);
4764 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4765 finalizing = set_finalizing;
4766 output_decl (decl, NULL_TREE);
4768 /* NOTE: The call above to `output_decl' may have caused one or more
4769 file-scope named types (i.e. tagged types) to be placed onto the
4770 pending_types_list. We have to get those types off of that list
4771 at some point, and this is the perfect time to do it. If we didn't
4772 take them off now, they might still be on the list when cc1 finally
4773 exits. That might be OK if it weren't for the fact that when we put
4774 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
4775 for these types, and that causes them never to be output unless
4776 `output_pending_types_for_scope' takes them off of the list and un-sets
4777 their TREE_ASM_WRITTEN flags. */
4779 output_pending_types_for_scope (NULL_TREE);
4781 /* The above call should have totally emptied the pending_types_list. */
4783 assert (pending_types == 0);
4785 ASM_OUTPUT_POP_SECTION (asm_out_file);
4787 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4788 current_funcdef_number++;
4791 /* Output a marker (i.e. a label) for the beginning of the generated code
4792 for a lexical block. */
4795 dwarfout_begin_block (blocknum)
4796 register unsigned blocknum;
4798 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4801 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
4802 ASM_OUTPUT_LABEL (asm_out_file, label);
4805 /* Output a marker (i.e. a label) for the end of the generated code
4806 for a lexical block. */
4809 dwarfout_end_block (blocknum)
4810 register unsigned blocknum;
4812 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4815 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
4816 ASM_OUTPUT_LABEL (asm_out_file, label);
4819 /* Output a marker (i.e. a label) at a point in the assembly code which
4820 corresponds to a given source level label. */
4823 dwarfout_label (insn)
4826 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4828 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4831 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
4832 (unsigned) INSN_UID (insn));
4833 ASM_OUTPUT_LABEL (asm_out_file, label);
4837 /* Output a marker (i.e. a label) for the absolute end of the generated code
4838 for a function definition. This gets called *after* the epilogue code
4839 has been generated. */
4842 dwarfout_end_epilogue ()
4844 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4846 /* Output a label to mark the endpoint of the code generated for this
4849 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4850 ASM_OUTPUT_LABEL (asm_out_file, label);
4854 shuffle_filename_entry (new_zeroth)
4855 register filename_entry *new_zeroth;
4857 filename_entry temp_entry;
4858 register filename_entry *limit_p;
4859 register filename_entry *move_p;
4861 if (new_zeroth == &filename_table[0])
4864 temp_entry = *new_zeroth;
4866 /* Shift entries up in the table to make room at [0]. */
4868 limit_p = &filename_table[0];
4869 for (move_p = new_zeroth; move_p > limit_p; move_p--)
4870 *move_p = *(move_p-1);
4872 /* Install the found entry at [0]. */
4874 filename_table[0] = temp_entry;
4877 /* Create a new (string) entry for the .debug_sfnames section. */
4880 generate_new_sfname_entry ()
4882 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4884 fputc ('\n', asm_out_file);
4885 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
4886 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
4887 ASM_OUTPUT_LABEL (asm_out_file, label);
4888 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4889 filename_table[0].name
4890 ? filename_table[0].name
4892 ASM_OUTPUT_POP_SECTION (asm_out_file);
4895 /* Lookup a filename (in the list of filenames that we know about here in
4896 dwarfout.c) and return its "index". The index of each (known) filename
4897 is just a unique number which is associated with only that one filename.
4898 We need such numbers for the sake of generating labels (in the
4899 .debug_sfnames section) and references to those unique labels (in the
4900 .debug_srcinfo and .debug_macinfo sections).
4902 If the filename given as an argument is not found in our current list,
4903 add it to the list and assign it the next available unique index number.
4905 Whatever we do (i.e. whether we find a pre-existing filename or add a new
4906 one), we shuffle the filename found (or added) up to the zeroth entry of
4907 our list of filenames (which is always searched linearly). We do this so
4908 as to optimize the most common case for these filename lookups within
4909 dwarfout.c. The most common case by far is the case where we call
4910 lookup_filename to lookup the very same filename that we did a lookup
4911 on the last time we called lookup_filename. We make sure that this
4912 common case is fast because such cases will constitute 99.9% of the
4913 lookups we ever do (in practice).
4915 If we add a new filename entry to our table, we go ahead and generate
4916 the corresponding entry in the .debug_sfnames section right away.
4917 Doing so allows us to avoid tickling an assembler bug (present in some
4918 m68k assemblers) which yields assembly-time errors in cases where the
4919 difference of two label addresses is taken and where the two labels
4920 are in a section *other* than the one where the difference is being
4921 calculated, and where at least one of the two symbol references is a
4922 forward reference. (This bug could be tickled by our .debug_srcinfo
4923 entries if we don't output their corresponding .debug_sfnames entries
4928 lookup_filename (file_name)
4931 register filename_entry *search_p;
4932 register filename_entry *limit_p = &filename_table[ft_entries];
4934 for (search_p = filename_table; search_p < limit_p; search_p++)
4935 if (!strcmp (file_name, search_p->name))
4937 /* When we get here, we have found the filename that we were
4938 looking for in the filename_table. Now we want to make sure
4939 that it gets moved to the zero'th entry in the table (if it
4940 is not already there) so that subsequent attempts to find the
4941 same filename will find it as quickly as possible. */
4943 shuffle_filename_entry (search_p);
4944 return filename_table[0].number;
4947 /* We come here whenever we have a new filename which is not registered
4948 in the current table. Here we add it to the table. */
4950 /* Prepare to add a new table entry by making sure there is enough space
4951 in the table to do so. If not, expand the current table. */
4953 if (ft_entries == ft_entries_allocated)
4955 ft_entries_allocated += FT_ENTRIES_INCREMENT;
4957 = (filename_entry *)
4958 xrealloc (filename_table,
4959 ft_entries_allocated * sizeof (filename_entry));
4962 /* Initially, add the new entry at the end of the filename table. */
4964 filename_table[ft_entries].number = ft_entries;
4965 filename_table[ft_entries].name = xstrdup (file_name);
4967 /* Shuffle the new entry into filename_table[0]. */
4969 shuffle_filename_entry (&filename_table[ft_entries]);
4971 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4972 generate_new_sfname_entry ();
4975 return filename_table[0].number;
4979 generate_srcinfo_entry (line_entry_num, files_entry_num)
4980 unsigned line_entry_num;
4981 unsigned files_entry_num;
4983 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4985 fputc ('\n', asm_out_file);
4986 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4987 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
4988 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
4989 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
4990 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
4991 ASM_OUTPUT_POP_SECTION (asm_out_file);
4995 dwarfout_line (filename, line)
4996 register char *filename;
4997 register unsigned line;
4999 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5001 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5002 static unsigned last_line_entry_num = 0;
5003 static unsigned prev_file_entry_num = (unsigned) -1;
5004 register unsigned this_file_entry_num = lookup_filename (filename);
5007 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
5008 ASM_OUTPUT_LABEL (asm_out_file, label);
5010 fputc ('\n', asm_out_file);
5011 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5013 if (this_file_entry_num != prev_file_entry_num)
5015 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
5017 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
5018 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5022 register char *tail = rindex (filename, '/');
5028 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5029 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5031 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5032 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5033 ASM_OUTPUT_POP_SECTION (asm_out_file);
5035 if (this_file_entry_num != prev_file_entry_num)
5036 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5037 prev_file_entry_num = this_file_entry_num;
5041 /* Generate an entry in the .debug_macinfo section. */
5044 generate_macinfo_entry (type_and_offset, string)
5045 register char *type_and_offset;
5046 register char *string;
5048 fputc ('\n', asm_out_file);
5049 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5050 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5051 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
5052 ASM_OUTPUT_POP_SECTION (asm_out_file);
5056 dwarfout_start_new_source_file (filename)
5057 register char *filename;
5059 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5060 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5062 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5063 sprintf (type_and_offset, "0x%08x+%s-%s",
5064 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
5065 generate_macinfo_entry (type_and_offset, "");
5069 dwarfout_resume_previous_source_file (lineno)
5070 register unsigned lineno;
5072 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5074 sprintf (type_and_offset, "0x%08x+%u",
5075 ((unsigned) MACINFO_resume << 24), lineno);
5076 generate_macinfo_entry (type_and_offset, "");
5079 /* Called from check_newline in c-parse.y. The `buffer' parameter
5080 contains the tail part of the directive line, i.e. the part which
5081 is past the initial whitespace, #, whitespace, directive-name,
5085 dwarfout_define (lineno, buffer)
5086 register unsigned lineno;
5087 register char *buffer;
5089 static int initialized = 0;
5090 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5094 dwarfout_start_new_source_file (primary_filename);
5097 sprintf (type_and_offset, "0x%08x+%u",
5098 ((unsigned) MACINFO_define << 24), lineno);
5099 generate_macinfo_entry (type_and_offset, buffer);
5102 /* Called from check_newline in c-parse.y. The `buffer' parameter
5103 contains the tail part of the directive line, i.e. the part which
5104 is past the initial whitespace, #, whitespace, directive-name,
5108 dwarfout_undef (lineno, buffer)
5109 register unsigned lineno;
5110 register char *buffer;
5112 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5114 sprintf (type_and_offset, "0x%08x+%u",
5115 ((unsigned) MACINFO_undef << 24), lineno);
5116 generate_macinfo_entry (type_and_offset, buffer);
5119 /* Set up for Dwarf output at the start of compilation. */
5122 dwarfout_init (asm_out_file, main_input_filename)
5123 register FILE *asm_out_file;
5124 register char *main_input_filename;
5126 /* Remember the name of the primary input file. */
5128 primary_filename = main_input_filename;
5130 /* Allocate the initial hunk of the pending_sibling_stack. */
5132 pending_sibling_stack
5134 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5135 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5136 pending_siblings = 1;
5138 /* Allocate the initial hunk of the filename_table. */
5141 = (filename_entry *)
5142 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5143 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5146 /* Allocate the initial hunk of the pending_types_list. */
5149 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5150 pending_types_allocated = PENDING_TYPES_INCREMENT;
5153 /* Create an artificial RECORD_TYPE node which we can use in our hack
5154 to get the DIEs representing types of formal parameters to come out
5155 only *after* the DIEs for the formal parameters themselves. */
5157 fake_containing_scope = make_node (RECORD_TYPE);
5159 /* Output a starting label for the .text section. */
5161 fputc ('\n', asm_out_file);
5162 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5163 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5164 ASM_OUTPUT_POP_SECTION (asm_out_file);
5166 /* Output a starting label for the .data section. */
5168 fputc ('\n', asm_out_file);
5169 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5170 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5171 ASM_OUTPUT_POP_SECTION (asm_out_file);
5173 /* Output a starting label for the .data1 section. */
5175 fputc ('\n', asm_out_file);
5176 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5177 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5178 ASM_OUTPUT_POP_SECTION (asm_out_file);
5180 /* Output a starting label for the .rodata section. */
5182 fputc ('\n', asm_out_file);
5183 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5184 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5185 ASM_OUTPUT_POP_SECTION (asm_out_file);
5187 /* Output a starting label for the .rodata1 section. */
5189 fputc ('\n', asm_out_file);
5190 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5191 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5192 ASM_OUTPUT_POP_SECTION (asm_out_file);
5194 /* Output a starting label for the .bss section. */
5196 fputc ('\n', asm_out_file);
5197 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5198 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5199 ASM_OUTPUT_POP_SECTION (asm_out_file);
5201 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5203 /* Output a starting label and an initial (compilation directory)
5204 entry for the .debug_sfnames section. The starting label will be
5205 referenced by the initial entry in the .debug_srcinfo section. */
5207 fputc ('\n', asm_out_file);
5208 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5209 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5211 register char *pwd = getpwd ();
5212 register unsigned len = strlen (pwd);
5213 register char *dirname = (char *) xmalloc (len + 2);
5215 strcpy (dirname, pwd);
5216 strcpy (dirname + len, "/");
5217 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5220 ASM_OUTPUT_POP_SECTION (asm_out_file);
5222 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5224 /* Output a starting label for the .debug_macinfo section. This
5225 label will be referenced by the AT_mac_info attribute in the
5226 TAG_compile_unit DIE. */
5228 fputc ('\n', asm_out_file);
5229 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5230 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5231 ASM_OUTPUT_POP_SECTION (asm_out_file);
5234 /* Generate the initial entry for the .line section. */
5236 fputc ('\n', asm_out_file);
5237 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5238 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5239 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5240 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5241 ASM_OUTPUT_POP_SECTION (asm_out_file);
5243 /* Generate the initial entry for the .debug_srcinfo section. */
5245 fputc ('\n', asm_out_file);
5246 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5247 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5248 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5249 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5250 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5251 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5252 #ifdef DWARF_TIMESTAMPS
5253 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5255 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5257 ASM_OUTPUT_POP_SECTION (asm_out_file);
5259 /* Generate the initial entry for the .debug_pubnames section. */
5261 fputc ('\n', asm_out_file);
5262 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5263 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5264 ASM_OUTPUT_POP_SECTION (asm_out_file);
5266 /* Generate the initial entry for the .debug_aranges section. */
5268 fputc ('\n', asm_out_file);
5269 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5270 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5271 ASM_OUTPUT_POP_SECTION (asm_out_file);
5274 /* Setup first DIE number == 1. */
5275 NEXT_DIE_NUM = next_unused_dienum++;
5277 /* Generate the initial DIE for the .debug section. Note that the
5278 (string) value given in the AT_name attribute of the TAG_compile_unit
5279 DIE will (typically) be a relative pathname and that this pathname
5280 should be taken as being relative to the directory from which the
5281 compiler was invoked when the given (base) source file was compiled. */
5283 fputc ('\n', asm_out_file);
5284 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5285 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5286 output_die (output_compile_unit_die, main_input_filename);
5287 ASM_OUTPUT_POP_SECTION (asm_out_file);
5289 fputc ('\n', asm_out_file);
5292 /* Output stuff that dwarf requires at the end of every file. */
5297 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5299 fputc ('\n', asm_out_file);
5300 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5302 /* Mark the end of the chain of siblings which represent all file-scope
5303 declarations in this compilation unit. */
5305 /* The (null) DIE which represents the terminator for the (sibling linked)
5306 list of file-scope items is *special*. Normally, we would just call
5307 end_sibling_chain at this point in order to output a word with the
5308 value `4' and that word would act as the terminator for the list of
5309 DIEs describing file-scope items. Unfortunately, if we were to simply
5310 do that, the label that would follow this DIE in the .debug section
5311 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5312 machines) to a 4 byte boundary.
5314 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5315 the trick used is to insert extra (otherwise useless) padding bytes
5316 into the (null) DIE that we know must precede the ..D2 label in the
5317 .debug section. The amount of padding required can be anywhere between
5318 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5319 with the padding) would normally contain the value 4, but now it will
5320 also have to include the padding bytes, so it will instead have some
5321 value in the range 4..7.
5323 Fortunately, the rules of Dwarf say that any DIE whose length word
5324 contains *any* value less than 8 should be treated as a null DIE, so
5325 this trick works out nicely. Clever, eh? Don't give me any credit
5326 (or blame). I didn't think of this scheme. I just conformed to it.
5329 output_die (output_padded_null_die, (void *)0);
5332 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5333 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5334 ASM_OUTPUT_POP_SECTION (asm_out_file);
5336 /* Output a terminator label for the .text section. */
5338 fputc ('\n', asm_out_file);
5339 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5340 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5341 ASM_OUTPUT_POP_SECTION (asm_out_file);
5343 /* Output a terminator label for the .data section. */
5345 fputc ('\n', asm_out_file);
5346 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5347 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5348 ASM_OUTPUT_POP_SECTION (asm_out_file);
5350 /* Output a terminator label for the .data1 section. */
5352 fputc ('\n', asm_out_file);
5353 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5354 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5355 ASM_OUTPUT_POP_SECTION (asm_out_file);
5357 /* Output a terminator label for the .rodata section. */
5359 fputc ('\n', asm_out_file);
5360 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5361 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5362 ASM_OUTPUT_POP_SECTION (asm_out_file);
5364 /* Output a terminator label for the .rodata1 section. */
5366 fputc ('\n', asm_out_file);
5367 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5368 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5369 ASM_OUTPUT_POP_SECTION (asm_out_file);
5371 /* Output a terminator label for the .bss section. */
5373 fputc ('\n', asm_out_file);
5374 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5375 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5376 ASM_OUTPUT_POP_SECTION (asm_out_file);
5378 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5380 /* Output a terminating entry for the .line section. */
5382 fputc ('\n', asm_out_file);
5383 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5384 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5385 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5386 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5387 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5388 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5389 ASM_OUTPUT_POP_SECTION (asm_out_file);
5391 /* Output a terminating entry for the .debug_srcinfo section. */
5393 fputc ('\n', asm_out_file);
5394 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5395 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5396 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5397 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5398 ASM_OUTPUT_POP_SECTION (asm_out_file);
5400 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5402 /* Output terminating entries for the .debug_macinfo section. */
5404 dwarfout_resume_previous_source_file (0);
5406 fputc ('\n', asm_out_file);
5407 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5408 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5409 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5410 ASM_OUTPUT_POP_SECTION (asm_out_file);
5413 /* Generate the terminating entry for the .debug_pubnames section. */
5415 fputc ('\n', asm_out_file);
5416 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5417 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5418 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5419 ASM_OUTPUT_POP_SECTION (asm_out_file);
5421 /* Generate the terminating entries for the .debug_aranges section.
5423 Note that we want to do this only *after* we have output the end
5424 labels (for the various program sections) which we are going to
5425 refer to here. This allows us to work around a bug in the m68k
5426 svr4 assembler. That assembler gives bogus assembly-time errors
5427 if (within any given section) you try to take the difference of
5428 two relocatable symbols, both of which are located within some
5429 other section, and if one (or both?) of the symbols involved is
5430 being forward-referenced. By generating the .debug_aranges
5431 entries at this late point in the assembly output, we skirt the
5432 issue simply by avoiding forward-references.
5435 fputc ('\n', asm_out_file);
5436 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5438 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5439 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5441 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5442 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5444 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5445 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5448 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5449 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5450 RODATA_BEGIN_LABEL);
5452 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5453 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5454 RODATA1_BEGIN_LABEL);
5456 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5457 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5459 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5460 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5462 ASM_OUTPUT_POP_SECTION (asm_out_file);
5466 #endif /* DWARF_DEBUGGING_INFO */