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, when given a pointer to some BLOCK node, returns
84 a pointer to the FUNCTION_DECL node from which the given BLOCK node
85 was instantiated (as an inline expansion). This macro needs to be
86 defined properly in tree.h, however for the moment, we just fake it. */
88 #define BLOCK_INLINE_FUNCTION(block) 0
90 /* Define a macro which returns non-zero for any tagged type which is
91 used (directly or indirectly) in the specification of either some
92 function's return type or some formal parameter of some function.
93 We use this macro when we are operating in "terse" mode to help us
94 know what tagged types have to be represented in Dwarf (even in
95 terse mode) and which ones don't.
97 A flag bit with this meaning really should be a part of the normal
98 GCC ..._TYPE nodes, but at the moment, there is no such bit defined
99 for these nodes. For now, we have to just fake it. It it safe for
100 us to simply return zero for all complete tagged types (which will
101 get forced out anyway if they were used in the specification of some
102 formal or return type) and non-zero for all incomplete tagged types.
105 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
107 extern int flag_traditional;
108 extern char *version_string;
109 extern char *language_string;
111 /* Maximum size (in bytes) of an artificially generated label. */
113 #define MAX_ARTIFICIAL_LABEL_BYTES 30
115 /* Make sure we know the sizes of the various types dwarf can describe.
116 These are only defaults. If the sizes are different for your target,
117 you should override these values by defining the appropriate symbols
118 in your tm.h file. */
120 #ifndef CHAR_TYPE_SIZE
121 #define CHAR_TYPE_SIZE BITS_PER_UNIT
124 #ifndef SHORT_TYPE_SIZE
125 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
128 #ifndef INT_TYPE_SIZE
129 #define INT_TYPE_SIZE BITS_PER_WORD
132 #ifndef LONG_TYPE_SIZE
133 #define LONG_TYPE_SIZE BITS_PER_WORD
136 #ifndef LONG_LONG_TYPE_SIZE
137 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
140 #ifndef WCHAR_TYPE_SIZE
141 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
144 #ifndef WCHAR_UNSIGNED
145 #define WCHAR_UNSIGNED 0
148 #ifndef FLOAT_TYPE_SIZE
149 #define FLOAT_TYPE_SIZE BITS_PER_WORD
152 #ifndef DOUBLE_TYPE_SIZE
153 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
156 #ifndef LONG_DOUBLE_TYPE_SIZE
157 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
160 /* Structure to keep track of source filenames. */
162 struct filename_entry {
167 typedef struct filename_entry filename_entry;
169 /* Pointer to an array of elements, each one having the structure above. */
171 static filename_entry *filename_table;
173 /* Total number of entries in the table (i.e. array) pointed to by
174 `filename_table'. This is the *total* and includes both used and
177 static unsigned ft_entries_allocated;
179 /* Number of entries in the filename_table which are actually in use. */
181 static unsigned ft_entries;
183 /* Size (in elements) of increments by which we may expand the filename
184 table. Actually, a single hunk of space of this size should be enough
185 for most typical programs. */
187 #define FT_ENTRIES_INCREMENT 64
189 /* Local pointer to the name of the main input file. Initialized in
192 static char *primary_filename;
194 /* Pointer to the most recent filename for which we produced some line info. */
196 static char *last_filename;
198 /* For Dwarf output, we must assign lexical-blocks id numbers
199 in the order in which their beginnings are encountered.
200 We output Dwarf debugging info that refers to the beginnings
201 and ends of the ranges of code for each lexical block with
202 assembler labels ..Bn and ..Bn.e, where n is the block number.
203 The labels themselves are generated in final.c, which assigns
204 numbers to the blocks in the same way. */
206 static unsigned next_block_number = 2;
208 /* Counter to generate unique names for DIEs. */
210 static unsigned next_unused_dienum = 1;
212 /* Number of the DIE which is currently being generated. */
214 static unsigned current_dienum;
216 /* Number to use for the special "pubname" label on the next DIE which
217 represents a function or data object defined in this compilation
218 unit which has "extern" linkage. */
220 static next_pubname_number = 0;
222 #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
224 /* Pointer to a dynamically allocated list of pre-reserved and still
225 pending sibling DIE numbers. Note that this list will grow as needed. */
227 static unsigned *pending_sibling_stack;
229 /* Counter to keep track of the number of pre-reserved and still pending
230 sibling DIE numbers. */
232 static unsigned pending_siblings;
234 /* The currently allocated size of the above list (expressed in number of
237 static unsigned pending_siblings_allocated;
239 /* Size (in elements) of increments by which we may expand the pending
240 sibling stack. Actually, a single hunk of space of this size should
241 be enough for most typical programs. */
243 #define PENDING_SIBLINGS_INCREMENT 64
245 /* Non-zero if we are performing our file-scope finalization pass and if
246 we should force out Dwarf descriptions of any and all file-scope
247 tagged types which are still incomplete types. */
249 static int finalizing = 0;
251 /* A pointer to the base of a list of pending types which we haven't
252 generated DIEs for yet, but which we will have to come back to
255 static tree *pending_types_list;
257 /* Number of elements currently allocated for the pending_types_list. */
259 static unsigned pending_types_allocated;
261 /* Number of elements of pending_types_list currently in use. */
263 static unsigned pending_types;
265 /* Size (in elements) of increments by which we may expand the pending
266 types list. Actually, a single hunk of space of this size should
267 be enough for most typical programs. */
269 #define PENDING_TYPES_INCREMENT 64
271 /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
272 This is used in a hack to help us get the DIEs describing types of
273 formal parameters to come *after* all of the DIEs describing the formal
274 parameters themselves. That's necessary in order to be compatible
275 with what the brain-damaged svr4 SDB debugger requires. */
277 static tree fake_containing_scope;
279 /* The number of the current function definition that we are generating
280 debugging information for. These numbers range from 1 up to the maximum
281 number of function definitions contained within the current compilation
282 unit. These numbers are used to create unique labels for various things
283 contained within various function definitions. */
285 static unsigned current_funcdef_number = 1;
287 /* Forward declarations for functions defined in this file. */
289 static void output_type ();
290 static void type_attribute ();
291 static void output_decls_for_scope ();
292 static void output_decl ();
293 static unsigned lookup_filename ();
295 /* Definitions of defaults for assembler-dependent names of various
296 pseudo-ops and section names.
298 Theses may be overridden in your tm.h file (if necessary) for your
299 particular assembler. The default values provided here correspond to
300 what is expected by "standard" AT&T System V.4 assemblers. */
303 #define FILE_ASM_OP ".file"
305 #ifndef VERSION_ASM_OP
306 #define VERSION_ASM_OP ".version"
308 #ifndef UNALIGNED_SHORT_ASM_OP
309 #define UNALIGNED_SHORT_ASM_OP ".2byte"
311 #ifndef UNALIGNED_INT_ASM_OP
312 #define UNALIGNED_INT_ASM_OP ".4byte"
315 #define ASM_BYTE_OP ".byte"
318 #define SET_ASM_OP ".set"
321 /* Pseudo-ops for pushing the current section onto the section stack (and
322 simultaneously changing to a new section) and for poping back to the
323 section we were in immediately before this one. Note that most svr4
324 assemblers only maintain a one level stack... you can push all the
325 sections you want, but you can only pop out one level. (The sparc
326 svr4 assembler is an exception to this general rule.) That's
327 OK because we only use at most one level of the section stack herein. */
329 #ifndef PUSHSECTION_ASM_OP
330 #define PUSHSECTION_ASM_OP ".section"
332 #ifndef POPSECTION_ASM_OP
333 #define POPSECTION_ASM_OP ".previous"
336 /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
337 to print the PUSHSECTION_ASM_OP and the section name. The default here
338 works for almost all svr4 assemblers, except for the sparc, where the
339 section name must be enclosed in double quotes. (See sparcv4.h.) */
341 #ifndef PUSHSECTION_FORMAT
342 #define PUSHSECTION_FORMAT "%s\t%s\n"
345 #ifndef DEBUG_SECTION
346 #define DEBUG_SECTION ".debug"
349 #define LINE_SECTION ".line"
351 #ifndef SFNAMES_SECTION
352 #define SFNAMES_SECTION ".debug_sfnames"
354 #ifndef SRCINFO_SECTION
355 #define SRCINFO_SECTION ".debug_srcinfo"
357 #ifndef MACINFO_SECTION
358 #define MACINFO_SECTION ".debug_macinfo"
360 #ifndef PUBNAMES_SECTION
361 #define PUBNAMES_SECTION ".debug_pubnames"
363 #ifndef ARANGES_SECTION
364 #define ARANGES_SECTION ".debug_aranges"
367 #define TEXT_SECTION ".text"
370 #define DATA_SECTION ".data"
372 #ifndef DATA1_SECTION
373 #define DATA1_SECTION ".data1"
375 #ifndef RODATA_SECTION
376 #define RODATA_SECTION ".rodata"
378 #ifndef RODATA1_SECTION
379 #define RODATA1_SECTION ".rodata1"
382 #define BSS_SECTION ".bss"
385 /* Definitions of defaults for formats and names of various special
386 (artificial) labels which may be generated within this file (when
387 the -g options is used and DWARF_DEBUGGING_INFO is in effect.
389 If necessary, these may be overridden from within your tm.h file,
390 but typically, you should never need to override these.
392 These labels have been hacked (temporarily) so that they all begin with
393 a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
394 stock m88k/svr4 assembler, both of which need to see .L at the start of
395 a label in order to prevent that label from going into the linker symbol
396 table). When I get time, I'll have to fix this the right way so that we
397 will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
398 but that will require a rather massive set of changes. For the moment,
399 the following definitions out to produce the right results for all svr4
400 and svr3 assemblers. -- rfg
403 #ifndef TEXT_BEGIN_LABEL
404 #define TEXT_BEGIN_LABEL ".L_text_b"
406 #ifndef TEXT_END_LABEL
407 #define TEXT_END_LABEL ".L_text_e"
410 #ifndef DATA_BEGIN_LABEL
411 #define DATA_BEGIN_LABEL ".L_data_b"
413 #ifndef DATA_END_LABEL
414 #define DATA_END_LABEL ".L_data_e"
417 #ifndef DATA1_BEGIN_LABEL
418 #define DATA1_BEGIN_LABEL ".L_data1_b"
420 #ifndef DATA1_END_LABEL
421 #define DATA1_END_LABEL ".L_data1_e"
424 #ifndef RODATA_BEGIN_LABEL
425 #define RODATA_BEGIN_LABEL ".L_rodata_b"
427 #ifndef RODATA_END_LABEL
428 #define RODATA_END_LABEL ".L_rodata_e"
431 #ifndef RODATA1_BEGIN_LABEL
432 #define RODATA1_BEGIN_LABEL ".L_rodata1_b"
434 #ifndef RODATA1_END_LABEL
435 #define RODATA1_END_LABEL ".L_rodata1_e"
438 #ifndef BSS_BEGIN_LABEL
439 #define BSS_BEGIN_LABEL ".L_bss_b"
441 #ifndef BSS_END_LABEL
442 #define BSS_END_LABEL ".L_bss_e"
445 #ifndef LINE_BEGIN_LABEL
446 #define LINE_BEGIN_LABEL ".L_line_b"
448 #ifndef LINE_LAST_ENTRY_LABEL
449 #define LINE_LAST_ENTRY_LABEL ".L_line_last"
451 #ifndef LINE_END_LABEL
452 #define LINE_END_LABEL ".L_line_e"
455 #ifndef DEBUG_BEGIN_LABEL
456 #define DEBUG_BEGIN_LABEL ".L_debug_b"
458 #ifndef SFNAMES_BEGIN_LABEL
459 #define SFNAMES_BEGIN_LABEL ".L_sfnames_b"
461 #ifndef SRCINFO_BEGIN_LABEL
462 #define SRCINFO_BEGIN_LABEL ".L_srcinfo_b"
464 #ifndef MACINFO_BEGIN_LABEL
465 #define MACINFO_BEGIN_LABEL ".L_macinfo_b"
468 #ifndef DIE_BEGIN_LABEL_FMT
469 #define DIE_BEGIN_LABEL_FMT ".L_D%u"
471 #ifndef DIE_END_LABEL_FMT
472 #define DIE_END_LABEL_FMT ".L_D%u_e"
474 #ifndef PUB_DIE_LABEL_FMT
475 #define PUB_DIE_LABEL_FMT ".L_P%u"
477 #ifndef INSN_LABEL_FMT
478 #define INSN_LABEL_FMT ".L_I%u_%u"
480 #ifndef BLOCK_BEGIN_LABEL_FMT
481 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
483 #ifndef BLOCK_END_LABEL_FMT
484 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
486 #ifndef SS_BEGIN_LABEL_FMT
487 #define SS_BEGIN_LABEL_FMT ".L_s%u"
489 #ifndef SS_END_LABEL_FMT
490 #define SS_END_LABEL_FMT ".L_s%u_e"
492 #ifndef EE_BEGIN_LABEL_FMT
493 #define EE_BEGIN_LABEL_FMT ".L_e%u"
495 #ifndef EE_END_LABEL_FMT
496 #define EE_END_LABEL_FMT ".L_e%u_e"
498 #ifndef MT_BEGIN_LABEL_FMT
499 #define MT_BEGIN_LABEL_FMT ".L_t%u"
501 #ifndef MT_END_LABEL_FMT
502 #define MT_END_LABEL_FMT ".L_t%u_e"
504 #ifndef LOC_BEGIN_LABEL_FMT
505 #define LOC_BEGIN_LABEL_FMT ".L_l%u"
507 #ifndef LOC_END_LABEL_FMT
508 #define LOC_END_LABEL_FMT ".L_l%u_e"
510 #ifndef BOUND_BEGIN_LABEL_FMT
511 #define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c"
513 #ifndef BOUND_END_LABEL_FMT
514 #define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e"
516 #ifndef DERIV_BEGIN_LABEL_FMT
517 #define DERIV_BEGIN_LABEL_FMT ".L_d%u"
519 #ifndef DERIV_END_LABEL_FMT
520 #define DERIV_END_LABEL_FMT ".L_d%u_e"
522 #ifndef SL_BEGIN_LABEL_FMT
523 #define SL_BEGIN_LABEL_FMT ".L_sl%u"
525 #ifndef SL_END_LABEL_FMT
526 #define SL_END_LABEL_FMT ".L_sl%u_e"
528 #ifndef FUNC_END_LABEL_FMT
529 #define FUNC_END_LABEL_FMT ".L_f%u_e"
531 #ifndef TYPE_NAME_FMT
532 #define TYPE_NAME_FMT ".L_T%u"
534 #ifndef DECL_NAME_FMT
535 #define DECL_NAME_FMT ".L_E%u"
537 #ifndef LINE_CODE_LABEL_FMT
538 #define LINE_CODE_LABEL_FMT ".L_LC%u"
540 #ifndef SFNAMES_ENTRY_LABEL_FMT
541 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
543 #ifndef LINE_ENTRY_LABEL_FMT
544 #define LINE_ENTRY_LABEL_FMT ".L_LE%u"
547 /* Definitions of defaults for various types of primitive assembly language
550 If necessary, these may be overridden from within your tm.h file,
551 but typically, you shouldn't need to override these. One known
552 exception is ASM_OUTPUT_DEF which has to be different for stock
553 sparc/svr4 assemblers.
556 #ifndef ASM_OUTPUT_PUSH_SECTION
557 #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
558 fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
561 #ifndef ASM_OUTPUT_POP_SECTION
562 #define ASM_OUTPUT_POP_SECTION(FILE) \
563 fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
566 #ifndef ASM_OUTPUT_SOURCE_FILENAME
567 #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
568 fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME)
571 #ifndef ASM_OUTPUT_DEF
572 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
573 do { fprintf ((FILE), "\t%s\t", SET_ASM_OP); \
574 assemble_name (FILE, LABEL1); \
575 fprintf (FILE, ","); \
576 assemble_name (FILE, LABEL2); \
577 fprintf (FILE, "\n"); \
581 #ifndef ASM_OUTPUT_DWARF_DELTA2
582 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
583 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
584 assemble_name (FILE, LABEL1); \
585 fprintf (FILE, "-"); \
586 assemble_name (FILE, LABEL2); \
587 fprintf (FILE, "\n"); \
591 #ifndef ASM_OUTPUT_DWARF_DELTA4
592 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
593 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
594 assemble_name (FILE, LABEL1); \
595 fprintf (FILE, "-"); \
596 assemble_name (FILE, LABEL2); \
597 fprintf (FILE, "\n"); \
601 #ifndef ASM_OUTPUT_DWARF_TAG
602 #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
604 fprintf ((FILE), "\t%s\t0x%x", \
605 UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \
606 if (flag_verbose_asm) \
607 fprintf ((FILE), "\t%s %s", \
608 ASM_COMMENT_START, dwarf_tag_name (TAG)); \
609 fputc ('\n', (FILE)); \
613 #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
614 #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \
616 fprintf ((FILE), "\t%s\t0x%x", \
617 UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \
618 if (flag_verbose_asm) \
619 fprintf ((FILE), "\t%s %s", \
620 ASM_COMMENT_START, dwarf_attr_name (ATTR)); \
621 fputc ('\n', (FILE)); \
625 #ifndef ASM_OUTPUT_DWARF_STACK_OP
626 #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \
628 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \
629 if (flag_verbose_asm) \
630 fprintf ((FILE), "\t%s %s", \
631 ASM_COMMENT_START, dwarf_stack_op_name (OP)); \
632 fputc ('\n', (FILE)); \
636 #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
637 #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \
639 fprintf ((FILE), "\t%s\t0x%x", \
640 UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \
641 if (flag_verbose_asm) \
642 fprintf ((FILE), "\t%s %s", \
643 ASM_COMMENT_START, dwarf_fund_type_name (FT)); \
644 fputc ('\n', (FILE)); \
648 #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
649 #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \
651 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \
652 if (flag_verbose_asm) \
653 fprintf ((FILE), "\t%s %s", \
654 ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \
655 fputc ('\n', (FILE)); \
659 #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
660 #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \
662 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \
663 if (flag_verbose_asm) \
664 fprintf ((FILE), "\t%s %s", \
665 ASM_COMMENT_START, dwarf_typemod_name (MOD)); \
666 fputc ('\n', (FILE)); \
670 #ifndef ASM_OUTPUT_DWARF_ADDR
671 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
672 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
673 assemble_name (FILE, LABEL); \
674 fprintf (FILE, "\n"); \
678 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
679 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
681 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
682 output_addr_const ((FILE), (RTX)); \
683 fputc ('\n', (FILE)); \
687 #ifndef ASM_OUTPUT_DWARF_REF
688 #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
689 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
690 assemble_name (FILE, LABEL); \
691 fprintf (FILE, "\n"); \
695 #ifndef ASM_OUTPUT_DWARF_DATA1
696 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
697 fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
700 #ifndef ASM_OUTPUT_DWARF_DATA2
701 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
702 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
705 #ifndef ASM_OUTPUT_DWARF_DATA4
706 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
707 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
710 #ifndef ASM_OUTPUT_DWARF_DATA8
711 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
713 if (WORDS_BIG_ENDIAN) \
715 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
716 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
720 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
721 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
726 #ifndef ASM_OUTPUT_DWARF_STRING
727 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
728 ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
731 /************************ general utility functions **************************/
737 register char *p = (char *) xmalloc (strlen (s) + 1);
747 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
748 || ((GET_CODE (rtl) == SUBREG)
749 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
754 register unsigned tag;
758 case TAG_padding: return "TAG_padding";
759 case TAG_array_type: return "TAG_array_type";
760 case TAG_class_type: return "TAG_class_type";
761 case TAG_entry_point: return "TAG_entry_point";
762 case TAG_enumeration_type: return "TAG_enumeration_type";
763 case TAG_formal_parameter: return "TAG_formal_parameter";
764 case TAG_global_subroutine: return "TAG_global_subroutine";
765 case TAG_global_variable: return "TAG_global_variable";
766 case TAG_label: return "TAG_label";
767 case TAG_lexical_block: return "TAG_lexical_block";
768 case TAG_local_variable: return "TAG_local_variable";
769 case TAG_member: return "TAG_member";
770 case TAG_pointer_type: return "TAG_pointer_type";
771 case TAG_reference_type: return "TAG_reference_type";
772 case TAG_compile_unit: return "TAG_compile_unit";
773 case TAG_string_type: return "TAG_string_type";
774 case TAG_structure_type: return "TAG_structure_type";
775 case TAG_subroutine: return "TAG_subroutine";
776 case TAG_subroutine_type: return "TAG_subroutine_type";
777 case TAG_typedef: return "TAG_typedef";
778 case TAG_union_type: return "TAG_union_type";
779 case TAG_unspecified_parameters: return "TAG_unspecified_parameters";
780 case TAG_variant: return "TAG_variant";
781 case TAG_common_block: return "TAG_common_block";
782 case TAG_common_inclusion: return "TAG_common_inclusion";
783 case TAG_inheritance: return "TAG_inheritance";
784 case TAG_inlined_subroutine: return "TAG_inlined_subroutine";
785 case TAG_module: return "TAG_module";
786 case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type";
787 case TAG_set_type: return "TAG_set_type";
788 case TAG_subrange_type: return "TAG_subrange_type";
789 case TAG_with_stmt: return "TAG_with_stmt";
791 /* GNU extensions. */
793 case TAG_format_label: return "TAG_format_label";
794 case TAG_namelist: return "TAG_namelist";
795 case TAG_function_template: return "TAG_function_template";
796 case TAG_class_template: return "TAG_class_template";
798 default: return "TAG_<unknown>";
803 dwarf_attr_name (attr)
804 register unsigned attr;
808 case AT_sibling: return "AT_sibling";
809 case AT_location: return "AT_location";
810 case AT_name: return "AT_name";
811 case AT_fund_type: return "AT_fund_type";
812 case AT_mod_fund_type: return "AT_mod_fund_type";
813 case AT_user_def_type: return "AT_user_def_type";
814 case AT_mod_u_d_type: return "AT_mod_u_d_type";
815 case AT_ordering: return "AT_ordering";
816 case AT_subscr_data: return "AT_subscr_data";
817 case AT_byte_size: return "AT_byte_size";
818 case AT_bit_offset: return "AT_bit_offset";
819 case AT_bit_size: return "AT_bit_size";
820 case AT_element_list: return "AT_element_list";
821 case AT_stmt_list: return "AT_stmt_list";
822 case AT_low_pc: return "AT_low_pc";
823 case AT_high_pc: return "AT_high_pc";
824 case AT_language: return "AT_language";
825 case AT_member: return "AT_member";
826 case AT_discr: return "AT_discr";
827 case AT_discr_value: return "AT_discr_value";
828 case AT_string_length: return "AT_string_length";
829 case AT_common_reference: return "AT_common_reference";
830 case AT_comp_dir: return "AT_comp_dir";
831 case AT_const_value_string: return "AT_const_value_string";
832 case AT_const_value_data2: return "AT_const_value_data2";
833 case AT_const_value_data4: return "AT_const_value_data4";
834 case AT_const_value_data8: return "AT_const_value_data8";
835 case AT_const_value_block2: return "AT_const_value_block2";
836 case AT_const_value_block4: return "AT_const_value_block4";
837 case AT_containing_type: return "AT_containing_type";
838 case AT_default_value_addr: return "AT_default_value_addr";
839 case AT_default_value_data2: return "AT_default_value_data2";
840 case AT_default_value_data4: return "AT_default_value_data4";
841 case AT_default_value_data8: return "AT_default_value_data8";
842 case AT_default_value_string: return "AT_default_value_string";
843 case AT_friends: return "AT_friends";
844 case AT_inline: return "AT_inline";
845 case AT_is_optional: return "AT_is_optional";
846 case AT_lower_bound_ref: return "AT_lower_bound_ref";
847 case AT_lower_bound_data2: return "AT_lower_bound_data2";
848 case AT_lower_bound_data4: return "AT_lower_bound_data4";
849 case AT_lower_bound_data8: return "AT_lower_bound_data8";
850 case AT_private: return "AT_private";
851 case AT_producer: return "AT_producer";
852 case AT_program: return "AT_program";
853 case AT_protected: return "AT_protected";
854 case AT_prototyped: return "AT_prototyped";
855 case AT_public: return "AT_public";
856 case AT_pure_virtual: return "AT_pure_virtual";
857 case AT_return_addr: return "AT_return_addr";
858 case AT_abstract_origin: return "AT_abstract_origin";
859 case AT_start_scope: return "AT_start_scope";
860 case AT_stride_size: return "AT_stride_size";
861 case AT_upper_bound_ref: return "AT_upper_bound_ref";
862 case AT_upper_bound_data2: return "AT_upper_bound_data2";
863 case AT_upper_bound_data4: return "AT_upper_bound_data4";
864 case AT_upper_bound_data8: return "AT_upper_bound_data8";
865 case AT_virtual: return "AT_virtual";
869 case AT_sf_names: return "AT_sf_names";
870 case AT_src_info: return "AT_src_info";
871 case AT_mac_info: return "AT_mac_info";
872 case AT_src_coords: return "AT_src_coords";
874 default: return "AT_<unknown>";
879 dwarf_stack_op_name (op)
880 register unsigned op;
884 case OP_REG: return "OP_REG";
885 case OP_BASEREG: return "OP_BASEREG";
886 case OP_ADDR: return "OP_ADDR";
887 case OP_CONST: return "OP_CONST";
888 case OP_DEREF2: return "OP_DEREF2";
889 case OP_DEREF4: return "OP_DEREF4";
890 case OP_ADD: return "OP_ADD";
891 default: return "OP_<unknown>";
896 dwarf_typemod_name (mod)
897 register unsigned mod;
901 case MOD_pointer_to: return "MOD_pointer_to";
902 case MOD_reference_to: return "MOD_reference_to";
903 case MOD_const: return "MOD_const";
904 case MOD_volatile: return "MOD_volatile";
905 default: return "MOD_<unknown>";
910 dwarf_fmt_byte_name (fmt)
911 register unsigned fmt;
915 case FMT_FT_C_C: return "FMT_FT_C_C";
916 case FMT_FT_C_X: return "FMT_FT_C_X";
917 case FMT_FT_X_C: return "FMT_FT_X_C";
918 case FMT_FT_X_X: return "FMT_FT_X_X";
919 case FMT_UT_C_C: return "FMT_UT_C_C";
920 case FMT_UT_C_X: return "FMT_UT_C_X";
921 case FMT_UT_X_C: return "FMT_UT_X_C";
922 case FMT_UT_X_X: return "FMT_UT_X_X";
923 case FMT_ET: return "FMT_ET";
924 default: return "FMT_<unknown>";
928 dwarf_fund_type_name (ft)
929 register unsigned ft;
933 case FT_char: return "FT_char";
934 case FT_signed_char: return "FT_signed_char";
935 case FT_unsigned_char: return "FT_unsigned_char";
936 case FT_short: return "FT_short";
937 case FT_signed_short: return "FT_signed_short";
938 case FT_unsigned_short: return "FT_unsigned_short";
939 case FT_integer: return "FT_integer";
940 case FT_signed_integer: return "FT_signed_integer";
941 case FT_unsigned_integer: return "FT_unsigned_integer";
942 case FT_long: return "FT_long";
943 case FT_signed_long: return "FT_signed_long";
944 case FT_unsigned_long: return "FT_unsigned_long";
945 case FT_pointer: return "FT_pointer";
946 case FT_float: return "FT_float";
947 case FT_dbl_prec_float: return "FT_dbl_prec_float";
948 case FT_ext_prec_float: return "FT_ext_prec_float";
949 case FT_complex: return "FT_complex";
950 case FT_dbl_prec_complex: return "FT_dbl_prec_complex";
951 case FT_void: return "FT_void";
952 case FT_boolean: return "FT_boolean";
953 case FT_ext_prec_complex: return "FT_ext_prec_complex";
954 case FT_label: return "FT_label";
956 /* GNU extensions. */
958 case FT_long_long: return "FT_long_long";
959 case FT_signed_long_long: return "FT_signed_long_long";
960 case FT_unsigned_long_long: return "FT_unsigned_long_long";
962 case FT_int8: return "FT_int8";
963 case FT_signed_int8: return "FT_signed_int8";
964 case FT_unsigned_int8: return "FT_unsigned_int8";
965 case FT_int16: return "FT_int16";
966 case FT_signed_int16: return "FT_signed_int16";
967 case FT_unsigned_int16: return "FT_unsigned_int16";
968 case FT_int32: return "FT_int32";
969 case FT_signed_int32: return "FT_signed_int32";
970 case FT_unsigned_int32: return "FT_unsigned_int32";
971 case FT_int64: return "FT_int64";
972 case FT_signed_int64: return "FT_signed_int64";
973 case FT_unsigned_int64: return "FT_signed_int64";
975 case FT_real32: return "FT_real32";
976 case FT_real64: return "FT_real64";
977 case FT_real96: return "FT_real96";
978 case FT_real128: return "FT_real128";
980 default: return "FT_<unknown>";
984 /* Determine the "ultimate origin" of a decl. The decl may be an
985 inlined instance of an inlined instance of a decl which is local
986 to an inline function, so we have to trace all of the way back
987 through the origin chain to find out what sort of node actually
988 served as the original seed for the given block. */
991 decl_ultimate_origin (decl)
994 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
996 if (immediate_origin == NULL)
1000 register tree ret_val;
1001 register tree lookahead = immediate_origin;
1005 ret_val = lookahead;
1006 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1008 while (lookahead != NULL && lookahead != ret_val);
1014 output_unsigned_leb128 (value)
1015 register unsigned long value;
1017 register unsigned long orig_value = value;
1021 register unsigned byte = (value & 0x7f);
1024 if (value != 0) /* more bytes to follow */
1026 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1027 if (flag_verbose_asm && value == 0)
1028 fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
1029 ASM_COMMENT_START, orig_value);
1030 fputc ('\n', asm_out_file);
1036 output_signed_leb128 (value)
1037 register long value;
1039 register long orig_value = value;
1040 register int negative = (value < 0);
1045 register unsigned byte = (value & 0x7f);
1049 value |= 0xfe000000; /* manually sign extend */
1050 if (((value == 0) && ((byte & 0x40) == 0))
1051 || ((value == -1) && ((byte & 0x40) == 1)))
1058 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
1059 if (flag_verbose_asm && more == 0)
1060 fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
1061 ASM_COMMENT_START, orig_value);
1062 fputc ('\n', asm_out_file);
1067 /**************** utility functions for attribute functions ******************/
1069 /* Given a pointer to a BLOCK node return non-zero if (and only if) the
1070 node in question represents the outermost block (i.e. the "body block")
1071 of a function or method.
1073 For any BLOCK node representing a "body block", the BLOCK_SUPERCONTEXT
1074 of the node will point to another BLOCK node which represents the outer-
1075 most (function) scope for the function or method. The BLOCK_SUPERCONTEXT
1076 of that node in turn will point to the relevant FUNCTION_DECL node.
1080 is_body_block (stmt)
1083 register enum tree_code code
1084 = TREE_CODE (BLOCK_SUPERCONTEXT (BLOCK_SUPERCONTEXT (stmt)));
1086 return (code == FUNCTION_DECL);
1089 /* Given a pointer to a tree node for some type, return a Dwarf fundamental
1090 type code for the given type.
1092 This routine must only be called for GCC type nodes that correspond to
1093 Dwarf fundamental types.
1095 The current Dwarf draft specification calls for Dwarf fundamental types
1096 to accurately reflect the fact that a given type was either a "plain"
1097 integral type or an explicitly "signed" integral type. Unfortunately,
1098 we can't always do this, because GCC may already have thrown away the
1099 information about the precise way in which the type was originally
1102 typedef signed int my_type;
1104 struct s { my_type f; };
1106 Since we may be stuck here without enought information to do exactly
1107 what is called for in the Dwarf draft specification, we do the best
1108 that we can under the circumstances and always use the "plain" integral
1109 fundamental type codes for int, short, and long types. That's probably
1110 good enough. The additional accuracy called for in the current DWARF
1111 draft specification is probably never even useful in practice. */
1114 fundamental_type_code (type)
1117 if (TREE_CODE (type) == ERROR_MARK)
1120 switch (TREE_CODE (type))
1129 /* Carefully distinguish all the standard types of C,
1130 without messing up if the language is not C.
1131 Note that we check only for the names that contain spaces;
1132 other names might occur by coincidence in other languages. */
1133 if (TYPE_NAME (type) != 0
1134 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1135 && DECL_NAME (TYPE_NAME (type)) != 0
1136 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1138 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1140 if (!strcmp (name, "unsigned char"))
1141 return FT_unsigned_char;
1142 if (!strcmp (name, "signed char"))
1143 return FT_signed_char;
1144 if (!strcmp (name, "unsigned int"))
1145 return FT_unsigned_integer;
1146 if (!strcmp (name, "short int"))
1148 if (!strcmp (name, "short unsigned int"))
1149 return FT_unsigned_short;
1150 if (!strcmp (name, "long int"))
1152 if (!strcmp (name, "long unsigned int"))
1153 return FT_unsigned_long;
1154 if (!strcmp (name, "long long int"))
1155 return FT_long_long; /* Not grok'ed by svr4 SDB */
1156 if (!strcmp (name, "long long unsigned int"))
1157 return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */
1160 /* Most integer types will be sorted out above, however, for the
1161 sake of special `array index' integer types, the following code
1162 is also provided. */
1164 if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
1165 return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
1167 if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
1168 return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
1170 if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
1171 return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
1173 if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
1174 return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
1176 if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
1177 return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
1182 /* Carefully distinguish all the standard types of C,
1183 without messing up if the language is not C. */
1184 if (TYPE_NAME (type) != 0
1185 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1186 && DECL_NAME (TYPE_NAME (type)) != 0
1187 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
1189 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
1191 /* Note that here we can run afowl of a serious bug in "classic"
1192 svr4 SDB debuggers. They don't seem to understand the
1193 FT_ext_prec_float type (even though they should). */
1195 if (!strcmp (name, "long double"))
1196 return FT_ext_prec_float;
1199 if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
1200 return FT_dbl_prec_float;
1201 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
1204 /* Note that here we can run afowl of a serious bug in "classic"
1205 svr4 SDB debuggers. They don't seem to understand the
1206 FT_ext_prec_float type (even though they should). */
1208 if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
1209 return FT_ext_prec_float;
1213 return FT_complex; /* GNU FORTRAN COMPLEX type. */
1216 return FT_char; /* GNU Pascal CHAR type. Not used in C. */
1219 return FT_boolean; /* GNU FORTRAN BOOLEAN type. */
1222 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
1227 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
1228 the Dwarf "root" type for the given input type. The Dwarf "root" type
1229 of a given type is generally the same as the given type, except that if
1230 the given type is a pointer or reference type, then the root type of
1231 the given type is the root type of the "basis" type for the pointer or
1232 reference type. (This definition of the "root" type is recursive.)
1233 Also, the root type of a `const' qualified type or a `volatile'
1234 qualified type is the root type of the given type without the
1241 if (TREE_CODE (type) == ERROR_MARK)
1242 return error_mark_node;
1244 switch (TREE_CODE (type))
1247 return error_mark_node;
1250 case REFERENCE_TYPE:
1251 return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type)));
1254 return TYPE_MAIN_VARIANT (type);
1258 /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
1259 of zero or more Dwarf "type-modifier" bytes applicable to the type. */
1262 write_modifier_bytes (type, decl_const, decl_volatile)
1264 register int decl_const;
1265 register int decl_volatile;
1267 if (TREE_CODE (type) == ERROR_MARK)
1270 if (TYPE_READONLY (type) || decl_const)
1271 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
1272 if (TYPE_VOLATILE (type) || decl_volatile)
1273 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
1274 switch (TREE_CODE (type))
1277 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
1278 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1281 case REFERENCE_TYPE:
1282 ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
1283 write_modifier_bytes (TREE_TYPE (type), 0, 0);
1292 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
1293 given input type is a Dwarf "fundamental" type. Otherwise return zero. */
1296 type_is_fundamental (type)
1299 switch (TREE_CODE (type))
1318 case REFERENCE_TYPE:
1331 /* Given a pointer to some ..._DECL tree node, generate an assembly language
1332 equate directive which will associate a symbolic name with the current DIE.
1334 The name used is an artificial label generated from the DECL_UID number
1335 associated with the given decl node. The name it gets equated to is the
1336 symbolic label that we (previously) output at the start of the DIE that
1337 we are currently generating.
1339 Calling this function while generating some "decl related" form of DIE
1340 makes it possible to later refer to the DIE which represents the given
1341 decl simply by re-generating the symbolic name from the ..._DECL node's
1345 equate_decl_number_to_die_number (decl)
1348 /* In the case where we are generating a DIE for some ..._DECL node
1349 which represents either some inline function declaration or some
1350 entity declared within an inline function declaration/definition,
1351 setup a symbolic name for the current DIE so that we have a name
1352 for this DIE that we can easily refer to later on within
1353 AT_abstract_origin attributes. */
1355 char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
1356 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1358 sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
1359 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1360 ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
1363 /* Given a pointer to some ..._TYPE tree node, generate an assembly language
1364 equate directive which will associate a symbolic name with the current DIE.
1366 The name used is an artificial label generated from the TYPE_UID number
1367 associated with the given type node. The name it gets equated to is the
1368 symbolic label that we (previously) output at the start of the DIE that
1369 we are currently generating.
1371 Calling this function while generating some "type related" form of DIE
1372 makes it easy to later refer to the DIE which represents the given type
1373 simply by re-generating the alternative name from the ..._TYPE node's
1377 equate_type_number_to_die_number (type)
1380 char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
1381 char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
1383 /* We are generating a DIE to represent the main variant of this type
1384 (i.e the type without any const or volatile qualifiers) so in order
1385 to get the equate to come out right, we need to get the main variant
1388 type = TYPE_MAIN_VARIANT (type);
1390 sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
1391 sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
1392 ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
1395 /* The following routine is a nice and simple transducer. It converts the
1396 RTL for a variable or parameter (resident in memory) into an equivalent
1397 Dwarf representation of a mechanism for getting the address of that same
1398 variable onto the top of a hypothetical "address evaluation" stack.
1400 When creating memory location descriptors, we are effectively trans-
1401 forming the RTL for a memory-resident object into its Dwarf postfix
1402 expression equivalent. This routine just recursively descends an
1403 RTL tree, turning it into Dwarf postfix code as it goes. */
1406 output_mem_loc_descriptor (rtl)
1409 /* Note that for a dynamically sized array, the location we will
1410 generate a description of here will be the lowest numbered location
1411 which is actually within the array. That's *not* necessarily the
1412 same as the zeroth element of the array. */
1414 switch (GET_CODE (rtl))
1418 /* The case of a subreg may arise when we have a local (register)
1419 variable or a formal (register) parameter which doesn't quite
1420 fill up an entire register. For now, just assume that it is
1421 legitimate to make the Dwarf info refer to the whole register
1422 which contains the given subreg. */
1424 rtl = XEXP (rtl, 0);
1429 /* Whenever a register number forms a part of the description of
1430 the method for calculating the (dynamic) address of a memory
1431 resident object, Dwarf rules require the register number to
1432 be referred to as a "base register". This distinction is not
1433 based in any way upon what category of register the hardware
1434 believes the given register belongs to. This is strictly
1435 Dwarf terminology we're dealing with here. */
1437 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
1438 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1439 DBX_REGISTER_NUMBER (REGNO (rtl)));
1443 output_mem_loc_descriptor (XEXP (rtl, 0));
1444 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
1449 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
1450 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1454 output_mem_loc_descriptor (XEXP (rtl, 0));
1455 output_mem_loc_descriptor (XEXP (rtl, 1));
1456 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1460 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1461 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
1469 /* Output a proper Dwarf location descriptor for a variable or parameter
1470 which is either allocated in a register or in a memory location. For
1471 a register, we just generate an OP_REG and the register number. For a
1472 memory location we provide a Dwarf postfix expression describing how to
1473 generate the (dynamic) address of the object onto the address stack. */
1476 output_loc_descriptor (rtl)
1479 switch (GET_CODE (rtl))
1483 /* The case of a subreg may arise when we have a local (register)
1484 variable or a formal (register) parameter which doesn't quite
1485 fill up an entire register. For now, just assume that it is
1486 legitimate to make the Dwarf info refer to the whole register
1487 which contains the given subreg. */
1489 rtl = XEXP (rtl, 0);
1493 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
1494 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1495 DBX_REGISTER_NUMBER (REGNO (rtl)));
1499 output_mem_loc_descriptor (XEXP (rtl, 0));
1503 abort (); /* Should never happen */
1507 /* Given a tree node describing an array bound (either lower or upper)
1508 output a representation for that bound. */
1511 output_bound_representation (bound, dim_num, u_or_l)
1512 register tree bound;
1513 register unsigned dim_num; /* For multi-dimensional arrays. */
1514 register char u_or_l; /* Designates upper or lower bound. */
1516 switch (TREE_CODE (bound))
1522 /* All fixed-bounds are represented by INTEGER_CST nodes. */
1525 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1526 (unsigned) TREE_INT_CST_LOW (bound));
1529 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
1533 bound = TREE_OPERAND (bound, 0);
1534 /* ... fall thru... */
1538 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1539 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1541 sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
1542 current_dienum, dim_num, u_or_l);
1544 sprintf (end_label, BOUND_END_LABEL_FMT,
1545 current_dienum, dim_num, u_or_l);
1547 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1548 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1550 /* If we are working on a bound for a dynamic dimension in C,
1551 the dynamic dimension in question had better have a static
1552 (zero) lower bound and a dynamic *upper* bound. */
1557 /* If optimization is turned on, the SAVE_EXPRs that describe
1558 how to access the upper bound values are essentially bogus.
1559 They only describe (at best) how to get at these values at
1560 the points in the generated code right after they have just
1561 been computed. Worse yet, in the typical case, the upper
1562 bound values will not even *be* computed in the optimized
1563 code, so these SAVE_EXPRs are entirely bogus.
1565 In order to compensate for this fact, we check here to see
1566 if optimization is enabled, and if so, we effectively create
1567 an empty location description for the (unknown and unknowable)
1570 This should not cause too much trouble for existing (stupid?)
1571 debuggers because they have to deal with empty upper bounds
1572 location descriptions anyway in order to be able to deal with
1573 incomplete array types.
1575 Of course an intelligent debugger (GDB?) should be able to
1576 comprehend that a missing upper bound specification in a
1577 array type used for a storage class `auto' local array variable
1578 indicates that the upper bound is both unknown (at compile-
1579 time) and unknowable (at run-time) due to optimization.
1583 output_loc_descriptor
1584 (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
1586 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1595 /* Recursive function to output a sequence of value/name pairs for
1596 enumeration constants in reversed order. This is called from
1597 enumeration_type_die. */
1600 output_enumeral_list (link)
1605 output_enumeral_list (TREE_CHAIN (link));
1606 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
1607 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
1608 ASM_OUTPUT_DWARF_STRING (asm_out_file,
1609 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
1613 /****************************** attributes *********************************/
1615 /* The following routines are responsible for writing out the various types
1616 of Dwarf attributes (and any following data bytes associated with them).
1617 These routines are listed in order based on the numerical codes of their
1618 associated attributes. */
1620 /* Generate an AT_sibling attribute. */
1623 sibling_attribute ()
1625 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1627 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
1628 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
1629 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
1632 /* Output the form of location attributes suitable for whole variables and
1633 whole parameters. Note that the location attributes for struct fields
1634 are generated by the routine `data_member_location_attribute' below. */
1637 location_attribute (rtl)
1640 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1641 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1643 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1644 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1645 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1646 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1647 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1649 /* Handle a special case. If we are about to output a location descriptor
1650 for a variable or parameter which has been optimized out of existence,
1651 don't do that. Instead we output a zero-length location descriptor
1652 value as part of the location attribute. Note that we cannot simply
1653 suppress the entire location attribute, because the absence of a
1654 location attribute in certain kinds of DIEs is used to indicate some-
1655 thing entirely different... i.e. that the DIE represents an object
1656 declaration, but not a definition. So sayeth the PLSIG. */
1658 if (! is_pseudo_reg (rtl))
1659 output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
1661 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1664 /* Output the specialized form of location attribute used for data members
1667 In the special case of a FIELD_DECL node which represents a bit-field,
1668 the "offset" part of this special location descriptor must indicate the
1669 distance in bytes from the lowest-addressed byte of the containing
1670 struct or union type to the lowest-addressed byte of the "containing
1671 object" for the bit-field.
1673 For any given bit-field, the "containing object" is a hypothetical
1674 object (of some integral or enum type) within which the given bit-field
1675 lives. The type of this hypothetical "containing object" is always the
1676 same as the declared type of the individual bit-field itself.
1678 Note that it is the size (in bytes) of the hypothetical "containing
1679 object" which will be given in the AT_byte_size attribute for this
1680 bit-field. (See the `byte_size_attribute' function below.)
1685 data_member_location_attribute (decl)
1688 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1689 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1690 register unsigned type_align_in_bytes;
1691 register unsigned type_align_in_bits;
1692 register unsigned offset_in_align_units;
1693 register unsigned offset_in_bytes;
1695 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
1696 register unsigned bitpos_int;
1698 if (TREE_CODE (decl) == ERROR_MARK)
1701 if (TREE_CODE (decl) != FIELD_DECL)
1704 /* The bit position given by DECL_FIELD_BITPOS could be non-constant
1705 in the case where one or more variable sized members preceded this
1706 member in the containing struct type. We could probably correctly
1707 handle this case someday, by it's too complicated to deal with at
1708 the moment (and probably too rare to worry about), so just punt on
1709 the whole AT_location attribute for now. Eventually, we'll have
1710 to analyze the expression given as the DECL_FIELD_BITPOS and turn
1711 it into a member-style AT_location descriptor, but that'll be
1712 tough to do. -- rfg */
1714 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
1716 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
1718 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
1719 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1720 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1721 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
1722 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1723 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
1725 type = DECL_BIT_FIELD_TYPE (decl);
1727 type = TREE_TYPE (decl);
1729 type_align_in_bits = TYPE_ALIGN (type);
1730 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
1732 /* WARNING! Note that the GCC front-end doesn't make any attempt to
1733 keep track of the starting bit offset (relative to the start of
1734 the containing structure type) of the hypothetical "containing
1735 object" for a bit-field. (See the comments at the start of this
1736 function.) Thus, when computing the byte offset value for a
1737 bit-field, all we can do is to divide the starting bit offset of
1738 the bit-field by the alignment of the hypothetical "containing
1739 object" (which we can easily find) and then multiply by the number
1740 of bytes of that alignment.
1742 This solution only yields an unambiguously correct result when
1743 the size of the bit-field is strictly larger than the size of the
1744 declared type minus the alignment of the declared type. When this
1745 condition is not satisfied, it means that there is at least an
1746 "alignment unit's" worth of other slop which co-resides within the
1747 hypothetical "containing object" with the bit field, and this other
1748 slop could be either to the left of the bit-field or to the right
1749 of the bit-field. (We have no way of knowing which.)
1751 It also means that we cannot unambiguously tell exactly where the
1752 hypothetical "containing object" begins within the containing struct
1753 type. We only know the precise position of the bit-field which is
1754 contained therein, and that the hypothetical containing object must
1755 be aligned as required for its type. But when there is at least an
1756 alignment unit's worth of slop co-resident in the containing object
1757 with the actual bit-field, the actual start of the containing object
1758 is ambiguous and thus, we cannot unambiguously determine the "correct"
1759 byte offset to put into the AT_location attribute for the bit-field
1762 This whole thing is a non-issue for the majority of targets, because
1763 (for most GCC targets) the alignment of each supported integral type
1764 is the same as the size of that type, and thus (size - alignment) for
1765 the declared type of any bit-field yields zero, and the size (in bits)
1766 of any bit-field must be bigger than zero, so there is never any
1767 ambiguity about the starting positions of the containing objects of
1768 bit-fields for most GCC targets.
1770 An exception arises however for some machines (e.g. i386) which have
1771 BIGGEST_ALIGNMENT set to something less than the size of type `long
1772 long' (i.e. 64) and when we are confronted with something like:
1776 long long field2:31;
1779 Here it is ambiguous (going by DWARF rules anyway) whether the con-
1780 taining `long long' object for `field2' should be said to occupy the
1781 first and second (32-bit) words of the containing struct type, or
1782 whether it should be said to occupy the second and third words of
1785 Currently, GCC allocates 8 bytes (for an i386 target) for each object
1786 of the above type. This is probably a bug however, and GCC should
1787 probably be allocating 12 bytes for each such structure (for the i386
1790 Assuming this bug gets fixed, one would have a strong case for saying
1791 that the containing `long long' object for `field2' occupies the second
1792 and third words of the above structure type, and that `field2' itself
1793 occupies the first 31 bits of that containing object. However consider:
1797 long long field2:31;
1799 long long field4:31;
1802 Even if the current "member allocation" bug in GCC is fixed, this ex-
1803 ample would still illustrate a case in which the starting point of the
1804 containing `long long' object for `field4' would be ambiguous, even
1805 though we know the exact starting bit offset (within the structure) of
1806 the `field4' bit-field itself.
1808 We essentially just ignore this whole issue here and always act as if
1809 most of the slop which co-resides in a containing object along with a
1810 bit-field appears in that containing object *AFTER* the bit field.
1811 Thus, for the above example, we say that the containing object for
1812 `field4' occupies the third and fourth words of the structure type,
1813 even though objects of the type only occupy three words. As long
1814 as the debugger understands that the compiler uses this disambiguation
1815 rule, the debugger should easily be able to do the Right Thing in all
1819 offset_in_align_units = bitpos_int / type_align_in_bits;
1820 offset_in_bytes = offset_in_align_units * type_align_in_bytes;
1822 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, offset_in_bytes);
1823 ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
1824 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1827 /* Output an AT_const_value attribute for a variable or a parameter which
1828 does not have a "location" either in memory or in a register. These
1829 things can arise in GNU C when a constant is passed as an actual
1830 parameter to an inlined function. They can also arise in C++ where
1831 declared constants do not necessarily get memory "homes". */
1834 const_value_attribute (rtl)
1837 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
1838 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
1840 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
1841 sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
1842 sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
1843 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
1844 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
1846 switch (GET_CODE (rtl))
1849 /* Note that a CONST_INT rtx could represent either an integer or
1850 a floating-point constant. A CONST_INT is used whenever the
1851 constant will fit into a single word. In all such cases, the
1852 original mode of the constant value is wiped out, and the
1853 CONST_INT rtx is assigned VOIDmode. Since we no longer have
1854 precise mode information for these constants, we always just
1855 output them using 4 bytes. */
1857 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
1861 /* Note that a CONST_DOUBLE rtx could represent either an integer
1862 or a floating-point constant. A CONST_DOUBLE is used whenever
1863 the constant requires more than one word in order to be adequately
1864 represented. In all such cases, the original mode of the constant
1865 value is preserved as the mode of the CONST_DOUBLE rtx, but for
1866 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
1868 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
1869 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
1870 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
1874 ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
1880 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
1884 /* In cases where an inlined instance of an inline function is passed
1885 the address of an `auto' variable (which is local to the caller)
1886 we can get a situation where the DECL_RTL of the artificial
1887 local variable (for the inlining) which acts as a stand-in for
1888 the corresponding formal parameter (of the inline function)
1889 will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
1890 This is not exactly a compile-time constant expression, but it
1891 isn't the address of the (artificial) local variable either.
1892 Rather, it represents the *value* which the artificial local
1893 variable always has during its lifetime. We currently have no
1894 way to represent such quasi-constant values in Dwarf, so for now
1895 we just punt and generate an AT_const_value attribute with form
1896 FORM_BLOCK4 and a length of zero. */
1900 ASM_OUTPUT_LABEL (asm_out_file, end_label);
1903 /* Generate *either* an AT_location attribute or else an AT_const_value
1904 data attribute for a variable or a parameter. We generate the
1905 AT_const_value attribute only in those cases where the given
1906 variable or parameter does not have a true "location" either in
1907 memory or in a register. This can happen (for example) when a
1908 constant is passed as an actual argument in a call to an inline
1909 function. (It's possible that these things can crop up in other
1910 ways also.) Note that one type of constant value which can be
1911 passed into an inlined function is a constant pointer. This can
1912 happen for example if an actual argument in an inlined function
1913 call evaluates to a compile-time constant address. */
1916 location_or_const_value_attribute (decl)
1921 if (TREE_CODE (decl) == ERROR_MARK)
1924 if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
1927 /* Existing Dwarf debuggers need and expect the location descriptors for
1928 formal parameters to reflect either the place where the parameters get
1929 passed (if they are passed on the stack and in memory) or else the
1930 (preserved) registers which the parameters get copied to during the
1933 At least this is the way things are for most common CISC machines
1934 (e.g. x86 and m68k) where parameters are passed in the stack, and for
1935 most common RISC machines (e.g. i860 and m88k) where parameters are
1936 passed in registers.
1938 The rules for Sparc are a little weird for some reason. The DWARF
1939 generated by the USL C compiler for the Sparc/svr4 reference port says
1940 that the parameters are passed in the stack. I haven't figured out
1941 how to duplicate that behavior here (for the Sparc) yet, or even if
1944 Note that none of this is clearly spelled out in the current Dwarf
1945 version 1 specification, but it's obvious if you look at the output of
1946 the CI5 compiler, or if you try to use the svr4 SDB debugger. Hopefully,
1947 a later version of the Dwarf specification will clarify this. For now,
1948 we just need to generate the right thing. Note that Dwarf version 2
1949 will provide us with a means to describe *all* of the locations in which
1950 a given variable or parameter resides (and the PC ranges over which it
1951 occupies each one), but for now we can only describe one "location"
1952 for each formal parameter passed, and so we just try to mimic existing
1953 practice as much as possible.
1956 if (TREE_CODE (decl) != PARM_DECL)
1957 /* If this decl is not a formal parameter, just use DECL_RTL. */
1958 rtl = DECL_RTL (decl);
1961 if (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM)
1962 /* Parameter was passed in memory, so say that's where it lives. */
1963 rtl = DECL_INCOMING_RTL (decl);
1966 /* Parameter was passed in a register, so say it lives in the
1967 register it will be copied to during the prologue. */
1968 rtl = DECL_RTL (decl);
1970 /* Note that in cases where the formal parameter is never used
1971 and where this compilation is done with -O, the copying of
1972 of an incoming register parameter to another register (in
1973 the prologue) can be totally optimized away. (In such cases
1974 the DECL_RTL will indicate a pseudo-register.) We could just
1975 use the DECL_RTL (as we normally do for register parameters)
1976 in these cases, but if we did that, we would end up generating
1977 a null location descriptor. (See `location_attribute' above.)
1978 That would be acceptable (according to the DWARF spec) but it
1979 is probably more useful to say that the formal resides where
1980 it was passed instead of saying that it resides nowhere. */
1981 if (is_pseudo_reg (rtl))
1982 rtl = DECL_INCOMING_RTL (decl);
1989 switch (GET_CODE (rtl))
1997 case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
1998 const_value_attribute (rtl);
2004 location_attribute (rtl);
2008 abort (); /* Should never happen. */
2012 /* Generate an AT_name attribute given some string value to be included as
2013 the value of the attribute. */
2016 name_attribute (name_string)
2017 register char *name_string;
2019 if (name_string && *name_string)
2021 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
2022 ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
2027 fund_type_attribute (ft_code)
2028 register unsigned ft_code;
2030 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
2031 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
2035 mod_fund_type_attribute (type, decl_const, decl_volatile)
2037 register int decl_const;
2038 register int decl_volatile;
2040 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2041 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2043 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
2044 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2045 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2046 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2047 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2048 write_modifier_bytes (type, decl_const, decl_volatile);
2049 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2050 fundamental_type_code (root_type (type)));
2051 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2055 user_def_type_attribute (type)
2058 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2060 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
2061 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
2062 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2066 mod_u_d_type_attribute (type, decl_const, decl_volatile)
2068 register int decl_const;
2069 register int decl_volatile;
2071 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2072 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2073 char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
2075 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
2076 sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
2077 sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
2078 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2079 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2080 write_modifier_bytes (type, decl_const, decl_volatile);
2081 sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
2082 ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
2083 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2087 ordering_attribute (ordering)
2088 register unsigned ordering;
2090 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
2091 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
2094 /* Note that the block of subscript information for an array type also
2095 includes information about the element type of type given array type. */
2098 subscript_data_attribute (type)
2101 register unsigned dimension_number;
2102 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2103 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2105 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
2106 sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
2107 sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
2108 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2109 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2111 /* The GNU compilers represent multidimensional array types as sequences
2112 of one dimensional array types whose element types are themselves array
2113 types. Here we squish that down, so that each multidimensional array
2114 type gets only one array_type DIE in the Dwarf debugging info. The
2115 draft Dwarf specification say that we are allowed to do this kind
2116 of compression in C (because there is no difference between an
2117 array or arrays and a multidimensional array in C) but for other
2118 source languages (e.g. Ada) we probably shouldn't do this. */
2120 for (dimension_number = 0;
2121 TREE_CODE (type) == ARRAY_TYPE;
2122 type = TREE_TYPE (type), dimension_number++)
2124 register tree domain = TYPE_DOMAIN (type);
2126 /* Arrays come in three flavors. Unspecified bounds, fixed
2127 bounds, and (in GNU C only) variable bounds. Handle all
2128 three forms here. */
2132 /* We have an array type with specified bounds. */
2134 register tree lower = TYPE_MIN_VALUE (domain);
2135 register tree upper = TYPE_MAX_VALUE (domain);
2137 /* Handle only fundamental types as index types for now. */
2139 if (! type_is_fundamental (domain))
2142 /* Output the representation format byte for this dimension. */
2144 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
2146 TREE_CODE (lower) == INTEGER_CST,
2147 TREE_CODE (upper) == INTEGER_CST));
2149 /* Output the index type for this dimension. */
2151 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
2152 fundamental_type_code (domain));
2154 /* Output the representation for the lower bound. */
2156 output_bound_representation (lower, dimension_number, 'l');
2158 /* Output the representation for the upper bound. */
2160 output_bound_representation (upper, dimension_number, 'u');
2164 /* We have an array type with an unspecified length. For C and
2165 C++ we can assume that this really means that (a) the index
2166 type is an integral type, and (b) the lower bound is zero.
2167 Note that Dwarf defines the representation of an unspecified
2168 (upper) bound as being a zero-length location description. */
2170 /* Output the array-bounds format byte. */
2172 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
2174 /* Output the (assumed) index type. */
2176 ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
2178 /* Output the (assumed) lower bound (constant) value. */
2180 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2182 /* Output the (empty) location description for the upper bound. */
2184 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
2188 /* Output the prefix byte that says that the element type is comming up. */
2190 ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
2192 /* Output a representation of the type of the elements of this array type. */
2194 type_attribute (type, 0, 0);
2196 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2200 byte_size_attribute (tree_node)
2201 register tree tree_node;
2203 register unsigned size;
2205 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
2206 switch (TREE_CODE (tree_node))
2215 size = int_size_in_bytes (tree_node);
2219 /* For a data member of a struct or union, the AT_byte_size is
2220 always given as the number of bytes normally allocated for
2221 an object of the *declared* type of the member itself. This
2222 is true even for bit-fields. */
2223 size = int_size_in_bytes (DECL_BIT_FIELD_TYPE (tree_node)
2224 ? DECL_BIT_FIELD_TYPE (tree_node)
2225 : TREE_TYPE (tree_node));
2232 /* Note that `size' might be -1 when we get to this point. If it
2233 is, that indicates that the byte size of the entity in question
2234 is variable. We have no good way of expressing this fact in Dwarf
2235 at the present time, so just let the -1 pass on through. */
2237 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
2240 /* For a FIELD_DECL node which represents a bit-field, output an attribute
2241 which specifies the distance in bits from the highest order bit of the
2242 "containing object" for the bit-field to the highest order bit of the
2245 For any given bit-field, the "containing object" is a hypothetical
2246 object (of some integral or enum type) within which the given bit-field
2247 lives. The type of this hypothetical "containing object" is always the
2248 same as the declared type of the individual bit-field itself.
2250 Note that it is the size (in bytes) of the hypothetical "containing
2251 object" which will be given in the AT_byte_size attribute for this
2252 bit-field. (See `byte_size_attribute' above.)
2256 bit_offset_attribute (decl)
2259 register tree type = DECL_BIT_FIELD_TYPE (decl);
2260 register unsigned dwarf_bit_offset;
2261 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
2262 register unsigned bitpos_int;
2264 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2265 assert (type); /* Must be a bit field. */
2267 /* The bit position given by DECL_FIELD_BITPOS could be non-constant
2268 in the case where one or more variable sized members preceded this
2269 member in the containing struct type. We could probably correctly
2270 handle this case someday, by it's too complicated to deal with at
2271 the moment, so just punt on the whole AT_bit_offset attribute for
2272 now. Eventually, we'll have to analyze the (variable) expression
2273 given as the DECL_FIELD_BITPOS and see if we can factor out just
2274 the (constant) bit offset part of that expression. -- rfg */
2276 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
2278 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
2280 /* For a detailed description of how the AT_bit_offset attribute value
2281 is calculated, see the comments in `data_member_location_attribute'
2284 #if (BYTES_BIG_ENDIAN == 1)
2285 dwarf_bit_offset = bitpos_int % TYPE_ALIGN (type);
2288 register unsigned high_order_bitpos
2289 = bitpos_int + (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
2290 register tree type_size_tree = TYPE_SIZE (type);
2291 register unsigned type_size_in_bits;
2293 if (TREE_CODE (type_size_tree) != INTEGER_CST)
2295 type_size_in_bits = (unsigned) TREE_INT_CST_LOW (type_size_tree);
2297 dwarf_bit_offset = type_size_in_bits
2298 - (high_order_bitpos % TYPE_ALIGN (type));
2302 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
2303 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, dwarf_bit_offset);
2306 /* For a FIELD_DECL node which represents a bit field, output an attribute
2307 which specifies the length in bits of the given field. */
2310 bit_size_attribute (decl)
2313 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
2314 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
2316 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
2317 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
2318 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
2321 /* The following routine outputs the `element_list' attribute for enumeration
2322 type DIEs. The element_lits attribute includes the names and values of
2323 all of the enumeration constants associated with the given enumeration
2327 element_list_attribute (element)
2328 register tree element;
2330 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2331 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2333 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
2334 sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
2335 sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
2336 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
2337 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2339 /* Here we output a list of value/name pairs for each enumeration constant
2340 defined for this enumeration type (as required), but we do it in REVERSE
2341 order. The order is the one required by the draft #5 Dwarf specification
2342 published by the UI/PLSIG. */
2344 output_enumeral_list (element); /* Recursively output the whole list. */
2346 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2349 /* Generate an AT_stmt_list attribute. These are normally present only in
2350 DIEs with a TAG_compile_unit tag. */
2353 stmt_list_attribute (label)
2354 register char *label;
2356 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
2357 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2358 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
2361 /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
2362 for a subroutine DIE. */
2365 low_pc_attribute (asm_low_label)
2366 register char *asm_low_label;
2368 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
2369 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
2372 /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
2376 high_pc_attribute (asm_high_label)
2377 register char *asm_high_label;
2379 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
2380 ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
2383 /* Generate an AT_language attribute given a LANG value. These attributes
2384 are used only within TAG_compile_unit DIEs. */
2387 language_attribute (language_code)
2388 register unsigned language_code;
2390 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
2391 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
2395 member_attribute (context)
2396 register tree context;
2398 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2400 /* Generate this attribute only for members in C++. */
2403 && (TREE_CODE (context) == RECORD_TYPE
2404 || TREE_CODE (context) == UNION_TYPE))
2406 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
2407 sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
2408 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2413 string_length_attribute (upper_bound)
2414 register tree upper_bound;
2416 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2417 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2419 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
2420 sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
2421 sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
2422 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
2423 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
2424 output_bound_representation (upper_bound, 0, 'u');
2425 ASM_OUTPUT_LABEL (asm_out_file, end_label);
2429 comp_dir_attribute (dirname)
2430 register char *dirname;
2432 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
2433 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
2437 sf_names_attribute (sf_names_start_label)
2438 register char *sf_names_start_label;
2440 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
2441 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2442 ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
2446 src_info_attribute (src_info_start_label)
2447 register char *src_info_start_label;
2449 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
2450 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2451 ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
2455 mac_info_attribute (mac_info_start_label)
2456 register char *mac_info_start_label;
2458 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
2459 /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */
2460 ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
2464 prototyped_attribute (func_type)
2465 register tree func_type;
2467 if ((strcmp (language_string, "GNU C") == 0)
2468 && (TYPE_ARG_TYPES (func_type) != NULL))
2470 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
2471 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2476 producer_attribute (producer)
2477 register char *producer;
2479 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
2480 ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
2484 inline_attribute (decl)
2487 if (TREE_INLINE (decl))
2489 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
2490 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2495 containing_type_attribute (containing_type)
2496 register tree containing_type;
2498 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2500 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
2501 sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
2502 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2506 abstract_origin_attribute (origin)
2507 register tree origin;
2509 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2511 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
2512 switch (TREE_CODE_CLASS (TREE_CODE (origin)))
2515 sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
2519 sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
2523 abort (); /* Should never happen. */
2526 ASM_OUTPUT_DWARF_REF (asm_out_file, label);
2529 #ifdef DWARF_DECL_COORDINATES
2531 src_coords_attribute (src_fileno, src_lineno)
2532 register unsigned src_fileno;
2533 register unsigned src_lineno;
2535 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
2536 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
2537 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
2539 #endif /* defined(DWARF_DECL_COORDINATES) */
2542 pure_or_virtual_attribute (func_decl)
2543 register tree func_decl;
2545 if (DECL_VIRTUAL_P (func_decl))
2547 if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
2548 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
2550 ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
2551 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
2555 /************************* end of attributes *****************************/
2557 /********************* utility routines for DIEs *************************/
2559 /* Output an AT_name attribute and an AT_src_coords attribute for the
2560 given decl, but only if it actually has a name. */
2563 name_and_src_coords_attributes (decl)
2566 register tree decl_name = DECL_NAME (decl);
2568 if (decl_name && IDENTIFIER_POINTER (decl_name))
2570 name_attribute (IDENTIFIER_POINTER (decl_name));
2571 #ifdef DWARF_DECL_COORDINATES
2573 register unsigned file_index;
2575 /* This is annoying, but we have to pop out of the .debug section
2576 for a moment while we call `lookup_filename' because calling it
2577 may cause a temporary switch into the .debug_sfnames section and
2578 most svr4 assemblers are not smart enough be be able to nest
2579 section switches to any depth greater than one. Note that we
2580 also can't skirt this issue by delaying all output to the
2581 .debug_sfnames section unit the end of compilation because that
2582 would cause us to have inter-section forward references and
2583 Fred Fish sez that m68k/svr4 assemblers botch those. */
2585 ASM_OUTPUT_POP_SECTION (asm_out_file);
2586 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
2587 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
2589 src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
2595 /* Many forms of DIEs contain a "type description" part. The following
2596 routine writes out these "type descriptor" parts. */
2599 type_attribute (type, decl_const, decl_volatile)
2601 register int decl_const;
2602 register int decl_volatile;
2604 register enum tree_code code = TREE_CODE (type);
2605 register int root_type_modified;
2607 if (TREE_CODE (type) == ERROR_MARK)
2610 /* Handle a special case. For functions whose return type is void,
2611 we generate *no* type attribute. (Note that no object may have
2612 type `void', so this only applies to function return types. */
2614 if (TREE_CODE (type) == VOID_TYPE)
2617 root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
2618 || decl_const || decl_volatile
2619 || TYPE_READONLY (type) || TYPE_VOLATILE (type));
2621 if (type_is_fundamental (root_type (type)))
2622 if (root_type_modified)
2623 mod_fund_type_attribute (type, decl_const, decl_volatile);
2625 fund_type_attribute (fundamental_type_code (type));
2627 if (root_type_modified)
2628 mod_u_d_type_attribute (type, decl_const, decl_volatile);
2630 user_def_type_attribute (type);
2633 /* Given a tree pointer to a struct, class, union, or enum type node, return
2634 a pointer to the (string) tag name for the given type, or zero if the
2635 type was declared without a tag. */
2641 register char *name = 0;
2643 if (TYPE_NAME (type) != 0)
2645 register tree t = 0;
2647 /* Find the IDENTIFIER_NODE for the type name. */
2648 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2649 t = TYPE_NAME (type);
2651 /* The g++ front end makes the TYPE_NAME of *each* tagged type point
2652 to a TYPE_DECL node, regardless of whether or not a `typedef' was
2653 involved. This is distinctly different from what the gcc front-end
2654 does. It always makes the TYPE_NAME for each tagged type be either
2655 NULL (signifying an anonymous tagged type) or else a pointer to an
2656 IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf
2657 for both C and C++, but given this inconsistency in the TREE
2658 representation of tagged types for C and C++ in the GNU front-ends,
2659 we cannot support both languages correctly unless we introduce some
2660 front-end specific code here, and rms objects to that, so we can
2661 only generate correct Dwarf for one of these two languages. C is
2662 more important, so for now we'll do the right thing for C and let
2666 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2667 t = DECL_NAME (TYPE_NAME (type));
2669 /* Now get the name as a string, or invent one. */
2671 name = IDENTIFIER_POINTER (t);
2674 return (name == 0 || *name == '\0') ? 0 : name;
2680 /* Start by checking if the pending_sibling_stack needs to be expanded.
2681 If necessary, expand it. */
2683 if (pending_siblings == pending_siblings_allocated)
2685 pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
2686 pending_sibling_stack
2687 = (unsigned *) xrealloc (pending_sibling_stack,
2688 pending_siblings_allocated * sizeof(unsigned));
2692 NEXT_DIE_NUM = next_unused_dienum++;
2695 /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
2705 member_declared_type (member)
2706 register tree member;
2708 return (DECL_BIT_FIELD_TYPE (member))
2709 ? DECL_BIT_FIELD_TYPE (member)
2710 : TREE_TYPE (member);
2713 /******************************* DIEs ************************************/
2715 /* Output routines for individual types of DIEs. */
2717 /* Note that every type of DIE (except a null DIE) gets a sibling. */
2720 output_array_type_die (arg)
2723 register tree type = arg;
2725 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
2726 sibling_attribute ();
2727 equate_type_number_to_die_number (type);
2728 member_attribute (TYPE_CONTEXT (type));
2730 /* I believe that we can default the array ordering. SDB will probably
2731 do the right things even if AT_ordering is not present. It's not
2732 even an issue until we start to get into multidimensional arrays
2733 anyway. If SDB is ever caught doing the Wrong Thing for multi-
2734 dimensional arrays, then we'll have to put the AT_ordering attribute
2735 back in. (But if and when we find out that we need to put these in,
2736 we will only do so for multidimensional arrays. After all, we don't
2737 want to waste space in the .debug section now do we?) */
2740 ordering_attribute (ORD_row_major);
2743 subscript_data_attribute (type);
2747 output_set_type_die (arg)
2750 register tree type = arg;
2752 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
2753 sibling_attribute ();
2754 equate_type_number_to_die_number (type);
2755 member_attribute (TYPE_CONTEXT (type));
2756 type_attribute (TREE_TYPE (type), 0, 0);
2760 /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */
2762 output_entry_point_die (arg)
2765 register tree decl = arg;
2766 register tree type = TREE_TYPE (decl);
2767 register tree return_type = TREE_TYPE (type);
2769 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
2770 sibling_attribute ();
2772 name_and_src_coords_attributes (decl);
2773 member_attribute (DECL_CONTEXT (decl));
2774 type_attribute (return_type, 0, 0);
2778 /* Output a DIE to represent an enumeration type. Note that these DIEs
2779 include all of the information about the enumeration values also.
2780 This information is encoded into the element_list attribute. */
2783 output_enumeration_type_die (arg)
2786 register tree type = arg;
2788 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
2789 sibling_attribute ();
2790 equate_type_number_to_die_number (type);
2791 name_attribute (type_tag (type));
2792 member_attribute (TYPE_CONTEXT (type));
2794 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
2795 given enum type is incomplete, do not generate the AT_byte_size
2796 attribute or the AT_element_list attribute. */
2798 if (TYPE_SIZE (type))
2800 byte_size_attribute (type);
2801 element_list_attribute (TYPE_FIELDS (type));
2805 /* Output a DIE to represent either a real live formal parameter decl or
2806 to represent just the type of some formal parameter position in some
2809 Note that this routine is a bit unusual because its argument may be
2810 either a PARM_DECL node or else some sort of a ..._TYPE node. If it's
2811 the formar then this function is being called to output a real live
2812 formal parameter declaration. If it's the latter, then this function
2813 is only being called to output a TAG_formal_parameter DIE to stand as
2814 a placeholder for some formal argument type of some subprogram type. */
2817 output_formal_parameter_die (arg)
2820 register tree decl = arg;
2823 if (TREE_CODE (decl) == PARM_DECL)
2824 type = TREE_TYPE (decl);
2827 type = decl; /* we were called with a type, not a decl */
2831 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
2832 sibling_attribute ();
2835 name_and_src_coords_attributes (decl);
2836 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2837 location_or_const_value_attribute (decl);
2840 type_attribute (type, 0, 0);
2843 /* Output a DIE to represent a declared function (either file-scope
2844 or block-local) which has "external linkage" (according to ANSI-C). */
2847 output_global_subroutine_die (arg)
2850 register tree decl = arg;
2851 register tree type = TREE_TYPE (decl);
2852 register tree return_type = TREE_TYPE (type);
2854 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
2855 sibling_attribute ();
2857 name_and_src_coords_attributes (decl);
2858 inline_attribute (decl);
2859 prototyped_attribute (type);
2860 member_attribute (DECL_CONTEXT (decl));
2861 type_attribute (return_type, 0, 0);
2862 if (!TREE_EXTERNAL (decl))
2864 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2866 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
2867 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2868 high_pc_attribute (func_end_label);
2872 /* Output a DIE to represent a declared data object (either file-scope
2873 or block-local) which has "external linkage" (according to ANSI-C). */
2876 output_global_variable_die (arg)
2879 register tree decl = arg;
2880 register tree type = TREE_TYPE (decl);
2882 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
2883 sibling_attribute ();
2884 name_and_src_coords_attributes (decl);
2885 member_attribute (DECL_CONTEXT (decl));
2886 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
2887 if (!TREE_EXTERNAL (decl))
2888 location_or_const_value_attribute (decl);
2892 /* TAG_inline_subroutine has been retired by the UI/PLSIG. We're
2893 now supposed to use either TAG_subroutine or TAG_global_subroutine
2894 (depending on whether or not the function in question has internal
2895 or external linkage) and we're supposed to just put in an AT_inline
2898 output_inline_subroutine_die (arg)
2901 register tree decl = arg;
2902 register tree type = TREE_TYPE (decl);
2903 register tree return_type = TREE_TYPE (type);
2905 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inline_subroutine);
2906 sibling_attribute ();
2908 name_and_src_coords_attributes (decl);
2909 prototyped_attribute (type);
2910 member_attribute (DECL_CONTEXT (decl));
2911 type_attribute (return_type, 0, 0);
2913 /* Note: For each inline function which gets an out-of-line body
2914 generated for it, we want to generate AT_low_pc and AT_high_pc
2915 attributes here for the function's out-of-line body.
2917 Unfortunately, the decision as to whether or not to generate an
2918 out-of-line body for any given inline function may not be made
2919 until we reach the end of the containing scope for the given
2920 inline function (because only then will it be known if the
2921 function was ever even called).
2923 For this reason, the output of DIEs representing file-scope inline
2924 functions gets delayed until a special post-pass which happens only
2925 after we have reached the end of the compilation unit. Because of
2926 this mechanism, we can always be sure (by the time we reach here)
2927 that TREE_ASM_WRITTEN(decl) will correctly indicate whether or not
2928 there was an out-of-line body generated for this inline function.
2931 if (!TREE_EXTERNAL (decl))
2933 if (TREE_ASM_WRITTEN (decl))
2935 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2937 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
2938 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
2939 high_pc_attribute (func_end_label);
2946 output_label_die (arg)
2949 register tree decl = arg;
2950 register rtx insn = DECL_RTL (decl);
2952 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
2953 sibling_attribute ();
2954 name_and_src_coords_attributes (decl);
2956 /* When optimization is enabled (with -O) the code in jump.c and in flow.c
2957 may cause insns representing one of more of the user's own labels to
2958 be deleted. This happens whenever it is determined that a given label
2961 In such cases, we here generate an abbreviated form of a label DIE.
2962 This abbreviated version does *not* have a low_pc attribute. This
2963 should signify to the debugger that the label has been optimized away.
2965 Note that a CODE_LABEL can get deleted either by begin converted into
2966 a NOTE_INSN_DELETED note, or by simply having its INSN_DELETED_P flag
2967 set to true. We handle both cases here.
2970 if (GET_CODE (insn) == CODE_LABEL && ! INSN_DELETED_P (insn))
2972 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2974 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
2975 (unsigned) INSN_UID (insn));
2976 low_pc_attribute (label);
2981 output_lexical_block_die (arg)
2984 register tree stmt = arg;
2985 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
2986 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2988 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
2989 sibling_attribute ();
2991 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
2992 low_pc_attribute (begin_label);
2993 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
2994 high_pc_attribute (end_label);
2998 output_inlined_subroutine_die (arg)
3001 register tree stmt = arg;
3002 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3003 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3005 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
3006 sibling_attribute ();
3008 sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
3009 low_pc_attribute (begin_label);
3010 sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
3011 high_pc_attribute (end_label);
3014 /* Output a DIE to represent a declared data object (either file-scope
3015 or block-local) which has "internal linkage" (according to ANSI-C). */
3018 output_local_variable_die (arg)
3021 register tree decl = arg;
3022 register tree type = TREE_TYPE (decl);
3024 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
3025 sibling_attribute ();
3026 name_and_src_coords_attributes (decl);
3027 member_attribute (DECL_CONTEXT (decl));
3028 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3029 location_or_const_value_attribute (decl);
3033 output_member_die (arg)
3036 register tree decl = arg;
3038 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
3039 sibling_attribute ();
3040 name_and_src_coords_attributes (decl);
3041 member_attribute (DECL_CONTEXT (decl));
3042 type_attribute (member_declared_type (decl),
3043 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3044 if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */
3046 byte_size_attribute (decl);
3047 bit_size_attribute (decl);
3048 bit_offset_attribute (decl);
3050 data_member_location_attribute (decl);
3054 /* Don't generate either pointer_type DIEs or reference_type DIEs. According
3055 to the 4-4-90 Dwarf draft spec (just after requirement #47):
3057 These two type entries are not currently generated by any compiler.
3058 Since the only way to name a pointer (or reference) type is C or C++
3059 is via a "typedef", an entry with the "typedef" tag is generated
3062 We keep this code here just in case these types of DIEs may be needed
3063 to represent certain things in other languages (e.g. Pascal) someday.
3067 output_pointer_type_die (arg)
3070 register tree type = arg;
3072 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
3073 sibling_attribute ();
3074 equate_type_number_to_die_number (type);
3075 member_attribute (TYPE_CONTEXT (type));
3076 type_attribute (TREE_TYPE (type), 0, 0);
3080 output_reference_type_die (arg)
3083 register tree type = arg;
3085 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
3086 sibling_attribute ();
3087 equate_type_number_to_die_number (type);
3088 member_attribute (TYPE_CONTEXT (type));
3089 type_attribute (TREE_TYPE (type), 0, 0);
3093 output_ptr_to_mbr_type_die (arg)
3096 register tree type = arg;
3098 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
3099 sibling_attribute ();
3100 equate_type_number_to_die_number (type);
3101 member_attribute (TYPE_CONTEXT (type));
3102 containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
3103 type_attribute (TREE_TYPE (type), 0, 0);
3107 output_compile_unit_die (arg)
3110 register char *main_input_filename = arg;
3112 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
3113 sibling_attribute ();
3115 name_attribute (main_input_filename);
3120 sprintf (producer, "%s %s", language_string, version_string);
3121 producer_attribute (producer);
3124 if (strcmp (language_string, "GNU C++") == 0)
3125 language_attribute (LANG_C_PLUS_PLUS);
3126 else if (flag_traditional)
3127 language_attribute (LANG_C);
3129 language_attribute (LANG_C89);
3130 low_pc_attribute (TEXT_BEGIN_LABEL);
3131 high_pc_attribute (TEXT_END_LABEL);
3132 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3133 stmt_list_attribute (LINE_BEGIN_LABEL);
3134 last_filename = xstrdup (main_input_filename);
3137 char *wd = getpwd ();
3139 comp_dir_attribute (wd);
3142 if (debug_info_level >= DINFO_LEVEL_NORMAL)
3144 sf_names_attribute (SFNAMES_BEGIN_LABEL);
3145 src_info_attribute (SRCINFO_BEGIN_LABEL);
3146 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
3147 mac_info_attribute (MACINFO_BEGIN_LABEL);
3152 output_string_type_die (arg)
3155 register tree type = arg;
3157 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
3158 sibling_attribute ();
3159 member_attribute (TYPE_CONTEXT (type));
3161 /* Fudge the string length attribute for now. */
3163 string_length_attribute (
3164 TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
3168 output_structure_type_die (arg)
3171 register tree type = arg;
3173 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
3174 sibling_attribute ();
3175 equate_type_number_to_die_number (type);
3176 name_attribute (type_tag (type));
3177 member_attribute (TYPE_CONTEXT (type));
3179 /* If this type has been completed, then give it a byte_size attribute
3180 and prepare to give a list of members. Otherwise, don't do either of
3181 these things. In the latter case, we will not be generating a list
3182 of members (since we don't have any idea what they might be for an
3183 incomplete type). */
3185 if (TYPE_SIZE (type))
3188 byte_size_attribute (type);
3192 /* Output a DIE to represent a declared function (either file-scope
3193 or block-local) which has "internal linkage" (according to ANSI-C). */
3196 output_local_subroutine_die (arg)
3199 register tree decl = arg;
3200 register tree type = TREE_TYPE (decl);
3201 register tree return_type = TREE_TYPE (type);
3202 char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3204 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
3205 sibling_attribute ();
3207 name_and_src_coords_attributes (decl);
3208 inline_attribute (decl);
3209 prototyped_attribute (type);
3210 member_attribute (DECL_CONTEXT (decl));
3211 type_attribute (return_type, 0, 0);
3213 /* Avoid getting screwed up in cases where a function was declared static
3214 but where no definition was ever given for it. */
3216 if (TREE_ASM_WRITTEN (decl))
3218 low_pc_attribute (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
3219 sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number);
3220 high_pc_attribute (func_end_label);
3225 output_subroutine_type_die (arg)
3228 register tree type = arg;
3229 register tree return_type = TREE_TYPE (type);
3231 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
3232 sibling_attribute ();
3234 equate_type_number_to_die_number (type);
3235 prototyped_attribute (type);
3236 member_attribute (TYPE_CONTEXT (type));
3237 type_attribute (return_type, 0, 0);
3241 output_typedef_die (arg)
3244 register tree decl = arg;
3245 register tree type = TREE_TYPE (decl);
3247 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
3248 sibling_attribute ();
3249 name_and_src_coords_attributes (decl);
3250 member_attribute (DECL_CONTEXT (decl));
3251 type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
3255 output_union_type_die (arg)
3258 register tree type = arg;
3260 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
3261 sibling_attribute ();
3262 equate_type_number_to_die_number (type);
3263 name_attribute (type_tag (type));
3264 member_attribute (TYPE_CONTEXT (type));
3266 /* If this type has been completed, then give it a byte_size attribute
3267 and prepare to give a list of members. Otherwise, don't do either of
3268 these things. In the latter case, we will not be generating a list
3269 of members (since we don't have any idea what they might be for an
3270 incomplete type). */
3272 if (TYPE_SIZE (type))
3275 byte_size_attribute (type);
3279 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
3280 at the end of an (ANSI prototyped) formal parameters list. */
3283 output_unspecified_parameters_die (arg)
3286 register tree decl_or_type = arg;
3288 ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
3289 sibling_attribute ();
3291 /* This kludge is here only for the sake of being compatible with what
3292 the USL CI5 C compiler does. The specification of Dwarf Version 1
3293 doesn't say that TAG_unspecified_parameters DIEs should contain any
3294 attributes other than the AT_sibling attribute, but they are certainly
3295 allowed to contain additional attributes, and the CI5 compiler
3296 generates AT_name, AT_fund_type, and AT_location attributes within
3297 TAG_unspecified_parameters DIEs which appear in the child lists for
3298 DIEs representing function definitions, so we do likewise here. */
3300 if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
3302 name_attribute ("...");
3303 fund_type_attribute (FT_pointer);
3304 /* location_attribute (?); */
3309 output_padded_null_die (arg)
3312 ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */
3315 /*************************** end of DIEs *********************************/
3317 /* Generate some type of DIE. This routine generates the generic outer
3318 wrapper stuff which goes around all types of DIE's (regardless of their
3319 TAGs. All forms of DIEs start with a DIE-specific label, followed by a
3320 DIE-length word, followed by the guts of the DIE itself. After the guts
3321 of the DIE, there must always be a terminator label for the DIE. */
3324 output_die (die_specific_output_function, param)
3325 register void (*die_specific_output_function)();
3326 register void *param;
3328 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3329 char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3331 current_dienum = NEXT_DIE_NUM;
3332 NEXT_DIE_NUM = next_unused_dienum;
3334 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3335 sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
3337 /* Write a label which will act as the name for the start of this DIE. */
3339 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3341 /* Write the DIE-length word. */
3343 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
3345 /* Fill in the guts of the DIE. */
3347 next_unused_dienum++;
3348 die_specific_output_function (param);
3350 /* Write a label which will act as the name for the end of this DIE. */
3352 ASM_OUTPUT_LABEL (asm_out_file, end_label);
3356 end_sibling_chain ()
3358 char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
3360 current_dienum = NEXT_DIE_NUM;
3361 NEXT_DIE_NUM = next_unused_dienum;
3363 sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
3365 /* Write a label which will act as the name for the start of this DIE. */
3367 ASM_OUTPUT_LABEL (asm_out_file, begin_label);
3369 /* Write the DIE-length word. */
3371 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
3376 /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
3377 TAG_unspecified_parameters DIE) to represent the types of the formal
3378 parameters as specified in some function type specification (except
3379 for those which appear as part of a function *definition*).
3381 Note that we must be careful here to output all of the parameter DIEs
3382 *before* we output any DIEs needed to represent the types of the formal
3383 parameters. This keeps svr4 SDB happy because it (incorrectly) thinks
3384 that the first non-parameter DIE it sees ends the formal parameter list.
3388 output_formal_types (function_or_method_type)
3389 register tree function_or_method_type;
3392 register tree formal_type;
3393 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
3395 /* In the case where we are generating a formal types list for a C++
3396 non-static member function type, skip over the first thing on the
3397 TYPE_ARG_TYPES list because it only represents the type of the
3398 hidden `this pointer'. The debugger should be able to figure
3399 out (without being explicitly told) that this non-static member
3400 function type takes a `this pointer' and should be able to figure
3401 what the type of that hidden parameter is from the AT_member
3402 attribute of the parent TAG_subroutine_type DIE. */
3404 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
3405 first_parm_type = TREE_CHAIN (first_parm_type);
3407 /* Make our first pass over the list of formal parameter types and output
3408 a TAG_formal_parameter DIE for each one. */
3410 for (link = first_parm_type; link; link = TREE_CHAIN (link))
3412 formal_type = TREE_VALUE (link);
3413 if (formal_type == void_type_node)
3416 /* Output a (nameless) DIE to represent the formal parameter itself. */
3418 output_die (output_formal_parameter_die, formal_type);
3421 /* If this function type has an ellipsis, add a TAG_unspecified_parameters
3422 DIE to the end of the parameter list. */
3424 if (formal_type != void_type_node)
3425 output_die (output_unspecified_parameters_die, function_or_method_type);
3427 /* Make our second (and final) pass over the list of formal parameter types
3428 and output DIEs to represent those types (as necessary). */
3430 for (link = TYPE_ARG_TYPES (function_or_method_type);
3432 link = TREE_CHAIN (link))
3434 formal_type = TREE_VALUE (link);
3435 if (formal_type == void_type_node)
3438 output_type (formal_type, function_or_method_type);
3442 /* Remember a type in the pending_types_list. */
3448 if (pending_types == pending_types_allocated)
3450 pending_types_allocated += PENDING_TYPES_INCREMENT;
3452 = (tree *) xrealloc (pending_types_list,
3453 sizeof (tree) * pending_types_allocated);
3455 pending_types_list[pending_types++] = type;
3457 /* Mark the pending type as having been output already (even though
3458 it hasn't been). This prevents the type from being added to the
3459 pending_types_list more than once. */
3461 TREE_ASM_WRITTEN (type) = 1;
3464 /* Return non-zero if it is legitimate to output DIEs to represent a
3465 given type while we are generating the list of child DIEs for some
3466 DIE associated with a given scope.
3468 This function returns non-zero if *either* of the following two conditions
3471 o the type actually belongs to the given scope (as evidenced
3472 by its TYPE_CONTEXT value), or
3474 o the type is anonymous, and the `scope' in question is *not*
3475 a RECORD_TYPE or UNION_TYPE.
3477 In theory, we should be able to generate DIEs for anonymous types
3478 *anywhere* (since the scope of an anonymous type is irrelevant)
3479 however svr4 SDB doesn't want to see other type DIEs within the
3480 lists of child DIEs for a TAG_structure_type or TAG_union_type DIE.
3482 Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
3483 or it may point to a BLOCK node (for types local to a block), or to a
3484 FUNCTION_DECL node (for types local to the heading of some function
3485 definition), or to a FUNCTION_TYPE node (for types local to the
3486 prototyped parameter list of a function type specification), or to a
3487 RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types).
3489 The `scope' parameter should likewise be NULL or should point to a
3490 BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
3491 node, or a UNION_TYPE node.
3493 This function is used only for deciding when to "pend" and when to
3494 "un-pend" types to/from the pending_types_list.
3496 Note that we sometimes make use of this "type pending" feature in a
3497 rather twisted way to temporarily delay the production of DIEs for the
3498 types of formal parameters. (We do this just to make svr4 SDB happy.)
3499 It order to delay the production of DIEs representing types of formal
3500 parameters, callers of this function supply `fake_containing_scope' as
3501 the `scope' parameter to this function. Given that fake_containing_scope
3502 is *not* the containing scope for *any* other type, the desired effect
3503 is achieved, i.e. output of DIEs representing types is temporarily
3504 suspended, and any type DIEs which would have been output otherwise
3505 are instead placed onto the pending_types_list. Later on, we can force
3506 these (temporarily pended) types to be output simply by calling
3507 `output_pending_types_for_scope' with an actual argument equal to the
3508 true scope of the types we temporarily pended.
3512 type_ok_for_scope (type, scope)
3514 register tree scope;
3516 return (TYPE_CONTEXT (type) == scope
3517 || (TYPE_NAME (type) == NULL
3518 && TREE_CODE (scope) != RECORD_TYPE
3519 && TREE_CODE (scope) != UNION_TYPE));
3522 /* Output any pending types (from the pending_types list) which we can output
3523 now (given the limitations of the scope that we are working on now).
3525 For each type output, remove the given type from the pending_types_list
3526 *before* we try to output it.
3528 Note that we have to process the list in beginning-to-end order,
3529 because the call made here to output_type may cause yet more types
3530 to be added to the end of the list, and we may have to output some
3535 output_pending_types_for_scope (containing_scope)
3536 register tree containing_scope;
3538 register unsigned i;
3540 for (i = 0; i < pending_types; )
3542 register tree type = pending_types_list[i];
3544 if (type_ok_for_scope (type, containing_scope))
3546 register tree *mover;
3547 register tree *limit;
3550 limit = &pending_types_list[pending_types];
3551 for (mover = &pending_types_list[i]; mover < limit; mover++)
3552 *mover = *(mover+1);
3554 /* Un-mark the type as having been output already (because it
3555 hasn't been, really). Then call output_type to generate a
3556 Dwarf representation of it. */
3558 TREE_ASM_WRITTEN (type) = 0;
3559 output_type (type, containing_scope);
3561 /* Don't increment the loop counter in this case because we
3562 have shifted all of the subsequent pending types down one
3563 element in the pending_types_list array. */
3571 output_type (type, containing_scope)
3573 register tree containing_scope;
3575 if (type == 0 || type == error_mark_node)
3578 /* We are going to output a DIE to represent the unqualified version of
3579 of this type (i.e. without any const or volatile qualifiers) so get
3580 the main variant (i.e. the unqualified version) of this type now. */
3582 type = TYPE_MAIN_VARIANT (type);
3584 if (TREE_ASM_WRITTEN (type))
3587 /* Don't generate any DIEs for this type now unless it is OK to do so
3588 (based upon what `type_ok_for_scope' tells us). */
3590 if (! type_ok_for_scope (type, containing_scope))
3596 switch (TREE_CODE (type))
3602 case REFERENCE_TYPE:
3603 /* For these types, all that is required is that we output a DIE
3604 (or a set of DIEs) to represent that "basis" type. */
3605 output_type (TREE_TYPE (type), containing_scope);
3609 /* This code is used for C++ pointer-to-data-member types. */
3610 /* Output a description of the relevant class type. */
3611 output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
3612 /* Output a description of the type of the object pointed to. */
3613 output_type (TREE_TYPE (type), containing_scope);
3614 /* Now output a DIE to represent this pointer-to-data-member type
3616 output_die (output_ptr_to_mbr_type_die, type);
3620 output_type (TREE_TYPE (type), containing_scope);
3621 output_die (output_set_type_die, type);
3625 output_type (TREE_TYPE (type), containing_scope);
3626 abort (); /* No way to represent these in Dwarf yet! */
3630 output_type (TREE_TYPE (type), containing_scope);
3631 output_die (output_string_type_die, type);
3635 /* Force out return type (in case it wasn't forced out already). */
3636 output_type (TREE_TYPE (type), containing_scope);
3637 output_die (output_subroutine_type_die, type);
3638 output_formal_types (type);
3639 end_sibling_chain ();
3643 /* Force out return type (in case it wasn't forced out already). */
3644 output_type (TREE_TYPE (type), containing_scope);
3645 output_die (output_subroutine_type_die, type);
3646 output_formal_types (type);
3647 end_sibling_chain ();
3652 register tree element_type;
3654 element_type = TREE_TYPE (type);
3655 while (TREE_CODE (element_type) == ARRAY_TYPE)
3656 element_type = TREE_TYPE (element_type);
3658 output_type (element_type, containing_scope);
3659 output_die (output_array_type_die, type);
3667 /* For a non-file-scope tagged type, we can always go ahead and
3668 output a Dwarf description of this type right now, even if
3669 the type in question is still incomplete, because if this
3670 local type *was* ever completed anywhere within its scope,
3671 that complete definition would already have been attached to
3672 this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the
3673 time we reach this point. That's true because of the way the
3674 front-end does its processing of file-scope declarations (of
3675 functions and class types) within which other types might be
3676 nested. The C and C++ front-ends always gobble up such "local
3677 scope" things en-mass before they try to output *any* debugging
3678 information for any of the stuff contained inside them and thus,
3679 we get the benefit here of what is (in effect) a pre-resolution
3680 of forward references to tagged types in local scopes.
3682 Note however that for file-scope tagged types we cannot assume
3683 that such pre-resolution of forward references has taken place.
3684 A given file-scope tagged type may appear to be incomplete when
3685 we reach this point, but it may yet be given a full definition
3686 (at file-scope) later on during compilation. In order to avoid
3687 generating a premature (and possibly incorrect) set of Dwarf
3688 DIEs for such (as yet incomplete) file-scope tagged types, we
3689 generate nothing at all for as-yet incomplete file-scope tagged
3690 types here unless we are making our special "finalization" pass
3691 for file-scope things at the very end of compilation. At that
3692 time, we will certainly know as much about each file-scope tagged
3693 type as we are ever going to know, so at that point in time, we
3694 can safely generate correct Dwarf descriptions for these file-
3698 if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
3699 return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */
3701 /* Prevent infinite recursion in cases where the type of some
3702 member of this type is expressed in terms of this type itself. */
3704 TREE_ASM_WRITTEN (type) = 1;
3706 /* Output a DIE to represent the tagged type itself. */
3708 switch (TREE_CODE (type))
3711 output_die (output_enumeration_type_die, type);
3712 return; /* a special case -- nothing left to do so just return */
3715 output_die (output_structure_type_die, type);
3719 output_die (output_union_type_die, type);
3723 /* If this is not an incomplete type, output descriptions of
3724 each of its members.
3726 Note that as we output the DIEs necessary to represent the
3727 members of this record or union type, we will also be trying
3728 to output DIEs to represent the *types* of those members.
3729 However the `output_type' function (above) will specifically
3730 avoid generating type DIEs for member types *within* the list
3731 of member DIEs for this (containing) type execpt for those
3732 types (of members) which are explicitly marked as also being
3733 members of this (containing) type themselves. The g++ front-
3734 end can force any given type to be treated as a member of some
3735 other (containing) type by setting the TYPE_CONTEXT of the
3736 given (member) type to point to the TREE node representing the
3737 appropriate (containing) type.
3740 if (TYPE_SIZE (type))
3743 register tree normal_member;
3745 /* First output info about the data members and type members. */
3747 for (normal_member = TYPE_FIELDS (type);
3749 normal_member = TREE_CHAIN (normal_member))
3750 output_decl (normal_member, type);
3754 register tree vec_base;
3756 /* Now output info about the function members (if any). */
3758 vec_base = TYPE_METHODS (type);
3761 register tree first_func_member = TREE_VEC_ELT (vec_base, 0);
3762 register tree func_member;
3764 /* This isn't documented, but the first element of the
3765 vector of member functions can be NULL in cases where
3766 the class type in question didn't have either a
3767 constructor or a destructor declared for it. We have
3768 to make allowances for that here. */
3770 if (first_func_member == NULL)
3771 first_func_member = TREE_VEC_ELT (vec_base, 1);
3773 for (func_member = first_func_member;
3775 func_member = TREE_CHAIN (func_member))
3776 output_decl (func_member, type);
3780 end_sibling_chain (); /* Terminate member chain. */
3791 break; /* No DIEs needed for fundamental types. */
3793 case LANG_TYPE: /* No Dwarf representation currently defined. */
3800 TREE_ASM_WRITTEN (type) = 1;
3803 /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
3804 the things which are local to the given block. */
3810 register int have_significant_locals = 0;
3812 /* Ignore blocks never really used to make RTL. */
3814 if (! stmt || ! TREE_USED (stmt))
3817 /* Determine if this block contains any "significant" local declarations
3818 which we need to output DIEs for. */
3820 if (BLOCK_INLINE_FUNCTION (stmt))
3821 /* The outer scopes for inlinings *must* always be represented. */
3822 have_significant_locals = 1;
3824 if (debug_info_level > DINFO_LEVEL_TERSE)
3825 have_significant_locals = (BLOCK_VARS (stmt) != NULL);
3830 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3831 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
3833 have_significant_locals = 1;
3838 /* It would be a waste of space to generate a Dwarf TAG_lexical_block
3839 DIE for any block which contains no significant local declarations
3840 at all. Rather, in such cases we just call `output_decls_for_scope'
3841 so that any needed Dwarf info for any sub-blocks will get properly
3842 generated. Note that in terse mode, our definition of what constitutes
3843 a "significant" local declaration gets restricted to include only
3844 inlined function instances and local (nested) function definitions. */
3846 if (have_significant_locals)
3848 output_die (BLOCK_INLINE_FUNCTION (stmt)
3849 ? output_inlined_subroutine_die
3850 : output_lexical_block_die,
3852 output_decls_for_scope (stmt);
3853 end_sibling_chain ();
3856 output_decls_for_scope (stmt);
3859 /* Output all of the decls declared within a given scope (also called
3860 a `binding contour') and (recursively) all of it's sub-blocks. */
3863 output_decls_for_scope (stmt)
3866 /* Ignore blocks never really used to make RTL. */
3868 if (! stmt || ! TREE_USED (stmt))
3871 next_block_number++;
3873 /* Output the DIEs to represent all of the data objects, functions,
3874 typedefs, and tagged types declared directly within this block
3875 but not within any nested sub-blocks. */
3880 for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
3881 output_decl (decl, stmt);
3884 output_pending_types_for_scope (stmt);
3886 /* Output the DIEs to represent all sub-blocks (and the items declared
3887 therein) of this block. */
3890 register tree subblocks;
3892 for (subblocks = BLOCK_SUBBLOCKS (stmt);
3894 subblocks = BLOCK_CHAIN (subblocks))
3895 output_block (subblocks);
3899 /* Output Dwarf .debug information for a decl described by DECL. */
3902 output_decl (decl, containing_scope)
3904 register tree containing_scope;
3906 if (TREE_CODE (decl) == ERROR_MARK)
3909 /* If this ..._DECL node is marked to be ignored, then ignore it.
3910 But don't ignore a function definition, since that would screw
3911 up our count of blocks, and that it turn will completely screw up the
3912 the labels we will reference in subsequent AT_low_pc and AT_high_pc
3913 attributes (for subsequent blocks). */
3915 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
3918 switch (TREE_CODE (decl))
3921 /* The individual enumerators of an enum type get output when we
3922 output the Dwarf representation of the relevant enum type itself. */
3926 /* If we are in terse mode, don't output any DIEs to represent
3927 mere external function declarations. Also, if we are conforming
3928 to the DWARF version 1 specification, don't output DIEs for
3929 mere external function declarations. */
3931 if (TREE_EXTERNAL (decl))
3932 #if (DWARF_VERSION > 1)
3933 if (debug_info_level <= DINFO_LEVEL_TERSE)
3937 /* Before we describe the FUNCTION_DECL itself, make sure that we
3938 have described its return type. */
3940 output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
3942 /* If the following DIE will represent a function definition for a
3943 function with "extern" linkage, output a special "pubnames" DIE
3944 label just ahead of the actual DIE. A reference to this label
3945 was already generated in the .debug_pubnames section sub-entry
3946 for this function definition. */
3948 if (TREE_PUBLIC (decl))
3950 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3952 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
3953 ASM_OUTPUT_LABEL (asm_out_file, label);
3956 /* Now output a DIE to represent the function itself. */
3958 output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
3959 ? output_global_subroutine_die
3960 : output_local_subroutine_die,
3963 /* Now output descriptions of the arguments for this function.
3964 This gets (unnecessarily?) complex because of the fact that
3965 the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
3966 cases where there was a trailing `...' at the end of the formal
3967 parameter list. In order to find out if there was a trailing
3968 ellipsis or not, we must instead look at the type associated
3969 with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE.
3970 If the chain of type nodes hanging off of this FUNCTION_TYPE node
3971 ends with a void_type_node then there should *not* be an ellipsis
3974 /* In the case where we are describing an external function, all
3975 we need to do here (and all we *can* do here) is to describe
3976 the *types* of its formal parameters. */
3978 if (TREE_EXTERNAL (decl))
3979 output_formal_types (TREE_TYPE (decl));
3982 register tree arg_decls = DECL_ARGUMENTS (decl);
3984 /* In the case where the FUNCTION_DECL represents a C++ non-static
3985 member function, skip over the first thing on the DECL_ARGUMENTS
3986 chain. It only represents the hidden `this pointer' parameter
3987 and the debugger should know implicitly that non-static member
3988 functions have such a thing, and should be able to figure out
3989 exactly what the type of each `this pointer' is (from the
3990 AT_member attribute of the parent TAG_subroutine DIE) without
3991 being explicitly told. */
3993 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
3994 arg_decls = TREE_CHAIN (arg_decls);
3997 register tree last_arg;
3999 last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK)
4000 ? tree_last (arg_decls)
4003 /* Generate DIEs to represent all known formal parameters, but
4004 don't do it if this looks like a varargs function. A given
4005 function is considered to be a varargs function if (and only
4006 if) its last named argument is named `__builtin_va_alist'. */
4009 || ! DECL_NAME (last_arg)
4010 || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)),
4011 "__builtin_va_alist"))
4015 /* WARNING! Kludge zone ahead! Here we have a special
4016 hack for svr4 SDB compatibility. Instead of passing the
4017 current FUNCTION_DECL node as the second parameter (i.e.
4018 the `containing_scope' parameter) to `output_decl' (as
4019 we ought to) we instead pass a pointer to our own private
4020 fake_containing_scope node. That node is a RECORD_TYPE
4021 node which NO OTHER TYPE may ever actually be a member of.
4023 This pointer will ultimately get passed into `output_type'
4024 as its `containing_scope' parameter. `Output_type' will
4025 then perform its part in the hack... i.e. it will pend
4026 the type of the formal parameter onto the pending_types
4027 list. Later on, when we are done generating the whole
4028 sequence of formal parameter DIEs for this function
4029 definition, we will un-pend all previously pended types
4030 of formal parameters for this function definition.
4032 This whole kludge prevents any type DIEs from being
4033 mixed in with the formal parameter DIEs. That's good
4034 because svr4 SDB believes that the list of formal
4035 parameter DIEs for a function ends wherever the first
4036 non-formal-parameter DIE appears. Thus, we have to
4037 keep the formal parameter DIEs segregated. They must
4038 all appear (consecutively) at the start of the list of
4039 children for the DIE representing the function definition.
4040 Then (and only then) may we output any additional DIEs
4041 needed to represent the types of these formal parameters.
4044 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
4045 if (TREE_CODE (parm) == PARM_DECL)
4046 output_decl (parm, fake_containing_scope);
4048 /* Now that we have finished generating all of the DIEs to
4049 represent the formal parameters themselves, force out
4050 any DIEs needed to represent their types. We do this
4051 simply by un-pending all previously pended types which
4052 can legitimately go into the chain of children DIEs for
4053 the current FUNCTION_DECL. */
4055 output_pending_types_for_scope (decl);
4059 /* Now try to decide if we should put an ellipsis at the end. */
4062 register int has_ellipsis = TRUE; /* default assumption */
4063 register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
4067 /* This function declaration/definition was prototyped. */
4069 /* If the list of formal argument types ends with a
4070 void_type_node, then the formals list did *not* end
4071 with an ellipsis. */
4073 if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
4074 has_ellipsis = FALSE;
4078 /* This function declaration/definition was not prototyped. */
4080 /* Note that all non-prototyped function *declarations* are
4081 assumed to represent varargs functions (until proven
4084 if (DECL_INITIAL (decl)) /* if this is a func definition */
4087 has_ellipsis = FALSE; /* no args == (void) */
4090 /* For a non-prototyped function definition which
4091 declares one or more formal parameters, if the name
4092 of the first formal parameter is *not*
4093 __builtin_va_alist then we must assume that this
4094 is *not* a varargs function. */
4096 if (DECL_NAME (arg_decls)
4097 && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
4098 "__builtin_va_alist"))
4099 has_ellipsis = FALSE;
4105 output_die (output_unspecified_parameters_die, decl);
4109 /* Output Dwarf info for all of the stuff within the body of the
4110 function (if it has one - it may be just a declaration). */
4113 register tree outer_scope = DECL_INITIAL (decl);
4115 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
4117 /* Note that here, `outer_scope' is a pointer to the outermost
4118 BLOCK node created to represent the body of a function.
4119 This outermost BLOCK actually represents the outermost
4120 binding contour for the function, i.e. the contour in which
4121 the function's formal parameters get declared. Just within
4122 this contour, there will be another (nested) BLOCK which
4123 represents the function's outermost block. We don't want
4124 to generate a lexical_block DIE to represent the outermost
4125 block of a function body, because that is not really an
4126 independent scope according to ANSI C rules. Rather, it is
4127 the same scope in which the parameters were declared and
4128 for Dwarf, we do not generate a TAG_lexical_block DIE for
4129 that scope. We must however see to it that the LABEL_DECLs
4130 associated with `outer_scope' get DIEs generated for them. */
4133 register tree label;
4135 for (label = BLOCK_VARS (outer_scope);
4137 label = TREE_CHAIN (label))
4138 output_decl (label, outer_scope);
4141 output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
4143 /* Finally, force out any pending types which are local to the
4144 outermost block of this function definition. These will
4145 all have a TYPE_CONTEXT which points to the FUNCTION_DECL
4148 output_pending_types_for_scope (decl);
4152 /* Generate a terminator for the list of stuff `owned' by this
4155 end_sibling_chain ();
4160 /* If we are in terse mode, don't generate any DIEs to represent
4161 any actual typedefs. Note that even when we are in terse mode,
4162 we must still output DIEs to represent those tagged types which
4163 are used (directly or indirectly) in the specification of either
4164 a return type or a formal parameter type of some function. */
4166 if (debug_info_level <= DINFO_LEVEL_TERSE)
4167 if (DECL_NAME (decl) != NULL
4168 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4171 output_type (TREE_TYPE (decl), containing_scope);
4173 /* Note that unlike the gcc front end (which generates a NULL named
4174 TYPE_DECL node for each complete tagged type, each array type,
4175 and each function type node created) the g++ front end generates
4176 a *named* TYPE_DECL node for each tagged type node created.
4177 Unfortunately, these g++ TYPE_DECL nodes cause us to output many
4178 superfluous and unnecessary TAG_typedef DIEs here. When g++ is
4179 fixed to stop generating these superfluous named TYPE_DECL nodes,
4180 the superfluous TAG_typedef DIEs will likewise cease. */
4182 if (DECL_NAME (decl))
4183 /* Output a DIE to represent the typedef itself. */
4184 output_die (output_typedef_die, decl);
4188 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4189 output_die (output_label_die, decl);
4193 /* If we are conforming to the DWARF version 1 specification, don't
4194 generated any DIEs to represent mere external object declarations. */
4196 #if (DWARF_VERSION <= 1)
4197 if (TREE_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
4201 /* If we are in terse mode, don't generate any DIEs to represent
4202 any variable declarations or definitions. */
4204 if (debug_info_level <= DINFO_LEVEL_TERSE)
4207 /* Output any DIEs that are needed to specify the type of this data
4210 output_type (TREE_TYPE (decl), containing_scope);
4212 /* If the following DIE will represent a data object definition for a
4213 data object with "extern" linkage, output a special "pubnames" DIE
4214 label just ahead of the actual DIE. A reference to this label
4215 was already generated in the .debug_pubnames section sub-entry
4216 for this data object definition. */
4218 if (TREE_PUBLIC (decl))
4220 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4222 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
4223 ASM_OUTPUT_LABEL (asm_out_file, label);
4226 /* Now output the DIE to represent the data object itself. */
4228 output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl)
4229 ? output_global_variable_die : output_local_variable_die,
4234 /* Ignore the nameless fields that are used to skip bits. */
4235 if (DECL_NAME (decl) != 0)
4237 output_type (member_declared_type (decl), containing_scope);
4238 output_die (output_member_die, decl);
4243 /* Force out the type of this formal, if it was not forced out yet.
4244 Note that here we can run afowl of a bug in "classic" svr4 SDB.
4245 It should be able to grok the presence of type DIEs within a list
4246 of TAG_formal_parameter DIEs, but it doesn't. */
4248 output_type (TREE_TYPE (decl), containing_scope);
4249 output_die (output_formal_parameter_die, decl);
4258 dwarfout_file_scope_decl (decl, set_finalizing)
4260 register int set_finalizing;
4262 if (TREE_CODE (decl) == ERROR_MARK)
4265 /* If this ..._DECL node is marked to be ignored, then ignore it. We
4266 gotta hope that the node in question doesn't represent a function
4267 definition. If it does, then totally ignoring it is bound to screw
4268 up our count of blocks, and that it turn will completely screw up the
4269 the labels we will reference in subsequent AT_low_pc and AT_high_pc
4270 attributes (for subsequent blocks). (It's too bad that BLOCK nodes
4271 don't carry their own sequence numbers with them!) */
4273 if (DECL_IGNORED_P (decl))
4275 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4280 switch (TREE_CODE (decl))
4284 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
4285 a builtin function. Explicit programmer-supplied declarations of
4286 these same functions should NOT be ignored however. */
4288 if (TREE_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
4291 /* Ignore this FUNCTION_DECL if it refers to a file-scope extern
4292 function declaration and if the declaration was never even
4293 referenced from within this entire compilation unit. We
4294 suppress these DIEs in order to save space in the .debug section
4295 (by eliminating entries which are probably useless). Note that
4296 we must not suppress block-local extern declarations (whether
4297 used or not) because that would screw-up the debugger's name
4298 lookup mechanism and cause it to miss things which really ought
4299 to be in scope at a given point. */
4301 if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
4304 if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl))
4306 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4308 /* Output a .debug_pubnames entry for a public function
4309 defined in this compilation unit. */
4311 fputc ('\n', asm_out_file);
4312 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4313 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4314 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4315 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4316 IDENTIFIER_POINTER (DECL_NAME (decl)));
4317 ASM_OUTPUT_POP_SECTION (asm_out_file);
4324 /* Ignore this VAR_DECL if it refers to a file-scope extern data
4325 object declaration and if the declaration was never even
4326 referenced from within this entire compilation unit. We
4327 suppress these DIEs in order to save space in the .debug section
4328 (by eliminating entries which are probably useless). Note that
4329 we must not suppress block-local extern declarations (whether
4330 used or not) because that would screw-up the debugger's name
4331 lookup mechanism and cause it to miss things which really ought
4332 to be in scope at a given point. */
4334 if (TREE_EXTERNAL (decl) && !TREE_USED (decl))
4337 if (TREE_PUBLIC (decl)
4338 && ! TREE_EXTERNAL (decl)
4339 && GET_CODE (DECL_RTL (decl)) == MEM)
4341 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4343 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4345 /* Output a .debug_pubnames entry for a public variable
4346 defined in this compilation unit. */
4348 fputc ('\n', asm_out_file);
4349 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4350 sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
4351 ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
4352 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4353 IDENTIFIER_POINTER (DECL_NAME (decl)));
4354 ASM_OUTPUT_POP_SECTION (asm_out_file);
4357 if (DECL_INITIAL (decl) == NULL)
4359 /* Output a .debug_aranges entry for a public variable
4360 which is tentatively defined in this compilation unit. */
4362 fputc ('\n', asm_out_file);
4363 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4364 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
4365 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4366 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
4367 (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
4368 ASM_OUTPUT_POP_SECTION (asm_out_file);
4372 /* If we are in terse mode, don't generate any DIEs to represent
4373 any variable declarations or definitions. */
4375 if (debug_info_level <= DINFO_LEVEL_TERSE)
4381 /* Don't generate any DIEs to represent the standard built-in types. */
4383 if (DECL_SOURCE_LINE (decl) == 0)
4386 /* If we are in terse mode, don't generate any DIEs to represent
4387 any actual typedefs. Note that even when we are in terse mode,
4388 we must still output DIEs to represent those tagged types which
4389 are used (directly or indirectly) in the specification of either
4390 a return type or a formal parameter type of some function. */
4392 if (debug_info_level <= DINFO_LEVEL_TERSE)
4393 if (DECL_NAME (decl) != NULL
4394 || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
4403 fputc ('\n', asm_out_file);
4404 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4405 finalizing = set_finalizing;
4406 output_decl (decl, NULL_TREE);
4408 /* NOTE: The call above to `output_decl' may have caused one or more
4409 file-scope named types (i.e. tagged types) to be placed onto the
4410 pending_types_list. We have to get those types off of that list
4411 at some point, and this is the perfect time to do it. If we didn't
4412 take them off now, they might still be on the list when cc1 finally
4413 exits. That might be OK if it weren't for the fact that when we put
4414 types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
4415 for these types, and that causes them never to be output unless
4416 `output_pending_types_for_scope' takes them off of the list and un-sets
4417 their TREE_ASM_WRITTEN flags. */
4419 output_pending_types_for_scope (NULL_TREE);
4421 /* The above call should have totally emptied the pending_types_list. */
4423 assert (pending_types == 0);
4425 ASM_OUTPUT_POP_SECTION (asm_out_file);
4427 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
4428 current_funcdef_number++;
4431 /* Output a marker (i.e. a label) for the beginning of the generated code
4432 for a lexical block. */
4435 dwarfout_begin_block (blocknum)
4436 register unsigned blocknum;
4438 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4441 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
4442 ASM_OUTPUT_LABEL (asm_out_file, label);
4445 /* Output a marker (i.e. a label) for the end of the generated code
4446 for a lexical block. */
4449 dwarfout_end_block (blocknum)
4450 register unsigned blocknum;
4452 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4455 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
4456 ASM_OUTPUT_LABEL (asm_out_file, label);
4459 /* Output a marker (i.e. a label) at a point in the assembly code which
4460 corresponds to a given source level label. */
4463 dwarfout_label (insn)
4466 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4468 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4471 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
4472 (unsigned) INSN_UID (insn));
4473 ASM_OUTPUT_LABEL (asm_out_file, label);
4477 /* Output a marker (i.e. a label) for the absolute end of the generated code
4478 for a function definition. This gets called *after* the epilogue code
4479 has been generated. */
4482 dwarfout_end_epilogue ()
4484 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4486 /* Output a label to mark the endpoint of the code generated for this
4489 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
4490 ASM_OUTPUT_LABEL (asm_out_file, label);
4494 shuffle_filename_entry (new_zeroth)
4495 register filename_entry *new_zeroth;
4497 filename_entry temp_entry;
4498 register filename_entry *limit_p;
4499 register filename_entry *move_p;
4501 if (new_zeroth == &filename_table[0])
4504 temp_entry = *new_zeroth;
4506 /* Shift entries up in the table to make room at [0]. */
4508 limit_p = &filename_table[0];
4509 for (move_p = new_zeroth; move_p > limit_p; move_p--)
4510 *move_p = *(move_p-1);
4512 /* Install the found entry at [0]. */
4514 filename_table[0] = temp_entry;
4517 /* Create a new (string) entry for the .debug_sfnames section. */
4520 generate_new_sfname_entry ()
4522 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4524 fputc ('\n', asm_out_file);
4525 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
4526 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
4527 ASM_OUTPUT_LABEL (asm_out_file, label);
4528 ASM_OUTPUT_DWARF_STRING (asm_out_file,
4529 filename_table[0].name
4530 ? filename_table[0].name
4532 ASM_OUTPUT_POP_SECTION (asm_out_file);
4535 /* Lookup a filename (in the list of filenames that we know about here in
4536 dwarfout.c) and return its "index". The index of each (known) filename
4537 is just a unique number which is associated with only that one filename.
4538 We need such numbers for the sake of generating labels (in the
4539 .debug_sfnames section) and references to those unique labels (in the
4540 .debug_srcinfo and .debug_macinfo sections).
4542 If the filename given as an argument is not found in our current list,
4543 add it to the list and assign it the next available unique index number.
4545 Whatever we do (i.e. whether we find a pre-existing filename or add a new
4546 one), we shuffle the filename found (or added) up to the zeroth entry of
4547 our list of filenames (which is always searched linearly). We do this so
4548 as to optimize the most common case for these filename lookups within
4549 dwarfout.c. The most common case by far is the case where we call
4550 lookup_filename to lookup the very same filename that we did a lookup
4551 on the last time we called lookup_filename. We make sure that this
4552 common case is fast because such cases will constitute 99.9% of the
4553 lookups we ever do (in practice).
4555 If we add a new filename entry to our table, we go ahead and generate
4556 the corresponding entry in the .debug_sfnames section right away.
4557 Doing so allows us to avoid tickling an assembler bug (present in some
4558 m68k assemblers) which yields assembly-time errors in cases where the
4559 difference of two label addresses is taken and where the two labels
4560 are in a section *other* than the one where the difference is being
4561 calculated, and where at least one of the two symbol references is a
4562 forward reference. (This bug could be tickled by our .debug_srcinfo
4563 entries if we don't output their corresponding .debug_sfnames entries
4568 lookup_filename (file_name)
4571 register filename_entry *search_p;
4572 register filename_entry *limit_p = &filename_table[ft_entries];
4574 for (search_p = filename_table; search_p < limit_p; search_p++)
4575 if (!strcmp (file_name, search_p->name))
4577 /* When we get here, we have found the filename that we were
4578 looking for in the filename_table. Now we want to make sure
4579 that it gets moved to the zero'th entry in the table (if it
4580 is not already there) so that subsequent attempts to find the
4581 same filename will find it as quickly as possible. */
4583 shuffle_filename_entry (search_p);
4584 return filename_table[0].number;
4587 /* We come here whenever we have a new filename which is not registered
4588 in the current table. Here we add it to the table. */
4590 /* Prepare to add a new table entry by making sure there is enough space
4591 in the table to do so. If not, expand the current table. */
4593 if (ft_entries == ft_entries_allocated)
4595 ft_entries_allocated += FT_ENTRIES_INCREMENT;
4597 = (filename_entry *)
4598 xrealloc (filename_table,
4599 ft_entries_allocated * sizeof (filename_entry));
4602 /* Initially, add the new entry at the end of the filename table. */
4604 filename_table[ft_entries].number = ft_entries;
4605 filename_table[ft_entries].name = xstrdup (file_name);
4607 /* Shuffle the new entry into filename_table[0]. */
4609 shuffle_filename_entry (&filename_table[ft_entries]);
4611 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4612 generate_new_sfname_entry ();
4615 return filename_table[0].number;
4619 generate_srcinfo_entry (line_entry_num, files_entry_num)
4620 unsigned line_entry_num;
4621 unsigned files_entry_num;
4623 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4625 fputc ('\n', asm_out_file);
4626 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4627 sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
4628 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
4629 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
4630 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
4631 ASM_OUTPUT_POP_SECTION (asm_out_file);
4635 dwarfout_line (filename, line)
4636 register char *filename;
4637 register unsigned line;
4639 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4641 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4642 static unsigned last_line_entry_num = 0;
4643 static unsigned prev_file_entry_num = (unsigned) -1;
4644 register unsigned this_file_entry_num = lookup_filename (filename);
4647 sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
4648 ASM_OUTPUT_LABEL (asm_out_file, label);
4650 fputc ('\n', asm_out_file);
4651 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4653 if (this_file_entry_num != prev_file_entry_num)
4655 char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
4657 sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
4658 ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
4662 register char *tail = rindex (filename, '/');
4668 fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
4669 UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
4671 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
4672 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
4673 ASM_OUTPUT_POP_SECTION (asm_out_file);
4675 if (this_file_entry_num != prev_file_entry_num)
4676 generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
4677 prev_file_entry_num = this_file_entry_num;
4681 /* Generate an entry in the .debug_macinfo section. */
4684 generate_macinfo_entry (type_and_offset, string)
4685 register char *type_and_offset;
4686 register char *string;
4688 fputc ('\n', asm_out_file);
4689 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4690 fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
4691 ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
4692 ASM_OUTPUT_POP_SECTION (asm_out_file);
4696 dwarfout_start_new_source_file (filename)
4697 register char *filename;
4699 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4700 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
4702 sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
4703 sprintf (type_and_offset, "0x%08x+%s-%s",
4704 ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
4705 generate_macinfo_entry (type_and_offset, "");
4709 dwarfout_resume_previous_source_file (lineno)
4710 register unsigned lineno;
4712 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4714 sprintf (type_and_offset, "0x%08x+%u",
4715 ((unsigned) MACINFO_resume << 24), lineno);
4716 generate_macinfo_entry (type_and_offset, "");
4719 /* Called from check_newline in c-parse.y. The `buffer' parameter
4720 contains the tail part of the directive line, i.e. the part which
4721 is past the initial whitespace, #, whitespace, directive-name,
4725 dwarfout_define (lineno, buffer)
4726 register unsigned lineno;
4727 register char *buffer;
4729 static int initialized = 0;
4730 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4734 dwarfout_start_new_source_file (primary_filename);
4737 sprintf (type_and_offset, "0x%08x+%u",
4738 ((unsigned) MACINFO_define << 24), lineno);
4739 generate_macinfo_entry (type_and_offset, buffer);
4742 /* Called from check_newline in c-parse.y. The `buffer' parameter
4743 contains the tail part of the directive line, i.e. the part which
4744 is past the initial whitespace, #, whitespace, directive-name,
4748 dwarfout_undef (lineno, buffer)
4749 register unsigned lineno;
4750 register char *buffer;
4752 char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
4754 sprintf (type_and_offset, "0x%08x+%u",
4755 ((unsigned) MACINFO_undef << 24), lineno);
4756 generate_macinfo_entry (type_and_offset, buffer);
4759 /* Set up for Dwarf output at the start of compilation. */
4762 dwarfout_init (asm_out_file, main_input_filename)
4763 register FILE *asm_out_file;
4764 register char *main_input_filename;
4766 /* Remember the name of the primary input file. */
4768 primary_filename = main_input_filename;
4770 /* Allocate the initial hunk of the pending_sibling_stack. */
4772 pending_sibling_stack
4774 xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
4775 pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
4776 pending_siblings = 1;
4778 /* Allocate the initial hunk of the filename_table. */
4781 = (filename_entry *)
4782 xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
4783 ft_entries_allocated = FT_ENTRIES_INCREMENT;
4786 /* Allocate the initial hunk of the pending_types_list. */
4789 = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
4790 pending_types_allocated = PENDING_TYPES_INCREMENT;
4793 /* Create an artificial RECORD_TYPE node which we can use in our hack
4794 to get the DIEs representing types of formal parameters to come out
4795 only *after* the DIEs for the formal parameters themselves. */
4797 fake_containing_scope = make_node (RECORD_TYPE);
4799 /* Output a starting label for the .text section. */
4801 fputc ('\n', asm_out_file);
4802 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
4803 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
4804 ASM_OUTPUT_POP_SECTION (asm_out_file);
4806 /* Output a starting label for the .data section. */
4808 fputc ('\n', asm_out_file);
4809 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
4810 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
4811 ASM_OUTPUT_POP_SECTION (asm_out_file);
4813 /* Output a starting label for the .data1 section. */
4815 fputc ('\n', asm_out_file);
4816 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
4817 ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
4818 ASM_OUTPUT_POP_SECTION (asm_out_file);
4820 /* Output a starting label for the .rodata section. */
4822 fputc ('\n', asm_out_file);
4823 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
4824 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
4825 ASM_OUTPUT_POP_SECTION (asm_out_file);
4827 /* Output a starting label for the .rodata1 section. */
4829 fputc ('\n', asm_out_file);
4830 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
4831 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
4832 ASM_OUTPUT_POP_SECTION (asm_out_file);
4834 /* Output a starting label for the .bss section. */
4836 fputc ('\n', asm_out_file);
4837 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
4838 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
4839 ASM_OUTPUT_POP_SECTION (asm_out_file);
4841 if (debug_info_level >= DINFO_LEVEL_NORMAL)
4843 /* Output a starting label and an initial (compilation directory)
4844 entry for the .debug_sfnames section. The starting label will be
4845 referenced by the initial entry in the .debug_srcinfo section. */
4847 fputc ('\n', asm_out_file);
4848 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
4849 ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
4851 register char *pwd = getpwd ();
4852 register unsigned len = strlen (pwd);
4853 register char *dirname = (char *) xmalloc (len + 2);
4855 strcpy (dirname, pwd);
4856 strcpy (dirname + len, "/");
4857 ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
4860 ASM_OUTPUT_POP_SECTION (asm_out_file);
4862 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
4864 /* Output a starting label for the .debug_macinfo section. This
4865 label will be referenced by the AT_mac_info attribute in the
4866 TAG_compile_unit DIE. */
4868 fputc ('\n', asm_out_file);
4869 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
4870 ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
4871 ASM_OUTPUT_POP_SECTION (asm_out_file);
4874 /* Generate the initial entry for the .line section. */
4876 fputc ('\n', asm_out_file);
4877 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
4878 ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
4879 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
4880 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4881 ASM_OUTPUT_POP_SECTION (asm_out_file);
4883 /* Generate the initial entry for the .debug_srcinfo section. */
4885 fputc ('\n', asm_out_file);
4886 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
4887 ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
4888 ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
4889 ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
4890 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
4891 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
4892 #ifdef DWARF_TIMESTAMPS
4893 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
4895 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
4897 ASM_OUTPUT_POP_SECTION (asm_out_file);
4899 /* Generate the initial entry for the .debug_pubnames section. */
4901 fputc ('\n', asm_out_file);
4902 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
4903 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
4904 ASM_OUTPUT_POP_SECTION (asm_out_file);
4906 /* Generate the initial entry for the .debug_aranges section. */
4908 fputc ('\n', asm_out_file);
4909 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
4910 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
4911 ASM_OUTPUT_POP_SECTION (asm_out_file);
4914 /* Setup first DIE number == 1. */
4915 NEXT_DIE_NUM = next_unused_dienum++;
4917 /* Generate the initial DIE for the .debug section. Note that the
4918 (string) value given in the AT_name attribute of the TAG_compile_unit
4919 DIE will (typically) be a relative pathname and that this pathname
4920 should be taken as being relative to the directory from which the
4921 compiler was invoked when the given (base) source file was compiled. */
4923 fputc ('\n', asm_out_file);
4924 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4925 ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
4926 output_die (output_compile_unit_die, main_input_filename);
4927 ASM_OUTPUT_POP_SECTION (asm_out_file);
4929 fputc ('\n', asm_out_file);
4932 /* Output stuff that dwarf requires at the end of every file. */
4937 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4939 fputc ('\n', asm_out_file);
4940 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
4942 /* Mark the end of the chain of siblings which represent all file-scope
4943 declarations in this compilation unit. */
4945 /* The (null) DIE which represents the terminator for the (sibling linked)
4946 list of file-scope items is *special*. Normally, we would just call
4947 end_sibling_chain at this point in order to output a word with the
4948 value `4' and that word would act as the terminator for the list of
4949 DIEs describing file-scope items. Unfortunately, if we were to simply
4950 do that, the label that would follow this DIE in the .debug section
4951 (i.e. `..D2') would *not* be properly aligned (as it must be on some
4952 machines) to a 4 byte boundary.
4954 In order to force the label `..D2' to get aligned to a 4 byte boundary,
4955 the trick used is to insert extra (otherwise useless) padding bytes
4956 into the (null) DIE that we know must precede the ..D2 label in the
4957 .debug section. The amount of padding required can be anywhere between
4958 0 and 3 bytes. The length word at the start of this DIE (i.e. the one
4959 with the padding) would normally contain the value 4, but now it will
4960 also have to include the padding bytes, so it will instead have some
4961 value in the range 4..7.
4963 Fortunately, the rules of Dwarf say that any DIE whose length word
4964 contains *any* value less than 8 should be treated as a null DIE, so
4965 this trick works out nicely. Clever, eh? Don't give me any credit
4966 (or blame). I didn't think of this scheme. I just conformed to it.
4969 output_die (output_padded_null_die, (void *)0);
4972 sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
4973 ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */
4974 ASM_OUTPUT_POP_SECTION (asm_out_file);
4976 /* Output a terminator label for the .text section. */
4978 fputc ('\n', asm_out_file);
4979 ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
4980 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
4981 ASM_OUTPUT_POP_SECTION (asm_out_file);
4983 /* Output a terminator label for the .data section. */
4985 fputc ('\n', asm_out_file);
4986 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
4987 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
4988 ASM_OUTPUT_POP_SECTION (asm_out_file);
4990 /* Output a terminator label for the .data1 section. */
4992 fputc ('\n', asm_out_file);
4993 ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
4994 ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
4995 ASM_OUTPUT_POP_SECTION (asm_out_file);
4997 /* Output a terminator label for the .rodata section. */
4999 fputc ('\n', asm_out_file);
5000 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
5001 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
5002 ASM_OUTPUT_POP_SECTION (asm_out_file);
5004 /* Output a terminator label for the .rodata1 section. */
5006 fputc ('\n', asm_out_file);
5007 ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
5008 ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
5009 ASM_OUTPUT_POP_SECTION (asm_out_file);
5011 /* Output a terminator label for the .bss section. */
5013 fputc ('\n', asm_out_file);
5014 ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
5015 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
5016 ASM_OUTPUT_POP_SECTION (asm_out_file);
5018 if (debug_info_level >= DINFO_LEVEL_NORMAL)
5020 /* Output a terminating entry for the .line section. */
5022 fputc ('\n', asm_out_file);
5023 ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
5024 ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
5025 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5026 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
5027 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5028 ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
5029 ASM_OUTPUT_POP_SECTION (asm_out_file);
5031 /* Output a terminating entry for the .debug_srcinfo section. */
5033 fputc ('\n', asm_out_file);
5034 ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
5035 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
5036 LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
5037 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
5038 ASM_OUTPUT_POP_SECTION (asm_out_file);
5040 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
5042 /* Output terminating entries for the .debug_macinfo section. */
5044 dwarfout_resume_previous_source_file (0);
5046 fputc ('\n', asm_out_file);
5047 ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
5048 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5049 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5050 ASM_OUTPUT_POP_SECTION (asm_out_file);
5053 /* Generate the terminating entry for the .debug_pubnames section. */
5055 fputc ('\n', asm_out_file);
5056 ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
5057 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5058 ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
5059 ASM_OUTPUT_POP_SECTION (asm_out_file);
5061 /* Generate the terminating entries for the .debug_aranges section.
5063 Note that we want to do this only *after* we have output the end
5064 labels (for the various program sections) which we are going to
5065 refer to here. This allows us to work around a bug in the m68k
5066 svr4 assembler. That assembler gives bogus assembly-time errors
5067 if (within any given section) you try to take the difference of
5068 two relocatable symbols, both of which are located within some
5069 other section, and if one (or both?) of the symbols involved is
5070 being forward-referenced. By generating the .debug_aranges
5071 entries at this late point in the assembly output, we skirt the
5072 issue simply by avoiding forward-references.
5075 fputc ('\n', asm_out_file);
5076 ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
5078 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
5079 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
5081 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
5082 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
5084 ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
5085 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
5088 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
5089 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
5090 RODATA_BEGIN_LABEL);
5092 ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
5093 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
5094 RODATA1_BEGIN_LABEL);
5096 ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
5097 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
5099 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5100 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5102 ASM_OUTPUT_POP_SECTION (asm_out_file);
5106 #endif /* DWARF_DEBUGGING_INFO */