1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com). Derived from the
4 DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #ifdef DWARF2_DEBUGGING_INFO
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
37 /* #define NDEBUG 1 */
40 extern char *getpwd ();
42 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
43 regarding the GNU implementation of DWARF. */
45 /* NOTE: In the comments in this file, many references are made to
46 "Debugging Information Entries". This term is abbreviated as `DIE'
47 throughout the remainder of this file. */
49 #if defined(__GNUC__) && (NDEBUG == 1)
50 #define inline static inline
56 /* An internal representation of the DWARF output is built, and then
57 walked to generate the DWARF debugging info. The walk of the internal
58 representation is done after the entire program has been compiled.
59 The types below are used to describe the internal representation. */
61 /* Each DIE may have a series of attribute/value pairs. Values
62 can take on several forms. The forms that are used in this
63 impelementation are listed below. */
69 dw_val_class_unsigned_const,
70 dw_val_class_double_const,
75 dw_val_class_section_offset,
80 /* Various DIE's use offsets relative to the beginning of the
81 .debug_info section to refer to each other. */
82 typedef long int dw_offset;
84 /* Define typedefs here to avoid circular dependencies. */
85 typedef struct die_struct *dw_die_ref;
86 typedef struct dw_attr_struct *dw_attr_ref;
87 typedef struct dw_val_struct *dw_val_ref;
88 typedef struct dw_line_info_struct *dw_line_info_ref;
89 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
90 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
91 typedef struct dw_cfi_struct *dw_cfi_ref;
92 typedef struct dw_fde_struct *dw_fde_ref;
93 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
94 typedef struct pubname_struct *pubname_ref;
95 typedef dw_die_ref *arange_ref;
97 /* Describe a double word constant value. */
98 typedef struct dw_double_const_struct
100 unsigned long dw_dbl_hi;
101 unsigned long dw_dbl_low;
105 /* Each entry in the line_info_table maintains the file and
106 line nuber associated with the label generated for that
107 entry. The label gives the PC value associated with
108 the line number entry. */
109 typedef struct dw_line_info_struct
111 unsigned long dw_file_num;
112 unsigned long dw_line_num;
116 /* Line information for functions in separate sections; each one gets its
118 typedef struct dw_separate_line_info_struct
120 unsigned long dw_file_num;
121 unsigned long dw_line_num;
122 unsigned long function;
124 dw_separate_line_info_entry;
126 /* The dw_val_node describes an attibute's value, as it is
127 represnted internally. */
128 typedef struct dw_val_struct
130 dw_val_class val_class;
134 dw_loc_descr_ref val_loc;
136 long unsigned val_unsigned;
137 dw_dbl_const val_dbl_const;
138 dw_die_ref val_die_ref;
139 unsigned val_fde_index;
143 unsigned char val_flag;
149 /* Locations in memory are described using a sequence of stack machine
151 typedef struct dw_loc_descr_struct
153 dw_loc_descr_ref dw_loc_next;
154 enum dwarf_location_atom dw_loc_opc;
155 dw_val_node dw_loc_oprnd1;
156 dw_val_node dw_loc_oprnd2;
160 /* Each DIE attribute has a field specifying the attribute kind,
161 a link to the next attribute in the chain, and an attribute value.
162 Attributes are typically linked below the DIE they modify. */
163 typedef struct dw_attr_struct
165 enum dwarf_attribute dw_attr;
166 dw_attr_ref dw_attr_next;
167 dw_val_node dw_attr_val;
171 /* Call frames are described using a sequence of Call Frame
172 Information instructions. The register number, offset
173 and address fields are provided as possible operands;
174 their use is selected by the opcode field. */
175 typedef union dw_cfi_oprnd_struct
177 unsigned long dw_cfi_reg_num;
178 long int dw_cfi_offset;
183 typedef struct dw_cfi_struct
185 dw_cfi_ref dw_cfi_next;
186 enum dwarf_call_frame_info dw_cfi_opc;
187 dw_cfi_oprnd dw_cfi_oprnd1;
188 dw_cfi_oprnd dw_cfi_oprnd2;
192 /* All call frame descriptions (FDE's) in the GCC generated DWARF
193 refer to a single Common Information Entry (CIE), defined at
194 the beginning of the .debug_frame section. This used of a single
195 CIE obviates the need to keep track of multiple CIE's
196 in the DWARF generation routines below. */
197 typedef struct dw_fde_struct
199 unsigned long dw_fde_offset;
201 char *dw_fde_current_label;
203 dw_cfi_ref dw_fde_cfi;
207 /* The Debugging Information Entry (DIE) structure */
208 typedef struct die_struct
210 enum dwarf_tag die_tag;
211 dw_attr_ref die_attr;
212 dw_attr_ref die_attr_last;
213 dw_die_ref die_parent;
214 dw_die_ref die_child;
215 dw_die_ref die_child_last;
217 dw_offset die_offset;
218 unsigned long die_abbrev;
222 /* The pubname structure */
223 typedef struct pubname_struct
230 /* How to start an assembler comment. */
231 #ifndef ASM_COMMENT_START
232 #define ASM_COMMENT_START ";#"
235 /* Define a macro which returns non-zero for a TYPE_DECL which was
236 implicitly generated for a tagged type.
238 Note that unlike the gcc front end (which generates a NULL named
239 TYPE_DECL node for each complete tagged type, each array type, and
240 each function type node created) the g++ front end generates a
241 _named_ TYPE_DECL node for each tagged type node created.
242 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
243 generate a DW_TAG_typedef DIE for them. */
244 #define TYPE_DECL_IS_STUB(decl) \
245 (DECL_NAME (decl) == NULL \
246 || (DECL_ARTIFICIAL (decl) \
247 && is_tagged_type (TREE_TYPE (decl)) \
248 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
250 /* Information concerning the compilation unit's programming
251 language, and compiler version. */
252 extern int flag_traditional;
253 extern char *version_string;
254 extern char *language_string;
256 /* Maximum size (in bytes) of an artificially generated label. */
257 #define MAX_ARTIFICIAL_LABEL_BYTES 30
259 /* Make sure we know the sizes of the various types dwarf can describe. These
260 are only defaults. If the sizes are different for your target, you should
261 override these values by defining the appropriate symbols in your tm.h
263 #ifndef CHAR_TYPE_SIZE
264 #define CHAR_TYPE_SIZE BITS_PER_UNIT
267 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
270 /* The size in bytes of a DWARF field indicating an offset or length
271 relative to a debug info section, specified to be 4 bytes in the DWARF-2
272 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
273 #ifndef DWARF_OFFSET_SIZE
274 #define DWARF_OFFSET_SIZE 4
277 #define DWARF_VERSION 2
279 /* Fixed size portion of the DWARF compilation unit header. */
280 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
282 /* Fixed size portion of debugging line information prolog. */
283 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
285 /* Fixed size portion of public names info. */
286 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
288 /* Round SIZE up to the nearest BOUNDARY. */
289 #define DWARF_ROUND(SIZE,BOUNDARY) \
290 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
292 /* Fixed size portion of the address range info. */
293 #define DWARF_ARANGES_HEADER_SIZE \
294 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
296 /* Fixed size portion of the CIE (including the length field). */
297 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5)
299 /* The un-padded size of the CIE. Initialized in calc_fde_sizes, used
300 in output_call_frame_info. */
301 static unsigned cie_size;
303 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
304 #define DWARF_CIE_DATA_ALIGNMENT -4
306 /* Fixed size portion of the FDE. */
307 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
309 /* Define the architecture-dependent minimum instruction length (in bytes).
310 In this implementation of DWARF, this field is used for information
311 purposes only. Since GCC generates assembly language, we have
312 no a priori knowledge of how many instruction bytes are generated
313 for each source line, and therefore can use only the DW_LNE_set_address
314 and DW_LNS_fixed_advance_pc line information commands. */
315 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
316 #define DWARF_LINE_MIN_INSTR_LENGTH 4
319 /* Minimum line offset in a special line info. opcode.
320 This value was chosen to give a reasonable range of values. */
321 #define DWARF_LINE_BASE -10
323 /* First special line opcde - leave room for the standard opcodes. */
324 #define DWARF_LINE_OPCODE_BASE 10
326 /* Range of line offsets in a special line info. opcode. */
327 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
329 /* Flag that indicates the initial value of the is_stmt_start flag.
330 In the present implementation, we do not mark any lines as
331 the beginning of a source statement, because that information
332 is not made available by the GCC front-end. */
333 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
335 /* This location is used by calc_die_sizes() to keep track
336 the offset of each DIE within the .debug_info section. */
337 static unsigned long next_die_offset;
339 /* This location is used by calc_fde_sizes() to keep track
340 the offset of each FDE within the .debug_frame section. */
341 static unsigned long next_fde_offset;
343 /* Record the root of the DIE's built for the current compilation unit. */
344 dw_die_ref comp_unit_die;
346 /* The number of DIEs with a NULL parent waiting to be relocated. */
347 static int limbo_die_count;
349 /* Pointer to an array of filenames referenced by this compilation unit. */
350 static char **file_table;
352 /* Total number of entries in the table (i.e. array) pointed to by
353 `file_table'. This is the *total* and includes both used and unused
355 static unsigned file_table_allocated;
357 /* Number of entries in the file_table which are actually in use. */
358 static unsigned file_table_in_use;
360 /* Size (in elements) of increments by which we may expand the filename
362 #define FILE_TABLE_INCREMENT 64
364 /* Local pointer to the name of the main input file. Initialized in
366 static char *primary_filename;
368 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
369 which their beginnings are encountered. We output Dwarf debugging info
370 that refers to the beginnings and ends of the ranges of code for each
371 lexical block. The labels themselves are generated in final.c, which
372 assigns numbers to the blocks in the same way. */
373 static unsigned next_block_number = 2;
375 /* A pointer to the base of a table of references to DIE's that describe
376 declarations. The table is indexed by DECL_UID() which is a unique
377 number, indentifying each decl. */
378 static dw_die_ref *decl_die_table;
380 /* Number of elements currently allocated for the decl_die_table. */
381 static unsigned decl_die_table_allocated;
383 /* Number of elements in decl_die_table currently in use. */
384 static unsigned decl_die_table_in_use;
386 /* Size (in elements) of increments by which we may expand the
388 #define DECL_DIE_TABLE_INCREMENT 256
390 /* A pointer to the base of a table of references to declaration
391 scopes. This table is a display which tracks the nesting
392 of declaration scopes at the current scope and containing
393 scopes. This table is used to find the proper place to
394 define type declaration DIE's. */
395 static tree *decl_scope_table;
397 /* Number of elements currently allocated for the decl_scope_table. */
398 static unsigned decl_scope_table_allocated;
400 /* Current level of nesting of declataion scopes. */
401 static unsigned decl_scope_depth;
403 /* Size (in elements) of increments by which we may expand the
405 #define DECL_SCOPE_TABLE_INCREMENT 64
407 /* A pointer to the base of a list of references to DIE's that
408 are uniquely identified by their tag, presence/absence of
409 children DIE's, and list of attribute/value pairs. */
410 static dw_die_ref *abbrev_die_table;
412 /* Number of elements currently allocated for abbrev_die_table. */
413 static unsigned abbrev_die_table_allocated;
415 /* Number of elements in type_die_table currently in use. */
416 static unsigned abbrev_die_table_in_use;
418 /* Size (in elements) of increments by which we may expand the
420 #define ABBREV_DIE_TABLE_INCREMENT 256
422 /* A pointer to the base of a table that contains line information
423 for each source code line in .text in the compilation unit. */
424 static dw_line_info_ref line_info_table;
426 /* Number of elements currently allocated for line_info_table. */
427 static unsigned line_info_table_allocated;
429 /* Number of elements in separate_line_info_table currently in use. */
430 static unsigned separate_line_info_table_in_use;
432 /* A pointer to the base of a table that contains line information
433 for each source code line outside of .text in the compilation unit. */
434 static dw_separate_line_info_ref separate_line_info_table;
436 /* Number of elements currently allocated for separate_line_info_table. */
437 static unsigned separate_line_info_table_allocated;
439 /* Number of elements in line_info_table currently in use. */
440 static unsigned line_info_table_in_use;
442 /* Size (in elements) of increments by which we may expand the
444 #define LINE_INFO_TABLE_INCREMENT 1024
446 /* A pointer to the base of a table that contains frame description
447 information for each routine. */
448 static dw_fde_ref fde_table;
450 /* Number of elements currently allocated for fde_table. */
451 static unsigned fde_table_allocated;
453 /* Number of elements in fde_table currently in use. */
454 static unsigned fde_table_in_use;
456 /* Size (in elements) of increments by which we may expand the
458 #define FDE_TABLE_INCREMENT 256
460 /* A list of call frame insns for the CIE. */
461 static dw_cfi_ref cie_cfi_head;
463 /* A pointer to the base of a table that contains a list of publicly
465 static pubname_ref pubname_table;
467 /* Number of elements currently allocated for pubname_table. */
468 static unsigned pubname_table_allocated;
470 /* Number of elements in pubname_table currently in use. */
471 static unsigned pubname_table_in_use;
473 /* Size (in elements) of increments by which we may expand the
475 #define PUBNAME_TABLE_INCREMENT 64
477 /* A pointer to the base of a table that contains a list of publicly
479 static arange_ref arange_table;
481 /* Number of elements currently allocated for arange_table. */
482 static unsigned arange_table_allocated;
484 /* Number of elements in arange_table currently in use. */
485 static unsigned arange_table_in_use;
487 /* Size (in elements) of increments by which we may expand the
489 #define ARANGE_TABLE_INCREMENT 64
491 /* A pointer to the base of a list of pending types which we haven't
492 generated DIEs for yet, but which we will have to come back to
495 static tree *pending_types_list;
497 /* Number of elements currently allocated for the pending_types_list. */
499 static unsigned pending_types_allocated;
501 /* Number of elements of pending_types_list currently in use. */
503 static unsigned pending_types;
505 /* Size (in elements) of increments by which we may expand the pending
506 types list. Actually, a single hunk of space of this size should
507 be enough for most typical programs. */
509 #define PENDING_TYPES_INCREMENT 64
511 /* The number of the current function definition for which debugging
512 information is being generated. These numbers range from 1 up to the
513 maximum number of function definitions contained within the current
514 compilation unit. These numbers are used to create unique label id's
515 unique to each function definition. */
516 static unsigned current_funcdef_number = 1;
518 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
519 attribute that accelerates the lookup of the FDE associated
520 with the subprogram. This variable holds the table index of the FDE
521 associated with the current function (body) definition. */
522 static unsigned current_funcdef_fde;
524 /* Record whether the function being analyzed contains inlined functions. */
525 static int current_function_has_inlines;
526 static int comp_unit_has_inlines;
528 /* A pointer to the ..._DECL node which we have most recently been working
529 on. We keep this around just in case something about it looks screwy and
530 we want to tell the user what the source coordinates for the actual
532 static tree dwarf_last_decl;
534 /* Forward declarations for functions defined in this file. */
535 static void gen_type_die ();
536 static void add_type_attribute ();
537 static void decls_for_scope ();
538 static void gen_decl_die ();
539 static unsigned lookup_filename ();
540 static int constant_size PROTO((long unsigned));
541 static enum dwarf_form value_format PROTO((dw_val_ref));
542 static unsigned reg_number ();
544 /* Definitions of defaults for assembler-dependent names of various
545 pseudo-ops and section names.
546 Theses may be overridden in the tm.h file (if necessary) for a particular
548 #ifndef UNALIGNED_SHORT_ASM_OP
549 #define UNALIGNED_SHORT_ASM_OP ".2byte"
551 #ifndef UNALIGNED_INT_ASM_OP
552 #define UNALIGNED_INT_ASM_OP ".4byte"
554 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
555 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
558 #define ASM_BYTE_OP ".byte"
561 #ifndef UNALIGNED_OFFSET_ASM_OP
562 #define UNALIGNED_OFFSET_ASM_OP \
563 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
566 #ifndef UNALIGNED_WORD_ASM_OP
567 #define UNALIGNED_WORD_ASM_OP \
568 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
571 /* Data and reference forms for relocatable data. */
572 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
573 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
575 /* Pseudo-op for defining a new section. */
576 #ifndef SECTION_ASM_OP
577 #define SECTION_ASM_OP ".section"
580 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
581 print the SECTION_ASM_OP and the section name. The default here works for
582 almost all svr4 assemblers, except for the sparc, where the section name
583 must be enclosed in double quotes. (See sparcv4.h). */
584 #ifndef SECTION_FORMAT
585 #define SECTION_FORMAT "\t%s\t%s\n"
588 /* Section names used to hold DWARF debugging information. */
589 #ifndef DEBUG_SECTION
590 #define DEBUG_SECTION ".debug_info"
592 #ifndef ABBREV_SECTION
593 #define ABBREV_SECTION ".debug_abbrev"
595 #ifndef ARANGES_SECTION
596 #define ARANGES_SECTION ".debug_aranges"
598 #ifndef DW_MACINFO_SECTION
599 #define DW_MACINFO_SECTION ".debug_macinfo"
601 #ifndef FRAME_SECTION
602 #define FRAME_SECTION ".debug_frame"
605 #define LINE_SECTION ".debug_line"
608 #define LOC_SECTION ".debug_loc"
610 #ifndef PUBNAMES_SECTION
611 #define PUBNAMES_SECTION ".debug_pubnames"
614 #define STR_SECTION ".debug_str"
617 /* Standerd ELF section names for compiled code and data. */
619 #define TEXT_SECTION ".text"
622 #define DATA_SECTION ".data"
625 #define BSS_SECTION ".bss"
629 /* Definitions of defaults for formats and names of various special
630 (artificial) labels which may be generated within this file (when the -g
631 options is used and DWARF_DEBUGGING_INFO is in effect.
632 If necessary, these may be overridden from within the tm.h file, but
633 typically, overriding these defaults is unnecessary. */
635 char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
637 #ifndef TEXT_END_LABEL
638 #define TEXT_END_LABEL "Letext"
640 #ifndef DATA_END_LABEL
641 #define DATA_END_LABEL "Ledata"
643 #ifndef BSS_END_LABEL
644 #define BSS_END_LABEL "Lebss"
646 #ifndef INSN_LABEL_FMT
647 #define INSN_LABEL_FMT "LI%u_"
649 #ifndef BLOCK_BEGIN_LABEL
650 #define BLOCK_BEGIN_LABEL "LBB"
652 #ifndef BLOCK_END_LABEL
653 #define BLOCK_END_LABEL "LBE"
655 #ifndef BODY_BEGIN_LABEL
656 #define BODY_BEGIN_LABEL "Lbb"
658 #ifndef BODY_END_LABEL
659 #define BODY_END_LABEL "Lbe"
661 #ifndef FUNC_BEGIN_LABEL
662 #define FUNC_BEGIN_LABEL "LFB"
664 #ifndef FUNC_END_LABEL
665 #define FUNC_END_LABEL "LFE"
667 #ifndef LINE_CODE_LABEL
668 #define LINE_CODE_LABEL "LM"
670 #ifndef SEPARATE_LINE_CODE_LABEL
671 #define SEPARATE_LINE_CODE_LABEL "LSM"
674 /* Definitions of defaults for various types of primitive assembly language
675 output operations. These may be overridden from within the tm.h file,
676 but typically, that is unecessary. */
677 #ifndef ASM_OUTPUT_SECTION
678 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
679 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
682 #ifndef ASM_OUTPUT_DWARF_DELTA2
683 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
684 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
685 assemble_name (FILE, LABEL1); \
686 fprintf (FILE, "-"); \
687 assemble_name (FILE, LABEL2); \
691 #ifndef ASM_OUTPUT_DWARF_DELTA4
692 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
693 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
694 assemble_name (FILE, LABEL1); \
695 fprintf (FILE, "-"); \
696 assemble_name (FILE, LABEL2); \
700 #ifndef ASM_OUTPUT_DWARF_DELTA
701 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
702 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
703 assemble_name (FILE, LABEL1); \
704 fprintf (FILE, "-"); \
705 assemble_name (FILE, LABEL2); \
709 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
710 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
711 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
712 assemble_name (FILE, LABEL1); \
713 fprintf (FILE, "-"); \
714 assemble_name (FILE, LABEL2); \
718 #ifndef ASM_OUTPUT_DWARF_ADDR
719 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
720 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
721 assemble_name (FILE, LABEL); \
725 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
726 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
727 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
730 #ifndef ASM_OUTPUT_DWARF_OFFSET
731 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
732 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
733 assemble_name (FILE, LABEL); \
737 #ifndef ASM_OUTPUT_DWARF_DATA1
738 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
739 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
742 #ifndef ASM_OUTPUT_DWARF_DATA2
743 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
744 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
747 #ifndef ASM_OUTPUT_DWARF_DATA4
748 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
749 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
752 #ifndef ASM_OUTPUT_DWARF_DATA
753 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
754 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
755 (unsigned long) VALUE)
758 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
759 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
760 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
761 (unsigned long) VALUE)
764 #ifndef ASM_OUTPUT_DWARF_DATA8
765 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
767 if (WORDS_BIG_ENDIAN) \
769 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
770 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
774 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
775 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
780 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
781 newline is produced. When flag_verbose_asm is asserted, we add commnetary
782 at the end of the line, so we must avoid output of a newline here. */
783 #ifndef ASM_OUTPUT_DWARF_STRING
784 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
786 register int slen = strlen(P); \
787 register char *p = (P); \
789 fprintf (FILE, "\t.ascii \""); \
790 for (i = 0; i < slen; i++) \
792 register int c = p[i]; \
793 if (c == '\"' || c == '\\') \
795 if (c >= ' ' && c < 0177) \
799 fprintf (FILE, "\\%o", c); \
802 fprintf (FILE, "\\0\""); \
807 /* Convert a reference to the assembler name of a C-level name. This
808 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
809 a string rather than writing to a file. */
810 #ifndef ASM_NAME_TO_STRING
811 #define ASM_NAME_TO_STRING(STR, NAME) \
813 if ((NAME)[0] == '*') \
814 strcpy (STR, NAME+1); \
816 strcpy (STR, NAME); \
821 /* The DWARF 2 CFA column which tracks the return address. Normally this
822 is the column for PC, or the first column after all of the hard
824 #ifndef DWARF_FRAME_RETURN_COLUMN
826 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
828 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER + 1
832 /* The mapping from gcc register number to DWARF 2 CFA column number. By
833 default, we provide columns for all registers after the CFA column. */
834 #ifndef DWARF_FRAME_REGNUM
835 #define DWARF_FRAME_REGNUM(REG) (DBX_REGISTER_NUMBER (REG) + 1)
838 /************************ general utility functions **************************/
840 /* Return a pointer to a copy of the section string name 's' with all
841 attributes stripped off. */
846 register char *stripped, *p;
847 stripped = xstrdup (s);
849 while (*p && *p != ',')
855 /* Convert an integer constant expression into assembler syntax.
856 Addition and subtraction are the only arithmetic
857 that may appear in these expressions. This is an adaptation
858 of output_addr_const() in final.c. Here, the target of the
859 conversion is a string buffer. We can't use output_addr_const
860 directly, because it writes to a file. */
862 addr_const_to_string (str, x)
871 switch (GET_CODE (x))
881 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
886 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
887 ASM_NAME_TO_STRING (buf2, buf1);
892 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
893 ASM_NAME_TO_STRING (buf2, buf1);
899 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
909 /* This used to output parentheses around the expression, but that does
910 not work on the 386 (either ATT or BSD assembler). */
911 addr_const_to_string (buf1, XEXP (x, 0));
916 if (GET_MODE (x) == VOIDmode)
918 /* We can use %d if the number is one word and positive. */
919 if (CONST_DOUBLE_HIGH (x))
921 #if HOST_BITS_PER_WIDE_INT == 64
922 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
928 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
934 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
935 else if (CONST_DOUBLE_LOW (x) < 0)
937 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
942 CONST_DOUBLE_LOW (x));
945 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
950 CONST_DOUBLE_LOW (x));
954 /* We can't handle floating point constants; PRINT_OPERAND must
956 output_operand_lossage ("floating constant misused");
960 /* Some assemblers need integer constants to appear last (eg masm). */
961 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
963 addr_const_to_string (buf1, XEXP (x, 1));
965 if (INTVAL (XEXP (x, 0)) >= 0)
967 addr_const_to_string (buf1, XEXP (x, 0));
972 addr_const_to_string (buf1, XEXP (x, 0));
974 if (INTVAL (XEXP (x, 1)) >= 0)
976 addr_const_to_string (buf1, XEXP (x, 1));
982 /* Avoid outputting things like x-x or x+5-x, since some assemblers
983 can't handle that. */
984 x = simplify_subtraction (x);
985 if (GET_CODE (x) != MINUS)
988 addr_const_to_string (buf1, XEXP (x, 0));
991 if (GET_CODE (XEXP (x, 1)) == CONST_INT
992 && INTVAL (XEXP (x, 1)) < 0)
994 strcat (str, ASM_OPEN_PAREN);
995 addr_const_to_string (buf1, XEXP (x, 1));
997 strcat (str, ASM_CLOSE_PAREN);
1001 addr_const_to_string (buf1, XEXP (x, 1));
1008 addr_const_to_string (buf1, XEXP (x, 0));
1013 output_operand_lossage ("invalid expression as operand");
1017 /* Convert an address constant to a string, and return a pointer to
1018 a copy of the result, located on the heap. */
1024 addr_const_to_string (buf, x);
1025 return xstrdup (buf);
1028 /* Test if rtl node points to a psuedo register. */
1033 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1034 || ((GET_CODE (rtl) == SUBREG)
1035 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1039 /* Return a reference to a type, with its const and volatile qualifiers
1042 type_main_variant (type)
1045 type = TYPE_MAIN_VARIANT (type);
1047 /* There really should be only one main variant among any group of variants
1048 of a given type (and all of the MAIN_VARIANT values for all members of
1049 the group should point to that one type) but sometimes the C front-end
1050 messes this up for array types, so we work around that bug here. */
1051 if (TREE_CODE (type) == ARRAY_TYPE)
1053 while (type != TYPE_MAIN_VARIANT (type))
1054 type = TYPE_MAIN_VARIANT (type);
1059 /* Return non-zero if the given type node represents a tagged type. */
1061 is_tagged_type (type)
1064 register enum tree_code code = TREE_CODE (type);
1066 return (code == RECORD_TYPE || code == UNION_TYPE
1067 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1070 /* Convert a DIE tag into its string name. */
1072 dwarf_tag_name (tag)
1073 register unsigned tag;
1077 case DW_TAG_padding:
1078 return "DW_TAG_padding";
1079 case DW_TAG_array_type:
1080 return "DW_TAG_array_type";
1081 case DW_TAG_class_type:
1082 return "DW_TAG_class_type";
1083 case DW_TAG_entry_point:
1084 return "DW_TAG_entry_point";
1085 case DW_TAG_enumeration_type:
1086 return "DW_TAG_enumeration_type";
1087 case DW_TAG_formal_parameter:
1088 return "DW_TAG_formal_parameter";
1089 case DW_TAG_imported_declaration:
1090 return "DW_TAG_imported_declaration";
1092 return "DW_TAG_label";
1093 case DW_TAG_lexical_block:
1094 return "DW_TAG_lexical_block";
1096 return "DW_TAG_member";
1097 case DW_TAG_pointer_type:
1098 return "DW_TAG_pointer_type";
1099 case DW_TAG_reference_type:
1100 return "DW_TAG_reference_type";
1101 case DW_TAG_compile_unit:
1102 return "DW_TAG_compile_unit";
1103 case DW_TAG_string_type:
1104 return "DW_TAG_string_type";
1105 case DW_TAG_structure_type:
1106 return "DW_TAG_structure_type";
1107 case DW_TAG_subroutine_type:
1108 return "DW_TAG_subroutine_type";
1109 case DW_TAG_typedef:
1110 return "DW_TAG_typedef";
1111 case DW_TAG_union_type:
1112 return "DW_TAG_union_type";
1113 case DW_TAG_unspecified_parameters:
1114 return "DW_TAG_unspecified_parameters";
1115 case DW_TAG_variant:
1116 return "DW_TAG_variant";
1117 case DW_TAG_common_block:
1118 return "DW_TAG_common_block";
1119 case DW_TAG_common_inclusion:
1120 return "DW_TAG_common_inclusion";
1121 case DW_TAG_inheritance:
1122 return "DW_TAG_inheritance";
1123 case DW_TAG_inlined_subroutine:
1124 return "DW_TAG_inlined_subroutine";
1126 return "DW_TAG_module";
1127 case DW_TAG_ptr_to_member_type:
1128 return "DW_TAG_ptr_to_member_type";
1129 case DW_TAG_set_type:
1130 return "DW_TAG_set_type";
1131 case DW_TAG_subrange_type:
1132 return "DW_TAG_subrange_type";
1133 case DW_TAG_with_stmt:
1134 return "DW_TAG_with_stmt";
1135 case DW_TAG_access_declaration:
1136 return "DW_TAG_access_declaration";
1137 case DW_TAG_base_type:
1138 return "DW_TAG_base_type";
1139 case DW_TAG_catch_block:
1140 return "DW_TAG_catch_block";
1141 case DW_TAG_const_type:
1142 return "DW_TAG_const_type";
1143 case DW_TAG_constant:
1144 return "DW_TAG_constant";
1145 case DW_TAG_enumerator:
1146 return "DW_TAG_enumerator";
1147 case DW_TAG_file_type:
1148 return "DW_TAG_file_type";
1150 return "DW_TAG_friend";
1151 case DW_TAG_namelist:
1152 return "DW_TAG_namelist";
1153 case DW_TAG_namelist_item:
1154 return "DW_TAG_namelist_item";
1155 case DW_TAG_packed_type:
1156 return "DW_TAG_packed_type";
1157 case DW_TAG_subprogram:
1158 return "DW_TAG_subprogram";
1159 case DW_TAG_template_type_param:
1160 return "DW_TAG_template_type_param";
1161 case DW_TAG_template_value_param:
1162 return "DW_TAG_template_value_param";
1163 case DW_TAG_thrown_type:
1164 return "DW_TAG_thrown_type";
1165 case DW_TAG_try_block:
1166 return "DW_TAG_try_block";
1167 case DW_TAG_variant_part:
1168 return "DW_TAG_variant_part";
1169 case DW_TAG_variable:
1170 return "DW_TAG_variable";
1171 case DW_TAG_volatile_type:
1172 return "DW_TAG_volatile_type";
1173 case DW_TAG_MIPS_loop:
1174 return "DW_TAG_MIPS_loop";
1175 case DW_TAG_format_label:
1176 return "DW_TAG_format_label";
1177 case DW_TAG_function_template:
1178 return "DW_TAG_function_template";
1179 case DW_TAG_class_template:
1180 return "DW_TAG_class_template";
1182 return "DW_TAG_<unknown>";
1186 /* Convert a DWARF attribute code into its string name. */
1188 dwarf_attr_name (attr)
1189 register unsigned attr;
1194 return "DW_AT_sibling";
1195 case DW_AT_location:
1196 return "DW_AT_location";
1198 return "DW_AT_name";
1199 case DW_AT_ordering:
1200 return "DW_AT_ordering";
1201 case DW_AT_subscr_data:
1202 return "DW_AT_subscr_data";
1203 case DW_AT_byte_size:
1204 return "DW_AT_byte_size";
1205 case DW_AT_bit_offset:
1206 return "DW_AT_bit_offset";
1207 case DW_AT_bit_size:
1208 return "DW_AT_bit_size";
1209 case DW_AT_element_list:
1210 return "DW_AT_element_list";
1211 case DW_AT_stmt_list:
1212 return "DW_AT_stmt_list";
1214 return "DW_AT_low_pc";
1216 return "DW_AT_high_pc";
1217 case DW_AT_language:
1218 return "DW_AT_language";
1220 return "DW_AT_member";
1222 return "DW_AT_discr";
1223 case DW_AT_discr_value:
1224 return "DW_AT_discr_value";
1225 case DW_AT_visibility:
1226 return "DW_AT_visibility";
1228 return "DW_AT_import";
1229 case DW_AT_string_length:
1230 return "DW_AT_string_length";
1231 case DW_AT_common_reference:
1232 return "DW_AT_common_reference";
1233 case DW_AT_comp_dir:
1234 return "DW_AT_comp_dir";
1235 case DW_AT_const_value:
1236 return "DW_AT_const_value";
1237 case DW_AT_containing_type:
1238 return "DW_AT_containing_type";
1239 case DW_AT_default_value:
1240 return "DW_AT_default_value";
1242 return "DW_AT_inline";
1243 case DW_AT_is_optional:
1244 return "DW_AT_is_optional";
1245 case DW_AT_lower_bound:
1246 return "DW_AT_lower_bound";
1247 case DW_AT_producer:
1248 return "DW_AT_producer";
1249 case DW_AT_prototyped:
1250 return "DW_AT_prototyped";
1251 case DW_AT_return_addr:
1252 return "DW_AT_return_addr";
1253 case DW_AT_start_scope:
1254 return "DW_AT_start_scope";
1255 case DW_AT_stride_size:
1256 return "DW_AT_stride_size";
1257 case DW_AT_upper_bound:
1258 return "DW_AT_upper_bound";
1259 case DW_AT_abstract_origin:
1260 return "DW_AT_abstract_origin";
1261 case DW_AT_accessibility:
1262 return "DW_AT_accessibility";
1263 case DW_AT_address_class:
1264 return "DW_AT_address_class";
1265 case DW_AT_artificial:
1266 return "DW_AT_artificial";
1267 case DW_AT_base_types:
1268 return "DW_AT_base_types";
1269 case DW_AT_calling_convention:
1270 return "DW_AT_calling_convention";
1272 return "DW_AT_count";
1273 case DW_AT_data_member_location:
1274 return "DW_AT_data_member_location";
1275 case DW_AT_decl_column:
1276 return "DW_AT_decl_column";
1277 case DW_AT_decl_file:
1278 return "DW_AT_decl_file";
1279 case DW_AT_decl_line:
1280 return "DW_AT_decl_line";
1281 case DW_AT_declaration:
1282 return "DW_AT_declaration";
1283 case DW_AT_discr_list:
1284 return "DW_AT_discr_list";
1285 case DW_AT_encoding:
1286 return "DW_AT_encoding";
1287 case DW_AT_external:
1288 return "DW_AT_external";
1289 case DW_AT_frame_base:
1290 return "DW_AT_frame_base";
1292 return "DW_AT_friend";
1293 case DW_AT_identifier_case:
1294 return "DW_AT_identifier_case";
1295 case DW_AT_macro_info:
1296 return "DW_AT_macro_info";
1297 case DW_AT_namelist_items:
1298 return "DW_AT_namelist_items";
1299 case DW_AT_priority:
1300 return "DW_AT_priority";
1302 return "DW_AT_segment";
1303 case DW_AT_specification:
1304 return "DW_AT_specification";
1305 case DW_AT_static_link:
1306 return "DW_AT_static_link";
1308 return "DW_AT_type";
1309 case DW_AT_use_location:
1310 return "DW_AT_use_location";
1311 case DW_AT_variable_parameter:
1312 return "DW_AT_variable_parameter";
1313 case DW_AT_virtuality:
1314 return "DW_AT_virtuality";
1315 case DW_AT_vtable_elem_location:
1316 return "DW_AT_vtable_elem_location";
1318 case DW_AT_MIPS_fde:
1319 return "DW_AT_MIPS_fde";
1320 case DW_AT_MIPS_loop_begin:
1321 return "DW_AT_MIPS_loop_begin";
1322 case DW_AT_MIPS_tail_loop_begin:
1323 return "DW_AT_MIPS_tail_loop_begin";
1324 case DW_AT_MIPS_epilog_begin:
1325 return "DW_AT_MIPS_epilog_begin";
1326 case DW_AT_MIPS_loop_unroll_factor:
1327 return "DW_AT_MIPS_loop_unroll_factor";
1328 case DW_AT_MIPS_software_pipeline_depth:
1329 return "DW_AT_MIPS_software_pipeline_depth";
1330 case DW_AT_MIPS_linkage_name:
1331 return "DW_AT_MIPS_linkage_name";
1332 case DW_AT_MIPS_stride:
1333 return "DW_AT_MIPS_stride";
1334 case DW_AT_MIPS_abstract_name:
1335 return "DW_AT_MIPS_abstract_name";
1336 case DW_AT_MIPS_clone_origin:
1337 return "DW_AT_MIPS_clone_origin";
1338 case DW_AT_MIPS_has_inlines:
1339 return "DW_AT_MIPS_has_inlines";
1341 case DW_AT_sf_names:
1342 return "DW_AT_sf_names";
1343 case DW_AT_src_info:
1344 return "DW_AT_src_info";
1345 case DW_AT_mac_info:
1346 return "DW_AT_mac_info";
1347 case DW_AT_src_coords:
1348 return "DW_AT_src_coords";
1349 case DW_AT_body_begin:
1350 return "DW_AT_body_begin";
1351 case DW_AT_body_end:
1352 return "DW_AT_body_end";
1354 return "DW_AT_<unknown>";
1358 /* Convert a DWARF value form code into its string name. */
1360 dwarf_form_name (form)
1361 register unsigned form;
1366 return "DW_FORM_addr";
1367 case DW_FORM_block2:
1368 return "DW_FORM_block2";
1369 case DW_FORM_block4:
1370 return "DW_FORM_block4";
1372 return "DW_FORM_data2";
1374 return "DW_FORM_data4";
1376 return "DW_FORM_data8";
1377 case DW_FORM_string:
1378 return "DW_FORM_string";
1380 return "DW_FORM_block";
1381 case DW_FORM_block1:
1382 return "DW_FORM_block1";
1384 return "DW_FORM_data1";
1386 return "DW_FORM_flag";
1388 return "DW_FORM_sdata";
1390 return "DW_FORM_strp";
1392 return "DW_FORM_udata";
1393 case DW_FORM_ref_addr:
1394 return "DW_FORM_ref_addr";
1396 return "DW_FORM_ref1";
1398 return "DW_FORM_ref2";
1400 return "DW_FORM_ref4";
1402 return "DW_FORM_ref8";
1403 case DW_FORM_ref_udata:
1404 return "DW_FORM_ref_udata";
1405 case DW_FORM_indirect:
1406 return "DW_FORM_indirect";
1408 return "DW_FORM_<unknown>";
1412 /* Convert a DWARF stack opcode into its string name. */
1414 dwarf_stack_op_name (op)
1415 register unsigned op;
1420 return "DW_OP_addr";
1422 return "DW_OP_deref";
1424 return "DW_OP_const1u";
1426 return "DW_OP_const1s";
1428 return "DW_OP_const2u";
1430 return "DW_OP_const2s";
1432 return "DW_OP_const4u";
1434 return "DW_OP_const4s";
1436 return "DW_OP_const8u";
1438 return "DW_OP_const8s";
1440 return "DW_OP_constu";
1442 return "DW_OP_consts";
1446 return "DW_OP_drop";
1448 return "DW_OP_over";
1450 return "DW_OP_pick";
1452 return "DW_OP_swap";
1456 return "DW_OP_xderef";
1464 return "DW_OP_minus";
1476 return "DW_OP_plus";
1477 case DW_OP_plus_uconst:
1478 return "DW_OP_plus_uconst";
1484 return "DW_OP_shra";
1502 return "DW_OP_skip";
1504 return "DW_OP_lit0";
1506 return "DW_OP_lit1";
1508 return "DW_OP_lit2";
1510 return "DW_OP_lit3";
1512 return "DW_OP_lit4";
1514 return "DW_OP_lit5";
1516 return "DW_OP_lit6";
1518 return "DW_OP_lit7";
1520 return "DW_OP_lit8";
1522 return "DW_OP_lit9";
1524 return "DW_OP_lit10";
1526 return "DW_OP_lit11";
1528 return "DW_OP_lit12";
1530 return "DW_OP_lit13";
1532 return "DW_OP_lit14";
1534 return "DW_OP_lit15";
1536 return "DW_OP_lit16";
1538 return "DW_OP_lit17";
1540 return "DW_OP_lit18";
1542 return "DW_OP_lit19";
1544 return "DW_OP_lit20";
1546 return "DW_OP_lit21";
1548 return "DW_OP_lit22";
1550 return "DW_OP_lit23";
1552 return "DW_OP_lit24";
1554 return "DW_OP_lit25";
1556 return "DW_OP_lit26";
1558 return "DW_OP_lit27";
1560 return "DW_OP_lit28";
1562 return "DW_OP_lit29";
1564 return "DW_OP_lit30";
1566 return "DW_OP_lit31";
1568 return "DW_OP_reg0";
1570 return "DW_OP_reg1";
1572 return "DW_OP_reg2";
1574 return "DW_OP_reg3";
1576 return "DW_OP_reg4";
1578 return "DW_OP_reg5";
1580 return "DW_OP_reg6";
1582 return "DW_OP_reg7";
1584 return "DW_OP_reg8";
1586 return "DW_OP_reg9";
1588 return "DW_OP_reg10";
1590 return "DW_OP_reg11";
1592 return "DW_OP_reg12";
1594 return "DW_OP_reg13";
1596 return "DW_OP_reg14";
1598 return "DW_OP_reg15";
1600 return "DW_OP_reg16";
1602 return "DW_OP_reg17";
1604 return "DW_OP_reg18";
1606 return "DW_OP_reg19";
1608 return "DW_OP_reg20";
1610 return "DW_OP_reg21";
1612 return "DW_OP_reg22";
1614 return "DW_OP_reg23";
1616 return "DW_OP_reg24";
1618 return "DW_OP_reg25";
1620 return "DW_OP_reg26";
1622 return "DW_OP_reg27";
1624 return "DW_OP_reg28";
1626 return "DW_OP_reg29";
1628 return "DW_OP_reg30";
1630 return "DW_OP_reg31";
1632 return "DW_OP_breg0";
1634 return "DW_OP_breg1";
1636 return "DW_OP_breg2";
1638 return "DW_OP_breg3";
1640 return "DW_OP_breg4";
1642 return "DW_OP_breg5";
1644 return "DW_OP_breg6";
1646 return "DW_OP_breg7";
1648 return "DW_OP_breg8";
1650 return "DW_OP_breg9";
1652 return "DW_OP_breg10";
1654 return "DW_OP_breg11";
1656 return "DW_OP_breg12";
1658 return "DW_OP_breg13";
1660 return "DW_OP_breg14";
1662 return "DW_OP_breg15";
1664 return "DW_OP_breg16";
1666 return "DW_OP_breg17";
1668 return "DW_OP_breg18";
1670 return "DW_OP_breg19";
1672 return "DW_OP_breg20";
1674 return "DW_OP_breg21";
1676 return "DW_OP_breg22";
1678 return "DW_OP_breg23";
1680 return "DW_OP_breg24";
1682 return "DW_OP_breg25";
1684 return "DW_OP_breg26";
1686 return "DW_OP_breg27";
1688 return "DW_OP_breg28";
1690 return "DW_OP_breg29";
1692 return "DW_OP_breg30";
1694 return "DW_OP_breg31";
1696 return "DW_OP_regx";
1698 return "DW_OP_fbreg";
1700 return "DW_OP_bregx";
1702 return "DW_OP_piece";
1703 case DW_OP_deref_size:
1704 return "DW_OP_deref_size";
1705 case DW_OP_xderef_size:
1706 return "DW_OP_xderef_size";
1710 return "OP_<unknown>";
1714 /* Convert a DWARF type code into its string name. */
1716 dwarf_type_encoding_name (enc)
1717 register unsigned enc;
1721 case DW_ATE_address:
1722 return "DW_ATE_address";
1723 case DW_ATE_boolean:
1724 return "DW_ATE_boolean";
1725 case DW_ATE_complex_float:
1726 return "DW_ATE_complex_float";
1728 return "DW_ATE_float";
1730 return "DW_ATE_signed";
1731 case DW_ATE_signed_char:
1732 return "DW_ATE_signed_char";
1733 case DW_ATE_unsigned:
1734 return "DW_ATE_unsigned";
1735 case DW_ATE_unsigned_char:
1736 return "DW_ATE_unsigned_char";
1738 return "DW_ATE_<unknown>";
1742 /* Convert a DWARF call frame info. operation to its string name */
1744 dwarf_cfi_name (cfi_opc)
1745 register unsigned cfi_opc;
1749 case DW_CFA_advance_loc:
1750 return "DW_CFA_advance_loc";
1752 return "DW_CFA_offset";
1753 case DW_CFA_restore:
1754 return "DW_CFA_restore";
1756 return "DW_CFA_nop";
1757 case DW_CFA_set_loc:
1758 return "DW_CFA_set_loc";
1759 case DW_CFA_advance_loc1:
1760 return "DW_CFA_advance_loc1";
1761 case DW_CFA_advance_loc2:
1762 return "DW_CFA_advance_loc2";
1763 case DW_CFA_advance_loc4:
1764 return "DW_CFA_advance_loc4";
1765 case DW_CFA_offset_extended:
1766 return "DW_CFA_offset_extended";
1767 case DW_CFA_restore_extended:
1768 return "DW_CFA_restore_extended";
1769 case DW_CFA_undefined:
1770 return "DW_CFA_undefined";
1771 case DW_CFA_same_value:
1772 return "DW_CFA_same_value";
1773 case DW_CFA_register:
1774 return "DW_CFA_register";
1775 case DW_CFA_remember_state:
1776 return "DW_CFA_remember_state";
1777 case DW_CFA_restore_state:
1778 return "DW_CFA_restore_state";
1779 case DW_CFA_def_cfa:
1780 return "DW_CFA_def_cfa";
1781 case DW_CFA_def_cfa_register:
1782 return "DW_CFA_def_cfa_register";
1783 case DW_CFA_def_cfa_offset:
1784 return "DW_CFA_def_cfa_offset";
1785 /* SGI/MIPS specific */
1786 case DW_CFA_MIPS_advance_loc8:
1787 return "DW_CFA_MIPS_advance_loc8";
1789 return "DW_CFA_<unknown>";
1793 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
1794 instance of an inlined instance of a decl which is local to an inline
1795 function, so we have to trace all of the way back through the origin chain
1796 to find out what sort of node actually served as the original seed for the
1799 decl_ultimate_origin (decl)
1802 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1804 if (immediate_origin == NULL)
1808 register tree ret_val;
1809 register tree lookahead = immediate_origin;
1813 ret_val = lookahead;
1814 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1816 while (lookahead != NULL && lookahead != ret_val);
1821 /* Determine the "ultimate origin" of a block. The block may be an inlined
1822 instance of an inlined instance of a block which is local to an inline
1823 function, so we have to trace all of the way back through the origin chain
1824 to find out what sort of node actually served as the original seed for the
1827 block_ultimate_origin (block)
1828 register tree block;
1830 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1832 if (immediate_origin == NULL)
1836 register tree ret_val;
1837 register tree lookahead = immediate_origin;
1841 ret_val = lookahead;
1842 lookahead = (TREE_CODE (ret_val) == BLOCK)
1843 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1846 while (lookahead != NULL && lookahead != ret_val);
1851 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1852 of a virtual function may refer to a base class, so we check the 'this'
1856 decl_class_context (decl)
1859 tree context = NULL_TREE;
1860 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
1861 context = DECL_CONTEXT (decl);
1863 context = TYPE_MAIN_VARIANT
1864 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1866 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1867 context = NULL_TREE;
1872 /**************** DIE internal representation constturction *******************/
1874 /* Add an attribute/value pair to a DIE */
1876 add_dwarf_attr (die, attr)
1877 register dw_die_ref die;
1878 register dw_attr_ref attr;
1880 if (die != NULL && attr != NULL)
1882 if (die->die_attr == NULL)
1884 die->die_attr = attr;
1885 die->die_attr_last = attr;
1889 die->die_attr_last->dw_attr_next = attr;
1890 die->die_attr_last = attr;
1895 /* Add a flag value attribute to a DIE. */
1897 add_AT_flag (die, attr_kind, flag)
1898 register dw_die_ref die;
1899 register enum dwarf_attribute attr_kind;
1900 register unsigned flag;
1902 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1905 attr->dw_attr_next = NULL;
1906 attr->dw_attr = attr_kind;
1907 attr->dw_attr_val.val_class = dw_val_class_flag;
1908 attr->dw_attr_val.v.val_flag = flag;
1909 add_dwarf_attr (die, attr);
1913 /* Add a signed integer attribute value to a DIE. */
1915 add_AT_int (die, attr_kind, int_val)
1916 register dw_die_ref die;
1917 register enum dwarf_attribute attr_kind;
1918 register long int int_val;
1920 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1923 attr->dw_attr_next = NULL;
1924 attr->dw_attr = attr_kind;
1925 attr->dw_attr_val.val_class = dw_val_class_const;
1926 attr->dw_attr_val.v.val_int = int_val;
1927 add_dwarf_attr (die, attr);
1931 /* Add an unsigned integer attribute value to a DIE. */
1933 add_AT_unsigned (die, attr_kind, unsigned_val)
1934 register dw_die_ref die;
1935 register enum dwarf_attribute attr_kind;
1936 register unsigned long unsigned_val;
1938 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1941 attr->dw_attr_next = NULL;
1942 attr->dw_attr = attr_kind;
1943 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
1944 attr->dw_attr_val.v.val_unsigned = unsigned_val;
1945 add_dwarf_attr (die, attr);
1949 /* Add an unsigned double integer attribute value to a DIE. */
1951 add_AT_double (die, attr_kind, val_hi, val_low)
1952 register dw_die_ref die;
1953 register enum dwarf_attribute attr_kind;
1954 register unsigned long val_hi;
1955 register unsigned long val_low;
1957 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1960 attr->dw_attr_next = NULL;
1961 attr->dw_attr = attr_kind;
1962 attr->dw_attr_val.val_class = dw_val_class_double_const;
1963 attr->dw_attr_val.v.val_dbl_const.dw_dbl_hi = val_hi;
1964 attr->dw_attr_val.v.val_dbl_const.dw_dbl_low = val_low;
1965 add_dwarf_attr (die, attr);
1969 /* Add a string attribute value to a DIE. */
1971 add_AT_string (die, attr_kind, str)
1972 register dw_die_ref die;
1973 register enum dwarf_attribute attr_kind;
1976 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1979 attr->dw_attr_next = NULL;
1980 attr->dw_attr = attr_kind;
1981 attr->dw_attr_val.val_class = dw_val_class_str;
1982 attr->dw_attr_val.v.val_str = xstrdup (str);
1983 add_dwarf_attr (die, attr);
1987 /* Add a DIE reference attribute value to a DIE. */
1989 add_AT_die_ref (die, attr_kind, targ_die)
1990 register dw_die_ref die;
1991 register enum dwarf_attribute attr_kind;
1992 register dw_die_ref targ_die;
1994 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
1997 attr->dw_attr_next = NULL;
1998 attr->dw_attr = attr_kind;
1999 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2000 attr->dw_attr_val.v.val_die_ref = targ_die;
2001 add_dwarf_attr (die, attr);
2005 /* Add an FDE reference attribute value to a DIE. */
2007 add_AT_fde_ref (die, attr_kind, targ_fde)
2008 register dw_die_ref die;
2009 register enum dwarf_attribute attr_kind;
2010 register unsigned targ_fde;
2012 register dw_attr_ref attr;
2014 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2017 attr->dw_attr_next = NULL;
2018 attr->dw_attr = attr_kind;
2019 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
2020 attr->dw_attr_val.v.val_fde_index = targ_fde;
2021 add_dwarf_attr (die, attr);
2025 /* Add a location description attribute value to a DIE. */
2027 add_AT_loc (die, attr_kind, loc)
2028 register dw_die_ref die;
2029 register enum dwarf_attribute attr_kind;
2030 register dw_loc_descr_ref loc;
2032 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2035 attr->dw_attr_next = NULL;
2036 attr->dw_attr = attr_kind;
2037 attr->dw_attr_val.val_class = dw_val_class_loc;
2038 attr->dw_attr_val.v.val_loc = loc;
2039 add_dwarf_attr (die, attr);
2043 /* Add an address constant attribute value to a DIE. */
2045 add_AT_addr (die, attr_kind, addr)
2046 register dw_die_ref die;
2047 register enum dwarf_attribute attr_kind;
2050 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2053 attr->dw_attr_next = NULL;
2054 attr->dw_attr = attr_kind;
2055 attr->dw_attr_val.val_class = dw_val_class_addr;
2056 attr->dw_attr_val.v.val_addr = addr;
2057 add_dwarf_attr (die, attr);
2061 /* Add a label identifier attribute value to a DIE. */
2063 add_AT_lbl_id (die, attr_kind, lbl_id)
2064 register dw_die_ref die;
2065 register enum dwarf_attribute attr_kind;
2066 register char *lbl_id;
2068 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2071 attr->dw_attr_next = NULL;
2072 attr->dw_attr = attr_kind;
2073 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2074 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2075 add_dwarf_attr (die, attr);
2079 /* Add a section offset attribute value to a DIE. */
2081 add_AT_section_offset (die, attr_kind, section)
2082 register dw_die_ref die;
2083 register enum dwarf_attribute attr_kind;
2084 register char *section;
2086 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2089 attr->dw_attr_next = NULL;
2090 attr->dw_attr = attr_kind;
2091 attr->dw_attr_val.val_class = dw_val_class_section_offset;
2092 attr->dw_attr_val.v.val_section = section;
2093 add_dwarf_attr (die, attr);
2097 /* Test if die refers to an external subroutine. */
2099 is_extern_subr_die (die)
2100 register dw_die_ref die;
2102 register dw_attr_ref a;
2103 register int is_subr = FALSE;
2104 register int is_extern = FALSE;
2105 if (die != NULL && die->die_tag == DW_TAG_subprogram)
2108 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2110 if (a->dw_attr == DW_AT_external
2111 && a->dw_attr_val.val_class == dw_val_class_flag
2112 && a->dw_attr_val.v.val_flag != 0)
2119 return is_subr && is_extern;
2122 /* Get the attribute of type attr_kind. */
2124 get_AT (die, attr_kind)
2125 register dw_die_ref die;
2126 register enum dwarf_attribute attr_kind;
2128 register dw_attr_ref a;
2129 register dw_die_ref spec = NULL;
2133 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2135 if (a->dw_attr == attr_kind)
2137 if (a->dw_attr == DW_AT_specification
2138 || a->dw_attr == DW_AT_abstract_origin)
2139 spec = a->dw_attr_val.v.val_die_ref;
2142 return get_AT (spec, attr_kind);
2147 /* Return the "low pc" attribute value, typically associated with
2148 a subprogram DIE. Return null if the "low pc" attribute is
2149 either not prsent, or if it cannot be represented as an
2150 assembler label identifier. */
2153 register dw_die_ref die;
2155 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2156 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2157 return a->dw_attr_val.v.val_lbl_id;
2161 /* Return the "high pc" attribute value, typically associated with
2162 a subprogram DIE. Return null if the "high pc" attribute is
2163 either not prsent, or if it cannot be represented as an
2164 assembler label identifier. */
2167 register dw_die_ref die;
2169 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2170 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2171 return a->dw_attr_val.v.val_lbl_id;
2175 /* Return the value of the string attribute designated by ATTR_KIND, or
2176 NULL if it is not present. */
2178 get_AT_string (die, attr_kind)
2179 register dw_die_ref die;
2180 register enum dwarf_attribute attr_kind;
2182 register dw_attr_ref a = get_AT (die, attr_kind);
2183 if (a && a->dw_attr_val.val_class == dw_val_class_str)
2184 return a->dw_attr_val.v.val_str;
2188 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
2189 if it is not present. */
2191 get_AT_flag (die, attr_kind)
2192 register dw_die_ref die;
2193 register enum dwarf_attribute attr_kind;
2195 register dw_attr_ref a = get_AT (die, attr_kind);
2196 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
2197 return a->dw_attr_val.v.val_flag;
2201 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2202 if it is not present. */
2204 get_AT_unsigned (die, attr_kind)
2205 register dw_die_ref die;
2206 register enum dwarf_attribute attr_kind;
2208 register dw_attr_ref a = get_AT (die, attr_kind);
2209 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
2210 return a->dw_attr_val.v.val_unsigned;
2217 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2218 return (lang == DW_LANG_C || lang == DW_LANG_C89
2219 || lang == DW_LANG_C_plus_plus);
2225 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2226 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
2229 /* Remove the specified attribute if present. */
2231 remove_AT (die, attr_kind)
2232 register dw_die_ref die;
2233 register enum dwarf_attribute attr_kind;
2235 register dw_attr_ref a;
2236 register dw_attr_ref removed = NULL;;
2239 if (die->die_attr->dw_attr == attr_kind)
2241 removed = die->die_attr;
2242 if (die->die_attr_last == die->die_attr)
2243 die->die_attr_last = NULL;
2244 die->die_attr = die->die_attr->dw_attr_next;
2246 else for (a = die->die_attr; a->dw_attr_next != NULL;
2247 a = a->dw_attr_next)
2248 if (a->dw_attr_next->dw_attr == attr_kind)
2250 removed = a->dw_attr_next;
2251 if (die->die_attr_last == a->dw_attr_next)
2252 die->die_attr_last = a;
2253 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
2261 /* Discard the children of this DIE. */
2263 remove_children (die)
2264 register dw_die_ref die;
2266 register dw_die_ref child_die = die->die_child;
2267 die->die_child = NULL;
2268 die->die_child_last = NULL;
2269 while (child_die != NULL)
2271 register dw_die_ref tmp_die = child_die;
2272 register dw_attr_ref a;
2273 child_die = child_die->die_sib;
2275 for (a = tmp_die->die_attr; a != NULL; )
2277 register dw_attr_ref tmp_a = a;
2278 a = a->dw_attr_next;
2285 /* Add a child DIE below its parent. */
2287 add_child_die (die, child_die)
2288 register dw_die_ref die;
2289 register dw_die_ref child_die;
2291 if (die != NULL && child_die != NULL)
2293 assert (die != child_die);
2294 child_die->die_parent = die;
2295 child_die->die_sib = NULL;
2296 if (die->die_child == NULL)
2298 die->die_child = child_die;
2299 die->die_child_last = child_die;
2303 die->die_child_last->die_sib = child_die;
2304 die->die_child_last = child_die;
2309 /* Return a pointer to a newly created DIE node. */
2311 new_die (tag_value, parent_die)
2312 register enum dwarf_tag tag_value;
2313 register dw_die_ref parent_die;
2315 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2318 die->die_tag = tag_value;
2319 die->die_abbrev = 0;
2320 die->die_offset = 0;
2321 die->die_child = NULL;
2322 die->die_parent = NULL;
2323 die->die_sib = NULL;
2324 die->die_child_last = NULL;
2325 die->die_attr = NULL;
2326 die->die_attr_last = NULL;
2327 if (parent_die != NULL)
2328 add_child_die (parent_die, die);
2335 /* Return the DIE associated with the given type specifier. */
2337 lookup_type_die (type)
2340 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
2343 /* Equate a DIE to a given type specifier. */
2345 equate_type_number_to_die (type, type_die)
2347 register dw_die_ref type_die;
2349 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
2352 /* Return the DIE associated with a given declaration. */
2354 lookup_decl_die (decl)
2357 register unsigned decl_id = DECL_UID (decl);
2358 return (decl_id < decl_die_table_in_use)
2359 ? decl_die_table[decl_id] : NULL;
2362 /* Equate a DIE to a particular declaration. */
2364 equate_decl_number_to_die (decl, decl_die)
2366 register dw_die_ref decl_die;
2368 register unsigned decl_id = DECL_UID (decl);
2369 register unsigned i;
2370 register unsigned num_allocated;
2371 if (decl_id >= decl_die_table_allocated)
2373 num_allocated = (((decl_id + 1)
2374 + DECL_DIE_TABLE_INCREMENT - 1)
2375 / DECL_DIE_TABLE_INCREMENT)
2376 * DECL_DIE_TABLE_INCREMENT;
2377 decl_die_table = (dw_die_ref *) xrealloc (decl_die_table,
2378 sizeof (dw_die_ref) * num_allocated);
2379 bzero (&decl_die_table[decl_die_table_allocated],
2380 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2381 decl_die_table_allocated = num_allocated;
2383 if (decl_id >= decl_die_table_in_use)
2385 decl_die_table_in_use = (decl_id + 1);
2387 decl_die_table[decl_id] = decl_die;
2390 /* Return a pointer to a newly allocated location description. Location
2391 descriptions are simple expression terms that can be strung
2392 together to form more complicated location (address) descriptions. */
2393 inline dw_loc_descr_ref
2394 new_loc_descr (op, oprnd1, oprnd2)
2395 register enum dwarf_location_atom op;
2396 register unsigned long oprnd1;
2397 register unsigned long oprnd2;
2399 register dw_loc_descr_ref descr =
2400 (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2403 descr->dw_loc_next = NULL;
2404 descr->dw_loc_opc = op;
2405 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2406 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2407 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2408 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2413 /* Add a location description term to a location description expression. */
2415 add_loc_descr (list_head, descr)
2416 register dw_loc_descr_ref *list_head;
2417 register dw_loc_descr_ref descr;
2419 register dw_loc_descr_ref *d;
2420 /* find the end of the chain. */
2421 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2428 /* Return a pointer to a newly allocated Call Frame Instruction. */
2432 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2435 cfi->dw_cfi_next = NULL;
2436 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2437 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2442 /* Add a Call Frame Instruction to list of instructions. */
2444 add_cfi (list_head, cfi)
2445 register dw_cfi_ref *list_head;
2446 register dw_cfi_ref cfi;
2448 register dw_cfi_ref *p;
2449 /* find the end of the chain. */
2450 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2457 /********* Print DWARF Internal Representation (debugging aids) ***************/
2459 /* Keep track of the number of spaces used to indent the
2460 output of the debugging routines that print the structure of
2461 the DIE internal representation. */
2462 static int print_indent;
2464 /* Indent the line the number of spaces given by print_indent. */
2466 print_spaces (outfile)
2469 fprintf (outfile, "%*s", print_indent, "");
2472 /* Print the information assoaciated with a given DIE, and its children.
2473 This routine is a debugging aid only. */
2475 print_die (die, outfile)
2479 register dw_attr_ref a;
2480 register dw_die_ref c;
2481 print_spaces (outfile);
2482 fprintf (outfile, "DIE %4u: %s\n",
2483 die->die_offset, dwarf_tag_name (die->die_tag));
2484 print_spaces (outfile);
2485 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
2486 fprintf (outfile, " offset: %u\n", die->die_offset);
2487 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2489 print_spaces (outfile);
2490 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
2491 switch (a->dw_attr_val.val_class)
2493 case dw_val_class_addr:
2494 fprintf (outfile, "address");
2496 case dw_val_class_loc:
2497 fprintf (outfile, "location descriptor");
2499 case dw_val_class_const:
2500 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2502 case dw_val_class_unsigned_const:
2503 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2505 case dw_val_class_double_const:
2506 fprintf (outfile, "constant (%u,%u)",
2507 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
2508 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
2510 case dw_val_class_flag:
2511 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2513 case dw_val_class_die_ref:
2514 if (a->dw_attr_val.v.val_die_ref != NULL)
2516 fprintf (outfile, "die -> %u",
2517 a->dw_attr_val.v.val_die_ref->die_offset);
2521 fprintf (outfile, "die -> <null>");
2524 case dw_val_class_lbl_id:
2525 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2527 case dw_val_class_section_offset:
2528 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2530 case dw_val_class_str:
2531 if (a->dw_attr_val.v.val_str != NULL)
2533 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2537 fprintf (outfile, "<null>");
2541 fprintf (outfile, "\n");
2543 if (die->die_child != NULL)
2546 for (c = die->die_child; c != NULL; c = c->die_sib)
2548 print_die (c, outfile);
2554 /* Print the contents of the source code line number correspondence table.
2555 This routine is a debugging aid only. */
2557 print_dwarf_line_table (outfile)
2560 register unsigned i;
2561 register dw_line_info_ref line_info;
2562 fprintf (outfile, "\n\nDWARF source line information\n");
2563 for (i = 1; i < line_info_table_in_use; ++i)
2565 line_info = &line_info_table[i];
2566 fprintf (outfile, "%5d: ", i);
2567 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2568 fprintf (outfile, "%6d", line_info->dw_line_num);
2569 fprintf (outfile, "\n");
2571 fprintf (outfile, "\n\n");
2574 /* Print the information collected for a given DIE. */
2576 debug_dwarf_die (die)
2579 print_die (die, stderr);
2582 /* Print all DWARF informaiton collected for the compilation unit.
2583 This routine is a debugging aid only. */
2588 print_die (comp_unit_die, stderr);
2589 print_dwarf_line_table (stderr);
2593 /***************** DWARF Information Construction Support *********************/
2595 /* Traverse the DIE, and add a sibling attribute if it may have the
2596 effect of speeding up access to siblings. To save some space,
2597 avoid generating sibling attributes for DIE's without children. */
2599 add_sibling_attributes(die)
2600 register dw_die_ref die;
2602 register dw_die_ref c;
2603 register dw_attr_ref attr;
2604 if (die != comp_unit_die && die->die_child != NULL)
2606 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2609 attr->dw_attr_next = NULL;
2610 attr->dw_attr = DW_AT_sibling;
2611 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2612 attr->dw_attr_val.v.val_die_ref = die->die_sib;
2614 /* add the sibling link to the front of the attribute list. */
2615 attr->dw_attr_next = die->die_attr;
2616 if (die->die_attr == NULL)
2618 die->die_attr_last = attr;
2620 die->die_attr = attr;
2622 for (c = die->die_child; c != NULL; c = c->die_sib)
2624 add_sibling_attributes (c);
2628 /* The format of each DIE (and its attribute value pairs)
2629 is encoded in an abbreviation table. This routine builds the
2630 abbreviation table and assigns a unique abbreviation id for
2631 each abbreviation entry. The children of each die are visited
2634 build_abbrev_table (die)
2635 register dw_die_ref die;
2637 register unsigned long abbrev_id;
2638 register unsigned long n_alloc;
2639 register dw_die_ref c;
2640 register dw_attr_ref d_attr, a_attr;
2641 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2643 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2644 if (abbrev->die_tag == die->die_tag)
2646 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2648 a_attr = abbrev->die_attr;
2649 d_attr = die->die_attr;
2650 while (a_attr != NULL && d_attr != NULL)
2652 if ((a_attr->dw_attr != d_attr->dw_attr)
2653 || (value_format (&a_attr->dw_attr_val)
2654 != value_format (&d_attr->dw_attr_val)))
2658 a_attr = a_attr->dw_attr_next;
2659 d_attr = d_attr->dw_attr_next;
2661 if (a_attr == NULL && d_attr == NULL)
2668 if (abbrev_id >= abbrev_die_table_in_use)
2670 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2672 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2673 abbrev_die_table = (dw_die_ref *)
2674 xmalloc (abbrev_die_table,
2675 sizeof (dw_die_ref) * n_alloc);
2676 bzero (&abbrev_die_table[abbrev_die_table_allocated],
2677 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2678 abbrev_die_table_allocated = n_alloc;
2680 ++abbrev_die_table_in_use;
2681 abbrev_die_table[abbrev_id] = die;
2683 die->die_abbrev = abbrev_id;
2684 for (c = die->die_child; c != NULL; c = c->die_sib)
2686 build_abbrev_table (c);
2691 /********************** DWARF Information Sizing *****************************/
2693 /* Return the size of an unsigned LEB128 quantity. */
2694 inline unsigned long
2695 size_of_uleb128 (value)
2696 register unsigned long value;
2698 register unsigned long size = 0;
2699 register unsigned byte;
2702 byte = (value & 0x7f);
2710 /* Return the size of a signed LEB128 quantity. */
2711 inline unsigned long
2712 size_of_sleb128 (value)
2713 register long value;
2715 register unsigned long size = 0;
2716 register unsigned byte;
2719 byte = (value & 0x7f);
2723 while (!(((value == 0) && ((byte & 0x40) == 0))
2724 || ((value == -1) && ((byte & 0x40) != 0))));
2728 /* Return the size of a string, including the null byte. */
2729 static unsigned long
2730 size_of_string (str)
2733 register unsigned long size = 0;
2734 register unsigned long slen = strlen (str);
2735 register unsigned long i;
2736 register unsigned c;
2737 for (i = 0; i < slen; ++i)
2746 /* Null terminator. */
2751 /* Return the size of a location descriptor. */
2752 static unsigned long
2753 size_of_loc_descr (loc)
2754 register dw_loc_descr_ref loc;
2756 register unsigned long size = 1;
2757 switch (loc->dw_loc_opc)
2779 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2782 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2787 case DW_OP_plus_uconst:
2788 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2826 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2829 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2832 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2835 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2836 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2839 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2841 case DW_OP_deref_size:
2842 case DW_OP_xderef_size:
2851 /* Return the size of a series of location descriptors. */
2852 static unsigned long
2854 register dw_loc_descr_ref loc;
2856 register unsigned long size = 0;
2857 for (; loc != NULL; loc = loc->dw_loc_next)
2858 size += size_of_loc_descr (loc);
2862 /* Return the power-of-two number of bytes necessary to represent VALUE. */
2864 constant_size (value)
2865 long unsigned value;
2872 log = floor_log2 (value);
2875 log = 1 << (floor_log2 (log) + 1);
2880 /* Return the size of a DIE, as it is represented in the
2881 .debug_info section. */
2882 static unsigned long
2884 register dw_die_ref die;
2886 register unsigned long size = 0;
2887 register dw_attr_ref a;
2888 size += size_of_uleb128 (die->die_abbrev);
2889 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2891 switch (a->dw_attr_val.val_class)
2893 case dw_val_class_addr:
2896 case dw_val_class_loc:
2898 register unsigned long lsize
2899 = size_of_locs (a->dw_attr_val.v.val_loc);
2902 size += constant_size (lsize);
2906 case dw_val_class_const:
2909 case dw_val_class_unsigned_const:
2910 size += constant_size (a->dw_attr_val.v.val_unsigned);
2912 case dw_val_class_double_const:
2915 case dw_val_class_flag:
2918 case dw_val_class_die_ref:
2919 size += DWARF_OFFSET_SIZE;
2921 case dw_val_class_fde_ref:
2922 size += DWARF_OFFSET_SIZE;
2924 case dw_val_class_lbl_id:
2927 case dw_val_class_section_offset:
2928 size += DWARF_OFFSET_SIZE;
2930 case dw_val_class_str:
2931 size += size_of_string (a->dw_attr_val.v.val_str);
2940 /* Size the debgging information associted with a given DIE.
2941 Visits the DIE's children recursively. Updates the global
2942 variable next_die_offset, on each time through. Uses the
2943 current value of next_die_offset to updete the die_offset
2944 field in each DIE. */
2946 calc_die_sizes (die)
2949 register dw_die_ref c;
2950 die->die_offset = next_die_offset;
2951 next_die_offset += size_of_die (die);
2952 for (c = die->die_child; c != NULL; c = c->die_sib)
2956 if (die->die_child != NULL)
2958 /* Count the null byte used to terminate sibling lists. */
2959 next_die_offset += 1;
2963 /* Return the size of the line information prolog generated for the
2964 compilation unit. */
2965 static unsigned long
2966 size_of_line_prolog ()
2968 register unsigned long size;
2969 register unsigned long ft_index;
2970 size = DWARF_LINE_PROLOG_HEADER_SIZE;
2971 /* Count the size of the table giving number of args for each
2973 size += DWARF_LINE_OPCODE_BASE - 1;
2974 /* Include directory table is empty (at present). Count only the
2975 the null byte used to terminate the table. */
2977 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
2979 /* File name entry. */
2980 size += size_of_string (file_table[ft_index]);
2981 /* Include directory index. */
2982 size += size_of_uleb128 (0);
2983 /* Modification time. */
2984 size += size_of_uleb128 (0);
2985 /* File length in bytes. */
2986 size += size_of_uleb128 (0);
2988 /* Count the file table terminator. */
2993 /* Return the size of the line information generated for this
2994 compilation unit. */
2995 static unsigned long
2996 size_of_line_info ()
2998 register unsigned long size;
2999 register unsigned long lt_index;
3000 register unsigned long current_line;
3001 register long line_offset;
3002 register long line_delta;
3003 register unsigned long current_file;
3004 register unsigned long function;
3005 /* Version number. */
3007 /* Prolog length specifier. */
3008 size += DWARF_OFFSET_SIZE;
3010 size += size_of_line_prolog ();
3011 /* Set address register instruction. */
3012 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3016 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
3018 register dw_line_info_ref line_info;
3019 /* Advance pc instruction. */
3021 line_info = &line_info_table[lt_index];
3022 if (line_info->dw_file_num != current_file)
3024 /* Set file number instruction. */
3026 current_file = line_info->dw_file_num;
3027 size += size_of_uleb128 (current_file);
3029 if (line_info->dw_line_num != current_line)
3031 line_offset = line_info->dw_line_num - current_line;
3032 line_delta = line_offset - DWARF_LINE_BASE;
3033 current_line = line_info->dw_line_num;
3034 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3036 /* 1-byte special line number instruction. */
3041 /* Advance line instruction. */
3043 size += size_of_sleb128 (line_offset);
3044 /* Generate line entry instruction. */
3049 /* Advance pc instruction. */
3051 /* End of line number info. marker. */
3052 size += 1 + size_of_uleb128 (1) + 1;
3056 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3058 register dw_separate_line_info_ref line_info
3059 = &separate_line_info_table[lt_index];
3060 if (function != line_info->function)
3062 function = line_info->function;
3063 /* Set address register instruction. */
3064 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3069 /* Advance pc instruction. */
3072 if (line_info->dw_file_num != current_file)
3074 /* Set file number instruction. */
3076 current_file = line_info->dw_file_num;
3077 size += size_of_uleb128 (current_file);
3079 if (line_info->dw_line_num != current_line)
3081 line_offset = line_info->dw_line_num - current_line;
3082 line_delta = line_offset - DWARF_LINE_BASE;
3083 current_line = line_info->dw_line_num;
3084 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3086 /* 1-byte special line number instruction. */
3091 /* Advance line instruction. */
3093 size += size_of_sleb128 (line_offset);
3094 /* Generate line entry instruction. */
3100 /* If we're done with a function, end its sequence. */
3101 if (lt_index == separate_line_info_table_in_use
3102 || separate_line_info_table[lt_index].function != function)
3106 /* Advance pc instruction. */
3108 /* End of line number info. marker. */
3109 size += 1 + size_of_uleb128 (1) + 1;
3115 /* Return the size of the .debug_pubnames table generated for the
3116 compilation unit. */
3117 static unsigned long
3120 register unsigned long size;
3121 register unsigned i;
3123 size = DWARF_PUBNAMES_HEADER_SIZE;
3124 for (i = 0; i < pubname_table_in_use; ++i)
3126 register pubname_ref p = &pubname_table[i];
3127 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
3129 size += DWARF_OFFSET_SIZE;
3133 /* Return the size of the information in the .debug_aranges seciton. */
3134 static unsigned long
3137 register unsigned long size;
3138 size = DWARF_ARANGES_HEADER_SIZE;
3139 /* Count the address/length pair for this compilation unit. */
3140 size += 2 * PTR_SIZE;
3141 size += 2 * PTR_SIZE * arange_table_in_use;
3142 /* Count the two zero words used to terminated the address range table. */
3143 size += 2 * PTR_SIZE;
3147 /**************** DWARF Debug Information Output *****************************/
3149 /* Output an unsigned LEB128 quantity. */
3151 output_uleb128 (value)
3152 register unsigned long value;
3154 unsigned long save_value = value;
3155 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3158 register unsigned byte = (value & 0x7f);
3162 /* More bytes to follow. */
3165 fprintf (asm_out_file, "0x%x", byte);
3168 fprintf (asm_out_file, ",");
3172 if (flag_verbose_asm)
3173 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
3176 /* Output an signed LEB128 quantity. */
3178 output_sleb128 (value)
3179 register long value;
3182 register unsigned byte;
3183 long save_value = value;
3184 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3187 byte = (value & 0x7f);
3188 /* arithmetic shift */
3190 more = !((((value == 0) && ((byte & 0x40) == 0))
3191 || ((value == -1) && ((byte & 0x40) != 0))));
3196 fprintf (asm_out_file, "0x%x", byte);
3199 fprintf (asm_out_file, ",");
3203 if (flag_verbose_asm)
3204 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
3207 /* Select the encoding of an attribute value. */
3208 static enum dwarf_form
3212 switch (v->val_class)
3214 case dw_val_class_addr:
3215 return DW_FORM_addr;
3216 case dw_val_class_loc:
3217 switch (constant_size (size_of_locs (v->v.val_loc)))
3220 return DW_FORM_block1;
3222 return DW_FORM_block2;
3226 case dw_val_class_const:
3227 return DW_FORM_data4;
3228 case dw_val_class_unsigned_const:
3229 switch (constant_size (v->v.val_unsigned))
3232 return DW_FORM_data1;
3234 return DW_FORM_data2;
3236 return DW_FORM_data4;
3240 case dw_val_class_double_const:
3241 return DW_FORM_data8;
3242 case dw_val_class_flag:
3243 return DW_FORM_flag;
3244 case dw_val_class_die_ref:
3246 case dw_val_class_fde_ref:
3247 return DW_FORM_data;
3248 case dw_val_class_lbl_id:
3249 return DW_FORM_addr;
3250 case dw_val_class_section_offset:
3251 return DW_FORM_data;
3252 case dw_val_class_str:
3253 return DW_FORM_string;
3259 /* Output the encoding of an attribute value. */
3261 output_value_format (v)
3264 enum dwarf_form form = value_format (v);
3265 output_uleb128 (form);
3266 if (flag_verbose_asm)
3267 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
3268 fputc ('\n', asm_out_file);
3271 /* Output the .debug_abbrev section which defines the DIE abbreviation
3274 output_abbrev_section ()
3276 unsigned long abbrev_id;
3278 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3280 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3281 output_uleb128 (abbrev_id);
3282 if (flag_verbose_asm)
3283 fprintf (asm_out_file, " (abbrev code)");
3284 fputc ('\n', asm_out_file);
3285 output_uleb128 (abbrev->die_tag);
3286 if (flag_verbose_asm)
3287 fprintf (asm_out_file, " (TAG: %s)",
3288 dwarf_tag_name (abbrev->die_tag));
3289 fputc ('\n', asm_out_file);
3290 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3291 (abbrev->die_child != NULL)
3292 ? DW_children_yes : DW_children_no);
3293 if (flag_verbose_asm)
3295 fprintf (asm_out_file, "\t%s %s",
3297 (abbrev->die_child != NULL)
3298 ? "DW_children_yes" : "DW_children_no");
3300 fputc ('\n', asm_out_file);
3301 for (a_attr = abbrev->die_attr; a_attr != NULL;
3302 a_attr = a_attr->dw_attr_next)
3304 output_uleb128 (a_attr->dw_attr);
3305 if (flag_verbose_asm)
3306 fprintf (asm_out_file, " (%s)",
3307 dwarf_attr_name (a_attr->dw_attr));
3308 fputc ('\n', asm_out_file);
3309 output_value_format (&a_attr->dw_attr_val);
3311 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3315 /* Output location description stack opcode's operands (if any). */
3317 output_loc_operands (loc)
3318 register dw_loc_descr_ref loc;
3320 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3321 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3322 switch (loc->dw_loc_opc)
3325 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3326 fputc ('\n', asm_out_file);
3330 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3331 fputc ('\n', asm_out_file);
3335 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3336 fputc ('\n', asm_out_file);
3340 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
3341 fputc ('\n', asm_out_file);
3345 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3346 val1->v.val_dbl_const.dw_dbl_hi,
3347 val2->v.val_dbl_const.dw_dbl_low);
3348 fputc ('\n', asm_out_file);
3351 output_uleb128 (val1->v.val_unsigned);
3352 fputc ('\n', asm_out_file);
3355 output_sleb128 (val1->v.val_int);
3356 fputc ('\n', asm_out_file);
3359 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
3360 fputc ('\n', asm_out_file);
3362 case DW_OP_plus_uconst:
3363 output_uleb128 (val1->v.val_unsigned);
3364 fputc ('\n', asm_out_file);
3368 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3369 fputc ('\n', asm_out_file);
3403 output_sleb128 (val1->v.val_int);
3404 fputc ('\n', asm_out_file);
3407 output_uleb128 (val1->v.val_unsigned);
3408 fputc ('\n', asm_out_file);
3411 output_sleb128 (val1->v.val_int);
3412 fputc ('\n', asm_out_file);
3415 output_uleb128 (val1->v.val_unsigned);
3416 fputc ('\n', asm_out_file);
3417 output_sleb128 (val2->v.val_int);
3418 fputc ('\n', asm_out_file);
3421 output_uleb128 (val1->v.val_unsigned);
3422 fputc ('\n', asm_out_file);
3424 case DW_OP_deref_size:
3425 case DW_OP_xderef_size:
3426 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3427 fputc ('\n', asm_out_file);
3434 /* Compute the offset of a sibling. */
3435 static unsigned long
3436 sibling_offset (die)
3439 unsigned long offset;
3440 if (die->die_child_last == NULL)
3442 offset = die->die_offset + size_of_die (die);
3446 offset = sibling_offset (die->die_child_last) + 1;
3451 /* Output the DIE and its attributes. Called recursively to generate
3452 the definitions of each child DIE. */
3455 register dw_die_ref die;
3457 register dw_attr_ref a;
3458 register dw_die_ref c;
3459 register unsigned long ref_offset;
3460 register unsigned long size;
3461 register dw_loc_descr_ref loc;
3462 output_uleb128 (die->die_abbrev);
3463 if (flag_verbose_asm)
3464 fprintf (asm_out_file, " (DIE (0x%x) %s)",
3465 die->die_offset, dwarf_tag_name (die->die_tag));
3466 fputc ('\n', asm_out_file);
3467 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3469 switch (a->dw_attr_val.val_class)
3471 case dw_val_class_addr:
3472 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
3473 a->dw_attr_val.v.val_addr);
3475 case dw_val_class_loc:
3476 size = size_of_locs (a->dw_attr_val.v.val_loc);
3477 /* Output the block length for this list of location operations. */
3478 switch (constant_size (size))
3481 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
3484 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
3489 if (flag_verbose_asm)
3491 fprintf (asm_out_file, "\t%s %s",
3492 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3494 fputc ('\n', asm_out_file);
3495 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3496 loc = loc->dw_loc_next)
3498 /* Output the opcode. */
3499 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3500 if (flag_verbose_asm)
3502 fprintf (asm_out_file, "\t%s %s",
3504 dwarf_stack_op_name (loc->dw_loc_opc));
3506 fputc ('\n', asm_out_file);
3507 /* Output the operand(s) (if any). */
3508 output_loc_operands (loc);
3511 case dw_val_class_const:
3512 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
3514 case dw_val_class_unsigned_const:
3515 switch (constant_size (a->dw_attr_val.v.val_unsigned))
3518 ASM_OUTPUT_DWARF_DATA1
3519 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3522 ASM_OUTPUT_DWARF_DATA2
3523 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3526 ASM_OUTPUT_DWARF_DATA4
3527 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3533 case dw_val_class_double_const:
3534 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3535 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
3536 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
3538 case dw_val_class_flag:
3539 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
3541 case dw_val_class_die_ref:
3542 if (a->dw_attr_val.v.val_die_ref != NULL)
3544 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
3546 else if (a->dw_attr == DW_AT_sibling)
3548 ref_offset = sibling_offset(die);
3554 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
3556 case dw_val_class_fde_ref:
3557 ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
3558 fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
3559 stripattributes (FRAME_SECTION), ref_offset);
3561 case dw_val_class_lbl_id:
3562 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
3564 case dw_val_class_section_offset:
3565 ASM_OUTPUT_DWARF_OFFSET
3566 (asm_out_file, stripattributes (a->dw_attr_val.v.val_section));
3568 case dw_val_class_str:
3569 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
3574 if (a->dw_attr_val.val_class != dw_val_class_loc)
3576 if (flag_verbose_asm)
3578 fprintf (asm_out_file, "\t%s %s",
3579 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3581 fputc ('\n', asm_out_file);
3584 for (c = die->die_child; c != NULL; c = c->die_sib)
3588 if (die->die_child != NULL)
3590 /* Add null byte to terminate sibling list. */
3591 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3592 if (flag_verbose_asm)
3593 fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
3594 ASM_COMMENT_START, die->die_offset);
3595 fputc ('\n', asm_out_file);
3599 /* Output the compilation unit that appears at the beginning of the
3600 .debug_info section, and precedes the DIE descriptions. */
3602 output_compilation_unit_header ()
3604 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
3605 if (flag_verbose_asm)
3607 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
3610 fputc ('\n', asm_out_file);
3611 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
3612 if (flag_verbose_asm)
3614 fprintf (asm_out_file, "\t%s DWARF version number",
3617 fputc ('\n', asm_out_file);
3618 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
3619 if (flag_verbose_asm)
3621 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
3624 fputc ('\n', asm_out_file);
3625 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
3626 if (flag_verbose_asm)
3628 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)",
3631 fputc ('\n', asm_out_file);
3634 /* Extract the register and offset values from RTL. If no register number
3635 is specified, return -1 to indicate frame-relative addressing. */
3637 decode_cfi_rtl (rtl, regp, offsetp)
3639 register unsigned long *regp;
3640 register long *offsetp;
3642 switch (GET_CODE (rtl))
3645 *regp = reg_number (rtl);
3649 *regp = reg_number (XEXP (rtl, 0));
3650 *offsetp = INTVAL (XEXP (rtl, 1));
3653 *regp = (unsigned long) -1;
3654 *offsetp = INTVAL (rtl);
3661 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
3662 or to the CIE if LABEL is NULL. */
3664 add_fde_cfi (label, cfi)
3665 register char * label;
3666 register dw_cfi_ref cfi;
3670 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
3671 if (fde->dw_fde_current_label == NULL
3672 || strcmp (label, fde->dw_fde_current_label) != 0)
3674 register dw_cfi_ref xcfi;
3676 fde->dw_fde_current_label = label = xstrdup (label);
3678 /* Set the location counter to the new label. */
3680 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
3681 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
3682 add_cfi (&fde->dw_fde_cfi, xcfi);
3684 add_cfi (&fde->dw_fde_cfi, cfi);
3687 add_cfi (&cie_cfi_head, cfi);
3690 /* Subroutine of lookup_cfa. */
3692 lookup_cfa_1 (cfi, regp, offsetp)
3693 register dw_cfi_ref cfi;
3694 register unsigned long *regp;
3695 register long *offsetp;
3697 switch (cfi->dw_cfi_opc)
3699 case DW_CFA_def_cfa_offset:
3700 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
3702 case DW_CFA_def_cfa_register:
3703 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
3705 case DW_CFA_def_cfa:
3706 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
3707 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
3712 /* Find the previous value for the CFA. */
3714 lookup_cfa (regp, offsetp)
3715 register unsigned long *regp;
3716 register long *offsetp;
3718 register dw_cfi_ref cfi;
3719 *regp = (unsigned long) -1;
3722 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
3723 lookup_cfa_1 (cfi, regp, offsetp);
3724 if (fde_table_in_use)
3726 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
3727 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
3728 lookup_cfa_1 (cfi, regp, offsetp);
3732 /* Entry point to update the canonical frame address (CFA).
3733 LABEL is passed to add_fde_cfi. RTL is either:
3735 a REG: The frame is at 0(REG).
3736 a PLUS of a REG and a CONST_INT: The frame is at CONST(REG). */
3738 dwarf2out_def_cfa (label, rtl)
3739 register char * label;
3742 register dw_cfi_ref cfi;
3743 unsigned long reg, old_reg;
3744 long offset, old_offset;
3746 decode_cfi_rtl (rtl, ®, &offset);
3747 lookup_cfa (&old_reg, &old_offset);
3749 if (reg == old_reg && offset == old_offset)
3756 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
3757 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
3759 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
3760 else if (offset == old_offset && old_reg != (unsigned long) -1)
3762 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
3763 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
3768 cfi->dw_cfi_opc = DW_CFA_def_cfa;
3769 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
3770 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
3773 add_fde_cfi (label, cfi);
3776 /* Add the CFI for saving a register. REG is the CFA column number.
3777 LABEL is passed to add_fde_cfi.
3780 a REG: The register is saved in REG.
3781 a CONST_INT: The register is saved at an offset of CONST
3784 reg_save (label, reg, rtl)
3785 register char * label;
3786 register unsigned long reg;
3789 register dw_cfi_ref cfi;
3795 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
3797 decode_cfi_rtl (rtl, &sreg, &offset);
3798 offset /= DWARF_CIE_DATA_ALIGNMENT;
3800 if (sreg == (unsigned long) -1)
3803 /* The register number won't fit in 6 bits, so we have to use
3805 cfi->dw_cfi_opc = DW_CFA_offset_extended;
3807 cfi->dw_cfi_opc = DW_CFA_offset;
3808 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
3812 cfi->dw_cfi_opc = DW_CFA_register;
3813 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
3816 add_fde_cfi (label, cfi);
3819 /* Entry point for saving a register. REG is the GCC register number.
3820 LABEL and RTL are passed to reg_save. */
3822 dwarf2out_reg_save (label, reg, rtl)
3823 register char * label;
3824 register unsigned long reg;
3827 reg_save (label, DWARF_FRAME_REGNUM (reg), rtl);
3830 /* Entry point for saving the return address.
3831 LABEL and RTL are passed to reg_save. */
3833 dwarf2out_return_save (label, rtl)
3834 register char * label;
3837 reg_save (label, DWARF_FRAME_RETURN_COLUMN, rtl);
3840 /* Return the size of a Call Frame Instruction. */
3841 static unsigned long
3845 register unsigned long size;
3846 /* count the 1-byte opcode */
3848 switch (cfi->dw_cfi_opc)
3851 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3853 case DW_CFA_set_loc:
3856 case DW_CFA_advance_loc1:
3859 case DW_CFA_advance_loc2:
3862 case DW_CFA_advance_loc4:
3865 #ifdef MIPS_DEBUGGING_INFO
3866 case DW_CFA_MIPS_advance_loc8:
3870 case DW_CFA_offset_extended:
3871 case DW_CFA_def_cfa:
3872 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3873 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3875 case DW_CFA_restore_extended:
3876 case DW_CFA_undefined:
3877 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3879 case DW_CFA_same_value:
3880 case DW_CFA_def_cfa_register:
3881 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3883 case DW_CFA_register:
3884 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3885 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3887 case DW_CFA_def_cfa_offset:
3888 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3896 /* Return the size of an FDE sans the length word. */
3897 inline unsigned long
3898 size_of_fde (fde, npad)
3900 unsigned long *npad;
3902 register dw_cfi_ref cfi;
3903 register unsigned long aligned_size;
3904 register unsigned long size;
3905 size = DWARF_FDE_HEADER_SIZE;
3906 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3908 size += size_of_cfi(cfi);
3910 /* Round the size up to a word boundary. */
3911 aligned_size = DWARF_ROUND (size, PTR_SIZE);
3912 *npad = aligned_size - size;
3913 return aligned_size;
3916 /* Calculate the size of the FDE table, and establish the offset
3917 of each FDE in the .debug_frame section. */
3921 register unsigned long i;
3922 register dw_fde_ref fde;
3923 register unsigned long fde_size;
3924 register dw_cfi_ref cfi;
3925 unsigned long fde_pad;
3927 cie_size = DWARF_CIE_HEADER_SIZE;
3928 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3929 cie_size += size_of_cfi (cfi);
3931 /* Initialize the beginning FDE offset. */
3932 next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
3934 for (i = 0; i < fde_table_in_use; ++i)
3936 fde = &fde_table[i];
3937 fde->dw_fde_offset = next_fde_offset;
3938 fde_size = size_of_fde (fde, &fde_pad);
3939 next_fde_offset += fde_size;
3943 /* Output a Call Frame Information opcode and its operand(s). */
3945 output_cfi (cfi, fde)
3946 register dw_cfi_ref cfi;
3947 register dw_fde_ref fde;
3949 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3951 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3953 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
3954 if (flag_verbose_asm)
3956 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START);
3958 fputc ('\n', asm_out_file);
3960 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3964 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3965 if (flag_verbose_asm)
3967 fprintf (asm_out_file, "\t%s DW_CFA_offset", ASM_COMMENT_START);
3969 fputc ('\n', asm_out_file);
3970 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3971 fputc ('\n', asm_out_file);
3973 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3975 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3977 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3978 if (flag_verbose_asm)
3980 fprintf (asm_out_file, "\t%s DW_CFA_restore", ASM_COMMENT_START);
3982 fputc ('\n', asm_out_file);
3986 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
3987 if (flag_verbose_asm)
3989 fprintf (asm_out_file, "\t%s %s",
3991 dwarf_cfi_name (cfi->dw_cfi_opc));
3993 fputc ('\n', asm_out_file);
3994 switch (cfi->dw_cfi_opc)
3996 case DW_CFA_set_loc:
3997 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3998 cfi->dw_cfi_oprnd1.dw_cfi_addr);
3999 fputc ('\n', asm_out_file);
4001 case DW_CFA_advance_loc1:
4002 /* TODO: not currently implemented. */
4005 case DW_CFA_advance_loc2:
4006 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
4007 cfi->dw_cfi_oprnd1.dw_cfi_addr,
4008 fde->dw_fde_current_label);
4009 fputc ('\n', asm_out_file);
4010 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
4012 case DW_CFA_advance_loc4:
4013 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
4014 cfi->dw_cfi_oprnd1.dw_cfi_addr,
4015 fde->dw_fde_current_label);
4016 fputc ('\n', asm_out_file);
4017 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
4019 #ifdef MIPS_DEBUGGING_INFO
4020 case DW_CFA_MIPS_advance_loc8:
4021 /* TODO: not currently implemented. */
4025 case DW_CFA_offset_extended:
4026 case DW_CFA_def_cfa:
4027 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4028 fputc ('\n', asm_out_file);
4029 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
4030 fputc ('\n', asm_out_file);
4032 case DW_CFA_restore_extended:
4033 case DW_CFA_undefined:
4034 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4035 fputc ('\n', asm_out_file);
4037 case DW_CFA_same_value:
4038 case DW_CFA_def_cfa_register:
4039 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4040 fputc ('\n', asm_out_file);
4042 case DW_CFA_register:
4043 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4044 fputc ('\n', asm_out_file);
4045 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4046 fputc ('\n', asm_out_file);
4048 case DW_CFA_def_cfa_offset:
4049 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
4050 fputc ('\n', asm_out_file);
4058 /* Output the call frame information used to used to record information
4059 that relates to calculating the frame pointer, and records the
4060 location of saved registers. */
4062 output_call_frame_info ()
4064 register unsigned long i, j;
4065 register dw_fde_ref fde;
4066 register unsigned long fde_size;
4067 register dw_cfi_ref cfi;
4068 unsigned long fde_pad;
4070 /* Only output the info if it will be interesting. */
4071 for (i = 0; i < fde_table_in_use; ++i)
4072 if (fde_table[i].dw_fde_cfi != NULL)
4074 if (i == fde_table_in_use)
4077 /* (re-)initialize the beginning FDE offset. */
4078 next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
4080 fputc ('\n', asm_out_file);
4081 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
4083 /* Output the CIE. */
4084 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_fde_offset - DWARF_OFFSET_SIZE);
4085 if (flag_verbose_asm)
4087 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
4090 fputc ('\n', asm_out_file);
4091 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
4092 if (flag_verbose_asm)
4094 fprintf (asm_out_file, "\t%s CIE Identifier Tag",
4097 fputc ('\n', asm_out_file);
4098 if (DWARF_OFFSET_SIZE == 8)
4100 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
4101 fputc ('\n', asm_out_file);
4103 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
4104 if (flag_verbose_asm)
4106 fprintf (asm_out_file, "\t%s CIE Version",
4109 fputc ('\n', asm_out_file);
4110 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4111 if (flag_verbose_asm)
4113 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
4116 fputc ('\n', asm_out_file);
4118 if (flag_verbose_asm)
4119 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
4120 fputc ('\n', asm_out_file);
4121 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
4122 if (flag_verbose_asm)
4123 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
4124 fputc ('\n', asm_out_file);
4125 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
4126 if (flag_verbose_asm)
4128 fprintf (asm_out_file, "\t%s CIE RA Column",
4131 fputc ('\n', asm_out_file);
4133 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
4136 /* Pad the CIE out to an address sized boundary. */
4137 for (i = next_fde_offset - cie_size; i; --i)
4139 /* Pad out to a pointer size boundary */
4140 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4141 if (flag_verbose_asm)
4143 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4146 fputc ('\n', asm_out_file);
4149 /* Loop through all of the FDE's. */
4150 for (i = 0; i < fde_table_in_use; ++i)
4152 fde = &fde_table[i];
4153 if (fde->dw_fde_cfi == NULL)
4155 fde_size = size_of_fde (fde, &fde_pad);
4156 ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
4157 if (flag_verbose_asm)
4159 fprintf (asm_out_file, "\t%s FDE Length",
4162 fputc ('\n', asm_out_file);
4163 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
4164 if (flag_verbose_asm)
4166 fprintf (asm_out_file, "\t%s FDE CIE offset",
4169 fputc ('\n', asm_out_file);
4170 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
4171 if (flag_verbose_asm)
4173 fprintf (asm_out_file, "\t%s FDE initial location",
4176 fputc ('\n', asm_out_file);
4177 ASM_OUTPUT_DWARF_ADDR_DELTA
4178 (asm_out_file, fde->dw_fde_end, fde->dw_fde_begin);
4179 if (flag_verbose_asm)
4181 fprintf (asm_out_file, "\t%s FDE address range",
4184 fputc ('\n', asm_out_file);
4186 /* Loop through the Call Frame Instructions associated with
4188 fde->dw_fde_current_label = fde->dw_fde_begin;
4189 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
4190 output_cfi (cfi, fde);
4192 /* Pad to a double word boundary. */
4193 for (j = 0; j < fde_pad; ++j)
4195 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4196 if (flag_verbose_asm)
4198 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4201 fputc ('\n', asm_out_file);
4206 /* Add a new entry to .debug_pubnames if appropriate. */
4208 add_pubname (decl, die)
4214 if (! TREE_PUBLIC (decl))
4217 if (pubname_table_in_use == pubname_table_allocated)
4219 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4220 pubname_table = (pubname_ref) xrealloc
4221 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4223 p = &pubname_table[pubname_table_in_use++];
4225 p->name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4228 /* Output the public names table used to speed up access to externally
4229 visible names. For now, only generate entries for externally
4230 visible procedures. */
4234 register unsigned i;
4236 register unsigned long pubnames_length = size_of_pubnames ();
4237 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
4239 if (flag_verbose_asm)
4241 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4244 fputc ('\n', asm_out_file);
4245 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4246 if (flag_verbose_asm)
4248 fprintf (asm_out_file, "\t%s DWARF Version",
4251 fputc ('\n', asm_out_file);
4252 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4253 if (flag_verbose_asm)
4255 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4258 fputc ('\n', asm_out_file);
4259 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
4260 if (flag_verbose_asm)
4262 fprintf (asm_out_file, "\t%s Compilation Unit Length",
4265 fputc ('\n', asm_out_file);
4266 for (i = 0; i < pubname_table_in_use; ++i)
4268 register pubname_ref pub = &pubname_table[i];
4269 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
4270 if (flag_verbose_asm)
4272 fprintf (asm_out_file, "\t%s DIE offset",
4275 fputc ('\n', asm_out_file);
4277 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4278 if (flag_verbose_asm)
4280 fprintf (asm_out_file, "%s external name",
4283 fputc ('\n', asm_out_file);
4285 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
4286 fputc ('\n', asm_out_file);
4289 /* Add a new entry to .debug_aranges if appropriate. */
4291 add_arange (decl, die)
4295 if (! DECL_SECTION_NAME (decl))
4298 if (arange_table_in_use == arange_table_allocated)
4300 arange_table_allocated += ARANGE_TABLE_INCREMENT;
4301 arange_table = (arange_ref) xrealloc
4302 (arange_table, arange_table_allocated * sizeof (dw_die_ref));
4304 arange_table[arange_table_in_use++] = die;
4307 /* Output the information that goes into the .debug_aranges table.
4308 Namely, define the beginning and ending address range of the
4309 text section generated for this compilation unit. */
4313 register unsigned i;
4315 register unsigned long aranges_length = size_of_aranges ();
4316 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
4318 if (flag_verbose_asm)
4320 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
4323 fputc ('\n', asm_out_file);
4324 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4325 if (flag_verbose_asm)
4327 fprintf (asm_out_file, "\t%s DWARF Version",
4330 fputc ('\n', asm_out_file);
4331 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4332 if (flag_verbose_asm)
4334 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4337 fputc ('\n', asm_out_file);
4338 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4339 if (flag_verbose_asm)
4341 fprintf (asm_out_file, "\t%s Size of Address",
4344 fputc ('\n', asm_out_file);
4345 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4346 if (flag_verbose_asm)
4348 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
4351 fputc ('\n', asm_out_file);
4352 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4354 fprintf (asm_out_file, ",0,0");
4355 if (flag_verbose_asm)
4357 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
4358 ASM_COMMENT_START, 2 * PTR_SIZE);
4360 fputc ('\n', asm_out_file);
4361 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
4362 if (flag_verbose_asm)
4364 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4366 fputc ('\n', asm_out_file);
4367 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
4368 if (flag_verbose_asm)
4370 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4372 fputc ('\n', asm_out_file);
4373 for (i = 0; i < arange_table_in_use; ++i)
4375 dw_die_ref a = arange_table[i];
4376 if (a->die_tag == DW_TAG_subprogram)
4377 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
4379 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_string (a, DW_AT_name));
4380 if (flag_verbose_asm)
4382 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4384 fputc ('\n', asm_out_file);
4385 if (a->die_tag == DW_TAG_subprogram)
4386 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
4389 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
4390 get_AT_unsigned (a, DW_AT_byte_size));
4391 if (flag_verbose_asm)
4393 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4395 fputc ('\n', asm_out_file);
4397 /* Output the terminator words. */
4398 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4399 fputc ('\n', asm_out_file);
4400 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4401 fputc ('\n', asm_out_file);
4404 /* Output the source line number correspondence information. This
4405 information goes into the .debug_line section. */
4409 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4410 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4411 register unsigned opc;
4412 register unsigned n_op_args;
4413 register unsigned long ft_index;
4414 register unsigned long lt_index;
4415 register unsigned long current_line;
4416 register long line_offset;
4417 register long line_delta;
4418 register unsigned long current_file;
4419 register unsigned long function;
4420 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
4421 if (flag_verbose_asm)
4423 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
4426 fputc ('\n', asm_out_file);
4427 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4428 if (flag_verbose_asm)
4430 fprintf (asm_out_file, "\t%s DWARF Version",
4433 fputc ('\n', asm_out_file);
4434 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
4435 if (flag_verbose_asm)
4437 fprintf (asm_out_file, "\t%s Prolog Length",
4440 fputc ('\n', asm_out_file);
4441 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
4442 if (flag_verbose_asm)
4444 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
4447 fputc ('\n', asm_out_file);
4448 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
4449 if (flag_verbose_asm)
4451 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
4454 fputc ('\n', asm_out_file);
4455 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
4456 if (flag_verbose_asm)
4458 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
4461 fputc ('\n', asm_out_file);
4462 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
4463 if (flag_verbose_asm)
4465 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
4468 fputc ('\n', asm_out_file);
4469 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
4470 if (flag_verbose_asm)
4472 fprintf (asm_out_file, "\t%s Special Opcode Base",
4475 fputc ('\n', asm_out_file);
4476 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
4480 case DW_LNS_advance_pc:
4481 case DW_LNS_advance_line:
4482 case DW_LNS_set_file:
4483 case DW_LNS_set_column:
4484 case DW_LNS_fixed_advance_pc:
4491 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
4492 if (flag_verbose_asm)
4494 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
4495 ASM_COMMENT_START, opc, n_op_args);
4497 fputc ('\n', asm_out_file);
4499 if (flag_verbose_asm)
4501 fprintf (asm_out_file, "%s Include Directory Table\n",
4504 /* Include directory table is empty, at present */
4505 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4506 fputc ('\n', asm_out_file);
4507 if (flag_verbose_asm)
4509 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
4511 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4513 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
4514 if (flag_verbose_asm)
4516 fprintf (asm_out_file, "%s File Entry: 0x%x",
4517 ASM_COMMENT_START, ft_index);
4519 fputc ('\n', asm_out_file);
4520 /* Include directory index */
4522 fputc ('\n', asm_out_file);
4523 /* Modification time */
4525 fputc ('\n', asm_out_file);
4526 /* File length in bytes */
4528 fputc ('\n', asm_out_file);
4530 /* Terminate the file name table */
4531 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4532 fputc ('\n', asm_out_file);
4534 /* Set the address register to the first location in the text section */
4535 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4536 if (flag_verbose_asm)
4538 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
4540 fputc ('\n', asm_out_file);
4541 output_uleb128 (1 + PTR_SIZE);
4542 fputc ('\n', asm_out_file);
4543 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4544 fputc ('\n', asm_out_file);
4545 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
4546 fputc ('\n', asm_out_file);
4548 /* Generate the line number to PC correspondence table, encoded as
4549 a series of state machine operations. */
4552 strcpy (prev_line_label, TEXT_SECTION);
4553 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4555 register dw_line_info_ref line_info;
4556 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4557 if (flag_verbose_asm)
4559 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4562 fputc ('\n', asm_out_file);
4563 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
4564 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4565 fputc ('\n', asm_out_file);
4566 line_info = &line_info_table[lt_index];
4567 if (line_info->dw_file_num != current_file)
4569 current_file = line_info->dw_file_num;
4570 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4571 if (flag_verbose_asm)
4573 fprintf (asm_out_file,
4574 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4576 fputc ('\n', asm_out_file);
4577 output_uleb128 (current_file);
4578 if (flag_verbose_asm)
4579 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
4580 fputc ('\n', asm_out_file);
4582 line_offset = line_info->dw_line_num - current_line;
4583 line_delta = line_offset - DWARF_LINE_BASE;
4584 current_line = line_info->dw_line_num;
4585 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4587 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4588 DWARF_LINE_OPCODE_BASE + line_delta);
4589 if (flag_verbose_asm)
4591 fprintf (asm_out_file,
4592 "\t%s line %d", ASM_COMMENT_START, current_line);
4594 fputc ('\n', asm_out_file);
4598 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4599 if (flag_verbose_asm)
4601 fprintf (asm_out_file,
4602 "\t%s advance to line %d",
4603 ASM_COMMENT_START, current_line);
4605 fputc ('\n', asm_out_file);
4606 output_sleb128 (line_offset);
4607 fputc ('\n', asm_out_file);
4608 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4609 fputc ('\n', asm_out_file);
4611 strcpy (prev_line_label, line_label);
4614 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4615 if (flag_verbose_asm)
4617 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4620 fputc ('\n', asm_out_file);
4621 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
4622 fputc ('\n', asm_out_file);
4624 /* Output the marker for the end of the line number info. */
4625 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4626 if (flag_verbose_asm)
4628 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
4630 fputc ('\n', asm_out_file);
4632 fputc ('\n', asm_out_file);
4633 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4634 fputc ('\n', asm_out_file);
4639 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4641 register dw_separate_line_info_ref line_info
4642 = &separate_line_info_table[lt_index];
4643 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
4645 if (function != line_info->function)
4647 function = line_info->function;
4648 /* Set the address register to the first line in the function */
4649 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4650 if (flag_verbose_asm)
4651 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
4653 fputc ('\n', asm_out_file);
4654 output_uleb128 (1 + PTR_SIZE);
4655 fputc ('\n', asm_out_file);
4656 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4657 fputc ('\n', asm_out_file);
4658 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
4659 fputc ('\n', asm_out_file);
4663 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4664 if (flag_verbose_asm)
4665 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4667 fputc ('\n', asm_out_file);
4668 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4669 fputc ('\n', asm_out_file);
4671 if (line_info->dw_file_num != current_file)
4673 current_file = line_info->dw_file_num;
4674 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4675 if (flag_verbose_asm)
4677 fprintf (asm_out_file,
4678 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4680 fputc ('\n', asm_out_file);
4681 output_uleb128 (current_file);
4682 if (flag_verbose_asm)
4683 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
4684 fputc ('\n', asm_out_file);
4686 if (line_info->dw_line_num != current_line)
4688 line_offset = line_info->dw_line_num - current_line;
4689 line_delta = line_offset - DWARF_LINE_BASE;
4690 current_line = line_info->dw_line_num;
4691 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4693 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4694 DWARF_LINE_OPCODE_BASE + line_delta);
4695 if (flag_verbose_asm)
4697 fprintf (asm_out_file,
4698 "\t%s line %d", ASM_COMMENT_START, current_line);
4700 fputc ('\n', asm_out_file);
4704 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4705 if (flag_verbose_asm)
4707 fprintf (asm_out_file,
4708 "\t%s advance to line %d",
4709 ASM_COMMENT_START, current_line);
4711 fputc ('\n', asm_out_file);
4712 output_sleb128 (line_offset);
4713 fputc ('\n', asm_out_file);
4714 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4715 fputc ('\n', asm_out_file);
4719 strcpy (prev_line_label, line_label);
4721 /* If we're done with a function, end its sequence. */
4722 if (lt_index == separate_line_info_table_in_use
4723 || separate_line_info_table[lt_index].function != function)
4727 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4728 if (flag_verbose_asm)
4729 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4731 fputc ('\n', asm_out_file);
4732 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
4733 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4734 fputc ('\n', asm_out_file);
4736 /* Output the marker for the end of this sequence. */
4737 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4738 if (flag_verbose_asm)
4739 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
4741 fputc ('\n', asm_out_file);
4743 fputc ('\n', asm_out_file);
4744 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4745 fputc ('\n', asm_out_file);
4750 /**************** attribute support utilities ********************************/
4753 * Given a pointer to a BLOCK node return non-zero if (and only if) the node
4754 * in question represents the outermost pair of curly braces (i.e. the "body
4755 * block") of a function or method.
4757 * For any BLOCK node representing a "body block" of a function or method, the
4758 * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
4759 * represents the outermost (function) scope for the function or method (i.e.
4760 * the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
4761 * *that* node in turn will point to the relevant FUNCTION_DECL node.
4764 is_body_block (stmt)
4767 if (TREE_CODE (stmt) == BLOCK)
4769 register tree parent = BLOCK_SUPERCONTEXT (stmt);
4771 if (TREE_CODE (parent) == BLOCK)
4773 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
4775 if (TREE_CODE (grandparent) == FUNCTION_DECL)
4782 /* Given a pointer to a tree node for some base type, return a pointer to
4783 a DIE that describes the given type.
4785 This routine must only be called for GCC type nodes that correspond to
4786 Dwarf base (fundamental) types. */
4788 base_type_die (type)
4791 register dw_die_ref base_type_result;
4792 register char *type_name;
4793 register enum dwarf_type encoding;
4795 if (TREE_CODE (type) == ERROR_MARK
4796 || TREE_CODE (type) == VOID_TYPE)
4800 register tree name = TYPE_NAME (type);
4801 if (TREE_CODE (name) == TYPE_DECL)
4802 name = DECL_NAME (name);
4803 type_name = IDENTIFIER_POINTER (name);
4806 switch (TREE_CODE (type))
4809 /* Carefully distinguish the C character types, without messing
4810 up if the language is not C. Note that we check only for the names
4811 that contain spaces; other names might occur by coincidence in other
4813 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
4814 && (type == char_type_node
4815 || ! strcmp (type_name, "signed char")
4816 || ! strcmp (type_name, "unsigned char"))))
4818 if (TREE_UNSIGNED (type))
4819 encoding = DW_ATE_unsigned;
4821 encoding = DW_ATE_signed;
4824 /* else fall through */
4827 /* GNU Pascal/Ada CHAR type. Not used in C. */
4828 if (TREE_UNSIGNED (type))
4829 encoding = DW_ATE_unsigned_char;
4831 encoding = DW_ATE_signed_char;
4835 encoding = DW_ATE_float;
4839 encoding = DW_ATE_complex_float;
4843 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
4844 encoding = DW_ATE_boolean;
4848 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
4851 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
4852 add_AT_string (base_type_result, DW_AT_name, type_name);
4853 add_AT_unsigned (base_type_result, DW_AT_byte_size,
4854 TYPE_PRECISION (type) / BITS_PER_UNIT);
4855 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
4857 return base_type_result;
4860 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
4861 the Dwarf "root" type for the given input type. The Dwarf "root" type of
4862 a given type is generally the same as the given type, except that if the
4863 given type is a pointer or reference type, then the root type of the given
4864 type is the root type of the "basis" type for the pointer or reference
4865 type. (This definition of the "root" type is recursive.) Also, the root
4866 type of a `const' qualified type or a `volatile' qualified type is the
4867 root type of the given type without the qualifiers. */
4872 if (TREE_CODE (type) == ERROR_MARK)
4873 return error_mark_node;
4875 switch (TREE_CODE (type))
4878 return error_mark_node;
4881 case REFERENCE_TYPE:
4882 return type_main_variant (root_type (TREE_TYPE (type)));
4885 return type_main_variant (type);
4889 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
4890 given input type is a Dwarf "fundamental" type. Otherwise return null. */
4895 switch (TREE_CODE (type))
4910 case QUAL_UNION_TYPE:
4915 case REFERENCE_TYPE:
4927 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
4928 entry that chains various modifiers in front of the given type. */
4930 modified_type_die (type, is_const_type, is_volatile_type, context_die)
4932 register int is_const_type;
4933 register int is_volatile_type;
4934 register dw_die_ref context_die;
4936 register enum tree_code code = TREE_CODE (type);
4937 register dw_die_ref mod_type_die = NULL;
4938 register dw_die_ref sub_die = NULL;
4939 register tree item_type;
4941 if (code != ERROR_MARK)
4943 type = build_type_variant (type, is_const_type, is_volatile_type);
4945 mod_type_die = lookup_type_die (type);
4947 return mod_type_die;
4949 /* Handle C typedef types. */
4950 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
4951 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
4953 tree dtype = TREE_TYPE (TYPE_NAME (type));
4956 /* For a named type, use the typedef. */
4957 gen_type_die (type, context_die);
4958 mod_type_die = lookup_type_die (type);
4960 else if (is_const_type < TYPE_READONLY (dtype)
4961 || is_volatile_type < TYPE_VOLATILE (dtype))
4962 /* cv-unqualified version of named type. Just use the unnamed
4963 type to which it refers. */
4964 mod_type_die = modified_type_die
4965 (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
4966 is_const_type, is_volatile_type);
4967 /* else cv-qualified version of named type; fall through. */
4972 else if (is_const_type)
4974 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
4975 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
4977 else if (is_volatile_type)
4979 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
4980 sub_die = modified_type_die (type, 0, 0, context_die);
4982 else if (code == POINTER_TYPE)
4984 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
4985 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
4987 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
4989 item_type = TREE_TYPE (type);
4990 sub_die = modified_type_die (item_type,
4991 TYPE_READONLY (item_type),
4992 TYPE_VOLATILE (item_type),
4995 else if (code == REFERENCE_TYPE)
4997 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
4998 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5000 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5002 item_type = TREE_TYPE (type);
5003 sub_die = modified_type_die (item_type,
5004 TYPE_READONLY (item_type),
5005 TYPE_VOLATILE (item_type),
5008 else if (is_base_type (type))
5010 mod_type_die = base_type_die (type);
5014 gen_type_die (type, context_die);
5016 /* We have to get the type_main_variant here (and pass that to the
5017 `lookup_type_die' routine) because the ..._TYPE node we have
5018 might simply be a *copy* of some original type node (where the
5019 copy was created to help us keep track of typedef names) and
5020 that copy might have a different TYPE_UID from the original
5022 mod_type_die = lookup_type_die (type_main_variant (type));
5023 assert (mod_type_die != NULL);
5026 if (sub_die != NULL)
5028 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5030 equate_type_number_to_die (type, mod_type_die);
5031 return mod_type_die;
5034 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5035 an enumerated type. */
5040 return TREE_CODE (type) == ENUMERAL_TYPE;
5043 /* Return the register number described by a given RTL node. */
5048 register unsigned regno = REGNO (rtl);
5050 if (regno >= FIRST_PSEUDO_REGISTER)
5052 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
5056 regno = DBX_REGISTER_NUMBER (regno);
5060 /* Return a location descriptor that designates a machine register. */
5061 static dw_loc_descr_ref
5062 reg_loc_descriptor (rtl)
5065 register dw_loc_descr_ref loc_result = NULL;
5066 register unsigned reg = reg_number (rtl);
5067 if (reg >= 0 && reg <= 31)
5069 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0);
5073 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5078 /* Return a location descriptor that designates a base+offset location. */
5079 static dw_loc_descr_ref
5080 based_loc_descr (reg, offset)
5084 register dw_loc_descr_ref loc_result;
5085 /* For the "frame base", we use the frame pointer or stack pointer
5086 registers, since the RTL for local variables is relative to one of
5088 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
5089 ? FRAME_POINTER_REGNUM
5090 : STACK_POINTER_REGNUM);
5093 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
5095 else if (reg >= 0 && reg <= 31)
5097 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset);
5101 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5106 /* Return true if this RTL expression describes a base+offset calculation. */
5111 return GET_CODE (rtl) == PLUS
5112 && ((GET_CODE (XEXP (rtl, 0)) == REG
5113 && GET_CODE (XEXP (rtl, 1)) == CONST_INT));
5116 /* The following routine converts the RTL for a variable or parameter
5117 (resident in memory) into an equivalent Dwarf representation of a
5118 mechanism for getting the address of that same variable onto the top of a
5119 hypothetical "address evaluation" stack.
5120 When creating memory location descriptors, we are effectively transforming
5121 the RTL for a memory-resident object into its Dwarf postfix expression
5122 equivalent. This routine recursively descends an RTL tree, turning
5123 it into Dwarf postfix code as it goes. */
5124 static dw_loc_descr_ref
5125 mem_loc_descriptor (rtl)
5128 dw_loc_descr_ref mem_loc_result = NULL;
5129 /* Note that for a dynamically sized array, the location we will generate a
5130 description of here will be the lowest numbered location which is
5131 actually within the array. That's *not* necessarily the same as the
5132 zeroth element of the array. */
5133 switch (GET_CODE (rtl))
5136 /* The case of a subreg may arise when we have a local (register)
5137 variable or a formal (register) parameter which doesn't quite fill
5138 up an entire register. For now, just assume that it is
5139 legitimate to make the Dwarf info refer to the whole register which
5140 contains the given subreg. */
5141 rtl = XEXP (rtl, 0);
5145 /* Whenever a register number forms a part of the description of the
5146 method for calculating the (dynamic) address of a memory resident
5147 object, DWARF rules require the register number be referred to as
5148 a "base register". This distinction is not based in any way upon
5149 what category of register the hardware believes the given register
5150 belongs to. This is strictly DWARF terminology we're dealing with
5151 here. Note that in cases where the location of a memory-resident
5152 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5153 OP_CONST (0)) the actual DWARF location descriptor that we generate
5154 may just be OP_BASEREG (basereg). This may look deceptively like
5155 the object in question was allocated to a register (rather than in
5156 memory) so DWARF consumers need to be aware of the subtle
5157 distinction between OP_REG and OP_BASEREG. */
5158 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
5162 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5163 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
5168 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
5169 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
5170 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
5174 if (is_based_loc (rtl))
5176 mem_loc_result = based_loc_descr (
5177 reg_number (XEXP (rtl, 0)),
5178 INTVAL (XEXP (rtl, 1)));
5182 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5183 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5184 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
5189 /* If a pseudo-reg is optimized away, it is possible for it to
5190 be replaced with a MEM containing a multiply. */
5191 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5192 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5193 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
5197 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5203 return mem_loc_result;
5206 /* Output a proper Dwarf location descriptor for a variable or parameter
5207 which is either allocated in a register or in a memory location. For a
5208 register, we just generate an OP_REG and the register number. For a
5209 memory location we provide a Dwarf postfix expression describing how to
5210 generate the (dynamic) address of the object onto the address stack. */
5211 static dw_loc_descr_ref
5212 loc_descriptor (rtl)
5215 dw_loc_descr_ref loc_result = NULL;
5216 switch (GET_CODE (rtl))
5220 /* The case of a subreg may arise when we have a local (register)
5221 variable or a formal (register) parameter which doesn't quite fill
5222 up an entire register. For now, just assume that it is
5223 legitimate to make the Dwarf info refer to the whole register which
5224 contains the given subreg. */
5226 rtl = XEXP (rtl, 0);
5230 loc_result = reg_loc_descriptor (rtl);
5234 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5238 abort (); /* Should never happen */
5243 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
5244 which is not less than the value itself. */
5246 ceiling (value, boundary)
5247 register unsigned value;
5248 register unsigned boundary;
5250 return (((value + boundary - 1) / boundary) * boundary);
5253 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5254 pointer to the declared type for the relevant field variable, or return
5255 `integer_type_node' if the given node turns out to be an
5263 if (TREE_CODE (decl) == ERROR_MARK)
5264 return integer_type_node;
5266 type = DECL_BIT_FIELD_TYPE (decl);
5268 type = TREE_TYPE (decl);
5273 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5274 node, return the alignment in bits for the type, or else return
5275 BITS_PER_WORD if the node actually turns out to be an
5278 simple_type_align_in_bits (type)
5281 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5284 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5285 node, return the size in bits for the type if it is a constant, or else
5286 return the alignment for the type if the type's size is not constant, or
5287 else return BITS_PER_WORD if the type actually turns out to be an
5290 simple_type_size_in_bits (type)
5293 if (TREE_CODE (type) == ERROR_MARK)
5294 return BITS_PER_WORD;
5297 register tree type_size_tree = TYPE_SIZE (type);
5299 if (TREE_CODE (type_size_tree) != INTEGER_CST)
5300 return TYPE_ALIGN (type);
5302 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5306 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5307 return the byte offset of the lowest addressed byte of the "containing
5308 object" for the given FIELD_DECL, or return 0 if we are unable to
5309 determine what that offset is, either because the argument turns out to
5310 be a pointer to an ERROR_MARK node, or because the offset is actually
5311 variable. (We can't handle the latter case just yet). */
5313 field_byte_offset (decl)
5316 register unsigned type_align_in_bytes;
5317 register unsigned type_align_in_bits;
5318 register unsigned type_size_in_bits;
5319 register unsigned object_offset_in_align_units;
5320 register unsigned object_offset_in_bits;
5321 register unsigned object_offset_in_bytes;
5323 register tree bitpos_tree;
5324 register tree field_size_tree;
5325 register unsigned bitpos_int;
5326 register unsigned deepest_bitpos;
5327 register unsigned field_size_in_bits;
5329 if (TREE_CODE (decl) == ERROR_MARK)
5332 if (TREE_CODE (decl) != FIELD_DECL)
5335 type = field_type (decl);
5337 bitpos_tree = DECL_FIELD_BITPOS (decl);
5338 field_size_tree = DECL_SIZE (decl);
5340 /* We cannot yet cope with fields whose positions or sizes are variable, so
5341 for now, when we see such things, we simply return 0. Someday, we may
5342 be able to handle such cases, but it will be damn difficult. */
5343 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5345 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5347 if (TREE_CODE (field_size_tree) != INTEGER_CST)
5349 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
5351 type_size_in_bits = simple_type_size_in_bits (type);
5353 type_align_in_bits = simple_type_align_in_bits (type);
5354 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
5356 /* Note that the GCC front-end doesn't make any attempt to keep track of
5357 the starting bit offset (relative to the start of the containing
5358 structure type) of the hypothetical "containing object" for a bit-
5359 field. Thus, when computing the byte offset value for the start of the
5360 "containing object" of a bit-field, we must deduce this information on
5361 our own. This can be rather tricky to do in some cases. For example,
5362 handling the following structure type definition when compiling for an
5363 i386/i486 target (which only aligns long long's to 32-bit boundaries)
5366 struct S { int field1; long long field2:31; };
5368 Fortunately, there is a simple rule-of-thumb which can be
5369 used in such cases. When compiling for an i386/i486, GCC will allocate
5370 8 bytes for the structure shown above. It decides to do this based upon
5371 one simple rule for bit-field allocation. Quite simply, GCC allocates
5372 each "containing object" for each bit-field at the first (i.e. lowest
5373 addressed) legitimate alignment boundary (based upon the required
5374 minimum alignment for the declared type of the field) which it can
5375 possibly use, subject to the condition that there is still enough
5376 available space remaining in the containing object (when allocated at
5377 the selected point) to fully accommodate all of the bits of the
5378 bit-field itself. This simple rule makes it obvious why GCC allocates
5379 8 bytes for each object of the structure type shown above. When looking
5380 for a place to allocate the "containing object" for `field2', the
5381 compiler simply tries to allocate a 64-bit "containing object" at each
5382 successive 32-bit boundary (starting at zero) until it finds a place to
5383 allocate that 64- bit field such that at least 31 contiguous (and
5384 previously unallocated) bits remain within that selected 64 bit field.
5385 (As it turns out, for the example above, the compiler finds that it is
5386 OK to allocate the "containing object" 64-bit field at bit-offset zero
5387 within the structure type.) Here we attempt to work backwards from the
5388 limited set of facts we're given, and we try to deduce from those facts,
5389 where GCC must have believed that the containing object started (within
5390 the structure type). The value we deduce is then used (by the callers of
5391 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
5392 for fields (both bit-fields and, in the case of DW_AT_location, regular
5395 /* Figure out the bit-distance from the start of the structure to the
5396 "deepest" bit of the bit-field. */
5397 deepest_bitpos = bitpos_int + field_size_in_bits;
5399 /* This is the tricky part. Use some fancy footwork to deduce where the
5400 lowest addressed bit of the containing object must be. */
5401 object_offset_in_bits
5402 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
5404 /* Compute the offset of the containing object in "alignment units". */
5405 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
5407 /* Compute the offset of the containing object in bytes. */
5408 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
5410 return object_offset_in_bytes;
5415 /****************************** attributes *********************************/
5417 /* The following routines define various Dwarf attributes
5418 (and any data associated with them). */
5421 /* Output the form of location attributes suitable for whole variables and
5422 whole parameters. Note that the location attributes for struct fields are
5423 generated by the routine `data_member_location_attribute' below. */
5425 add_location_attribute (die, rtl)
5429 dw_loc_descr_ref loc_descr = NULL;
5431 /* Handle a special case. If we are about to output a location descriptor
5432 for a variable or parameter which has been optimized out of existence,
5433 don't do that. Instead we output a null location descriptor value as
5434 part of the location attribute. A variable which has been optimized out
5435 of existence will have a DECL_RTL value which denotes a pseudo-reg.
5436 Currently, in some rare cases, variables can have DECL_RTL values which
5437 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
5438 elsewhere in the compiler. We treat such cases as if the variable(s) in
5439 question had been optimized out of existence. Note that in all cases
5440 where we wish to express the fact that a variable has been optimized out
5441 of existence, we do not simply suppress the generation of the entire
5442 location attribute because the absence of a location attribute in
5443 certain kinds of DIEs is used to indicate something else entirely...
5444 i.e. that the DIE represents an object declaration, but not a
5445 definition. So sayeth the PLSIG. */
5446 if (!is_pseudo_reg (rtl)
5447 && (GET_CODE (rtl) != MEM
5448 || !is_pseudo_reg (XEXP (rtl, 0))))
5450 loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
5453 #ifdef MIPS_DEBUGGING_INFO
5454 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
5455 location descriptor. Lets just use r0 for now to represent a
5456 variable that has been optimized away. */
5457 if (loc_descr == NULL)
5459 loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
5463 add_AT_loc (die, DW_AT_location, loc_descr);
5466 /* Attach the specialized form of location attribute used for data
5467 members of struct and union types. In the special case of a
5468 FIELD_DECL node which represents a bit-field, the "offset" part
5469 of this special location descriptor must indicate the distance
5470 in bytes from the lowest-addressed byte of the containing struct
5471 or union type to the lowest-addressed byte of the "containing
5472 object" for the bit-field. (See the `field_byte_offset' function
5473 above).. For any given bit-field, the "containing object" is a
5474 hypothetical object (of some integral or enum type) within which
5475 the given bit-field lives. The type of this hypothetical
5476 "containing object" is always the same as the declared type of
5477 the individual bit-field itself (for GCC anyway... the DWARF
5478 spec doesn't actually mandate this). Note that it is the size
5479 (in bytes) of the hypothetical "containing object" which will
5480 be given in the DW_AT_byte_size attribute for this bit-field.
5481 (See the `byte_size_attribute' function below.) It is also used
5482 when calculating the value of the DW_AT_bit_offset attribute.
5483 (See the `bit_offset_attribute' function below). */
5485 add_data_member_location_attribute (die, decl)
5486 register dw_die_ref die;
5489 register unsigned long offset;
5490 register dw_loc_descr_ref loc_descr;
5491 register enum dwarf_location_atom op;
5493 if (TREE_CODE (decl) == TREE_VEC)
5494 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
5496 offset = field_byte_offset (decl);
5498 /* The DWARF2 standard says that we should assume that the structure address
5499 is already on the stack, so we can specify a structure field address
5500 by using DW_OP_plus_uconst. */
5501 #ifdef MIPS_DEBUGGING_INFO
5502 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
5503 correctly. It works only if we leave the offset on the stack. */
5506 op = DW_OP_plus_uconst;
5508 loc_descr = new_loc_descr (op, offset, 0);
5509 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
5512 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
5513 does not have a "location" either in memory or in a register. These
5514 things can arise in GNU C when a constant is passed as an actual parameter
5515 to an inlined function. They can also arise in C++ where declared
5516 constants do not necessarily get memory "homes". */
5518 add_const_value_attribute (die, rtl)
5519 register dw_die_ref die;
5522 switch (GET_CODE (rtl))
5525 /* Note that a CONST_INT rtx could represent either an integer or a
5526 floating-point constant. A CONST_INT is used whenever the constant
5527 will fit into a single word. In all such cases, the original mode
5528 of the constant value is wiped out, and the CONST_INT rtx is
5529 assigned VOIDmode. */
5530 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
5534 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
5535 floating-point constant. A CONST_DOUBLE is used whenever the
5536 constant requires more than one word in order to be adequately
5537 represented. In all such cases, the original mode of the constant
5538 value is preserved as the mode of the CONST_DOUBLE rtx, but for
5539 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
5540 add_AT_double (die, DW_AT_const_value,
5541 (unsigned) CONST_DOUBLE_HIGH (rtl),
5542 (unsigned) CONST_DOUBLE_LOW (rtl));
5546 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
5552 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
5556 /* In cases where an inlined instance of an inline function is passed
5557 the address of an `auto' variable (which is local to the caller) we
5558 can get a situation where the DECL_RTL of the artificial local
5559 variable (for the inlining) which acts as a stand-in for the
5560 corresponding formal parameter (of the inline function) will look
5561 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
5562 exactly a compile-time constant expression, but it isn't the address
5563 of the (artificial) local variable either. Rather, it represents the
5564 *value* which the artificial local variable always has during its
5565 lifetime. We currently have no way to represent such quasi-constant
5566 values in Dwarf, so for now we just punt and generate an
5567 DW_AT_const_value attribute with null address. */
5568 add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
5572 /* No other kinds of rtx should be possible here. */
5578 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
5579 data attribute for a variable or a parameter. We generate the
5580 DW_AT_const_value attribute only in those cases where the given variable
5581 or parameter does not have a true "location" either in memory or in a
5582 register. This can happen (for example) when a constant is passed as an
5583 actual argument in a call to an inline function. (It's possible that
5584 these things can crop up in other ways also.) Note that one type of
5585 constant value which can be passed into an inlined function is a constant
5586 pointer. This can happen for example if an actual argument in an inlined
5587 function call evaluates to a compile-time constant address. */
5589 add_location_or_const_value_attribute (die, decl)
5590 register dw_die_ref die;
5594 register tree declared_type;
5595 register tree passed_type;
5597 if (TREE_CODE (decl) == ERROR_MARK)
5601 if ((TREE_CODE (decl) != VAR_DECL)
5602 && (TREE_CODE (decl) != PARM_DECL))
5604 /* Should never happen. */
5608 /* Here we have to decide where we are going to say the parameter "lives"
5609 (as far as the debugger is concerned). We only have a couple of
5610 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
5611 DECL_RTL normally indicates where the parameter lives during most of the
5612 activa- tion of the function. If optimization is enabled however, this
5613 could be either NULL or else a pseudo-reg. Both of those cases indicate
5614 that the parameter doesn't really live anywhere (as far as the code
5615 generation parts of GCC are concerned) during most of the function's
5616 activation. That will happen (for example) if the parameter is never
5617 referenced within the function. We could just generate a location
5618 descriptor here for all non-NULL non-pseudo values of DECL_RTL and
5619 ignore all of the rest, but we can be a little nicer than that if we
5620 also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a
5621 pseudo-reg. Note however that we can only get away with using
5622 DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited
5623 cases. In cases where DECL_ARG_TYPE(decl) indicates the same type as
5624 TREE_TYPE(decl) we can be sure that the parameter was passed using the
5625 same type as it is declared to have within the function, and that its
5626 DECL_INCOMING_RTL points us to a place where a value of that type is
5627 passed. In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are
5628 different types however, we cannot (in general) use DECL_INCOMING_RTL as
5629 a backup substitute for DECL_RTL because in these cases,
5630 DECL_INCOMING_RTL points us to a value of some type which is *different*
5631 from the type of the parameter itself. Thus, if we tried to use
5632 DECL_INCOMING_RTL to generate a location attribute in such cases, the
5633 debugger would end up (for example) trying to fetch a `float' from a
5634 place which actually contains the first part of a `double'. That would
5635 lead to really incorrect and confusing output at debug-time, and we
5636 don't want that now do we? So in general, we DO NOT use
5637 DECL_INCOMING_RTL as a backup for DECL_RTL in cases where
5638 DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a couple of cute
5639 exceptions however. On little-endian machines we can get away with
5640 using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as
5641 TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type
5642 which is smaller than TREE_TYPE(decl). These cases arise when (on a
5643 little-endian machine) a non-prototyped function has a parameter
5644 declared to be of type `short' or `char'. In such cases,
5645 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
5646 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
5647 passed `int' value. If the debugger then uses that address to fetch a
5648 `short' or a `char' (on a little-endian machine) the result will be the
5649 correct data, so we allow for such exceptional cases below. Note that
5650 our goal here is to describe the place where the given formal parameter
5651 lives during most of the function's activation (i.e. between the end of
5652 the prologue and the start of the epilogue). We'll do that as best as
5653 we can. Note however that if the given formal parameter is modified
5654 sometime during the execution of the function, then a stack backtrace
5655 (at debug-time) will show the function as having been called with the
5656 *new* value rather than the value which was originally passed in. This
5657 happens rarely enough that it is not a major problem, but it *is* a
5658 problem, and I'd like to fix it. A future version of dwarf2out.c may
5659 generate two additional attributes for any given DW_TAG_formal_parameter
5660 DIE which will describe the "passed type" and the "passed location" for
5661 the given formal parameter in addition to the attributes we now generate
5662 to indicate the "declared type" and the "active location" for each
5663 parameter. This additional set of attributes could be used by debuggers
5664 for stack backtraces. Separately, note that sometimes DECL_RTL can be
5665 NULL and DECL_INCOMING_RTL can be NULL also. This happens (for example)
5666 for inlined-instances of inline function formal parameters which are
5667 never referenced. This really shouldn't be happening. All PARM_DECL
5668 nodes should get valid non-NULL DECL_INCOMING_RTL values, but
5669 integrate.c doesn't currently generate these values for inlined
5670 instances of inline function parameters, so when we see such cases, we
5671 are just SOL (shit-out-of-luck) for the time being (until integrate.c
5674 /* Use DECL_RTL as the "location" unless we find something better. */
5675 rtl = DECL_RTL (decl);
5677 if (TREE_CODE (decl) == PARM_DECL)
5679 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
5681 declared_type = type_main_variant (TREE_TYPE (decl));
5682 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
5683 /* This decl represents a formal parameter which was
5686 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
5687 all* cases where (rtl == NULL_RTX) just below. */
5688 if (declared_type == passed_type)
5690 rtl = DECL_INCOMING_RTL (decl);
5692 else if (!BYTES_BIG_ENDIAN)
5694 if (TREE_CODE (declared_type) == INTEGER_TYPE)
5696 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
5698 rtl = DECL_INCOMING_RTL (decl);
5704 if (rtl == NULL_RTX)
5707 switch (GET_CODE (rtl))
5716 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
5717 add_const_value_attribute (die, rtl);
5723 add_location_attribute (die, rtl);
5727 abort (); /* Should never happen. */
5731 /* Generate an DW_AT_name attribute given some string value to be included as
5732 the value of the attribute. */
5734 add_name_attribute (die, name_string)
5735 register dw_die_ref die;
5736 register char *name_string;
5738 if (name_string && *name_string)
5740 add_AT_string (die, DW_AT_name, name_string);
5744 /* Given a tree node describing an array bound (either lower or upper) output
5745 a representation for that bound.
5747 FIXME: This uses location descriptions for variable bounds, whereas the
5748 DWARF-2 spec only allowes for constants or DIE references. */
5750 add_bound_info (subrange_die, bound_attr, bound)
5751 register dw_die_ref subrange_die;
5752 register enum dwarf_attribute bound_attr;
5753 register tree bound;
5755 register dw_loc_descr_ref bound_loc = NULL;
5756 register unsigned bound_value = 0;
5757 switch (TREE_CODE (bound))
5762 /* All fixed-bounds are represented by INTEGER_CST nodes. */
5764 bound_value = TREE_INT_CST_LOW (bound);
5765 /* TODO: we need to check for C language below, or some flag
5766 derived from the language. C implies a lower bound of 0. */
5767 if (!(bound_attr == DW_AT_lower_bound && bound_value == 0))
5769 add_AT_unsigned (subrange_die, bound_attr, bound_value);
5773 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
5776 bound = TREE_OPERAND (bound, 0);
5777 /* ... fall thru... */
5780 /* If optimization is turned on, the SAVE_EXPRs that describe how to
5781 access the upper bound values are essentially bogus. They only
5782 describe (at best) how to get at these values at the points in the
5783 generated code right after they have just been computed. Worse yet,
5784 in the typical case, the upper bound values will not even *be*
5785 computed in the optimized code, so these SAVE_EXPRs are entirely
5786 bogus. In order to compensate for this fact, we check here to see if
5787 optimization is enabled, and if so, we effectively create an empty
5788 location description for the (unknown and unknowable) upper bound.
5789 This should not cause too much trouble for existing (stupid?)
5790 debuggers because they have to deal with empty upper bounds location
5791 descriptions anyway in order to be able to deal with incomplete array
5792 types. Of course an intelligent debugger (GDB?) should be able to
5793 comprehend that a missing upper bound specification in a array type
5794 used for a storage class `auto' local array variable indicates that
5795 the upper bound is both unknown (at compile- time) and unknowable (at
5796 run-time) due to optimization. */
5799 bound_loc = mem_loc_descriptor (
5800 eliminate_regs (SAVE_EXPR_RTL (bound),
5807 add_AT_loc (subrange_die, bound_attr, bound_loc);
5815 /* Note that the block of subscript information for an array type also
5816 includes information about the element type of type given array type. */
5818 add_subscript_info (type_die, type)
5819 register dw_die_ref type_die;
5822 register unsigned dimension_number;
5823 register tree lower, upper;
5824 register dw_die_ref subrange_die;
5826 /* The GNU compilers represent multidimensional array types as sequences of
5827 one dimensional array types whose element types are themselves array
5828 types. Here we squish that down, so that each multidimensional array
5829 type gets only one array_type DIE in the Dwarf debugging info. The draft
5830 Dwarf specification say that we are allowed to do this kind of
5831 compression in C (because there is no difference between an array or
5832 arrays and a multidimensional array in C) but for other source languages
5833 (e.g. Ada) we probably shouldn't do this. */
5834 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5835 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
5836 We work around this by disabling this feature. See also
5837 gen_array_type_die. */
5838 #ifndef MIPS_DEBUGGING_INFO
5839 for (dimension_number = 0;
5840 TREE_CODE (type) == ARRAY_TYPE;
5841 type = TREE_TYPE (type), dimension_number++)
5844 register tree domain = TYPE_DOMAIN (type);
5846 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
5847 and (in GNU C only) variable bounds. Handle all three forms
5849 subrange_die = new_die (DW_TAG_subrange_type, type_die);
5852 /* We have an array type with specified bounds. */
5853 lower = TYPE_MIN_VALUE (domain);
5854 upper = TYPE_MAX_VALUE (domain);
5856 /* define the index type. */
5857 if (TREE_TYPE (domain))
5858 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
5861 if (! is_c_family () && ! is_fortran ())
5862 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
5863 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
5867 /* We have an array type with an unspecified length. The DWARF-2
5868 spec does not say how to handle this; let's just leave out the
5871 #ifndef MIPS_DEBUGGING_INFO
5877 add_byte_size_attribute (die, tree_node)
5879 register tree tree_node;
5881 register unsigned size;
5883 switch (TREE_CODE (tree_node))
5891 case QUAL_UNION_TYPE:
5892 size = int_size_in_bytes (tree_node);
5895 /* For a data member of a struct or union, the DW_AT_byte_size is
5896 generally given as the number of bytes normally allocated for an
5897 object of the *declared* type of the member itself. This is true
5898 even for bit-fields. */
5899 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
5905 /* Note that `size' might be -1 when we get to this point. If it is, that
5906 indicates that the byte size of the entity in question is variable. We
5907 have no good way of expressing this fact in Dwarf at the present time,
5908 so just let the -1 pass on through. */
5910 add_AT_unsigned (die, DW_AT_byte_size, size);
5913 /* For a FIELD_DECL node which represents a bit-field, output an attribute
5914 which specifies the distance in bits from the highest order bit of the
5915 "containing object" for the bit-field to the highest order bit of the
5918 For any given bit-field, the "containing object" is a hypothetical
5919 object (of some integral or enum type) within which the given bit-field
5920 lives. The type of this hypothetical "containing object" is always the
5921 same as the declared type of the individual bit-field itself. The
5922 determination of the exact location of the "containing object" for a
5923 bit-field is rather complicated. It's handled by the
5924 `field_byte_offset' function (above).
5926 Note that it is the size (in bytes) of the hypothetical "containing object"
5927 which will be given in the DW_AT_byte_size attribute for this bit-field.
5928 (See `byte_size_attribute' above). */
5930 add_bit_offset_attribute (die, decl)
5931 register dw_die_ref die;
5934 register unsigned object_offset_in_bytes = field_byte_offset (decl);
5935 register tree type = DECL_BIT_FIELD_TYPE (decl);
5936 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
5937 register unsigned bitpos_int;
5938 register unsigned highest_order_object_bit_offset;
5939 register unsigned highest_order_field_bit_offset;
5940 register unsigned bit_offset;
5942 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5943 assert (type); /* Must be a bit field. */
5945 /* We can't yet handle bit-fields whose offsets are variable, so if we
5946 encounter such things, just return without generating any attribute
5948 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5952 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5954 /* Note that the bit offset is always the distance (in bits) from the
5955 highest-order bit of the "containing object" to the highest-order bit of
5956 the bit-field itself. Since the "high-order end" of any object or field
5957 is different on big-endian and little-endian machines, the computation
5958 below must take account of these differences. */
5959 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
5960 highest_order_field_bit_offset = bitpos_int;
5962 if (!BYTES_BIG_ENDIAN)
5964 highest_order_field_bit_offset
5965 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
5967 highest_order_object_bit_offset += simple_type_size_in_bits (type);
5971 ? highest_order_object_bit_offset - highest_order_field_bit_offset
5972 : highest_order_field_bit_offset - highest_order_object_bit_offset);
5974 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
5977 /* For a FIELD_DECL node which represents a bit field, output an attribute
5978 which specifies the length in bits of the given field. */
5980 add_bit_size_attribute (die, decl)
5981 register dw_die_ref die;
5984 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5985 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
5986 add_AT_unsigned (die, DW_AT_bit_size,
5987 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
5990 /* If the compiled language is ANSI C, then add a 'prototyped'
5991 attribute, if arg types are given for the parameters of a function. */
5993 add_prototyped_attribute (die, func_type)
5994 register dw_die_ref die;
5995 register tree func_type;
5997 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
5998 && TYPE_ARG_TYPES (func_type) != NULL)
5999 add_AT_flag (die, DW_AT_prototyped, 1);
6003 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
6004 by looking in either the type declaration or object declaration
6007 add_abstract_origin_attribute (die, origin)
6008 register dw_die_ref die;
6009 register tree origin;
6011 dw_die_ref origin_die = NULL;
6012 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6014 origin_die = lookup_decl_die (origin);
6016 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6018 origin_die = lookup_type_die (origin);
6020 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6023 /* We do not currently support the pure_virtual attribute. */
6026 add_pure_or_virtual_attribute (die, func_decl)
6027 register dw_die_ref die;
6028 register tree func_decl;
6030 if (DECL_VINDEX (func_decl))
6032 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6033 add_AT_loc (die, DW_AT_vtable_elem_location, new_loc_descr
6034 (DW_OP_constu, TREE_INT_CST_LOW (DECL_VINDEX (func_decl))));
6035 /* GNU extension: Record what type this method came from originally. */
6036 if (debug_info_level > DINFO_LEVEL_TERSE)
6037 add_AT_die_ref (die, DW_AT_containing_type,
6038 lookup_type_die (DECL_CONTEXT (func_decl)));
6042 /********************* utility routines for DIEs *************************/
6044 /* Add source coordinate attributes for the given decl. */
6046 add_src_coords_attributes (die, decl)
6047 register dw_die_ref die;
6050 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
6051 add_AT_unsigned (die, DW_AT_decl_file, file_index);
6052 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6055 /* Add an DW_AT_name attribute and source coordinate attribute for the
6056 given decl, but only if it actually has a name. */
6058 add_name_and_src_coords_attributes (die, decl)
6059 register dw_die_ref die;
6062 register tree decl_name;
6063 if (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
6064 decl_name = DECL_ASSEMBLER_NAME (decl);
6066 decl_name = DECL_NAME (decl);
6068 if (decl_name && IDENTIFIER_POINTER (decl_name))
6070 add_name_attribute (die, IDENTIFIER_POINTER (decl_name));
6071 add_src_coords_attributes (die, decl);
6075 /* Push a new declaration scope. */
6077 push_decl_scope (scope)
6080 /* Make room in the decl_scope_table, if necessary. */
6081 if (decl_scope_table_allocated == decl_scope_depth)
6083 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
6084 decl_scope_table = (tree *) xrealloc (decl_scope_table,
6085 decl_scope_table_allocated * sizeof (tree));
6087 decl_scope_table[decl_scope_depth++] = scope;
6090 /* Return the DIE for the scope the immediately contains this declaration. */
6092 scope_die_for (t, context_die)
6094 register dw_die_ref context_die;
6096 register dw_die_ref scope_die = NULL;
6097 register tree containing_scope;
6098 register unsigned long i;
6100 /* Function-local tags and functions get stuck in limbo until they are
6101 fixed up by decls_for_scope. */
6102 if (context_die == NULL
6103 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
6106 /* Walk back up the declaration tree looking for a place to define
6108 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
6109 containing_scope = TYPE_CONTEXT (t);
6110 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
6111 containing_scope = decl_class_context (t);
6113 containing_scope = DECL_CONTEXT (t);
6115 if (containing_scope == NULL)
6117 scope_die = comp_unit_die;
6121 for (i = decl_scope_depth, scope_die = context_die;
6122 i > 0 && decl_scope_table[i - 1] != containing_scope;
6123 scope_die = scope_die->die_parent, --i)
6127 assert (scope_die == comp_unit_die);
6128 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
6129 if (debug_info_level > DINFO_LEVEL_TERSE)
6130 assert (TREE_ASM_WRITTEN (containing_scope));
6136 /* Pop a declaration scope. */
6140 assert (decl_scope_depth > 0);
6144 /* Many forms of DIEs require a "type description" attribute. This
6145 routine locates the proper "type descriptor" die for the type given
6146 by 'type', and adds an DW_AT_type attribute below the given die. */
6148 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
6149 register dw_die_ref object_die;
6151 register int decl_const;
6152 register int decl_volatile;
6153 register dw_die_ref context_die;
6155 register enum tree_code code = TREE_CODE (type);
6156 register dw_die_ref type_die = NULL;
6158 if (code == ERROR_MARK)
6163 /* Handle a special case. For functions whose return type is void, we
6164 generate *no* type attribute. (Note that no object may have type
6165 `void', so this only applies to function return types). */
6166 if (code == VOID_TYPE)
6171 type_die = modified_type_die (type,
6172 decl_const || TYPE_READONLY (type),
6173 decl_volatile || TYPE_VOLATILE (type),
6175 if (type_die != NULL)
6177 add_AT_die_ref (object_die, DW_AT_type, type_die);
6181 /* Given a tree pointer to a struct, class, union, or enum type node, return
6182 a pointer to the (string) tag name for the given type, or zero if the type
6183 was declared without a tag. */
6188 register char *name = 0;
6190 if (TYPE_NAME (type) != 0)
6192 register tree t = 0;
6194 /* Find the IDENTIFIER_NODE for the type name. */
6195 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6196 t = TYPE_NAME (type);
6198 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
6199 a TYPE_DECL node, regardless of whether or not a `typedef' was
6201 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6202 && ! DECL_IGNORED_P (TYPE_NAME (type)))
6203 t = DECL_NAME (TYPE_NAME (type));
6205 /* Now get the name as a string, or invent one. */
6207 name = IDENTIFIER_POINTER (t);
6209 return (name == 0 || *name == '\0') ? 0 : name;
6212 /* Return the type associated with a data member, make a special check
6213 for bit field types. */
6215 member_declared_type (member)
6216 register tree member;
6218 return (DECL_BIT_FIELD_TYPE (member))
6219 ? DECL_BIT_FIELD_TYPE (member)
6220 : TREE_TYPE (member);
6223 /* Get the decl's label, as described by its RTL. This may be different
6224 from the DECL_NAME name used in the source file. */
6226 decl_start_label (decl)
6231 x = DECL_RTL (decl);
6232 if (GET_CODE (x) != MEM)
6237 if (GET_CODE (x) != SYMBOL_REF)
6241 fnname = XSTR (x, 0);
6245 /******************************* DIE Generation *************************/
6247 /* These routines generate the internnal representation of the DIE's for
6248 the compilation unit. Debugging information is collected by walking
6249 the declaration trees passed in from dwarf2out_decl(). */
6252 gen_array_type_die (type, context_die)
6254 register dw_die_ref context_die;
6256 register dw_die_ref scope_die = scope_die_for (type, context_die);
6257 register dw_die_ref array_die;
6258 register tree element_type;
6260 /* ??? The SGI dwarf reader fails for array of array of enum types unless
6261 the inner array type comes before the outer array type. Thus we must
6262 call gen_type_die before we call new_die. See below also. */
6263 #ifdef MIPS_DEBUGGING_INFO
6264 gen_type_die (TREE_TYPE (type), context_die);
6267 array_die = new_die (DW_TAG_array_type, scope_die);
6270 /* We default the array ordering. SDB will probably do
6271 the right things even if DW_AT_ordering is not present. It's not even
6272 an issue until we start to get into multidimensional arrays anyway. If
6273 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6274 then we'll have to put the DW_AT_ordering attribute back in. (But if
6275 and when we find out that we need to put these in, we will only do so
6276 for multidimensional arrays. */
6277 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
6280 #ifdef MIPS_DEBUGGING_INFO
6281 /* The SGI compilers handle arrays of unknown bound by setting
6282 AT_declaration and not emitting any subrange DIEs. */
6283 if (! TYPE_DOMAIN (type))
6284 add_AT_unsigned (array_die, DW_AT_declaration, 1);
6287 add_subscript_info (array_die, type);
6289 equate_type_number_to_die (type, array_die);
6291 /* Add representation of the type of the elements of this array type. */
6292 element_type = TREE_TYPE (type);
6293 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6294 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6295 We work around this by disabling this feature. See also
6296 add_subscript_info. */
6297 #ifndef MIPS_DEBUGGING_INFO
6298 while (TREE_CODE (element_type) == ARRAY_TYPE)
6300 element_type = TREE_TYPE (element_type);
6302 gen_type_die (element_type, context_die);
6305 add_type_attribute (array_die, element_type, 0, 0, context_die);
6309 gen_set_type_die (type, context_die)
6311 register dw_die_ref context_die;
6313 register dw_die_ref type_die = new_die
6314 (DW_TAG_set_type, scope_die_for (type, context_die));
6315 equate_type_number_to_die (type, type_die);
6316 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
6320 gen_entry_point_die (decl, context_die)
6322 register dw_die_ref context_die;
6324 register tree origin = decl_ultimate_origin (decl);
6325 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
6328 add_abstract_origin_attribute (decl_die, origin);
6332 add_name_and_src_coords_attributes (decl_die, decl);
6333 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
6336 if (DECL_ABSTRACT (decl))
6338 equate_decl_number_to_die (decl, decl_die);
6342 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
6346 /* Remember a type in the pending_types_list. */
6352 if (pending_types == pending_types_allocated)
6354 pending_types_allocated += PENDING_TYPES_INCREMENT;
6356 = (tree *) xrealloc (pending_types_list,
6357 sizeof (tree) * pending_types_allocated);
6359 pending_types_list[pending_types++] = type;
6362 /* Output any pending types (from the pending_types list) which we can output
6363 now (taking into account the scope that we are working on now).
6365 For each type output, remove the given type from the pending_types_list
6366 *before* we try to output it. */
6369 output_pending_types_for_scope (context_die)
6370 register dw_die_ref context_die;
6374 while (pending_types)
6377 type = pending_types_list[pending_types];
6378 gen_type_die (type, context_die);
6379 assert (TREE_ASM_WRITTEN (type));
6383 /* Generate a DIE to represent an inlined instance of an enumeration type. */
6385 gen_inlined_enumeration_type_die (type, context_die)
6387 register dw_die_ref context_die;
6389 register dw_die_ref type_die;
6390 type_die = new_die (DW_TAG_enumeration_type,
6391 scope_die_for (type, context_die));
6392 assert (TREE_ASM_WRITTEN (type));
6393 add_abstract_origin_attribute (type_die, type);
6396 /* Generate a DIE to represent an inlined instance of a structure type. */
6398 gen_inlined_structure_type_die (type, context_die)
6400 register dw_die_ref context_die;
6402 register dw_die_ref type_die;
6403 type_die = new_die (DW_TAG_structure_type,
6404 scope_die_for (type, context_die));
6405 assert (TREE_ASM_WRITTEN (type));
6406 add_abstract_origin_attribute (type_die, type);
6409 /* Generate a DIE to represent an inlined instance of a union type. */
6411 gen_inlined_union_type_die (type, context_die)
6413 register dw_die_ref context_die;
6415 register dw_die_ref type_die;
6416 type_die = new_die (DW_TAG_union_type,
6417 scope_die_for (type, context_die));
6418 assert (TREE_ASM_WRITTEN (type));
6419 add_abstract_origin_attribute (type_die, type);
6422 /* Generate a DIE to represent an enumeration type. Note that these DIEs
6423 include all of the information about the enumeration values also. Each
6424 enumerated type name/value is listed as a child of the enumerated type
6427 gen_enumeration_type_die (type, context_die)
6429 register dw_die_ref context_die;
6431 register dw_die_ref type_die = lookup_type_die (type);
6433 if (type_die == NULL)
6435 type_die = new_die (DW_TAG_enumeration_type,
6436 scope_die_for (type, context_die));
6437 equate_type_number_to_die (type, type_die);
6438 add_name_attribute (type_die, type_tag (type));
6440 else if (! TYPE_SIZE (type))
6443 remove_AT (type_die, DW_AT_declaration);
6445 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
6446 given enum type is incomplete, do not generate the DW_AT_byte_size
6447 attribute or the DW_AT_element_list attribute. */
6448 if (TYPE_SIZE (type))
6451 TREE_ASM_WRITTEN (type) = 1;
6452 add_byte_size_attribute (type_die, type);
6453 if (type_tag (type))
6454 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
6455 for (link = TYPE_FIELDS (type);
6456 link != NULL; link = TREE_CHAIN (link))
6458 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
6459 add_name_attribute (enum_die,
6460 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
6461 add_AT_unsigned (enum_die, DW_AT_const_value,
6462 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
6466 add_AT_flag (type_die, DW_AT_declaration, 1);
6470 /* Generate a DIE to represent either a real live formal parameter decl or to
6471 represent just the type of some formal parameter position in some function
6473 Note that this routine is a bit unusual because its argument may be a
6474 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
6475 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
6476 node. If it's the former then this function is being called to output a
6477 DIE to represent a formal parameter object (or some inlining thereof). If
6478 it's the latter, then this function is only being called to output a
6479 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
6480 argument type of some subprogram type. */
6482 gen_formal_parameter_die (node, context_die)
6484 register dw_die_ref context_die;
6486 register dw_die_ref parm_die = new_die (DW_TAG_formal_parameter,
6488 register tree origin;
6489 switch (TREE_CODE_CLASS (TREE_CODE (node)))
6491 /* We were called with some kind of a ..._DECL node. */
6493 origin = decl_ultimate_origin (node);
6495 add_abstract_origin_attribute (parm_die, origin);
6498 add_name_and_src_coords_attributes (parm_die, node);
6499 add_type_attribute (parm_die, TREE_TYPE (node),
6500 TREE_READONLY (node),
6501 TREE_THIS_VOLATILE (node),
6503 if (DECL_ARTIFICIAL (node))
6504 add_AT_flag (parm_die, DW_AT_artificial, 1);
6506 if (DECL_ABSTRACT (node))
6507 equate_decl_number_to_die (node, parm_die);
6509 add_location_or_const_value_attribute (parm_die, node);
6512 /* We were called with some kind of a ..._TYPE node. */
6514 add_type_attribute (parm_die, node, 0, 0, context_die);
6517 /* Should never happen. */
6524 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
6525 at the end of an (ANSI prototyped) formal parameters list. */
6527 gen_unspecified_parameters_die (decl_or_type, context_die)
6528 register tree decl_or_type;
6529 register dw_die_ref context_die;
6531 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
6535 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
6536 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
6537 parameters as specified in some function type specification (except for
6538 those which appear as part of a function *definition*).
6539 Note that we must be careful here to output all of the parameter DIEs before*
6540 we output any DIEs needed to represent the types of the formal parameters.
6541 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
6542 non-parameter DIE it sees ends the formal parameter list. */
6544 gen_formal_types_die (function_or_method_type, context_die)
6545 register tree function_or_method_type;
6546 register dw_die_ref context_die;
6549 register tree formal_type = NULL;
6550 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
6553 /* In the case where we are generating a formal types list for a C++
6554 non-static member function type, skip over the first thing on the
6555 TYPE_ARG_TYPES list because it only represents the type of the hidden
6556 `this pointer'. The debugger should be able to figure out (without
6557 being explicitly told) that this non-static member function type takes a
6558 `this pointer' and should be able to figure what the type of that hidden
6559 parameter is from the DW_AT_member attribute of the parent
6560 DW_TAG_subroutine_type DIE. */
6561 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
6562 first_parm_type = TREE_CHAIN (first_parm_type);
6565 /* Make our first pass over the list of formal parameter types and output a
6566 DW_TAG_formal_parameter DIE for each one. */
6567 for (link = first_parm_type; link; link = TREE_CHAIN (link))
6569 register dw_die_ref parm_die;
6571 formal_type = TREE_VALUE (link);
6572 if (formal_type == void_type_node)
6575 /* Output a (nameless) DIE to represent the formal parameter itself. */
6576 parm_die = gen_formal_parameter_die (formal_type, context_die);
6577 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
6578 && link == first_parm_type)
6579 add_AT_flag (parm_die, DW_AT_artificial, 1);
6582 /* If this function type has an ellipsis, add a
6583 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
6584 if (formal_type != void_type_node)
6585 gen_unspecified_parameters_die (function_or_method_type, context_die);
6587 /* Make our second (and final) pass over the list of formal parameter types
6588 and output DIEs to represent those types (as necessary). */
6589 for (link = TYPE_ARG_TYPES (function_or_method_type);
6591 link = TREE_CHAIN (link))
6593 formal_type = TREE_VALUE (link);
6594 if (formal_type == void_type_node)
6597 gen_type_die (formal_type, context_die);
6601 /* Generate a DIE to represent a declared function (either file-scope or
6604 gen_subprogram_die (decl, context_die)
6606 register dw_die_ref context_die;
6608 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
6609 register tree origin = decl_ultimate_origin (decl);
6610 register dw_die_ref subr_die;
6611 register dw_loc_descr_ref fp_loc = NULL;
6612 register unsigned fp_reg;
6613 register tree fn_arg_types;
6614 register tree outer_scope;
6615 register dw_die_ref old_die = lookup_decl_die (decl);
6616 register int declaration = (current_function_decl != decl
6617 || context_die->die_tag == DW_TAG_structure_type
6618 || context_die->die_tag == DW_TAG_union_type);
6622 subr_die = new_die (DW_TAG_subprogram, context_die);
6623 add_abstract_origin_attribute (subr_die, origin);
6627 register unsigned file_index
6628 = lookup_filename (DECL_SOURCE_FILE (decl));
6630 assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
6632 /* If the definition comes from the same place as the declaration,
6633 maybe use the old DIE. We always want the DIE for this function
6634 that has the *_pc attributes to be under comp_unit_die so the
6635 debugger can find it. For inlines, that is the concrete instance,
6636 so we can use the old DIE here. For non-inline methods, we want a
6637 specification DIE at toplevel, so we need a new DIE. For local
6638 class methods, this does not apply. */
6639 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
6640 || context_die == NULL)
6641 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
6642 && (get_AT_unsigned (old_die, DW_AT_decl_line)
6643 == DECL_SOURCE_LINE (decl)))
6647 /* Clear out the declaration attribute and the parm types. */
6648 remove_AT (subr_die, DW_AT_declaration);
6649 remove_children (subr_die);
6653 subr_die = new_die (DW_TAG_subprogram, context_die);
6654 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
6655 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6656 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
6657 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6658 != DECL_SOURCE_LINE (decl))
6660 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6665 register dw_die_ref scope_die;
6667 if (DECL_CONTEXT (decl))
6668 scope_die = scope_die_for (decl, context_die);
6670 /* Don't put block extern declarations under comp_unit_die. */
6671 scope_die = context_die;
6673 subr_die = new_die (DW_TAG_subprogram, scope_die);
6675 if (TREE_PUBLIC (decl))
6676 add_AT_flag (subr_die, DW_AT_external, 1);
6677 add_name_and_src_coords_attributes (subr_die, decl);
6678 if (debug_info_level > DINFO_LEVEL_TERSE)
6680 register tree type = TREE_TYPE (decl);
6681 add_prototyped_attribute (subr_die, type);
6682 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
6684 add_pure_or_virtual_attribute (subr_die, decl);
6685 if (DECL_ARTIFICIAL (decl))
6686 add_AT_flag (subr_die, DW_AT_artificial, 1);
6687 if (TREE_PROTECTED (decl))
6688 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
6689 else if (TREE_PRIVATE (decl))
6690 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
6695 add_AT_flag (subr_die, DW_AT_declaration, 1);
6697 /* The first time we see a member function, it is in the context of
6698 the class to which it belongs. We make sure of this by emitting
6699 the class first. The next time is the definition, which is
6700 handled above. The two may come from the same source text. */
6701 if (decl_class_context (decl))
6702 equate_decl_number_to_die (decl, subr_die);
6704 else if (DECL_ABSTRACT (decl))
6706 if (DECL_DEFER_OUTPUT (decl))
6708 if (DECL_INLINE (decl))
6709 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
6711 add_AT_unsigned (subr_die, DW_AT_inline,
6712 DW_INL_declared_not_inlined);
6714 else if (DECL_INLINE (decl))
6715 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
6716 else if (declaration)
6717 /* block extern declaration in an inline function. */
6718 add_AT_flag (subr_die, DW_AT_declaration, 1);
6722 equate_decl_number_to_die (decl, subr_die);
6724 else if (!DECL_EXTERNAL (decl))
6727 equate_decl_number_to_die (decl, subr_die);
6728 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
6729 current_funcdef_number);
6730 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
6731 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
6732 current_funcdef_number);
6733 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
6735 add_pubname (decl, subr_die);
6736 add_arange (decl, subr_die);
6738 #ifdef MIPS_DEBUGGING_INFO
6739 /* Add a reference to the FDE for this routine. */
6740 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
6743 /* Define the "frame base" location for this routine. We use the
6744 frame pointer or stack pointer registers, since the RTL for local
6745 variables is relative to one of them. */
6746 fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6747 ? FRAME_POINTER_REGNUM
6748 : STACK_POINTER_REGNUM);
6749 assert (fp_reg >= 0 && fp_reg <= 31);
6750 fp_loc = new_loc_descr (DW_OP_reg0 + fp_reg);
6751 add_AT_loc (subr_die, DW_AT_frame_base, fp_loc);
6753 if (current_function_needs_context)
6754 add_AT_loc (subr_die, DW_AT_static_link,
6755 loc_descriptor (lookup_static_chain (decl)));
6758 /* Now output descriptions of the arguments for this function. This gets
6759 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
6760 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
6761 `...' at the end of the formal parameter list. In order to find out if
6762 there was a trailing ellipsis or not, we must instead look at the type
6763 associated with the FUNCTION_DECL. This will be a node of type
6764 FUNCTION_TYPE. If the chain of type nodes hanging off of this
6765 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
6766 an ellipsis at the end. */
6768 push_decl_scope (decl);
6769 /* In the case where we are describing a mere function declaration, all we
6770 need to do here (and all we *can* do here) is to describe the *types* of
6771 its formal parameters. */
6772 if (debug_info_level <= DINFO_LEVEL_TERSE)
6774 else if (declaration)
6775 gen_formal_types_die (TREE_TYPE (decl), subr_die);
6778 /* Generate DIEs to represent all known formal parameters */
6779 register tree arg_decls = DECL_ARGUMENTS (decl);
6782 /* When generating DIEs, generate the unspecified_parameters DIE
6783 instead if we come across the arg "__builtin_va_alist" */
6784 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
6786 if (TREE_CODE (parm) == PARM_DECL)
6788 if (DECL_NAME (parm) &&
6789 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
6790 "__builtin_va_alist"))
6792 gen_unspecified_parameters_die (parm, subr_die);
6796 gen_decl_die (parm, subr_die);
6801 /* Decide whether we need a unspecified_parameters DIE at the end.
6802 There are 2 more cases to do this for: 1) the ansi ... declaration -
6803 this is detectable when the end of the arg list is not a
6804 void_type_node 2) an unprototyped function declaration (not a
6805 definition). This just means that we have no info about the
6806 parameters at all. */
6807 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
6810 /* this is the prototyped case, check for ... */
6811 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
6813 gen_unspecified_parameters_die (decl, subr_die);
6818 /* this is unprotoyped, check for undefined (just declaration) */
6819 if (!DECL_INITIAL (decl))
6821 gen_unspecified_parameters_die (decl, subr_die);
6826 /* Output Dwarf info for all of the stuff within the body of the function
6827 (if it has one - it may be just a declaration). */
6828 outer_scope = DECL_INITIAL (decl);
6830 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
6831 node created to represent a function. This outermost BLOCK actually
6832 represents the outermost binding contour for the function, i.e. the
6833 contour in which the function's formal parameters and labels get
6834 declared. Curiously, it appears that the front end doesn't actually
6835 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
6836 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
6837 list for the function instead.) The BLOCK_VARS list for the
6838 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
6839 the function however, and we output DWARF info for those in
6840 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
6841 node representing the function's outermost pair of curly braces, and
6842 any blocks used for the base and member initializers of a C++
6843 constructor function. */
6844 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
6846 current_function_has_inlines = 0;
6847 decls_for_scope (outer_scope, subr_die, 0);
6848 #if 0 && defined (MIPS_DEBUGGING_INFO)
6849 if (current_function_has_inlines)
6851 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
6852 if (! comp_unit_has_inlines)
6854 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
6855 comp_unit_has_inlines = 1;
6863 /* Generate a DIE to represent a declared data object. */
6865 gen_variable_die (decl, context_die)
6867 register dw_die_ref context_die;
6869 register tree origin = decl_ultimate_origin (decl);
6870 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
6871 dw_die_ref old_die = lookup_decl_die (decl);
6873 = (DECL_EXTERNAL (decl)
6874 || current_function_decl != decl_function_context (decl)
6875 || context_die->die_tag == DW_TAG_structure_type
6876 || context_die->die_tag == DW_TAG_union_type);
6880 add_abstract_origin_attribute (var_die, origin);
6884 assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
6885 add_AT_die_ref (var_die, DW_AT_specification, old_die);
6886 if (DECL_NAME (decl))
6888 register unsigned file_index
6889 = lookup_filename (DECL_SOURCE_FILE (decl));
6890 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6891 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
6892 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6893 != DECL_SOURCE_LINE (decl))
6895 (var_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6900 add_name_and_src_coords_attributes (var_die, decl);
6901 add_type_attribute (var_die, TREE_TYPE (decl),
6902 TREE_READONLY (decl),
6903 TREE_THIS_VOLATILE (decl), context_die);
6904 if (TREE_PUBLIC (decl))
6905 add_AT_flag (var_die, DW_AT_external, 1);
6906 if (DECL_ARTIFICIAL (decl))
6907 add_AT_flag (var_die, DW_AT_artificial, 1);
6908 if (TREE_PROTECTED (decl))
6909 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
6910 else if (TREE_PRIVATE (decl))
6911 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
6915 add_AT_flag (var_die, DW_AT_declaration, 1);
6917 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
6918 equate_decl_number_to_die (decl, var_die);
6920 if (! declaration && ! DECL_ABSTRACT (decl))
6922 if (TREE_STATIC (decl))
6923 equate_decl_number_to_die (decl, var_die);
6924 add_location_or_const_value_attribute (var_die, decl);
6925 add_pubname (decl, var_die);
6929 /* Generate a DIE to represent a label identifier. */
6931 gen_label_die (decl, context_die)
6933 register dw_die_ref context_die;
6935 register tree origin = decl_ultimate_origin (decl);
6936 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
6938 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6939 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
6942 add_abstract_origin_attribute (lbl_die, origin);
6946 add_name_and_src_coords_attributes (lbl_die, decl);
6948 if (DECL_ABSTRACT (decl))
6950 equate_decl_number_to_die (decl, lbl_die);
6954 insn = DECL_RTL (decl);
6955 if (GET_CODE (insn) == CODE_LABEL)
6957 /* When optimization is enabled (via -O) some parts of the compiler
6958 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
6959 represent source-level labels which were explicitly declared by
6960 the user. This really shouldn't be happening though, so catch
6961 it if it ever does happen. */
6962 if (INSN_DELETED_P (insn))
6964 abort (); /* Should never happen. */
6966 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
6967 ASM_GENERATE_INTERNAL_LABEL (label, label2,
6968 (unsigned) INSN_UID (insn));
6969 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
6974 /* Generate a DIE for a lexical block. */
6976 gen_lexical_block_die (stmt, context_die, depth)
6978 register dw_die_ref context_die;
6981 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
6982 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6983 if (!BLOCK_ABSTRACT (stmt))
6985 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
6987 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
6988 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
6989 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
6991 push_decl_scope (stmt);
6992 decls_for_scope (stmt, stmt_die, depth);
6996 /* Generate a DIE for an inlined subprogram. */
6998 gen_inlined_subroutine_die (stmt, context_die, depth)
7000 register dw_die_ref context_die;
7003 if (!BLOCK_ABSTRACT (stmt))
7005 register dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine,
7007 register tree decl = block_ultimate_origin (stmt);
7008 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7009 add_abstract_origin_attribute (subr_die, decl);
7010 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7012 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
7013 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7014 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
7015 push_decl_scope (decl);
7016 decls_for_scope (stmt, subr_die, depth);
7018 current_function_has_inlines = 1;
7022 /* Generate a DIE for a field in a record, or structure. */
7024 gen_field_die (decl, context_die)
7026 register dw_die_ref context_die;
7028 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
7029 add_name_and_src_coords_attributes (decl_die, decl);
7030 add_type_attribute (decl_die, member_declared_type (decl),
7031 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
7033 /* If this is a bit field... */
7034 if (DECL_BIT_FIELD_TYPE (decl))
7036 add_byte_size_attribute (decl_die, decl);
7037 add_bit_size_attribute (decl_die, decl);
7038 add_bit_offset_attribute (decl_die, decl);
7040 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
7041 add_data_member_location_attribute (decl_die, decl);
7042 if (DECL_ARTIFICIAL (decl))
7043 add_AT_flag (decl_die, DW_AT_artificial, 1);
7044 if (TREE_PROTECTED (decl))
7045 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
7046 else if (TREE_PRIVATE (decl))
7047 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
7051 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7052 Use modified_type_die instead.
7053 We keep this code here just in case these types of DIEs may be needed to
7054 represent certain things in other languages (e.g. Pascal) someday. */
7056 gen_pointer_type_die (type, context_die)
7058 register dw_die_ref context_die;
7060 register dw_die_ref ptr_die = new_die
7061 (DW_TAG_pointer_type, scope_die_for (type, context_die));
7062 equate_type_number_to_die (type, ptr_die);
7063 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7064 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7067 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7068 Use modified_type_die instead.
7069 We keep this code here just in case these types of DIEs may be needed to
7070 represent certain things in other languages (e.g. Pascal) someday. */
7072 gen_reference_type_die (type, context_die)
7074 register dw_die_ref context_die;
7076 register dw_die_ref ref_die = new_die
7077 (DW_TAG_reference_type, scope_die_for (type, context_die));
7078 equate_type_number_to_die (type, ref_die);
7079 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
7080 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7084 /* Generate a DIE for a pointer to a member type. */
7086 gen_ptr_to_mbr_type_die (type, context_die)
7088 register dw_die_ref context_die;
7090 register dw_die_ref ptr_die = new_die
7091 (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
7092 equate_type_number_to_die (type, ptr_die);
7093 add_AT_die_ref (ptr_die, DW_AT_containing_type,
7094 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
7095 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7098 /* Generate the DIE for the compilation unit. */
7100 gen_compile_unit_die (main_input_filename)
7101 register char *main_input_filename;
7104 char *wd = getpwd ();
7106 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
7108 add_name_attribute (comp_unit_die, main_input_filename);
7112 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
7115 sprintf (producer, "%s %s", language_string, version_string);
7117 #ifdef MIPS_DEBUGGING_INFO
7118 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
7119 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
7120 not appear in the producer string, the debugger reaches the conclusion
7121 that the object file is stripped and has no debugging information.
7122 To get the MIPS/SGI debugger to believe that there is debugging
7123 information in the object file, we add a -g to the producer string. */
7124 if (debug_info_level > DINFO_LEVEL_TERSE)
7125 strcat (producer, " -g");
7128 add_AT_string (comp_unit_die, DW_AT_producer, producer);
7130 if (strcmp (language_string, "GNU C++") == 0)
7131 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
7132 else if (strcmp (language_string, "GNU Ada") == 0)
7133 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
7134 else if (strcmp (language_string, "GNU F77") == 0)
7135 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
7136 else if (flag_traditional)
7137 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
7139 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
7141 #if 0 /* unimplemented */
7142 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
7143 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
7147 /* Generate a DIE for a string type. */
7149 gen_string_type_die (type, context_die)
7151 register dw_die_ref context_die;
7153 register dw_die_ref type_die = new_die
7154 (DW_TAG_string_type, scope_die_for (type, context_die));
7155 equate_type_number_to_die (type, type_die);
7157 /* Fudge the string length attribute for now. */
7159 /* TODO: add string length info.
7160 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7161 bound_representation (upper_bound, 0, 'u'); */
7164 /* Generate the DIE for a base class. */
7166 gen_inheritance_die (binfo, context_die)
7167 register tree binfo;
7168 register dw_die_ref context_die;
7170 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
7171 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
7172 add_data_member_location_attribute (die, binfo);
7173 if (TREE_VIA_VIRTUAL (binfo))
7174 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7175 if (TREE_VIA_PUBLIC (binfo))
7176 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
7177 else if (TREE_VIA_PROTECTED (binfo))
7178 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
7181 /* Genearate a DIE for a class member. */
7183 gen_member_die (type, context_die)
7185 register dw_die_ref context_die;
7187 register tree member;
7188 /* If this is not an incomplete type, output descriptions of each of its
7189 members. Note that as we output the DIEs necessary to represent the
7190 members of this record or union type, we will also be trying to output
7191 DIEs to represent the *types* of those members. However the `type'
7192 function (above) will specifically avoid generating type DIEs for member
7193 types *within* the list of member DIEs for this (containing) type execpt
7194 for those types (of members) which are explicitly marked as also being
7195 members of this (containing) type themselves. The g++ front- end can
7196 force any given type to be treated as a member of some other
7197 (containing) type by setting the TYPE_CONTEXT of the given (member) type
7198 to point to the TREE node representing the appropriate (containing)
7201 /* First output info about the base classes. */
7202 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
7204 register tree bases = TYPE_BINFO_BASETYPES (type);
7205 register int n_bases = TREE_VEC_LENGTH (bases);
7208 for (i = 0; i < n_bases; i++)
7209 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
7212 /* Now output info about the data members and type members. */
7213 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
7214 gen_decl_die (member, context_die);
7216 /* Now output info about the function members (if any). */
7217 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
7218 gen_decl_die (member, context_die);
7221 /* Generate a DIE for a structure or union type. */
7223 gen_struct_or_union_type_die (type, context_die)
7225 register dw_die_ref context_die;
7227 register dw_die_ref type_die = lookup_type_die (type);
7228 register dw_die_ref scope_die = 0;
7229 register int nested = 0;
7231 if (type_die && ! TYPE_SIZE (type))
7234 if (TYPE_CONTEXT (type)
7235 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
7238 scope_die = scope_die_for (type, context_die);
7240 if (! type_die || (nested && scope_die == comp_unit_die))
7241 /* First occurrence of type or toplevel definition of nested class. */
7243 register dw_die_ref old_die = type_die;
7244 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
7245 ? DW_TAG_structure_type : DW_TAG_union_type,
7247 equate_type_number_to_die (type, type_die);
7248 add_name_attribute (type_die, type_tag (type));
7250 add_AT_die_ref (type_die, DW_AT_specification, old_die);
7253 remove_AT (type_die, DW_AT_declaration);
7255 /* If we're not in the right context to be defining this type, defer to
7256 avoid tricky recursion. */
7257 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
7259 add_AT_flag (type_die, DW_AT_declaration, 1);
7262 /* If this type has been completed, then give it a byte_size attribute and
7263 then give a list of members. */
7264 else if (TYPE_SIZE (type))
7266 /* Prevent infinite recursion in cases where the type of some member of
7267 this type is expressed in terms of this type itself. */
7268 TREE_ASM_WRITTEN (type) = 1;
7269 add_byte_size_attribute (type_die, type);
7270 if (type_tag (type))
7271 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7272 push_decl_scope (type);
7273 gen_member_die (type, type_die);
7275 /* GNU extension: Record what type our vtable lives in. */
7276 if (TYPE_VFIELD (type))
7278 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
7279 gen_type_die (vtype, context_die);
7280 add_AT_die_ref (type_die, DW_AT_containing_type,
7281 lookup_type_die (vtype));
7285 add_AT_flag (type_die, DW_AT_declaration, 1);
7288 /* Generate a DIE for a subroutine _type_. */
7290 gen_subroutine_type_die (type, context_die)
7292 register dw_die_ref context_die;
7294 register tree return_type = TREE_TYPE (type);
7295 register dw_die_ref subr_die = new_die
7296 (DW_TAG_subroutine_type, scope_die_for (type, context_die));
7297 equate_type_number_to_die (type, subr_die);
7298 add_prototyped_attribute (subr_die, type);
7299 add_type_attribute (subr_die, return_type, 0, 0, context_die);
7300 gen_formal_types_die (type, subr_die);
7303 /* Generate a DIE for a type definition */
7305 gen_typedef_die (decl, context_die)
7307 register dw_die_ref context_die;
7309 register dw_die_ref type_die;
7310 register tree origin;
7312 if (TREE_ASM_WRITTEN (decl))
7314 TREE_ASM_WRITTEN (decl) = 1;
7316 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
7317 origin = decl_ultimate_origin (decl);
7319 add_abstract_origin_attribute (type_die, origin);
7323 add_name_and_src_coords_attributes (type_die, decl);
7324 if (DECL_ORIGINAL_TYPE (decl))
7326 type = DECL_ORIGINAL_TYPE (decl);
7327 equate_type_number_to_die (TREE_TYPE (decl), type_die);
7330 type = TREE_TYPE (decl);
7331 add_type_attribute (type_die, type, TREE_READONLY (decl),
7332 TREE_THIS_VOLATILE (decl), context_die);
7334 if (DECL_ABSTRACT (decl))
7335 equate_decl_number_to_die (decl, type_die);
7338 /* Generate a type description DIE. */
7340 gen_type_die (type, context_die)
7342 register dw_die_ref context_die;
7344 if (type == 0 || type == error_mark_node)
7349 /* We are going to output a DIE to represent the unqualified version of of
7350 this type (i.e. without any const or volatile qualifiers) so get the
7351 main variant (i.e. the unqualified version) of this type now. */
7352 type = type_main_variant (type);
7354 if (TREE_ASM_WRITTEN (type))
7359 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7360 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7362 TREE_ASM_WRITTEN (type) = 1;
7363 gen_decl_die (TYPE_NAME (type), context_die);
7367 switch (TREE_CODE (type))
7373 case REFERENCE_TYPE:
7374 /* For these types, all that is required is that we output a DIE (or a
7375 set of DIEs) to represent the "basis" type. */
7376 gen_type_die (TREE_TYPE (type), context_die);
7380 /* This code is used for C++ pointer-to-data-member types. */
7381 /* Output a description of the relevant class type. */
7382 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
7383 /* Output a description of the type of the object pointed to. */
7384 gen_type_die (TREE_TYPE (type), context_die);
7385 /* Now output a DIE to represent this pointer-to-data-member type
7387 gen_ptr_to_mbr_type_die (type, context_die);
7391 gen_type_die (TYPE_DOMAIN (type), context_die);
7392 gen_set_type_die (type, context_die);
7396 gen_type_die (TREE_TYPE (type), context_die);
7397 abort (); /* No way to represent these in Dwarf yet! */
7401 /* Force out return type (in case it wasn't forced out already). */
7402 gen_type_die (TREE_TYPE (type), context_die);
7403 gen_subroutine_type_die (type, context_die);
7407 /* Force out return type (in case it wasn't forced out already). */
7408 gen_type_die (TREE_TYPE (type), context_die);
7409 gen_subroutine_type_die (type, context_die);
7413 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
7415 gen_type_die (TREE_TYPE (type), context_die);
7416 gen_string_type_die (type, context_die);
7420 gen_array_type_die (type, context_die);
7427 case QUAL_UNION_TYPE:
7428 /* If this is a nested type whose containing class hasn't been
7429 written out yet, writing it out will cover this one, too. */
7430 if (TYPE_CONTEXT (type)
7431 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
7432 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
7434 gen_type_die (TYPE_CONTEXT (type), context_die);
7436 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
7439 /* If that failed, attach ourselves to the stub. */
7440 push_decl_scope (TYPE_CONTEXT (type));
7441 context_die = lookup_type_die (TYPE_CONTEXT (type));
7444 if (TREE_CODE (type) == ENUMERAL_TYPE)
7445 gen_enumeration_type_die (type, context_die);
7447 gen_struct_or_union_type_die (type, context_die);
7449 if (TYPE_CONTEXT (type)
7450 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
7451 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
7454 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
7455 it up if it is ever completed. gen_*_type_die will set it for us
7456 when appropriate. */
7465 /* No DIEs needed for fundamental types. */
7469 /* No Dwarf representation currently defined. */
7476 TREE_ASM_WRITTEN (type) = 1;
7479 /* Generate a DIE for a tagged type instantiation. */
7481 gen_tagged_type_instantiation_die (type, context_die)
7483 register dw_die_ref context_die;
7485 if (type == 0 || type == error_mark_node)
7490 /* We are going to output a DIE to represent the unqualified version of of
7491 this type (i.e. without any const or volatile qualifiers) so make sure
7492 that we have the main variant (i.e. the unqualified version) of this
7494 assert (type == type_main_variant (type));
7495 assert (TREE_ASM_WRITTEN (type));
7497 switch (TREE_CODE (type))
7503 gen_inlined_enumeration_type_die (type, context_die);
7507 gen_inlined_structure_type_die (type, context_die);
7511 case QUAL_UNION_TYPE:
7512 gen_inlined_union_type_die (type, context_die);
7516 abort (); /* Should never happen. */
7520 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
7521 things which are local to the given block. */
7523 gen_block_die (stmt, context_die, depth)
7525 register dw_die_ref context_die;
7528 register int must_output_die = 0;
7529 register tree origin;
7531 register enum tree_code origin_code;
7533 /* Ignore blocks never really used to make RTL. */
7535 if (!stmt || !TREE_USED (stmt))
7540 /* Determine the "ultimate origin" of this block. This block may be an
7541 inlined instance of an inlined instance of inline function, so we have
7542 to trace all of the way back through the origin chain to find out what
7543 sort of node actually served as the original seed for the creation of
7544 the current block. */
7545 origin = block_ultimate_origin (stmt);
7546 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
7548 /* Determine if we need to output any Dwarf DIEs at all to represent this
7550 if (origin_code == FUNCTION_DECL)
7552 /* The outer scopes for inlinings *must* always be represented. We
7553 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
7554 must_output_die = 1;
7558 /* In the case where the current block represents an inlining of the
7559 "body block" of an inline function, we must *NOT* output any DIE for
7560 this block because we have already output a DIE to represent the
7561 whole inlined function scope and the "body block" of any function
7562 doesn't really represent a different scope according to ANSI C
7563 rules. So we check here to make sure that this block does not
7564 represent a "body block inlining" before trying to set the
7565 `must_output_die' flag. */
7566 if (! is_body_block (origin ? origin : stmt))
7568 /* Determine if this block directly contains any "significant"
7569 local declarations which we will need to output DIEs for. */
7570 if (debug_info_level > DINFO_LEVEL_TERSE)
7572 /* We are not in terse mode so *any* local declaration counts
7573 as being a "significant" one. */
7574 must_output_die = (BLOCK_VARS (stmt) != NULL);
7578 /* We are in terse mode, so only local (nested) function
7579 definitions count as "significant" local declarations. */
7580 for (decl = BLOCK_VARS (stmt);
7581 decl != NULL; decl = TREE_CHAIN (decl))
7583 if (TREE_CODE (decl) == FUNCTION_DECL
7584 && DECL_INITIAL (decl))
7586 must_output_die = 1;
7594 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
7595 DIE for any block which contains no significant local declarations at
7596 all. Rather, in such cases we just call `decls_for_scope' so that any
7597 needed Dwarf info for any sub-blocks will get properly generated. Note
7598 that in terse mode, our definition of what constitutes a "significant"
7599 local declaration gets restricted to include only inlined function
7600 instances and local (nested) function definitions. */
7601 if (must_output_die)
7603 if (origin_code == FUNCTION_DECL)
7605 gen_inlined_subroutine_die (stmt, context_die, depth);
7609 gen_lexical_block_die (stmt, context_die, depth);
7613 decls_for_scope (stmt, context_die, depth);
7616 /* Generate all of the decls declared within a given scope and (recursively)
7617 all of it's sub-blocks. */
7619 decls_for_scope (stmt, context_die, depth)
7621 register dw_die_ref context_die;
7625 register tree subblocks;
7626 /* Ignore blocks never really used to make RTL. */
7627 if (!stmt || !TREE_USED (stmt))
7631 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
7633 next_block_number++;
7636 /* Output the DIEs to represent all of the data objects and typedefs
7637 declared directly within this block but not within any nested
7638 sub-blocks. Also, nested function and tag DIEs have been
7639 generated with a parent of NULL; fix that up now. */
7640 for (decl = BLOCK_VARS (stmt);
7641 decl != NULL; decl = TREE_CHAIN (decl))
7643 register dw_die_ref die;
7645 if (TREE_CODE (decl) == FUNCTION_DECL)
7646 die = lookup_decl_die (decl);
7647 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
7648 die = lookup_type_die (TREE_TYPE (decl));
7652 if (die && die->die_parent == NULL)
7654 add_child_die (context_die, die);
7658 gen_decl_die (decl, context_die);
7661 /* Output the DIEs to represent all sub-blocks (and the items declared
7662 therein) of this block. */
7663 for (subblocks = BLOCK_SUBBLOCKS (stmt);
7665 subblocks = BLOCK_CHAIN (subblocks))
7667 gen_block_die (subblocks, context_die, depth + 1);
7671 /* Is this a typedef we can avoid emitting? */
7673 is_redundant_typedef (decl)
7676 if (TYPE_DECL_IS_STUB (decl))
7678 if (DECL_ARTIFICIAL (decl)
7679 && DECL_CONTEXT (decl)
7680 && is_tagged_type (DECL_CONTEXT (decl))
7681 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
7682 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
7683 /* Also ignore the artificial member typedef for the class name. */
7688 /* Generate Dwarf debug information for a decl described by DECL. */
7690 gen_decl_die (decl, context_die)
7692 register dw_die_ref context_die;
7694 register tree origin;
7695 /* Make a note of the decl node we are going to be working on. We may need
7696 to give the user the source coordinates of where it appeared in case we
7697 notice (later on) that something about it looks screwy. */
7698 dwarf_last_decl = decl;
7700 if (TREE_CODE (decl) == ERROR_MARK)
7705 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
7706 ignore a function definition, since that would screw up our count of
7707 blocks, and that it turn will completely screw up the the labels we will
7708 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7709 subsequent blocks). */
7710 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
7715 switch (TREE_CODE (decl))
7718 /* The individual enumerators of an enum type get output when we output
7719 the Dwarf representation of the relevant enum type itself. */
7723 /* Don't output any DIEs to represent mere function declarations,
7724 unless they are class members or explicit block externs. */
7725 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
7726 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
7731 if (debug_info_level > DINFO_LEVEL_TERSE)
7733 /* Before we describe the FUNCTION_DECL itself, make sure that we
7734 have described its return type. */
7735 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
7737 /* And its containing type. */
7738 origin = decl_class_context (decl);
7740 gen_type_die (origin, context_die);
7742 /* And its virtual context. */
7743 if (DECL_VINDEX (decl))
7744 gen_type_die (DECL_CONTEXT (decl), context_die);
7747 /* Now output a DIE to represent the function itself. */
7748 gen_subprogram_die (decl, context_die);
7752 /* If we are in terse mode, don't generate any DIEs to represent any
7754 if (debug_info_level <= DINFO_LEVEL_TERSE)
7757 /* In the special case of a TYPE_DECL node representing the
7758 declaration of some type tag, if the given TYPE_DECL is marked as
7759 having been instantiated from some other (original) TYPE_DECL node
7760 (e.g. one which was generated within the original definition of an
7761 inline function) we have to generate a special (abbreviated)
7762 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
7764 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl))
7766 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
7770 if (is_redundant_typedef (decl))
7771 gen_type_die (TREE_TYPE (decl), context_die);
7774 /* Output a DIE to represent the typedef itself. */
7775 gen_typedef_die (decl, context_die);
7780 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7782 gen_label_die (decl, context_die);
7787 /* If we are in terse mode, don't generate any DIEs to represent any
7788 variable declarations or definitions. */
7789 if (debug_info_level <= DINFO_LEVEL_TERSE)
7794 /* Output any DIEs that are needed to specify the type of this data
7796 gen_type_die (TREE_TYPE (decl), context_die);
7798 /* And its containing type. */
7799 origin = decl_class_context (decl);
7801 gen_type_die (origin, context_die);
7803 /* Now output the DIE to represent the data object itself. This gets
7804 complicated because of the possibility that the VAR_DECL really
7805 represents an inlined instance of a formal parameter for an inline
7807 origin = decl_ultimate_origin (decl);
7808 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
7810 gen_formal_parameter_die (decl, context_die);
7814 gen_variable_die (decl, context_die);
7819 /* Ignore the nameless fields that are used to skip bits, but
7820 handle C++ anonymous unions. */
7821 if (DECL_NAME (decl) != 0 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
7823 gen_type_die (member_declared_type (decl), context_die);
7824 gen_field_die (decl, context_die);
7829 gen_type_die (TREE_TYPE (decl), context_die);
7830 gen_formal_parameter_die (decl, context_die);
7838 /***************** Debug Information Generation Hooks ***********************/
7840 dwarf2out_decl (decl)
7843 register dw_die_ref context_die = comp_unit_die;
7845 if (TREE_CODE (decl) == ERROR_MARK)
7850 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
7851 hope that the node in question doesn't represent a function definition.
7852 If it does, then totally ignoring it is bound to screw up our count of
7853 blocks, and that it turn will completely screw up the the labels we will
7854 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7855 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
7856 own sequence numbers with them!) */
7857 if (DECL_IGNORED_P (decl))
7859 if (TREE_CODE (decl) == FUNCTION_DECL
7860 && DECL_INITIAL (decl) != NULL)
7867 switch (TREE_CODE (decl))
7870 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
7871 builtin function. Explicit programmer-supplied declarations of
7872 these same functions should NOT be ignored however. */
7873 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
7878 /* What we would really like to do here is to filter out all mere
7879 file-scope declarations of file-scope functions which are never
7880 referenced later within this translation unit (and keep all of ones
7881 that *are* referenced later on) but we aren't clarvoiant, so we have
7882 no idea which functions will be referenced in the future (i.e. later
7883 on within the current translation unit). So here we just ignore all
7884 file-scope function declarations which are not also definitions. If
7885 and when the debugger needs to know something about these funcstion,
7886 it wil have to hunt around and find the DWARF information associated
7887 with the definition of the function. Note that we can't just check
7888 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
7889 definitions and which ones represent mere declarations. We have to
7890 check `DECL_INITIAL' instead. That's because the C front-end
7891 supports some weird semantics for "extern inline" function
7892 definitions. These can get inlined within the current translation
7893 unit (an thus, we need to generate DWARF info for their abstract
7894 instances so that the DWARF info for the concrete inlined instances
7895 can have something to refer to) but the compiler never generates any
7896 out-of-lines instances of such things (despite the fact that they
7897 *are* definitions). The important point is that the C front-end
7898 marks these "extern inline" functions as DECL_EXTERNAL, but we need
7899 to generate DWARF for them anyway. Note that the C++ front-end also
7900 plays some similar games for inline function definitions appearing
7901 within include files which also contain
7902 `#pragma interface' pragmas. */
7903 if (DECL_INITIAL (decl) == NULL_TREE)
7908 /* If we're a nested function, initially use a parent of NULL; if we're
7909 a plain function, this will be fixed up in decls_for_scope. If
7910 we're a method, it will be ignored, since we already have a DIE. */
7911 if (decl_function_context (decl))
7917 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
7918 declaration and if the declaration was never even referenced from
7919 within this entire compilation unit. We suppress these DIEs in
7920 order to save space in the .debug section (by eliminating entries
7921 which are probably useless). Note that we must not suppress
7922 block-local extern declarations (whether used or not) because that
7923 would screw-up the debugger's name lookup mechanism and cause it to
7924 miss things which really ought to be in scope at a given point. */
7925 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
7930 /* If we are in terse mode, don't generate any DIEs to represent any
7931 variable declarations or definitions. */
7932 if (debug_info_level <= DINFO_LEVEL_TERSE)
7939 /* Don't bother trying to generate any DIEs to represent any of the
7940 normal built-in types for the language we are compiling. */
7941 if (DECL_SOURCE_LINE (decl) == 0)
7943 /* OK, we need to generate one for `bool' so GDB knows what type
7944 comparisons have. */
7945 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
7946 == DW_LANG_C_plus_plus)
7947 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
7948 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
7952 /* If we are in terse mode, don't generate any DIEs for types. */
7953 if (debug_info_level <= DINFO_LEVEL_TERSE)
7956 /* If we're a function-scope tag, initially use a parent of NULL;
7957 this will be fixed up in decls_for_scope. */
7958 if (decl_function_context (decl))
7967 gen_decl_die (decl, context_die);
7968 output_pending_types_for_scope (comp_unit_die);
7970 if (TREE_CODE (decl) == FUNCTION_DECL
7971 && DECL_INITIAL (decl) != NULL)
7973 current_funcdef_number++;
7978 /* Output a marker (i.e. a label) for the beginning of the generated code for
7981 dwarf2out_begin_block (blocknum)
7982 register unsigned blocknum;
7984 function_section (current_function_decl);
7985 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
7988 /* Output a marker (i.e. a label) for the end of the generated code for a
7991 dwarf2out_end_block (blocknum)
7992 register unsigned blocknum;
7994 function_section (current_function_decl);
7995 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
7998 /* Output a marker (i.e. a label) at a point in the assembly code which
7999 corresponds to a given source level label. */
8001 dwarf2out_label (insn)
8004 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8005 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8007 function_section (current_function_decl);
8008 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
8009 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
8010 (unsigned) INSN_UID (insn));
8014 /* Output a marker (i.e. a label) for the beginning of a function, before
8017 dwarf2out_begin_prologue ()
8019 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8020 register dw_fde_ref fde;
8022 function_section (current_function_decl);
8023 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
8024 current_funcdef_number);
8025 ASM_OUTPUT_LABEL (asm_out_file, label);
8027 /* Expand the fde table if necessary. */
8028 if (fde_table_in_use == fde_table_allocated)
8030 fde_table_allocated += FDE_TABLE_INCREMENT;
8031 fde_table = (dw_fde_ref) xrealloc (fde_table,
8032 fde_table_allocated * sizeof (dw_fde_node));
8035 /* Record the FDE associated with this function. */
8036 current_funcdef_fde = fde_table_in_use;
8038 /* Add the new FDE at the end of the fde_table. */
8039 fde = &fde_table[fde_table_in_use++];
8040 fde->dw_fde_begin = xstrdup (label);
8041 fde->dw_fde_current_label = NULL;
8042 fde->dw_fde_end = NULL;
8043 fde->dw_fde_cfi = NULL;
8046 /* Output a marker (i.e. a label) for the point in the generated code where
8047 the real body of the function begins (after parameters have been moved to
8048 their home locations). */
8050 dwarf2out_begin_function ()
8052 #ifdef MIPS_DEBUGGING_INFO
8053 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8054 register long int offset;
8055 register dw_fde_ref fde;
8056 register dw_cfi_ref cfi;
8057 register int regno, fp_inc;
8059 function_section (current_function_decl);
8060 ASM_GENERATE_INTERNAL_LABEL (label, BODY_BEGIN_LABEL,
8061 current_funcdef_number);
8062 ASM_OUTPUT_LABEL (asm_out_file, label);
8064 /* Define the CFA as an offset from either the frame pointer
8065 or the stack pointer. */
8067 (label, gen_rtx (PLUS, VOIDmode,
8068 gen_rtx (REG, VOIDmode,
8069 (frame_pointer_needed ? FRAME_POINTER_REGNUM
8070 : STACK_POINTER_REGNUM)),
8071 GEN_INT (current_frame_info.total_size)));
8073 /* Record the locations of the return address and any callee-saved regs. */
8074 offset = current_frame_info.gp_save_offset / DWARF_CIE_DATA_ALIGNMENT;
8075 for (regno = GP_REG_LAST; regno >= GP_REG_FIRST; --regno)
8076 if (current_frame_info.mask & (1<<regno))
8078 assert (offset >= 0);
8081 dwarf2out_return_save (label, GEN_INT (offset));
8083 dwarf2out_reg_save (label, regno, GEN_INT (offset));
8084 offset -= UNITS_PER_WORD / DWARF_CIE_DATA_ALIGNMENT;
8087 fp_inc = (TARGET_FLOAT64 || TARGET_SINGLE_FLOAT) ? 1 : 2;
8088 offset = current_frame_info.fp_save_offset / DWARF_CIE_DATA_ALIGNMENT;
8089 for (regno = FP_REG_LAST - 1; regno >= FP_REG_FIRST; regno -= fp_inc)
8090 if (current_frame_info.fmask & (1 << (regno - FP_REG_FIRST)))
8092 assert (offset >= 0);
8093 dwarf2out_reg_save (label, regno, GEN_INT (offset));
8094 offset -= (fp_inc * UNITS_PER_FPREG) / DWARF_CIE_DATA_ALIGNMENT;
8099 /* Output a marker (i.e. a label) for the absolute end of the generated code
8100 for a function definition. This gets called *after* the epilogue code has
8103 dwarf2out_end_epilogue ()
8106 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8107 /* Output a label to mark the endpoint of the code generated for this
8109 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
8110 ASM_OUTPUT_LABEL (asm_out_file, label);
8111 fde = &fde_table[fde_table_in_use - 1];
8112 fde->dw_fde_end = xstrdup (label);
8115 /* Lookup a filename (in the list of filenames that we know about here in
8116 dwarf2out.c) and return its "index". The index of each (known) filename is
8117 just a unique number which is associated with only that one filename.
8118 We need such numbers for the sake of generating labels
8119 (in the .debug_sfnames section) and references to those
8120 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
8121 If the filename given as an argument is not found in our current list,
8122 add it to the list and assign it the next available unique index number.
8123 In order to speed up searches, we remember the index of the filename
8124 was looked up last. This handles the majority of all searches. */
8126 lookup_filename (file_name)
8129 static unsigned last_file_lookup_index = 0;
8131 register unsigned i;
8133 /* Check to see if the file name that was searched on the previous call
8134 matches this file name. If so, return the index. */
8135 if (last_file_lookup_index != 0)
8137 fn = file_table[last_file_lookup_index];
8138 if (strcmp (file_name, fn) == 0)
8140 return last_file_lookup_index;
8144 /* Didn't match the previous lookup, search the table */
8145 for (i = 1; i < file_table_in_use; ++i)
8148 if (strcmp (file_name, fn) == 0)
8150 last_file_lookup_index = i;
8155 /* Prepare to add a new table entry by making sure there is enough space in
8156 the table to do so. If not, expand the current table. */
8157 if (file_table_in_use == file_table_allocated)
8159 file_table_allocated += FILE_TABLE_INCREMENT;
8162 xrealloc (file_table, file_table_allocated * sizeof (char *));
8165 /* add the new entry to the end of the filename table. */
8166 file_table[file_table_in_use] = xstrdup (file_name);
8167 last_file_lookup_index = file_table_in_use++;
8168 return last_file_lookup_index;
8171 /* Output a label to mark the beginning of a source code line entry
8172 and record information relating to this source line, in
8173 'line_info_table' for later output of the .debug_line section. */
8175 dwarf2out_line (filename, line)
8176 register char *filename;
8177 register unsigned line;
8179 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8181 function_section (current_function_decl);
8183 if (DECL_SECTION_NAME (current_function_decl))
8185 register dw_separate_line_info_ref line_info;
8186 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
8187 separate_line_info_table_in_use);
8188 fputc ('\n', asm_out_file);
8190 /* expand the line info table if necessary */
8191 if (separate_line_info_table_in_use
8192 == separate_line_info_table_allocated)
8194 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8195 separate_line_info_table
8196 = (dw_separate_line_info_ref) xrealloc
8197 (separate_line_info_table,
8198 separate_line_info_table_allocated
8199 * sizeof (dw_separate_line_info_entry));
8201 /* add the new entry at the end of the line_info_table. */
8203 = &separate_line_info_table[separate_line_info_table_in_use++];
8204 line_info->dw_file_num = lookup_filename (filename);
8205 line_info->dw_line_num = line;
8206 line_info->function = current_funcdef_number;
8210 register dw_line_info_ref line_info;
8211 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
8212 line_info_table_in_use);
8213 fputc ('\n', asm_out_file);
8215 /* expand the line info table if necessary */
8216 if (line_info_table_in_use == line_info_table_allocated)
8218 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8220 = (dw_line_info_ref) xrealloc
8222 line_info_table_allocated * sizeof (dw_line_info_entry));
8224 /* add the new entry at the end of the line_info_table. */
8225 line_info = &line_info_table[line_info_table_in_use++];
8226 line_info->dw_file_num = lookup_filename (filename);
8227 line_info->dw_line_num = line;
8232 /* Record the beginning of a new source file, for later output
8233 of the .debug_macinfo section. At present, unimplemented. */
8235 dwarf2out_start_source_file (filename)
8236 register char *filename;
8240 /* Record the end of a source file, for later output
8241 of the .debug_macinfo section. At present, unimplemented. */
8243 dwarf2out_end_source_file ()
8247 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8248 the tail part of the directive line, i.e. the part which is past the
8249 initial whitespace, #, whitespace, directive-name, whitespace part. */
8251 dwarf2out_define (lineno, buffer)
8252 register unsigned lineno;
8253 register char *buffer;
8255 static int initialized = 0;
8258 dwarf2out_start_source_file (primary_filename);
8263 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8264 the tail part of the directive line, i.e. the part which is past the
8265 initial whitespace, #, whitespace, directive-name, whitespace part. */
8267 dwarf2out_undef (lineno, buffer)
8268 register unsigned lineno;
8269 register char *buffer;
8273 /* Set up for Dwarf output at the start of compilation. */
8275 dwarf2out_init (asm_out_file, main_input_filename)
8276 register FILE *asm_out_file;
8277 register char *main_input_filename;
8279 /* Remember the name of the primary input file. */
8280 primary_filename = main_input_filename;
8282 /* Allocate the initial hunk of the file_table. */
8283 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
8284 bzero (file_table, FILE_TABLE_INCREMENT * sizeof (char *));
8285 file_table_allocated = FILE_TABLE_INCREMENT;
8286 /* skip the first entry - file numbers begin at 1 */
8287 file_table_in_use = 1;
8289 /* Allocate the initial hunk of the decl_die_table. */
8291 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8292 bzero (decl_die_table, DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8293 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
8294 decl_die_table_in_use = 0;
8296 /* Allocate the initial hunk of the decl_scope_table. */
8298 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8299 bzero (decl_scope_table, DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8300 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
8301 decl_scope_depth = 0;
8303 /* Allocate the initial hunk of the abbrev_die_table. */
8305 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
8306 * sizeof (dw_die_ref));
8307 bzero (abbrev_die_table, ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8308 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
8309 /* zero-th entry is allocated, but unused */
8310 abbrev_die_table_in_use = 1;
8312 /* Allocate the initial hunk of the line_info_table. */
8314 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
8315 * sizeof (dw_line_info_entry));
8316 bzero (line_info_table, LINE_INFO_TABLE_INCREMENT
8317 * sizeof (dw_line_info_entry));
8318 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
8319 /* zero-th entry is allocated, but unused */
8320 line_info_table_in_use = 1;
8322 /* Allocate the initial hunk of the fde_table. */
8323 fde_table = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8324 bzero (fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8325 fde_table_allocated = FDE_TABLE_INCREMENT;
8326 fde_table_in_use = 0;
8328 /* Generate the initial DIE for the .debug section. Note that the (string)
8329 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8330 will (typically) be a relative pathname and that this pathname should be
8331 taken as being relative to the directory from which the compiler was
8332 invoked when the given (base) source file was compiled. */
8333 gen_compile_unit_die (main_input_filename);
8335 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
8337 /* Generate the CFA instructions common to all FDE's. Do it now for the
8338 sake of lookup_cfa. */
8339 #ifdef MIPS_DEBUGGING_INFO
8340 /* On entry, the Call Frame Address is in the stack pointer register. */
8341 dwarf2out_def_cfa (NULL, gen_rtx (REG, VOIDmode, STACK_POINTER_REGNUM));
8343 /* Set the RA on entry to be the contents of r31. */
8344 dwarf2out_return_save (NULL, gen_rtx (REG, VOIDmode, GP_REG_FIRST + 31));
8348 /* Output stuff that dwarf requires at the end of every file,
8349 and generate the DWARF-2 debugging info. */
8353 /* Traverse the DIE tree and add sibling attributes to those DIE's
8354 that have children. */
8355 add_sibling_attributes (comp_unit_die);
8357 /* Output a terminator label for the .text section. */
8358 fputc ('\n', asm_out_file);
8359 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8360 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
8363 /* Output a terminator label for the .data section. */
8364 fputc ('\n', asm_out_file);
8365 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8366 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
8368 /* Output a terminator label for the .bss section. */
8369 fputc ('\n', asm_out_file);
8370 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8371 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
8374 /* Output the source line correspondence table. */
8375 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8377 fputc ('\n', asm_out_file);
8378 ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
8379 output_line_info ();
8381 /* We can only use the low/high_pc attributes if all of the code
8383 if (separate_line_info_table_in_use == 0)
8385 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
8386 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
8388 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
8391 /* Output the abbreviation table. */
8392 fputc ('\n', asm_out_file);
8393 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
8394 build_abbrev_table (comp_unit_die);
8395 output_abbrev_section ();
8397 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8398 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8399 calc_die_sizes (comp_unit_die);
8401 /* calculate sizes/offsets for FDEs. */
8404 /* Output debugging information. */
8405 fputc ('\n', asm_out_file);
8406 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
8407 output_compilation_unit_header ();
8408 output_die (comp_unit_die);
8410 if (pubname_table_in_use)
8412 /* Output public names table. */
8413 fputc ('\n', asm_out_file);
8414 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
8418 if (fde_table_in_use)
8420 /* Output call frame information. */
8421 output_call_frame_info ();
8423 /* Output the address range information. */
8424 fputc ('\n', asm_out_file);
8425 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
8429 /* The only DIE we should have with a parent of NULL is comp_unit_die. */
8430 assert (limbo_die_count == 1);
8432 #endif /* DWARF2_DEBUGGING_INFO */