1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 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).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #ifdef DWARF2_DEBUGGING_INFO
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
39 /* #define NDEBUG 1 */
42 extern char *getpwd ();
44 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
45 regarding the GNU implementation of DWARF. */
47 /* NOTE: In the comments in this file, many references are made to
48 "Debugging Information Entries". This term is abbreviated as `DIE'
49 throughout the remainder of this file. */
51 #if defined(__GNUC__) && (NDEBUG == 1)
52 #define inline static inline
58 /* An internal representation of the DWARF output is built, and then
59 walked to generate the DWARF debugging info. The walk of the internal
60 representation is done after the entire program has been compiled.
61 The types below are used to describe the internal representation. */
63 /* Each DIE may have a series of attribute/value pairs. Values
64 can take on several forms. The forms that are used in this
65 impelementation are listed below. */
71 dw_val_class_unsigned_const
,
72 dw_val_class_long_long
,
78 dw_val_class_section_offset
,
83 /* Various DIE's use offsets relative to the beginning of the
84 .debug_info section to refer to each other. */
85 typedef long int dw_offset
;
87 /* Define typedefs here to avoid circular dependencies. */
88 typedef struct die_struct
*dw_die_ref
;
89 typedef struct dw_attr_struct
*dw_attr_ref
;
90 typedef struct dw_val_struct
*dw_val_ref
;
91 typedef struct dw_line_info_struct
*dw_line_info_ref
;
92 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
93 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
94 typedef struct dw_cfi_struct
*dw_cfi_ref
;
95 typedef struct dw_fde_struct
*dw_fde_ref
;
96 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
97 typedef struct pubname_struct
*pubname_ref
;
98 typedef dw_die_ref
*arange_ref
;
100 /* Describe a double word constant value. */
101 typedef struct dw_long_long_struct
108 /* Describe a floating point constant value. */
109 typedef struct dw_fp_struct
116 /* Each entry in the line_info_table maintains the file and
117 line nuber associated with the label generated for that
118 entry. The label gives the PC value associated with
119 the line number entry. */
120 typedef struct dw_line_info_struct
122 unsigned long dw_file_num
;
123 unsigned long dw_line_num
;
127 /* Line information for functions in separate sections; each one gets its
129 typedef struct dw_separate_line_info_struct
131 unsigned long dw_file_num
;
132 unsigned long dw_line_num
;
133 unsigned long function
;
135 dw_separate_line_info_entry
;
137 /* The dw_val_node describes an attibute's value, as it is
138 represnted internally. */
139 typedef struct dw_val_struct
141 dw_val_class val_class
;
145 dw_loc_descr_ref val_loc
;
147 long unsigned val_unsigned
;
148 dw_long_long_const val_long_long
;
149 dw_float_const val_float
;
150 dw_die_ref val_die_ref
;
151 unsigned val_fde_index
;
155 unsigned char val_flag
;
161 /* Locations in memory are described using a sequence of stack machine
163 typedef struct dw_loc_descr_struct
165 dw_loc_descr_ref dw_loc_next
;
166 enum dwarf_location_atom dw_loc_opc
;
167 dw_val_node dw_loc_oprnd1
;
168 dw_val_node dw_loc_oprnd2
;
172 /* Each DIE attribute has a field specifying the attribute kind,
173 a link to the next attribute in the chain, and an attribute value.
174 Attributes are typically linked below the DIE they modify. */
175 typedef struct dw_attr_struct
177 enum dwarf_attribute dw_attr
;
178 dw_attr_ref dw_attr_next
;
179 dw_val_node dw_attr_val
;
183 /* Call frames are described using a sequence of Call Frame
184 Information instructions. The register number, offset
185 and address fields are provided as possible operands;
186 their use is selected by the opcode field. */
187 typedef union dw_cfi_oprnd_struct
189 unsigned long dw_cfi_reg_num
;
190 long int dw_cfi_offset
;
195 typedef struct dw_cfi_struct
197 dw_cfi_ref dw_cfi_next
;
198 enum dwarf_call_frame_info dw_cfi_opc
;
199 dw_cfi_oprnd dw_cfi_oprnd1
;
200 dw_cfi_oprnd dw_cfi_oprnd2
;
204 /* All call frame descriptions (FDE's) in the GCC generated DWARF
205 refer to a single Common Information Entry (CIE), defined at
206 the beginning of the .debug_frame section. This used of a single
207 CIE obviates the need to keep track of multiple CIE's
208 in the DWARF generation routines below. */
209 typedef struct dw_fde_struct
211 unsigned long dw_fde_offset
;
213 char *dw_fde_current_label
;
215 dw_cfi_ref dw_fde_cfi
;
219 /* The Debugging Information Entry (DIE) structure */
220 typedef struct die_struct
222 enum dwarf_tag die_tag
;
223 dw_attr_ref die_attr
;
224 dw_attr_ref die_attr_last
;
225 dw_die_ref die_parent
;
226 dw_die_ref die_child
;
227 dw_die_ref die_child_last
;
229 dw_offset die_offset
;
230 unsigned long die_abbrev
;
234 /* The pubname structure */
235 typedef struct pubname_struct
242 /* How to start an assembler comment. */
243 #ifndef ASM_COMMENT_START
244 #define ASM_COMMENT_START ";#"
247 /* Define a macro which returns non-zero for a TYPE_DECL which was
248 implicitly generated for a tagged type.
250 Note that unlike the gcc front end (which generates a NULL named
251 TYPE_DECL node for each complete tagged type, each array type, and
252 each function type node created) the g++ front end generates a
253 _named_ TYPE_DECL node for each tagged type node created.
254 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
255 generate a DW_TAG_typedef DIE for them. */
256 #define TYPE_DECL_IS_STUB(decl) \
257 (DECL_NAME (decl) == NULL \
258 || (DECL_ARTIFICIAL (decl) \
259 && is_tagged_type (TREE_TYPE (decl)) \
260 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
262 /* Information concerning the compilation unit's programming
263 language, and compiler version. */
264 extern int flag_traditional
;
265 extern char *version_string
;
266 extern char *language_string
;
268 /* Maximum size (in bytes) of an artificially generated label. */
269 #define MAX_ARTIFICIAL_LABEL_BYTES 30
271 /* Make sure we know the sizes of the various types dwarf can describe. These
272 are only defaults. If the sizes are different for your target, you should
273 override these values by defining the appropriate symbols in your tm.h
275 #ifndef CHAR_TYPE_SIZE
276 #define CHAR_TYPE_SIZE BITS_PER_UNIT
279 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
282 /* The size in bytes of a DWARF field indicating an offset or length
283 relative to a debug info section, specified to be 4 bytes in the DWARF-2
284 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
285 #ifndef DWARF_OFFSET_SIZE
286 #define DWARF_OFFSET_SIZE 4
289 #define DWARF_VERSION 2
291 /* Fixed size portion of the DWARF compilation unit header. */
292 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
294 /* Fixed size portion of debugging line information prolog. */
295 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
297 /* Fixed size portion of public names info. */
298 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
300 /* Round SIZE up to the nearest BOUNDARY. */
301 #define DWARF_ROUND(SIZE,BOUNDARY) \
302 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
304 /* Fixed size portion of the address range info. */
305 #define DWARF_ARANGES_HEADER_SIZE \
306 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
308 /* Fixed size portion of the CIE (including the length field). */
309 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5)
311 /* The un-padded size of the CIE. Initialized in calc_fde_sizes, used
312 in output_call_frame_info. */
313 static unsigned cie_size
;
315 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
316 #ifdef STACK_GROWS_DOWNWARD
317 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
319 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
322 /* Fixed size portion of the FDE. */
323 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
325 /* Define the architecture-dependent minimum instruction length (in bytes).
326 In this implementation of DWARF, this field is used for information
327 purposes only. Since GCC generates assembly language, we have
328 no a priori knowledge of how many instruction bytes are generated
329 for each source line, and therefore can use only the DW_LNE_set_address
330 and DW_LNS_fixed_advance_pc line information commands. */
331 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
332 #define DWARF_LINE_MIN_INSTR_LENGTH 4
335 /* Minimum line offset in a special line info. opcode.
336 This value was chosen to give a reasonable range of values. */
337 #define DWARF_LINE_BASE -10
339 /* First special line opcde - leave room for the standard opcodes. */
340 #define DWARF_LINE_OPCODE_BASE 10
342 /* Range of line offsets in a special line info. opcode. */
343 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
345 /* Flag that indicates the initial value of the is_stmt_start flag.
346 In the present implementation, we do not mark any lines as
347 the beginning of a source statement, because that information
348 is not made available by the GCC front-end. */
349 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
351 /* This location is used by calc_die_sizes() to keep track
352 the offset of each DIE within the .debug_info section. */
353 static unsigned long next_die_offset
;
355 /* This location is used by calc_fde_sizes() to keep track
356 the offset of each FDE within the .debug_frame section. */
357 static unsigned long next_fde_offset
;
359 /* Record the root of the DIE's built for the current compilation unit. */
360 dw_die_ref comp_unit_die
;
362 /* The number of DIEs with a NULL parent waiting to be relocated. */
363 static int limbo_die_count
;
365 /* Pointer to an array of filenames referenced by this compilation unit. */
366 static char **file_table
;
368 /* Total number of entries in the table (i.e. array) pointed to by
369 `file_table'. This is the *total* and includes both used and unused
371 static unsigned file_table_allocated
;
373 /* Number of entries in the file_table which are actually in use. */
374 static unsigned file_table_in_use
;
376 /* Size (in elements) of increments by which we may expand the filename
378 #define FILE_TABLE_INCREMENT 64
380 /* Local pointer to the name of the main input file. Initialized in
382 static char *primary_filename
;
384 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
385 which their beginnings are encountered. We output Dwarf debugging info
386 that refers to the beginnings and ends of the ranges of code for each
387 lexical block. The labels themselves are generated in final.c, which
388 assigns numbers to the blocks in the same way. */
389 static unsigned next_block_number
= 2;
391 /* A pointer to the base of a table of references to DIE's that describe
392 declarations. The table is indexed by DECL_UID() which is a unique
393 number, indentifying each decl. */
394 static dw_die_ref
*decl_die_table
;
396 /* Number of elements currently allocated for the decl_die_table. */
397 static unsigned decl_die_table_allocated
;
399 /* Number of elements in decl_die_table currently in use. */
400 static unsigned decl_die_table_in_use
;
402 /* Size (in elements) of increments by which we may expand the
404 #define DECL_DIE_TABLE_INCREMENT 256
406 /* A pointer to the base of a table of references to declaration
407 scopes. This table is a display which tracks the nesting
408 of declaration scopes at the current scope and containing
409 scopes. This table is used to find the proper place to
410 define type declaration DIE's. */
411 static tree
*decl_scope_table
;
413 /* Number of elements currently allocated for the decl_scope_table. */
414 static unsigned decl_scope_table_allocated
;
416 /* Current level of nesting of declataion scopes. */
417 static unsigned decl_scope_depth
;
419 /* Size (in elements) of increments by which we may expand the
421 #define DECL_SCOPE_TABLE_INCREMENT 64
423 /* A pointer to the base of a list of references to DIE's that
424 are uniquely identified by their tag, presence/absence of
425 children DIE's, and list of attribute/value pairs. */
426 static dw_die_ref
*abbrev_die_table
;
428 /* Number of elements currently allocated for abbrev_die_table. */
429 static unsigned abbrev_die_table_allocated
;
431 /* Number of elements in type_die_table currently in use. */
432 static unsigned abbrev_die_table_in_use
;
434 /* Size (in elements) of increments by which we may expand the
436 #define ABBREV_DIE_TABLE_INCREMENT 256
438 /* A pointer to the base of a table that contains line information
439 for each source code line in .text in the compilation unit. */
440 static dw_line_info_ref line_info_table
;
442 /* Number of elements currently allocated for line_info_table. */
443 static unsigned line_info_table_allocated
;
445 /* Number of elements in separate_line_info_table currently in use. */
446 static unsigned separate_line_info_table_in_use
;
448 /* A pointer to the base of a table that contains line information
449 for each source code line outside of .text in the compilation unit. */
450 static dw_separate_line_info_ref separate_line_info_table
;
452 /* Number of elements currently allocated for separate_line_info_table. */
453 static unsigned separate_line_info_table_allocated
;
455 /* Number of elements in line_info_table currently in use. */
456 static unsigned line_info_table_in_use
;
458 /* Size (in elements) of increments by which we may expand the
460 #define LINE_INFO_TABLE_INCREMENT 1024
462 /* A pointer to the base of a table that contains frame description
463 information for each routine. */
464 static dw_fde_ref fde_table
;
466 /* Number of elements currently allocated for fde_table. */
467 static unsigned fde_table_allocated
;
469 /* Number of elements in fde_table currently in use. */
470 static unsigned fde_table_in_use
;
472 /* Size (in elements) of increments by which we may expand the
474 #define FDE_TABLE_INCREMENT 256
476 /* A list of call frame insns for the CIE. */
477 static dw_cfi_ref cie_cfi_head
;
479 /* A pointer to the base of a table that contains a list of publicly
481 static pubname_ref pubname_table
;
483 /* Number of elements currently allocated for pubname_table. */
484 static unsigned pubname_table_allocated
;
486 /* Number of elements in pubname_table currently in use. */
487 static unsigned pubname_table_in_use
;
489 /* Size (in elements) of increments by which we may expand the
491 #define PUBNAME_TABLE_INCREMENT 64
493 /* A pointer to the base of a table that contains a list of publicly
495 static arange_ref arange_table
;
497 /* Number of elements currently allocated for arange_table. */
498 static unsigned arange_table_allocated
;
500 /* Number of elements in arange_table currently in use. */
501 static unsigned arange_table_in_use
;
503 /* Size (in elements) of increments by which we may expand the
505 #define ARANGE_TABLE_INCREMENT 64
507 /* A pointer to the base of a list of pending types which we haven't
508 generated DIEs for yet, but which we will have to come back to
511 static tree
*pending_types_list
;
513 /* Number of elements currently allocated for the pending_types_list. */
515 static unsigned pending_types_allocated
;
517 /* Number of elements of pending_types_list currently in use. */
519 static unsigned pending_types
;
521 /* Size (in elements) of increments by which we may expand the pending
522 types list. Actually, a single hunk of space of this size should
523 be enough for most typical programs. */
525 #define PENDING_TYPES_INCREMENT 64
527 /* The number of the current function definition for which debugging
528 information is being generated. These numbers range from 1 up to the
529 maximum number of function definitions contained within the current
530 compilation unit. These numbers are used to create unique label id's
531 unique to each function definition. */
532 static unsigned current_funcdef_number
= 1;
534 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
535 attribute that accelerates the lookup of the FDE associated
536 with the subprogram. This variable holds the table index of the FDE
537 associated with the current function (body) definition. */
538 static unsigned current_funcdef_fde
;
540 /* Record whether the function being analyzed contains inlined functions. */
541 static int current_function_has_inlines
;
542 static int comp_unit_has_inlines
;
544 /* A pointer to the ..._DECL node which we have most recently been working
545 on. We keep this around just in case something about it looks screwy and
546 we want to tell the user what the source coordinates for the actual
548 static tree dwarf_last_decl
;
550 /* Forward declarations for functions defined in this file. */
551 static void gen_type_die ();
552 static void add_type_attribute ();
553 static void decls_for_scope ();
554 static void gen_decl_die ();
555 static unsigned lookup_filename ();
556 static int constant_size
PROTO((long unsigned));
557 static enum dwarf_form value_format
PROTO((dw_val_ref
));
558 static unsigned reg_number ();
560 /* Definitions of defaults for assembler-dependent names of various
561 pseudo-ops and section names.
562 Theses may be overridden in the tm.h file (if necessary) for a particular
564 #ifndef UNALIGNED_SHORT_ASM_OP
565 #define UNALIGNED_SHORT_ASM_OP ".2byte"
567 #ifndef UNALIGNED_INT_ASM_OP
568 #define UNALIGNED_INT_ASM_OP ".4byte"
570 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
571 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
574 #define ASM_BYTE_OP ".byte"
577 #ifndef UNALIGNED_OFFSET_ASM_OP
578 #define UNALIGNED_OFFSET_ASM_OP \
579 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
582 #ifndef UNALIGNED_WORD_ASM_OP
583 #define UNALIGNED_WORD_ASM_OP \
584 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
587 /* Data and reference forms for relocatable data. */
588 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
589 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
591 /* Pseudo-op for defining a new section. */
592 #ifndef SECTION_ASM_OP
593 #define SECTION_ASM_OP ".section"
596 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
597 print the SECTION_ASM_OP and the section name. The default here works for
598 almost all svr4 assemblers, except for the sparc, where the section name
599 must be enclosed in double quotes. (See sparcv4.h). */
600 #ifndef SECTION_FORMAT
601 #define SECTION_FORMAT "\t%s\t%s\n"
604 /* Section names used to hold DWARF debugging information. */
605 #ifndef DEBUG_SECTION
606 #define DEBUG_SECTION ".debug_info"
608 #ifndef ABBREV_SECTION
609 #define ABBREV_SECTION ".debug_abbrev"
611 #ifndef ARANGES_SECTION
612 #define ARANGES_SECTION ".debug_aranges"
614 #ifndef DW_MACINFO_SECTION
615 #define DW_MACINFO_SECTION ".debug_macinfo"
617 #ifndef FRAME_SECTION
618 #define FRAME_SECTION ".debug_frame"
621 #define LINE_SECTION ".debug_line"
624 #define LOC_SECTION ".debug_loc"
626 #ifndef PUBNAMES_SECTION
627 #define PUBNAMES_SECTION ".debug_pubnames"
630 #define STR_SECTION ".debug_str"
633 /* Standerd ELF section names for compiled code and data. */
635 #define TEXT_SECTION ".text"
638 #define DATA_SECTION ".data"
641 #define BSS_SECTION ".bss"
645 /* Definitions of defaults for formats and names of various special
646 (artificial) labels which may be generated within this file (when the -g
647 options is used and DWARF_DEBUGGING_INFO is in effect.
648 If necessary, these may be overridden from within the tm.h file, but
649 typically, overriding these defaults is unnecessary. */
651 char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
653 #ifndef TEXT_END_LABEL
654 #define TEXT_END_LABEL "Letext"
656 #ifndef DATA_END_LABEL
657 #define DATA_END_LABEL "Ledata"
659 #ifndef BSS_END_LABEL
660 #define BSS_END_LABEL "Lebss"
662 #ifndef INSN_LABEL_FMT
663 #define INSN_LABEL_FMT "LI%u_"
665 #ifndef BLOCK_BEGIN_LABEL
666 #define BLOCK_BEGIN_LABEL "LBB"
668 #ifndef BLOCK_END_LABEL
669 #define BLOCK_END_LABEL "LBE"
671 #ifndef BODY_BEGIN_LABEL
672 #define BODY_BEGIN_LABEL "Lbb"
674 #ifndef BODY_END_LABEL
675 #define BODY_END_LABEL "Lbe"
677 #ifndef FUNC_BEGIN_LABEL
678 #define FUNC_BEGIN_LABEL "LFB"
680 #ifndef FUNC_END_LABEL
681 #define FUNC_END_LABEL "LFE"
683 #ifndef LINE_CODE_LABEL
684 #define LINE_CODE_LABEL "LM"
686 #ifndef SEPARATE_LINE_CODE_LABEL
687 #define SEPARATE_LINE_CODE_LABEL "LSM"
690 /* Definitions of defaults for various types of primitive assembly language
691 output operations. These may be overridden from within the tm.h file,
692 but typically, that is unecessary. */
693 #ifndef ASM_OUTPUT_SECTION
694 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
695 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
698 #ifndef ASM_OUTPUT_DWARF_DELTA2
699 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
700 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
701 assemble_name (FILE, LABEL1); \
702 fprintf (FILE, "-"); \
703 assemble_name (FILE, LABEL2); \
707 #ifndef ASM_OUTPUT_DWARF_DELTA4
708 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
709 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
710 assemble_name (FILE, LABEL1); \
711 fprintf (FILE, "-"); \
712 assemble_name (FILE, LABEL2); \
716 #ifndef ASM_OUTPUT_DWARF_DELTA
717 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
718 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
719 assemble_name (FILE, LABEL1); \
720 fprintf (FILE, "-"); \
721 assemble_name (FILE, LABEL2); \
725 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
726 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
727 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
728 assemble_name (FILE, LABEL1); \
729 fprintf (FILE, "-"); \
730 assemble_name (FILE, LABEL2); \
734 #ifndef ASM_OUTPUT_DWARF_ADDR
735 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
736 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
737 assemble_name (FILE, LABEL); \
741 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
742 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
743 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
746 #ifndef ASM_OUTPUT_DWARF_OFFSET
747 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
748 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
749 assemble_name (FILE, LABEL); \
753 #ifndef ASM_OUTPUT_DWARF_DATA1
754 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
755 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
758 #ifndef ASM_OUTPUT_DWARF_DATA2
759 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
760 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
763 #ifndef ASM_OUTPUT_DWARF_DATA4
764 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
765 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
768 #ifndef ASM_OUTPUT_DWARF_DATA
769 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
770 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
771 (unsigned long) VALUE)
774 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
775 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
776 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
777 (unsigned long) VALUE)
780 #ifndef ASM_OUTPUT_DWARF_DATA8
781 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
783 if (WORDS_BIG_ENDIAN) \
785 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
786 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
790 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
791 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
796 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
797 newline is produced. When flag_verbose_asm is asserted, we add commnetary
798 at the end of the line, so we must avoid output of a newline here. */
799 #ifndef ASM_OUTPUT_DWARF_STRING
800 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
802 register int slen = strlen(P); \
803 register char *p = (P); \
805 fprintf (FILE, "\t.ascii \""); \
806 for (i = 0; i < slen; i++) \
808 register int c = p[i]; \
809 if (c == '\"' || c == '\\') \
811 if (c >= ' ' && c < 0177) \
815 fprintf (FILE, "\\%o", c); \
818 fprintf (FILE, "\\0\""); \
823 /* Convert a reference to the assembler name of a C-level name. This
824 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
825 a string rather than writing to a file. */
826 #ifndef ASM_NAME_TO_STRING
827 #define ASM_NAME_TO_STRING(STR, NAME) \
829 if ((NAME)[0] == '*') \
830 strcpy (STR, NAME+1); \
832 strcpy (STR, NAME); \
837 /* The DWARF 2 CFA column which tracks the return address. Normally this
838 is the column for PC, or the first column after all of the hard
840 #ifndef DWARF_FRAME_RETURN_COLUMN
842 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
844 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER + 1
848 /* The mapping from gcc register number to DWARF 2 CFA column number. By
849 default, we just provide columns for all registers. */
850 #ifndef DWARF_FRAME_REGNUM
851 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
854 /************************ general utility functions **************************/
856 /* Return a pointer to a copy of the section string name 's' with all
857 attributes stripped off. */
862 register char *stripped
, *p
;
863 stripped
= xstrdup (s
);
865 while (*p
&& *p
!= ',')
871 /* Convert an integer constant expression into assembler syntax.
872 Addition and subtraction are the only arithmetic
873 that may appear in these expressions. This is an adaptation
874 of output_addr_const() in final.c. Here, the target of the
875 conversion is a string buffer. We can't use output_addr_const
876 directly, because it writes to a file. */
878 addr_const_to_string (str
, x
)
887 switch (GET_CODE (x
))
897 ASM_NAME_TO_STRING (buf1
, XSTR (x
, 0));
902 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
903 ASM_NAME_TO_STRING (buf2
, buf1
);
908 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (x
));
909 ASM_NAME_TO_STRING (buf2
, buf1
);
915 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
925 /* This used to output parentheses around the expression, but that does
926 not work on the 386 (either ATT or BSD assembler). */
927 addr_const_to_string (buf1
, XEXP (x
, 0));
932 if (GET_MODE (x
) == VOIDmode
)
934 /* We can use %d if the number is one word and positive. */
935 if (CONST_DOUBLE_HIGH (x
))
937 #if HOST_BITS_PER_WIDE_INT == 64
938 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
944 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
950 CONST_DOUBLE_HIGH (x
), CONST_DOUBLE_LOW (x
));
951 else if (CONST_DOUBLE_LOW (x
) < 0)
953 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
958 CONST_DOUBLE_LOW (x
));
961 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
966 CONST_DOUBLE_LOW (x
));
970 /* We can't handle floating point constants; PRINT_OPERAND must
972 output_operand_lossage ("floating constant misused");
976 /* Some assemblers need integer constants to appear last (eg masm). */
977 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
979 addr_const_to_string (buf1
, XEXP (x
, 1));
981 if (INTVAL (XEXP (x
, 0)) >= 0)
983 addr_const_to_string (buf1
, XEXP (x
, 0));
988 addr_const_to_string (buf1
, XEXP (x
, 0));
990 if (INTVAL (XEXP (x
, 1)) >= 0)
992 addr_const_to_string (buf1
, XEXP (x
, 1));
998 /* Avoid outputting things like x-x or x+5-x, since some assemblers
999 can't handle that. */
1000 x
= simplify_subtraction (x
);
1001 if (GET_CODE (x
) != MINUS
)
1004 addr_const_to_string (buf1
, XEXP (x
, 0));
1007 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
1008 && INTVAL (XEXP (x
, 1)) < 0)
1010 strcat (str
, ASM_OPEN_PAREN
);
1011 addr_const_to_string (buf1
, XEXP (x
, 1));
1013 strcat (str
, ASM_CLOSE_PAREN
);
1017 addr_const_to_string (buf1
, XEXP (x
, 1));
1024 addr_const_to_string (buf1
, XEXP (x
, 0));
1029 output_operand_lossage ("invalid expression as operand");
1033 /* Convert an address constant to a string, and return a pointer to
1034 a copy of the result, located on the heap. */
1040 addr_const_to_string (buf
, x
);
1041 return xstrdup (buf
);
1044 /* Test if rtl node points to a psuedo register. */
1049 return (((GET_CODE (rtl
) == REG
) && (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
))
1050 || ((GET_CODE (rtl
) == SUBREG
)
1051 && (REGNO (XEXP (rtl
, 0)) >= FIRST_PSEUDO_REGISTER
)));
1055 /* Return a reference to a type, with its const and volatile qualifiers
1058 type_main_variant (type
)
1061 type
= TYPE_MAIN_VARIANT (type
);
1063 /* There really should be only one main variant among any group of variants
1064 of a given type (and all of the MAIN_VARIANT values for all members of
1065 the group should point to that one type) but sometimes the C front-end
1066 messes this up for array types, so we work around that bug here. */
1067 if (TREE_CODE (type
) == ARRAY_TYPE
)
1069 while (type
!= TYPE_MAIN_VARIANT (type
))
1070 type
= TYPE_MAIN_VARIANT (type
);
1075 /* Return non-zero if the given type node represents a tagged type. */
1077 is_tagged_type (type
)
1080 register enum tree_code code
= TREE_CODE (type
);
1082 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
1083 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
1086 /* Convert a DIE tag into its string name. */
1088 dwarf_tag_name (tag
)
1089 register unsigned tag
;
1093 case DW_TAG_padding
:
1094 return "DW_TAG_padding";
1095 case DW_TAG_array_type
:
1096 return "DW_TAG_array_type";
1097 case DW_TAG_class_type
:
1098 return "DW_TAG_class_type";
1099 case DW_TAG_entry_point
:
1100 return "DW_TAG_entry_point";
1101 case DW_TAG_enumeration_type
:
1102 return "DW_TAG_enumeration_type";
1103 case DW_TAG_formal_parameter
:
1104 return "DW_TAG_formal_parameter";
1105 case DW_TAG_imported_declaration
:
1106 return "DW_TAG_imported_declaration";
1108 return "DW_TAG_label";
1109 case DW_TAG_lexical_block
:
1110 return "DW_TAG_lexical_block";
1112 return "DW_TAG_member";
1113 case DW_TAG_pointer_type
:
1114 return "DW_TAG_pointer_type";
1115 case DW_TAG_reference_type
:
1116 return "DW_TAG_reference_type";
1117 case DW_TAG_compile_unit
:
1118 return "DW_TAG_compile_unit";
1119 case DW_TAG_string_type
:
1120 return "DW_TAG_string_type";
1121 case DW_TAG_structure_type
:
1122 return "DW_TAG_structure_type";
1123 case DW_TAG_subroutine_type
:
1124 return "DW_TAG_subroutine_type";
1125 case DW_TAG_typedef
:
1126 return "DW_TAG_typedef";
1127 case DW_TAG_union_type
:
1128 return "DW_TAG_union_type";
1129 case DW_TAG_unspecified_parameters
:
1130 return "DW_TAG_unspecified_parameters";
1131 case DW_TAG_variant
:
1132 return "DW_TAG_variant";
1133 case DW_TAG_common_block
:
1134 return "DW_TAG_common_block";
1135 case DW_TAG_common_inclusion
:
1136 return "DW_TAG_common_inclusion";
1137 case DW_TAG_inheritance
:
1138 return "DW_TAG_inheritance";
1139 case DW_TAG_inlined_subroutine
:
1140 return "DW_TAG_inlined_subroutine";
1142 return "DW_TAG_module";
1143 case DW_TAG_ptr_to_member_type
:
1144 return "DW_TAG_ptr_to_member_type";
1145 case DW_TAG_set_type
:
1146 return "DW_TAG_set_type";
1147 case DW_TAG_subrange_type
:
1148 return "DW_TAG_subrange_type";
1149 case DW_TAG_with_stmt
:
1150 return "DW_TAG_with_stmt";
1151 case DW_TAG_access_declaration
:
1152 return "DW_TAG_access_declaration";
1153 case DW_TAG_base_type
:
1154 return "DW_TAG_base_type";
1155 case DW_TAG_catch_block
:
1156 return "DW_TAG_catch_block";
1157 case DW_TAG_const_type
:
1158 return "DW_TAG_const_type";
1159 case DW_TAG_constant
:
1160 return "DW_TAG_constant";
1161 case DW_TAG_enumerator
:
1162 return "DW_TAG_enumerator";
1163 case DW_TAG_file_type
:
1164 return "DW_TAG_file_type";
1166 return "DW_TAG_friend";
1167 case DW_TAG_namelist
:
1168 return "DW_TAG_namelist";
1169 case DW_TAG_namelist_item
:
1170 return "DW_TAG_namelist_item";
1171 case DW_TAG_packed_type
:
1172 return "DW_TAG_packed_type";
1173 case DW_TAG_subprogram
:
1174 return "DW_TAG_subprogram";
1175 case DW_TAG_template_type_param
:
1176 return "DW_TAG_template_type_param";
1177 case DW_TAG_template_value_param
:
1178 return "DW_TAG_template_value_param";
1179 case DW_TAG_thrown_type
:
1180 return "DW_TAG_thrown_type";
1181 case DW_TAG_try_block
:
1182 return "DW_TAG_try_block";
1183 case DW_TAG_variant_part
:
1184 return "DW_TAG_variant_part";
1185 case DW_TAG_variable
:
1186 return "DW_TAG_variable";
1187 case DW_TAG_volatile_type
:
1188 return "DW_TAG_volatile_type";
1189 case DW_TAG_MIPS_loop
:
1190 return "DW_TAG_MIPS_loop";
1191 case DW_TAG_format_label
:
1192 return "DW_TAG_format_label";
1193 case DW_TAG_function_template
:
1194 return "DW_TAG_function_template";
1195 case DW_TAG_class_template
:
1196 return "DW_TAG_class_template";
1198 return "DW_TAG_<unknown>";
1202 /* Convert a DWARF attribute code into its string name. */
1204 dwarf_attr_name (attr
)
1205 register unsigned attr
;
1210 return "DW_AT_sibling";
1211 case DW_AT_location
:
1212 return "DW_AT_location";
1214 return "DW_AT_name";
1215 case DW_AT_ordering
:
1216 return "DW_AT_ordering";
1217 case DW_AT_subscr_data
:
1218 return "DW_AT_subscr_data";
1219 case DW_AT_byte_size
:
1220 return "DW_AT_byte_size";
1221 case DW_AT_bit_offset
:
1222 return "DW_AT_bit_offset";
1223 case DW_AT_bit_size
:
1224 return "DW_AT_bit_size";
1225 case DW_AT_element_list
:
1226 return "DW_AT_element_list";
1227 case DW_AT_stmt_list
:
1228 return "DW_AT_stmt_list";
1230 return "DW_AT_low_pc";
1232 return "DW_AT_high_pc";
1233 case DW_AT_language
:
1234 return "DW_AT_language";
1236 return "DW_AT_member";
1238 return "DW_AT_discr";
1239 case DW_AT_discr_value
:
1240 return "DW_AT_discr_value";
1241 case DW_AT_visibility
:
1242 return "DW_AT_visibility";
1244 return "DW_AT_import";
1245 case DW_AT_string_length
:
1246 return "DW_AT_string_length";
1247 case DW_AT_common_reference
:
1248 return "DW_AT_common_reference";
1249 case DW_AT_comp_dir
:
1250 return "DW_AT_comp_dir";
1251 case DW_AT_const_value
:
1252 return "DW_AT_const_value";
1253 case DW_AT_containing_type
:
1254 return "DW_AT_containing_type";
1255 case DW_AT_default_value
:
1256 return "DW_AT_default_value";
1258 return "DW_AT_inline";
1259 case DW_AT_is_optional
:
1260 return "DW_AT_is_optional";
1261 case DW_AT_lower_bound
:
1262 return "DW_AT_lower_bound";
1263 case DW_AT_producer
:
1264 return "DW_AT_producer";
1265 case DW_AT_prototyped
:
1266 return "DW_AT_prototyped";
1267 case DW_AT_return_addr
:
1268 return "DW_AT_return_addr";
1269 case DW_AT_start_scope
:
1270 return "DW_AT_start_scope";
1271 case DW_AT_stride_size
:
1272 return "DW_AT_stride_size";
1273 case DW_AT_upper_bound
:
1274 return "DW_AT_upper_bound";
1275 case DW_AT_abstract_origin
:
1276 return "DW_AT_abstract_origin";
1277 case DW_AT_accessibility
:
1278 return "DW_AT_accessibility";
1279 case DW_AT_address_class
:
1280 return "DW_AT_address_class";
1281 case DW_AT_artificial
:
1282 return "DW_AT_artificial";
1283 case DW_AT_base_types
:
1284 return "DW_AT_base_types";
1285 case DW_AT_calling_convention
:
1286 return "DW_AT_calling_convention";
1288 return "DW_AT_count";
1289 case DW_AT_data_member_location
:
1290 return "DW_AT_data_member_location";
1291 case DW_AT_decl_column
:
1292 return "DW_AT_decl_column";
1293 case DW_AT_decl_file
:
1294 return "DW_AT_decl_file";
1295 case DW_AT_decl_line
:
1296 return "DW_AT_decl_line";
1297 case DW_AT_declaration
:
1298 return "DW_AT_declaration";
1299 case DW_AT_discr_list
:
1300 return "DW_AT_discr_list";
1301 case DW_AT_encoding
:
1302 return "DW_AT_encoding";
1303 case DW_AT_external
:
1304 return "DW_AT_external";
1305 case DW_AT_frame_base
:
1306 return "DW_AT_frame_base";
1308 return "DW_AT_friend";
1309 case DW_AT_identifier_case
:
1310 return "DW_AT_identifier_case";
1311 case DW_AT_macro_info
:
1312 return "DW_AT_macro_info";
1313 case DW_AT_namelist_items
:
1314 return "DW_AT_namelist_items";
1315 case DW_AT_priority
:
1316 return "DW_AT_priority";
1318 return "DW_AT_segment";
1319 case DW_AT_specification
:
1320 return "DW_AT_specification";
1321 case DW_AT_static_link
:
1322 return "DW_AT_static_link";
1324 return "DW_AT_type";
1325 case DW_AT_use_location
:
1326 return "DW_AT_use_location";
1327 case DW_AT_variable_parameter
:
1328 return "DW_AT_variable_parameter";
1329 case DW_AT_virtuality
:
1330 return "DW_AT_virtuality";
1331 case DW_AT_vtable_elem_location
:
1332 return "DW_AT_vtable_elem_location";
1334 case DW_AT_MIPS_fde
:
1335 return "DW_AT_MIPS_fde";
1336 case DW_AT_MIPS_loop_begin
:
1337 return "DW_AT_MIPS_loop_begin";
1338 case DW_AT_MIPS_tail_loop_begin
:
1339 return "DW_AT_MIPS_tail_loop_begin";
1340 case DW_AT_MIPS_epilog_begin
:
1341 return "DW_AT_MIPS_epilog_begin";
1342 case DW_AT_MIPS_loop_unroll_factor
:
1343 return "DW_AT_MIPS_loop_unroll_factor";
1344 case DW_AT_MIPS_software_pipeline_depth
:
1345 return "DW_AT_MIPS_software_pipeline_depth";
1346 case DW_AT_MIPS_linkage_name
:
1347 return "DW_AT_MIPS_linkage_name";
1348 case DW_AT_MIPS_stride
:
1349 return "DW_AT_MIPS_stride";
1350 case DW_AT_MIPS_abstract_name
:
1351 return "DW_AT_MIPS_abstract_name";
1352 case DW_AT_MIPS_clone_origin
:
1353 return "DW_AT_MIPS_clone_origin";
1354 case DW_AT_MIPS_has_inlines
:
1355 return "DW_AT_MIPS_has_inlines";
1357 case DW_AT_sf_names
:
1358 return "DW_AT_sf_names";
1359 case DW_AT_src_info
:
1360 return "DW_AT_src_info";
1361 case DW_AT_mac_info
:
1362 return "DW_AT_mac_info";
1363 case DW_AT_src_coords
:
1364 return "DW_AT_src_coords";
1365 case DW_AT_body_begin
:
1366 return "DW_AT_body_begin";
1367 case DW_AT_body_end
:
1368 return "DW_AT_body_end";
1370 return "DW_AT_<unknown>";
1374 /* Convert a DWARF value form code into its string name. */
1376 dwarf_form_name (form
)
1377 register unsigned form
;
1382 return "DW_FORM_addr";
1383 case DW_FORM_block2
:
1384 return "DW_FORM_block2";
1385 case DW_FORM_block4
:
1386 return "DW_FORM_block4";
1388 return "DW_FORM_data2";
1390 return "DW_FORM_data4";
1392 return "DW_FORM_data8";
1393 case DW_FORM_string
:
1394 return "DW_FORM_string";
1396 return "DW_FORM_block";
1397 case DW_FORM_block1
:
1398 return "DW_FORM_block1";
1400 return "DW_FORM_data1";
1402 return "DW_FORM_flag";
1404 return "DW_FORM_sdata";
1406 return "DW_FORM_strp";
1408 return "DW_FORM_udata";
1409 case DW_FORM_ref_addr
:
1410 return "DW_FORM_ref_addr";
1412 return "DW_FORM_ref1";
1414 return "DW_FORM_ref2";
1416 return "DW_FORM_ref4";
1418 return "DW_FORM_ref8";
1419 case DW_FORM_ref_udata
:
1420 return "DW_FORM_ref_udata";
1421 case DW_FORM_indirect
:
1422 return "DW_FORM_indirect";
1424 return "DW_FORM_<unknown>";
1428 /* Convert a DWARF stack opcode into its string name. */
1430 dwarf_stack_op_name (op
)
1431 register unsigned op
;
1436 return "DW_OP_addr";
1438 return "DW_OP_deref";
1440 return "DW_OP_const1u";
1442 return "DW_OP_const1s";
1444 return "DW_OP_const2u";
1446 return "DW_OP_const2s";
1448 return "DW_OP_const4u";
1450 return "DW_OP_const4s";
1452 return "DW_OP_const8u";
1454 return "DW_OP_const8s";
1456 return "DW_OP_constu";
1458 return "DW_OP_consts";
1462 return "DW_OP_drop";
1464 return "DW_OP_over";
1466 return "DW_OP_pick";
1468 return "DW_OP_swap";
1472 return "DW_OP_xderef";
1480 return "DW_OP_minus";
1492 return "DW_OP_plus";
1493 case DW_OP_plus_uconst
:
1494 return "DW_OP_plus_uconst";
1500 return "DW_OP_shra";
1518 return "DW_OP_skip";
1520 return "DW_OP_lit0";
1522 return "DW_OP_lit1";
1524 return "DW_OP_lit2";
1526 return "DW_OP_lit3";
1528 return "DW_OP_lit4";
1530 return "DW_OP_lit5";
1532 return "DW_OP_lit6";
1534 return "DW_OP_lit7";
1536 return "DW_OP_lit8";
1538 return "DW_OP_lit9";
1540 return "DW_OP_lit10";
1542 return "DW_OP_lit11";
1544 return "DW_OP_lit12";
1546 return "DW_OP_lit13";
1548 return "DW_OP_lit14";
1550 return "DW_OP_lit15";
1552 return "DW_OP_lit16";
1554 return "DW_OP_lit17";
1556 return "DW_OP_lit18";
1558 return "DW_OP_lit19";
1560 return "DW_OP_lit20";
1562 return "DW_OP_lit21";
1564 return "DW_OP_lit22";
1566 return "DW_OP_lit23";
1568 return "DW_OP_lit24";
1570 return "DW_OP_lit25";
1572 return "DW_OP_lit26";
1574 return "DW_OP_lit27";
1576 return "DW_OP_lit28";
1578 return "DW_OP_lit29";
1580 return "DW_OP_lit30";
1582 return "DW_OP_lit31";
1584 return "DW_OP_reg0";
1586 return "DW_OP_reg1";
1588 return "DW_OP_reg2";
1590 return "DW_OP_reg3";
1592 return "DW_OP_reg4";
1594 return "DW_OP_reg5";
1596 return "DW_OP_reg6";
1598 return "DW_OP_reg7";
1600 return "DW_OP_reg8";
1602 return "DW_OP_reg9";
1604 return "DW_OP_reg10";
1606 return "DW_OP_reg11";
1608 return "DW_OP_reg12";
1610 return "DW_OP_reg13";
1612 return "DW_OP_reg14";
1614 return "DW_OP_reg15";
1616 return "DW_OP_reg16";
1618 return "DW_OP_reg17";
1620 return "DW_OP_reg18";
1622 return "DW_OP_reg19";
1624 return "DW_OP_reg20";
1626 return "DW_OP_reg21";
1628 return "DW_OP_reg22";
1630 return "DW_OP_reg23";
1632 return "DW_OP_reg24";
1634 return "DW_OP_reg25";
1636 return "DW_OP_reg26";
1638 return "DW_OP_reg27";
1640 return "DW_OP_reg28";
1642 return "DW_OP_reg29";
1644 return "DW_OP_reg30";
1646 return "DW_OP_reg31";
1648 return "DW_OP_breg0";
1650 return "DW_OP_breg1";
1652 return "DW_OP_breg2";
1654 return "DW_OP_breg3";
1656 return "DW_OP_breg4";
1658 return "DW_OP_breg5";
1660 return "DW_OP_breg6";
1662 return "DW_OP_breg7";
1664 return "DW_OP_breg8";
1666 return "DW_OP_breg9";
1668 return "DW_OP_breg10";
1670 return "DW_OP_breg11";
1672 return "DW_OP_breg12";
1674 return "DW_OP_breg13";
1676 return "DW_OP_breg14";
1678 return "DW_OP_breg15";
1680 return "DW_OP_breg16";
1682 return "DW_OP_breg17";
1684 return "DW_OP_breg18";
1686 return "DW_OP_breg19";
1688 return "DW_OP_breg20";
1690 return "DW_OP_breg21";
1692 return "DW_OP_breg22";
1694 return "DW_OP_breg23";
1696 return "DW_OP_breg24";
1698 return "DW_OP_breg25";
1700 return "DW_OP_breg26";
1702 return "DW_OP_breg27";
1704 return "DW_OP_breg28";
1706 return "DW_OP_breg29";
1708 return "DW_OP_breg30";
1710 return "DW_OP_breg31";
1712 return "DW_OP_regx";
1714 return "DW_OP_fbreg";
1716 return "DW_OP_bregx";
1718 return "DW_OP_piece";
1719 case DW_OP_deref_size
:
1720 return "DW_OP_deref_size";
1721 case DW_OP_xderef_size
:
1722 return "DW_OP_xderef_size";
1726 return "OP_<unknown>";
1730 /* Convert a DWARF type code into its string name. */
1732 dwarf_type_encoding_name (enc
)
1733 register unsigned enc
;
1737 case DW_ATE_address
:
1738 return "DW_ATE_address";
1739 case DW_ATE_boolean
:
1740 return "DW_ATE_boolean";
1741 case DW_ATE_complex_float
:
1742 return "DW_ATE_complex_float";
1744 return "DW_ATE_float";
1746 return "DW_ATE_signed";
1747 case DW_ATE_signed_char
:
1748 return "DW_ATE_signed_char";
1749 case DW_ATE_unsigned
:
1750 return "DW_ATE_unsigned";
1751 case DW_ATE_unsigned_char
:
1752 return "DW_ATE_unsigned_char";
1754 return "DW_ATE_<unknown>";
1758 /* Convert a DWARF call frame info. operation to its string name */
1760 dwarf_cfi_name (cfi_opc
)
1761 register unsigned cfi_opc
;
1765 case DW_CFA_advance_loc
:
1766 return "DW_CFA_advance_loc";
1768 return "DW_CFA_offset";
1769 case DW_CFA_restore
:
1770 return "DW_CFA_restore";
1772 return "DW_CFA_nop";
1773 case DW_CFA_set_loc
:
1774 return "DW_CFA_set_loc";
1775 case DW_CFA_advance_loc1
:
1776 return "DW_CFA_advance_loc1";
1777 case DW_CFA_advance_loc2
:
1778 return "DW_CFA_advance_loc2";
1779 case DW_CFA_advance_loc4
:
1780 return "DW_CFA_advance_loc4";
1781 case DW_CFA_offset_extended
:
1782 return "DW_CFA_offset_extended";
1783 case DW_CFA_restore_extended
:
1784 return "DW_CFA_restore_extended";
1785 case DW_CFA_undefined
:
1786 return "DW_CFA_undefined";
1787 case DW_CFA_same_value
:
1788 return "DW_CFA_same_value";
1789 case DW_CFA_register
:
1790 return "DW_CFA_register";
1791 case DW_CFA_remember_state
:
1792 return "DW_CFA_remember_state";
1793 case DW_CFA_restore_state
:
1794 return "DW_CFA_restore_state";
1795 case DW_CFA_def_cfa
:
1796 return "DW_CFA_def_cfa";
1797 case DW_CFA_def_cfa_register
:
1798 return "DW_CFA_def_cfa_register";
1799 case DW_CFA_def_cfa_offset
:
1800 return "DW_CFA_def_cfa_offset";
1801 /* SGI/MIPS specific */
1802 case DW_CFA_MIPS_advance_loc8
:
1803 return "DW_CFA_MIPS_advance_loc8";
1805 return "DW_CFA_<unknown>";
1809 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
1810 instance of an inlined instance of a decl which is local to an inline
1811 function, so we have to trace all of the way back through the origin chain
1812 to find out what sort of node actually served as the original seed for the
1815 decl_ultimate_origin (decl
)
1818 register tree immediate_origin
= DECL_ABSTRACT_ORIGIN (decl
);
1820 if (immediate_origin
== NULL
)
1824 register tree ret_val
;
1825 register tree lookahead
= immediate_origin
;
1829 ret_val
= lookahead
;
1830 lookahead
= DECL_ABSTRACT_ORIGIN (ret_val
);
1832 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
1837 /* Determine the "ultimate origin" of a block. The block may be an inlined
1838 instance of an inlined instance of a block which is local to an inline
1839 function, so we have to trace all of the way back through the origin chain
1840 to find out what sort of node actually served as the original seed for the
1843 block_ultimate_origin (block
)
1844 register tree block
;
1846 register tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
1848 if (immediate_origin
== NULL
)
1852 register tree ret_val
;
1853 register tree lookahead
= immediate_origin
;
1857 ret_val
= lookahead
;
1858 lookahead
= (TREE_CODE (ret_val
) == BLOCK
)
1859 ? BLOCK_ABSTRACT_ORIGIN (ret_val
)
1862 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
1867 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1868 of a virtual function may refer to a base class, so we check the 'this'
1872 decl_class_context (decl
)
1875 tree context
= NULL_TREE
;
1876 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
1877 context
= DECL_CONTEXT (decl
);
1879 context
= TYPE_MAIN_VARIANT
1880 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
1882 if (context
&& TREE_CODE_CLASS (TREE_CODE (context
)) != 't')
1883 context
= NULL_TREE
;
1888 /**************** DIE internal representation constturction *******************/
1890 /* Add an attribute/value pair to a DIE */
1892 add_dwarf_attr (die
, attr
)
1893 register dw_die_ref die
;
1894 register dw_attr_ref attr
;
1896 if (die
!= NULL
&& attr
!= NULL
)
1898 if (die
->die_attr
== NULL
)
1900 die
->die_attr
= attr
;
1901 die
->die_attr_last
= attr
;
1905 die
->die_attr_last
->dw_attr_next
= attr
;
1906 die
->die_attr_last
= attr
;
1911 /* Add a flag value attribute to a DIE. */
1913 add_AT_flag (die
, attr_kind
, flag
)
1914 register dw_die_ref die
;
1915 register enum dwarf_attribute attr_kind
;
1916 register unsigned flag
;
1918 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1921 attr
->dw_attr_next
= NULL
;
1922 attr
->dw_attr
= attr_kind
;
1923 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
1924 attr
->dw_attr_val
.v
.val_flag
= flag
;
1925 add_dwarf_attr (die
, attr
);
1929 /* Add a signed integer attribute value to a DIE. */
1931 add_AT_int (die
, attr_kind
, int_val
)
1932 register dw_die_ref die
;
1933 register enum dwarf_attribute attr_kind
;
1934 register long int int_val
;
1936 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1939 attr
->dw_attr_next
= NULL
;
1940 attr
->dw_attr
= attr_kind
;
1941 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
1942 attr
->dw_attr_val
.v
.val_int
= int_val
;
1943 add_dwarf_attr (die
, attr
);
1947 /* Add an unsigned integer attribute value to a DIE. */
1949 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
1950 register dw_die_ref die
;
1951 register enum dwarf_attribute attr_kind
;
1952 register unsigned long unsigned_val
;
1954 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1957 attr
->dw_attr_next
= NULL
;
1958 attr
->dw_attr
= attr_kind
;
1959 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
1960 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
1961 add_dwarf_attr (die
, attr
);
1965 /* Add an unsigned double integer attribute value to a DIE. */
1967 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
1968 register dw_die_ref die
;
1969 register enum dwarf_attribute attr_kind
;
1970 register unsigned long val_hi
;
1971 register unsigned long val_low
;
1973 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1976 attr
->dw_attr_next
= NULL
;
1977 attr
->dw_attr
= attr_kind
;
1978 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
1979 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
1980 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
1981 add_dwarf_attr (die
, attr
);
1985 /* Add a floating point attribute value to a DIE and return it. */
1987 add_AT_float (die
, attr_kind
, length
, array
)
1988 register dw_die_ref die
;
1989 register enum dwarf_attribute attr_kind
;
1990 register unsigned length
;
1991 register long *array
;
1993 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1996 attr
->dw_attr_next
= NULL
;
1997 attr
->dw_attr
= attr_kind
;
1998 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
1999 attr
->dw_attr_val
.v
.val_float
.length
= length
;
2000 attr
->dw_attr_val
.v
.val_float
.array
= array
;
2001 add_dwarf_attr (die
, attr
);
2005 /* Add a string attribute value to a DIE. */
2007 add_AT_string (die
, attr_kind
, str
)
2008 register dw_die_ref die
;
2009 register enum dwarf_attribute attr_kind
;
2012 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2015 attr
->dw_attr_next
= NULL
;
2016 attr
->dw_attr
= attr_kind
;
2017 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
2018 attr
->dw_attr_val
.v
.val_str
= xstrdup (str
);
2019 add_dwarf_attr (die
, attr
);
2023 /* Add a DIE reference attribute value to a DIE. */
2025 add_AT_die_ref (die
, attr_kind
, targ_die
)
2026 register dw_die_ref die
;
2027 register enum dwarf_attribute attr_kind
;
2028 register dw_die_ref targ_die
;
2030 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2033 attr
->dw_attr_next
= NULL
;
2034 attr
->dw_attr
= attr_kind
;
2035 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
2036 attr
->dw_attr_val
.v
.val_die_ref
= targ_die
;
2037 add_dwarf_attr (die
, attr
);
2041 /* Add an FDE reference attribute value to a DIE. */
2043 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
2044 register dw_die_ref die
;
2045 register enum dwarf_attribute attr_kind
;
2046 register unsigned targ_fde
;
2048 register dw_attr_ref attr
;
2050 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_fde_ref
;
2056 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
2057 add_dwarf_attr (die
, attr
);
2061 /* Add a location description attribute value to a DIE. */
2063 add_AT_loc (die
, attr_kind
, loc
)
2064 register dw_die_ref die
;
2065 register enum dwarf_attribute attr_kind
;
2066 register dw_loc_descr_ref loc
;
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_loc
;
2074 attr
->dw_attr_val
.v
.val_loc
= loc
;
2075 add_dwarf_attr (die
, attr
);
2079 /* Add an address constant attribute value to a DIE. */
2081 add_AT_addr (die
, attr_kind
, addr
)
2082 register dw_die_ref die
;
2083 register enum dwarf_attribute attr_kind
;
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_addr
;
2092 attr
->dw_attr_val
.v
.val_addr
= addr
;
2093 add_dwarf_attr (die
, attr
);
2097 /* Add a label identifier attribute value to a DIE. */
2099 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
2100 register dw_die_ref die
;
2101 register enum dwarf_attribute attr_kind
;
2102 register char *lbl_id
;
2104 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2107 attr
->dw_attr_next
= NULL
;
2108 attr
->dw_attr
= attr_kind
;
2109 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
2110 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
2111 add_dwarf_attr (die
, attr
);
2115 /* Add a section offset attribute value to a DIE. */
2117 add_AT_section_offset (die
, attr_kind
, section
)
2118 register dw_die_ref die
;
2119 register enum dwarf_attribute attr_kind
;
2120 register char *section
;
2122 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2125 attr
->dw_attr_next
= NULL
;
2126 attr
->dw_attr
= attr_kind
;
2127 attr
->dw_attr_val
.val_class
= dw_val_class_section_offset
;
2128 attr
->dw_attr_val
.v
.val_section
= section
;
2129 add_dwarf_attr (die
, attr
);
2133 /* Test if die refers to an external subroutine. */
2135 is_extern_subr_die (die
)
2136 register dw_die_ref die
;
2138 register dw_attr_ref a
;
2139 register int is_subr
= FALSE
;
2140 register int is_extern
= FALSE
;
2141 if (die
!= NULL
&& die
->die_tag
== DW_TAG_subprogram
)
2144 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2146 if (a
->dw_attr
== DW_AT_external
2147 && a
->dw_attr_val
.val_class
== dw_val_class_flag
2148 && a
->dw_attr_val
.v
.val_flag
!= 0)
2155 return is_subr
&& is_extern
;
2158 /* Get the attribute of type attr_kind. */
2160 get_AT (die
, attr_kind
)
2161 register dw_die_ref die
;
2162 register enum dwarf_attribute attr_kind
;
2164 register dw_attr_ref a
;
2165 register dw_die_ref spec
= NULL
;
2169 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2171 if (a
->dw_attr
== attr_kind
)
2173 if (a
->dw_attr
== DW_AT_specification
2174 || a
->dw_attr
== DW_AT_abstract_origin
)
2175 spec
= a
->dw_attr_val
.v
.val_die_ref
;
2178 return get_AT (spec
, attr_kind
);
2183 /* Return the "low pc" attribute value, typically associated with
2184 a subprogram DIE. Return null if the "low pc" attribute is
2185 either not prsent, or if it cannot be represented as an
2186 assembler label identifier. */
2189 register dw_die_ref die
;
2191 register dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
2192 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
2193 return a
->dw_attr_val
.v
.val_lbl_id
;
2197 /* Return the "high pc" attribute value, typically associated with
2198 a subprogram DIE. Return null if the "high pc" attribute is
2199 either not prsent, or if it cannot be represented as an
2200 assembler label identifier. */
2203 register dw_die_ref die
;
2205 register dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
2206 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
2207 return a
->dw_attr_val
.v
.val_lbl_id
;
2211 /* Return the value of the string attribute designated by ATTR_KIND, or
2212 NULL if it is not present. */
2214 get_AT_string (die
, attr_kind
)
2215 register dw_die_ref die
;
2216 register enum dwarf_attribute attr_kind
;
2218 register dw_attr_ref a
= get_AT (die
, attr_kind
);
2219 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_str
)
2220 return a
->dw_attr_val
.v
.val_str
;
2224 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
2225 if it is not present. */
2227 get_AT_flag (die
, attr_kind
)
2228 register dw_die_ref die
;
2229 register enum dwarf_attribute attr_kind
;
2231 register dw_attr_ref a
= get_AT (die
, attr_kind
);
2232 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_flag
)
2233 return a
->dw_attr_val
.v
.val_flag
;
2237 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2238 if it is not present. */
2240 get_AT_unsigned (die
, attr_kind
)
2241 register dw_die_ref die
;
2242 register enum dwarf_attribute attr_kind
;
2244 register dw_attr_ref a
= get_AT (die
, attr_kind
);
2245 if (a
&& a
->dw_attr_val
.val_class
== dw_val_class_unsigned_const
)
2246 return a
->dw_attr_val
.v
.val_unsigned
;
2253 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
2254 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
2255 || lang
== DW_LANG_C_plus_plus
);
2261 register unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
2262 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
2265 /* Remove the specified attribute if present. */
2267 remove_AT (die
, attr_kind
)
2268 register dw_die_ref die
;
2269 register enum dwarf_attribute attr_kind
;
2271 register dw_attr_ref a
;
2272 register dw_attr_ref removed
= NULL
;;
2275 if (die
->die_attr
->dw_attr
== attr_kind
)
2277 removed
= die
->die_attr
;
2278 if (die
->die_attr_last
== die
->die_attr
)
2279 die
->die_attr_last
= NULL
;
2280 die
->die_attr
= die
->die_attr
->dw_attr_next
;
2282 else for (a
= die
->die_attr
; a
->dw_attr_next
!= NULL
;
2283 a
= a
->dw_attr_next
)
2284 if (a
->dw_attr_next
->dw_attr
== attr_kind
)
2286 removed
= a
->dw_attr_next
;
2287 if (die
->die_attr_last
== a
->dw_attr_next
)
2288 die
->die_attr_last
= a
;
2289 a
->dw_attr_next
= a
->dw_attr_next
->dw_attr_next
;
2297 /* Discard the children of this DIE. */
2299 remove_children (die
)
2300 register dw_die_ref die
;
2302 register dw_die_ref child_die
= die
->die_child
;
2303 die
->die_child
= NULL
;
2304 die
->die_child_last
= NULL
;
2305 while (child_die
!= NULL
)
2307 register dw_die_ref tmp_die
= child_die
;
2308 register dw_attr_ref a
;
2309 child_die
= child_die
->die_sib
;
2311 for (a
= tmp_die
->die_attr
; a
!= NULL
; )
2313 register dw_attr_ref tmp_a
= a
;
2314 a
= a
->dw_attr_next
;
2321 /* Add a child DIE below its parent. */
2323 add_child_die (die
, child_die
)
2324 register dw_die_ref die
;
2325 register dw_die_ref child_die
;
2327 if (die
!= NULL
&& child_die
!= NULL
)
2329 assert (die
!= child_die
);
2330 child_die
->die_parent
= die
;
2331 child_die
->die_sib
= NULL
;
2332 if (die
->die_child
== NULL
)
2334 die
->die_child
= child_die
;
2335 die
->die_child_last
= child_die
;
2339 die
->die_child_last
->die_sib
= child_die
;
2340 die
->die_child_last
= child_die
;
2345 /* Return a pointer to a newly created DIE node. */
2347 new_die (tag_value
, parent_die
)
2348 register enum dwarf_tag tag_value
;
2349 register dw_die_ref parent_die
;
2351 register dw_die_ref die
= (dw_die_ref
) xmalloc (sizeof (die_node
));
2354 die
->die_tag
= tag_value
;
2355 die
->die_abbrev
= 0;
2356 die
->die_offset
= 0;
2357 die
->die_child
= NULL
;
2358 die
->die_parent
= NULL
;
2359 die
->die_sib
= NULL
;
2360 die
->die_child_last
= NULL
;
2361 die
->die_attr
= NULL
;
2362 die
->die_attr_last
= NULL
;
2363 if (parent_die
!= NULL
)
2364 add_child_die (parent_die
, die
);
2371 /* Return the DIE associated with the given type specifier. */
2373 lookup_type_die (type
)
2376 return (dw_die_ref
) TYPE_SYMTAB_POINTER (type
);
2379 /* Equate a DIE to a given type specifier. */
2381 equate_type_number_to_die (type
, type_die
)
2383 register dw_die_ref type_die
;
2385 TYPE_SYMTAB_POINTER (type
) = (char *) type_die
;
2388 /* Return the DIE associated with a given declaration. */
2390 lookup_decl_die (decl
)
2393 register unsigned decl_id
= DECL_UID (decl
);
2394 return (decl_id
< decl_die_table_in_use
)
2395 ? decl_die_table
[decl_id
] : NULL
;
2398 /* Equate a DIE to a particular declaration. */
2400 equate_decl_number_to_die (decl
, decl_die
)
2402 register dw_die_ref decl_die
;
2404 register unsigned decl_id
= DECL_UID (decl
);
2405 register unsigned i
;
2406 register unsigned num_allocated
;
2407 if (decl_id
>= decl_die_table_allocated
)
2409 num_allocated
= (((decl_id
+ 1)
2410 + DECL_DIE_TABLE_INCREMENT
- 1)
2411 / DECL_DIE_TABLE_INCREMENT
)
2412 * DECL_DIE_TABLE_INCREMENT
;
2413 decl_die_table
= (dw_die_ref
*) xrealloc (decl_die_table
,
2414 sizeof (dw_die_ref
) * num_allocated
);
2415 bzero (&decl_die_table
[decl_die_table_allocated
],
2416 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
2417 decl_die_table_allocated
= num_allocated
;
2419 if (decl_id
>= decl_die_table_in_use
)
2421 decl_die_table_in_use
= (decl_id
+ 1);
2423 decl_die_table
[decl_id
] = decl_die
;
2426 /* Return a pointer to a newly allocated location description. Location
2427 descriptions are simple expression terms that can be strung
2428 together to form more complicated location (address) descriptions. */
2429 inline dw_loc_descr_ref
2430 new_loc_descr (op
, oprnd1
, oprnd2
)
2431 register enum dwarf_location_atom op
;
2432 register unsigned long oprnd1
;
2433 register unsigned long oprnd2
;
2435 register dw_loc_descr_ref descr
=
2436 (dw_loc_descr_ref
) xmalloc (sizeof (dw_loc_descr_node
));
2439 descr
->dw_loc_next
= NULL
;
2440 descr
->dw_loc_opc
= op
;
2441 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2442 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2443 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2444 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2449 /* Add a location description term to a location description expression. */
2451 add_loc_descr (list_head
, descr
)
2452 register dw_loc_descr_ref
*list_head
;
2453 register dw_loc_descr_ref descr
;
2455 register dw_loc_descr_ref
*d
;
2456 /* find the end of the chain. */
2457 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2464 /* Return a pointer to a newly allocated Call Frame Instruction. */
2468 register dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
2471 cfi
->dw_cfi_next
= NULL
;
2472 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
2473 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
2478 /* Add a Call Frame Instruction to list of instructions. */
2480 add_cfi (list_head
, cfi
)
2481 register dw_cfi_ref
*list_head
;
2482 register dw_cfi_ref cfi
;
2484 register dw_cfi_ref
*p
;
2485 /* find the end of the chain. */
2486 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
2493 /********* Print DWARF Internal Representation (debugging aids) ***************/
2495 /* Keep track of the number of spaces used to indent the
2496 output of the debugging routines that print the structure of
2497 the DIE internal representation. */
2498 static int print_indent
;
2500 /* Indent the line the number of spaces given by print_indent. */
2502 print_spaces (outfile
)
2505 fprintf (outfile
, "%*s", print_indent
, "");
2508 /* Print the information assoaciated with a given DIE, and its children.
2509 This routine is a debugging aid only. */
2511 print_die (die
, outfile
)
2515 register dw_attr_ref a
;
2516 register dw_die_ref c
;
2517 print_spaces (outfile
);
2518 fprintf (outfile
, "DIE %4u: %s\n",
2519 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
2520 print_spaces (outfile
);
2521 fprintf (outfile
, " abbrev id: %u", die
->die_abbrev
);
2522 fprintf (outfile
, " offset: %u\n", die
->die_offset
);
2523 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2525 print_spaces (outfile
);
2526 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
2527 switch (a
->dw_attr_val
.val_class
)
2529 case dw_val_class_addr
:
2530 fprintf (outfile
, "address");
2532 case dw_val_class_loc
:
2533 fprintf (outfile
, "location descriptor");
2535 case dw_val_class_const
:
2536 fprintf (outfile
, "%d", a
->dw_attr_val
.v
.val_int
);
2538 case dw_val_class_unsigned_const
:
2539 fprintf (outfile
, "%u", a
->dw_attr_val
.v
.val_unsigned
);
2541 case dw_val_class_long_long
:
2542 fprintf (outfile
, "constant (%u,%u)",
2543 a
->dw_attr_val
.v
.val_long_long
.hi
,
2544 a
->dw_attr_val
.v
.val_long_long
.low
);
2546 case dw_val_class_float
:
2547 fprintf (outfile
, "floating-point constant");
2549 case dw_val_class_flag
:
2550 fprintf (outfile
, "%u", a
->dw_attr_val
.v
.val_flag
);
2552 case dw_val_class_die_ref
:
2553 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
2555 fprintf (outfile
, "die -> %u",
2556 a
->dw_attr_val
.v
.val_die_ref
->die_offset
);
2560 fprintf (outfile
, "die -> <null>");
2563 case dw_val_class_lbl_id
:
2564 fprintf (outfile
, "label: %s", a
->dw_attr_val
.v
.val_lbl_id
);
2566 case dw_val_class_section_offset
:
2567 fprintf (outfile
, "section: %s", a
->dw_attr_val
.v
.val_section
);
2569 case dw_val_class_str
:
2570 if (a
->dw_attr_val
.v
.val_str
!= NULL
)
2572 fprintf (outfile
, "\"%s\"", a
->dw_attr_val
.v
.val_str
);
2576 fprintf (outfile
, "<null>");
2580 fprintf (outfile
, "\n");
2582 if (die
->die_child
!= NULL
)
2585 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2587 print_die (c
, outfile
);
2593 /* Print the contents of the source code line number correspondence table.
2594 This routine is a debugging aid only. */
2596 print_dwarf_line_table (outfile
)
2599 register unsigned i
;
2600 register dw_line_info_ref line_info
;
2601 fprintf (outfile
, "\n\nDWARF source line information\n");
2602 for (i
= 1; i
< line_info_table_in_use
; ++i
)
2604 line_info
= &line_info_table
[i
];
2605 fprintf (outfile
, "%5d: ", i
);
2606 fprintf (outfile
, "%-20s", file_table
[line_info
->dw_file_num
]);
2607 fprintf (outfile
, "%6d", line_info
->dw_line_num
);
2608 fprintf (outfile
, "\n");
2610 fprintf (outfile
, "\n\n");
2613 /* Print the information collected for a given DIE. */
2615 debug_dwarf_die (die
)
2618 print_die (die
, stderr
);
2621 /* Print all DWARF informaiton collected for the compilation unit.
2622 This routine is a debugging aid only. */
2627 print_die (comp_unit_die
, stderr
);
2628 print_dwarf_line_table (stderr
);
2632 /***************** DWARF Information Construction Support *********************/
2634 /* Traverse the DIE, and add a sibling attribute if it may have the
2635 effect of speeding up access to siblings. To save some space,
2636 avoid generating sibling attributes for DIE's without children. */
2638 add_sibling_attributes(die
)
2639 register dw_die_ref die
;
2641 register dw_die_ref c
;
2642 register dw_attr_ref attr
;
2643 if (die
!= comp_unit_die
&& die
->die_child
!= NULL
)
2645 attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2648 attr
->dw_attr_next
= NULL
;
2649 attr
->dw_attr
= DW_AT_sibling
;
2650 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
2651 attr
->dw_attr_val
.v
.val_die_ref
= die
->die_sib
;
2653 /* add the sibling link to the front of the attribute list. */
2654 attr
->dw_attr_next
= die
->die_attr
;
2655 if (die
->die_attr
== NULL
)
2657 die
->die_attr_last
= attr
;
2659 die
->die_attr
= attr
;
2661 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2663 add_sibling_attributes (c
);
2667 /* The format of each DIE (and its attribute value pairs)
2668 is encoded in an abbreviation table. This routine builds the
2669 abbreviation table and assigns a unique abbreviation id for
2670 each abbreviation entry. The children of each die are visited
2673 build_abbrev_table (die
)
2674 register dw_die_ref die
;
2676 register unsigned long abbrev_id
;
2677 register unsigned long n_alloc
;
2678 register dw_die_ref c
;
2679 register dw_attr_ref d_attr
, a_attr
;
2680 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
2682 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
2683 if (abbrev
->die_tag
== die
->die_tag
)
2685 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
2687 a_attr
= abbrev
->die_attr
;
2688 d_attr
= die
->die_attr
;
2689 while (a_attr
!= NULL
&& d_attr
!= NULL
)
2691 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
2692 || (value_format (&a_attr
->dw_attr_val
)
2693 != value_format (&d_attr
->dw_attr_val
)))
2697 a_attr
= a_attr
->dw_attr_next
;
2698 d_attr
= d_attr
->dw_attr_next
;
2700 if (a_attr
== NULL
&& d_attr
== NULL
)
2707 if (abbrev_id
>= abbrev_die_table_in_use
)
2709 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
2711 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
2712 abbrev_die_table
= (dw_die_ref
*)
2713 xmalloc (abbrev_die_table
,
2714 sizeof (dw_die_ref
) * n_alloc
);
2715 bzero (&abbrev_die_table
[abbrev_die_table_allocated
],
2716 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
2717 abbrev_die_table_allocated
= n_alloc
;
2719 ++abbrev_die_table_in_use
;
2720 abbrev_die_table
[abbrev_id
] = die
;
2722 die
->die_abbrev
= abbrev_id
;
2723 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2725 build_abbrev_table (c
);
2730 /********************** DWARF Information Sizing *****************************/
2732 /* Return the size of an unsigned LEB128 quantity. */
2733 inline unsigned long
2734 size_of_uleb128 (value
)
2735 register unsigned long value
;
2737 register unsigned long size
= 0;
2738 register unsigned byte
;
2741 byte
= (value
& 0x7f);
2749 /* Return the size of a signed LEB128 quantity. */
2750 inline unsigned long
2751 size_of_sleb128 (value
)
2752 register long value
;
2754 register unsigned long size
= 0;
2755 register unsigned byte
;
2758 byte
= (value
& 0x7f);
2762 while (!(((value
== 0) && ((byte
& 0x40) == 0))
2763 || ((value
== -1) && ((byte
& 0x40) != 0))));
2767 /* Return the size of a string, including the null byte. */
2768 static unsigned long
2769 size_of_string (str
)
2772 register unsigned long size
= 0;
2773 register unsigned long slen
= strlen (str
);
2774 register unsigned long i
;
2775 register unsigned c
;
2776 for (i
= 0; i
< slen
; ++i
)
2785 /* Null terminator. */
2790 /* Return the size of a location descriptor. */
2791 static unsigned long
2792 size_of_loc_descr (loc
)
2793 register dw_loc_descr_ref loc
;
2795 register unsigned long size
= 1;
2796 switch (loc
->dw_loc_opc
)
2818 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2821 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2826 case DW_OP_plus_uconst
:
2827 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2865 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2868 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2871 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2874 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2875 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2878 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2880 case DW_OP_deref_size
:
2881 case DW_OP_xderef_size
:
2890 /* Return the size of a series of location descriptors. */
2891 static unsigned long
2893 register dw_loc_descr_ref loc
;
2895 register unsigned long size
= 0;
2896 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2897 size
+= size_of_loc_descr (loc
);
2901 /* Return the power-of-two number of bytes necessary to represent VALUE. */
2903 constant_size (value
)
2904 long unsigned value
;
2911 log
= floor_log2 (value
);
2914 log
= 1 << (floor_log2 (log
) + 1);
2919 /* Return the size of a DIE, as it is represented in the
2920 .debug_info section. */
2921 static unsigned long
2923 register dw_die_ref die
;
2925 register unsigned long size
= 0;
2926 register dw_attr_ref a
;
2927 size
+= size_of_uleb128 (die
->die_abbrev
);
2928 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2930 switch (a
->dw_attr_val
.val_class
)
2932 case dw_val_class_addr
:
2935 case dw_val_class_loc
:
2937 register unsigned long lsize
2938 = size_of_locs (a
->dw_attr_val
.v
.val_loc
);
2941 size
+= constant_size (lsize
);
2945 case dw_val_class_const
:
2948 case dw_val_class_unsigned_const
:
2949 size
+= constant_size (a
->dw_attr_val
.v
.val_unsigned
);
2951 case dw_val_class_long_long
:
2952 size
+= 1 + 8; /* block */
2954 case dw_val_class_float
:
2955 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
2957 case dw_val_class_flag
:
2960 case dw_val_class_die_ref
:
2961 size
+= DWARF_OFFSET_SIZE
;
2963 case dw_val_class_fde_ref
:
2964 size
+= DWARF_OFFSET_SIZE
;
2966 case dw_val_class_lbl_id
:
2969 case dw_val_class_section_offset
:
2970 size
+= DWARF_OFFSET_SIZE
;
2972 case dw_val_class_str
:
2973 size
+= size_of_string (a
->dw_attr_val
.v
.val_str
);
2982 /* Size the debgging information associted with a given DIE.
2983 Visits the DIE's children recursively. Updates the global
2984 variable next_die_offset, on each time through. Uses the
2985 current value of next_die_offset to updete the die_offset
2986 field in each DIE. */
2988 calc_die_sizes (die
)
2991 register dw_die_ref c
;
2992 die
->die_offset
= next_die_offset
;
2993 next_die_offset
+= size_of_die (die
);
2994 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2998 if (die
->die_child
!= NULL
)
3000 /* Count the null byte used to terminate sibling lists. */
3001 next_die_offset
+= 1;
3005 /* Return the size of the line information prolog generated for the
3006 compilation unit. */
3007 static unsigned long
3008 size_of_line_prolog ()
3010 register unsigned long size
;
3011 register unsigned long ft_index
;
3012 size
= DWARF_LINE_PROLOG_HEADER_SIZE
;
3013 /* Count the size of the table giving number of args for each
3015 size
+= DWARF_LINE_OPCODE_BASE
- 1;
3016 /* Include directory table is empty (at present). Count only the
3017 the null byte used to terminate the table. */
3019 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
3021 /* File name entry. */
3022 size
+= size_of_string (file_table
[ft_index
]);
3023 /* Include directory index. */
3024 size
+= size_of_uleb128 (0);
3025 /* Modification time. */
3026 size
+= size_of_uleb128 (0);
3027 /* File length in bytes. */
3028 size
+= size_of_uleb128 (0);
3030 /* Count the file table terminator. */
3035 /* Return the size of the line information generated for this
3036 compilation unit. */
3037 static unsigned long
3038 size_of_line_info ()
3040 register unsigned long size
;
3041 register unsigned long lt_index
;
3042 register unsigned long current_line
;
3043 register long line_offset
;
3044 register long line_delta
;
3045 register unsigned long current_file
;
3046 register unsigned long function
;
3047 /* Version number. */
3049 /* Prolog length specifier. */
3050 size
+= DWARF_OFFSET_SIZE
;
3052 size
+= size_of_line_prolog ();
3053 /* Set address register instruction. */
3054 size
+= 1 + size_of_uleb128 (1 + PTR_SIZE
)
3058 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
3060 register dw_line_info_ref line_info
;
3061 /* Advance pc instruction. */
3063 line_info
= &line_info_table
[lt_index
];
3064 if (line_info
->dw_file_num
!= current_file
)
3066 /* Set file number instruction. */
3068 current_file
= line_info
->dw_file_num
;
3069 size
+= size_of_uleb128 (current_file
);
3071 if (line_info
->dw_line_num
!= current_line
)
3073 line_offset
= line_info
->dw_line_num
- current_line
;
3074 line_delta
= line_offset
- DWARF_LINE_BASE
;
3075 current_line
= line_info
->dw_line_num
;
3076 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
3078 /* 1-byte special line number instruction. */
3083 /* Advance line instruction. */
3085 size
+= size_of_sleb128 (line_offset
);
3086 /* Generate line entry instruction. */
3091 /* Advance pc instruction. */
3093 /* End of line number info. marker. */
3094 size
+= 1 + size_of_uleb128 (1) + 1;
3098 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
3100 register dw_separate_line_info_ref line_info
3101 = &separate_line_info_table
[lt_index
];
3102 if (function
!= line_info
->function
)
3104 function
= line_info
->function
;
3105 /* Set address register instruction. */
3106 size
+= 1 + size_of_uleb128 (1 + PTR_SIZE
)
3111 /* Advance pc instruction. */
3114 if (line_info
->dw_file_num
!= current_file
)
3116 /* Set file number instruction. */
3118 current_file
= line_info
->dw_file_num
;
3119 size
+= size_of_uleb128 (current_file
);
3121 if (line_info
->dw_line_num
!= current_line
)
3123 line_offset
= line_info
->dw_line_num
- current_line
;
3124 line_delta
= line_offset
- DWARF_LINE_BASE
;
3125 current_line
= line_info
->dw_line_num
;
3126 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
3128 /* 1-byte special line number instruction. */
3133 /* Advance line instruction. */
3135 size
+= size_of_sleb128 (line_offset
);
3136 /* Generate line entry instruction. */
3142 /* If we're done with a function, end its sequence. */
3143 if (lt_index
== separate_line_info_table_in_use
3144 || separate_line_info_table
[lt_index
].function
!= function
)
3148 /* Advance pc instruction. */
3150 /* End of line number info. marker. */
3151 size
+= 1 + size_of_uleb128 (1) + 1;
3157 /* Return the size of the .debug_pubnames table generated for the
3158 compilation unit. */
3159 static unsigned long
3162 register unsigned long size
;
3163 register unsigned i
;
3165 size
= DWARF_PUBNAMES_HEADER_SIZE
;
3166 for (i
= 0; i
< pubname_table_in_use
; ++i
)
3168 register pubname_ref p
= &pubname_table
[i
];
3169 size
+= DWARF_OFFSET_SIZE
+ size_of_string (p
->name
);
3171 size
+= DWARF_OFFSET_SIZE
;
3175 /* Return the size of the information in the .debug_aranges seciton. */
3176 static unsigned long
3179 register unsigned long size
;
3180 size
= DWARF_ARANGES_HEADER_SIZE
;
3181 /* Count the address/length pair for this compilation unit. */
3182 size
+= 2 * PTR_SIZE
;
3183 size
+= 2 * PTR_SIZE
* arange_table_in_use
;
3184 /* Count the two zero words used to terminated the address range table. */
3185 size
+= 2 * PTR_SIZE
;
3189 /**************** DWARF Debug Information Output *****************************/
3191 /* Output an unsigned LEB128 quantity. */
3193 output_uleb128 (value
)
3194 register unsigned long value
;
3196 unsigned long save_value
= value
;
3197 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
3200 register unsigned byte
= (value
& 0x7f);
3204 /* More bytes to follow. */
3207 fprintf (asm_out_file
, "0x%x", byte
);
3210 fprintf (asm_out_file
, ",");
3214 if (flag_verbose_asm
)
3215 fprintf (asm_out_file
, "\t%s ULEB128 0x%x", ASM_COMMENT_START
, save_value
);
3218 /* Output an signed LEB128 quantity. */
3220 output_sleb128 (value
)
3221 register long value
;
3224 register unsigned byte
;
3225 long save_value
= value
;
3226 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
3229 byte
= (value
& 0x7f);
3230 /* arithmetic shift */
3232 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
3233 || ((value
== -1) && ((byte
& 0x40) != 0))));
3238 fprintf (asm_out_file
, "0x%x", byte
);
3241 fprintf (asm_out_file
, ",");
3245 if (flag_verbose_asm
)
3246 fprintf (asm_out_file
, "\t%s SLEB128 %d", ASM_COMMENT_START
, save_value
);
3249 /* Select the encoding of an attribute value. */
3250 static enum dwarf_form
3254 switch (v
->val_class
)
3256 case dw_val_class_addr
:
3257 return DW_FORM_addr
;
3258 case dw_val_class_loc
:
3259 switch (constant_size (size_of_locs (v
->v
.val_loc
)))
3262 return DW_FORM_block1
;
3264 return DW_FORM_block2
;
3268 case dw_val_class_const
:
3269 return DW_FORM_data4
;
3270 case dw_val_class_unsigned_const
:
3271 switch (constant_size (v
->v
.val_unsigned
))
3274 return DW_FORM_data1
;
3276 return DW_FORM_data2
;
3278 return DW_FORM_data4
;
3282 case dw_val_class_long_long
:
3283 return DW_FORM_block1
;
3284 case dw_val_class_float
:
3285 return DW_FORM_block1
;
3286 case dw_val_class_flag
:
3287 return DW_FORM_flag
;
3288 case dw_val_class_die_ref
:
3290 case dw_val_class_fde_ref
:
3291 return DW_FORM_data
;
3292 case dw_val_class_lbl_id
:
3293 return DW_FORM_addr
;
3294 case dw_val_class_section_offset
:
3295 return DW_FORM_data
;
3296 case dw_val_class_str
:
3297 return DW_FORM_string
;
3303 /* Output the encoding of an attribute value. */
3305 output_value_format (v
)
3308 enum dwarf_form form
= value_format (v
);
3309 output_uleb128 (form
);
3310 if (flag_verbose_asm
)
3311 fprintf (asm_out_file
, " (%s)", dwarf_form_name (form
));
3312 fputc ('\n', asm_out_file
);
3315 /* Output the .debug_abbrev section which defines the DIE abbreviation
3318 output_abbrev_section ()
3320 unsigned long abbrev_id
;
3322 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
3324 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
3325 output_uleb128 (abbrev_id
);
3326 if (flag_verbose_asm
)
3327 fprintf (asm_out_file
, " (abbrev code)");
3328 fputc ('\n', asm_out_file
);
3329 output_uleb128 (abbrev
->die_tag
);
3330 if (flag_verbose_asm
)
3331 fprintf (asm_out_file
, " (TAG: %s)",
3332 dwarf_tag_name (abbrev
->die_tag
));
3333 fputc ('\n', asm_out_file
);
3334 fprintf (asm_out_file
, "\t%s\t0x%x", ASM_BYTE_OP
,
3335 (abbrev
->die_child
!= NULL
)
3336 ? DW_children_yes
: DW_children_no
);
3337 if (flag_verbose_asm
)
3339 fprintf (asm_out_file
, "\t%s %s",
3341 (abbrev
->die_child
!= NULL
)
3342 ? "DW_children_yes" : "DW_children_no");
3344 fputc ('\n', asm_out_file
);
3345 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
3346 a_attr
= a_attr
->dw_attr_next
)
3348 output_uleb128 (a_attr
->dw_attr
);
3349 if (flag_verbose_asm
)
3350 fprintf (asm_out_file
, " (%s)",
3351 dwarf_attr_name (a_attr
->dw_attr
));
3352 fputc ('\n', asm_out_file
);
3353 output_value_format (&a_attr
->dw_attr_val
);
3355 fprintf (asm_out_file
, "\t%s\t0,0\n", ASM_BYTE_OP
);
3359 /* Output location description stack opcode's operands (if any). */
3361 output_loc_operands (loc
)
3362 register dw_loc_descr_ref loc
;
3364 register dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3365 register dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3366 switch (loc
->dw_loc_opc
)
3369 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, val1
->v
.val_addr
);
3370 fputc ('\n', asm_out_file
);
3374 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
3375 fputc ('\n', asm_out_file
);
3379 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
3380 fputc ('\n', asm_out_file
);
3384 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, val1
->v
.val_int
);
3385 fputc ('\n', asm_out_file
);
3390 fputc ('\n', asm_out_file
);
3393 output_uleb128 (val1
->v
.val_unsigned
);
3394 fputc ('\n', asm_out_file
);
3397 output_sleb128 (val1
->v
.val_int
);
3398 fputc ('\n', asm_out_file
);
3401 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_int
);
3402 fputc ('\n', asm_out_file
);
3404 case DW_OP_plus_uconst
:
3405 output_uleb128 (val1
->v
.val_unsigned
);
3406 fputc ('\n', asm_out_file
);
3410 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
3411 fputc ('\n', asm_out_file
);
3445 output_sleb128 (val1
->v
.val_int
);
3446 fputc ('\n', asm_out_file
);
3449 output_uleb128 (val1
->v
.val_unsigned
);
3450 fputc ('\n', asm_out_file
);
3453 output_sleb128 (val1
->v
.val_int
);
3454 fputc ('\n', asm_out_file
);
3457 output_uleb128 (val1
->v
.val_unsigned
);
3458 fputc ('\n', asm_out_file
);
3459 output_sleb128 (val2
->v
.val_int
);
3460 fputc ('\n', asm_out_file
);
3463 output_uleb128 (val1
->v
.val_unsigned
);
3464 fputc ('\n', asm_out_file
);
3466 case DW_OP_deref_size
:
3467 case DW_OP_xderef_size
:
3468 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
3469 fputc ('\n', asm_out_file
);
3476 /* Compute the offset of a sibling. */
3477 static unsigned long
3478 sibling_offset (die
)
3481 unsigned long offset
;
3482 if (die
->die_child_last
== NULL
)
3484 offset
= die
->die_offset
+ size_of_die (die
);
3488 offset
= sibling_offset (die
->die_child_last
) + 1;
3493 /* Output the DIE and its attributes. Called recursively to generate
3494 the definitions of each child DIE. */
3497 register dw_die_ref die
;
3499 register dw_attr_ref a
;
3500 register dw_die_ref c
;
3501 register unsigned long ref_offset
;
3502 register unsigned long size
;
3503 register dw_loc_descr_ref loc
;
3506 output_uleb128 (die
->die_abbrev
);
3507 if (flag_verbose_asm
)
3508 fprintf (asm_out_file
, " (DIE (0x%x) %s)",
3509 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
3510 fputc ('\n', asm_out_file
);
3511 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3513 switch (a
->dw_attr_val
.val_class
)
3515 case dw_val_class_addr
:
3516 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
,
3517 a
->dw_attr_val
.v
.val_addr
);
3519 case dw_val_class_loc
:
3520 size
= size_of_locs (a
->dw_attr_val
.v
.val_loc
);
3521 /* Output the block length for this list of location operations. */
3522 switch (constant_size (size
))
3525 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, size
);
3528 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, size
);
3533 if (flag_verbose_asm
)
3535 fprintf (asm_out_file
, "\t%s %s",
3536 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
3538 fputc ('\n', asm_out_file
);
3539 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
;
3540 loc
= loc
->dw_loc_next
)
3542 /* Output the opcode. */
3543 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, loc
->dw_loc_opc
);
3544 if (flag_verbose_asm
)
3546 fprintf (asm_out_file
, "\t%s %s",
3548 dwarf_stack_op_name (loc
->dw_loc_opc
));
3550 fputc ('\n', asm_out_file
);
3551 /* Output the operand(s) (if any). */
3552 output_loc_operands (loc
);
3555 case dw_val_class_const
:
3556 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, a
->dw_attr_val
.v
.val_int
);
3558 case dw_val_class_unsigned_const
:
3559 switch (constant_size (a
->dw_attr_val
.v
.val_unsigned
))
3562 ASM_OUTPUT_DWARF_DATA1
3563 (asm_out_file
, a
->dw_attr_val
.v
.val_unsigned
);
3566 ASM_OUTPUT_DWARF_DATA2
3567 (asm_out_file
, a
->dw_attr_val
.v
.val_unsigned
);
3570 ASM_OUTPUT_DWARF_DATA4
3571 (asm_out_file
, a
->dw_attr_val
.v
.val_unsigned
);
3577 case dw_val_class_long_long
:
3578 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 8);
3579 if (flag_verbose_asm
)
3580 fprintf (asm_out_file
, "\t%s %s",
3581 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
3582 fputc ('\n', asm_out_file
);
3583 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
3584 a
->dw_attr_val
.v
.val_long_long
.hi
,
3585 a
->dw_attr_val
.v
.val_long_long
.low
);
3586 if (flag_verbose_asm
)
3587 fprintf (asm_out_file
, "\t%s long long constant",
3589 fputc ('\n', asm_out_file
);
3591 case dw_val_class_float
:
3592 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
3593 a
->dw_attr_val
.v
.val_float
.length
* 4);
3594 if (flag_verbose_asm
)
3595 fprintf (asm_out_file
, "\t%s %s",
3596 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
3597 fputc ('\n', asm_out_file
);
3598 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; ++i
)
3600 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
,
3601 a
->dw_attr_val
.v
.val_float
.array
[i
]);
3602 if (flag_verbose_asm
)
3603 fprintf (asm_out_file
, "\t%s fp constant word %d",
3604 ASM_COMMENT_START
, i
);
3605 fputc ('\n', asm_out_file
);
3608 case dw_val_class_flag
:
3609 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, a
->dw_attr_val
.v
.val_flag
);
3611 case dw_val_class_die_ref
:
3612 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
3614 ref_offset
= a
->dw_attr_val
.v
.val_die_ref
->die_offset
;
3616 else if (a
->dw_attr
== DW_AT_sibling
)
3618 ref_offset
= sibling_offset(die
);
3624 ASM_OUTPUT_DWARF_DATA (asm_out_file
, ref_offset
);
3626 case dw_val_class_fde_ref
:
3627 ref_offset
= fde_table
[a
->dw_attr_val
.v
.val_fde_index
].dw_fde_offset
;
3628 fprintf (asm_out_file
, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP
,
3629 stripattributes (FRAME_SECTION
), ref_offset
);
3631 case dw_val_class_lbl_id
:
3632 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, a
->dw_attr_val
.v
.val_lbl_id
);
3634 case dw_val_class_section_offset
:
3635 ASM_OUTPUT_DWARF_OFFSET
3636 (asm_out_file
, stripattributes (a
->dw_attr_val
.v
.val_section
));
3638 case dw_val_class_str
:
3639 ASM_OUTPUT_DWARF_STRING (asm_out_file
, a
->dw_attr_val
.v
.val_str
);
3644 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
3645 && a
->dw_attr_val
.val_class
!= dw_val_class_long_long
3646 && a
->dw_attr_val
.val_class
!= dw_val_class_float
)
3648 if (flag_verbose_asm
)
3650 fprintf (asm_out_file
, "\t%s %s",
3651 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
3653 fputc ('\n', asm_out_file
);
3656 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
3660 if (die
->die_child
!= NULL
)
3662 /* Add null byte to terminate sibling list. */
3663 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
3664 if (flag_verbose_asm
)
3665 fprintf (asm_out_file
, "\t%s end of children of DIE 0x%x",
3666 ASM_COMMENT_START
, die
->die_offset
);
3667 fputc ('\n', asm_out_file
);
3671 /* Output the compilation unit that appears at the beginning of the
3672 .debug_info section, and precedes the DIE descriptions. */
3674 output_compilation_unit_header ()
3676 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
- DWARF_OFFSET_SIZE
);
3677 if (flag_verbose_asm
)
3679 fprintf (asm_out_file
, "\t%s Length of Compilation Unit Info.",
3682 fputc ('\n', asm_out_file
);
3683 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
3684 if (flag_verbose_asm
)
3686 fprintf (asm_out_file
, "\t%s DWARF version number",
3689 fputc ('\n', asm_out_file
);
3690 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (ABBREV_SECTION
));
3691 if (flag_verbose_asm
)
3693 fprintf (asm_out_file
, "\t%s Offset Into Abbrev. Section",
3696 fputc ('\n', asm_out_file
);
3697 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
3698 if (flag_verbose_asm
)
3700 fprintf (asm_out_file
, "\t%s Pointer Size (in bytes)",
3703 fputc ('\n', asm_out_file
);
3706 /* Generate a new label for the CFI info to refer to. */
3709 dwarf2out_cfi_label ()
3711 static char label
[20];
3712 static unsigned long label_num
= 0;
3714 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
3715 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3720 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
3721 or to the CIE if LABEL is NULL. */
3724 add_fde_cfi (label
, cfi
)
3725 register char * label
;
3726 register dw_cfi_ref cfi
;
3730 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
3732 label
= dwarf2out_cfi_label ();
3733 if (fde
->dw_fde_current_label
== NULL
3734 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
3736 register dw_cfi_ref xcfi
;
3738 fde
->dw_fde_current_label
= label
= xstrdup (label
);
3740 /* Set the location counter to the new label. */
3742 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
3743 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
3744 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
3746 add_cfi (&fde
->dw_fde_cfi
, cfi
);
3749 add_cfi (&cie_cfi_head
, cfi
);
3752 /* Subroutine of lookup_cfa. */
3754 lookup_cfa_1 (cfi
, regp
, offsetp
)
3755 register dw_cfi_ref cfi
;
3756 register unsigned long *regp
;
3757 register long *offsetp
;
3759 switch (cfi
->dw_cfi_opc
)
3761 case DW_CFA_def_cfa_offset
:
3762 *offsetp
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
3764 case DW_CFA_def_cfa_register
:
3765 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
3767 case DW_CFA_def_cfa
:
3768 *regp
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
3769 *offsetp
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
3774 /* Find the previous value for the CFA. */
3776 lookup_cfa (regp
, offsetp
)
3777 register unsigned long *regp
;
3778 register long *offsetp
;
3780 register dw_cfi_ref cfi
;
3781 *regp
= (unsigned long) -1;
3784 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
3785 lookup_cfa_1 (cfi
, regp
, offsetp
);
3786 if (fde_table_in_use
)
3788 register dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
3789 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
3790 lookup_cfa_1 (cfi
, regp
, offsetp
);
3794 /* Entry point to update the canonical frame address (CFA).
3795 LABEL is passed to add_fde_cfi. The value of CFA is now to be
3796 calculated from REG+OFFSET. */
3799 dwarf2out_def_cfa (label
, reg
, offset
)
3800 register char * label
;
3801 register unsigned reg
;
3802 register long offset
;
3804 register dw_cfi_ref cfi
;
3808 reg
= DWARF_FRAME_REGNUM (reg
);
3809 lookup_cfa (&old_reg
, &old_offset
);
3811 if (reg
== old_reg
&& offset
== old_offset
)
3818 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
3819 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= offset
;
3821 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
3822 else if (offset
== old_offset
&& old_reg
!= (unsigned long) -1)
3824 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
3825 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
3830 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
3831 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
3832 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
3835 add_fde_cfi (label
, cfi
);
3838 /* Add the CFI for saving a register. REG is the CFA column number.
3839 LABEL is passed to add_fde_cfi.
3840 If SREG is -1, the register is saved at OFFSET from the CFA;
3841 otherwise it is saved in SREG. */
3844 reg_save (label
, reg
, sreg
, offset
)
3845 register char * label
;
3846 register unsigned reg
;
3847 register unsigned sreg
;
3848 register long offset
;
3850 register dw_cfi_ref cfi
= new_cfi ();
3852 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
3857 /* The register number won't fit in 6 bits, so we have to use
3859 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
3861 cfi
->dw_cfi_opc
= DW_CFA_offset
;
3863 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
3864 assert (offset
>= 0);
3865 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
3869 cfi
->dw_cfi_opc
= DW_CFA_register
;
3870 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
3873 add_fde_cfi (label
, cfi
);
3876 /* Entry point for saving a register. REG is the GCC register number.
3877 LABEL and OFFSET are passed to reg_save. */
3880 dwarf2out_reg_save (label
, reg
, offset
)
3881 register char * label
;
3882 register unsigned reg
;
3883 register long offset
;
3885 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
3888 /* Record the initial position of the return address. RTL is
3889 INCOMING_RETURN_ADDR_RTX. */
3892 initial_return_save (rtl
)
3898 switch (GET_CODE (rtl
))
3901 /* RA is in a register. */
3902 reg
= reg_number (rtl
);
3905 /* RA is on the stack. */
3906 rtl
= XEXP (rtl
, 0);
3907 switch (GET_CODE (rtl
))
3910 assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
3914 assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
3915 offset
= INTVAL (XEXP (rtl
, 1));
3918 assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
3919 offset
= -INTVAL (XEXP (rtl
, 1));
3929 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
);
3932 /* Record call frame debugging information for INSN, which either
3933 sets SP or FP (adjusting how we calculate the frame address) or saves a
3934 register to the stack. If INSN is NULL_RTX, initialize our state. */
3937 dwarf2out_frame_debug (insn
)
3944 /* The current rule for calculating the DWARF2 canonical frame address. */
3945 static unsigned cfa_reg
;
3946 static long cfa_offset
;
3948 /* The register used for saving registers to the stack, and its offset
3950 static unsigned cfa_store_reg
;
3951 static long cfa_store_offset
;
3953 /* A temporary register used in adjusting SP or setting up the store_reg. */
3954 static unsigned cfa_temp_reg
;
3955 static long cfa_temp_value
;
3957 if (insn
== NULL_RTX
)
3959 /* Set up state for generating call frame debug info. */
3960 cfa_reg
= STACK_POINTER_REGNUM
;
3962 cfa_store_reg
= STACK_POINTER_REGNUM
;
3963 cfa_store_offset
= 0;
3969 label
= dwarf2out_cfi_label ();
3971 insn
= PATTERN (insn
);
3972 assert (GET_CODE (insn
) == SET
);
3974 src
= SET_SRC (insn
);
3975 dest
= SET_DEST (insn
);
3977 switch (GET_CODE (dest
))
3980 /* Update the CFA rule wrt SP or FP. Make sure src is
3981 relative to the current CFA register. */
3982 switch (GET_CODE (src
))
3984 /* Setting FP from SP. */
3986 assert (cfa_reg
== REGNO (src
));
3987 assert (REGNO (dest
) == STACK_POINTER_REGNUM
3988 || frame_pointer_needed
&& REGNO (dest
) == FRAME_POINTER_REGNUM
);
3989 cfa_reg
= REGNO (dest
);
3994 if (dest
== stack_pointer_rtx
)
3997 switch (GET_CODE (XEXP (src
, 1)))
4000 offset
= INTVAL (XEXP (src
, 1));
4003 assert (REGNO (XEXP (src
, 1)) == cfa_temp_reg
);
4004 offset
= cfa_temp_value
;
4009 if (GET_CODE (src
) == PLUS
)
4011 if (cfa_reg
== STACK_POINTER_REGNUM
)
4012 cfa_offset
+= offset
;
4013 if (cfa_store_reg
== STACK_POINTER_REGNUM
)
4014 cfa_store_offset
+= offset
;
4015 assert (XEXP (src
, 0) == stack_pointer_rtx
);
4019 /* Initializing the store base register. */
4020 assert (GET_CODE (src
) == PLUS
);
4021 assert (XEXP (src
, 1) == stack_pointer_rtx
);
4022 assert (GET_CODE (XEXP (src
, 0)) == REG
4023 && REGNO (XEXP (src
, 0)) == cfa_temp_reg
);
4024 assert (cfa_store_reg
== STACK_POINTER_REGNUM
);
4025 cfa_store_reg
= REGNO (dest
);
4026 cfa_store_offset
-= cfa_temp_value
;
4031 cfa_temp_reg
= REGNO (dest
);
4032 cfa_temp_value
= INTVAL (src
);
4038 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
4042 /* Saving a register to the stack. Make sure dest is relative to the
4044 assert (GET_CODE (src
) == REG
);
4045 switch (GET_CODE (XEXP (dest
, 0)))
4050 offset
= GET_MODE_SIZE (GET_MODE (dest
));
4051 if (GET_CODE (src
) == PRE_INC
)
4053 assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
);
4054 assert (cfa_store_reg
== STACK_POINTER_REGNUM
);
4055 cfa_store_offset
+= offset
;
4056 if (cfa_reg
== STACK_POINTER_REGNUM
)
4057 cfa_offset
= cfa_store_offset
;
4058 offset
= -cfa_store_offset
;
4061 /* With an offset. */
4064 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
4065 if (GET_CODE (src
) == MINUS
)
4067 assert (cfa_store_reg
== REGNO (XEXP (XEXP (dest
, 0), 0)));
4068 offset
-= cfa_store_offset
;
4074 dwarf2out_def_cfa (label
, cfa_reg
, cfa_offset
);
4075 dwarf2out_reg_save (label
, REGNO (src
), offset
);
4083 /* Return the size of a Call Frame Instruction. */
4084 static unsigned long
4088 register unsigned long size
;
4089 /* count the 1-byte opcode */
4091 switch (cfi
->dw_cfi_opc
)
4094 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
4096 case DW_CFA_set_loc
:
4099 case DW_CFA_advance_loc1
:
4102 case DW_CFA_advance_loc2
:
4105 case DW_CFA_advance_loc4
:
4108 #ifdef MIPS_DEBUGGING_INFO
4109 case DW_CFA_MIPS_advance_loc8
:
4113 case DW_CFA_offset_extended
:
4114 case DW_CFA_def_cfa
:
4115 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4116 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
4118 case DW_CFA_restore_extended
:
4119 case DW_CFA_undefined
:
4120 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4122 case DW_CFA_same_value
:
4123 case DW_CFA_def_cfa_register
:
4124 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4126 case DW_CFA_register
:
4127 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4128 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
4130 case DW_CFA_def_cfa_offset
:
4131 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
4139 /* Return the size of an FDE sans the length word. */
4140 inline unsigned long
4141 size_of_fde (fde
, npad
)
4143 unsigned long *npad
;
4145 register dw_cfi_ref cfi
;
4146 register unsigned long aligned_size
;
4147 register unsigned long size
;
4148 size
= DWARF_FDE_HEADER_SIZE
;
4149 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
4151 size
+= size_of_cfi(cfi
);
4153 /* Round the size up to a word boundary. */
4154 aligned_size
= DWARF_ROUND (size
, PTR_SIZE
);
4155 *npad
= aligned_size
- size
;
4156 return aligned_size
;
4159 /* Calculate the size of the FDE table, and establish the offset
4160 of each FDE in the .debug_frame section. */
4164 register unsigned long i
;
4165 register dw_fde_ref fde
;
4166 register unsigned long fde_size
;
4167 register dw_cfi_ref cfi
;
4168 unsigned long fde_pad
;
4170 cie_size
= DWARF_CIE_HEADER_SIZE
;
4171 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
4172 cie_size
+= size_of_cfi (cfi
);
4174 /* Initialize the beginning FDE offset. */
4175 next_fde_offset
= DWARF_ROUND (cie_size
, PTR_SIZE
);
4177 for (i
= 0; i
< fde_table_in_use
; ++i
)
4179 fde
= &fde_table
[i
];
4180 fde
->dw_fde_offset
= next_fde_offset
;
4181 fde_size
= size_of_fde (fde
, &fde_pad
);
4182 next_fde_offset
+= fde_size
;
4186 /* Output a Call Frame Information opcode and its operand(s). */
4188 output_cfi (cfi
, fde
)
4189 register dw_cfi_ref cfi
;
4190 register dw_fde_ref fde
;
4192 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
4194 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
4196 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f));
4197 if (flag_verbose_asm
)
4198 fprintf (asm_out_file
, "\t%s DW_CFA_advance_loc 0x%x",
4199 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
4200 fputc ('\n', asm_out_file
);
4202 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
4204 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
4206 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
4207 if (flag_verbose_asm
)
4208 fprintf (asm_out_file
, "\t%s DW_CFA_offset, column 0x%x",
4209 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4210 fputc ('\n', asm_out_file
);
4211 output_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
4212 fputc ('\n', asm_out_file
);
4214 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
4216 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
4218 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
4219 if (flag_verbose_asm
)
4220 fprintf (asm_out_file
, "\t%s DW_CFA_restore, column 0x%x",
4221 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4222 fputc ('\n', asm_out_file
);
4226 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, cfi
->dw_cfi_opc
);
4227 if (flag_verbose_asm
)
4229 fprintf (asm_out_file
, "\t%s %s",
4231 dwarf_cfi_name (cfi
->dw_cfi_opc
));
4233 fputc ('\n', asm_out_file
);
4234 switch (cfi
->dw_cfi_opc
)
4236 case DW_CFA_set_loc
:
4237 ASM_OUTPUT_DWARF_ADDR (asm_out_file
,
4238 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
);
4239 fputc ('\n', asm_out_file
);
4241 case DW_CFA_advance_loc1
:
4242 /* TODO: not currently implemented. */
4245 case DW_CFA_advance_loc2
:
4246 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
,
4247 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
4248 fde
->dw_fde_current_label
);
4249 fputc ('\n', asm_out_file
);
4250 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
4252 case DW_CFA_advance_loc4
:
4253 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
4254 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
4255 fde
->dw_fde_current_label
);
4256 fputc ('\n', asm_out_file
);
4257 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
4259 #ifdef MIPS_DEBUGGING_INFO
4260 case DW_CFA_MIPS_advance_loc8
:
4261 /* TODO: not currently implemented. */
4265 case DW_CFA_offset_extended
:
4266 case DW_CFA_def_cfa
:
4267 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4268 fputc ('\n', asm_out_file
);
4269 output_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
4270 fputc ('\n', asm_out_file
);
4272 case DW_CFA_restore_extended
:
4273 case DW_CFA_undefined
:
4274 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4275 fputc ('\n', asm_out_file
);
4277 case DW_CFA_same_value
:
4278 case DW_CFA_def_cfa_register
:
4279 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4280 fputc ('\n', asm_out_file
);
4282 case DW_CFA_register
:
4283 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
4284 fputc ('\n', asm_out_file
);
4285 output_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
4286 fputc ('\n', asm_out_file
);
4288 case DW_CFA_def_cfa_offset
:
4289 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
4290 fputc ('\n', asm_out_file
);
4298 /* Output the call frame information used to used to record information
4299 that relates to calculating the frame pointer, and records the
4300 location of saved registers. */
4302 output_call_frame_info ()
4304 register unsigned long i
, j
;
4305 register dw_fde_ref fde
;
4306 register unsigned long fde_size
;
4307 register dw_cfi_ref cfi
;
4308 unsigned long fde_pad
;
4310 /* Only output the info if it will be interesting. */
4311 for (i
= 0; i
< fde_table_in_use
; ++i
)
4312 if (fde_table
[i
].dw_fde_cfi
!= NULL
)
4314 if (i
== fde_table_in_use
)
4317 /* (re-)initialize the beginning FDE offset. */
4318 next_fde_offset
= DWARF_ROUND (cie_size
, PTR_SIZE
);
4320 fputc ('\n', asm_out_file
);
4321 ASM_OUTPUT_SECTION (asm_out_file
, FRAME_SECTION
);
4323 /* Output the CIE. */
4324 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_fde_offset
- DWARF_OFFSET_SIZE
);
4325 if (flag_verbose_asm
)
4327 fprintf (asm_out_file
, "\t%s Length of Common Information Entry",
4330 fputc ('\n', asm_out_file
);
4331 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
4332 if (flag_verbose_asm
)
4334 fprintf (asm_out_file
, "\t%s CIE Identifier Tag",
4337 fputc ('\n', asm_out_file
);
4338 if (DWARF_OFFSET_SIZE
== 8)
4340 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
4341 fputc ('\n', asm_out_file
);
4343 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CIE_VERSION
);
4344 if (flag_verbose_asm
)
4346 fprintf (asm_out_file
, "\t%s CIE Version",
4349 fputc ('\n', asm_out_file
);
4350 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4351 if (flag_verbose_asm
)
4353 fprintf (asm_out_file
, "\t%s CIE Augmentation (none)",
4356 fputc ('\n', asm_out_file
);
4358 if (flag_verbose_asm
)
4359 fprintf (asm_out_file
, " (CIE Code Alignment Factor)");
4360 fputc ('\n', asm_out_file
);
4361 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT
);
4362 if (flag_verbose_asm
)
4363 fprintf (asm_out_file
, " (CIE Data Alignment Factor)");
4364 fputc ('\n', asm_out_file
);
4365 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_FRAME_RETURN_COLUMN
);
4366 if (flag_verbose_asm
)
4368 fprintf (asm_out_file
, "\t%s CIE RA Column",
4371 fputc ('\n', asm_out_file
);
4373 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
4376 /* Pad the CIE out to an address sized boundary. */
4377 for (i
= next_fde_offset
- cie_size
; i
; --i
)
4379 /* Pad out to a pointer size boundary */
4380 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CFA_nop
);
4381 if (flag_verbose_asm
)
4383 fprintf (asm_out_file
, "\t%s CIE DW_CFA_nop (pad)",
4386 fputc ('\n', asm_out_file
);
4389 /* Loop through all of the FDE's. */
4390 for (i
= 0; i
< fde_table_in_use
; ++i
)
4392 fde
= &fde_table
[i
];
4393 if (fde
->dw_fde_cfi
== NULL
)
4395 fde_size
= size_of_fde (fde
, &fde_pad
);
4396 ASM_OUTPUT_DWARF_DATA (asm_out_file
, fde_size
- DWARF_OFFSET_SIZE
);
4397 if (flag_verbose_asm
)
4399 fprintf (asm_out_file
, "\t%s FDE Length",
4402 fputc ('\n', asm_out_file
);
4403 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (FRAME_SECTION
));
4404 if (flag_verbose_asm
)
4406 fprintf (asm_out_file
, "\t%s FDE CIE offset",
4409 fputc ('\n', asm_out_file
);
4410 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, fde
->dw_fde_begin
);
4411 if (flag_verbose_asm
)
4413 fprintf (asm_out_file
, "\t%s FDE initial location",
4416 fputc ('\n', asm_out_file
);
4417 ASM_OUTPUT_DWARF_ADDR_DELTA
4418 (asm_out_file
, fde
->dw_fde_end
, fde
->dw_fde_begin
);
4419 if (flag_verbose_asm
)
4421 fprintf (asm_out_file
, "\t%s FDE address range",
4424 fputc ('\n', asm_out_file
);
4426 /* Loop through the Call Frame Instructions associated with
4428 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
4429 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
4430 output_cfi (cfi
, fde
);
4432 /* Pad to a double word boundary. */
4433 for (j
= 0; j
< fde_pad
; ++j
)
4435 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CFA_nop
);
4436 if (flag_verbose_asm
)
4438 fprintf (asm_out_file
, "\t%s CIE DW_CFA_nop (pad)",
4441 fputc ('\n', asm_out_file
);
4446 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
4447 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
4448 argument list, and maybe the scope. */
4451 dwarf2_name (decl
, scope
)
4455 return (*decl_printable_name
) (decl
, scope
? 1 : 0);
4458 /* Add a new entry to .debug_pubnames if appropriate. */
4460 add_pubname (decl
, die
)
4466 if (! TREE_PUBLIC (decl
))
4469 if (pubname_table_in_use
== pubname_table_allocated
)
4471 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
4472 pubname_table
= (pubname_ref
) xrealloc
4473 (pubname_table
, pubname_table_allocated
* sizeof (pubname_entry
));
4475 p
= &pubname_table
[pubname_table_in_use
++];
4478 p
->name
= xstrdup (dwarf2_name (decl
, 1));
4481 /* Output the public names table used to speed up access to externally
4482 visible names. For now, only generate entries for externally
4483 visible procedures. */
4487 register unsigned i
;
4489 register unsigned long pubnames_length
= size_of_pubnames ();
4490 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pubnames_length
);
4492 if (flag_verbose_asm
)
4494 fprintf (asm_out_file
, "\t%s Length of Public Names Info.",
4497 fputc ('\n', asm_out_file
);
4498 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
4499 if (flag_verbose_asm
)
4501 fprintf (asm_out_file
, "\t%s DWARF Version",
4504 fputc ('\n', asm_out_file
);
4505 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (DEBUG_SECTION
));
4506 if (flag_verbose_asm
)
4508 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
4511 fputc ('\n', asm_out_file
);
4512 ASM_OUTPUT_DWARF_DATA (asm_out_file
, next_die_offset
);
4513 if (flag_verbose_asm
)
4515 fprintf (asm_out_file
, "\t%s Compilation Unit Length",
4518 fputc ('\n', asm_out_file
);
4519 for (i
= 0; i
< pubname_table_in_use
; ++i
)
4521 register pubname_ref pub
= &pubname_table
[i
];
4522 ASM_OUTPUT_DWARF_DATA (asm_out_file
, pub
->die
->die_offset
);
4523 if (flag_verbose_asm
)
4525 fprintf (asm_out_file
, "\t%s DIE offset",
4528 fputc ('\n', asm_out_file
);
4530 ASM_OUTPUT_DWARF_STRING (asm_out_file
, pub
->name
);
4531 if (flag_verbose_asm
)
4533 fprintf (asm_out_file
, "%s external name",
4536 fputc ('\n', asm_out_file
);
4538 ASM_OUTPUT_DWARF_DATA (asm_out_file
, 0);
4539 fputc ('\n', asm_out_file
);
4542 /* Add a new entry to .debug_aranges if appropriate. */
4544 add_arange (decl
, die
)
4548 if (! DECL_SECTION_NAME (decl
))
4551 if (arange_table_in_use
== arange_table_allocated
)
4553 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
4554 arange_table
= (arange_ref
) xrealloc
4555 (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
4557 arange_table
[arange_table_in_use
++] = die
;
4560 /* Output the information that goes into the .debug_aranges table.
4561 Namely, define the beginning and ending address range of the
4562 text section generated for this compilation unit. */
4566 register unsigned i
;
4568 register unsigned long aranges_length
= size_of_aranges ();
4569 ASM_OUTPUT_DWARF_DATA (asm_out_file
, aranges_length
);
4571 if (flag_verbose_asm
)
4573 fprintf (asm_out_file
, "\t%s Length of Address Ranges Info.",
4576 fputc ('\n', asm_out_file
);
4577 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
4578 if (flag_verbose_asm
)
4580 fprintf (asm_out_file
, "\t%s DWARF Version",
4583 fputc ('\n', asm_out_file
);
4584 ASM_OUTPUT_DWARF_OFFSET (asm_out_file
, stripattributes (DEBUG_SECTION
));
4585 if (flag_verbose_asm
)
4587 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
4590 fputc ('\n', asm_out_file
);
4591 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
4592 if (flag_verbose_asm
)
4594 fprintf (asm_out_file
, "\t%s Size of Address",
4597 fputc ('\n', asm_out_file
);
4598 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4599 if (flag_verbose_asm
)
4601 fprintf (asm_out_file
, "\t%s Size of Segment Descriptor",
4604 fputc ('\n', asm_out_file
);
4605 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 4);
4607 fprintf (asm_out_file
, ",0,0");
4608 if (flag_verbose_asm
)
4610 fprintf (asm_out_file
, "\t%s Pad to %d byte boundary",
4611 ASM_COMMENT_START
, 2 * PTR_SIZE
);
4613 fputc ('\n', asm_out_file
);
4614 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_SECTION
);
4615 if (flag_verbose_asm
)
4617 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
4619 fputc ('\n', asm_out_file
);
4620 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, text_end_label
, TEXT_SECTION
);
4621 if (flag_verbose_asm
)
4623 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
4625 fputc ('\n', asm_out_file
);
4626 for (i
= 0; i
< arange_table_in_use
; ++i
)
4628 dw_die_ref a
= arange_table
[i
];
4629 if (a
->die_tag
== DW_TAG_subprogram
)
4630 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, get_AT_low_pc (a
));
4633 char *name
= get_AT_string (a
, DW_AT_MIPS_linkage_name
);
4635 name
= get_AT_string (a
, DW_AT_name
);
4636 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, name
);
4638 if (flag_verbose_asm
)
4640 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
4642 fputc ('\n', asm_out_file
);
4643 if (a
->die_tag
== DW_TAG_subprogram
)
4644 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file
, get_AT_hi_pc (a
),
4647 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
,
4648 get_AT_unsigned (a
, DW_AT_byte_size
));
4649 if (flag_verbose_asm
)
4651 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
4653 fputc ('\n', asm_out_file
);
4655 /* Output the terminator words. */
4656 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
4657 fputc ('\n', asm_out_file
);
4658 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file
, 0);
4659 fputc ('\n', asm_out_file
);
4662 /* Output the source line number correspondence information. This
4663 information goes into the .debug_line section. */
4667 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4668 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4669 register unsigned opc
;
4670 register unsigned n_op_args
;
4671 register unsigned long ft_index
;
4672 register unsigned long lt_index
;
4673 register unsigned long current_line
;
4674 register long line_offset
;
4675 register long line_delta
;
4676 register unsigned long current_file
;
4677 register unsigned long function
;
4678 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_info ());
4679 if (flag_verbose_asm
)
4681 fprintf (asm_out_file
, "\t%s Length of Source Line Info.",
4684 fputc ('\n', asm_out_file
);
4685 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
4686 if (flag_verbose_asm
)
4688 fprintf (asm_out_file
, "\t%s DWARF Version",
4691 fputc ('\n', asm_out_file
);
4692 ASM_OUTPUT_DWARF_DATA (asm_out_file
, size_of_line_prolog ());
4693 if (flag_verbose_asm
)
4695 fprintf (asm_out_file
, "\t%s Prolog Length",
4698 fputc ('\n', asm_out_file
);
4699 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_MIN_INSTR_LENGTH
);
4700 if (flag_verbose_asm
)
4702 fprintf (asm_out_file
, "\t%s Minimum Instruction Length",
4705 fputc ('\n', asm_out_file
);
4706 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_DEFAULT_IS_STMT_START
);
4707 if (flag_verbose_asm
)
4709 fprintf (asm_out_file
, "\t%s Default is_stmt_start flag",
4712 fputc ('\n', asm_out_file
);
4713 fprintf (asm_out_file
, "\t%s\t%d", ASM_BYTE_OP
, DWARF_LINE_BASE
);
4714 if (flag_verbose_asm
)
4716 fprintf (asm_out_file
, "\t%s Line Base Value (Special Opcodes)",
4719 fputc ('\n', asm_out_file
);
4720 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_RANGE
);
4721 if (flag_verbose_asm
)
4723 fprintf (asm_out_file
, "\t%s Line Range Value (Special Opcodes)",
4726 fputc ('\n', asm_out_file
);
4727 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_OPCODE_BASE
);
4728 if (flag_verbose_asm
)
4730 fprintf (asm_out_file
, "\t%s Special Opcode Base",
4733 fputc ('\n', asm_out_file
);
4734 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; ++opc
)
4738 case DW_LNS_advance_pc
:
4739 case DW_LNS_advance_line
:
4740 case DW_LNS_set_file
:
4741 case DW_LNS_set_column
:
4742 case DW_LNS_fixed_advance_pc
:
4749 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, n_op_args
);
4750 if (flag_verbose_asm
)
4752 fprintf (asm_out_file
, "\t%s opcode: 0x%x has %d args",
4753 ASM_COMMENT_START
, opc
, n_op_args
);
4755 fputc ('\n', asm_out_file
);
4757 if (flag_verbose_asm
)
4759 fprintf (asm_out_file
, "%s Include Directory Table\n",
4762 /* Include directory table is empty, at present */
4763 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4764 fputc ('\n', asm_out_file
);
4765 if (flag_verbose_asm
)
4767 fprintf (asm_out_file
, "%s File Name Table\n", ASM_COMMENT_START
);
4769 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
4771 ASM_OUTPUT_DWARF_STRING (asm_out_file
, file_table
[ft_index
]);
4772 if (flag_verbose_asm
)
4774 fprintf (asm_out_file
, "%s File Entry: 0x%x",
4775 ASM_COMMENT_START
, ft_index
);
4777 fputc ('\n', asm_out_file
);
4778 /* Include directory index */
4780 fputc ('\n', asm_out_file
);
4781 /* Modification time */
4783 fputc ('\n', asm_out_file
);
4784 /* File length in bytes */
4786 fputc ('\n', asm_out_file
);
4788 /* Terminate the file name table */
4789 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4790 fputc ('\n', asm_out_file
);
4792 /* Set the address register to the first location in the text section */
4793 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4794 if (flag_verbose_asm
)
4796 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
4798 fputc ('\n', asm_out_file
);
4799 output_uleb128 (1 + PTR_SIZE
);
4800 fputc ('\n', asm_out_file
);
4801 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
4802 fputc ('\n', asm_out_file
);
4803 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_SECTION
);
4804 fputc ('\n', asm_out_file
);
4806 /* Generate the line number to PC correspondence table, encoded as
4807 a series of state machine operations. */
4810 strcpy (prev_line_label
, TEXT_SECTION
);
4811 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
4813 register dw_line_info_ref line_info
;
4814 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
4815 if (flag_verbose_asm
)
4817 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
4820 fputc ('\n', asm_out_file
);
4821 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
4822 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
4823 fputc ('\n', asm_out_file
);
4824 line_info
= &line_info_table
[lt_index
];
4825 if (line_info
->dw_file_num
!= current_file
)
4827 current_file
= line_info
->dw_file_num
;
4828 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
4829 if (flag_verbose_asm
)
4831 fprintf (asm_out_file
,
4832 "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
4834 fputc ('\n', asm_out_file
);
4835 output_uleb128 (current_file
);
4836 if (flag_verbose_asm
)
4837 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
4838 fputc ('\n', asm_out_file
);
4840 line_offset
= line_info
->dw_line_num
- current_line
;
4841 line_delta
= line_offset
- DWARF_LINE_BASE
;
4842 current_line
= line_info
->dw_line_num
;
4843 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
4845 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
4846 DWARF_LINE_OPCODE_BASE
+ line_delta
);
4847 if (flag_verbose_asm
)
4849 fprintf (asm_out_file
,
4850 "\t%s line %d", ASM_COMMENT_START
, current_line
);
4852 fputc ('\n', asm_out_file
);
4856 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
4857 if (flag_verbose_asm
)
4859 fprintf (asm_out_file
,
4860 "\t%s advance to line %d",
4861 ASM_COMMENT_START
, current_line
);
4863 fputc ('\n', asm_out_file
);
4864 output_sleb128 (line_offset
);
4865 fputc ('\n', asm_out_file
);
4866 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
4867 fputc ('\n', asm_out_file
);
4869 strcpy (prev_line_label
, line_label
);
4872 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
4873 if (flag_verbose_asm
)
4875 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
4878 fputc ('\n', asm_out_file
);
4879 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, text_end_label
, prev_line_label
);
4880 fputc ('\n', asm_out_file
);
4882 /* Output the marker for the end of the line number info. */
4883 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4884 if (flag_verbose_asm
)
4886 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START
);
4888 fputc ('\n', asm_out_file
);
4890 fputc ('\n', asm_out_file
);
4891 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
4892 fputc ('\n', asm_out_file
);
4897 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
; )
4899 register dw_separate_line_info_ref line_info
4900 = &separate_line_info_table
[lt_index
];
4901 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
4903 if (function
!= line_info
->function
)
4905 function
= line_info
->function
;
4906 /* Set the address register to the first line in the function */
4907 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4908 if (flag_verbose_asm
)
4909 fprintf (asm_out_file
, "\t%s DW_LNE_set_address",
4911 fputc ('\n', asm_out_file
);
4912 output_uleb128 (1 + PTR_SIZE
);
4913 fputc ('\n', asm_out_file
);
4914 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
4915 fputc ('\n', asm_out_file
);
4916 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, line_label
);
4917 fputc ('\n', asm_out_file
);
4921 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
4922 if (flag_verbose_asm
)
4923 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
4925 fputc ('\n', asm_out_file
);
4926 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
4927 fputc ('\n', asm_out_file
);
4929 if (line_info
->dw_file_num
!= current_file
)
4931 current_file
= line_info
->dw_file_num
;
4932 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
4933 if (flag_verbose_asm
)
4935 fprintf (asm_out_file
,
4936 "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
4938 fputc ('\n', asm_out_file
);
4939 output_uleb128 (current_file
);
4940 if (flag_verbose_asm
)
4941 fprintf (asm_out_file
, " (\"%s\")", file_table
[current_file
]);
4942 fputc ('\n', asm_out_file
);
4944 if (line_info
->dw_line_num
!= current_line
)
4946 line_offset
= line_info
->dw_line_num
- current_line
;
4947 line_delta
= line_offset
- DWARF_LINE_BASE
;
4948 current_line
= line_info
->dw_line_num
;
4949 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
4951 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
4952 DWARF_LINE_OPCODE_BASE
+ line_delta
);
4953 if (flag_verbose_asm
)
4955 fprintf (asm_out_file
,
4956 "\t%s line %d", ASM_COMMENT_START
, current_line
);
4958 fputc ('\n', asm_out_file
);
4962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
4963 if (flag_verbose_asm
)
4965 fprintf (asm_out_file
,
4966 "\t%s advance to line %d",
4967 ASM_COMMENT_START
, current_line
);
4969 fputc ('\n', asm_out_file
);
4970 output_sleb128 (line_offset
);
4971 fputc ('\n', asm_out_file
);
4972 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
4973 fputc ('\n', asm_out_file
);
4977 strcpy (prev_line_label
, line_label
);
4979 /* If we're done with a function, end its sequence. */
4980 if (lt_index
== separate_line_info_table_in_use
4981 || separate_line_info_table
[lt_index
].function
!= function
)
4985 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
4986 if (flag_verbose_asm
)
4987 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
4989 fputc ('\n', asm_out_file
);
4990 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
4991 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
4992 fputc ('\n', asm_out_file
);
4994 /* Output the marker for the end of this sequence. */
4995 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4996 if (flag_verbose_asm
)
4997 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence",
4999 fputc ('\n', asm_out_file
);
5001 fputc ('\n', asm_out_file
);
5002 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
5003 fputc ('\n', asm_out_file
);
5008 /**************** attribute support utilities ********************************/
5011 * Given a pointer to a BLOCK node return non-zero if (and only if) the node
5012 * in question represents the outermost pair of curly braces (i.e. the "body
5013 * block") of a function or method.
5015 * For any BLOCK node representing a "body block" of a function or method, the
5016 * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5017 * represents the outermost (function) scope for the function or method (i.e.
5018 * the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5019 * *that* node in turn will point to the relevant FUNCTION_DECL node.
5022 is_body_block (stmt
)
5025 if (TREE_CODE (stmt
) == BLOCK
)
5027 register tree parent
= BLOCK_SUPERCONTEXT (stmt
);
5029 if (TREE_CODE (parent
) == BLOCK
)
5031 register tree grandparent
= BLOCK_SUPERCONTEXT (parent
);
5033 if (TREE_CODE (grandparent
) == FUNCTION_DECL
)
5040 /* Given a pointer to a tree node for some base type, return a pointer to
5041 a DIE that describes the given type.
5043 This routine must only be called for GCC type nodes that correspond to
5044 Dwarf base (fundamental) types. */
5046 base_type_die (type
)
5049 register dw_die_ref base_type_result
;
5050 register char *type_name
;
5051 register enum dwarf_type encoding
;
5053 if (TREE_CODE (type
) == ERROR_MARK
5054 || TREE_CODE (type
) == VOID_TYPE
)
5058 register tree name
= TYPE_NAME (type
);
5059 if (TREE_CODE (name
) == TYPE_DECL
)
5060 name
= DECL_NAME (name
);
5061 type_name
= IDENTIFIER_POINTER (name
);
5064 switch (TREE_CODE (type
))
5067 /* Carefully distinguish the C character types, without messing
5068 up if the language is not C. Note that we check only for the names
5069 that contain spaces; other names might occur by coincidence in other
5071 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
5072 && (type
== char_type_node
5073 || ! strcmp (type_name
, "signed char")
5074 || ! strcmp (type_name
, "unsigned char"))))
5076 if (TREE_UNSIGNED (type
))
5077 encoding
= DW_ATE_unsigned
;
5079 encoding
= DW_ATE_signed
;
5082 /* else fall through */
5085 /* GNU Pascal/Ada CHAR type. Not used in C. */
5086 if (TREE_UNSIGNED (type
))
5087 encoding
= DW_ATE_unsigned_char
;
5089 encoding
= DW_ATE_signed_char
;
5093 encoding
= DW_ATE_float
;
5097 encoding
= DW_ATE_complex_float
;
5101 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
5102 encoding
= DW_ATE_boolean
;
5106 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
5109 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
);
5110 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
5111 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
5112 TYPE_PRECISION (type
) / BITS_PER_UNIT
);
5113 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
5115 return base_type_result
;
5118 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
5119 the Dwarf "root" type for the given input type. The Dwarf "root" type of
5120 a given type is generally the same as the given type, except that if the
5121 given type is a pointer or reference type, then the root type of the given
5122 type is the root type of the "basis" type for the pointer or reference
5123 type. (This definition of the "root" type is recursive.) Also, the root
5124 type of a `const' qualified type or a `volatile' qualified type is the
5125 root type of the given type without the qualifiers. */
5130 if (TREE_CODE (type
) == ERROR_MARK
)
5131 return error_mark_node
;
5133 switch (TREE_CODE (type
))
5136 return error_mark_node
;
5139 case REFERENCE_TYPE
:
5140 return type_main_variant (root_type (TREE_TYPE (type
)));
5143 return type_main_variant (type
);
5147 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
5148 given input type is a Dwarf "fundamental" type. Otherwise return null. */
5153 switch (TREE_CODE (type
))
5168 case QUAL_UNION_TYPE
:
5173 case REFERENCE_TYPE
:
5185 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
5186 entry that chains various modifiers in front of the given type. */
5188 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
5190 register int is_const_type
;
5191 register int is_volatile_type
;
5192 register dw_die_ref context_die
;
5194 register enum tree_code code
= TREE_CODE (type
);
5195 register dw_die_ref mod_type_die
= NULL
;
5196 register dw_die_ref sub_die
= NULL
;
5197 register tree item_type
= NULL
;
5199 if (code
!= ERROR_MARK
)
5201 type
= build_type_variant (type
, is_const_type
, is_volatile_type
);
5203 mod_type_die
= lookup_type_die (type
);
5205 return mod_type_die
;
5207 /* Handle C typedef types. */
5208 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
5209 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
5211 tree dtype
= TREE_TYPE (TYPE_NAME (type
));
5214 /* For a named type, use the typedef. */
5215 gen_type_die (type
, context_die
);
5216 mod_type_die
= lookup_type_die (type
);
5218 else if (is_const_type
< TYPE_READONLY (dtype
)
5219 || is_volatile_type
< TYPE_VOLATILE (dtype
))
5220 /* cv-unqualified version of named type. Just use the unnamed
5221 type to which it refers. */
5222 mod_type_die
= modified_type_die
5223 (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)),
5224 is_const_type
, is_volatile_type
);
5225 /* else cv-qualified version of named type; fall through. */
5230 else if (is_const_type
)
5232 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
);
5233 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
5235 else if (is_volatile_type
)
5237 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
);
5238 sub_die
= modified_type_die (type
, 0, 0, context_die
);
5240 else if (code
== POINTER_TYPE
)
5242 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
);
5243 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
5245 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
5247 item_type
= TREE_TYPE (type
);
5249 else if (code
== REFERENCE_TYPE
)
5251 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
);
5252 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
5254 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
5256 item_type
= TREE_TYPE (type
);
5258 else if (is_base_type (type
))
5260 mod_type_die
= base_type_die (type
);
5264 gen_type_die (type
, context_die
);
5266 /* We have to get the type_main_variant here (and pass that to the
5267 `lookup_type_die' routine) because the ..._TYPE node we have
5268 might simply be a *copy* of some original type node (where the
5269 copy was created to help us keep track of typedef names) and
5270 that copy might have a different TYPE_UID from the original
5272 mod_type_die
= lookup_type_die (type_main_variant (type
));
5273 assert (mod_type_die
!= NULL
);
5276 equate_type_number_to_die (type
, mod_type_die
);
5279 /* We must do this after the equate_type_number_to_die call, in case
5280 this is a recursive type. This ensures that the modified_type_die
5281 recursion will terminate even if the type is recursive. Recursive
5282 types are possible in Ada. */
5283 sub_die
= modified_type_die (item_type
,
5284 TYPE_READONLY (item_type
),
5285 TYPE_VOLATILE (item_type
),
5288 if (sub_die
!= NULL
)
5290 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
5292 return mod_type_die
;
5295 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5296 an enumerated type. */
5301 return TREE_CODE (type
) == ENUMERAL_TYPE
;
5304 /* Return the register number described by a given RTL node. */
5309 register unsigned regno
= REGNO (rtl
);
5311 if (regno
>= FIRST_PSEUDO_REGISTER
)
5313 warning_with_decl (dwarf_last_decl
, "internal regno botch: regno = %d\n",
5317 regno
= DBX_REGISTER_NUMBER (regno
);
5321 /* Return a location descriptor that designates a machine register. */
5322 static dw_loc_descr_ref
5323 reg_loc_descriptor (rtl
)
5326 register dw_loc_descr_ref loc_result
= NULL
;
5327 register unsigned reg
= reg_number (rtl
);
5328 if (reg
>= 0 && reg
<= 31)
5330 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0);
5334 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
5339 /* Return a location descriptor that designates a base+offset location. */
5340 static dw_loc_descr_ref
5341 based_loc_descr (reg
, offset
)
5345 register dw_loc_descr_ref loc_result
;
5346 /* For the "frame base", we use the frame pointer or stack pointer
5347 registers, since the RTL for local variables is relative to one of
5349 register unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
5350 ? FRAME_POINTER_REGNUM
5351 : STACK_POINTER_REGNUM
);
5354 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
5356 else if (reg
>= 0 && reg
<= 31)
5358 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
);
5362 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
5367 /* Return true if this RTL expression describes a base+offset calculation. */
5372 return GET_CODE (rtl
) == PLUS
5373 && ((GET_CODE (XEXP (rtl
, 0)) == REG
5374 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
));
5377 /* The following routine converts the RTL for a variable or parameter
5378 (resident in memory) into an equivalent Dwarf representation of a
5379 mechanism for getting the address of that same variable onto the top of a
5380 hypothetical "address evaluation" stack.
5381 When creating memory location descriptors, we are effectively transforming
5382 the RTL for a memory-resident object into its Dwarf postfix expression
5383 equivalent. This routine recursively descends an RTL tree, turning
5384 it into Dwarf postfix code as it goes. */
5385 static dw_loc_descr_ref
5386 mem_loc_descriptor (rtl
)
5389 dw_loc_descr_ref mem_loc_result
= NULL
;
5390 /* Note that for a dynamically sized array, the location we will generate a
5391 description of here will be the lowest numbered location which is
5392 actually within the array. That's *not* necessarily the same as the
5393 zeroth element of the array. */
5394 switch (GET_CODE (rtl
))
5397 /* The case of a subreg may arise when we have a local (register)
5398 variable or a formal (register) parameter which doesn't quite fill
5399 up an entire register. For now, just assume that it is
5400 legitimate to make the Dwarf info refer to the whole register which
5401 contains the given subreg. */
5402 rtl
= XEXP (rtl
, 0);
5406 /* Whenever a register number forms a part of the description of the
5407 method for calculating the (dynamic) address of a memory resident
5408 object, DWARF rules require the register number be referred to as
5409 a "base register". This distinction is not based in any way upon
5410 what category of register the hardware believes the given register
5411 belongs to. This is strictly DWARF terminology we're dealing with
5412 here. Note that in cases where the location of a memory-resident
5413 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5414 OP_CONST (0)) the actual DWARF location descriptor that we generate
5415 may just be OP_BASEREG (basereg). This may look deceptively like
5416 the object in question was allocated to a register (rather than in
5417 memory) so DWARF consumers need to be aware of the subtle
5418 distinction between OP_REG and OP_BASEREG. */
5419 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
5423 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
5424 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
5429 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
5430 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
5431 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= addr_to_string (rtl
);
5435 if (is_based_loc (rtl
))
5437 mem_loc_result
= based_loc_descr (
5438 reg_number (XEXP (rtl
, 0)),
5439 INTVAL (XEXP (rtl
, 1)));
5443 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0)));
5444 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1)));
5445 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_plus
, 0, 0));
5450 /* If a pseudo-reg is optimized away, it is possible for it to
5451 be replaced with a MEM containing a multiply. */
5452 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0)));
5453 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1)));
5454 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
5458 mem_loc_result
= new_loc_descr (DW_OP_constu
, INTVAL (rtl
), 0);
5464 return mem_loc_result
;
5467 /* Output a proper Dwarf location descriptor for a variable or parameter
5468 which is either allocated in a register or in a memory location. For a
5469 register, we just generate an OP_REG and the register number. For a
5470 memory location we provide a Dwarf postfix expression describing how to
5471 generate the (dynamic) address of the object onto the address stack. */
5472 static dw_loc_descr_ref
5473 loc_descriptor (rtl
)
5476 dw_loc_descr_ref loc_result
= NULL
;
5477 switch (GET_CODE (rtl
))
5481 /* The case of a subreg may arise when we have a local (register)
5482 variable or a formal (register) parameter which doesn't quite fill
5483 up an entire register. For now, just assume that it is
5484 legitimate to make the Dwarf info refer to the whole register which
5485 contains the given subreg. */
5487 rtl
= XEXP (rtl
, 0);
5491 loc_result
= reg_loc_descriptor (rtl
);
5495 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
5499 abort (); /* Should never happen */
5504 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
5505 which is not less than the value itself. */
5507 ceiling (value
, boundary
)
5508 register unsigned value
;
5509 register unsigned boundary
;
5511 return (((value
+ boundary
- 1) / boundary
) * boundary
);
5514 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5515 pointer to the declared type for the relevant field variable, or return
5516 `integer_type_node' if the given node turns out to be an
5524 if (TREE_CODE (decl
) == ERROR_MARK
)
5525 return integer_type_node
;
5527 type
= DECL_BIT_FIELD_TYPE (decl
);
5529 type
= TREE_TYPE (decl
);
5534 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5535 node, return the alignment in bits for the type, or else return
5536 BITS_PER_WORD if the node actually turns out to be an
5539 simple_type_align_in_bits (type
)
5542 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
5545 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5546 node, return the size in bits for the type if it is a constant, or else
5547 return the alignment for the type if the type's size is not constant, or
5548 else return BITS_PER_WORD if the type actually turns out to be an
5551 simple_type_size_in_bits (type
)
5554 if (TREE_CODE (type
) == ERROR_MARK
)
5555 return BITS_PER_WORD
;
5558 register tree type_size_tree
= TYPE_SIZE (type
);
5560 if (TREE_CODE (type_size_tree
) != INTEGER_CST
)
5561 return TYPE_ALIGN (type
);
5563 return (unsigned) TREE_INT_CST_LOW (type_size_tree
);
5567 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5568 return the byte offset of the lowest addressed byte of the "containing
5569 object" for the given FIELD_DECL, or return 0 if we are unable to
5570 determine what that offset is, either because the argument turns out to
5571 be a pointer to an ERROR_MARK node, or because the offset is actually
5572 variable. (We can't handle the latter case just yet). */
5574 field_byte_offset (decl
)
5577 register unsigned type_align_in_bytes
;
5578 register unsigned type_align_in_bits
;
5579 register unsigned type_size_in_bits
;
5580 register unsigned object_offset_in_align_units
;
5581 register unsigned object_offset_in_bits
;
5582 register unsigned object_offset_in_bytes
;
5584 register tree bitpos_tree
;
5585 register tree field_size_tree
;
5586 register unsigned bitpos_int
;
5587 register unsigned deepest_bitpos
;
5588 register unsigned field_size_in_bits
;
5590 if (TREE_CODE (decl
) == ERROR_MARK
)
5593 if (TREE_CODE (decl
) != FIELD_DECL
)
5596 type
= field_type (decl
);
5598 bitpos_tree
= DECL_FIELD_BITPOS (decl
);
5599 field_size_tree
= DECL_SIZE (decl
);
5601 /* We cannot yet cope with fields whose positions or sizes are variable, so
5602 for now, when we see such things, we simply return 0. Someday, we may
5603 be able to handle such cases, but it will be damn difficult. */
5604 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
5606 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
5608 if (TREE_CODE (field_size_tree
) != INTEGER_CST
)
5610 field_size_in_bits
= (unsigned) TREE_INT_CST_LOW (field_size_tree
);
5612 type_size_in_bits
= simple_type_size_in_bits (type
);
5614 type_align_in_bits
= simple_type_align_in_bits (type
);
5615 type_align_in_bytes
= type_align_in_bits
/ BITS_PER_UNIT
;
5617 /* Note that the GCC front-end doesn't make any attempt to keep track of
5618 the starting bit offset (relative to the start of the containing
5619 structure type) of the hypothetical "containing object" for a bit-
5620 field. Thus, when computing the byte offset value for the start of the
5621 "containing object" of a bit-field, we must deduce this information on
5622 our own. This can be rather tricky to do in some cases. For example,
5623 handling the following structure type definition when compiling for an
5624 i386/i486 target (which only aligns long long's to 32-bit boundaries)
5627 struct S { int field1; long long field2:31; };
5629 Fortunately, there is a simple rule-of-thumb which can be
5630 used in such cases. When compiling for an i386/i486, GCC will allocate
5631 8 bytes for the structure shown above. It decides to do this based upon
5632 one simple rule for bit-field allocation. Quite simply, GCC allocates
5633 each "containing object" for each bit-field at the first (i.e. lowest
5634 addressed) legitimate alignment boundary (based upon the required
5635 minimum alignment for the declared type of the field) which it can
5636 possibly use, subject to the condition that there is still enough
5637 available space remaining in the containing object (when allocated at
5638 the selected point) to fully accommodate all of the bits of the
5639 bit-field itself. This simple rule makes it obvious why GCC allocates
5640 8 bytes for each object of the structure type shown above. When looking
5641 for a place to allocate the "containing object" for `field2', the
5642 compiler simply tries to allocate a 64-bit "containing object" at each
5643 successive 32-bit boundary (starting at zero) until it finds a place to
5644 allocate that 64- bit field such that at least 31 contiguous (and
5645 previously unallocated) bits remain within that selected 64 bit field.
5646 (As it turns out, for the example above, the compiler finds that it is
5647 OK to allocate the "containing object" 64-bit field at bit-offset zero
5648 within the structure type.) Here we attempt to work backwards from the
5649 limited set of facts we're given, and we try to deduce from those facts,
5650 where GCC must have believed that the containing object started (within
5651 the structure type). The value we deduce is then used (by the callers of
5652 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
5653 for fields (both bit-fields and, in the case of DW_AT_location, regular
5656 /* Figure out the bit-distance from the start of the structure to the
5657 "deepest" bit of the bit-field. */
5658 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
5660 /* This is the tricky part. Use some fancy footwork to deduce where the
5661 lowest addressed bit of the containing object must be. */
5662 object_offset_in_bits
5663 = ceiling (deepest_bitpos
, type_align_in_bits
) - type_size_in_bits
;
5665 /* Compute the offset of the containing object in "alignment units". */
5666 object_offset_in_align_units
= object_offset_in_bits
/ type_align_in_bits
;
5668 /* Compute the offset of the containing object in bytes. */
5669 object_offset_in_bytes
= object_offset_in_align_units
* type_align_in_bytes
;
5671 return object_offset_in_bytes
;
5676 /****************************** attributes *********************************/
5678 /* The following routines define various Dwarf attributes
5679 (and any data associated with them). */
5682 /* Output the form of location attributes suitable for whole variables and
5683 whole parameters. Note that the location attributes for struct fields are
5684 generated by the routine `data_member_location_attribute' below. */
5686 add_location_attribute (die
, rtl
)
5690 dw_loc_descr_ref loc_descr
= NULL
;
5692 /* Handle a special case. If we are about to output a location descriptor
5693 for a variable or parameter which has been optimized out of existence,
5694 don't do that. Instead we output a null location descriptor value as
5695 part of the location attribute. A variable which has been optimized out
5696 of existence will have a DECL_RTL value which denotes a pseudo-reg.
5697 Currently, in some rare cases, variables can have DECL_RTL values which
5698 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
5699 elsewhere in the compiler. We treat such cases as if the variable(s) in
5700 question had been optimized out of existence. Note that in all cases
5701 where we wish to express the fact that a variable has been optimized out
5702 of existence, we do not simply suppress the generation of the entire
5703 location attribute because the absence of a location attribute in
5704 certain kinds of DIEs is used to indicate something else entirely...
5705 i.e. that the DIE represents an object declaration, but not a
5706 definition. So sayeth the PLSIG. */
5707 if (!is_pseudo_reg (rtl
)
5708 && (GET_CODE (rtl
) != MEM
5709 || !is_pseudo_reg (XEXP (rtl
, 0))))
5711 loc_descr
= loc_descriptor (eliminate_regs (rtl
, 0, NULL_RTX
, 0));
5714 #ifdef MIPS_DEBUGGING_INFO
5715 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
5716 location descriptor. Lets just use r0 for now to represent a
5717 variable that has been optimized away. */
5718 if (loc_descr
== NULL
)
5720 loc_descr
= loc_descriptor (gen_rtx (REG
, word_mode
, 0));
5724 add_AT_loc (die
, DW_AT_location
, loc_descr
);
5727 /* Attach the specialized form of location attribute used for data
5728 members of struct and union types. In the special case of a
5729 FIELD_DECL node which represents a bit-field, the "offset" part
5730 of this special location descriptor must indicate the distance
5731 in bytes from the lowest-addressed byte of the containing struct
5732 or union type to the lowest-addressed byte of the "containing
5733 object" for the bit-field. (See the `field_byte_offset' function
5734 above).. For any given bit-field, the "containing object" is a
5735 hypothetical object (of some integral or enum type) within which
5736 the given bit-field lives. The type of this hypothetical
5737 "containing object" is always the same as the declared type of
5738 the individual bit-field itself (for GCC anyway... the DWARF
5739 spec doesn't actually mandate this). Note that it is the size
5740 (in bytes) of the hypothetical "containing object" which will
5741 be given in the DW_AT_byte_size attribute for this bit-field.
5742 (See the `byte_size_attribute' function below.) It is also used
5743 when calculating the value of the DW_AT_bit_offset attribute.
5744 (See the `bit_offset_attribute' function below). */
5746 add_data_member_location_attribute (die
, decl
)
5747 register dw_die_ref die
;
5750 register unsigned long offset
;
5751 register dw_loc_descr_ref loc_descr
;
5752 register enum dwarf_location_atom op
;
5754 if (TREE_CODE (decl
) == TREE_VEC
)
5755 offset
= TREE_INT_CST_LOW (BINFO_OFFSET (decl
));
5757 offset
= field_byte_offset (decl
);
5759 /* The DWARF2 standard says that we should assume that the structure address
5760 is already on the stack, so we can specify a structure field address
5761 by using DW_OP_plus_uconst. */
5762 #ifdef MIPS_DEBUGGING_INFO
5763 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
5764 correctly. It works only if we leave the offset on the stack. */
5767 op
= DW_OP_plus_uconst
;
5769 loc_descr
= new_loc_descr (op
, offset
, 0);
5770 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
5773 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
5774 does not have a "location" either in memory or in a register. These
5775 things can arise in GNU C when a constant is passed as an actual parameter
5776 to an inlined function. They can also arise in C++ where declared
5777 constants do not necessarily get memory "homes". */
5779 add_const_value_attribute (die
, rtl
)
5780 register dw_die_ref die
;
5783 switch (GET_CODE (rtl
))
5786 /* Note that a CONST_INT rtx could represent either an integer or a
5787 floating-point constant. A CONST_INT is used whenever the constant
5788 will fit into a single word. In all such cases, the original mode
5789 of the constant value is wiped out, and the CONST_INT rtx is
5790 assigned VOIDmode. */
5791 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned) INTVAL (rtl
));
5795 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
5796 floating-point constant. A CONST_DOUBLE is used whenever the
5797 constant requires more than one word in order to be adequately
5798 represented. We output CONST_DOUBLEs as blocks. */
5800 register enum machine_mode mode
= GET_MODE (rtl
);
5802 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5804 union real_extract u
;
5806 register unsigned length
= GET_MODE_SIZE (mode
) / 4;
5807 register long *array
= (long *) xmalloc (length
* sizeof (long));
5809 bcopy ((char *) &CONST_DOUBLE_LOW (rtl
), (char *) &u
, sizeof u
);
5811 if (setjmp (handler
))
5813 error ("floating point trap outputting debug info");
5817 set_float_handler (handler
);
5822 REAL_VALUE_TO_TARGET_SINGLE (u
.d
, array
[0]);
5826 REAL_VALUE_TO_TARGET_DOUBLE (u
.d
, array
);
5831 REAL_VALUE_TO_TARGET_LONG_DOUBLE (u
.d
, array
);
5838 set_float_handler (NULL_PTR
);
5840 add_AT_float (die
, DW_AT_const_value
, length
, array
);
5843 add_AT_long_long (die
, DW_AT_const_value
,
5844 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
5849 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
5855 add_AT_addr (die
, DW_AT_const_value
, addr_to_string (rtl
));
5859 /* In cases where an inlined instance of an inline function is passed
5860 the address of an `auto' variable (which is local to the caller) we
5861 can get a situation where the DECL_RTL of the artificial local
5862 variable (for the inlining) which acts as a stand-in for the
5863 corresponding formal parameter (of the inline function) will look
5864 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
5865 exactly a compile-time constant expression, but it isn't the address
5866 of the (artificial) local variable either. Rather, it represents the
5867 *value* which the artificial local variable always has during its
5868 lifetime. We currently have no way to represent such quasi-constant
5869 values in Dwarf, so for now we just punt and generate an
5870 DW_AT_const_value attribute with null address. */
5871 add_AT_addr (die
, DW_AT_const_value
, addr_to_string (const0_rtx
));
5875 /* No other kinds of rtx should be possible here. */
5881 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
5882 data attribute for a variable or a parameter. We generate the
5883 DW_AT_const_value attribute only in those cases where the given variable
5884 or parameter does not have a true "location" either in memory or in a
5885 register. This can happen (for example) when a constant is passed as an
5886 actual argument in a call to an inline function. (It's possible that
5887 these things can crop up in other ways also.) Note that one type of
5888 constant value which can be passed into an inlined function is a constant
5889 pointer. This can happen for example if an actual argument in an inlined
5890 function call evaluates to a compile-time constant address. */
5892 add_location_or_const_value_attribute (die
, decl
)
5893 register dw_die_ref die
;
5897 register tree declared_type
;
5898 register tree passed_type
;
5900 if (TREE_CODE (decl
) == ERROR_MARK
)
5904 if ((TREE_CODE (decl
) != VAR_DECL
)
5905 && (TREE_CODE (decl
) != PARM_DECL
))
5907 /* Should never happen. */
5911 /* Here we have to decide where we are going to say the parameter "lives"
5912 (as far as the debugger is concerned). We only have a couple of
5913 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
5914 DECL_RTL normally indicates where the parameter lives during most of the
5915 activa- tion of the function. If optimization is enabled however, this
5916 could be either NULL or else a pseudo-reg. Both of those cases indicate
5917 that the parameter doesn't really live anywhere (as far as the code
5918 generation parts of GCC are concerned) during most of the function's
5919 activation. That will happen (for example) if the parameter is never
5920 referenced within the function. We could just generate a location
5921 descriptor here for all non-NULL non-pseudo values of DECL_RTL and
5922 ignore all of the rest, but we can be a little nicer than that if we
5923 also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a
5924 pseudo-reg. Note however that we can only get away with using
5925 DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited
5926 cases. In cases where DECL_ARG_TYPE(decl) indicates the same type as
5927 TREE_TYPE(decl) we can be sure that the parameter was passed using the
5928 same type as it is declared to have within the function, and that its
5929 DECL_INCOMING_RTL points us to a place where a value of that type is
5930 passed. In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are
5931 different types however, we cannot (in general) use DECL_INCOMING_RTL as
5932 a backup substitute for DECL_RTL because in these cases,
5933 DECL_INCOMING_RTL points us to a value of some type which is *different*
5934 from the type of the parameter itself. Thus, if we tried to use
5935 DECL_INCOMING_RTL to generate a location attribute in such cases, the
5936 debugger would end up (for example) trying to fetch a `float' from a
5937 place which actually contains the first part of a `double'. That would
5938 lead to really incorrect and confusing output at debug-time, and we
5939 don't want that now do we? So in general, we DO NOT use
5940 DECL_INCOMING_RTL as a backup for DECL_RTL in cases where
5941 DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a couple of cute
5942 exceptions however. On little-endian machines we can get away with
5943 using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as
5944 TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type
5945 which is smaller than TREE_TYPE(decl). These cases arise when (on a
5946 little-endian machine) a non-prototyped function has a parameter
5947 declared to be of type `short' or `char'. In such cases,
5948 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
5949 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
5950 passed `int' value. If the debugger then uses that address to fetch a
5951 `short' or a `char' (on a little-endian machine) the result will be the
5952 correct data, so we allow for such exceptional cases below. Note that
5953 our goal here is to describe the place where the given formal parameter
5954 lives during most of the function's activation (i.e. between the end of
5955 the prologue and the start of the epilogue). We'll do that as best as
5956 we can. Note however that if the given formal parameter is modified
5957 sometime during the execution of the function, then a stack backtrace
5958 (at debug-time) will show the function as having been called with the
5959 *new* value rather than the value which was originally passed in. This
5960 happens rarely enough that it is not a major problem, but it *is* a
5961 problem, and I'd like to fix it. A future version of dwarf2out.c may
5962 generate two additional attributes for any given DW_TAG_formal_parameter
5963 DIE which will describe the "passed type" and the "passed location" for
5964 the given formal parameter in addition to the attributes we now generate
5965 to indicate the "declared type" and the "active location" for each
5966 parameter. This additional set of attributes could be used by debuggers
5967 for stack backtraces. Separately, note that sometimes DECL_RTL can be
5968 NULL and DECL_INCOMING_RTL can be NULL also. This happens (for example)
5969 for inlined-instances of inline function formal parameters which are
5970 never referenced. This really shouldn't be happening. All PARM_DECL
5971 nodes should get valid non-NULL DECL_INCOMING_RTL values, but
5972 integrate.c doesn't currently generate these values for inlined
5973 instances of inline function parameters, so when we see such cases, we
5974 are just SOL (shit-out-of-luck) for the time being (until integrate.c
5977 /* Use DECL_RTL as the "location" unless we find something better. */
5978 rtl
= DECL_RTL (decl
);
5980 if (TREE_CODE (decl
) == PARM_DECL
)
5982 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
5984 declared_type
= type_main_variant (TREE_TYPE (decl
));
5985 passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
5986 /* This decl represents a formal parameter which was
5989 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
5990 all* cases where (rtl == NULL_RTX) just below. */
5991 if (declared_type
== passed_type
)
5993 rtl
= DECL_INCOMING_RTL (decl
);
5995 else if (!BYTES_BIG_ENDIAN
)
5997 if (TREE_CODE (declared_type
) == INTEGER_TYPE
)
5999 if (TYPE_SIZE (declared_type
) <= TYPE_SIZE (passed_type
))
6001 rtl
= DECL_INCOMING_RTL (decl
);
6007 if (rtl
== NULL_RTX
)
6010 switch (GET_CODE (rtl
))
6019 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
6020 add_const_value_attribute (die
, rtl
);
6026 add_location_attribute (die
, rtl
);
6030 abort (); /* Should never happen. */
6034 /* Generate an DW_AT_name attribute given some string value to be included as
6035 the value of the attribute. */
6037 add_name_attribute (die
, name_string
)
6038 register dw_die_ref die
;
6039 register char *name_string
;
6041 if (name_string
&& *name_string
)
6043 add_AT_string (die
, DW_AT_name
, name_string
);
6047 /* Given a tree node describing an array bound (either lower or upper) output
6048 a representation for that bound.
6050 FIXME: This uses location descriptions for variable bounds, whereas the
6051 DWARF-2 spec only allowes for constants or DIE references. */
6053 add_bound_info (subrange_die
, bound_attr
, bound
)
6054 register dw_die_ref subrange_die
;
6055 register enum dwarf_attribute bound_attr
;
6056 register tree bound
;
6058 register dw_loc_descr_ref bound_loc
= NULL
;
6059 register unsigned bound_value
= 0;
6060 switch (TREE_CODE (bound
))
6065 /* All fixed-bounds are represented by INTEGER_CST nodes. */
6067 bound_value
= TREE_INT_CST_LOW (bound
);
6068 if (bound_attr
== DW_AT_lower_bound
6069 && ((is_c_family () && bound_value
== 0)
6070 || (is_fortran () && bound_value
== 1)))
6071 /* use the default */;
6073 add_AT_unsigned (subrange_die
, bound_attr
, bound_value
);
6076 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
6079 bound
= TREE_OPERAND (bound
, 0);
6080 /* ... fall thru... */
6083 /* Handle the simple case of `int ar[i];'. */
6084 if (bound_attr
== DW_AT_upper_bound
&& is_c_family ()
6085 && TREE_CODE (TREE_OPERAND (bound
, 0)) == MINUS_EXPR
)
6087 tree t
= TREE_OPERAND (bound
, 0);
6088 if (integer_onep (TREE_OPERAND (bound
, 1)))
6089 t
= TREE_OPERAND (t
, 0);
6090 if (TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
6092 add_AT_die_ref (subrange_die
, DW_AT_count
, lookup_decl_die (t
));
6097 /* If optimization is turned on, the SAVE_EXPRs that describe how to
6098 access the upper bound values are essentially bogus. They only
6099 describe (at best) how to get at these values at the points in the
6100 generated code right after they have just been computed. Worse
6101 yet, in the typical case, the upper bound values will not even
6102 *be* computed in the optimized code, so these SAVE_EXPRs are
6103 entirely bogus. In order to compensate for this fact, we check
6104 here to see if optimization is enabled, and if so, we don't add an
6105 attribute for the (unknown and unknowable) upper bound. This
6106 should not cause too much trouble for existing (stupid?)
6107 debuggers because they have to deal with empty upper bounds
6108 location descriptions anyway in order to be able to deal with
6109 incomplete array types. Of course an intelligent debugger (GDB?)
6110 should be able to comprehend that a missing upper bound
6111 specification in a array type used for a storage class `auto'
6112 local array variable indicates that the upper bound is both
6113 unknown (at compile- time) and unknowable (at run-time) due to
6117 bound_loc
= mem_loc_descriptor
6118 (eliminate_regs (SAVE_EXPR_RTL (bound
), 0, NULL_RTX
, 0));
6119 add_AT_loc (subrange_die
, bound_attr
, bound_loc
);
6121 /* else leave out the attribute. */
6129 /* Note that the block of subscript information for an array type also
6130 includes information about the element type of type given array type. */
6132 add_subscript_info (type_die
, type
)
6133 register dw_die_ref type_die
;
6136 register unsigned dimension_number
;
6137 register tree lower
, upper
;
6138 register dw_die_ref subrange_die
;
6140 /* The GNU compilers represent multidimensional array types as sequences of
6141 one dimensional array types whose element types are themselves array
6142 types. Here we squish that down, so that each multidimensional array
6143 type gets only one array_type DIE in the Dwarf debugging info. The draft
6144 Dwarf specification say that we are allowed to do this kind of
6145 compression in C (because there is no difference between an array or
6146 arrays and a multidimensional array in C) but for other source languages
6147 (e.g. Ada) we probably shouldn't do this. */
6148 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6149 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6150 We work around this by disabling this feature. See also
6151 gen_array_type_die. */
6152 #ifndef MIPS_DEBUGGING_INFO
6153 for (dimension_number
= 0;
6154 TREE_CODE (type
) == ARRAY_TYPE
;
6155 type
= TREE_TYPE (type
), dimension_number
++)
6158 register tree domain
= TYPE_DOMAIN (type
);
6160 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
6161 and (in GNU C only) variable bounds. Handle all three forms
6163 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
);
6166 /* We have an array type with specified bounds. */
6167 lower
= TYPE_MIN_VALUE (domain
);
6168 upper
= TYPE_MAX_VALUE (domain
);
6170 /* define the index type. */
6171 if (TREE_TYPE (domain
))
6172 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
6175 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
6176 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
6180 /* We have an array type with an unspecified length. The DWARF-2
6181 spec does not say how to handle this; let's just leave out the
6184 #ifndef MIPS_DEBUGGING_INFO
6190 add_byte_size_attribute (die
, tree_node
)
6192 register tree tree_node
;
6194 register unsigned size
;
6196 switch (TREE_CODE (tree_node
))
6204 case QUAL_UNION_TYPE
:
6205 size
= int_size_in_bytes (tree_node
);
6208 /* For a data member of a struct or union, the DW_AT_byte_size is
6209 generally given as the number of bytes normally allocated for an
6210 object of the *declared* type of the member itself. This is true
6211 even for bit-fields. */
6212 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
6218 /* Note that `size' might be -1 when we get to this point. If it is, that
6219 indicates that the byte size of the entity in question is variable. We
6220 have no good way of expressing this fact in Dwarf at the present time,
6221 so just let the -1 pass on through. */
6223 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
6226 /* For a FIELD_DECL node which represents a bit-field, output an attribute
6227 which specifies the distance in bits from the highest order bit of the
6228 "containing object" for the bit-field to the highest order bit of the
6231 For any given bit-field, the "containing object" is a hypothetical
6232 object (of some integral or enum type) within which the given bit-field
6233 lives. The type of this hypothetical "containing object" is always the
6234 same as the declared type of the individual bit-field itself. The
6235 determination of the exact location of the "containing object" for a
6236 bit-field is rather complicated. It's handled by the
6237 `field_byte_offset' function (above).
6239 Note that it is the size (in bytes) of the hypothetical "containing object"
6240 which will be given in the DW_AT_byte_size attribute for this bit-field.
6241 (See `byte_size_attribute' above). */
6243 add_bit_offset_attribute (die
, decl
)
6244 register dw_die_ref die
;
6247 register unsigned object_offset_in_bytes
= field_byte_offset (decl
);
6248 register tree type
= DECL_BIT_FIELD_TYPE (decl
);
6249 register tree bitpos_tree
= DECL_FIELD_BITPOS (decl
);
6250 register unsigned bitpos_int
;
6251 register unsigned highest_order_object_bit_offset
;
6252 register unsigned highest_order_field_bit_offset
;
6253 register unsigned bit_offset
;
6255 assert (TREE_CODE (decl
) == FIELD_DECL
); /* Must be a field. */
6256 assert (type
); /* Must be a bit field. */
6258 /* We can't yet handle bit-fields whose offsets are variable, so if we
6259 encounter such things, just return without generating any attribute
6261 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
6265 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
6267 /* Note that the bit offset is always the distance (in bits) from the
6268 highest-order bit of the "containing object" to the highest-order bit of
6269 the bit-field itself. Since the "high-order end" of any object or field
6270 is different on big-endian and little-endian machines, the computation
6271 below must take account of these differences. */
6272 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
6273 highest_order_field_bit_offset
= bitpos_int
;
6275 if (!BYTES_BIG_ENDIAN
)
6277 highest_order_field_bit_offset
6278 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
));
6280 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
6284 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
6285 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
6287 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
6290 /* For a FIELD_DECL node which represents a bit field, output an attribute
6291 which specifies the length in bits of the given field. */
6293 add_bit_size_attribute (die
, decl
)
6294 register dw_die_ref die
;
6297 assert (TREE_CODE (decl
) == FIELD_DECL
); /* Must be a field. */
6298 assert (DECL_BIT_FIELD_TYPE (decl
)); /* Must be a bit field. */
6299 add_AT_unsigned (die
, DW_AT_bit_size
,
6300 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
)));
6303 /* If the compiled language is ANSI C, then add a 'prototyped'
6304 attribute, if arg types are given for the parameters of a function. */
6306 add_prototyped_attribute (die
, func_type
)
6307 register dw_die_ref die
;
6308 register tree func_type
;
6310 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
6311 && TYPE_ARG_TYPES (func_type
) != NULL
)
6312 add_AT_flag (die
, DW_AT_prototyped
, 1);
6316 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
6317 by looking in either the type declaration or object declaration
6320 add_abstract_origin_attribute (die
, origin
)
6321 register dw_die_ref die
;
6322 register tree origin
;
6324 dw_die_ref origin_die
= NULL
;
6325 if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 'd')
6327 origin_die
= lookup_decl_die (origin
);
6329 else if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 't')
6331 origin_die
= lookup_type_die (origin
);
6333 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
6336 /* We do not currently support the pure_virtual attribute. */
6339 add_pure_or_virtual_attribute (die
, func_decl
)
6340 register dw_die_ref die
;
6341 register tree func_decl
;
6343 if (DECL_VINDEX (func_decl
))
6345 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
6346 add_AT_loc (die
, DW_AT_vtable_elem_location
, new_loc_descr
6347 (DW_OP_constu
, TREE_INT_CST_LOW (DECL_VINDEX (func_decl
))));
6348 /* GNU extension: Record what type this method came from originally. */
6349 if (debug_info_level
> DINFO_LEVEL_TERSE
)
6350 add_AT_die_ref (die
, DW_AT_containing_type
,
6351 lookup_type_die (DECL_CONTEXT (func_decl
)));
6355 /********************* utility routines for DIEs *************************/
6357 /* Add source coordinate attributes for the given decl. */
6359 add_src_coords_attributes (die
, decl
)
6360 register dw_die_ref die
;
6363 register unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
6364 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
6365 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
6368 /* Add an DW_AT_name attribute and source coordinate attribute for the
6369 given decl, but only if it actually has a name. */
6371 add_name_and_src_coords_attributes (die
, decl
)
6372 register dw_die_ref die
;
6375 register tree decl_name
;
6376 decl_name
= DECL_NAME (decl
);
6377 if (decl_name
&& IDENTIFIER_POINTER (decl_name
))
6379 add_name_attribute (die
, dwarf2_name (decl
, 0));
6380 add_src_coords_attributes (die
, decl
);
6381 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
6382 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
6383 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
6384 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
6388 /* Push a new declaration scope. */
6390 push_decl_scope (scope
)
6393 /* Make room in the decl_scope_table, if necessary. */
6394 if (decl_scope_table_allocated
== decl_scope_depth
)
6396 decl_scope_table_allocated
+= DECL_SCOPE_TABLE_INCREMENT
;
6397 decl_scope_table
= (tree
*) xrealloc (decl_scope_table
,
6398 decl_scope_table_allocated
* sizeof (tree
));
6400 decl_scope_table
[decl_scope_depth
++] = scope
;
6403 /* Return the DIE for the scope the immediately contains this declaration. */
6405 scope_die_for (t
, context_die
)
6407 register dw_die_ref context_die
;
6409 register dw_die_ref scope_die
= NULL
;
6410 register tree containing_scope
;
6411 register unsigned long i
;
6413 /* Function-local tags and functions get stuck in limbo until they are
6414 fixed up by decls_for_scope. */
6415 if (context_die
== NULL
6416 && (TREE_CODE (t
) == FUNCTION_DECL
|| is_tagged_type (t
)))
6419 /* Walk back up the declaration tree looking for a place to define
6421 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
6422 containing_scope
= TYPE_CONTEXT (t
);
6423 else if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_VINDEX (t
))
6424 containing_scope
= decl_class_context (t
);
6426 containing_scope
= DECL_CONTEXT (t
);
6428 if (containing_scope
== NULL
)
6430 scope_die
= comp_unit_die
;
6434 for (i
= decl_scope_depth
, scope_die
= context_die
;
6435 i
> 0 && decl_scope_table
[i
- 1] != containing_scope
;
6436 scope_die
= scope_die
->die_parent
, --i
)
6440 assert (scope_die
== comp_unit_die
);
6441 assert (TREE_CODE_CLASS (TREE_CODE (containing_scope
)) == 't');
6442 if (debug_info_level
> DINFO_LEVEL_TERSE
)
6443 assert (TREE_ASM_WRITTEN (containing_scope
));
6449 /* Pop a declaration scope. */
6453 assert (decl_scope_depth
> 0);
6457 /* Many forms of DIEs require a "type description" attribute. This
6458 routine locates the proper "type descriptor" die for the type given
6459 by 'type', and adds an DW_AT_type attribute below the given die. */
6461 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
6462 register dw_die_ref object_die
;
6464 register int decl_const
;
6465 register int decl_volatile
;
6466 register dw_die_ref context_die
;
6468 register enum tree_code code
= TREE_CODE (type
);
6469 register dw_die_ref type_die
= NULL
;
6471 if (code
== ERROR_MARK
)
6476 /* Handle a special case. For functions whose return type is void, we
6477 generate *no* type attribute. (Note that no object may have type
6478 `void', so this only applies to function return types). */
6479 if (code
== VOID_TYPE
)
6484 type_die
= modified_type_die (type
,
6485 decl_const
|| TYPE_READONLY (type
),
6486 decl_volatile
|| TYPE_VOLATILE (type
),
6488 if (type_die
!= NULL
)
6490 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
6494 /* Given a tree pointer to a struct, class, union, or enum type node, return
6495 a pointer to the (string) tag name for the given type, or zero if the type
6496 was declared without a tag. */
6501 register char *name
= 0;
6503 if (TYPE_NAME (type
) != 0)
6505 register tree t
= 0;
6507 /* Find the IDENTIFIER_NODE for the type name. */
6508 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
6509 t
= TYPE_NAME (type
);
6511 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
6512 a TYPE_DECL node, regardless of whether or not a `typedef' was
6514 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
6515 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
6516 t
= DECL_NAME (TYPE_NAME (type
));
6518 /* Now get the name as a string, or invent one. */
6520 name
= IDENTIFIER_POINTER (t
);
6522 return (name
== 0 || *name
== '\0') ? 0 : name
;
6525 /* Return the type associated with a data member, make a special check
6526 for bit field types. */
6528 member_declared_type (member
)
6529 register tree member
;
6531 return (DECL_BIT_FIELD_TYPE (member
))
6532 ? DECL_BIT_FIELD_TYPE (member
)
6533 : TREE_TYPE (member
);
6536 /* Get the decl's label, as described by its RTL. This may be different
6537 from the DECL_NAME name used in the source file. */
6539 decl_start_label (decl
)
6544 x
= DECL_RTL (decl
);
6545 if (GET_CODE (x
) != MEM
)
6550 if (GET_CODE (x
) != SYMBOL_REF
)
6554 fnname
= XSTR (x
, 0);
6558 /******************************* DIE Generation *************************/
6560 /* These routines generate the internnal representation of the DIE's for
6561 the compilation unit. Debugging information is collected by walking
6562 the declaration trees passed in from dwarf2out_decl(). */
6565 gen_array_type_die (type
, context_die
)
6567 register dw_die_ref context_die
;
6569 register dw_die_ref scope_die
= scope_die_for (type
, context_die
);
6570 register dw_die_ref array_die
;
6571 register tree element_type
;
6573 /* ??? The SGI dwarf reader fails for array of array of enum types unless
6574 the inner array type comes before the outer array type. Thus we must
6575 call gen_type_die before we call new_die. See below also. */
6576 #ifdef MIPS_DEBUGGING_INFO
6577 gen_type_die (TREE_TYPE (type
), context_die
);
6580 array_die
= new_die (DW_TAG_array_type
, scope_die
);
6583 /* We default the array ordering. SDB will probably do
6584 the right things even if DW_AT_ordering is not present. It's not even
6585 an issue until we start to get into multidimensional arrays anyway. If
6586 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6587 then we'll have to put the DW_AT_ordering attribute back in. (But if
6588 and when we find out that we need to put these in, we will only do so
6589 for multidimensional arrays. */
6590 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
6593 #ifdef MIPS_DEBUGGING_INFO
6594 /* The SGI compilers handle arrays of unknown bound by setting
6595 AT_declaration and not emitting any subrange DIEs. */
6596 if (! TYPE_DOMAIN (type
))
6597 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
6600 add_subscript_info (array_die
, type
);
6602 equate_type_number_to_die (type
, array_die
);
6604 /* Add representation of the type of the elements of this array type. */
6605 element_type
= TREE_TYPE (type
);
6606 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6607 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6608 We work around this by disabling this feature. See also
6609 add_subscript_info. */
6610 #ifndef MIPS_DEBUGGING_INFO
6611 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
6613 element_type
= TREE_TYPE (element_type
);
6615 gen_type_die (element_type
, context_die
);
6618 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
6622 gen_set_type_die (type
, context_die
)
6624 register dw_die_ref context_die
;
6626 register dw_die_ref type_die
= new_die
6627 (DW_TAG_set_type
, scope_die_for (type
, context_die
));
6628 equate_type_number_to_die (type
, type_die
);
6629 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
6633 gen_entry_point_die (decl
, context_die
)
6635 register dw_die_ref context_die
;
6637 register tree origin
= decl_ultimate_origin (decl
);
6638 register dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
);
6641 add_abstract_origin_attribute (decl_die
, origin
);
6645 add_name_and_src_coords_attributes (decl_die
, decl
);
6646 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
6649 if (DECL_ABSTRACT (decl
))
6651 equate_decl_number_to_die (decl
, decl_die
);
6655 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
6659 /* Remember a type in the pending_types_list. */
6665 if (pending_types
== pending_types_allocated
)
6667 pending_types_allocated
+= PENDING_TYPES_INCREMENT
;
6669 = (tree
*) xrealloc (pending_types_list
,
6670 sizeof (tree
) * pending_types_allocated
);
6672 pending_types_list
[pending_types
++] = type
;
6675 /* Output any pending types (from the pending_types list) which we can output
6676 now (taking into account the scope that we are working on now).
6678 For each type output, remove the given type from the pending_types_list
6679 *before* we try to output it. */
6682 output_pending_types_for_scope (context_die
)
6683 register dw_die_ref context_die
;
6687 while (pending_types
)
6690 type
= pending_types_list
[pending_types
];
6691 gen_type_die (type
, context_die
);
6692 assert (TREE_ASM_WRITTEN (type
));
6696 /* Generate a DIE to represent an inlined instance of an enumeration type. */
6698 gen_inlined_enumeration_type_die (type
, context_die
)
6700 register dw_die_ref context_die
;
6702 register dw_die_ref type_die
;
6703 type_die
= new_die (DW_TAG_enumeration_type
,
6704 scope_die_for (type
, context_die
));
6705 assert (TREE_ASM_WRITTEN (type
));
6706 add_abstract_origin_attribute (type_die
, type
);
6709 /* Generate a DIE to represent an inlined instance of a structure type. */
6711 gen_inlined_structure_type_die (type
, context_die
)
6713 register dw_die_ref context_die
;
6715 register dw_die_ref type_die
;
6716 type_die
= new_die (DW_TAG_structure_type
,
6717 scope_die_for (type
, context_die
));
6718 assert (TREE_ASM_WRITTEN (type
));
6719 add_abstract_origin_attribute (type_die
, type
);
6722 /* Generate a DIE to represent an inlined instance of a union type. */
6724 gen_inlined_union_type_die (type
, context_die
)
6726 register dw_die_ref context_die
;
6728 register dw_die_ref type_die
;
6729 type_die
= new_die (DW_TAG_union_type
,
6730 scope_die_for (type
, context_die
));
6731 assert (TREE_ASM_WRITTEN (type
));
6732 add_abstract_origin_attribute (type_die
, type
);
6735 /* Generate a DIE to represent an enumeration type. Note that these DIEs
6736 include all of the information about the enumeration values also. Each
6737 enumerated type name/value is listed as a child of the enumerated type
6740 gen_enumeration_type_die (type
, context_die
)
6742 register dw_die_ref context_die
;
6744 register dw_die_ref type_die
= lookup_type_die (type
);
6746 if (type_die
== NULL
)
6748 type_die
= new_die (DW_TAG_enumeration_type
,
6749 scope_die_for (type
, context_die
));
6750 equate_type_number_to_die (type
, type_die
);
6751 add_name_attribute (type_die
, type_tag (type
));
6753 else if (! TYPE_SIZE (type
))
6756 remove_AT (type_die
, DW_AT_declaration
);
6758 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
6759 given enum type is incomplete, do not generate the DW_AT_byte_size
6760 attribute or the DW_AT_element_list attribute. */
6761 if (TYPE_SIZE (type
))
6764 TREE_ASM_WRITTEN (type
) = 1;
6765 add_byte_size_attribute (type_die
, type
);
6766 if (type_tag (type
))
6767 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
6768 for (link
= TYPE_FIELDS (type
);
6769 link
!= NULL
; link
= TREE_CHAIN (link
))
6771 register dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
);
6772 add_name_attribute (enum_die
,
6773 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
6774 add_AT_unsigned (enum_die
, DW_AT_const_value
,
6775 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link
)));
6779 add_AT_flag (type_die
, DW_AT_declaration
, 1);
6783 /* Generate a DIE to represent either a real live formal parameter decl or to
6784 represent just the type of some formal parameter position in some function
6786 Note that this routine is a bit unusual because its argument may be a
6787 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
6788 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
6789 node. If it's the former then this function is being called to output a
6790 DIE to represent a formal parameter object (or some inlining thereof). If
6791 it's the latter, then this function is only being called to output a
6792 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
6793 argument type of some subprogram type. */
6795 gen_formal_parameter_die (node
, context_die
)
6797 register dw_die_ref context_die
;
6799 register dw_die_ref parm_die
= new_die (DW_TAG_formal_parameter
,
6801 register tree origin
;
6802 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
6804 /* We were called with some kind of a ..._DECL node. */
6806 origin
= decl_ultimate_origin (node
);
6808 add_abstract_origin_attribute (parm_die
, origin
);
6811 add_name_and_src_coords_attributes (parm_die
, node
);
6812 add_type_attribute (parm_die
, TREE_TYPE (node
),
6813 TREE_READONLY (node
),
6814 TREE_THIS_VOLATILE (node
),
6816 if (DECL_ARTIFICIAL (node
))
6817 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
6819 equate_decl_number_to_die (node
, parm_die
);
6820 if (! DECL_ABSTRACT (node
))
6821 add_location_or_const_value_attribute (parm_die
, node
);
6824 /* We were called with some kind of a ..._TYPE node. */
6826 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
6829 /* Should never happen. */
6836 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
6837 at the end of an (ANSI prototyped) formal parameters list. */
6839 gen_unspecified_parameters_die (decl_or_type
, context_die
)
6840 register tree decl_or_type
;
6841 register dw_die_ref context_die
;
6843 register dw_die_ref parm_die
= new_die (DW_TAG_unspecified_parameters
,
6847 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
6848 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
6849 parameters as specified in some function type specification (except for
6850 those which appear as part of a function *definition*).
6851 Note that we must be careful here to output all of the parameter DIEs before*
6852 we output any DIEs needed to represent the types of the formal parameters.
6853 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
6854 non-parameter DIE it sees ends the formal parameter list. */
6856 gen_formal_types_die (function_or_method_type
, context_die
)
6857 register tree function_or_method_type
;
6858 register dw_die_ref context_die
;
6861 register tree formal_type
= NULL
;
6862 register tree first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
6865 /* In the case where we are generating a formal types list for a C++
6866 non-static member function type, skip over the first thing on the
6867 TYPE_ARG_TYPES list because it only represents the type of the hidden
6868 `this pointer'. The debugger should be able to figure out (without
6869 being explicitly told) that this non-static member function type takes a
6870 `this pointer' and should be able to figure what the type of that hidden
6871 parameter is from the DW_AT_member attribute of the parent
6872 DW_TAG_subroutine_type DIE. */
6873 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
)
6874 first_parm_type
= TREE_CHAIN (first_parm_type
);
6877 /* Make our first pass over the list of formal parameter types and output a
6878 DW_TAG_formal_parameter DIE for each one. */
6879 for (link
= first_parm_type
; link
; link
= TREE_CHAIN (link
))
6881 register dw_die_ref parm_die
;
6883 formal_type
= TREE_VALUE (link
);
6884 if (formal_type
== void_type_node
)
6887 /* Output a (nameless) DIE to represent the formal parameter itself. */
6888 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
6889 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
6890 && link
== first_parm_type
)
6891 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
6894 /* If this function type has an ellipsis, add a
6895 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
6896 if (formal_type
!= void_type_node
)
6897 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
6899 /* Make our second (and final) pass over the list of formal parameter types
6900 and output DIEs to represent those types (as necessary). */
6901 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
6903 link
= TREE_CHAIN (link
))
6905 formal_type
= TREE_VALUE (link
);
6906 if (formal_type
== void_type_node
)
6909 gen_type_die (formal_type
, context_die
);
6913 /* Generate a DIE to represent a declared function (either file-scope or
6916 gen_subprogram_die (decl
, context_die
)
6918 register dw_die_ref context_die
;
6920 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
6921 register tree origin
= decl_ultimate_origin (decl
);
6922 register dw_die_ref subr_die
;
6923 register dw_loc_descr_ref fp_loc
= NULL
;
6924 register unsigned fp_reg
;
6925 register tree fn_arg_types
;
6926 register tree outer_scope
;
6927 register dw_die_ref old_die
= lookup_decl_die (decl
);
6928 register int declaration
= (current_function_decl
!= decl
6929 || context_die
->die_tag
== DW_TAG_structure_type
6930 || context_die
->die_tag
== DW_TAG_union_type
);
6934 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
6935 add_abstract_origin_attribute (subr_die
, origin
);
6939 register unsigned file_index
6940 = lookup_filename (DECL_SOURCE_FILE (decl
));
6942 assert (get_AT_flag (old_die
, DW_AT_declaration
) == 1);
6944 /* If the definition comes from the same place as the declaration,
6945 maybe use the old DIE. We always want the DIE for this function
6946 that has the *_pc attributes to be under comp_unit_die so the
6947 debugger can find it. For inlines, that is the concrete instance,
6948 so we can use the old DIE here. For non-inline methods, we want a
6949 specification DIE at toplevel, so we need a new DIE. For local
6950 class methods, this does not apply. */
6951 if ((DECL_ABSTRACT (decl
) || old_die
->die_parent
== comp_unit_die
6952 || context_die
== NULL
)
6953 && get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
6954 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
6955 == DECL_SOURCE_LINE (decl
)))
6959 /* Clear out the declaration attribute and the parm types. */
6960 remove_AT (subr_die
, DW_AT_declaration
);
6961 remove_children (subr_die
);
6965 subr_die
= new_die (DW_TAG_subprogram
, context_die
);
6966 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
6967 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
6968 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
6969 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
6970 != DECL_SOURCE_LINE (decl
))
6972 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
6977 register dw_die_ref scope_die
;
6979 if (DECL_CONTEXT (decl
))
6980 scope_die
= scope_die_for (decl
, context_die
);
6982 /* Don't put block extern declarations under comp_unit_die. */
6983 scope_die
= context_die
;
6985 subr_die
= new_die (DW_TAG_subprogram
, scope_die
);
6987 if (TREE_PUBLIC (decl
))
6988 add_AT_flag (subr_die
, DW_AT_external
, 1);
6989 add_name_and_src_coords_attributes (subr_die
, decl
);
6990 if (debug_info_level
> DINFO_LEVEL_TERSE
)
6992 register tree type
= TREE_TYPE (decl
);
6993 add_prototyped_attribute (subr_die
, type
);
6994 add_type_attribute (subr_die
, TREE_TYPE (type
), 0, 0, context_die
);
6996 add_pure_or_virtual_attribute (subr_die
, decl
);
6997 if (DECL_ARTIFICIAL (decl
))
6998 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
6999 if (TREE_PROTECTED (decl
))
7000 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
7001 else if (TREE_PRIVATE (decl
))
7002 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
7007 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
7009 /* The first time we see a member function, it is in the context of
7010 the class to which it belongs. We make sure of this by emitting
7011 the class first. The next time is the definition, which is
7012 handled above. The two may come from the same source text. */
7013 if (decl_class_context (decl
))
7014 equate_decl_number_to_die (decl
, subr_die
);
7016 else if (DECL_ABSTRACT (decl
))
7018 if (DECL_DEFER_OUTPUT (decl
))
7020 if (DECL_INLINE (decl
))
7021 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
7023 add_AT_unsigned (subr_die
, DW_AT_inline
,
7024 DW_INL_declared_not_inlined
);
7026 else if (DECL_INLINE (decl
))
7027 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
7028 else if (declaration
)
7029 /* block extern declaration in an inline function. */
7030 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
7034 equate_decl_number_to_die (decl
, subr_die
);
7036 else if (!DECL_EXTERNAL (decl
))
7039 equate_decl_number_to_die (decl
, subr_die
);
7040 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
7041 current_funcdef_number
);
7042 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
7043 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
7044 current_funcdef_number
);
7045 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
7047 add_pubname (decl
, subr_die
);
7048 add_arange (decl
, subr_die
);
7050 #ifdef MIPS_DEBUGGING_INFO
7051 /* Add a reference to the FDE for this routine. */
7052 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
7055 /* Define the "frame base" location for this routine. We use the
7056 frame pointer or stack pointer registers, since the RTL for local
7057 variables is relative to one of them. */
7058 fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
7059 ? FRAME_POINTER_REGNUM
7060 : STACK_POINTER_REGNUM
);
7061 assert (fp_reg
>= 0 && fp_reg
<= 31);
7062 fp_loc
= new_loc_descr (DW_OP_reg0
+ fp_reg
);
7063 add_AT_loc (subr_die
, DW_AT_frame_base
, fp_loc
);
7065 if (current_function_needs_context
)
7066 add_AT_loc (subr_die
, DW_AT_static_link
,
7067 loc_descriptor (lookup_static_chain (decl
)));
7070 /* Now output descriptions of the arguments for this function. This gets
7071 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
7072 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
7073 `...' at the end of the formal parameter list. In order to find out if
7074 there was a trailing ellipsis or not, we must instead look at the type
7075 associated with the FUNCTION_DECL. This will be a node of type
7076 FUNCTION_TYPE. If the chain of type nodes hanging off of this
7077 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
7078 an ellipsis at the end. */
7080 push_decl_scope (decl
);
7081 /* In the case where we are describing a mere function declaration, all we
7082 need to do here (and all we *can* do here) is to describe the *types* of
7083 its formal parameters. */
7084 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
7086 else if (declaration
)
7087 gen_formal_types_die (TREE_TYPE (decl
), subr_die
);
7090 /* Generate DIEs to represent all known formal parameters */
7091 register tree arg_decls
= DECL_ARGUMENTS (decl
);
7094 /* When generating DIEs, generate the unspecified_parameters DIE
7095 instead if we come across the arg "__builtin_va_alist" */
7096 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
7098 if (TREE_CODE (parm
) == PARM_DECL
)
7100 if (DECL_NAME (parm
) &&
7101 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
7102 "__builtin_va_alist"))
7104 gen_unspecified_parameters_die (parm
, subr_die
);
7108 gen_decl_die (parm
, subr_die
);
7113 /* Decide whether we need a unspecified_parameters DIE at the end.
7114 There are 2 more cases to do this for: 1) the ansi ... declaration -
7115 this is detectable when the end of the arg list is not a
7116 void_type_node 2) an unprototyped function declaration (not a
7117 definition). This just means that we have no info about the
7118 parameters at all. */
7119 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
7122 /* this is the prototyped case, check for ... */
7123 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
7125 gen_unspecified_parameters_die (decl
, subr_die
);
7130 /* this is unprotoyped, check for undefined (just declaration) */
7131 if (!DECL_INITIAL (decl
))
7133 gen_unspecified_parameters_die (decl
, subr_die
);
7138 /* Output Dwarf info for all of the stuff within the body of the function
7139 (if it has one - it may be just a declaration). */
7140 outer_scope
= DECL_INITIAL (decl
);
7142 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
7143 node created to represent a function. This outermost BLOCK actually
7144 represents the outermost binding contour for the function, i.e. the
7145 contour in which the function's formal parameters and labels get
7146 declared. Curiously, it appears that the front end doesn't actually
7147 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
7148 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
7149 list for the function instead.) The BLOCK_VARS list for the
7150 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
7151 the function however, and we output DWARF info for those in
7152 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
7153 node representing the function's outermost pair of curly braces, and
7154 any blocks used for the base and member initializers of a C++
7155 constructor function. */
7156 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
7158 current_function_has_inlines
= 0;
7159 decls_for_scope (outer_scope
, subr_die
, 0);
7160 #if 0 && defined (MIPS_DEBUGGING_INFO)
7161 if (current_function_has_inlines
)
7163 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
7164 if (! comp_unit_has_inlines
)
7166 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
7167 comp_unit_has_inlines
= 1;
7175 /* Generate a DIE to represent a declared data object. */
7177 gen_variable_die (decl
, context_die
)
7179 register dw_die_ref context_die
;
7181 register tree origin
= decl_ultimate_origin (decl
);
7182 register dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
);
7183 dw_die_ref old_die
= lookup_decl_die (decl
);
7185 = (DECL_EXTERNAL (decl
)
7186 || current_function_decl
!= decl_function_context (decl
)
7187 || context_die
->die_tag
== DW_TAG_structure_type
7188 || context_die
->die_tag
== DW_TAG_union_type
);
7192 add_abstract_origin_attribute (var_die
, origin
);
7194 else if (old_die
&& TREE_STATIC (decl
))
7196 assert (get_AT_flag (old_die
, DW_AT_declaration
) == 1);
7197 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
7198 if (DECL_NAME (decl
))
7200 register unsigned file_index
7201 = lookup_filename (DECL_SOURCE_FILE (decl
));
7202 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
7203 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
7204 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
7205 != DECL_SOURCE_LINE (decl
))
7207 (var_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
7212 add_name_and_src_coords_attributes (var_die
, decl
);
7213 add_type_attribute (var_die
, TREE_TYPE (decl
),
7214 TREE_READONLY (decl
),
7215 TREE_THIS_VOLATILE (decl
), context_die
);
7216 if (TREE_PUBLIC (decl
))
7217 add_AT_flag (var_die
, DW_AT_external
, 1);
7218 if (DECL_ARTIFICIAL (decl
))
7219 add_AT_flag (var_die
, DW_AT_artificial
, 1);
7220 if (TREE_PROTECTED (decl
))
7221 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
7222 else if (TREE_PRIVATE (decl
))
7223 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
7227 add_AT_flag (var_die
, DW_AT_declaration
, 1);
7229 if ((declaration
&& decl_class_context (decl
)) || DECL_ABSTRACT (decl
))
7230 equate_decl_number_to_die (decl
, var_die
);
7232 if (! declaration
&& ! DECL_ABSTRACT (decl
))
7234 equate_decl_number_to_die (decl
, var_die
);
7235 add_location_or_const_value_attribute (var_die
, decl
);
7236 add_pubname (decl
, var_die
);
7240 /* Generate a DIE to represent a label identifier. */
7242 gen_label_die (decl
, context_die
)
7244 register dw_die_ref context_die
;
7246 register tree origin
= decl_ultimate_origin (decl
);
7247 register dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
);
7249 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7250 char label2
[MAX_ARTIFICIAL_LABEL_BYTES
];
7253 add_abstract_origin_attribute (lbl_die
, origin
);
7257 add_name_and_src_coords_attributes (lbl_die
, decl
);
7259 if (DECL_ABSTRACT (decl
))
7261 equate_decl_number_to_die (decl
, lbl_die
);
7265 insn
= DECL_RTL (decl
);
7266 if (GET_CODE (insn
) == CODE_LABEL
)
7268 /* When optimization is enabled (via -O) some parts of the compiler
7269 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
7270 represent source-level labels which were explicitly declared by
7271 the user. This really shouldn't be happening though, so catch
7272 it if it ever does happen. */
7273 if (INSN_DELETED_P (insn
))
7275 abort (); /* Should never happen. */
7277 sprintf (label2
, INSN_LABEL_FMT
, current_funcdef_number
);
7278 ASM_GENERATE_INTERNAL_LABEL (label
, label2
,
7279 (unsigned) INSN_UID (insn
));
7280 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
7285 /* Generate a DIE for a lexical block. */
7287 gen_lexical_block_die (stmt
, context_die
, depth
)
7289 register dw_die_ref context_die
;
7292 register dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
);
7293 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7294 if (!BLOCK_ABSTRACT (stmt
))
7296 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
7298 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
7299 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
, next_block_number
);
7300 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
7302 push_decl_scope (stmt
);
7303 decls_for_scope (stmt
, stmt_die
, depth
);
7307 /* Generate a DIE for an inlined subprogram. */
7309 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
7311 register dw_die_ref context_die
;
7314 if (!BLOCK_ABSTRACT (stmt
))
7316 register dw_die_ref subr_die
= new_die (DW_TAG_inlined_subroutine
,
7318 register tree decl
= block_ultimate_origin (stmt
);
7319 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7320 add_abstract_origin_attribute (subr_die
, decl
);
7321 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
7323 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
7324 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
, next_block_number
);
7325 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
7326 push_decl_scope (decl
);
7327 decls_for_scope (stmt
, subr_die
, depth
);
7329 current_function_has_inlines
= 1;
7333 /* Generate a DIE for a field in a record, or structure. */
7335 gen_field_die (decl
, context_die
)
7337 register dw_die_ref context_die
;
7339 register dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
);
7340 add_name_and_src_coords_attributes (decl_die
, decl
);
7341 add_type_attribute (decl_die
, member_declared_type (decl
),
7342 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
7344 /* If this is a bit field... */
7345 if (DECL_BIT_FIELD_TYPE (decl
))
7347 add_byte_size_attribute (decl_die
, decl
);
7348 add_bit_size_attribute (decl_die
, decl
);
7349 add_bit_offset_attribute (decl_die
, decl
);
7351 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
7352 add_data_member_location_attribute (decl_die
, decl
);
7353 if (DECL_ARTIFICIAL (decl
))
7354 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
7355 if (TREE_PROTECTED (decl
))
7356 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
7357 else if (TREE_PRIVATE (decl
))
7358 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
7362 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7363 Use modified_type_die instead.
7364 We keep this code here just in case these types of DIEs may be needed to
7365 represent certain things in other languages (e.g. Pascal) someday. */
7367 gen_pointer_type_die (type
, context_die
)
7369 register dw_die_ref context_die
;
7371 register dw_die_ref ptr_die
= new_die
7372 (DW_TAG_pointer_type
, scope_die_for (type
, context_die
));
7373 equate_type_number_to_die (type
, ptr_die
);
7374 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
7375 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7378 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7379 Use modified_type_die instead.
7380 We keep this code here just in case these types of DIEs may be needed to
7381 represent certain things in other languages (e.g. Pascal) someday. */
7383 gen_reference_type_die (type
, context_die
)
7385 register dw_die_ref context_die
;
7387 register dw_die_ref ref_die
= new_die
7388 (DW_TAG_reference_type
, scope_die_for (type
, context_die
));
7389 equate_type_number_to_die (type
, ref_die
);
7390 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
7391 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7395 /* Generate a DIE for a pointer to a member type. */
7397 gen_ptr_to_mbr_type_die (type
, context_die
)
7399 register dw_die_ref context_die
;
7401 register dw_die_ref ptr_die
= new_die
7402 (DW_TAG_ptr_to_member_type
, scope_die_for (type
, context_die
));
7403 equate_type_number_to_die (type
, ptr_die
);
7404 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
7405 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
7406 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
7409 /* Generate the DIE for the compilation unit. */
7411 gen_compile_unit_die (main_input_filename
)
7412 register char *main_input_filename
;
7415 char *wd
= getpwd ();
7417 comp_unit_die
= new_die (DW_TAG_compile_unit
, NULL
);
7419 add_name_attribute (comp_unit_die
, main_input_filename
);
7423 add_AT_string (comp_unit_die
, DW_AT_comp_dir
, wd
);
7426 sprintf (producer
, "%s %s", language_string
, version_string
);
7428 #ifdef MIPS_DEBUGGING_INFO
7429 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
7430 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
7431 not appear in the producer string, the debugger reaches the conclusion
7432 that the object file is stripped and has no debugging information.
7433 To get the MIPS/SGI debugger to believe that there is debugging
7434 information in the object file, we add a -g to the producer string. */
7435 if (debug_info_level
> DINFO_LEVEL_TERSE
)
7436 strcat (producer
, " -g");
7439 add_AT_string (comp_unit_die
, DW_AT_producer
, producer
);
7441 if (strcmp (language_string
, "GNU C++") == 0)
7442 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C_plus_plus
);
7443 else if (strcmp (language_string
, "GNU Ada") == 0)
7444 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Ada83
);
7445 else if (strcmp (language_string
, "GNU F77") == 0)
7446 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Fortran77
);
7447 else if (flag_traditional
)
7448 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C
);
7450 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C89
);
7452 #if 0 /* unimplemented */
7453 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
7454 add_AT_unsigned (comp_unit_die
, DW_AT_macro_info
, 0);
7458 /* Generate a DIE for a string type. */
7460 gen_string_type_die (type
, context_die
)
7462 register dw_die_ref context_die
;
7464 register dw_die_ref type_die
= new_die
7465 (DW_TAG_string_type
, scope_die_for (type
, context_die
));
7466 equate_type_number_to_die (type
, type_die
);
7468 /* Fudge the string length attribute for now. */
7470 /* TODO: add string length info.
7471 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7472 bound_representation (upper_bound, 0, 'u'); */
7475 /* Generate the DIE for a base class. */
7477 gen_inheritance_die (binfo
, context_die
)
7478 register tree binfo
;
7479 register dw_die_ref context_die
;
7481 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
);
7482 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
7483 add_data_member_location_attribute (die
, binfo
);
7484 if (TREE_VIA_VIRTUAL (binfo
))
7485 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
7486 if (TREE_VIA_PUBLIC (binfo
))
7487 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
7488 else if (TREE_VIA_PROTECTED (binfo
))
7489 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
7492 /* Genearate a DIE for a class member. */
7494 gen_member_die (type
, context_die
)
7496 register dw_die_ref context_die
;
7498 register tree member
;
7499 /* If this is not an incomplete type, output descriptions of each of its
7500 members. Note that as we output the DIEs necessary to represent the
7501 members of this record or union type, we will also be trying to output
7502 DIEs to represent the *types* of those members. However the `type'
7503 function (above) will specifically avoid generating type DIEs for member
7504 types *within* the list of member DIEs for this (containing) type execpt
7505 for those types (of members) which are explicitly marked as also being
7506 members of this (containing) type themselves. The g++ front- end can
7507 force any given type to be treated as a member of some other
7508 (containing) type by setting the TYPE_CONTEXT of the given (member) type
7509 to point to the TREE node representing the appropriate (containing)
7512 /* First output info about the base classes. */
7513 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
7515 register tree bases
= TYPE_BINFO_BASETYPES (type
);
7516 register int n_bases
= TREE_VEC_LENGTH (bases
);
7519 for (i
= 0; i
< n_bases
; i
++)
7520 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
7523 /* Now output info about the data members and type members. */
7524 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
7525 gen_decl_die (member
, context_die
);
7527 /* Now output info about the function members (if any). */
7528 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
7529 gen_decl_die (member
, context_die
);
7532 /* Generate a DIE for a structure or union type. */
7534 gen_struct_or_union_type_die (type
, context_die
)
7536 register dw_die_ref context_die
;
7538 register dw_die_ref type_die
= lookup_type_die (type
);
7539 register dw_die_ref scope_die
= 0;
7540 register int nested
= 0;
7542 if (type_die
&& ! TYPE_SIZE (type
))
7545 if (TYPE_CONTEXT (type
)
7546 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't')
7549 scope_die
= scope_die_for (type
, context_die
);
7551 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
7552 /* First occurrence of type or toplevel definition of nested class. */
7554 register dw_die_ref old_die
= type_die
;
7555 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
7556 ? DW_TAG_structure_type
: DW_TAG_union_type
,
7558 equate_type_number_to_die (type
, type_die
);
7559 add_name_attribute (type_die
, type_tag (type
));
7561 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
7564 remove_AT (type_die
, DW_AT_declaration
);
7566 /* If we're not in the right context to be defining this type, defer to
7567 avoid tricky recursion. */
7568 if (TYPE_SIZE (type
) && decl_scope_depth
> 0 && scope_die
== comp_unit_die
)
7570 add_AT_flag (type_die
, DW_AT_declaration
, 1);
7573 /* If this type has been completed, then give it a byte_size attribute and
7574 then give a list of members. */
7575 else if (TYPE_SIZE (type
))
7577 /* Prevent infinite recursion in cases where the type of some member of
7578 this type is expressed in terms of this type itself. */
7579 TREE_ASM_WRITTEN (type
) = 1;
7580 add_byte_size_attribute (type_die
, type
);
7581 if (type_tag (type
))
7582 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
7583 push_decl_scope (type
);
7584 gen_member_die (type
, type_die
);
7586 /* GNU extension: Record what type our vtable lives in. */
7587 if (TYPE_VFIELD (type
))
7589 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
7590 gen_type_die (vtype
, context_die
);
7591 add_AT_die_ref (type_die
, DW_AT_containing_type
,
7592 lookup_type_die (vtype
));
7596 add_AT_flag (type_die
, DW_AT_declaration
, 1);
7599 /* Generate a DIE for a subroutine _type_. */
7601 gen_subroutine_type_die (type
, context_die
)
7603 register dw_die_ref context_die
;
7605 register tree return_type
= TREE_TYPE (type
);
7606 register dw_die_ref subr_die
= new_die
7607 (DW_TAG_subroutine_type
, scope_die_for (type
, context_die
));
7608 equate_type_number_to_die (type
, subr_die
);
7609 add_prototyped_attribute (subr_die
, type
);
7610 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
7611 gen_formal_types_die (type
, subr_die
);
7614 /* Generate a DIE for a type definition */
7616 gen_typedef_die (decl
, context_die
)
7618 register dw_die_ref context_die
;
7620 register dw_die_ref type_die
;
7621 register tree origin
;
7623 if (TREE_ASM_WRITTEN (decl
))
7625 TREE_ASM_WRITTEN (decl
) = 1;
7627 type_die
= new_die (DW_TAG_typedef
, scope_die_for (decl
, context_die
));
7628 origin
= decl_ultimate_origin (decl
);
7630 add_abstract_origin_attribute (type_die
, origin
);
7634 add_name_and_src_coords_attributes (type_die
, decl
);
7635 if (DECL_ORIGINAL_TYPE (decl
))
7637 type
= DECL_ORIGINAL_TYPE (decl
);
7638 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
7641 type
= TREE_TYPE (decl
);
7642 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
7643 TREE_THIS_VOLATILE (decl
), context_die
);
7645 if (DECL_ABSTRACT (decl
))
7646 equate_decl_number_to_die (decl
, type_die
);
7649 /* Generate a type description DIE. */
7651 gen_type_die (type
, context_die
)
7653 register dw_die_ref context_die
;
7655 if (type
== 0 || type
== error_mark_node
)
7660 /* We are going to output a DIE to represent the unqualified version of of
7661 this type (i.e. without any const or volatile qualifiers) so get the
7662 main variant (i.e. the unqualified version) of this type now. */
7663 type
= type_main_variant (type
);
7665 if (TREE_ASM_WRITTEN (type
))
7670 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
7671 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
7673 TREE_ASM_WRITTEN (type
) = 1;
7674 gen_decl_die (TYPE_NAME (type
), context_die
);
7678 switch (TREE_CODE (type
))
7684 case REFERENCE_TYPE
:
7685 /* For these types, all that is required is that we output a DIE (or a
7686 set of DIEs) to represent the "basis" type. */
7687 gen_type_die (TREE_TYPE (type
), context_die
);
7691 /* This code is used for C++ pointer-to-data-member types. */
7692 /* Output a description of the relevant class type. */
7693 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
7694 /* Output a description of the type of the object pointed to. */
7695 gen_type_die (TREE_TYPE (type
), context_die
);
7696 /* Now output a DIE to represent this pointer-to-data-member type
7698 gen_ptr_to_mbr_type_die (type
, context_die
);
7702 gen_type_die (TYPE_DOMAIN (type
), context_die
);
7703 gen_set_type_die (type
, context_die
);
7707 gen_type_die (TREE_TYPE (type
), context_die
);
7708 abort (); /* No way to represent these in Dwarf yet! */
7712 /* Force out return type (in case it wasn't forced out already). */
7713 gen_type_die (TREE_TYPE (type
), context_die
);
7714 gen_subroutine_type_die (type
, context_die
);
7718 /* Force out return type (in case it wasn't forced out already). */
7719 gen_type_die (TREE_TYPE (type
), context_die
);
7720 gen_subroutine_type_die (type
, context_die
);
7724 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
7726 gen_type_die (TREE_TYPE (type
), context_die
);
7727 gen_string_type_die (type
, context_die
);
7731 gen_array_type_die (type
, context_die
);
7738 case QUAL_UNION_TYPE
:
7739 /* If this is a nested type whose containing class hasn't been
7740 written out yet, writing it out will cover this one, too. */
7741 if (TYPE_CONTEXT (type
)
7742 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't'
7743 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
7745 gen_type_die (TYPE_CONTEXT (type
), context_die
);
7747 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
7750 /* If that failed, attach ourselves to the stub. */
7751 push_decl_scope (TYPE_CONTEXT (type
));
7752 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
7755 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
7756 gen_enumeration_type_die (type
, context_die
);
7758 gen_struct_or_union_type_die (type
, context_die
);
7760 if (TYPE_CONTEXT (type
)
7761 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type
))) == 't'
7762 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
7765 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
7766 it up if it is ever completed. gen_*_type_die will set it for us
7767 when appropriate. */
7776 /* No DIEs needed for fundamental types. */
7780 /* No Dwarf representation currently defined. */
7787 TREE_ASM_WRITTEN (type
) = 1;
7790 /* Generate a DIE for a tagged type instantiation. */
7792 gen_tagged_type_instantiation_die (type
, context_die
)
7794 register dw_die_ref context_die
;
7796 if (type
== 0 || type
== error_mark_node
)
7801 /* We are going to output a DIE to represent the unqualified version of of
7802 this type (i.e. without any const or volatile qualifiers) so make sure
7803 that we have the main variant (i.e. the unqualified version) of this
7805 assert (type
== type_main_variant (type
));
7806 assert (TREE_ASM_WRITTEN (type
));
7808 switch (TREE_CODE (type
))
7814 gen_inlined_enumeration_type_die (type
, context_die
);
7818 gen_inlined_structure_type_die (type
, context_die
);
7822 case QUAL_UNION_TYPE
:
7823 gen_inlined_union_type_die (type
, context_die
);
7827 abort (); /* Should never happen. */
7831 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
7832 things which are local to the given block. */
7834 gen_block_die (stmt
, context_die
, depth
)
7836 register dw_die_ref context_die
;
7839 register int must_output_die
= 0;
7840 register tree origin
;
7842 register enum tree_code origin_code
;
7844 /* Ignore blocks never really used to make RTL. */
7846 if (!stmt
|| !TREE_USED (stmt
))
7851 /* Determine the "ultimate origin" of this block. This block may be an
7852 inlined instance of an inlined instance of inline function, so we have
7853 to trace all of the way back through the origin chain to find out what
7854 sort of node actually served as the original seed for the creation of
7855 the current block. */
7856 origin
= block_ultimate_origin (stmt
);
7857 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
7859 /* Determine if we need to output any Dwarf DIEs at all to represent this
7861 if (origin_code
== FUNCTION_DECL
)
7863 /* The outer scopes for inlinings *must* always be represented. We
7864 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
7865 must_output_die
= 1;
7869 /* In the case where the current block represents an inlining of the
7870 "body block" of an inline function, we must *NOT* output any DIE for
7871 this block because we have already output a DIE to represent the
7872 whole inlined function scope and the "body block" of any function
7873 doesn't really represent a different scope according to ANSI C
7874 rules. So we check here to make sure that this block does not
7875 represent a "body block inlining" before trying to set the
7876 `must_output_die' flag. */
7877 if (! is_body_block (origin
? origin
: stmt
))
7879 /* Determine if this block directly contains any "significant"
7880 local declarations which we will need to output DIEs for. */
7881 if (debug_info_level
> DINFO_LEVEL_TERSE
)
7883 /* We are not in terse mode so *any* local declaration counts
7884 as being a "significant" one. */
7885 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
7889 /* We are in terse mode, so only local (nested) function
7890 definitions count as "significant" local declarations. */
7891 for (decl
= BLOCK_VARS (stmt
);
7892 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
7894 if (TREE_CODE (decl
) == FUNCTION_DECL
7895 && DECL_INITIAL (decl
))
7897 must_output_die
= 1;
7905 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
7906 DIE for any block which contains no significant local declarations at
7907 all. Rather, in such cases we just call `decls_for_scope' so that any
7908 needed Dwarf info for any sub-blocks will get properly generated. Note
7909 that in terse mode, our definition of what constitutes a "significant"
7910 local declaration gets restricted to include only inlined function
7911 instances and local (nested) function definitions. */
7912 if (must_output_die
)
7914 if (origin_code
== FUNCTION_DECL
)
7916 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
7920 gen_lexical_block_die (stmt
, context_die
, depth
);
7924 decls_for_scope (stmt
, context_die
, depth
);
7927 /* Generate all of the decls declared within a given scope and (recursively)
7928 all of it's sub-blocks. */
7930 decls_for_scope (stmt
, context_die
, depth
)
7932 register dw_die_ref context_die
;
7936 register tree subblocks
;
7937 /* Ignore blocks never really used to make RTL. */
7938 if (!stmt
|| !TREE_USED (stmt
))
7942 if (!BLOCK_ABSTRACT (stmt
) && depth
> 0)
7944 next_block_number
++;
7947 /* Output the DIEs to represent all of the data objects and typedefs
7948 declared directly within this block but not within any nested
7949 sub-blocks. Also, nested function and tag DIEs have been
7950 generated with a parent of NULL; fix that up now. */
7951 for (decl
= BLOCK_VARS (stmt
);
7952 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
7954 register dw_die_ref die
;
7956 if (TREE_CODE (decl
) == FUNCTION_DECL
)
7957 die
= lookup_decl_die (decl
);
7958 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
7959 die
= lookup_type_die (TREE_TYPE (decl
));
7963 if (die
&& die
->die_parent
== NULL
)
7965 add_child_die (context_die
, die
);
7969 gen_decl_die (decl
, context_die
);
7972 /* Output the DIEs to represent all sub-blocks (and the items declared
7973 therein) of this block. */
7974 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
7976 subblocks
= BLOCK_CHAIN (subblocks
))
7978 gen_block_die (subblocks
, context_die
, depth
+ 1);
7982 /* Is this a typedef we can avoid emitting? */
7984 is_redundant_typedef (decl
)
7987 if (TYPE_DECL_IS_STUB (decl
))
7989 if (DECL_ARTIFICIAL (decl
)
7990 && DECL_CONTEXT (decl
)
7991 && is_tagged_type (DECL_CONTEXT (decl
))
7992 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
7993 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
7994 /* Also ignore the artificial member typedef for the class name. */
7999 /* Generate Dwarf debug information for a decl described by DECL. */
8001 gen_decl_die (decl
, context_die
)
8003 register dw_die_ref context_die
;
8005 register tree origin
;
8006 /* Make a note of the decl node we are going to be working on. We may need
8007 to give the user the source coordinates of where it appeared in case we
8008 notice (later on) that something about it looks screwy. */
8009 dwarf_last_decl
= decl
;
8011 if (TREE_CODE (decl
) == ERROR_MARK
)
8016 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
8017 ignore a function definition, since that would screw up our count of
8018 blocks, and that it turn will completely screw up the the labels we will
8019 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8020 subsequent blocks). */
8021 if (DECL_IGNORED_P (decl
) && TREE_CODE (decl
) != FUNCTION_DECL
)
8026 switch (TREE_CODE (decl
))
8029 /* The individual enumerators of an enum type get output when we output
8030 the Dwarf representation of the relevant enum type itself. */
8034 /* Don't output any DIEs to represent mere function declarations,
8035 unless they are class members or explicit block externs. */
8036 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
8037 && (current_function_decl
== NULL_TREE
|| ! DECL_ARTIFICIAL (decl
)))
8042 if (debug_info_level
> DINFO_LEVEL_TERSE
)
8044 /* Before we describe the FUNCTION_DECL itself, make sure that we
8045 have described its return type. */
8046 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
8048 /* And its containing type. */
8049 origin
= decl_class_context (decl
);
8051 gen_type_die (origin
, context_die
);
8053 /* And its virtual context. */
8054 if (DECL_VINDEX (decl
))
8055 gen_type_die (DECL_CONTEXT (decl
), context_die
);
8058 /* Now output a DIE to represent the function itself. */
8059 gen_subprogram_die (decl
, context_die
);
8063 /* If we are in terse mode, don't generate any DIEs to represent any
8065 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8068 /* In the special case of a TYPE_DECL node representing the
8069 declaration of some type tag, if the given TYPE_DECL is marked as
8070 having been instantiated from some other (original) TYPE_DECL node
8071 (e.g. one which was generated within the original definition of an
8072 inline function) we have to generate a special (abbreviated)
8073 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
8075 if (TYPE_DECL_IS_STUB (decl
) && DECL_ABSTRACT_ORIGIN (decl
))
8077 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
8081 if (is_redundant_typedef (decl
))
8082 gen_type_die (TREE_TYPE (decl
), context_die
);
8085 /* Output a DIE to represent the typedef itself. */
8086 gen_typedef_die (decl
, context_die
);
8091 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
8093 gen_label_die (decl
, context_die
);
8098 /* If we are in terse mode, don't generate any DIEs to represent any
8099 variable declarations or definitions. */
8100 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8105 /* Output any DIEs that are needed to specify the type of this data
8107 gen_type_die (TREE_TYPE (decl
), context_die
);
8109 /* And its containing type. */
8110 origin
= decl_class_context (decl
);
8112 gen_type_die (origin
, context_die
);
8114 /* Now output the DIE to represent the data object itself. This gets
8115 complicated because of the possibility that the VAR_DECL really
8116 represents an inlined instance of a formal parameter for an inline
8118 origin
= decl_ultimate_origin (decl
);
8119 if (origin
!= NULL
&& TREE_CODE (origin
) == PARM_DECL
)
8121 gen_formal_parameter_die (decl
, context_die
);
8125 gen_variable_die (decl
, context_die
);
8130 /* Ignore the nameless fields that are used to skip bits, but
8131 handle C++ anonymous unions. */
8132 if (DECL_NAME (decl
) != 0 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
8134 gen_type_die (member_declared_type (decl
), context_die
);
8135 gen_field_die (decl
, context_die
);
8140 gen_type_die (TREE_TYPE (decl
), context_die
);
8141 gen_formal_parameter_die (decl
, context_die
);
8149 /***************** Debug Information Generation Hooks ***********************/
8151 dwarf2out_decl (decl
)
8154 register dw_die_ref context_die
= comp_unit_die
;
8156 if (TREE_CODE (decl
) == ERROR_MARK
)
8161 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
8162 hope that the node in question doesn't represent a function definition.
8163 If it does, then totally ignoring it is bound to screw up our count of
8164 blocks, and that it turn will completely screw up the the labels we will
8165 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8166 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
8167 own sequence numbers with them!) */
8168 if (DECL_IGNORED_P (decl
))
8170 if (TREE_CODE (decl
) == FUNCTION_DECL
8171 && DECL_INITIAL (decl
) != NULL
)
8178 switch (TREE_CODE (decl
))
8181 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
8182 builtin function. Explicit programmer-supplied declarations of
8183 these same functions should NOT be ignored however. */
8184 if (DECL_EXTERNAL (decl
) && DECL_FUNCTION_CODE (decl
))
8189 /* What we would really like to do here is to filter out all mere
8190 file-scope declarations of file-scope functions which are never
8191 referenced later within this translation unit (and keep all of ones
8192 that *are* referenced later on) but we aren't clarvoiant, so we have
8193 no idea which functions will be referenced in the future (i.e. later
8194 on within the current translation unit). So here we just ignore all
8195 file-scope function declarations which are not also definitions. If
8196 and when the debugger needs to know something about these funcstion,
8197 it wil have to hunt around and find the DWARF information associated
8198 with the definition of the function. Note that we can't just check
8199 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
8200 definitions and which ones represent mere declarations. We have to
8201 check `DECL_INITIAL' instead. That's because the C front-end
8202 supports some weird semantics for "extern inline" function
8203 definitions. These can get inlined within the current translation
8204 unit (an thus, we need to generate DWARF info for their abstract
8205 instances so that the DWARF info for the concrete inlined instances
8206 can have something to refer to) but the compiler never generates any
8207 out-of-lines instances of such things (despite the fact that they
8208 *are* definitions). The important point is that the C front-end
8209 marks these "extern inline" functions as DECL_EXTERNAL, but we need
8210 to generate DWARF for them anyway. Note that the C++ front-end also
8211 plays some similar games for inline function definitions appearing
8212 within include files which also contain
8213 `#pragma interface' pragmas. */
8214 if (DECL_INITIAL (decl
) == NULL_TREE
)
8219 /* If we're a nested function, initially use a parent of NULL; if we're
8220 a plain function, this will be fixed up in decls_for_scope. If
8221 we're a method, it will be ignored, since we already have a DIE. */
8222 if (decl_function_context (decl
))
8228 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
8229 declaration and if the declaration was never even referenced from
8230 within this entire compilation unit. We suppress these DIEs in
8231 order to save space in the .debug section (by eliminating entries
8232 which are probably useless). Note that we must not suppress
8233 block-local extern declarations (whether used or not) because that
8234 would screw-up the debugger's name lookup mechanism and cause it to
8235 miss things which really ought to be in scope at a given point. */
8236 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
8241 /* If we are in terse mode, don't generate any DIEs to represent any
8242 variable declarations or definitions. */
8243 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8250 /* Don't bother trying to generate any DIEs to represent any of the
8251 normal built-in types for the language we are compiling. */
8252 if (DECL_SOURCE_LINE (decl
) == 0)
8254 /* OK, we need to generate one for `bool' so GDB knows what type
8255 comparisons have. */
8256 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
8257 == DW_LANG_C_plus_plus
)
8258 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
)
8259 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
8263 /* If we are in terse mode, don't generate any DIEs for types. */
8264 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8267 /* If we're a function-scope tag, initially use a parent of NULL;
8268 this will be fixed up in decls_for_scope. */
8269 if (decl_function_context (decl
))
8278 gen_decl_die (decl
, context_die
);
8279 output_pending_types_for_scope (comp_unit_die
);
8281 if (TREE_CODE (decl
) == FUNCTION_DECL
8282 && DECL_INITIAL (decl
) != NULL
)
8284 current_funcdef_number
++;
8289 /* Output a marker (i.e. a label) for the beginning of the generated code for
8292 dwarf2out_begin_block (blocknum
)
8293 register unsigned blocknum
;
8295 function_section (current_function_decl
);
8296 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
8299 /* Output a marker (i.e. a label) for the end of the generated code for a
8302 dwarf2out_end_block (blocknum
)
8303 register unsigned blocknum
;
8305 function_section (current_function_decl
);
8306 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
8309 /* Output a marker (i.e. a label) at a point in the assembly code which
8310 corresponds to a given source level label. */
8312 dwarf2out_label (insn
)
8315 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8316 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
8318 function_section (current_function_decl
);
8319 sprintf (label
, INSN_LABEL_FMT
, current_funcdef_number
);
8320 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, label
,
8321 (unsigned) INSN_UID (insn
));
8325 /* Output a marker (i.e. a label) for the beginning of a function, before
8328 dwarf2out_begin_prologue ()
8330 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8331 register dw_fde_ref fde
;
8333 function_section (current_function_decl
);
8334 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
8335 current_funcdef_number
);
8336 ASM_OUTPUT_LABEL (asm_out_file
, label
);
8338 /* Expand the fde table if necessary. */
8339 if (fde_table_in_use
== fde_table_allocated
)
8341 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
8342 fde_table
= (dw_fde_ref
) xrealloc (fde_table
,
8343 fde_table_allocated
* sizeof (dw_fde_node
));
8346 /* Record the FDE associated with this function. */
8347 current_funcdef_fde
= fde_table_in_use
;
8349 /* Add the new FDE at the end of the fde_table. */
8350 fde
= &fde_table
[fde_table_in_use
++];
8351 fde
->dw_fde_begin
= xstrdup (label
);
8352 fde
->dw_fde_current_label
= NULL
;
8353 fde
->dw_fde_end
= NULL
;
8354 fde
->dw_fde_cfi
= NULL
;
8357 /* Output a marker (i.e. a label) for the absolute end of the generated code
8358 for a function definition. This gets called *after* the epilogue code has
8361 dwarf2out_end_epilogue ()
8364 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8365 /* Output a label to mark the endpoint of the code generated for this
8367 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
8368 ASM_OUTPUT_LABEL (asm_out_file
, label
);
8369 fde
= &fde_table
[fde_table_in_use
- 1];
8370 fde
->dw_fde_end
= xstrdup (label
);
8373 /* Lookup a filename (in the list of filenames that we know about here in
8374 dwarf2out.c) and return its "index". The index of each (known) filename is
8375 just a unique number which is associated with only that one filename.
8376 We need such numbers for the sake of generating labels
8377 (in the .debug_sfnames section) and references to those
8378 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
8379 If the filename given as an argument is not found in our current list,
8380 add it to the list and assign it the next available unique index number.
8381 In order to speed up searches, we remember the index of the filename
8382 was looked up last. This handles the majority of all searches. */
8384 lookup_filename (file_name
)
8387 static unsigned last_file_lookup_index
= 0;
8389 register unsigned i
;
8391 /* Check to see if the file name that was searched on the previous call
8392 matches this file name. If so, return the index. */
8393 if (last_file_lookup_index
!= 0)
8395 fn
= file_table
[last_file_lookup_index
];
8396 if (strcmp (file_name
, fn
) == 0)
8398 return last_file_lookup_index
;
8402 /* Didn't match the previous lookup, search the table */
8403 for (i
= 1; i
< file_table_in_use
; ++i
)
8406 if (strcmp (file_name
, fn
) == 0)
8408 last_file_lookup_index
= i
;
8413 /* Prepare to add a new table entry by making sure there is enough space in
8414 the table to do so. If not, expand the current table. */
8415 if (file_table_in_use
== file_table_allocated
)
8417 file_table_allocated
+= FILE_TABLE_INCREMENT
;
8420 xrealloc (file_table
, file_table_allocated
* sizeof (char *));
8423 /* add the new entry to the end of the filename table. */
8424 file_table
[file_table_in_use
] = xstrdup (file_name
);
8425 last_file_lookup_index
= file_table_in_use
++;
8426 return last_file_lookup_index
;
8429 /* Output a label to mark the beginning of a source code line entry
8430 and record information relating to this source line, in
8431 'line_info_table' for later output of the .debug_line section. */
8433 dwarf2out_line (filename
, line
)
8434 register char *filename
;
8435 register unsigned line
;
8437 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
8439 function_section (current_function_decl
);
8441 if (DECL_SECTION_NAME (current_function_decl
))
8443 register dw_separate_line_info_ref line_info
;
8444 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
8445 separate_line_info_table_in_use
);
8446 fputc ('\n', asm_out_file
);
8448 /* expand the line info table if necessary */
8449 if (separate_line_info_table_in_use
8450 == separate_line_info_table_allocated
)
8452 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
8453 separate_line_info_table
8454 = (dw_separate_line_info_ref
) xrealloc
8455 (separate_line_info_table
,
8456 separate_line_info_table_allocated
8457 * sizeof (dw_separate_line_info_entry
));
8459 /* add the new entry at the end of the line_info_table. */
8461 = &separate_line_info_table
[separate_line_info_table_in_use
++];
8462 line_info
->dw_file_num
= lookup_filename (filename
);
8463 line_info
->dw_line_num
= line
;
8464 line_info
->function
= current_funcdef_number
;
8468 register dw_line_info_ref line_info
;
8469 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
8470 line_info_table_in_use
);
8471 fputc ('\n', asm_out_file
);
8473 /* expand the line info table if necessary */
8474 if (line_info_table_in_use
== line_info_table_allocated
)
8476 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
8478 = (dw_line_info_ref
) xrealloc
8480 line_info_table_allocated
* sizeof (dw_line_info_entry
));
8482 /* add the new entry at the end of the line_info_table. */
8483 line_info
= &line_info_table
[line_info_table_in_use
++];
8484 line_info
->dw_file_num
= lookup_filename (filename
);
8485 line_info
->dw_line_num
= line
;
8490 /* Record the beginning of a new source file, for later output
8491 of the .debug_macinfo section. At present, unimplemented. */
8493 dwarf2out_start_source_file (filename
)
8494 register char *filename
;
8498 /* Record the end of a source file, for later output
8499 of the .debug_macinfo section. At present, unimplemented. */
8501 dwarf2out_end_source_file ()
8505 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8506 the tail part of the directive line, i.e. the part which is past the
8507 initial whitespace, #, whitespace, directive-name, whitespace part. */
8509 dwarf2out_define (lineno
, buffer
)
8510 register unsigned lineno
;
8511 register char *buffer
;
8513 static int initialized
= 0;
8516 dwarf2out_start_source_file (primary_filename
);
8521 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8522 the tail part of the directive line, i.e. the part which is past the
8523 initial whitespace, #, whitespace, directive-name, whitespace part. */
8525 dwarf2out_undef (lineno
, buffer
)
8526 register unsigned lineno
;
8527 register char *buffer
;
8531 /* Set up for Dwarf output at the start of compilation. */
8533 dwarf2out_init (asm_out_file
, main_input_filename
)
8534 register FILE *asm_out_file
;
8535 register char *main_input_filename
;
8537 /* Remember the name of the primary input file. */
8538 primary_filename
= main_input_filename
;
8540 /* Allocate the initial hunk of the file_table. */
8541 file_table
= (char **) xmalloc (FILE_TABLE_INCREMENT
* sizeof (char *));
8542 bzero (file_table
, FILE_TABLE_INCREMENT
* sizeof (char *));
8543 file_table_allocated
= FILE_TABLE_INCREMENT
;
8544 /* skip the first entry - file numbers begin at 1 */
8545 file_table_in_use
= 1;
8547 /* Allocate the initial hunk of the decl_die_table. */
8549 = (dw_die_ref
*) xmalloc (DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
8550 bzero (decl_die_table
, DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
8551 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
8552 decl_die_table_in_use
= 0;
8554 /* Allocate the initial hunk of the decl_scope_table. */
8556 = (tree
*) xmalloc (DECL_SCOPE_TABLE_INCREMENT
* sizeof (tree
));
8557 bzero (decl_scope_table
, DECL_SCOPE_TABLE_INCREMENT
* sizeof (tree
));
8558 decl_scope_table_allocated
= DECL_SCOPE_TABLE_INCREMENT
;
8559 decl_scope_depth
= 0;
8561 /* Allocate the initial hunk of the abbrev_die_table. */
8563 = (dw_die_ref
*) xmalloc (ABBREV_DIE_TABLE_INCREMENT
8564 * sizeof (dw_die_ref
));
8565 bzero (abbrev_die_table
, ABBREV_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
8566 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
8567 /* zero-th entry is allocated, but unused */
8568 abbrev_die_table_in_use
= 1;
8570 /* Allocate the initial hunk of the line_info_table. */
8572 = (dw_line_info_ref
) xmalloc (LINE_INFO_TABLE_INCREMENT
8573 * sizeof (dw_line_info_entry
));
8574 bzero (line_info_table
, LINE_INFO_TABLE_INCREMENT
8575 * sizeof (dw_line_info_entry
));
8576 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
8577 /* zero-th entry is allocated, but unused */
8578 line_info_table_in_use
= 1;
8580 /* Allocate the initial hunk of the fde_table. */
8581 fde_table
= (dw_fde_ref
) xmalloc (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
8582 bzero (fde_table
, FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
8583 fde_table_allocated
= FDE_TABLE_INCREMENT
;
8584 fde_table_in_use
= 0;
8586 /* Generate the initial DIE for the .debug section. Note that the (string)
8587 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8588 will (typically) be a relative pathname and that this pathname should be
8589 taken as being relative to the directory from which the compiler was
8590 invoked when the given (base) source file was compiled. */
8591 gen_compile_unit_die (main_input_filename
);
8593 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
8595 /* Generate the CFA instructions common to all FDE's. Do it now for the
8596 sake of lookup_cfa. */
8598 #ifdef INCOMING_RETURN_ADDR_RTX
8599 /* On entry, the Canonical Frame Address is at SP+0. */
8600 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, 0);
8601 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
8605 /* Output stuff that dwarf requires at the end of every file,
8606 and generate the DWARF-2 debugging info. */
8610 /* Traverse the DIE tree and add sibling attributes to those DIE's
8611 that have children. */
8612 add_sibling_attributes (comp_unit_die
);
8614 /* Output a terminator label for the .text section. */
8615 fputc ('\n', asm_out_file
);
8616 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
8617 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
8620 /* Output a terminator label for the .data section. */
8621 fputc ('\n', asm_out_file
);
8622 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
8623 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, DATA_END_LABEL
, 0);
8625 /* Output a terminator label for the .bss section. */
8626 fputc ('\n', asm_out_file
);
8627 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
8628 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, BSS_END_LABEL
, 0);
8631 /* Output the source line correspondence table. */
8632 if (line_info_table_in_use
> 1 || separate_line_info_table_in_use
)
8634 fputc ('\n', asm_out_file
);
8635 ASM_OUTPUT_SECTION (asm_out_file
, LINE_SECTION
);
8636 output_line_info ();
8638 /* We can only use the low/high_pc attributes if all of the code
8640 if (separate_line_info_table_in_use
== 0)
8642 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, TEXT_SECTION
);
8643 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
8645 add_AT_section_offset (comp_unit_die
, DW_AT_stmt_list
, LINE_SECTION
);
8648 /* Output the abbreviation table. */
8649 fputc ('\n', asm_out_file
);
8650 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
8651 build_abbrev_table (comp_unit_die
);
8652 output_abbrev_section ();
8654 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8655 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8656 calc_die_sizes (comp_unit_die
);
8658 /* calculate sizes/offsets for FDEs. */
8661 /* Output debugging information. */
8662 fputc ('\n', asm_out_file
);
8663 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_SECTION
);
8664 output_compilation_unit_header ();
8665 output_die (comp_unit_die
);
8667 if (pubname_table_in_use
)
8669 /* Output public names table. */
8670 fputc ('\n', asm_out_file
);
8671 ASM_OUTPUT_SECTION (asm_out_file
, PUBNAMES_SECTION
);
8675 if (fde_table_in_use
)
8677 /* Output call frame information. */
8678 output_call_frame_info ();
8680 /* Output the address range information. */
8681 fputc ('\n', asm_out_file
);
8682 ASM_OUTPUT_SECTION (asm_out_file
, ARANGES_SECTION
);
8686 /* The only DIE we should have with a parent of NULL is comp_unit_die. */
8687 assert (limbo_die_count
== 1);
8689 #endif /* DWARF2_DEBUGGING_INFO */