1 /* This file contains code written by Ron Guilmette (rfg@ncd.com) for
2 Network Computing Devices, August, September, October, November 1990.
4 Output Dwarf format symbol table information from the GNU C compiler.
5 Copyright (C) 1992 Free Software Foundation, Inc.
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #ifdef DWARF_DEBUGGING_INFO
31 #include "insn-config.h"
37 #define DWARF_VERSION 1
40 /* #define NDEBUG 1 */
43 #if defined(DWARF_TIMESTAMPS)
46 #else /* !defined(POSIX) */
47 #include <sys/types.h>
49 extern time_t time (time_t *);
50 #else /* !defined(__STDC__) */
51 extern time_t time ();
52 #endif /* !defined(__STDC__) */
53 #endif /* !defined(POSIX) */
54 #endif /* defined(DWARF_TIMESTAMPS) */
56 extern char *getpwd ();
58 extern char *index ();
59 extern char *rindex ();
61 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
62 regarding the GNU implementation of Dwarf. */
64 /* NOTE: In the comments in this file, many references are made to
65 so called "Debugging Information Entries". For the sake of brevity,
66 this term is abbreviated to `DIE' throughout the remainder of this
69 /* Note that the implementation of C++ support herein is (as yet) unfinished.
70 If you want to try to complete it, more power to you. */
72 #if defined(__GNUC__) && (NDEBUG == 1)
73 #define inline static inline
78 /* How to start an assembler comment. */
79 #ifndef ASM_COMMENT_START
80 #define ASM_COMMENT_START ";#"
83 /* Define a macro which returns non-zero for any tagged type which is
84 used (directly or indirectly) in the specification of either some
85 function's return type or some formal parameter of some function.
86 We use this macro when we are operating in "terse" mode to help us
87 know what tagged types have to be represented in Dwarf (even in
88 terse mode) and which ones don't.
90 A flag bit with this meaning really should be a part of the normal
91 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
92 for these nodes. For now, we have to just fake it. It it safe for
93 us to simply return zero for all complete tagged types (which will
94 get forced out anyway if they were used in the specification of some
95 formal or return type) and non-zero for all incomplete tagged types.
98 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
100 extern int flag_traditional;
101 extern char *version_string;
102 extern char *language_string;
104 /* Maximum size (in bytes) of an artificially generated label. */
106 #define MAX_ARTIFICIAL_LABEL_BYTES 30
108 /* Make sure we know the sizes of the various types dwarf can describe.
109 These are only defaults. If the sizes are different for your target,
110 you should override these values by defining the appropriate symbols
111 in your tm.h file. */
113 #ifndef CHAR_TYPE_SIZE
114 #define CHAR_TYPE_SIZE BITS_PER_UNIT
117 #ifndef SHORT_TYPE_SIZE
118 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
121 #ifndef INT_TYPE_SIZE
122 #define INT_TYPE_SIZE BITS_PER_WORD
125 #ifndef LONG_TYPE_SIZE
126 #define LONG_TYPE_SIZE BITS_PER_WORD
129 #ifndef LONG_LONG_TYPE_SIZE
130 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
133 #ifndef WCHAR_TYPE_SIZE
134 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
137 #ifndef WCHAR_UNSIGNED
138 #define WCHAR_UNSIGNED 0
141 #ifndef FLOAT_TYPE_SIZE
142 #define FLOAT_TYPE_SIZE BITS_PER_WORD
145 #ifndef DOUBLE_TYPE_SIZE
146 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
149 #ifndef LONG_DOUBLE_TYPE_SIZE
150 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
153 /* Structure to keep track of source filenames. */
155 struct filename_entry {
160 typedef struct filename_entry filename_entry;
162 /* Pointer to an array of elements, each one having the structure above. */
164 static filename_entry *filename_table;
166 /* Total number of entries in the table (i.e. array) pointed to by
167 `filename_table'. This is the *total* and includes both used and
170 static unsigned ft_entries_allocated;
172 /* Number of entries in the filename_table which are actually in use. */
174 static unsigned ft_entries;
176 /* Size (in elements) of increments by which we may expand the filename
177 table. Actually, a single hunk of space of this size should be enough
178 for most typical programs. */
180 #define FT_ENTRIES_INCREMENT 64
182 /* Local pointer to the name of the main input file. Initialized in
185 static char *primary_filename;
187 /* Pointer to the most recent filename for which we produced some line info. */
189 static char *last_filename;
191 /* For Dwarf output, we must assign lexical-blocks id numbers
192 in the order in which their beginnings are encountered.
193 We output Dwarf debugging info that refers to the beginnings
194 and ends of the ranges of code for each lexical block with
195 assembler labels ..Bn and ..Bn.e, where n is the block number.
196 The labels themselves are generated in final.c, which assigns
197 numbers to the blocks in the same way. */
199 static unsigned next_block_number = 2;
201 /* Counter to generate unique names for DIEs. */
203 static unsigned next_unused_dienum = 1;
205 /* Number of the DIE which is currently being generated. */
207 static unsigned current_dienum;
209 /* Number to use for the special "pubname" label on the next DIE which
210 represents a function or data object defined in this compilation
211 unit which has "extern" linkage. */
213 static next_pubname_number = 0;
215 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
217 /* Pointer to a dynamically allocated list of pre-reserved and still
218 pending sibling DIE numbers. Note that this list will grow as needed. */
220 static unsigned *pending_sibling_stack;
222 /* Counter to keep track of the number of pre-reserved and still pending
223 sibling DIE numbers. */
225 static unsigned pending_siblings;
227 /* The currently allocated size of the above list (expressed in number of
230 static unsigned pending_siblings_allocated;
232 /* Size (in elements) of increments by which we may expand the pending
233 sibling stack. Actually, a single hunk of space of this size should
234 be enough for most typical programs. */
236 #define PENDING_SIBLINGS_INCREMENT 64
238 /* Non-zero if we are performing our file-scope finalization pass and if
239 we should force out Dwarf descriptions of any and all file-scope
240 tagged types which are still incomplete types. */
242 static int finalizing = 0;
244 /* A pointer to the base of a list of pending types which we haven't
245 generated DIEs for yet, but which we will have to come back to
248 static tree *pending_types_list;
250 /* Number of elements currently allocated for the pending_types_list. */
252 static unsigned pending_types_allocated;
254 /* Number of elements of pending_types_list currently in use. */
256 static unsigned pending_types;
258 /* Size (in elements) of increments by which we may expand the pending
259 types list. Actually, a single hunk of space of this size should
260 be enough for most typical programs. */
262 #define PENDING_TYPES_INCREMENT 64
264 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
265 This is used in a hack to help us get the DIEs describing types of
266 formal parameters to come *after* all of the DIEs describing the formal
267 parameters themselves. That's necessary in order to be compatible
268 with what the brain-damaged svr4 SDB debugger requires. */
270 static tree fake_containing_scope;
272 /* The number of the current function definition that we are generating
273 debugging information for. These numbers range from 1 up to the maximum
274 number of function definitions contained within the current compilation
275 unit. These numbers are used to create unique labels for various things
276 contained within various function definitions. */
278 static unsigned current_funcdef_number = 1;
280 /* Forward declarations for functions defined in this file. */
282 static void output_type ();
283 static void type_attribute ();
284 static void output_decls_for_scope ();
285 static void output_decl ();
286 static unsigned lookup_filename ();
288 /* Definitions of defaults for assembler-dependent names of various
289 pseudo-ops and section names.
291 Theses may be overridden in your tm.h file (if necessary) for your
292 particular assembler. The default values provided here correspond to
293 what is expected by "standard" AT&T System V.4 assemblers. */
296 #define FILE_ASM_OP ".file"
298 #ifndef VERSION_ASM_OP
299 #define VERSION_ASM_OP ".version"
301 #ifndef UNALIGNED_SHORT_ASM_OP
302 #define UNALIGNED_SHORT_ASM_OP ".2byte"
304 #ifndef UNALIGNED_INT_ASM_OP
305 #define UNALIGNED_INT_ASM_OP ".4byte"
308 #define ASM_BYTE_OP ".byte"
311 #define SET_ASM_OP ".set"
314 /* Pseudo-ops for pushing the current section onto the section stack (and
315 simultaneously changing to a new section) and for poping back to the
316 section we were in immediately before this one. Note that most svr4
317 assemblers only maintain a one level stack... you can push all the
318 sections you want, but you can only pop out one level. (The sparc
319 svr4 assembler is an exception to this general rule.) That's
320 OK because we only use at most one level of the section stack herein. */
322 #ifndef PUSHSECTION_ASM_OP
323 #define PUSHSECTION_ASM_OP ".section"
325 #ifndef POPSECTION_ASM_OP
326 #define POPSECTION_ASM_OP ".previous"
329 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
330 to print the PUSHSECTION_ASM_OP and the section name. The default here
331 works for almost all svr4 assemblers, except for the sparc, where the
332 section name must be enclosed in double quotes. (See sparcv4.h.) */
334 #ifndef PUSHSECTION_FORMAT
335 #define PUSHSECTION_FORMAT "%s\t%s\n"
338 #ifndef DEBUG_SECTION
339 #define DEBUG_SECTION ".debug"
342 #define LINE_SECTION ".line"
344 #ifndef SFNAMES_SECTION
345 #define SFNAMES_SECTION ".debug_sfnames"
347 #ifndef SRCINFO_SECTION
348 #define SRCINFO_SECTION ".debug_srcinfo"
350 #ifndef MACINFO_SECTION
351 #define MACINFO_SECTION ".debug_macinfo"
353 #ifndef PUBNAMES_SECTION
354 #define PUBNAMES_SECTION ".debug_pubnames"
356 #ifndef ARANGES_SECTION
357 #define ARANGES_SECTION ".debug_aranges"
360 #define TEXT_SECTION ".text"
363 #define DATA_SECTION ".data"
365 #ifndef DATA1_SECTION
366 #define DATA1_SECTION ".data1"
368 #ifndef RODATA_SECTION
369 #define RODATA_SECTION ".rodata"
371 #ifndef RODATA1_SECTION
372 #define RODATA1_SECTION ".rodata1"
375 #define BSS_SECTION ".bss"
378 /* Definitions of defaults for formats and names of various special
379 (artificial) labels which may be generated within this file (when
380 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
382 If necessary, these may be overridden from within your tm.h file,
383 but typically, you should never need to override these.
385 These labels have been hacked (temporarily) so that they all begin with
386 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
387 stock m88k/svr4 assembler, both of which need to see .L at the start of
388 a label in order to prevent that label from going into the linker symbol
389 table). When I get time, I'll have to fix this the right way so that we
390 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
391 but that will require a rather massive set of changes. For the moment,
392 the following definitions out to produce the right results for all svr4
393 and svr3 assemblers. -- rfg
396 #ifndef TEXT_BEGIN_LABEL
397 #define TEXT_BEGIN_LABEL ".L_text_b"
399 #ifndef TEXT_END_LABEL
400 #define TEXT_END_LABEL ".L_text_e"
403 #ifndef DATA_BEGIN_LABEL
404 #define DATA_BEGIN_LABEL ".L_data_b"
406 #ifndef DATA_END_LABEL
407 #define DATA_END_LABEL ".L_data_e"
410 #ifndef DATA1_BEGIN_LABEL
411 #define DATA1_BEGIN_LABEL ".L_data1_b"
413 #ifndef DATA1_END_LABEL
414 #define DATA1_END_LABEL ".L_data1_e"
417 #ifndef RODATA_BEGIN_LABEL
418 #define RODATA_BEGIN_LABEL ".L_rodata_b"
420 #ifndef RODATA_END_LABEL
421 #define RODATA_END_LABEL ".L_rodata_e"
424 #ifndef RODATA1_BEGIN_LABEL
425 #define RODATA1_BEGIN_LABEL ".L_rodata1_b"
427 #ifndef RODATA1_END_LABEL
428 #define RODATA1_END_LABEL ".L_rodata1_e"
431 #ifndef BSS_BEGIN_LABEL
432 #define BSS_BEGIN_LABEL ".L_bss_b"
434 #ifndef BSS_END_LABEL
435 #define BSS_END_LABEL ".L_bss_e"
438 #ifndef LINE_BEGIN_LABEL
439 #define LINE_BEGIN_LABEL ".L_line_b"
441 #ifndef LINE_LAST_ENTRY_LABEL
442 #define LINE_LAST_ENTRY_LABEL ".L_line_last"
444 #ifndef LINE_END_LABEL
445 #define LINE_END_LABEL ".L_line_e"
448 #ifndef DEBUG_BEGIN_LABEL
449 #define DEBUG_BEGIN_LABEL ".L_debug_b"
451 #ifndef SFNAMES_BEGIN_LABEL
452 #define SFNAMES_BEGIN_LABEL ".L_sfnames_b"
454 #ifndef SRCINFO_BEGIN_LABEL
455 #define SRCINFO_BEGIN_LABEL ".L_srcinfo_b"
457 #ifndef MACINFO_BEGIN_LABEL
458 #define MACINFO_BEGIN_LABEL ".L_macinfo_b"
461 #ifndef DIE_BEGIN_LABEL_FMT
462 #define DIE_BEGIN_LABEL_FMT ".L_D%u"
464 #ifndef DIE_END_LABEL_FMT
465 #define DIE_END_LABEL_FMT ".L_D%u_e"
467 #ifndef PUB_DIE_LABEL_FMT
468 #define PUB_DIE_LABEL_FMT ".L_P%u"
470 #ifndef INSN_LABEL_FMT
471 #define INSN_LABEL_FMT ".L_I%u_%u"
473 #ifndef BLOCK_BEGIN_LABEL_FMT
474 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
476 #ifndef BLOCK_END_LABEL_FMT
477 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
479 #ifndef SS_BEGIN_LABEL_FMT
480 #define SS_BEGIN_LABEL_FMT ".L_s%u"
482 #ifndef SS_END_LABEL_FMT
483 #define SS_END_LABEL_FMT ".L_s%u_e"
485 #ifndef EE_BEGIN_LABEL_FMT
486 #define EE_BEGIN_LABEL_FMT ".L_e%u"
488 #ifndef EE_END_LABEL_FMT
489 #define EE_END_LABEL_FMT ".L_e%u_e"
491 #ifndef MT_BEGIN_LABEL_FMT
492 #define MT_BEGIN_LABEL_FMT ".L_t%u"
494 #ifndef MT_END_LABEL_FMT
495 #define MT_END_LABEL_FMT ".L_t%u_e"
497 #ifndef LOC_BEGIN_LABEL_FMT
498 #define LOC_BEGIN_LABEL_FMT ".L_l%u"
500 #ifndef LOC_END_LABEL_FMT
501 #define LOC_END_LABEL_FMT ".L_l%u_e"
503 #ifndef BOUND_BEGIN_LABEL_FMT
504 #define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c"
506 #ifndef BOUND_END_LABEL_FMT
507 #define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e"
509 #ifndef DERIV_BEGIN_LABEL_FMT
510 #define DERIV_BEGIN_LABEL_FMT ".L_d%u"
512 #ifndef DERIV_END_LABEL_FMT
513 #define DERIV_END_LABEL_FMT ".L_d%u_e"
515 #ifndef SL_BEGIN_LABEL_FMT
516 #define SL_BEGIN_LABEL_FMT ".L_sl%u"
518 #ifndef SL_END_LABEL_FMT
519 #define SL_END_LABEL_FMT ".L_sl%u_e"
521 #ifndef FUNC_END_LABEL_FMT
522 #define FUNC_END_LABEL_FMT ".L_f%u_e"
524 #ifndef TYPE_NAME_FMT
525 #define TYPE_NAME_FMT ".L_T%u"
527 #ifndef DECL_NAME_FMT
528 #define DECL_NAME_FMT ".L_E%u"
530 #ifndef LINE_CODE_LABEL_FMT
531 #define LINE_CODE_LABEL_FMT ".L_LC%u"
533 #ifndef SFNAMES_ENTRY_LABEL_FMT
534 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
536 #ifndef LINE_ENTRY_LABEL_FMT
537 #define LINE_ENTRY_LABEL_FMT ".L_LE%u"
540 /* Definitions of defaults for various types of primitive assembly language
543 If necessary, these may be overridden from within your tm.h file,
544 but typically, you shouldn't need to override these. One known
545 exception is ASM_OUTPUT_DEF which has to be different for stock
546 sparc/svr4 assemblers.
549 #ifndef ASM_OUTPUT_PUSH_SECTION
550 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
551 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
554 #ifndef ASM_OUTPUT_POP_SECTION
555 #define ASM_OUTPUT_POP_SECTION(FILE) \
556 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
559 #ifndef ASM_OUTPUT_SOURCE_FILENAME
560 #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
561 fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME)
564 #ifndef ASM_OUTPUT_DEF
565 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
566 do { fprintf ((FILE), "\t%s\t", SET_ASM_OP); \
567 assemble_name (FILE, LABEL1); \
568 fprintf (FILE, ","); \
569 assemble_name (FILE, LABEL2); \
570 fprintf (FILE, "\n"); \
574 #ifndef ASM_OUTPUT_DWARF_DELTA2
575 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
576 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
577 assemble_name (FILE, LABEL1); \
578 fprintf (FILE, "-"); \
579 assemble_name (FILE, LABEL2); \
580 fprintf (FILE, "\n"); \
584 #ifndef ASM_OUTPUT_DWARF_DELTA4
585 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
586 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
587 assemble_name (FILE, LABEL1); \
588 fprintf (FILE, "-"); \
589 assemble_name (FILE, LABEL2); \
590 fprintf (FILE, "\n"); \
594 #ifndef ASM_OUTPUT_DWARF_TAG
595 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
597 fprintf ((FILE), "\t%s\t0x%x", \
598 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
599 if (flag_verbose_asm) \
600 fprintf ((FILE), "\t%s %s", \
601 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
602 fputc ('\n', (FILE)); \
606 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
607 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
609 fprintf ((FILE), "\t%s\t0x%x", \
610 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
611 if (flag_verbose_asm) \
612 fprintf ((FILE), "\t%s %s", \
613 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
614 fputc ('\n', (FILE)); \
618 #ifndef ASM_OUTPUT_DWARF_STACK_OP
619 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
621 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
622 if (flag_verbose_asm) \
623 fprintf ((FILE), "\t%s %s", \
624 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
625 fputc ('\n', (FILE)); \
629 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
630 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
632 fprintf ((FILE), "\t%s\t0x%x", \
633 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
634 if (flag_verbose_asm) \
635 fprintf ((FILE), "\t%s %s", \
636 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
637 fputc ('\n', (FILE)); \
641 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
642 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
644 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
645 if (flag_verbose_asm) \
646 fprintf ((FILE), "\t%s %s", \
647 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
648 fputc ('\n', (FILE)); \
652 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
653 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
655 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
656 if (flag_verbose_asm) \
657 fprintf ((FILE), "\t%s %s", \
658 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
659 fputc ('\n', (FILE)); \
663 #ifndef ASM_OUTPUT_DWARF_ADDR
664 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
665 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
666 assemble_name (FILE, LABEL); \
667 fprintf (FILE, "\n"); \
671 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
672 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
674 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
675 output_addr_const ((FILE), (RTX)); \
676 fputc ('\n', (FILE)); \
680 #ifndef ASM_OUTPUT_DWARF_REF
681 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
682 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
683 assemble_name (FILE, LABEL); \
684 fprintf (FILE, "\n"); \
688 #ifndef ASM_OUTPUT_DWARF_DATA1
689 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
690 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
693 #ifndef ASM_OUTPUT_DWARF_DATA2
694 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
695 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
698 #ifndef ASM_OUTPUT_DWARF_DATA4
699 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
700 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
703 #ifndef ASM_OUTPUT_DWARF_DATA8
704 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
706 if (WORDS_BIG_ENDIAN) \
708 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
709 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
713 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
714 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
719 #ifndef ASM_OUTPUT_DWARF_STRING
720 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
721 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
724 /************************ general utility functions **************************/
730 register char *p = (char *) xmalloc (strlen (s) + 1);
740 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
741 || ((GET_CODE (rtl) == SUBREG)
742 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
745 /* Return non-zero if the given type node represents a tagged type. */
748 is_tagged_type (type)
751 register enum tree_code code = TREE_CODE (type);
753 return (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE);
758 register unsigned tag;
762 case TAG_padding: return "TAG_padding";
763 case TAG_array_type: return "TAG_array_type";
764 case TAG_class_type: return "TAG_class_type";
765 case TAG_entry_point: return "TAG_entry_point";
766 case TAG_enumeration_type: return "TAG_enumeration_type";
767 case TAG_formal_parameter: return "TAG_formal_parameter";
768 case TAG_global_subroutine: return "TAG_global_subroutine";
769 case TAG_global_variable: return "TAG_global_variable";
770 case TAG_label: return "TAG_label";
771 case TAG_lexical_block: return "TAG_lexical_block";
772 case TAG_local_variable: return "TAG_local_variable";
773 case TAG_member: return "TAG_member";
774 case TAG_pointer_type: return "TAG_pointer_type";
775 case TAG_reference_type: return "TAG_reference_type";
776 case TAG_compile_unit: return "TAG_compile_unit";
777 case TAG_string_type: return "TAG_string_type";
778 case TAG_structure_type: return "TAG_structure_type";
779 case TAG_subroutine: return "TAG_subroutine";
780 case TAG_subroutine_type: return "TAG_subroutine_type";
781 case TAG_typedef: return "TAG_typedef";
782 case TAG_union_type: return "TAG_union_type";
783 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
784 case TAG_variant: return "TAG_variant";
785 case TAG_common_block: return "TAG_common_block";
786 case TAG_common_inclusion: return "TAG_common_inclusion";
787 case TAG_inheritance: return "TAG_inheritance";
788 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
789 case TAG_module: return "TAG_module";
790 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
791 case TAG_set_type: return "TAG_set_type";
792 case TAG_subrange_type: return "TAG_subrange_type";
793 case TAG_with_stmt: return "TAG_with_stmt";
795 /* GNU extensions. */
797 case TAG_format_label: return "TAG_format_label";
798 case TAG_namelist: return "TAG_namelist";
799 case TAG_function_template: return "TAG_function_template";
800 case TAG_class_template: return "TAG_class_template";
802 default: return "TAG_<unknown>";
807 dwarf_attr_name (attr)
808 register unsigned attr;
812 case AT_sibling: return "AT_sibling";
813 case AT_location: return "AT_location";
814 case AT_name: return "AT_name";
815 case AT_fund_type: return "AT_fund_type";
816 case AT_mod_fund_type: return "AT_mod_fund_type";
817 case AT_user_def_type: return "AT_user_def_type";
818 case AT_mod_u_d_type: return "AT_mod_u_d_type";
819 case AT_ordering: return "AT_ordering";
820 case AT_subscr_data: return "AT_subscr_data";
821 case AT_byte_size: return "AT_byte_size";
822 case AT_bit_offset: return "AT_bit_offset";
823 case AT_bit_size: return "AT_bit_size";
824 case AT_element_list: return "AT_element_list";
825 case AT_stmt_list: return "AT_stmt_list";
826 case AT_low_pc: return "AT_low_pc";
827 case AT_high_pc: return "AT_high_pc";
828 case AT_language: return "AT_language";
829 case AT_member: return "AT_member";
830 case AT_discr: return "AT_discr";
831 case AT_discr_value: return "AT_discr_value";
832 case AT_string_length: return "AT_string_length";
833 case AT_common_reference: return "AT_common_reference";
834 case AT_comp_dir: return "AT_comp_dir";
835 case AT_const_value_string: return "AT_const_value_string";
836 case AT_const_value_data2: return "AT_const_value_data2";
837 case AT_const_value_data4: return "AT_const_value_data4";
838 case AT_const_value_data8: return "AT_const_value_data8";
839 case AT_const_value_block2: return "AT_const_value_block2";
840 case AT_const_value_block4: return "AT_const_value_block4";
841 case AT_containing_type: return "AT_containing_type";
842 case AT_default_value_addr: return "AT_default_value_addr";
843 case AT_default_value_data2: return "AT_default_value_data2";
844 case AT_default_value_data4: return "AT_default_value_data4";
845 case AT_default_value_data8: return "AT_default_value_data8";
846 case AT_default_value_string: return "AT_default_value_string";
847 case AT_friends: return "AT_friends";
848 case AT_inline: return "AT_inline";
849 case AT_is_optional: return "AT_is_optional";
850 case AT_lower_bound_ref: return "AT_lower_bound_ref";
851 case AT_lower_bound_data2: return "AT_lower_bound_data2";
852 case AT_lower_bound_data4: return "AT_lower_bound_data4";
853 case AT_lower_bound_data8: return "AT_lower_bound_data8";
854 case AT_private: return "AT_private";
855 case AT_producer: return "AT_producer";
856 case AT_program: return "AT_program";
857 case AT_protected: return "AT_protected";
858 case AT_prototyped: return "AT_prototyped";
859 case AT_public: return "AT_public";
860 case AT_pure_virtual: return "AT_pure_virtual";
861 case AT_return_addr: return "AT_return_addr";
862 case AT_abstract_origin: return "AT_abstract_origin";
863 case AT_start_scope: return "AT_start_scope";
864 case AT_stride_size: return "AT_stride_size";
865 case AT_upper_bound_ref: return "AT_upper_bound_ref";
866 case AT_upper_bound_data2: return "AT_upper_bound_data2";
867 case AT_upper_bound_data4: return "AT_upper_bound_data4";
868 case AT_upper_bound_data8: return "AT_upper_bound_data8";
869 case AT_virtual: return "AT_virtual";
873 case AT_sf_names: return "AT_sf_names";
874 case AT_src_info: return "AT_src_info";
875 case AT_mac_info: return "AT_mac_info";
876 case AT_src_coords: return "AT_src_coords";
878 default: return "AT_<unknown>";
883 dwarf_stack_op_name (op)
884 register unsigned op;
888 case OP_REG: return "OP_REG";
889 case OP_BASEREG: return "OP_BASEREG";
890 case OP_ADDR: return "OP_ADDR";
891 case OP_CONST: return "OP_CONST";
892 case OP_DEREF2: return "OP_DEREF2";
893 case OP_DEREF4: return "OP_DEREF4";
894 case OP_ADD: return "OP_ADD";
895 default: return "OP_<unknown>";
900 dwarf_typemod_name (mod)
901 register unsigned mod;
905 case MOD_pointer_to: return "MOD_pointer_to";
906 case MOD_reference_to: return "MOD_reference_to";
907 case MOD_const: return "MOD_const";
908 case MOD_volatile: return "MOD_volatile";
909 default: return "MOD_<unknown>";
914 dwarf_fmt_byte_name (fmt)
915 register unsigned fmt;
919 case FMT_FT_C_C: return "FMT_FT_C_C";
920 case FMT_FT_C_X: return "FMT_FT_C_X";
921 case FMT_FT_X_C: return "FMT_FT_X_C";
922 case FMT_FT_X_X: return "FMT_FT_X_X";
923 case FMT_UT_C_C: return "FMT_UT_C_C";
924 case FMT_UT_C_X: return "FMT_UT_C_X";
925 case FMT_UT_X_C: return "FMT_UT_X_C";
926 case FMT_UT_X_X: return "FMT_UT_X_X";
927 case FMT_ET: return "FMT_ET";
928 default: return "FMT_<unknown>";
932 dwarf_fund_type_name (ft)
933 register unsigned ft;
937 case FT_char: return "FT_char";
938 case FT_signed_char: return "FT_signed_char";
939 case FT_unsigned_char: return "FT_unsigned_char";
940 case FT_short: return "FT_short";
941 case FT_signed_short: return "FT_signed_short";
942 case FT_unsigned_short: return "FT_unsigned_short";
943 case FT_integer: return "FT_integer";
944 case FT_signed_integer: return "FT_signed_integer";
945 case FT_unsigned_integer: return "FT_unsigned_integer";
946 case FT_long: return "FT_long";
947 case FT_signed_long: return "FT_signed_long";
948 case FT_unsigned_long: return "FT_unsigned_long";
949 case FT_pointer: return "FT_pointer";
950 case FT_float: return "FT_float";
951 case FT_dbl_prec_float: return "FT_dbl_prec_float";
952 case FT_ext_prec_float: return "FT_ext_prec_float";
953 case FT_complex: return "FT_complex";
954 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
955 case FT_void: return "FT_void";
956 case FT_boolean: return "FT_boolean";
957 case FT_ext_prec_complex: return "FT_ext_prec_complex";
958 case FT_label: return "FT_label";
960 /* GNU extensions. */
962 case FT_long_long: return "FT_long_long";
963 case FT_signed_long_long: return "FT_signed_long_long";
964 case FT_unsigned_long_long: return "FT_unsigned_long_long";
966 case FT_int8: return "FT_int8";
967 case FT_signed_int8: return "FT_signed_int8";
968 case FT_unsigned_int8: return "FT_unsigned_int8";
969 case FT_int16: return "FT_int16";
970 case FT_signed_int16: return "FT_signed_int16";
971 case FT_unsigned_int16: return "FT_unsigned_int16";
972 case FT_int32: return "FT_int32";
973 case FT_signed_int32: return "FT_signed_int32";
974 case FT_unsigned_int32: return "FT_unsigned_int32";
975 case FT_int64: return "FT_int64";
976 case FT_signed_int64: return "FT_signed_int64";
977 case FT_unsigned_int64: return "FT_signed_int64";
979 case FT_real32: return "FT_real32";
980 case FT_real64: return "FT_real64";
981 case FT_real96: return "FT_real96";
982 case FT_real128: return "FT_real128";
984 default: return "FT_<unknown>";
988 /* Determine the "ultimate origin" of a decl. The decl may be an
989 inlined instance of an inlined instance of a decl which is local
990 to an inline function, so we have to trace all of the way back
991 through the origin chain to find out what sort of node actually
992 served as the original seed for the given block. */
995 decl_ultimate_origin (decl)
998 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1000 if (immediate_origin == NULL)
1004 register tree ret_val;
1005 register tree lookahead = immediate_origin;
1009 ret_val = lookahead;
1010 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1012 while (lookahead != NULL && lookahead != ret_val);
1017 /* Determine the "ultimate origin" of a block. The block may be an
1018 inlined instance of an inlined instance of a block which is local
1019 to an inline function, so we have to trace all of the way back
1020 through the origin chain to find out what sort of node actually
1021 served as the original seed for the given block. */
1024 block_ultimate_origin (block)
1025 register tree block;
1027 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1029 if (immediate_origin == NULL)
1033 register tree ret_val;
1034 register tree lookahead = immediate_origin;
1038 ret_val = lookahead;
1039 lookahead = (TREE_CODE (ret_val) == BLOCK)
1040 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1043 while (lookahead != NULL && lookahead != ret_val);
1049 output_unsigned_leb128 (value)
1050 register unsigned long value;
1052 register unsigned long orig_value = value;
1056 register unsigned byte = (value & 0x7f);
1059 if (value != 0) /* more bytes to follow */
1061 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1062 if (flag_verbose_asm && value == 0)
1063 fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1064 ASM_COMMENT_START, orig_value);
1065 fputc ('\n', asm_out_file);
1071 output_signed_leb128 (value)
1072 register long value;
1074 register long orig_value = value;
1075 register int negative = (value < 0);
1080 register unsigned byte = (value & 0x7f);
1084 value |= 0xfe000000; /* manually sign extend */
1085 if (((value == 0) && ((byte & 0x40) == 0))
1086 || ((value == -1) && ((byte & 0x40) == 1)))
1093 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1094 if (flag_verbose_asm && more == 0)
1095 fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1096 ASM_COMMENT_START, orig_value);
1097 fputc ('\n', asm_out_file);
1102 /**************** utility functions for attribute functions ******************/
1104 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1105 node in question represents the outermost pair of curly braces (i.e.
1106 the "body block") of a function or method.
1108 For any BLOCK node representing a "body block" of a function or method,
1109 the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
1110 which represents the outermost (function) scope for the function or
1111 method (i.e. the one which includes the formal parameters). The
1112 BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
1117 is_body_block (stmt)
1120 if (TREE_CODE (stmt) == BLOCK)
1122 register tree parent = BLOCK_SUPERCONTEXT (stmt);
1124 if (TREE_CODE (parent) == BLOCK)
1126 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
1128 if (TREE_CODE (grandparent) == FUNCTION_DECL)
1135 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1136 type code for the given type.
1138 This routine must only be called for GCC type nodes that correspond to
1139 Dwarf fundamental types.
1141 The current Dwarf draft specification calls for Dwarf fundamental types
1142 to accurately reflect the fact that a given type was either a "plain"
1143 integral type or an explicitly "signed" integral type. Unfortunately,
1144 we can't always do this, because GCC may already have thrown away the
1145 information about the precise way in which the type was originally
1148 typedef signed int my_type;
1150 struct s { my_type f; };
1152 Since we may be stuck here without enought information to do exactly
1153 what is called for in the Dwarf draft specification, we do the best
1154 that we can under the circumstances and always use the "plain" integral
1155 fundamental type codes for int, short, and long types. That's probably
1156 good enough. The additional accuracy called for in the current DWARF
1157 draft specification is probably never even useful in practice. */
1160 fundamental_type_code (type)
1163 if (TREE_CODE (type) == ERROR_MARK)
1166 switch (TREE_CODE (type))
1175 /* Carefully distinguish all the standard types of C,
1176 without messing up if the language is not C.
1177 Note that we check only for the names that contain spaces;
1178 other names might occur by coincidence in other languages. */
1179 if (TYPE_NAME (type) != 0
1180 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1181 && DECL_NAME (TYPE_NAME (type)) != 0
1182 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1184 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1186 if (!strcmp (name, "unsigned char"))
1187 return FT_unsigned_char;
1188 if (!strcmp (name, "signed char"))
1189 return FT_signed_char;
1190 if (!strcmp (name, "unsigned int"))
1191 return FT_unsigned_integer;
1192 if (!strcmp (name, "short int"))
1194 if (!strcmp (name, "short unsigned int"))
1195 return FT_unsigned_short;
1196 if (!strcmp (name, "long int"))
1198 if (!strcmp (name, "long unsigned int"))
1199 return FT_unsigned_long;
1200 if (!strcmp (name, "long long int"))
1201 return FT_long_long; /* Not grok'ed by svr4 SDB */
1202 if (!strcmp (name, "long long unsigned int"))
1203 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1206 /* Most integer types will be sorted out above, however, for the
1207 sake of special `array index' integer types, the following code
1208 is also provided. */
1210 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1211 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1213 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1214 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1216 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1217 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1219 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1220 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1222 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1223 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1228 /* Carefully distinguish all the standard types of C,
1229 without messing up if the language is not C. */
1230 if (TYPE_NAME (type) != 0
1231 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1232 && DECL_NAME (TYPE_NAME (type)) != 0
1233 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1235 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1237 /* Note that here we can run afowl of a serious bug in "classic"
1238 svr4 SDB debuggers. They don't seem to understand the
1239 FT_ext_prec_float type (even though they should). */
1241 if (!strcmp (name, "long double"))
1242 return FT_ext_prec_float;
1245 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1246 return FT_dbl_prec_float;
1247 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1250 /* Note that here we can run afowl of a serious bug in "classic"
1251 svr4 SDB debuggers. They don't seem to understand the
1252 FT_ext_prec_float type (even though they should). */
1254 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1255 return FT_ext_prec_float;
1259 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1262 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1265 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1268 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1273 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1274 the Dwarf "root" type for the given input type. The Dwarf "root" type
1275 of a given type is generally the same as the given type, except that if
1276 the given type is a pointer or reference type, then the root type of
1277 the given type is the root type of the "basis" type for the pointer or
1278 reference type. (This definition of the "root" type is recursive.)
1279 Also, the root type of a `const' qualified type or a `volatile'
1280 qualified type is the root type of the given type without the
1287 if (TREE_CODE (type) == ERROR_MARK)
1288 return error_mark_node;
1290 switch (TREE_CODE (type))
1293 return error_mark_node;
1296 case REFERENCE_TYPE:
1297 return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type)));
1300 return TYPE_MAIN_VARIANT (type);
1304 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1305 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1308 write_modifier_bytes (type, decl_const, decl_volatile)
1310 register int decl_const;
1311 register int decl_volatile;
1313 if (TREE_CODE (type) == ERROR_MARK)
1316 if (TYPE_READONLY (type) || decl_const)
1317 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1318 if (TYPE_VOLATILE (type) || decl_volatile)
1319 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1320 switch (TREE_CODE (type))
1323 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1324 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1327 case REFERENCE_TYPE:
1328 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1329 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1338 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1339 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1342 type_is_fundamental (type)
1345 switch (TREE_CODE (type))
1364 case REFERENCE_TYPE:
1377 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1378 equate directive which will associate a symbolic name with the current DIE.
1380 The name used is an artificial label generated from the DECL_UID number
1381 associated with the given decl node. The name it gets equated to is the
1382 symbolic label that we (previously) output at the start of the DIE that
1383 we are currently generating.
1385 Calling this function while generating some "decl related" form of DIE
1386 makes it possible to later refer to the DIE which represents the given
1387 decl simply by re-generating the symbolic name from the ..._DECL node's
1391 equate_decl_number_to_die_number (decl)
1394 /* In the case where we are generating a DIE for some ..._DECL node
1395 which represents either some inline function declaration or some
1396 entity declared within an inline function declaration/definition,
1397 setup a symbolic name for the current DIE so that we have a name
1398 for this DIE that we can easily refer to later on within
1399 AT_abstract_origin attributes. */
1401 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1402 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1404 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1405 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1406 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1409 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1410 equate directive which will associate a symbolic name with the current DIE.
1412 The name used is an artificial label generated from the TYPE_UID number
1413 associated with the given type node. The name it gets equated to is the
1414 symbolic label that we (previously) output at the start of the DIE that
1415 we are currently generating.
1417 Calling this function while generating some "type related" form of DIE
1418 makes it easy to later refer to the DIE which represents the given type
1419 simply by re-generating the alternative name from the ..._TYPE node's
1423 equate_type_number_to_die_number (type)
1426 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1427 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1429 /* We are generating a DIE to represent the main variant of this type
1430 (i.e the type without any const or volatile qualifiers) so in order
1431 to get the equate to come out right, we need to get the main variant
1434 type = TYPE_MAIN_VARIANT (type);
1436 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1437 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1438 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1441 /* The following routine is a nice and simple transducer. It converts the
1442 RTL for a variable or parameter (resident in memory) into an equivalent
1443 Dwarf representation of a mechanism for getting the address of that same
1444 variable onto the top of a hypothetical "address evaluation" stack.
1446 When creating memory location descriptors, we are effectively trans-
1447 forming the RTL for a memory-resident object into its Dwarf postfix
1448 expression equivalent. This routine just recursively descends an
1449 RTL tree, turning it into Dwarf postfix code as it goes. */
1452 output_mem_loc_descriptor (rtl)
1455 /* Note that for a dynamically sized array, the location we will
1456 generate a description of here will be the lowest numbered location
1457 which is actually within the array. That's *not* necessarily the
1458 same as the zeroth element of the array. */
1460 switch (GET_CODE (rtl))
1464 /* The case of a subreg may arise when we have a local (register)
1465 variable or a formal (register) parameter which doesn't quite
1466 fill up an entire register. For now, just assume that it is
1467 legitimate to make the Dwarf info refer to the whole register
1468 which contains the given subreg. */
1470 rtl = XEXP (rtl, 0);
1475 /* Whenever a register number forms a part of the description of
1476 the method for calculating the (dynamic) address of a memory
1477 resident object, DWARF rules require the register number to
1478 be referred to as a "base register". This distinction is not
1479 based in any way upon what category of register the hardware
1480 believes the given register belongs to. This is strictly
1481 DWARF terminology we're dealing with here.
1483 Note that in cases where the location of a memory-resident data
1484 object could be expressed as:
1486 OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
1488 the actual DWARF location descriptor that we generate may just
1489 be OP_BASEREG (basereg). This may look deceptively like the
1490 object in question was allocated to a register (rather than
1491 in memory) so DWARF consumers need to be aware of the subtle
1492 distinction between OP_REG and OP_BASEREG. */
1494 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1496 register unsigned regno = REGNO (rtl);
1498 if (regno >= FIRST_PSEUDO_REGISTER)
1500 fprintf (stderr, "%s: regno botch detected: dwarfout.c:%u\n",
1501 language_string, __LINE__);
1505 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DBX_REGISTER_NUMBER (regno));
1510 output_mem_loc_descriptor (XEXP (rtl, 0));
1511 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1516 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1517 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1521 output_mem_loc_descriptor (XEXP (rtl, 0));
1522 output_mem_loc_descriptor (XEXP (rtl, 1));
1523 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1527 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1528 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1536 /* Output a proper Dwarf location descriptor for a variable or parameter
1537 which is either allocated in a register or in a memory location. For
1538 a register, we just generate an OP_REG and the register number. For a
1539 memory location we provide a Dwarf postfix expression describing how to
1540 generate the (dynamic) address of the object onto the address stack. */
1543 output_loc_descriptor (rtl)
1546 switch (GET_CODE (rtl))
1550 /* The case of a subreg may arise when we have a local (register)
1551 variable or a formal (register) parameter which doesn't quite
1552 fill up an entire register. For now, just assume that it is
1553 legitimate to make the Dwarf info refer to the whole register
1554 which contains the given subreg. */
1556 rtl = XEXP (rtl, 0);
1560 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1562 register unsigned regno = REGNO (rtl);
1564 if (regno >= FIRST_PSEUDO_REGISTER)
1566 fprintf (stderr, "%s: regno botch detected: dwarfout.c:%u\n",
1567 language_string, __LINE__);
1571 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DBX_REGISTER_NUMBER (regno));
1576 output_mem_loc_descriptor (XEXP (rtl, 0));
1580 abort (); /* Should never happen */
1584 /* Given a tree node describing an array bound (either lower or upper)
1585 output a representation for that bound. */
1588 output_bound_representation (bound, dim_num, u_or_l)
1589 register tree bound;
1590 register unsigned dim_num; /* For multi-dimensional arrays. */
1591 register char u_or_l; /* Designates upper or lower bound. */
1593 switch (TREE_CODE (bound))
1599 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1602 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1603 (unsigned) TREE_INT_CST_LOW (bound));
1606 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1610 bound = TREE_OPERAND (bound, 0);
1611 /* ... fall thru... */
1615 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1616 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1618 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1619 current_dienum, dim_num, u_or_l);
1621 sprintf (end_label, BOUND_END_LABEL_FMT,
1622 current_dienum, dim_num, u_or_l);
1624 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1625 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1627 /* If we are working on a bound for a dynamic dimension in C,
1628 the dynamic dimension in question had better have a static
1629 (zero) lower bound and a dynamic *upper* bound. */
1634 /* If optimization is turned on, the SAVE_EXPRs that describe
1635 how to access the upper bound values are essentially bogus.
1636 They only describe (at best) how to get at these values at
1637 the points in the generated code right after they have just
1638 been computed. Worse yet, in the typical case, the upper
1639 bound values will not even *be* computed in the optimized
1640 code, so these SAVE_EXPRs are entirely bogus.
1642 In order to compensate for this fact, we check here to see
1643 if optimization is enabled, and if so, we effectively create
1644 an empty location description for the (unknown and unknowable)
1647 This should not cause too much trouble for existing (stupid?)
1648 debuggers because they have to deal with empty upper bounds
1649 location descriptions anyway in order to be able to deal with
1650 incomplete array types.
1652 Of course an intelligent debugger (GDB?) should be able to
1653 comprehend that a missing upper bound specification in a
1654 array type used for a storage class `auto' local array variable
1655 indicates that the upper bound is both unknown (at compile-
1656 time) and unknowable (at run-time) due to optimization.
1660 output_loc_descriptor
1661 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1663 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1672 /* Recursive function to output a sequence of value/name pairs for
1673 enumeration constants in reversed order. This is called from
1674 enumeration_type_die. */
1677 output_enumeral_list (link)
1682 output_enumeral_list (TREE_CHAIN (link));
1683 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1684 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1685 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1686 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1690 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
1691 which is not less than the value itself. */
1694 ceiling (value, boundary)
1695 register unsigned value;
1696 register unsigned boundary;
1698 return (((value + boundary - 1) / boundary) * boundary);
1701 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
1702 pointer to the declared type for the relevant field variable, or return
1703 `integer_type_node' if the given node turns out to be an ERROR_MARK node. */
1711 if (TREE_CODE (decl) == ERROR_MARK)
1712 return integer_type_node;
1714 type = DECL_BIT_FIELD_TYPE (decl);
1716 type = TREE_TYPE (decl);
1720 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1721 node, return the alignment in bits for the type, or else return
1722 BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */
1725 simple_type_align_in_bits (type)
1728 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
1731 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
1732 node, return the size in bits for the type if it is a constant, or
1733 else return the alignment for the type if the type's size is not
1734 constant, or else return BITS_PER_WORD if the type actually turns out
1735 to be an ERROR_MARK node. */
1738 simple_type_size_in_bits (type)
1741 if (TREE_CODE (type) == ERROR_MARK)
1742 return BITS_PER_WORD;
1745 register tree type_size_tree = TYPE_SIZE (type);
1747 if (TREE_CODE (type_size_tree) != INTEGER_CST)
1748 return TYPE_ALIGN (type);
1750 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
1754 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
1755 return the byte offset of the lowest addressed byte of the "containing
1756 object" for the given FIELD_DECL, or return 0 if we are unable to deter-
1757 mine what that offset is, either because the argument turns out to be a
1758 pointer to an ERROR_MARK node, or because the offset is actually variable.
1759 (We can't handle the latter case just yet.) */
1762 field_byte_offset (decl)
1765 register unsigned type_align_in_bytes;
1766 register unsigned type_align_in_bits;
1767 register unsigned type_size_in_bits;
1768 register unsigned object_offset_in_align_units;
1769 register unsigned object_offset_in_bits;
1770 register unsigned object_offset_in_bytes;
1772 register tree bitpos_tree;
1773 register tree field_size_tree;
1774 register unsigned bitpos_int;
1775 register unsigned deepest_bitpos;
1776 register unsigned field_size_in_bits;
1778 if (TREE_CODE (decl) == ERROR_MARK)
1781 if (TREE_CODE (decl) != FIELD_DECL)
1784 type = field_type (decl);
1786 bitpos_tree = DECL_FIELD_BITPOS (decl);
1787 field_size_tree = DECL_SIZE (decl);
1789 /* We cannot yet cope with fields whose positions or sizes are variable,
1790 so for now, when we see such things, we simply return 0. Someday,
1791 we may be able to handle such cases, but it will be damn difficult. */
1793 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1795 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1797 if (TREE_CODE (field_size_tree) != INTEGER_CST)
1799 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
1801 type_size_in_bits = simple_type_size_in_bits (type);
1803 type_align_in_bits = simple_type_align_in_bits (type);
1804 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1806 /* Note that the GCC front-end doesn't make any attempt to keep track
1807 of the starting bit offset (relative to the start of the containing
1808 structure type) of the hypothetical "containing object" for a bit-
1809 field. Thus, when computing the byte offset value for the start of
1810 the "containing object" of a bit-field, we must deduce this infor-
1813 This can be rather tricky to do in some cases. For example, handling
1814 the following structure type definition when compiling for an i386/i486
1815 target (which only aligns long long's to 32-bit boundaries) can be very
1820 long long field2:31;
1823 Fortunately, there is a simple rule-of-thumb which can be used in such
1824 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for
1825 the structure shown above. It decides to do this based upon one simple
1826 rule for bit-field allocation. Quite simply, GCC allocates each "con-
1827 taining object" for each bit-field at the first (i.e. lowest addressed)
1828 legitimate alignment boundary (based upon the required minimum alignment
1829 for the declared type of the field) which it can possibly use, subject
1830 to the condition that there is still enough available space remaining
1831 in the containing object (when allocated at the selected point) to
1832 fully accomodate all of the bits of the bit-field itself.
1834 This simple rule makes it obvious why GCC allocates 8 bytes for each
1835 object of the structure type shown above. When looking for a place to
1836 allocate the "containing object" for `field2', the compiler simply tries
1837 to allocate a 64-bit "containing object" at each successive 32-bit
1838 boundary (starting at zero) until it finds a place to allocate that 64-
1839 bit field such that at least 31 contiguous (and previously unallocated)
1840 bits remain within that selected 64 bit field. (As it turns out, for
1841 the example above, the compiler finds that it is OK to allocate the
1842 "containing object" 64-bit field at bit-offset zero within the
1845 Here we attempt to work backwards from the limited set of facts we're
1846 given, and we try to deduce from those facts, where GCC must have
1847 believed that the containing object started (within the structure type).
1849 The value we deduce is then used (by the callers of this routine) to
1850 generate AT_location and AT_bit_offset attributes for fields (both
1851 bit-fields and, in the case of AT_location, regular fields as well).
1854 /* Figure out the bit-distance from the start of the structure to the
1855 "deepest" bit of the bit-field. */
1856 deepest_bitpos = bitpos_int + field_size_in_bits;
1858 /* This is the tricky part. Use some fancy footwork to deduce where the
1859 lowest addressed bit of the containing object must be. */
1860 object_offset_in_bits
1861 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
1863 /* Compute the offset of the containing object in "alignment units". */
1864 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
1866 /* Compute the offset of the containing object in bytes. */
1867 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
1869 return object_offset_in_bytes;
1872 /****************************** attributes *********************************/
1874 /* The following routines are responsible for writing out the various types
1875 of Dwarf attributes (and any following data bytes associated with them).
1876 These routines are listed in order based on the numerical codes of their
1877 associated attributes. */
1879 /* Generate an AT_sibling attribute. */
1882 sibling_attribute ()
1884 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1886 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
1887 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
1888 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1891 /* Output the form of location attributes suitable for whole variables and
1892 whole parameters. Note that the location attributes for struct fields
1893 are generated by the routine `data_member_location_attribute' below. */
1896 location_attribute (rtl)
1899 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1900 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1902 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1903 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1904 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1905 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1906 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1908 /* Handle a special case. If we are about to output a location descriptor
1909 for a variable or parameter which has been optimized out of existence,
1910 don't do that. Instead we output a zero-length location descriptor
1911 value as part of the location attribute.
1913 A variable which has been optimized out of existance will have a
1914 DECL_RTL value which denotes a pseudo-reg.
1916 Currently, in some rare cases, variables can have DECL_RTL values
1917 which look like (MEM (REG pseudo-reg#)). These cases are due to
1918 bugs elsewhere in the compiler. We treat such cases
1919 as if the variable(s) in question had been optimized out of existance.
1921 Note that in all cases where we wish to express the fact that a
1922 variable has been optimized out of existance, we do not simply
1923 suppress the generation of the entire location attribute because
1924 the absence of a location attribute in certain kinds of DIEs is
1925 used to indicate something else entirely... i.e. that the DIE
1926 represents an object declaration, but not a definition. So sayeth
1930 if (! is_pseudo_reg (rtl)
1931 && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
1932 output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
1934 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1937 /* Output the specialized form of location attribute used for data members
1938 of struct and union types.
1940 In the special case of a FIELD_DECL node which represents a bit-field,
1941 the "offset" part of this special location descriptor must indicate the
1942 distance in bytes from the lowest-addressed byte of the containing
1943 struct or union type to the lowest-addressed byte of the "containing
1944 object" for the bit-field. (See the `field_byte_offset' function above.)
1946 For any given bit-field, the "containing object" is a hypothetical
1947 object (of some integral or enum type) within which the given bit-field
1948 lives. The type of this hypothetical "containing object" is always the
1949 same as the declared type of the individual bit-field itself (for GCC
1950 anyway... the DWARF spec doesn't actually mandate this).
1952 Note that it is the size (in bytes) of the hypothetical "containing
1953 object" which will be given in the AT_byte_size attribute for this
1954 bit-field. (See the `byte_size_attribute' function below.) It is
1955 also used when calculating the value of the AT_bit_offset attribute.
1956 (See the `bit_offset_attribute' function below.)
1960 data_member_location_attribute (decl)
1963 register unsigned object_offset_in_bytes = field_byte_offset (decl);
1964 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1965 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1967 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1968 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1969 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1970 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1971 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1972 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1973 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
1974 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1975 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1978 /* Output an AT_const_value attribute for a variable or a parameter which
1979 does not have a "location" either in memory or in a register. These
1980 things can arise in GNU C when a constant is passed as an actual
1981 parameter to an inlined function. They can also arise in C++ where
1982 declared constants do not necessarily get memory "homes". */
1985 const_value_attribute (rtl)
1988 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1989 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1991 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
1992 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1993 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1994 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
1995 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1997 switch (GET_CODE (rtl))
2000 /* Note that a CONST_INT rtx could represent either an integer or
2001 a floating-point constant. A CONST_INT is used whenever the
2002 constant will fit into a single word. In all such cases, the
2003 original mode of the constant value is wiped out, and the
2004 CONST_INT rtx is assigned VOIDmode. Since we no longer have
2005 precise mode information for these constants, we always just
2006 output them using 4 bytes. */
2008 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
2012 /* Note that a CONST_DOUBLE rtx could represent either an integer
2013 or a floating-point constant. A CONST_DOUBLE is used whenever
2014 the constant requires more than one word in order to be adequately
2015 represented. In all such cases, the original mode of the constant
2016 value is preserved as the mode of the CONST_DOUBLE rtx, but for
2017 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
2019 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
2020 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
2021 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
2025 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
2031 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
2035 /* In cases where an inlined instance of an inline function is passed
2036 the address of an `auto' variable (which is local to the caller)
2037 we can get a situation where the DECL_RTL of the artificial
2038 local variable (for the inlining) which acts as a stand-in for
2039 the corresponding formal parameter (of the inline function)
2040 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
2041 This is not exactly a compile-time constant expression, but it
2042 isn't the address of the (artificial) local variable either.
2043 Rather, it represents the *value* which the artificial local
2044 variable always has during its lifetime. We currently have no
2045 way to represent such quasi-constant values in Dwarf, so for now
2046 we just punt and generate an AT_const_value attribute with form
2047 FORM_BLOCK4 and a length of zero. */
2051 abort (); /* No other kinds of rtx should be possible here. */
2054 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2057 /* Generate *either* an AT_location attribute or else an AT_const_value
2058 data attribute for a variable or a parameter. We generate the
2059 AT_const_value attribute only in those cases where the given
2060 variable or parameter does not have a true "location" either in
2061 memory or in a register. This can happen (for example) when a
2062 constant is passed as an actual argument in a call to an inline
2063 function. (It's possible that these things can crop up in other
2064 ways also.) Note that one type of constant value which can be
2065 passed into an inlined function is a constant pointer. This can
2066 happen for example if an actual argument in an inlined function
2067 call evaluates to a compile-time constant address. */
2070 location_or_const_value_attribute (decl)
2075 if (TREE_CODE (decl) == ERROR_MARK)
2078 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
2081 /* Existing Dwarf debuggers need and expect the location descriptors for
2082 formal parameters to reflect either the place where the parameters get
2083 passed (if they are passed on the stack and in memory) or else the
2084 (preserved) registers which the parameters get copied to during the
2087 At least this is the way things are for most common CISC machines
2088 (e.g. x86 and m68k) where parameters are passed in the stack, and for
2089 most common RISC machines (e.g. i860 and m88k) where parameters are
2090 passed in registers.
2092 The rules for Sparc are a little weird for some reason. The DWARF
2093 generated by the USL C compiler for the Sparc/svr4 reference port says
2094 that the parameters are passed in the stack. I haven't figured out
2095 how to duplicate that behavior here (for the Sparc) yet, or even if
2098 Note that none of this is clearly spelled out in the current Dwarf
2099 version 1 specification, but it's obvious if you look at the output of
2100 the CI5 compiler, or if you try to use the svr4 SDB debugger. Hopefully,
2101 a later version of the Dwarf specification will clarify this. For now,
2102 we just need to generate the right thing. Note that Dwarf version 2
2103 will provide us with a means to describe *all* of the locations in which
2104 a given variable or parameter resides (and the PC ranges over which it
2105 occupies each one), but for now we can only describe one "location"
2106 for each formal parameter passed, and so we just try to mimic existing
2107 practice as much as possible.
2110 if (TREE_CODE (decl) != PARM_DECL)
2111 /* If this decl is not a formal parameter, just use DECL_RTL. */
2112 rtl = DECL_RTL (decl);
2115 if (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM)
2116 /* Parameter was passed in memory, so say that's where it lives. */
2117 rtl = DECL_INCOMING_RTL (decl);
2120 /* Parameter was passed in a register, so say it lives in the
2121 register it will be copied to during the prologue. */
2122 rtl = DECL_RTL (decl);
2124 /* Note that in cases where the formal parameter is never used
2125 and where this compilation is done with -O, the copying of
2126 of an incoming register parameter to another register (in
2127 the prologue) can be totally optimized away. (In such cases
2128 the DECL_RTL will indicate a pseudo-register.) We could just
2129 use the DECL_RTL (as we normally do for register parameters)
2130 in these cases, but if we did that, we would end up generating
2131 a null location descriptor. (See `location_attribute' above.)
2132 That would be acceptable (according to the DWARF spec) but it
2133 is probably more useful to say that the formal resides where
2134 it was passed instead of saying that it resides nowhere. */
2135 if (is_pseudo_reg (rtl))
2136 rtl = DECL_INCOMING_RTL (decl);
2143 switch (GET_CODE (rtl))
2151 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
2152 const_value_attribute (rtl);
2158 location_attribute (rtl);
2162 abort (); /* Should never happen. */
2166 /* Generate an AT_name attribute given some string value to be included as
2167 the value of the attribute. */
2170 name_attribute (name_string)
2171 register char *name_string;
2173 if (name_string && *name_string)
2175 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2176 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2181 fund_type_attribute (ft_code)
2182 register unsigned ft_code;
2184 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2185 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2189 mod_fund_type_attribute (type, decl_const, decl_volatile)
2191 register int decl_const;
2192 register int decl_volatile;
2194 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2195 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2197 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2198 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2199 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2200 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2201 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2202 write_modifier_bytes (type, decl_const, decl_volatile);
2203 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2204 fundamental_type_code (root_type (type)));
2205 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2209 user_def_type_attribute (type)
2212 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2214 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2215 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2216 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2220 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2222 register int decl_const;
2223 register int decl_volatile;
2225 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2226 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2227 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2229 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2230 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2231 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2232 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2233 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2234 write_modifier_bytes (type, decl_const, decl_volatile);
2235 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2236 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2237 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2240 #ifdef USE_ORDERING_ATTRIBUTE
2242 ordering_attribute (ordering)
2243 register unsigned ordering;
2245 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2246 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2248 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2250 /* Note that the block of subscript information for an array type also
2251 includes information about the element type of type given array type. */
2254 subscript_data_attribute (type)
2257 register unsigned dimension_number;
2258 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2259 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2261 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2262 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2263 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2264 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2265 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2267 /* The GNU compilers represent multidimensional array types as sequences
2268 of one dimensional array types whose element types are themselves array
2269 types. Here we squish that down, so that each multidimensional array
2270 type gets only one array_type DIE in the Dwarf debugging info. The
2271 draft Dwarf specification say that we are allowed to do this kind
2272 of compression in C (because there is no difference between an
2273 array or arrays and a multidimensional array in C) but for other
2274 source languages (e.g. Ada) we probably shouldn't do this. */
2276 for (dimension_number = 0;
2277 TREE_CODE (type) == ARRAY_TYPE;
2278 type = TREE_TYPE (type), dimension_number++)
2280 register tree domain = TYPE_DOMAIN (type);
2282 /* Arrays come in three flavors. Unspecified bounds, fixed
2283 bounds, and (in GNU C only) variable bounds. Handle all
2284 three forms here. */
2288 /* We have an array type with specified bounds. */
2290 register tree lower = TYPE_MIN_VALUE (domain);
2291 register tree upper = TYPE_MAX_VALUE (domain);
2293 /* Handle only fundamental types as index types for now. */
2295 if (! type_is_fundamental (domain))
2298 /* Output the representation format byte for this dimension. */
2300 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2302 TREE_CODE (lower) == INTEGER_CST,
2303 TREE_CODE (upper) == INTEGER_CST));
2305 /* Output the index type for this dimension. */
2307 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2308 fundamental_type_code (domain));
2310 /* Output the representation for the lower bound. */
2312 output_bound_representation (lower, dimension_number, 'l');
2314 /* Output the representation for the upper bound. */
2316 output_bound_representation (upper, dimension_number, 'u');
2320 /* We have an array type with an unspecified length. For C and
2321 C++ we can assume that this really means that (a) the index
2322 type is an integral type, and (b) the lower bound is zero.
2323 Note that Dwarf defines the representation of an unspecified
2324 (upper) bound as being a zero-length location description. */
2326 /* Output the array-bounds format byte. */
2328 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2330 /* Output the (assumed) index type. */
2332 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2334 /* Output the (assumed) lower bound (constant) value. */
2336 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2338 /* Output the (empty) location description for the upper bound. */
2340 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2344 /* Output the prefix byte that says that the element type is comming up. */
2346 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2348 /* Output a representation of the type of the elements of this array type. */
2350 type_attribute (type, 0, 0);
2352 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2356 byte_size_attribute (tree_node)
2357 register tree tree_node;
2359 register unsigned size;
2361 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2362 switch (TREE_CODE (tree_node))
2371 size = int_size_in_bytes (tree_node);
2375 /* For a data member of a struct or union, the AT_byte_size is
2376 generally given as the number of bytes normally allocated for
2377 an object of the *declared* type of the member itself. This
2378 is true even for bit-fields. */
2379 size = simple_type_size_in_bits (field_type (tree_node))
2387 /* Note that `size' might be -1 when we get to this point. If it
2388 is, that indicates that the byte size of the entity in question
2389 is variable. We have no good way of expressing this fact in Dwarf
2390 at the present time, so just let the -1 pass on through. */
2392 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2395 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2396 which specifies the distance in bits from the highest order bit of the
2397 "containing object" for the bit-field to the highest order bit of the
2400 For any given bit-field, the "containing object" is a hypothetical
2401 object (of some integral or enum type) within which the given bit-field
2402 lives. The type of this hypothetical "containing object" is always the
2403 same as the declared type of the individual bit-field itself.
2405 The determination of the exact location of the "containing object" for
2406 a bit-field is rather complicated. It's handled by the `field_byte_offset'
2409 Note that it is the size (in bytes) of the hypothetical "containing
2410 object" which will be given in the AT_byte_size attribute for this
2411 bit-field. (See `byte_size_attribute' above.)
2415 bit_offset_attribute (decl)
2418 register unsigned object_offset_in_bytes = field_byte_offset (decl);
2419 register tree type = DECL_BIT_FIELD_TYPE (decl);
2420 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2421 register unsigned bitpos_int;
2422 register unsigned highest_order_object_bit_offset;
2423 register unsigned highest_order_field_bit_offset;
2424 register unsigned bit_offset;
2426 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2427 assert (type); /* Must be a bit field. */
2429 /* We can't yet handle bit-fields whose offsets are variable, so if we
2430 encounter such things, just return without generating any attribute
2433 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2435 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2437 /* Note that the bit offset is always the distance (in bits) from the
2438 highest-order bit of the "containing object" to the highest-order
2439 bit of the bit-field itself. Since the "high-order end" of any
2440 object or field is different on big-endian and little-endian machines,
2441 the computation below must take account of these differences. */
2443 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
2444 highest_order_field_bit_offset = bitpos_int;
2446 #if (BYTES_BIG_ENDIAN == 0)
2447 highest_order_field_bit_offset
2448 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2450 highest_order_object_bit_offset += simple_type_size_in_bits (type);
2451 #endif /* (BYTES_BIG_ENDIAN == 0) */
2454 #if (BYTES_BIG_ENDIAN == 0)
2455 highest_order_object_bit_offset - highest_order_field_bit_offset;
2456 #else /* (BYTES_BIG_ENDIAN != 0) */
2457 highest_order_field_bit_offset - highest_order_object_bit_offset;
2458 #endif /* (BYTES_BIG_ENDIAN != 0) */
2460 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2461 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
2464 /* For a FIELD_DECL node which represents a bit field, output an attribute
2465 which specifies the length in bits of the given field. */
2468 bit_size_attribute (decl)
2471 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2472 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
2474 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2475 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2476 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2479 /* The following routine outputs the `element_list' attribute for enumeration
2480 type DIEs. The element_lits attribute includes the names and values of
2481 all of the enumeration constants associated with the given enumeration
2485 element_list_attribute (element)
2486 register tree element;
2488 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2489 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2491 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2492 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2493 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2494 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2495 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2497 /* Here we output a list of value/name pairs for each enumeration constant
2498 defined for this enumeration type (as required), but we do it in REVERSE
2499 order. The order is the one required by the draft #5 Dwarf specification
2500 published by the UI/PLSIG. */
2502 output_enumeral_list (element); /* Recursively output the whole list. */
2504 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2507 /* Generate an AT_stmt_list attribute. These are normally present only in
2508 DIEs with a TAG_compile_unit tag. */
2511 stmt_list_attribute (label)
2512 register char *label;
2514 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2515 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2516 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2519 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2520 for a subroutine DIE. */
2523 low_pc_attribute (asm_low_label)
2524 register char *asm_low_label;
2526 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2527 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2530 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2534 high_pc_attribute (asm_high_label)
2535 register char *asm_high_label;
2537 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2538 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2541 /* Generate an AT_language attribute given a LANG value. These attributes
2542 are used only within TAG_compile_unit DIEs. */
2545 language_attribute (language_code)
2546 register unsigned language_code;
2548 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2549 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2553 member_attribute (context)
2554 register tree context;
2556 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2558 /* Generate this attribute only for members in C++. */
2560 if (context != NULL && is_tagged_type (context))
2562 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2563 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2564 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2569 string_length_attribute (upper_bound)
2570 register tree upper_bound;
2572 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2573 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2575 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2576 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2577 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2578 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2579 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2580 output_bound_representation (upper_bound, 0, 'u');
2581 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2585 comp_dir_attribute (dirname)
2586 register char *dirname;
2588 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2589 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2593 sf_names_attribute (sf_names_start_label)
2594 register char *sf_names_start_label;
2596 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2597 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2598 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2602 src_info_attribute (src_info_start_label)
2603 register char *src_info_start_label;
2605 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2606 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2607 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2611 mac_info_attribute (mac_info_start_label)
2612 register char *mac_info_start_label;
2614 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2615 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2616 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2620 prototyped_attribute (func_type)
2621 register tree func_type;
2623 if ((strcmp (language_string, "GNU C") == 0)
2624 && (TYPE_ARG_TYPES (func_type) != NULL))
2626 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2627 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2632 producer_attribute (producer)
2633 register char *producer;
2635 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2636 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2640 inline_attribute (decl)
2643 if (DECL_INLINE (decl))
2645 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2646 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2651 containing_type_attribute (containing_type)
2652 register tree containing_type;
2654 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2656 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2657 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2658 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2662 abstract_origin_attribute (origin)
2663 register tree origin;
2665 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2667 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2668 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2671 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2675 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2679 abort (); /* Should never happen. */
2682 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2685 #ifdef DWARF_DECL_COORDINATES
2687 src_coords_attribute (src_fileno, src_lineno)
2688 register unsigned src_fileno;
2689 register unsigned src_lineno;
2691 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2692 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2693 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2695 #endif /* defined(DWARF_DECL_COORDINATES) */
2698 pure_or_virtual_attribute (func_decl)
2699 register tree func_decl;
2701 if (DECL_VIRTUAL_P (func_decl))
2703 #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */
2704 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2705 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2708 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2709 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2713 /************************* end of attributes *****************************/
2715 /********************* utility routines for DIEs *************************/
2717 /* Output an AT_name attribute and an AT_src_coords attribute for the
2718 given decl, but only if it actually has a name. */
2721 name_and_src_coords_attributes (decl)
2724 register tree decl_name = DECL_NAME (decl);
2726 if (decl_name && IDENTIFIER_POINTER (decl_name))
2728 name_attribute (IDENTIFIER_POINTER (decl_name));
2729 #ifdef DWARF_DECL_COORDINATES
2731 register unsigned file_index;
2733 /* This is annoying, but we have to pop out of the .debug section
2734 for a moment while we call `lookup_filename' because calling it
2735 may cause a temporary switch into the .debug_sfnames section and
2736 most svr4 assemblers are not smart enough be be able to nest
2737 section switches to any depth greater than one. Note that we
2738 also can't skirt this issue by delaying all output to the
2739 .debug_sfnames section unit the end of compilation because that
2740 would cause us to have inter-section forward references and
2741 Fred Fish sez that m68k/svr4 assemblers botch those. */
2743 ASM_OUTPUT_POP_SECTION (asm_out_file);
2744 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
2745 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
2747 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
2749 #endif /* defined(DWARF_DECL_COORDINATES) */
2753 /* Many forms of DIEs contain a "type description" part. The following
2754 routine writes out these "type descriptor" parts. */
2757 type_attribute (type, decl_const, decl_volatile)
2759 register int decl_const;
2760 register int decl_volatile;
2762 register enum tree_code code = TREE_CODE (type);
2763 register int root_type_modified;
2765 if (TREE_CODE (type) == ERROR_MARK)
2768 /* Handle a special case. For functions whose return type is void,
2769 we generate *no* type attribute. (Note that no object may have
2770 type `void', so this only applies to function return types. */
2772 if (TREE_CODE (type) == VOID_TYPE)
2775 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2776 || decl_const || decl_volatile
2777 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2779 if (type_is_fundamental (root_type (type)))
2780 if (root_type_modified)
2781 mod_fund_type_attribute (type, decl_const, decl_volatile);
2783 fund_type_attribute (fundamental_type_code (type));
2785 if (root_type_modified)
2786 mod_u_d_type_attribute (type, decl_const, decl_volatile);
2788 user_def_type_attribute (type);
2791 /* Given a tree pointer to a struct, class, union, or enum type node, return
2792 a pointer to the (string) tag name for the given type, or zero if the
2793 type was declared without a tag. */
2799 register char *name = 0;
2801 if (TYPE_NAME (type) != 0)
2803 register tree t = 0;
2805 /* Find the IDENTIFIER_NODE for the type name. */
2806 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2807 t = TYPE_NAME (type);
2809 /* The g++ front end makes the TYPE_NAME of *each* tagged type point
2810 to a TYPE_DECL node, regardless of whether or not a `typedef' was
2811 involved. This is distinctly different from what the gcc front-end
2812 does. It always makes the TYPE_NAME for each tagged type be either
2813 NULL (signifying an anonymous tagged type) or else a pointer to an
2814 IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf
2815 for both C and C++, but given this inconsistency in the TREE
2816 representation of tagged types for C and C++ in the GNU front-ends,
2817 we cannot support both languages correctly unless we introduce some
2818 front-end specific code here, and rms objects to that, so we can
2819 only generate correct Dwarf for one of these two languages. C is
2820 more important, so for now we'll do the right thing for C and let
2824 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2825 t = DECL_NAME (TYPE_NAME (type));
2827 /* Now get the name as a string, or invent one. */
2829 name = IDENTIFIER_POINTER (t);
2832 return (name == 0 || *name == '\0') ? 0 : name;
2838 /* Start by checking if the pending_sibling_stack needs to be expanded.
2839 If necessary, expand it. */
2841 if (pending_siblings == pending_siblings_allocated)
2843 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
2844 pending_sibling_stack
2845 = (unsigned *) xrealloc (pending_sibling_stack,
2846 pending_siblings_allocated * sizeof(unsigned));
2850 NEXT_DIE_NUM = next_unused_dienum++;
2853 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
2863 member_declared_type (member)
2864 register tree member;
2866 return (DECL_BIT_FIELD_TYPE (member))
2867 ? DECL_BIT_FIELD_TYPE (member)
2868 : TREE_TYPE (member);
2871 /******************************* DIEs ************************************/
2873 /* Output routines for individual types of DIEs. */
2875 /* Note that every type of DIE (except a null DIE) gets a sibling. */
2878 output_array_type_die (arg)
2881 register tree type = arg;
2883 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
2884 sibling_attribute ();
2885 equate_type_number_to_die_number (type);
2886 member_attribute (TYPE_CONTEXT (type));
2888 /* I believe that we can default the array ordering. SDB will probably
2889 do the right things even if AT_ordering is not present. It's not
2890 even an issue until we start to get into multidimensional arrays
2891 anyway. If SDB is ever caught doing the Wrong Thing for multi-
2892 dimensional arrays, then we'll have to put the AT_ordering attribute
2893 back in. (But if and when we find out that we need to put these in,
2894 we will only do so for multidimensional arrays. After all, we don't
2895 want to waste space in the .debug section now do we?) */
2897 #ifdef USE_ORDERING_ATTRIBUTE
2898 ordering_attribute (ORD_row_major);
2899 #endif /* defined(USE_ORDERING_ATTRIBUTE) */
2901 subscript_data_attribute (type);
2905 output_set_type_die (arg)
2908 register tree type = arg;
2910 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
2911 sibling_attribute ();
2912 equate_type_number_to_die_number (type);
2913 member_attribute (TYPE_CONTEXT (type));
2914 type_attribute (TREE_TYPE (type), 0, 0);
2918 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
2920 output_entry_point_die (arg)
2923 register tree decl = arg;
2924 register tree origin = decl_ultimate_origin (decl);
2926 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
2927 sibling_attribute ();
2930 abstract_origin_attribute (origin);
2933 name_and_src_coords_attributes (decl);
2934 member_attribute (DECL_CONTEXT (decl));
2935 type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
2937 if (DECL_ABSTRACT (decl))
2938 equate_decl_number_to_die_number (decl);
2940 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
2944 /* Output a DIE to represent an inlined instance of an enumeration type. */
2947 output_inlined_enumeration_type_die (arg)
2950 register tree type = arg;
2952 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2953 sibling_attribute ();
2954 assert (TREE_ASM_WRITTEN (type));
2955 abstract_origin_attribute (type);
2958 /* Output a DIE to represent an inlined instance of a structure type. */
2961 output_inlined_structure_type_die (arg)
2964 register tree type = arg;
2966 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_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 union type. */
2975 output_inlined_union_type_die (arg)
2978 register tree type = arg;
2980 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
2981 sibling_attribute ();
2982 assert (TREE_ASM_WRITTEN (type));
2983 abstract_origin_attribute (type);
2986 /* Output a DIE to represent an enumeration type. Note that these DIEs
2987 include all of the information about the enumeration values also.
2988 This information is encoded into the element_list attribute. */
2991 output_enumeration_type_die (arg)
2994 register tree type = arg;
2996 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2997 sibling_attribute ();
2998 equate_type_number_to_die_number (type);
2999 name_attribute (type_tag (type));
3000 member_attribute (TYPE_CONTEXT (type));
3002 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
3003 given enum type is incomplete, do not generate the AT_byte_size
3004 attribute or the AT_element_list attribute. */
3006 if (TYPE_SIZE (type))
3008 byte_size_attribute (type);
3009 element_list_attribute (TYPE_FIELDS (type));
3013 /* Output a DIE to represent either a real live formal parameter decl or
3014 to represent just the type of some formal parameter position in some
3017 Note that this routine is a bit unusual because its argument may be
3018 a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
3019 represents an inlining of some PARM_DECL) or else some sort of a
3020 ..._TYPE node. If it's the former then this function is being called
3021 to output a DIE to represent a formal parameter object (or some inlining
3022 thereof). If it's the latter, then this function is only being called
3023 to output a TAG_formal_parameter DIE to stand as a placeholder for some
3024 formal argument type of some subprogram type. */
3027 output_formal_parameter_die (arg)
3030 register tree node = arg;
3032 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
3033 sibling_attribute ();
3035 switch (TREE_CODE_CLASS (TREE_CODE (node)))
3037 case 'd': /* We were called with some kind of a ..._DECL node. */
3039 register tree origin = decl_ultimate_origin (node);
3042 abstract_origin_attribute (origin);
3045 name_and_src_coords_attributes (node);
3046 type_attribute (TREE_TYPE (node),
3047 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
3049 if (DECL_ABSTRACT (node))
3050 equate_decl_number_to_die_number (node);
3052 location_or_const_value_attribute (node);
3056 case 't': /* We were called with some kind of a ..._TYPE node. */
3057 type_attribute (node, 0, 0);
3061 abort (); /* Should never happen. */
3065 /* Output a DIE to represent a declared function (either file-scope
3066 or block-local) which has "external linkage" (according to ANSI-C). */
3069 output_global_subroutine_die (arg)
3072 register tree decl = arg;
3073 register tree origin = decl_ultimate_origin (decl);
3075 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
3076 sibling_attribute ();
3079 abstract_origin_attribute (origin);
3082 register tree type = TREE_TYPE (decl);
3084 name_and_src_coords_attributes (decl);
3085 inline_attribute (decl);
3086 prototyped_attribute (type);
3087 member_attribute (DECL_CONTEXT (decl));
3088 type_attribute (TREE_TYPE (type), 0, 0);
3089 pure_or_virtual_attribute (decl);
3091 if (DECL_ABSTRACT (decl))
3092 equate_decl_number_to_die_number (decl);
3095 if (! DECL_EXTERNAL (decl))
3097 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3099 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
3100 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3101 high_pc_attribute (func_end_label);
3106 /* Output a DIE to represent a declared data object (either file-scope
3107 or block-local) which has "external linkage" (according to ANSI-C). */
3110 output_global_variable_die (arg)
3113 register tree decl = arg;
3114 register tree origin = decl_ultimate_origin (decl);
3116 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
3117 sibling_attribute ();
3119 abstract_origin_attribute (origin);
3122 name_and_src_coords_attributes (decl);
3123 member_attribute (DECL_CONTEXT (decl));
3124 type_attribute (TREE_TYPE (decl),
3125 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3127 if (DECL_ABSTRACT (decl))
3128 equate_decl_number_to_die_number (decl);
3131 if (!DECL_EXTERNAL (decl))
3132 location_or_const_value_attribute (decl);
3137 output_label_die (arg)
3140 register tree decl = arg;
3141 register tree origin = decl_ultimate_origin (decl);
3143 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
3144 sibling_attribute ();
3146 abstract_origin_attribute (origin);
3148 name_and_src_coords_attributes (decl);
3149 if (DECL_ABSTRACT (decl))
3150 equate_decl_number_to_die_number (decl);
3153 register rtx insn = DECL_RTL (decl);
3155 if (GET_CODE (insn) == CODE_LABEL)
3157 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3159 /* When optimization is enabled (via -O) some parts of the compiler
3160 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
3161 represent source-level labels which were explicitly declared by
3162 the user. This really shouldn't be happening though, so catch
3163 it if it ever does happen. */
3165 if (INSN_DELETED_P (insn))
3166 abort (); /* Should never happen. */
3168 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
3169 (unsigned) INSN_UID (insn));
3170 low_pc_attribute (label);
3176 output_lexical_block_die (arg)
3179 register tree stmt = arg;
3181 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
3182 sibling_attribute ();
3184 if (! BLOCK_ABSTRACT (stmt))
3186 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3187 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3189 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3190 low_pc_attribute (begin_label);
3191 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3192 high_pc_attribute (end_label);
3197 output_inlined_subroutine_die (arg)
3200 register tree stmt = arg;
3202 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3203 sibling_attribute ();
3205 abstract_origin_attribute (block_ultimate_origin (stmt));
3206 if (! BLOCK_ABSTRACT (stmt))
3208 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3209 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3211 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3212 low_pc_attribute (begin_label);
3213 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3214 high_pc_attribute (end_label);
3218 /* Output a DIE to represent a declared data object (either file-scope
3219 or block-local) which has "internal linkage" (according to ANSI-C). */
3222 output_local_variable_die (arg)
3225 register tree decl = arg;
3226 register tree origin = decl_ultimate_origin (decl);
3228 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3229 sibling_attribute ();
3231 abstract_origin_attribute (origin);
3234 name_and_src_coords_attributes (decl);
3235 member_attribute (DECL_CONTEXT (decl));
3236 type_attribute (TREE_TYPE (decl),
3237 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3239 if (DECL_ABSTRACT (decl))
3240 equate_decl_number_to_die_number (decl);
3242 location_or_const_value_attribute (decl);
3246 output_member_die (arg)
3249 register tree decl = arg;
3251 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3252 sibling_attribute ();
3253 name_and_src_coords_attributes (decl);
3254 member_attribute (DECL_CONTEXT (decl));
3255 type_attribute (member_declared_type (decl),
3256 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3257 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3259 byte_size_attribute (decl);
3260 bit_size_attribute (decl);
3261 bit_offset_attribute (decl);
3263 data_member_location_attribute (decl);
3267 /* Don't generate either pointer_type DIEs or reference_type DIEs. Use
3268 modified types instead.
3270 We keep this code here just in case these types of DIEs may be needed
3271 to represent certain things in other languages (e.g. Pascal) someday.
3275 output_pointer_type_die (arg)
3278 register tree type = arg;
3280 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3281 sibling_attribute ();
3282 equate_type_number_to_die_number (type);
3283 member_attribute (TYPE_CONTEXT (type));
3284 type_attribute (TREE_TYPE (type), 0, 0);
3288 output_reference_type_die (arg)
3291 register tree type = arg;
3293 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3294 sibling_attribute ();
3295 equate_type_number_to_die_number (type);
3296 member_attribute (TYPE_CONTEXT (type));
3297 type_attribute (TREE_TYPE (type), 0, 0);
3302 output_ptr_to_mbr_type_die (arg)
3305 register tree type = arg;
3307 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3308 sibling_attribute ();
3309 equate_type_number_to_die_number (type);
3310 member_attribute (TYPE_CONTEXT (type));
3311 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3312 type_attribute (TREE_TYPE (type), 0, 0);
3316 output_compile_unit_die (arg)
3319 register char *main_input_filename = arg;
3321 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3322 sibling_attribute ();
3324 name_attribute (main_input_filename);
3329 sprintf (producer, "%s %s", language_string, version_string);
3330 producer_attribute (producer);
3333 if (strcmp (language_string, "GNU C++") == 0)
3334 language_attribute (LANG_C_PLUS_PLUS);
3335 else if (flag_traditional)
3336 language_attribute (LANG_C);
3338 language_attribute (LANG_C89);
3339 low_pc_attribute (TEXT_BEGIN_LABEL);
3340 high_pc_attribute (TEXT_END_LABEL);
3341 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3342 stmt_list_attribute (LINE_BEGIN_LABEL);
3343 last_filename = xstrdup (main_input_filename);
3346 char *wd = getpwd ();
3348 comp_dir_attribute (wd);
3351 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3353 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3354 src_info_attribute (SRCINFO_BEGIN_LABEL);
3355 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3356 mac_info_attribute (MACINFO_BEGIN_LABEL);
3361 output_string_type_die (arg)
3364 register tree type = arg;
3366 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3367 sibling_attribute ();
3368 member_attribute (TYPE_CONTEXT (type));
3370 /* Fudge the string length attribute for now. */
3372 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
3376 output_structure_type_die (arg)
3379 register tree type = arg;
3381 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3382 sibling_attribute ();
3383 equate_type_number_to_die_number (type);
3384 name_attribute (type_tag (type));
3385 member_attribute (TYPE_CONTEXT (type));
3387 /* If this type has been completed, then give it a byte_size attribute
3388 and prepare to give a list of members. Otherwise, don't do either of
3389 these things. In the latter case, we will not be generating a list
3390 of members (since we don't have any idea what they might be for an
3391 incomplete type). */
3393 if (TYPE_SIZE (type))
3396 byte_size_attribute (type);
3400 /* Output a DIE to represent a declared function (either file-scope
3401 or block-local) which has "internal linkage" (according to ANSI-C). */
3404 output_local_subroutine_die (arg)
3407 register tree decl = arg;
3408 register tree origin = decl_ultimate_origin (decl);
3410 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3411 sibling_attribute ();
3414 abstract_origin_attribute (origin);
3417 register tree type = TREE_TYPE (decl);
3419 name_and_src_coords_attributes (decl);
3420 inline_attribute (decl);
3421 prototyped_attribute (type);
3422 member_attribute (DECL_CONTEXT (decl));
3423 type_attribute (TREE_TYPE (type), 0, 0);
3424 pure_or_virtual_attribute (decl);
3426 if (DECL_ABSTRACT (decl))
3427 equate_decl_number_to_die_number (decl);
3430 /* Avoid getting screwed up in cases where a function was declared
3431 static but where no definition was ever given for it. */
3433 if (TREE_ASM_WRITTEN (decl))
3435 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3437 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
3438 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3439 high_pc_attribute (func_end_label);
3445 output_subroutine_type_die (arg)
3448 register tree type = arg;
3449 register tree return_type = TREE_TYPE (type);
3451 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3452 sibling_attribute ();
3454 equate_type_number_to_die_number (type);
3455 prototyped_attribute (type);
3456 member_attribute (TYPE_CONTEXT (type));
3457 type_attribute (return_type, 0, 0);
3461 output_typedef_die (arg)
3464 register tree decl = arg;
3465 register tree origin = decl_ultimate_origin (decl);
3467 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3468 sibling_attribute ();
3470 abstract_origin_attribute (origin);
3473 name_and_src_coords_attributes (decl);
3474 member_attribute (DECL_CONTEXT (decl));
3475 type_attribute (TREE_TYPE (decl),
3476 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3478 if (DECL_ABSTRACT (decl))
3479 equate_decl_number_to_die_number (decl);
3483 output_union_type_die (arg)
3486 register tree type = arg;
3488 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3489 sibling_attribute ();
3490 equate_type_number_to_die_number (type);
3491 name_attribute (type_tag (type));
3492 member_attribute (TYPE_CONTEXT (type));
3494 /* If this type has been completed, then give it a byte_size attribute
3495 and prepare to give a list of members. Otherwise, don't do either of
3496 these things. In the latter case, we will not be generating a list
3497 of members (since we don't have any idea what they might be for an
3498 incomplete type). */
3500 if (TYPE_SIZE (type))
3503 byte_size_attribute (type);
3507 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3508 at the end of an (ANSI prototyped) formal parameters list. */
3511 output_unspecified_parameters_die (arg)
3514 register tree decl_or_type = arg;
3516 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3517 sibling_attribute ();
3519 /* This kludge is here only for the sake of being compatible with what
3520 the USL CI5 C compiler does. The specification of Dwarf Version 1
3521 doesn't say that TAG_unspecified_parameters DIEs should contain any
3522 attributes other than the AT_sibling attribute, but they are certainly
3523 allowed to contain additional attributes, and the CI5 compiler
3524 generates AT_name, AT_fund_type, and AT_location attributes within
3525 TAG_unspecified_parameters DIEs which appear in the child lists for
3526 DIEs representing function definitions, so we do likewise here. */
3528 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3530 name_attribute ("...");
3531 fund_type_attribute (FT_pointer);
3532 /* location_attribute (?); */
3537 output_padded_null_die (arg)
3540 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3543 /*************************** end of DIEs *********************************/
3545 /* Generate some type of DIE. This routine generates the generic outer
3546 wrapper stuff which goes around all types of DIE's (regardless of their
3547 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3548 DIE-length word, followed by the guts of the DIE itself. After the guts
3549 of the DIE, there must always be a terminator label for the DIE. */
3552 output_die (die_specific_output_function, param)
3553 register void (*die_specific_output_function)();
3554 register void *param;
3556 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3557 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3559 current_dienum = NEXT_DIE_NUM;
3560 NEXT_DIE_NUM = next_unused_dienum;
3562 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3563 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3565 /* Write a label which will act as the name for the start of this DIE. */
3567 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3569 /* Write the DIE-length word. */
3571 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3573 /* Fill in the guts of the DIE. */
3575 next_unused_dienum++;
3576 die_specific_output_function (param);
3578 /* Write a label which will act as the name for the end of this DIE. */
3580 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3584 end_sibling_chain ()
3586 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3588 current_dienum = NEXT_DIE_NUM;
3589 NEXT_DIE_NUM = next_unused_dienum;
3591 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3593 /* Write a label which will act as the name for the start of this DIE. */
3595 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3597 /* Write the DIE-length word. */
3599 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3604 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3605 TAG_unspecified_parameters DIE) to represent the types of the formal
3606 parameters as specified in some function type specification (except
3607 for those which appear as part of a function *definition*).
3609 Note that we must be careful here to output all of the parameter DIEs
3610 *before* we output any DIEs needed to represent the types of the formal
3611 parameters. This keeps svr4 SDB happy because it (incorrectly) thinks
3612 that the first non-parameter DIE it sees ends the formal parameter list.
3616 output_formal_types (function_or_method_type)
3617 register tree function_or_method_type;
3620 register tree formal_type = NULL;
3621 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3623 /* In the case where we are generating a formal types list for a C++
3624 non-static member function type, skip over the first thing on the
3625 TYPE_ARG_TYPES list because it only represents the type of the
3626 hidden `this pointer'. The debugger should be able to figure
3627 out (without being explicitly told) that this non-static member
3628 function type takes a `this pointer' and should be able to figure
3629 what the type of that hidden parameter is from the AT_member
3630 attribute of the parent TAG_subroutine_type DIE. */
3632 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3633 first_parm_type = TREE_CHAIN (first_parm_type);
3635 /* Make our first pass over the list of formal parameter types and output
3636 a TAG_formal_parameter DIE for each one. */
3638 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3640 formal_type = TREE_VALUE (link);
3641 if (formal_type == void_type_node)
3644 /* Output a (nameless) DIE to represent the formal parameter itself. */
3646 output_die (output_formal_parameter_die, formal_type);
3649 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
3650 DIE to the end of the parameter list. */
3652 if (formal_type != void_type_node)
3653 output_die (output_unspecified_parameters_die, function_or_method_type);
3655 /* Make our second (and final) pass over the list of formal parameter types
3656 and output DIEs to represent those types (as necessary). */
3658 for (link = TYPE_ARG_TYPES (function_or_method_type);
3660 link = TREE_CHAIN (link))
3662 formal_type = TREE_VALUE (link);
3663 if (formal_type == void_type_node)
3666 output_type (formal_type, function_or_method_type);
3670 /* Remember a type in the pending_types_list. */
3676 if (pending_types == pending_types_allocated)
3678 pending_types_allocated += PENDING_TYPES_INCREMENT;
3680 = (tree *) xrealloc (pending_types_list,
3681 sizeof (tree) * pending_types_allocated);
3683 pending_types_list[pending_types++] = type;
3685 /* Mark the pending type as having been output already (even though
3686 it hasn't been). This prevents the type from being added to the
3687 pending_types_list more than once. */
3689 TREE_ASM_WRITTEN (type) = 1;
3692 /* Return non-zero if it is legitimate to output DIEs to represent a
3693 given type while we are generating the list of child DIEs for some
3694 DIE (e.g. a function or lexical block DIE) associated with a given scope.
3696 See the comments within the function for a description of when it is
3697 considered legitimate to output DIEs for various kinds of types.
3699 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
3700 or it may point to a BLOCK node (for types local to a block), or to a
3701 FUNCTION_DECL node (for types local to the heading of some function
3702 definition), or to a FUNCTION_TYPE node (for types local to the
3703 prototyped parameter list of a function type specification), or to a
3704 RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types).
3706 The `scope' parameter should likewise be NULL or should point to a
3707 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
3708 node, or a UNION_TYPE node.
3710 This function is used only for deciding when to "pend" and when to
3711 "un-pend" types to/from the pending_types_list.
3713 Note that we sometimes make use of this "type pending" feature in a
3714 rather twisted way to temporarily delay the production of DIEs for the
3715 types of formal parameters. (We do this just to make svr4 SDB happy.)
3716 It order to delay the production of DIEs representing types of formal
3717 parameters, callers of this function supply `fake_containing_scope' as
3718 the `scope' parameter to this function. Given that fake_containing_scope
3719 is a tagged type which is *not* the containing scope for *any* other type,
3720 the desired effect is achieved, i.e. output of DIEs representing types
3721 is temporarily suspended, and any type DIEs which would have otherwise
3722 been output are instead placed onto the pending_types_list. Later on,
3723 we force these (temporarily pended) types to be output simply by calling
3724 `output_pending_types_for_scope' with an actual argument equal to the
3725 true scope of the types we temporarily pended.
3729 type_ok_for_scope (type, scope)
3731 register tree scope;
3733 /* Tagged types (i.e. struct, union, and enum types) must always be
3734 output only in the scopes where they actually belong (or else the
3735 scoping of their own tag names and the scoping of their member
3736 names will be incorrect). Non-tagged-types on the other hand can
3737 generally be output anywhere, except that svr4 SDB really doesn't
3738 want to see them nested within struct or union types, so here we
3739 say it is always OK to immediately output any such a (non-tagged)
3740 type, so long as we are not within such a context. Note that the
3741 only kinds of non-tagged types which we will be dealing with here
3742 (for C and C++ anyway) will be array types and function types. */
3744 return is_tagged_type (type)
3745 ? (TYPE_CONTEXT (type) == scope)
3746 : (scope == NULL_TREE || ! is_tagged_type (scope));
3749 /* Output any pending types (from the pending_types list) which we can output
3750 now (taking into account the scope that we are working on now).
3752 For each type output, remove the given type from the pending_types_list
3753 *before* we try to output it.
3755 Note that we have to process the list in beginning-to-end order,
3756 because the call made here to output_type may cause yet more types
3757 to be added to the end of the list, and we may have to output some
3762 output_pending_types_for_scope (containing_scope)
3763 register tree containing_scope;
3765 register unsigned i;
3767 for (i = 0; i < pending_types; )
3769 register tree type = pending_types_list[i];
3771 if (type_ok_for_scope (type, containing_scope))
3773 register tree *mover;
3774 register tree *limit;
3777 limit = &pending_types_list[pending_types];
3778 for (mover = &pending_types_list[i]; mover < limit; mover++)
3779 *mover = *(mover+1);
3781 /* Un-mark the type as having been output already (because it
3782 hasn't been, really). Then call output_type to generate a
3783 Dwarf representation of it. */
3785 TREE_ASM_WRITTEN (type) = 0;
3786 output_type (type, containing_scope);
3788 /* Don't increment the loop counter in this case because we
3789 have shifted all of the subsequent pending types down one
3790 element in the pending_types_list array. */
3798 output_type (type, containing_scope)
3800 register tree containing_scope;
3802 if (type == 0 || type == error_mark_node)
3805 /* We are going to output a DIE to represent the unqualified version of
3806 of this type (i.e. without any const or volatile qualifiers) so get
3807 the main variant (i.e. the unqualified version) of this type now. */
3809 type = TYPE_MAIN_VARIANT (type);
3811 if (TREE_ASM_WRITTEN (type))
3814 /* Don't generate any DIEs for this type now unless it is OK to do so
3815 (based upon what `type_ok_for_scope' tells us). */
3817 if (! type_ok_for_scope (type, containing_scope))
3823 switch (TREE_CODE (type))
3829 case REFERENCE_TYPE:
3830 /* For these types, all that is required is that we output a DIE
3831 (or a set of DIEs) to represent that "basis" type. */
3832 output_type (TREE_TYPE (type), containing_scope);
3836 /* This code is used for C++ pointer-to-data-member types. */
3837 /* Output a description of the relevant class type. */
3838 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
3839 /* Output a description of the type of the object pointed to. */
3840 output_type (TREE_TYPE (type), containing_scope);
3841 /* Now output a DIE to represent this pointer-to-data-member type
3843 output_die (output_ptr_to_mbr_type_die, type);
3847 output_type (TREE_TYPE (type), containing_scope);
3848 output_die (output_set_type_die, type);
3852 output_type (TREE_TYPE (type), containing_scope);
3853 abort (); /* No way to represent these in Dwarf yet! */
3857 output_type (TREE_TYPE (type), containing_scope);
3858 output_die (output_string_type_die, type);
3862 /* Force out return type (in case it wasn't forced out already). */
3863 output_type (TREE_TYPE (type), containing_scope);
3864 output_die (output_subroutine_type_die, type);
3865 output_formal_types (type);
3866 end_sibling_chain ();
3870 /* Force out return type (in case it wasn't forced out already). */
3871 output_type (TREE_TYPE (type), containing_scope);
3872 output_die (output_subroutine_type_die, type);
3873 output_formal_types (type);
3874 end_sibling_chain ();
3879 register tree element_type;
3881 element_type = TREE_TYPE (type);
3882 while (TREE_CODE (element_type) == ARRAY_TYPE)
3883 element_type = TREE_TYPE (element_type);
3885 output_type (element_type, containing_scope);
3886 output_die (output_array_type_die, type);
3894 /* For a non-file-scope tagged type, we can always go ahead and
3895 output a Dwarf description of this type right now, even if
3896 the type in question is still incomplete, because if this
3897 local type *was* ever completed anywhere within its scope,
3898 that complete definition would already have been attached to
3899 this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the
3900 time we reach this point. That's true because of the way the
3901 front-end does its processing of file-scope declarations (of
3902 functions and class types) within which other types might be
3903 nested. The C and C++ front-ends always gobble up such "local
3904 scope" things en-mass before they try to output *any* debugging
3905 information for any of the stuff contained inside them and thus,
3906 we get the benefit here of what is (in effect) a pre-resolution
3907 of forward references to tagged types in local scopes.
3909 Note however that for file-scope tagged types we cannot assume
3910 that such pre-resolution of forward references has taken place.
3911 A given file-scope tagged type may appear to be incomplete when
3912 we reach this point, but it may yet be given a full definition
3913 (at file-scope) later on during compilation. In order to avoid
3914 generating a premature (and possibly incorrect) set of Dwarf
3915 DIEs for such (as yet incomplete) file-scope tagged types, we
3916 generate nothing at all for as-yet incomplete file-scope tagged
3917 types here unless we are making our special "finalization" pass
3918 for file-scope things at the very end of compilation. At that
3919 time, we will certainly know as much about each file-scope tagged
3920 type as we are ever going to know, so at that point in time, we
3921 can safely generate correct Dwarf descriptions for these file-
3925 if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
3926 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
3928 /* Prevent infinite recursion in cases where the type of some
3929 member of this type is expressed in terms of this type itself. */
3931 TREE_ASM_WRITTEN (type) = 1;
3933 /* Output a DIE to represent the tagged type itself. */
3935 switch (TREE_CODE (type))
3938 output_die (output_enumeration_type_die, type);
3939 return; /* a special case -- nothing left to do so just return */
3942 output_die (output_structure_type_die, type);
3946 output_die (output_union_type_die, type);
3950 abort (); /* Should never happen. */
3953 /* If this is not an incomplete type, output descriptions of
3954 each of its members.
3956 Note that as we output the DIEs necessary to represent the
3957 members of this record or union type, we will also be trying
3958 to output DIEs to represent the *types* of those members.
3959 However the `output_type' function (above) will specifically
3960 avoid generating type DIEs for member types *within* the list
3961 of member DIEs for this (containing) type execpt for those
3962 types (of members) which are explicitly marked as also being
3963 members of this (containing) type themselves. The g++ front-
3964 end can force any given type to be treated as a member of some
3965 other (containing) type by setting the TYPE_CONTEXT of the
3966 given (member) type to point to the TREE node representing the
3967 appropriate (containing) type.
3970 if (TYPE_SIZE (type))
3973 register tree normal_member;
3975 /* First output info about the data members and type members. */
3977 for (normal_member = TYPE_FIELDS (type);
3979 normal_member = TREE_CHAIN (normal_member))
3980 output_decl (normal_member, type);
3984 register tree vec_base;
3986 /* Now output info about the function members (if any). */
3988 vec_base = TYPE_METHODS (type);
3991 register tree first_func_member = TREE_VEC_ELT (vec_base, 0);
3992 register tree func_member;
3994 /* This isn't documented, but the first element of the
3995 vector of member functions can be NULL in cases where
3996 the class type in question didn't have either a
3997 constructor or a destructor declared for it. We have
3998 to make allowances for that here. */
4000 if (first_func_member == NULL)
4001 first_func_member = TREE_VEC_ELT (vec_base, 1);
4003 for (func_member = first_func_member;
4005 func_member = TREE_CHAIN (func_member))
4006 output_decl (func_member, type);
4010 /* RECORD_TYPEs and UNION_TYPEs are themselves scopes (at least
4011 in C++) so we must now output any nested pending types which
4012 are local just to this RECORD_TYPE or UNION_TYPE. */
4014 output_pending_types_for_scope (type);
4016 end_sibling_chain (); /* Terminate member chain. */
4027 break; /* No DIEs needed for fundamental types. */
4029 case LANG_TYPE: /* No Dwarf representation currently defined. */
4036 TREE_ASM_WRITTEN (type) = 1;
4040 output_tagged_type_instantiation (type)
4043 if (type == 0 || type == error_mark_node)
4046 /* We are going to output a DIE to represent the unqualified version of
4047 of this type (i.e. without any const or volatile qualifiers) so make
4048 sure that we have the main variant (i.e. the unqualified version) of
4051 assert (type == TYPE_MAIN_VARIANT (type));
4053 assert (TREE_ASM_WRITTEN (type));
4055 switch (TREE_CODE (type))
4061 output_die (output_inlined_enumeration_type_die, type);
4065 output_die (output_inlined_structure_type_die, type);
4069 output_die (output_inlined_union_type_die, type);
4073 abort (); /* Should never happen. */
4077 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
4078 the things which are local to the given block. */
4084 register int must_output_die = 0;
4085 register tree origin;
4086 register enum tree_code origin_code;
4088 /* Ignore blocks never really used to make RTL. */
4090 if (! stmt || ! TREE_USED (stmt))
4093 /* Determine the "ultimate origin" of this block. This block may be an
4094 inlined instance of an inlined instance of inline function, so we
4095 have to trace all of the way back through the origin chain to find
4096 out what sort of node actually served as the original seed for the
4097 creation of the current block. */
4099 origin = block_ultimate_origin (stmt);
4100 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
4102 /* Determine if we need to output any Dwarf DIEs at all to represent this
4105 if (origin_code == FUNCTION_DECL)
4106 /* The outer scopes for inlinings *must* always be represented. We
4107 generate TAG_inlined_subroutine DIEs for them. (See below.) */
4108 must_output_die = 1;
4111 /* In the case where the current block represents an inlining of the
4112 "body block" of an inline function, we must *NOT* output any DIE
4113 for this block because we have already output a DIE to represent
4114 the whole inlined function scope and the "body block" of any
4115 function doesn't really represent a different scope according to
4116 ANSI C rules. So we check here to make sure that this block does
4117 not represent a "body block inlining" before trying to set the
4118 `must_output_die' flag. */
4120 if (origin == NULL || ! is_body_block (origin))
4122 /* Determine if this block directly contains any "significant"
4123 local declarations which we will need to output DIEs for. */
4125 if (debug_info_level > DINFO_LEVEL_TERSE)
4126 /* We are not in terse mode so *any* local declaration counts
4127 as being a "significant" one. */
4128 must_output_die = (BLOCK_VARS (stmt) != NULL);
4133 /* We are in terse mode, so only local (nested) function
4134 definitions count as "significant" local declarations. */
4136 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4137 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
4139 must_output_die = 1;
4146 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
4147 DIE for any block which contains no significant local declarations
4148 at all. Rather, in such cases we just call `output_decls_for_scope'
4149 so that any needed Dwarf info for any sub-blocks will get properly
4150 generated. Note that in terse mode, our definition of what constitutes
4151 a "significant" local declaration gets restricted to include only
4152 inlined function instances and local (nested) function definitions. */
4154 if (must_output_die)
4156 output_die ((origin_code == FUNCTION_DECL)
4157 ? output_inlined_subroutine_die
4158 : output_lexical_block_die,
4160 output_decls_for_scope (stmt);
4161 end_sibling_chain ();
4164 output_decls_for_scope (stmt);
4167 /* Output all of the decls declared within a given scope (also called
4168 a `binding contour') and (recursively) all of it's sub-blocks. */
4171 output_decls_for_scope (stmt)
4174 /* Ignore blocks never really used to make RTL. */
4176 if (! stmt || ! TREE_USED (stmt))
4179 if (! BLOCK_ABSTRACT (stmt))
4180 next_block_number++;
4182 /* Output the DIEs to represent all of the data objects, functions,
4183 typedefs, and tagged types declared directly within this block
4184 but not within any nested sub-blocks. */
4189 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
4190 output_decl (decl, stmt);
4193 output_pending_types_for_scope (stmt);
4195 /* Output the DIEs to represent all sub-blocks (and the items declared
4196 therein) of this block. */
4199 register tree subblocks;
4201 for (subblocks = BLOCK_SUBBLOCKS (stmt);
4203 subblocks = BLOCK_CHAIN (subblocks))
4204 output_block (subblocks);
4208 /* Output Dwarf .debug information for a decl described by DECL. */
4211 output_decl (decl, containing_scope)
4213 register tree containing_scope;
4215 if (TREE_CODE (decl) == ERROR_MARK)
4218 /* If this ..._DECL node is marked to be ignored, then ignore it.
4219 But don't ignore a function definition, since that would screw
4220 up our count of blocks, and that it turn will completely screw up the
4221 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4222 attributes (for subsequent blocks). */
4224 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
4227 switch (TREE_CODE (decl))
4230 /* The individual enumerators of an enum type get output when we
4231 output the Dwarf representation of the relevant enum type itself. */
4235 /* If we are in terse mode, don't output any DIEs to represent
4236 mere external function declarations. Also, if we are conforming
4237 to the DWARF version 1 specification, don't output DIEs for
4238 mere external function declarations. */
4240 if (DECL_EXTERNAL (decl))
4241 #if (DWARF_VERSION > 1)
4242 if (debug_info_level <= DINFO_LEVEL_TERSE)
4246 /* Before we describe the FUNCTION_DECL itself, make sure that we
4247 have described its return type. */
4249 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
4251 /* If the following DIE will represent a function definition for a
4252 function with "extern" linkage, output a special "pubnames" DIE
4253 label just ahead of the actual DIE. A reference to this label
4254 was already generated in the .debug_pubnames section sub-entry
4255 for this function definition. */
4257 if (TREE_PUBLIC (decl))
4259 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4261 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4262 ASM_OUTPUT_LABEL (asm_out_file, label);
4265 /* Now output a DIE to represent the function itself. */
4267 output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
4268 ? output_global_subroutine_die
4269 : output_local_subroutine_die,
4272 /* Now output descriptions of the arguments for this function.
4273 This gets (unnecessarily?) complex because of the fact that
4274 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
4275 cases where there was a trailing `...' at the end of the formal
4276 parameter list. In order to find out if there was a trailing
4277 ellipsis or not, we must instead look at the type associated
4278 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
4279 If the chain of type nodes hanging off of this FUNCTION_TYPE node
4280 ends with a void_type_node then there should *not* be an ellipsis
4283 /* In the case where we are describing an external function, all
4284 we need to do here (and all we *can* do here) is to describe
4285 the *types* of its formal parameters. */
4287 if (DECL_EXTERNAL (decl))
4288 output_formal_types (TREE_TYPE (decl));
4291 register tree arg_decls = DECL_ARGUMENTS (decl);
4294 register tree last_arg;
4296 last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK)
4297 ? tree_last (arg_decls)
4300 /* Generate DIEs to represent all known formal parameters, but
4301 don't do it if this looks like a varargs function. A given
4302 function is considered to be a varargs function if (and only
4303 if) its last named argument is named `__builtin_va_alist'. */
4306 || ! DECL_NAME (last_arg)
4307 || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)),
4308 "__builtin_va_alist"))
4312 /* WARNING! Kludge zone ahead! Here we have a special
4313 hack for svr4 SDB compatibility. Instead of passing the
4314 current FUNCTION_DECL node as the second parameter (i.e.
4315 the `containing_scope' parameter) to `output_decl' (as
4316 we ought to) we instead pass a pointer to our own private
4317 fake_containing_scope node. That node is a RECORD_TYPE
4318 node which NO OTHER TYPE may ever actually be a member of.
4320 This pointer will ultimately get passed into `output_type'
4321 as its `containing_scope' parameter. `Output_type' will
4322 then perform its part in the hack... i.e. it will pend
4323 the type of the formal parameter onto the pending_types
4324 list. Later on, when we are done generating the whole
4325 sequence of formal parameter DIEs for this function
4326 definition, we will un-pend all previously pended types
4327 of formal parameters for this function definition.
4329 This whole kludge prevents any type DIEs from being
4330 mixed in with the formal parameter DIEs. That's good
4331 because svr4 SDB believes that the list of formal
4332 parameter DIEs for a function ends wherever the first
4333 non-formal-parameter DIE appears. Thus, we have to
4334 keep the formal parameter DIEs segregated. They must
4335 all appear (consecutively) at the start of the list of
4336 children for the DIE representing the function definition.
4337 Then (and only then) may we output any additional DIEs
4338 needed to represent the types of these formal parameters.
4341 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4342 if (TREE_CODE (parm) == PARM_DECL)
4343 output_decl (parm, fake_containing_scope);
4345 /* Now that we have finished generating all of the DIEs to
4346 represent the formal parameters themselves, force out
4347 any DIEs needed to represent their types. We do this
4348 simply by un-pending all previously pended types which
4349 can legitimately go into the chain of children DIEs for
4350 the current FUNCTION_DECL. */
4352 output_pending_types_for_scope (decl);
4356 /* Now try to decide if we should put an ellipsis at the end. */
4359 register int has_ellipsis = TRUE; /* default assumption */
4360 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4364 /* This function declaration/definition was prototyped. */
4366 /* If the list of formal argument types ends with a
4367 void_type_node, then the formals list did *not* end
4368 with an ellipsis. */
4370 if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
4371 has_ellipsis = FALSE;
4375 /* This function declaration/definition was not prototyped. */
4377 /* Note that all non-prototyped function *declarations* are
4378 assumed to represent varargs functions (until proven
4381 if (DECL_INITIAL (decl)) /* if this is a func definition */
4384 has_ellipsis = FALSE; /* no args == (void) */
4387 /* For a non-prototyped function definition which
4388 declares one or more formal parameters, if the name
4389 of the first formal parameter is *not*
4390 __builtin_va_alist then we must assume that this
4391 is *not* a varargs function. */
4393 if (DECL_NAME (arg_decls)
4394 && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
4395 "__builtin_va_alist"))
4396 has_ellipsis = FALSE;
4402 output_die (output_unspecified_parameters_die, decl);
4406 /* Output Dwarf info for all of the stuff within the body of the
4407 function (if it has one - it may be just a declaration). */
4410 register tree outer_scope = DECL_INITIAL (decl);
4412 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4414 /* Note that here, `outer_scope' is a pointer to the outermost
4415 BLOCK node created to represent a function.
4416 This outermost BLOCK actually represents the outermost
4417 binding contour for the function, i.e. the contour in which
4418 the function's formal parameters and labels get declared.
4420 Curiously, it appears that the front end doesn't actually
4421 put the PARM_DECL nodes for the current function onto the
4422 BLOCK_VARS list for this outer scope. (They are strung
4423 off of the DECL_ARGUMENTS list for the function instead.)
4424 The BLOCK_VARS list for the `outer_scope' does provide us
4425 with a list of the LABEL_DECL nodes for the function however,
4426 and we output DWARF info for those here.
4428 Just within the `outer_scope' there will be another BLOCK
4429 node representing the function's outermost pair of curly
4430 braces. We musn't generate a lexical_block DIE for this
4431 outermost pair of curly braces because that is not really an
4432 independent scope according to ANSI C rules. Rather, it is
4433 the same scope in which the parameters were declared. */
4436 register tree label;
4438 for (label = BLOCK_VARS (outer_scope);
4440 label = TREE_CHAIN (label))
4441 output_decl (label, outer_scope);
4444 /* Note here that `BLOCK_SUBBLOCKS (outer_scope)' points to a
4445 list of BLOCK nodes which is always only one element long.
4446 That one element represents the outermost pair of curley
4447 braces for the function body. */
4449 output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
4451 /* Finally, force out any pending types which are local to the
4452 outermost block of this function definition. These will
4453 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4456 output_pending_types_for_scope (decl);
4460 /* Generate a terminator for the list of stuff `owned' by this
4463 end_sibling_chain ();
4468 /* If we are in terse mode, don't generate any DIEs to represent
4469 any actual typedefs. Note that even when we are in terse mode,
4470 we must still output DIEs to represent those tagged types which
4471 are used (directly or indirectly) in the specification of either
4472 a return type or a formal parameter type of some function. */
4474 if (debug_info_level <= DINFO_LEVEL_TERSE)
4475 if (DECL_NAME (decl) != NULL
4476 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4479 /* In the special case of a null-named TYPE_DECL node (representing
4480 the declaration of some type tag), if the given TYPE_DECL is
4481 marked as having been instantiated from some other (original)
4482 TYPE_DECL node (e.g. one which was generated within the original
4483 definition of an inline function) we have to generate a special
4484 (abbreviated) TAG_structure_type, TAG_union_type, or
4485 TAG_enumeration-type DIE here. */
4487 if (! DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
4489 output_tagged_type_instantiation (TREE_TYPE (decl));
4493 output_type (TREE_TYPE (decl), containing_scope);
4495 /* Note that unlike the gcc front end (which generates a NULL named
4496 TYPE_DECL node for each complete tagged type, each array type,
4497 and each function type node created) the g++ front end generates
4498 a *named* TYPE_DECL node for each tagged type node created.
4499 Unfortunately, these g++ TYPE_DECL nodes cause us to output many
4500 superfluous and unnecessary TAG_typedef DIEs here. When g++ is
4501 fixed to stop generating these superfluous named TYPE_DECL nodes,
4502 the superfluous TAG_typedef DIEs will likewise cease. */
4504 if (DECL_NAME (decl))
4505 /* Output a DIE to represent the typedef itself. */
4506 output_die (output_typedef_die, decl);
4510 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4511 output_die (output_label_die, decl);
4515 /* If we are conforming to the DWARF version 1 specification, don't
4516 generated any DIEs to represent mere external object declarations. */
4518 #if (DWARF_VERSION <= 1)
4519 if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4523 /* If we are in terse mode, don't generate any DIEs to represent
4524 any variable declarations or definitions. */
4526 if (debug_info_level <= DINFO_LEVEL_TERSE)
4529 /* Output any DIEs that are needed to specify the type of this data
4532 output_type (TREE_TYPE (decl), containing_scope);
4534 /* If the following DIE will represent a data object definition for a
4535 data object with "extern" linkage, output a special "pubnames" DIE
4536 label just ahead of the actual DIE. A reference to this label
4537 was already generated in the .debug_pubnames section sub-entry
4538 for this data object definition. */
4540 if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
4542 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4544 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4545 ASM_OUTPUT_LABEL (asm_out_file, label);
4548 /* Now output the DIE to represent the data object itself. This gets
4549 complicated because of the possibility that the VAR_DECL really
4550 represents an inlined instance of a formal parameter for an inline
4554 register void (*func) ();
4555 register tree origin = decl_ultimate_origin (decl);
4557 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
4558 func = output_formal_parameter_die;
4561 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
4562 func = output_global_variable_die;
4564 func = output_local_variable_die;
4566 output_die (func, decl);
4571 /* Ignore the nameless fields that are used to skip bits. */
4572 if (DECL_NAME (decl) != 0)
4574 output_type (member_declared_type (decl), containing_scope);
4575 output_die (output_member_die, decl);
4580 /* Force out the type of this formal, if it was not forced out yet.
4581 Note that here we can run afowl of a bug in "classic" svr4 SDB.
4582 It should be able to grok the presence of type DIEs within a list
4583 of TAG_formal_parameter DIEs, but it doesn't. */
4585 output_type (TREE_TYPE (decl), containing_scope);
4586 output_die (output_formal_parameter_die, decl);
4595 dwarfout_file_scope_decl (decl, set_finalizing)
4597 register int set_finalizing;
4599 if (TREE_CODE (decl) == ERROR_MARK)
4602 /* If this ..._DECL node is marked to be ignored, then ignore it. We
4603 gotta hope that the node in question doesn't represent a function
4604 definition. If it does, then totally ignoring it is bound to screw
4605 up our count of blocks, and that it turn will completely screw up the
4606 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4607 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
4608 don't carry their own sequence numbers with them!) */
4610 if (DECL_IGNORED_P (decl))
4612 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4617 switch (TREE_CODE (decl))
4621 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
4622 a builtin function. Explicit programmer-supplied declarations of
4623 these same functions should NOT be ignored however. */
4625 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
4628 /* Ignore this FUNCTION_DECL if it refers to a file-scope extern
4629 function declaration and if the declaration was never even
4630 referenced from within this entire compilation unit. We
4631 suppress these DIEs in order to save space in the .debug section
4632 (by eliminating entries which are probably useless). Note that
4633 we must not suppress block-local extern declarations (whether
4634 used or not) because that would screw-up the debugger's name
4635 lookup mechanism and cause it to miss things which really ought
4636 to be in scope at a given point. */
4638 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
4641 if (TREE_PUBLIC (decl)
4642 && ! DECL_EXTERNAL (decl)
4643 && ! DECL_ABSTRACT (decl))
4645 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4647 /* Output a .debug_pubnames entry for a public function
4648 defined in this compilation unit. */
4650 fputc ('\n', asm_out_file);
4651 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4652 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4653 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4654 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4655 IDENTIFIER_POINTER (DECL_NAME (decl)));
4656 ASM_OUTPUT_POP_SECTION (asm_out_file);
4663 /* Ignore this VAR_DECL if it refers to a file-scope extern data
4664 object declaration and if the declaration was never even
4665 referenced from within this entire compilation unit. We
4666 suppress these DIEs in order to save space in the .debug section
4667 (by eliminating entries which are probably useless). Note that
4668 we must not suppress block-local extern declarations (whether
4669 used or not) because that would screw-up the debugger's name
4670 lookup mechanism and cause it to miss things which really ought
4671 to be in scope at a given point. */
4673 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
4676 if (TREE_PUBLIC (decl)
4677 && ! DECL_EXTERNAL (decl)
4678 && GET_CODE (DECL_RTL (decl)) == MEM
4679 && ! DECL_ABSTRACT (decl))
4681 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4683 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4685 /* Output a .debug_pubnames entry for a public variable
4686 defined in this compilation unit. */
4688 fputc ('\n', asm_out_file);
4689 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4690 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4691 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4692 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4693 IDENTIFIER_POINTER (DECL_NAME (decl)));
4694 ASM_OUTPUT_POP_SECTION (asm_out_file);
4697 if (DECL_INITIAL (decl) == NULL)
4699 /* Output a .debug_aranges entry for a public variable
4700 which is tentatively defined in this compilation unit. */
4702 fputc ('\n', asm_out_file);
4703 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4704 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
4705 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4706 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4707 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
4708 ASM_OUTPUT_POP_SECTION (asm_out_file);
4712 /* If we are in terse mode, don't generate any DIEs to represent
4713 any variable declarations or definitions. */
4715 if (debug_info_level <= DINFO_LEVEL_TERSE)
4721 /* Don't generate any DIEs to represent the standard built-in types. */
4723 if (DECL_SOURCE_LINE (decl) == 0)
4726 /* If we are in terse mode, don't generate any DIEs to represent
4727 any actual typedefs. Note that even when we are in terse mode,
4728 we must still output DIEs to represent those tagged types which
4729 are used (directly or indirectly) in the specification of either
4730 a return type or a formal parameter type of some function. */
4732 if (debug_info_level <= DINFO_LEVEL_TERSE)
4733 if (DECL_NAME (decl) != NULL
4734 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4743 fputc ('\n', asm_out_file);
4744 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4745 finalizing = set_finalizing;
4746 output_decl (decl, NULL_TREE);
4748 /* NOTE: The call above to `output_decl' may have caused one or more
4749 file-scope named types (i.e. tagged types) to be placed onto the
4750 pending_types_list. We have to get those types off of that list
4751 at some point, and this is the perfect time to do it. If we didn't
4752 take them off now, they might still be on the list when cc1 finally
4753 exits. That might be OK if it weren't for the fact that when we put
4754 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
4755 for these types, and that causes them never to be output unless
4756 `output_pending_types_for_scope' takes them off of the list and un-sets
4757 their TREE_ASM_WRITTEN flags. */
4759 output_pending_types_for_scope (NULL_TREE);
4761 /* The above call should have totally emptied the pending_types_list. */
4763 assert (pending_types == 0);
4765 ASM_OUTPUT_POP_SECTION (asm_out_file);
4767 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4768 current_funcdef_number++;
4771 /* Output a marker (i.e. a label) for the beginning of the generated code
4772 for a lexical block. */
4775 dwarfout_begin_block (blocknum)
4776 register unsigned blocknum;
4778 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4781 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
4782 ASM_OUTPUT_LABEL (asm_out_file, label);
4785 /* Output a marker (i.e. a label) for the end of the generated code
4786 for a lexical block. */
4789 dwarfout_end_block (blocknum)
4790 register unsigned blocknum;
4792 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4795 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
4796 ASM_OUTPUT_LABEL (asm_out_file, label);
4799 /* Output a marker (i.e. a label) at a point in the assembly code which
4800 corresponds to a given source level label. */
4803 dwarfout_label (insn)
4806 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4808 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4811 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
4812 (unsigned) INSN_UID (insn));
4813 ASM_OUTPUT_LABEL (asm_out_file, label);
4817 /* Output a marker (i.e. a label) for the absolute end of the generated code
4818 for a function definition. This gets called *after* the epilogue code
4819 has been generated. */
4822 dwarfout_end_epilogue ()
4824 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4826 /* Output a label to mark the endpoint of the code generated for this
4829 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4830 ASM_OUTPUT_LABEL (asm_out_file, label);
4834 shuffle_filename_entry (new_zeroth)
4835 register filename_entry *new_zeroth;
4837 filename_entry temp_entry;
4838 register filename_entry *limit_p;
4839 register filename_entry *move_p;
4841 if (new_zeroth == &filename_table[0])
4844 temp_entry = *new_zeroth;
4846 /* Shift entries up in the table to make room at [0]. */
4848 limit_p = &filename_table[0];
4849 for (move_p = new_zeroth; move_p > limit_p; move_p--)
4850 *move_p = *(move_p-1);
4852 /* Install the found entry at [0]. */
4854 filename_table[0] = temp_entry;
4857 /* Create a new (string) entry for the .debug_sfnames section. */
4860 generate_new_sfname_entry ()
4862 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4864 fputc ('\n', asm_out_file);
4865 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
4866 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
4867 ASM_OUTPUT_LABEL (asm_out_file, label);
4868 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4869 filename_table[0].name
4870 ? filename_table[0].name
4872 ASM_OUTPUT_POP_SECTION (asm_out_file);
4875 /* Lookup a filename (in the list of filenames that we know about here in
4876 dwarfout.c) and return its "index". The index of each (known) filename
4877 is just a unique number which is associated with only that one filename.
4878 We need such numbers for the sake of generating labels (in the
4879 .debug_sfnames section) and references to those unique labels (in the
4880 .debug_srcinfo and .debug_macinfo sections).
4882 If the filename given as an argument is not found in our current list,
4883 add it to the list and assign it the next available unique index number.
4885 Whatever we do (i.e. whether we find a pre-existing filename or add a new
4886 one), we shuffle the filename found (or added) up to the zeroth entry of
4887 our list of filenames (which is always searched linearly). We do this so
4888 as to optimize the most common case for these filename lookups within
4889 dwarfout.c. The most common case by far is the case where we call
4890 lookup_filename to lookup the very same filename that we did a lookup
4891 on the last time we called lookup_filename. We make sure that this
4892 common case is fast because such cases will constitute 99.9% of the
4893 lookups we ever do (in practice).
4895 If we add a new filename entry to our table, we go ahead and generate
4896 the corresponding entry in the .debug_sfnames section right away.
4897 Doing so allows us to avoid tickling an assembler bug (present in some
4898 m68k assemblers) which yields assembly-time errors in cases where the
4899 difference of two label addresses is taken and where the two labels
4900 are in a section *other* than the one where the difference is being
4901 calculated, and where at least one of the two symbol references is a
4902 forward reference. (This bug could be tickled by our .debug_srcinfo
4903 entries if we don't output their corresponding .debug_sfnames entries
4908 lookup_filename (file_name)
4911 register filename_entry *search_p;
4912 register filename_entry *limit_p = &filename_table[ft_entries];
4914 for (search_p = filename_table; search_p < limit_p; search_p++)
4915 if (!strcmp (file_name, search_p->name))
4917 /* When we get here, we have found the filename that we were
4918 looking for in the filename_table. Now we want to make sure
4919 that it gets moved to the zero'th entry in the table (if it
4920 is not already there) so that subsequent attempts to find the
4921 same filename will find it as quickly as possible. */
4923 shuffle_filename_entry (search_p);
4924 return filename_table[0].number;
4927 /* We come here whenever we have a new filename which is not registered
4928 in the current table. Here we add it to the table. */
4930 /* Prepare to add a new table entry by making sure there is enough space
4931 in the table to do so. If not, expand the current table. */
4933 if (ft_entries == ft_entries_allocated)
4935 ft_entries_allocated += FT_ENTRIES_INCREMENT;
4937 = (filename_entry *)
4938 xrealloc (filename_table,
4939 ft_entries_allocated * sizeof (filename_entry));
4942 /* Initially, add the new entry at the end of the filename table. */
4944 filename_table[ft_entries].number = ft_entries;
4945 filename_table[ft_entries].name = xstrdup (file_name);
4947 /* Shuffle the new entry into filename_table[0]. */
4949 shuffle_filename_entry (&filename_table[ft_entries]);
4951 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4952 generate_new_sfname_entry ();
4955 return filename_table[0].number;
4959 generate_srcinfo_entry (line_entry_num, files_entry_num)
4960 unsigned line_entry_num;
4961 unsigned files_entry_num;
4963 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4965 fputc ('\n', asm_out_file);
4966 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4967 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
4968 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
4969 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
4970 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
4971 ASM_OUTPUT_POP_SECTION (asm_out_file);
4975 dwarfout_line (filename, line)
4976 register char *filename;
4977 register unsigned line;
4979 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4981 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4982 static unsigned last_line_entry_num = 0;
4983 static unsigned prev_file_entry_num = (unsigned) -1;
4984 register unsigned this_file_entry_num = lookup_filename (filename);
4987 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
4988 ASM_OUTPUT_LABEL (asm_out_file, label);
4990 fputc ('\n', asm_out_file);
4991 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4993 if (this_file_entry_num != prev_file_entry_num)
4995 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
4997 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
4998 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
5002 register char *tail = rindex (filename, '/');
5008 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
5009 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
5011 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5012 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
5013 ASM_OUTPUT_POP_SECTION (asm_out_file);
5015 if (this_file_entry_num != prev_file_entry_num)
5016 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
5017 prev_file_entry_num = this_file_entry_num;
5021 /* Generate an entry in the .debug_macinfo section. */
5024 generate_macinfo_entry (type_and_offset, string)
5025 register char *type_and_offset;
5026 register char *string;
5028 fputc ('\n', asm_out_file);
5029 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5030 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
5031 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
5032 ASM_OUTPUT_POP_SECTION (asm_out_file);
5036 dwarfout_start_new_source_file (filename)
5037 register char *filename;
5039 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5040 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
5042 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
5043 sprintf (type_and_offset, "0x%08x+%s-%s",
5044 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
5045 generate_macinfo_entry (type_and_offset, "");
5049 dwarfout_resume_previous_source_file (lineno)
5050 register unsigned lineno;
5052 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5054 sprintf (type_and_offset, "0x%08x+%u",
5055 ((unsigned) MACINFO_resume << 24), lineno);
5056 generate_macinfo_entry (type_and_offset, "");
5059 /* Called from check_newline in c-parse.y. The `buffer' parameter
5060 contains the tail part of the directive line, i.e. the part which
5061 is past the initial whitespace, #, whitespace, directive-name,
5065 dwarfout_define (lineno, buffer)
5066 register unsigned lineno;
5067 register char *buffer;
5069 static int initialized = 0;
5070 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5074 dwarfout_start_new_source_file (primary_filename);
5077 sprintf (type_and_offset, "0x%08x+%u",
5078 ((unsigned) MACINFO_define << 24), lineno);
5079 generate_macinfo_entry (type_and_offset, buffer);
5082 /* Called from check_newline in c-parse.y. The `buffer' parameter
5083 contains the tail part of the directive line, i.e. the part which
5084 is past the initial whitespace, #, whitespace, directive-name,
5088 dwarfout_undef (lineno, buffer)
5089 register unsigned lineno;
5090 register char *buffer;
5092 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
5094 sprintf (type_and_offset, "0x%08x+%u",
5095 ((unsigned) MACINFO_undef << 24), lineno);
5096 generate_macinfo_entry (type_and_offset, buffer);
5099 /* Set up for Dwarf output at the start of compilation. */
5102 dwarfout_init (asm_out_file, main_input_filename)
5103 register FILE *asm_out_file;
5104 register char *main_input_filename;
5106 /* Remember the name of the primary input file. */
5108 primary_filename = main_input_filename;
5110 /* Allocate the initial hunk of the pending_sibling_stack. */
5112 pending_sibling_stack
5114 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
5115 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
5116 pending_siblings = 1;
5118 /* Allocate the initial hunk of the filename_table. */
5121 = (filename_entry *)
5122 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
5123 ft_entries_allocated = FT_ENTRIES_INCREMENT;
5126 /* Allocate the initial hunk of the pending_types_list. */
5129 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
5130 pending_types_allocated = PENDING_TYPES_INCREMENT;
5133 /* Create an artificial RECORD_TYPE node which we can use in our hack
5134 to get the DIEs representing types of formal parameters to come out
5135 only *after* the DIEs for the formal parameters themselves. */
5137 fake_containing_scope = make_node (RECORD_TYPE);
5139 /* Output a starting label for the .text section. */
5141 fputc ('\n', asm_out_file);
5142 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5143 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
5144 ASM_OUTPUT_POP_SECTION (asm_out_file);
5146 /* Output a starting label for the .data section. */
5148 fputc ('\n', asm_out_file);
5149 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5150 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
5151 ASM_OUTPUT_POP_SECTION (asm_out_file);
5153 /* Output a starting label for the .data1 section. */
5155 fputc ('\n', asm_out_file);
5156 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5157 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
5158 ASM_OUTPUT_POP_SECTION (asm_out_file);
5160 /* Output a starting label for the .rodata section. */
5162 fputc ('\n', asm_out_file);
5163 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5164 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
5165 ASM_OUTPUT_POP_SECTION (asm_out_file);
5167 /* Output a starting label for the .rodata1 section. */
5169 fputc ('\n', asm_out_file);
5170 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5171 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
5172 ASM_OUTPUT_POP_SECTION (asm_out_file);
5174 /* Output a starting label for the .bss section. */
5176 fputc ('\n', asm_out_file);
5177 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5178 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
5179 ASM_OUTPUT_POP_SECTION (asm_out_file);
5181 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5183 /* Output a starting label and an initial (compilation directory)
5184 entry for the .debug_sfnames section. The starting label will be
5185 referenced by the initial entry in the .debug_srcinfo section. */
5187 fputc ('\n', asm_out_file);
5188 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
5189 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
5191 register char *pwd = getpwd ();
5192 register unsigned len = strlen (pwd);
5193 register char *dirname = (char *) xmalloc (len + 2);
5195 strcpy (dirname, pwd);
5196 strcpy (dirname + len, "/");
5197 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
5200 ASM_OUTPUT_POP_SECTION (asm_out_file);
5202 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5204 /* Output a starting label for the .debug_macinfo section. This
5205 label will be referenced by the AT_mac_info attribute in the
5206 TAG_compile_unit DIE. */
5208 fputc ('\n', asm_out_file);
5209 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5210 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
5211 ASM_OUTPUT_POP_SECTION (asm_out_file);
5214 /* Generate the initial entry for the .line section. */
5216 fputc ('\n', asm_out_file);
5217 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5218 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
5219 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
5220 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5221 ASM_OUTPUT_POP_SECTION (asm_out_file);
5223 /* Generate the initial entry for the .debug_srcinfo section. */
5225 fputc ('\n', asm_out_file);
5226 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5227 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
5228 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
5229 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
5230 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5231 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
5232 #ifdef DWARF_TIMESTAMPS
5233 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
5235 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5237 ASM_OUTPUT_POP_SECTION (asm_out_file);
5239 /* Generate the initial entry for the .debug_pubnames section. */
5241 fputc ('\n', asm_out_file);
5242 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5243 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5244 ASM_OUTPUT_POP_SECTION (asm_out_file);
5246 /* Generate the initial entry for the .debug_aranges section. */
5248 fputc ('\n', asm_out_file);
5249 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5250 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
5251 ASM_OUTPUT_POP_SECTION (asm_out_file);
5254 /* Setup first DIE number == 1. */
5255 NEXT_DIE_NUM = next_unused_dienum++;
5257 /* Generate the initial DIE for the .debug section. Note that the
5258 (string) value given in the AT_name attribute of the TAG_compile_unit
5259 DIE will (typically) be a relative pathname and that this pathname
5260 should be taken as being relative to the directory from which the
5261 compiler was invoked when the given (base) source file was compiled. */
5263 fputc ('\n', asm_out_file);
5264 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5265 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
5266 output_die (output_compile_unit_die, main_input_filename);
5267 ASM_OUTPUT_POP_SECTION (asm_out_file);
5269 fputc ('\n', asm_out_file);
5272 /* Output stuff that dwarf requires at the end of every file. */
5277 char label[MAX_ARTIFICIAL_LABEL_BYTES];
5279 fputc ('\n', asm_out_file);
5280 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
5282 /* Mark the end of the chain of siblings which represent all file-scope
5283 declarations in this compilation unit. */
5285 /* The (null) DIE which represents the terminator for the (sibling linked)
5286 list of file-scope items is *special*. Normally, we would just call
5287 end_sibling_chain at this point in order to output a word with the
5288 value `4' and that word would act as the terminator for the list of
5289 DIEs describing file-scope items. Unfortunately, if we were to simply
5290 do that, the label that would follow this DIE in the .debug section
5291 (i.e. `..D2') would *not* be properly aligned (as it must be on some
5292 machines) to a 4 byte boundary.
5294 In order to force the label `..D2' to get aligned to a 4 byte boundary,
5295 the trick used is to insert extra (otherwise useless) padding bytes
5296 into the (null) DIE that we know must precede the ..D2 label in the
5297 .debug section. The amount of padding required can be anywhere between
5298 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
5299 with the padding) would normally contain the value 4, but now it will
5300 also have to include the padding bytes, so it will instead have some
5301 value in the range 4..7.
5303 Fortunately, the rules of Dwarf say that any DIE whose length word
5304 contains *any* value less than 8 should be treated as a null DIE, so
5305 this trick works out nicely. Clever, eh? Don't give me any credit
5306 (or blame). I didn't think of this scheme. I just conformed to it.
5309 output_die (output_padded_null_die, (void *)0);
5312 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
5313 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
5314 ASM_OUTPUT_POP_SECTION (asm_out_file);
5316 /* Output a terminator label for the .text section. */
5318 fputc ('\n', asm_out_file);
5319 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
5320 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
5321 ASM_OUTPUT_POP_SECTION (asm_out_file);
5323 /* Output a terminator label for the .data section. */
5325 fputc ('\n', asm_out_file);
5326 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
5327 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
5328 ASM_OUTPUT_POP_SECTION (asm_out_file);
5330 /* Output a terminator label for the .data1 section. */
5332 fputc ('\n', asm_out_file);
5333 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
5334 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
5335 ASM_OUTPUT_POP_SECTION (asm_out_file);
5337 /* Output a terminator label for the .rodata section. */
5339 fputc ('\n', asm_out_file);
5340 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5341 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5342 ASM_OUTPUT_POP_SECTION (asm_out_file);
5344 /* Output a terminator label for the .rodata1 section. */
5346 fputc ('\n', asm_out_file);
5347 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5348 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5349 ASM_OUTPUT_POP_SECTION (asm_out_file);
5351 /* Output a terminator label for the .bss section. */
5353 fputc ('\n', asm_out_file);
5354 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5355 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5356 ASM_OUTPUT_POP_SECTION (asm_out_file);
5358 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5360 /* Output a terminating entry for the .line section. */
5362 fputc ('\n', asm_out_file);
5363 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5364 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5365 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5366 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5367 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5368 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5369 ASM_OUTPUT_POP_SECTION (asm_out_file);
5371 /* Output a terminating entry for the .debug_srcinfo section. */
5373 fputc ('\n', asm_out_file);
5374 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5375 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5376 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5377 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5378 ASM_OUTPUT_POP_SECTION (asm_out_file);
5380 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5382 /* Output terminating entries for the .debug_macinfo section. */
5384 dwarfout_resume_previous_source_file (0);
5386 fputc ('\n', asm_out_file);
5387 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5388 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5389 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5390 ASM_OUTPUT_POP_SECTION (asm_out_file);
5393 /* Generate the terminating entry for the .debug_pubnames section. */
5395 fputc ('\n', asm_out_file);
5396 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5397 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5398 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5399 ASM_OUTPUT_POP_SECTION (asm_out_file);
5401 /* Generate the terminating entries for the .debug_aranges section.
5403 Note that we want to do this only *after* we have output the end
5404 labels (for the various program sections) which we are going to
5405 refer to here. This allows us to work around a bug in the m68k
5406 svr4 assembler. That assembler gives bogus assembly-time errors
5407 if (within any given section) you try to take the difference of
5408 two relocatable symbols, both of which are located within some
5409 other section, and if one (or both?) of the symbols involved is
5410 being forward-referenced. By generating the .debug_aranges
5411 entries at this late point in the assembly output, we skirt the
5412 issue simply by avoiding forward-references.
5415 fputc ('\n', asm_out_file);
5416 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5418 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5419 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5421 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5422 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5424 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5425 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5428 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5429 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5430 RODATA_BEGIN_LABEL);
5432 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5433 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5434 RODATA1_BEGIN_LABEL);
5436 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5437 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5439 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5440 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5442 ASM_OUTPUT_POP_SECTION (asm_out_file);
5446 #endif /* DWARF_DEBUGGING_INFO */